diff options
author | Godin <mandrikov@gmail.com> | 2010-10-16 02:02:32 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-10-16 02:02:32 +0000 |
commit | 300f7336934c36d0624190985434a60ebbcc21d0 (patch) | |
tree | b63f187cb4efc17980a671274a9fd0470cceeceb /subprojects | |
parent | ab7b786eb2cf0c683641d33e7decf24ceca80ea6 (diff) | |
download | sonarqube-300f7336934c36d0624190985434a60ebbcc21d0.tar.gz sonarqube-300f7336934c36d0624190985434a60ebbcc21d0.zip |
SONAR-1868: sonar-packaging-maven-plugin - extract plugin key from artifact id
Diffstat (limited to 'subprojects')
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")); + } + +} |