Verified Commit 04f940c5 authored by Daniel Mangold's avatar Daniel Mangold
Browse files

Switched to Semantic Versioning

parent 940b9152
......@@ -208,7 +208,7 @@ public class Utils {
Version localVersion = new Version(LOCAL_VERSION),
remoteVersion = new Version(remoteReader.readLine());
if (remoteVersion.isNewerThan(localVersion)) {
if (remoteVersion.compareTo(localVersion) > 0) {
System.out.println("Update available! Local version: " + localVersion + " -- Remote version: " + remoteVersion);
System.out.println("Changelog: " + REPOSITORY_URL + "blob/master/changelog.md");
} else
......@@ -216,7 +216,7 @@ public class Utils {
for (
String line = remoteReader.readLine();
(CHECK_HASHES || (AUTO_UPDATE && remoteVersion.isNewerThan(localVersion))) && line != null && line.length() != 0;
(CHECK_HASHES || (AUTO_UPDATE && remoteVersion.compareTo(localVersion) > 0)) && line != null && line.length() != 0;
line = remoteReader.readLine()
) {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
......@@ -299,29 +299,35 @@ public class Utils {
System.out.println("unable to fetch file from repository");
}
private static class Version {
private static class Version implements Comparable<Version> {
private final Integer MAJOR_VERSION, MINOR_VERSION;
private final int MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION;
private Version(String version) {
String[] versions = version.split("\\.");
MAJOR_VERSION = Integer.parseInt(versions[0]);
MINOR_VERSION = Integer.parseInt(versions[1]);
PATCH_VERSION = Integer.parseInt(versions[2]);
}
/**
* Returns whether this Version is newer (higher version number) than the given one
* @param version the Version object to compare to
* @return {@code true} if this Version object is newer, {@code false} otherwise
*/
private boolean isNewerThan(Version version) {
return MAJOR_VERSION > version.MAJOR_VERSION || (MAJOR_VERSION.equals(version.MAJOR_VERSION) && MINOR_VERSION > version.MINOR_VERSION);
@Override
public int compareTo(Version version) {
int versionDiffMajor = MAJOR_VERSION - version.MAJOR_VERSION,
versionDiffMinor = MINOR_VERSION - version.MINOR_VERSION,
versionDiffPatch = PATCH_VERSION - version.PATCH_VERSION;
if (versionDiffMajor != 0)
return versionDiffMajor;
else if (versionDiffMinor != 0)
return versionDiffMinor;
else
return versionDiffPatch;
}
@Override
public String toString() {
return MAJOR_VERSION + "." + MINOR_VERSION;
return MAJOR_VERSION + "." + MINOR_VERSION + "." + PATCH_VERSION;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment