]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1868: sonar-packaging-maven-plugin - extract plugin key from artifact id
authorGodin <mandrikov@gmail.com>
Sat, 16 Oct 2010 02:02:32 +0000 (02:02 +0000)
committerGodin <mandrikov@gmail.com>
Sat, 16 Oct 2010 02:02:32 +0000 (02:02 +0000)
subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojo.java
subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/test/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojoTest.java [new file with mode: 0644]

index eae8defb9ed1f6f486ae7084f93e13eb10e07588..3841ae85ccc64397178e69b59c6209e33f766608 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.updatecenter.mavenplugin;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.plugin.AbstractMojo;
@@ -98,7 +99,7 @@ public abstract class AbstractSonarPluginMojo extends AbstractMojo {
    * 
    * @parameter expression="${sonar.pluginKey}" default-value="${project.artifactId}"
    */
-  private String pluginKey;
+  protected String pluginKey;
 
   /**
    * @parameter expression="${sonar.pluginTermsConditionsUrl}"
@@ -172,6 +173,12 @@ 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 pluginKey;
   }
 
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
new file mode 100644 (file)
index 0000000..a2412a2
--- /dev/null
@@ -0,0 +1,26 @@
+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"));
+  }
+
+}