From: David Gageot Date: Wed, 20 Jun 2012 06:52:07 +0000 (+0200) Subject: SONAR-3516 Recognize x.y.z-RCi versions(cherry picked from commit 328b6927d369b9872be... X-Git-Tag: 3.2~306 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f38e92da30408bef015e8296f83d28672cdaf85d;p=sonarqube.git SONAR-3516 Recognize x.y.z-RCi versions(cherry picked from commit 328b6927d369b9872beeda3bbd515c4337db46ec) --- diff --git a/sonar-core/src/main/java/org/sonar/core/plugins/DefaultPluginMetadata.java b/sonar-core/src/main/java/org/sonar/core/plugins/DefaultPluginMetadata.java index 22ff29fadb9..0d2df0524e8 100644 --- a/sonar-core/src/main/java/org/sonar/core/plugins/DefaultPluginMetadata.java +++ b/sonar-core/src/main/java/org/sonar/core/plugins/DefaultPluginMetadata.java @@ -196,19 +196,27 @@ public class DefaultPluginMetadata implements PluginMetadata, Comparable= 0; } private static int part(String version, int index) { - Iterable parts = Splitter.on('.').split(version); + Iterable 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() { diff --git a/sonar-core/src/test/java/org/sonar/core/plugins/DefaultPluginMetadataTest.java b/sonar-core/src/test/java/org/sonar/core/plugins/DefaultPluginMetadataTest.java index 02053827323..5ac3f1dcc0a 100644 --- a/sonar-core/src/test/java/org/sonar/core/plugins/DefaultPluginMetadataTest.java +++ b/sonar-core/src/test/java/org/sonar/core/plugins/DefaultPluginMetadataTest.java @@ -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(); }