[FIX] Исправлена логика выявления типа версии - часть 2.

This commit is contained in:
zaxar163 2019-01-22 22:12:56 +03:00
parent 012870cf26
commit 2a59e8fe0b
No known key found for this signature in database
GPG key ID: E3B309DD3852DE06
2 changed files with 27 additions and 44 deletions

View file

@ -8,6 +8,7 @@
import java.util.Locale; import java.util.Locale;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -26,6 +27,7 @@ public class Updater extends TimerTask {
private static final Version VERSION = Launcher.getVersion(); private static final Version VERSION = Launcher.getVersion();
private final Timer taskPool; private final Timer taskPool;
private final GHRepository gravitLauncher; private final GHRepository gravitLauncher;
private Version parent = VERSION;
public Updater(LaunchServer srv) { public Updater(LaunchServer srv) {
this.taskPool = new Timer("Updater thread", true); this.taskPool = new Timer("Updater thread", true);
@ -37,7 +39,6 @@ public Updater(LaunchServer srv) {
LogHelper.error(e); LogHelper.error(e);
} }
this.gravitLauncher = gravitLauncherTmp; this.gravitLauncher = gravitLauncherTmp;
run(); run();
if (srv.config.updatesNotify) taskPool.schedule(this, new Date(System.currentTimeMillis()+period), period); if (srv.config.updatesNotify) taskPool.schedule(this, new Date(System.currentTimeMillis()+period), period);
} }
@ -47,6 +48,7 @@ public void run() {
try { try {
GHRelease rel = gravitLauncher.getLatestRelease(); GHRelease rel = gravitLauncher.getLatestRelease();
Version relV = parseVer(rel.getTagName()); Version relV = parseVer(rel.getTagName());
if (!relV.equals(parent)) parent = relV;
if (VERSION.major >= relV.major || VERSION.minor >= relV.minor if (VERSION.major >= relV.major || VERSION.minor >= relV.minor
|| VERSION.patch >= relV.patch || VERSION.build >= relV.build) return; || VERSION.patch >= relV.patch || VERSION.build >= relV.build) return;
if (relV.release.equals(Type.STABLE) || relV.release.equals(Type.LTS)) { if (relV.release.equals(Type.STABLE) || relV.release.equals(Type.LTS)) {
@ -68,9 +70,9 @@ public void run() {
private static Version parseVer(String relS) { private static Version parseVer(String relS) {
Matcher verMatcher = startingVerPattern.matcher(relS); Matcher verMatcher = startingVerPattern.matcher(relS);
if (!verMatcher.find()) return null; if (!verMatcher.find()) return VERSION;
String[] ver = pointPatternStriper.split(relS.substring(verMatcher.start(), verMatcher.end())); String[] ver = pointPatternStriper.split(relS.substring(verMatcher.start(), verMatcher.end()));
if (ver.length < 3) return null; if (ver.length < 3) return VERSION;
return new Version(Integer.parseInt(ver[0]), Integer.parseInt(ver[1]), return new Version(Integer.parseInt(ver[0]), Integer.parseInt(ver[1]),
Integer.parseInt(ver[2]), ver.length > 3 ? Integer.parseInt(ver[3]) : 0, findRelType(relS.substring(verMatcher.end()+1))); Integer.parseInt(ver[2]), ver.length > 3 ? Integer.parseInt(ver[3]) : 0, findRelType(relS.substring(verMatcher.end()+1)));
} }
@ -79,16 +81,11 @@ private static Type findRelType(String substring) {
if (substring.length() < 3 || substring.isEmpty()) return Type.UNKNOWN; if (substring.length() < 3 || substring.isEmpty()) return Type.UNKNOWN;
String tS = substring; String tS = substring;
if (tS.startsWith("-")) tS = tS.substring(1); if (tS.startsWith("-")) tS = tS.substring(1);
tS = tS.toUpperCase(Locale.ENGLISH); final String wrk = tS.toLowerCase(Locale.ENGLISH);
Type t = Type.UNKNOWN; final AtomicReference<Type> t = new AtomicReference<Type>(Type.UNKNOWN);
try { Type.unModTypes.forEach((s, type) -> {
t = Type.valueOf(tS); if (wrk.startsWith(s)) t.set(type);
} catch (Throwable ign) { // ignore it });
} return t.get();
return t;
}
public static void main(String[] args) {
System.out.println(parseVer("v3.4.5.6-stable").release);
} }
} }

View file

@ -2,6 +2,11 @@
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
public final class Version { public final class Version {
@ -68,34 +73,8 @@ public int hashCode() {
@LauncherAPI @LauncherAPI
public String getReleaseStatus() { public String getReleaseStatus() {
String result; if (release.equals(Type.UNKNOWN)) return "";
switch (release) { return release.name().toLowerCase(Locale.ENGLISH);
case LTS:
result = "lts";
break;
case STABLE:
result = "stable";
break;
case BETA:
result = "beta";
break;
case ALPHA:
result = "alpha";
break;
case DEV:
result = "dev";
break;
case EXPERIMENTAL:
result = "experimental";
break;
case UNKNOWN:
result = "";
break;
default:
result = "";
break;
}
return result;
} }
@Override @Override
@ -112,6 +91,13 @@ public enum Type {
ALPHA, ALPHA,
DEV, DEV,
EXPERIMENTAL, EXPERIMENTAL,
UNKNOWN UNKNOWN;
private static final Map<String, Type> types = new HashMap<>();
public static final Map<String, Type> unModTypes = Collections.unmodifiableMap(types);
static {
Arrays.asList(values()).stream().forEach(type -> types.put(type.name().substring(0, type.name().length() < 3 ? type.name().length() : 3), type));
}
} }
} }