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() {
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();
}