aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojo.java9
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/test/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojoTest.java26
2 files changed, 34 insertions, 1 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 eae8defb9ed..3841ae85ccc 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,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
index 00000000000..a2412a26963
--- /dev/null
+++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/test/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojoTest.java
@@ -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"));
+ }
+
+}