diff options
author | David Gageot <david@gageot.net> | 2012-06-20 08:52:07 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-06-20 08:52:27 +0200 |
commit | f38e92da30408bef015e8296f83d28672cdaf85d (patch) | |
tree | d358c7bf6150c7b344e9582baef795c273708f22 /sonar-core/src | |
parent | 061451b53d8a8fc2e3f4716705d6c6a28689baa8 (diff) | |
download | sonarqube-f38e92da30408bef015e8296f83d28672cdaf85d.tar.gz sonarqube-f38e92da30408bef015e8296f83d28672cdaf85d.zip |
SONAR-3516 Recognize x.y.z-RCi versions(cherry picked from commit 328b6927d369b9872beeda3bbd515c4337db46ec)
Diffstat (limited to 'sonar-core/src')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/plugins/DefaultPluginMetadata.java | 20 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/plugins/DefaultPluginMetadataTest.java | 5 |
2 files changed, 19 insertions, 6 deletions
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<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() { 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(); } |