2015-03-31 17:00:01 +02:00
|
|
|
package cc.arduino.contributions;
|
|
|
|
|
|
|
|
import com.github.zafarkhaja.semver.Version;
|
|
|
|
|
|
|
|
public class VersionHelper {
|
|
|
|
|
|
|
|
public static Version valueOf(String ver) {
|
|
|
|
if (ver == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-04-07 12:05:05 +02:00
|
|
|
try {
|
|
|
|
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]));
|
|
|
|
}
|
2015-03-31 17:00:01 +02:00
|
|
|
} else {
|
2015-04-07 12:05:05 +02:00
|
|
|
return Version.valueOf(ver);
|
2015-03-31 17:00:01 +02:00
|
|
|
}
|
2015-04-07 12:05:05 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
System.err.println("Invalid version found: " + ver);
|
|
|
|
return null;
|
2015-03-31 17:00:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|