diff options
Diffstat (limited to 'subprojects')
5 files changed, 57 insertions, 70 deletions
diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojo.java b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojo.java index fd3d4252ab0..eda6b943405 100644 --- a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojo.java +++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojo.java @@ -19,17 +19,17 @@ */ package org.sonar.updatecenter.mavenplugin; -import org.apache.commons.lang.StringUtils; +import java.io.File; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; - -import java.io.File; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import org.sonar.updatecenter.common.PluginKeyUtils; /** * Base class for Sonar-plugin-packaging related tasks. @@ -37,6 +37,7 @@ import java.util.Set; * @author Evgeny Mandrikov */ public abstract class AbstractSonarPluginMojo extends AbstractMojo { + public static final String SONAR_GROUPID = "org.codehaus.sonar"; public static final String SONAR_PLUGIN_API_ARTIFACTID = "sonar-plugin-api"; public static final String SONAR_PLUGIN_API_TYPE = "jar"; @@ -173,13 +174,7 @@ public abstract class AbstractSonarPluginMojo extends AbstractMojo { } public String getPluginKey() { - if (StringUtils.startsWith(pluginKey, "sonar-") && StringUtils.endsWith(pluginKey, "-plugin")) { - return StringUtils.removeEnd(StringUtils.removeStart(pluginKey, "sonar-"), "-plugin"); - } - if (StringUtils.endsWith(pluginKey, "-sonar-plugin")) { - return StringUtils.removeEnd(pluginKey, "-sonar-plugin"); - } - return StringUtils.remove(pluginKey, "-"); + return PluginKeyUtils.getPluginKey(pluginKey); } protected final String getPluginClass() { @@ -214,7 +209,7 @@ public abstract class AbstractSonarPluginMojo extends AbstractMojo { return skipDependenciesPackaging; } - @SuppressWarnings( { "unchecked" }) + @SuppressWarnings({ "unchecked" }) protected Set<Artifact> getDependencyArtifacts() { return getProject().getDependencyArtifacts(); } @@ -229,7 +224,7 @@ public abstract class AbstractSonarPluginMojo extends AbstractMojo { return result; } - @SuppressWarnings( { "unchecked" }) + @SuppressWarnings({ "unchecked" }) protected Set<Artifact> getIncludedArtifacts() { Set<Artifact> result = new HashSet<Artifact>(); Set<Artifact> artifacts = getProject().getArtifacts(); @@ -246,8 +241,7 @@ public abstract class AbstractSonarPluginMojo extends AbstractMojo { Set<Artifact> dependencies = getDependencyArtifacts(); if (dependencies != null) { for (Artifact dep : dependencies) { - if (SONAR_GROUPID.equals(dep.getGroupId()) - && SONAR_PLUGIN_API_ARTIFACTID.equals(dep.getArtifactId()) + if (SONAR_GROUPID.equals(dep.getGroupId()) && SONAR_PLUGIN_API_ARTIFACTID.equals(dep.getArtifactId()) && SONAR_PLUGIN_API_TYPE.equals(dep.getType())) { return dep; } diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/test/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojoTest.java b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/test/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojoTest.java deleted file mode 100644 index 27f8acfb396..00000000000 --- a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/test/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojoTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.updatecenter.mavenplugin; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.junit.Test; - -public class AbstractSonarPluginMojoTest { - - @Test - public void shouldExtractPluginKeyFromArtifactId() { - AbstractSonarPluginMojo mojo = new AbstractSonarPluginMojo() { - public void execute() throws MojoExecutionException, MojoFailureException { - } - }; - mojo.pluginKey = "sonar-test-plugin"; - assertThat(mojo.getPluginKey(), is("test")); - mojo.pluginKey = "test-sonar-plugin"; - assertThat(mojo.getPluginKey(), is("test")); - mojo.pluginKey = "test"; - assertThat(mojo.getPluginKey(), is("test")); - mojo.pluginKey = "test-foo"; - assertThat(mojo.getPluginKey(), is("testfoo")); - - } - -} diff --git a/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginKeyUtils.java b/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginKeyUtils.java new file mode 100644 index 00000000000..3978cac2831 --- /dev/null +++ b/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginKeyUtils.java @@ -0,0 +1,20 @@ +package org.sonar.updatecenter.common; + +import org.apache.commons.lang.StringUtils; + +public final class PluginKeyUtils { + + public static String getPluginKey(String pluginKey) { + String key = pluginKey; + if (StringUtils.startsWith(pluginKey, "sonar-") && StringUtils.endsWith(pluginKey, "-plugin")) { + key = StringUtils.removeEnd(StringUtils.removeStart(pluginKey, "sonar-"), "-plugin"); + } else if (StringUtils.endsWith(pluginKey, "-sonar-plugin")) { + key = StringUtils.removeEnd(pluginKey, "-sonar-plugin"); + } + return StringUtils.remove(key, "-"); + } + + private PluginKeyUtils() { + } + +} diff --git a/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java b/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java index 4934978abba..ed86cf52a96 100644 --- a/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java +++ b/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java @@ -19,8 +19,7 @@ */ package org.sonar.updatecenter.common; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; +import static org.sonar.updatecenter.common.FormatUtils.toDate; import java.io.File; import java.io.IOException; @@ -29,7 +28,8 @@ import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; -import static org.sonar.updatecenter.common.FormatUtils.toDate; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.builder.ReflectionToStringBuilder; /** * This class loads Sonar plugin metadata from JAR manifest. @@ -94,7 +94,8 @@ public final class PluginManifest { } /** - * @param manifest, can not be null + * @param manifest + * , can not be null */ public PluginManifest(Manifest manifest) { loadManifest(manifest); @@ -105,7 +106,7 @@ public final class PluginManifest { private void loadManifest(Manifest manifest) { Attributes attributes = manifest.getMainAttributes(); - this.key = attributes.getValue(KEY); + this.key = PluginKeyUtils.getPluginKey(attributes.getValue(KEY)); this.mainClass = attributes.getValue(MAIN_CLASS); this.name = attributes.getValue(NAME); this.description = attributes.getValue(DESCRIPTION); diff --git a/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/PluginKeyUtilsTest.java b/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/PluginKeyUtilsTest.java new file mode 100644 index 00000000000..1e9e646344a --- /dev/null +++ b/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/PluginKeyUtilsTest.java @@ -0,0 +1,20 @@ +package org.sonar.updatecenter.common; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import org.junit.Test; + +public class PluginKeyUtilsTest { + + @Test + public void shouldExtractCorrectPluginKey() { + assertThat(PluginKeyUtils.getPluginKey("sonar-test-plugin"), is("test")); + assertThat(PluginKeyUtils.getPluginKey("test-sonar-plugin"), is("test")); + assertThat(PluginKeyUtils.getPluginKey("test"), is("test")); + + assertThat(PluginKeyUtils.getPluginKey("sonar-test-foo-plugin"), is("testfoo")); + assertThat(PluginKeyUtils.getPluginKey("test-foo-sonar-plugin"), is("testfoo")); + assertThat(PluginKeyUtils.getPluginKey("test-foo"), is("testfoo")); + } +} |