diff --git a/arduino-core/lib/java-semver-0.8.0.jar b/arduino-core/lib/java-semver-0.8.0.jar new file mode 100644 index 000000000..967f0d154 Binary files /dev/null and b/arduino-core/lib/java-semver-0.8.0.jar differ diff --git a/arduino-core/lib/java-semver.LICENSE.MIT.txt b/arduino-core/lib/java-semver.LICENSE.MIT.txt new file mode 100644 index 000000000..e69de29bb diff --git a/arduino-core/src/cc/arduino/packages/contributions/VersionComparator.java b/arduino-core/src/cc/arduino/packages/contributions/VersionComparator.java index b23c66649..6fb742efa 100644 --- a/arduino-core/src/cc/arduino/packages/contributions/VersionComparator.java +++ b/arduino-core/src/cc/arduino/packages/contributions/VersionComparator.java @@ -28,6 +28,8 @@ */ package cc.arduino.packages.contributions; +import com.github.zafarkhaja.semver.Version; + import java.util.Comparator; public class VersionComparator implements Comparator { @@ -45,8 +47,23 @@ public class VersionComparator implements Comparator { if (b == null) return 1; - // TODO: do a proper version compare. Look also http://semver.org/ - return a.compareTo(b); + Version versionA = valueOf(a); + Version versionB = valueOf(b); + + return versionA.compareTo(versionB); + } + + private Version valueOf(String ver) { + String[] verParts = ver.split("\\."); + if (verParts.length < 3) { + if (verParts.length == 2) { + return Version.forIntegers(Integer.valueOf(verParts[0]), Integer.valueOf(verParts[1])); + } else { + return Version.forIntegers(Integer.valueOf(verParts[0])); + } + } else { + return Version.valueOf(ver); + } } }