*/
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;
*
* @parameter expression="${sonar.pluginKey}" default-value="${project.artifactId}"
*/
- private String pluginKey;
+ protected String pluginKey;
/**
* @parameter expression="${sonar.pluginTermsConditionsUrl}"
}
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;
}
--- /dev/null
+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"));
+ }
+
+}