]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3516 Recognize x.y.z-RCi versions(cherry picked from commit 328b6927d369b9872be...
authorDavid Gageot <david@gageot.net>
Wed, 20 Jun 2012 06:52:07 +0000 (08:52 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 20 Jun 2012 06:52:27 +0000 (08:52 +0200)
sonar-core/src/main/java/org/sonar/core/plugins/DefaultPluginMetadata.java
sonar-core/src/test/java/org/sonar/core/plugins/DefaultPluginMetadataTest.java

index 22ff29fadb955d42dd7fb4dd83f372addb3c4b7d..0d2df0524e8d3841592ee2b25e84a5072dfeadd5 100644 (file)
@@ -196,19 +196,27 @@ public class DefaultPluginMetadata implements PluginMetadata, Comparable<PluginM
       return true;
     }
 
+    // A version takes this form: x[.y][.z][-RCi|FCS|SNAPSHOT]
     return ComparisonChain.start()
-        .compare(part(sonarVersion, 0), part(this.sonarVersion, 0))
-        .compare(part(sonarVersion, 1), part(this.sonarVersion, 1))
-        .compare(part(sonarVersion, 2), part(this.sonarVersion, 2))
+        .compare(part(sonarVersion, 0), part(this.sonarVersion, 0)) // x
+        .compare(part(sonarVersion, 1), part(this.sonarVersion, 1)) // y
+        .compare(part(sonarVersion, 2), part(this.sonarVersion, 2)) // z
+        .compare(increment(sonarVersion), increment(this.sonarVersion)) // i
         .result() >= 0;
   }
 
   private static int part(String version, int index) {
-    Iterable<String> parts = Splitter.on('.').split(version);
+    Iterable<String> parts = Splitter.on('.').split(StringUtils.substringBefore(version, "-"));
     String part = Iterables.get(parts, index, "0");
-    String onlyDigits = CharMatcher.DIGIT.retainFrom(part);
 
-    return Integer.parseInt(onlyDigits);
+    return Integer.parseInt(part);
+  }
+
+  private static int increment(String version) {
+    String onlyDigits = CharMatcher.DIGIT.retainFrom(StringUtils.substringAfter(version, "-"));
+    String increment = StringUtils.defaultIfBlank(onlyDigits, "0");
+
+    return Integer.parseInt(increment);
   }
 
   public String getHomepage() {
index 02053827323b52f038142f357b15fdf9a010478b..5ac3f1dcc0ad64a5d8d3c4bb9f708c611505267f 100644 (file)
@@ -122,6 +122,11 @@ public class DefaultPluginMetadataTest {
     assertThat(pluginWithVersion("1.1-SNAPSHOT").isCompatibleWith("1.2")).isTrue();
     assertThat(pluginWithVersion("1.0.1-SNAPSHOT").isCompatibleWith("1.0")).isFalse();
 
+    assertThat(pluginWithVersion("3.1-RC2").isCompatibleWith("3.2-SNAPSHOT")).isTrue();
+    assertThat(pluginWithVersion("3.1-RC1").isCompatibleWith("3.2-RC2")).isTrue();
+    assertThat(pluginWithVersion("3.1-RC1").isCompatibleWith("3.1-RC2")).isTrue();
+    assertThat(pluginWithVersion("3.1-RC2").isCompatibleWith("3.1-RC1")).isFalse();
+
     assertThat(pluginWithVersion(null).isCompatibleWith("0")).isTrue();
     assertThat(pluginWithVersion(null).isCompatibleWith("3.1")).isTrue();
   }