VersionInfo { public static int compare(String str1, String str2) { String[] vals1 = normalizeVersion(str1).split("\\."); String[] vals2 = normalizeVersion(str2).split("\\."); int i = 0; while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { i++; } if (i < vals1.length && i < vals2.length) { if (vals1[i].isEmpty()) { vals1[i] = "0"; } if (vals2[i].isEmpty()) { vals2[i] = "0"; } int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i])); return Integer.signum(diff); } else { return Integer.signum(vals1.length - vals2.length); } } VersionInfo(Class<?> classInJar, String groupId, String artifactId, String gitPropertiesResource); String getVersion(); String getDate(); String getUser(); String getRevision(); String getBuildVersion(); static int compare(String str1, String str2); static boolean isCompatible(String thisVersion, String requiredVersion); @SuppressWarnings("UseOfSystemOutOrSystemErr") static void main(String[] args); static final VersionInfo APEX_VERSION; }
@Test public void testCompareVersion() { int c = VersionInfo.compare("1.0", "1.1"); Assert.assertTrue(c < 0); c = VersionInfo.compare("1.10", "1.2"); Assert.assertTrue(c > 0); c = VersionInfo.compare("1.0", "1.0"); Assert.assertTrue(c == 0); c = VersionInfo.compare("1.0-SNAPSHOT", "1.0"); Assert.assertTrue(c == 0); c = VersionInfo.compare("asdb", "1.0"); Assert.assertTrue(c < 0); }