Skip to content

Commit

Permalink
Parse snapshot version strings correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
LunNova committed Jun 22, 2016
1 parent b03eb43 commit c8c274d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/me/nallar/modpatcher/ModPatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,16 @@ static class Version implements Comparable<Version> {
public static final Version LATEST = new Version(String.valueOf(Integer.MAX_VALUE));
public static final Version NONE = new Version("0");
private String version;
private boolean snapshot;

private Version(String version) {
if (version == null)
throw new IllegalArgumentException("Version can not be null");
version = version.trim();
if (version.endsWith("-SNAPSHOT")) {
version = version.replace("-SNAPSHOT", "");
snapshot = true;
}
if (!version.matches("[0-9]+(\\.[0-9]+)*"))
throw new IllegalArgumentException("Invalid version format. Should consist entirely of digits and dots. Got '" + version + "'");
this.version = version;
Expand Down Expand Up @@ -387,7 +392,7 @@ public int compareTo(Version that) {
return 1;
}

return 0;
return this.snapshot == that.snapshot ? 0 : (this.snapshot ? 1 : -1);
}

@Override
Expand Down

0 comments on commit c8c274d

Please sign in to comment.