3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

SemVer compatibility, also change up the messages a bit.

Dieser Commit ist enthalten in:
Myles 2016-08-20 13:47:09 +01:00
Ursprung ed311e4059
Commit f159a2250c
2 geänderte Dateien mit 31 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -82,14 +82,18 @@ public class UpdateUtil {
try {
current = new Version(ViaVersion.getInstance().getVersion());
} catch (IllegalArgumentException e) {
return "You are using a debug/custom version, consider updating.";
return "You are using a custom version, consider updating.";
}
Version newest = new Version(newestString);
if (current.compareTo(newest) < 0)
return "There is a newer version available: " + newest.toString();
return "There is a newer version available: " + newest.toString() + ", you're on: " + current.toString();
else if (console && current.compareTo(newest) != 0) {
if (current.getTag().toLowerCase().startsWith("dev") || current.getTag().toLowerCase().startsWith("snapshot")) {
return "You are running a development version, please report any bugs to GitHub.";
} else {
return "You are running a newer version than is released!";
}
}
return null;
}

Datei anzeigen

@ -2,21 +2,26 @@ package us.myles.ViaVersion.update;
import org.apache.commons.lang.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Version implements Comparable<Version> {
private int[] parts;
private static Pattern semVer = Pattern.compile("(?<a>0|[1-9]\\d*)\\.(?<b>0|[1-9]\\d*)(?:\\.(?<c>0|[1-9]\\d*))?(?:-(?<tag>[A-z0-9.-]*))?");
private int[] parts = new int[3];
private String tag;
public Version(String value) {
if (value == null)
throw new IllegalArgumentException("Version can not be null");
if (!value.matches("^[0-9]+(\\.[0-9]+)*$"))
Matcher matcher = semVer.matcher(value);
if (!matcher.matches())
throw new IllegalArgumentException("Invalid version format");
parts[0] = Integer.parseInt(matcher.group("a"));
parts[1] = Integer.parseInt(matcher.group("b"));
parts[2] = matcher.group("c") == null ? 0 : Integer.parseInt(matcher.group("c"));
String[] split = value.split("\\.");
parts = new int[split.length];
for (int i = 0; i < split.length; i += 1)
parts[i] = Integer.parseInt(split[i]);
tag = matcher.group("tag") == null ? "" : matcher.group("tag");
}
public static int compare(Version verA, Version verB) {
@ -33,6 +38,12 @@ public class Version implements Comparable<Version> {
if (partA > partB) return 1;
}
// Simple tag check
if (verA.tag.length() == 0 && verB.tag.length() > 0)
return 1;
if (verA.tag.length() > 0 && verB.tag.length() == 0)
return -1;
return 0;
}
@ -47,7 +58,7 @@ public class Version implements Comparable<Version> {
for (int i = 0; i < parts.length; i += 1)
split[i] = String.valueOf(parts[i]);
return StringUtils.join(split, ".");
return StringUtils.join(split, ".") + (tag.length() != 0 ? "-" + tag : "");
}
@Override
@ -59,4 +70,8 @@ public class Version implements Comparable<Version> {
public boolean equals(Object that) {
return that instanceof Version && equals(this, (Version) that);
}
public String getTag() {
return tag;
}
}