Skip to content

Commit 0489585

Browse files
author
Federico Fissore
committed
Now using semantic versioning
1 parent d8ef278 commit 0489585

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed
43.7 KB
Binary file not shown.

arduino-core/lib/java-semver.LICENSE.MIT.txt

Whitespace-only changes.

arduino-core/src/cc/arduino/packages/contributions/VersionComparator.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
package cc.arduino.packages.contributions;
3030

31+
import com.github.zafarkhaja.semver.Version;
32+
3133
import java.util.Comparator;
3234

3335
public class VersionComparator implements Comparator<String> {
@@ -45,8 +47,23 @@ public int compare(String a, String b) {
4547
if (b == null)
4648
return 1;
4749

48-
// TODO: do a proper version compare. Look also http://semver.org/
49-
return a.compareTo(b);
50+
Version versionA = valueOf(a);
51+
Version versionB = valueOf(b);
52+
53+
return versionA.compareTo(versionB);
54+
}
55+
56+
private Version valueOf(String ver) {
57+
String[] verParts = ver.split("\\.");
58+
if (verParts.length < 3) {
59+
if (verParts.length == 2) {
60+
return Version.forIntegers(Integer.valueOf(verParts[0]), Integer.valueOf(verParts[1]));
61+
} else {
62+
return Version.forIntegers(Integer.valueOf(verParts[0]));
63+
}
64+
} else {
65+
return Version.valueOf(ver);
66+
}
5067
}
5168

5269
}

0 commit comments

Comments
 (0)