From 8913a12ffbf80f6c11c75a0af93f94ede2282d8e Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 20 Jun 2012 11:35:52 +0200 Subject: [PATCH] SONAR-3516 Use common code to find version components --- .../core/plugins/DefaultPluginMetadata.java | 34 +++---------------- .../plugins/DefaultPluginMetadataTest.java | 2 +- 2 files changed, 6 insertions(+), 30 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 0d2df0524e8..fb9498bc0f8 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 @@ -19,15 +19,12 @@ */ package org.sonar.core.plugins; -import com.google.common.base.CharMatcher; -import com.google.common.base.Splitter; -import com.google.common.collect.ComparisonChain; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.platform.PluginMetadata; +import org.sonar.updatecenter.common.Version; import java.io.File; import java.util.List; @@ -86,7 +83,7 @@ public class DefaultPluginMetadata implements PluginMetadata, Comparable files) { - this.deprecatedExtensions = (files==null ? Lists.newArrayList() : files); + this.deprecatedExtensions = (files == null ? Lists. newArrayList() : files); return this; } @@ -192,31 +189,10 @@ public class DefaultPluginMetadata implements PluginMetadata, Comparable= 0; - } - - private static int part(String version, int index) { - Iterable parts = Splitter.on('.').split(StringUtils.substringBefore(version, "-")); - String part = Iterables.get(parts, index, "0"); - - 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); + Version minimumVersion = Version.create(this.sonarVersion); + Version actualVersion = Version.create(sonarVersion); + return actualVersion.compareTo(minimumVersion) >= 0; } 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 5ac3f1dcc0a..c2e34ec93b2 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 @@ -125,7 +125,7 @@ public class DefaultPluginMetadataTest { 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("3.1-RC2").isCompatibleWith("3.1-RC1")).isTrue(); assertThat(pluginWithVersion(null).isCompatibleWith("0")).isTrue(); assertThat(pluginWithVersion(null).isCompatibleWith("3.1")).isTrue(); -- 2.39.5