aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/sonar-update-center/sonar-packaging-maven-plugin
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/sonar-update-center/sonar-packaging-maven-plugin')
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/pom.xml2
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/invoker.properties1
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/pom.xml39
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/src/main/java/org/sonar/plugins/sample/SamplePlugin.java30
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/pom.xml39
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/src/main/java/org/sonar/plugins/sample/SamplePlugin.java30
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/verify.bsh23
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/AbstractSonarPluginMojo.java6
-rw-r--r--subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/SonarPluginMojo.java19
9 files changed, 183 insertions, 6 deletions
diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/pom.xml b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/pom.xml
index 46ef99d0644..159667d3010 100644
--- a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/pom.xml
+++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/pom.xml
@@ -112,7 +112,7 @@
</goals>
<settingsFile>src/it/settings.xml</settingsFile>
<filterProperties>
- <sonar.version>2.3-SNAPSHOT</sonar.version>
+ <sonar.version>2.4-SNAPSHOT</sonar.version>
</filterProperties>
<!--<debug>true</debug>-->
</configuration>
diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/invoker.properties b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/invoker.properties
new file mode 100644
index 00000000000..c21e972fc6b
--- /dev/null
+++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/invoker.properties
@@ -0,0 +1 @@
+invoker.buildResult = failure
diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/pom.xml b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/pom.xml
new file mode 100644
index 00000000000..23055892a53
--- /dev/null
+++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0</version>
+ <packaging>sonar-plugin</packaging>
+ <name>Package dependencies</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ <version>@sonar.version@</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>@project.groupId@</groupId>
+ <artifactId>@project.artifactId@</artifactId>
+ <version>@project.version@</version>
+ <extensions>true</extensions>
+ <configuration>
+ <pluginKey>key-with.bad%characters</pluginKey>
+ <pluginClass>org.sonar.plugins.sample.SamplePlugin</pluginClass>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.1</version>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/src/main/java/org/sonar/plugins/sample/SamplePlugin.java b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/src/main/java/org/sonar/plugins/sample/SamplePlugin.java
new file mode 100644
index 00000000000..31710c3a0e6
--- /dev/null
+++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/failIfBadlyFormattedPluginKey/src/main/java/org/sonar/plugins/sample/SamplePlugin.java
@@ -0,0 +1,30 @@
+package org.sonar.plugins.sample;
+
+import org.sonar.api.Extension;
+import org.sonar.api.Plugin;
+
+import java.util.Collections;
+import java.util.List;
+
+public class SamplePlugin implements Plugin {
+ public String getKey() {
+ return "sample";
+ }
+
+ public String getName() {
+ return "My first Sonar plugin";
+ }
+
+ public String getDescription() {
+ return "You shouldn't expect too much from this plugin.";
+ }
+
+ public List<Class<? extends Extension>> getExtensions() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String toString() {
+ return getKey();
+ }
+}
diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/pom.xml b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/pom.xml
new file mode 100644
index 00000000000..71741bbcaac
--- /dev/null
+++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0</version>
+ <packaging>sonar-plugin</packaging>
+ <name>Package dependencies</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ <version>@sonar.version@</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>@project.groupId@</groupId>
+ <artifactId>@project.artifactId@</artifactId>
+ <version>@project.version@</version>
+ <extensions>true</extensions>
+ <configuration>
+ <pluginKey>newkey</pluginKey>
+ <pluginClass>org.sonar.plugins.sample.SamplePlugin</pluginClass>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.1</version>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/src/main/java/org/sonar/plugins/sample/SamplePlugin.java b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/src/main/java/org/sonar/plugins/sample/SamplePlugin.java
new file mode 100644
index 00000000000..31710c3a0e6
--- /dev/null
+++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/src/main/java/org/sonar/plugins/sample/SamplePlugin.java
@@ -0,0 +1,30 @@
+package org.sonar.plugins.sample;
+
+import org.sonar.api.Extension;
+import org.sonar.api.Plugin;
+
+import java.util.Collections;
+import java.util.List;
+
+public class SamplePlugin implements Plugin {
+ public String getKey() {
+ return "sample";
+ }
+
+ public String getName() {
+ return "My first Sonar plugin";
+ }
+
+ public String getDescription() {
+ return "You shouldn't expect too much from this plugin.";
+ }
+
+ public List<Class<? extends Extension>> getExtensions() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String toString() {
+ return getKey();
+ }
+}
diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/verify.bsh b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/verify.bsh
new file mode 100644
index 00000000000..416c8e1f5de
--- /dev/null
+++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/overridenPluginKey/verify.bsh
@@ -0,0 +1,23 @@
+import java.io.*;
+import java.util.zip.*;
+import java.util.jar.Manifest;
+
+File file = new File( basedir, "target/test-1.0.jar" );
+if ( !file.isFile() )
+{
+ throw new FileNotFoundException( "Could not find generated JAR: " + file );
+}
+
+ZipFile zipFile = new ZipFile(file);
+InputStream input = null;
+try {
+ input = zipFile.getInputStream(zipFile.getEntry("META-INF/MANIFEST.MF"));
+ Manifest manifest = new Manifest(input);
+ String key = manifest.getMainAttributes().getValue("Plugin-Key");
+ if (!key.equals("newkey")) {
+ throw new Exception("Plugin key is not valid: " + key);
+ }
+} finally {
+ zipFile.close();
+ input.close();
+}
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 eda6b943405..2908c45ad92 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
@@ -98,7 +98,7 @@ public abstract class AbstractSonarPluginMojo extends AbstractMojo {
/**
* Plugin key.
*
- * @parameter expression="${sonar.pluginKey}" default-value="${project.artifactId}"
+ * @parameter expression="${sonar.pluginKey}"
*/
protected String pluginKey;
@@ -173,8 +173,8 @@ public abstract class AbstractSonarPluginMojo extends AbstractMojo {
return classifier;
}
- public String getPluginKey() {
- return PluginKeyUtils.getPluginKey(pluginKey);
+ public String getExplicitPluginKey() {
+ return pluginKey;
}
protected final String getPluginClass() {
diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/SonarPluginMojo.java b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/SonarPluginMojo.java
index 4f32ae2fc34..494260d139c 100644
--- a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/SonarPluginMojo.java
+++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/main/java/org/sonar/updatecenter/mavenplugin/SonarPluginMojo.java
@@ -39,6 +39,7 @@ import org.apache.maven.shared.dependency.tree.traversal.BuildingDependencyNodeV
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.util.FileUtils;
import org.sonar.updatecenter.common.FormatUtils;
+import org.sonar.updatecenter.common.PluginKeyUtils;
import org.sonar.updatecenter.common.PluginManifest;
import java.io.File;
@@ -144,6 +145,9 @@ public class SonarPluginMojo extends AbstractSonarPluginMojo {
private boolean addMavenDescriptor = true;
public void execute() throws MojoExecutionException, MojoFailureException {
+ checkPluginKey();
+ checkPluginClass();
+
File jarFile = createArchive();
String classifier = getClassifier();
if (classifier != null) {
@@ -154,8 +158,6 @@ public class SonarPluginMojo extends AbstractSonarPluginMojo {
}
public File createArchive() throws MojoExecutionException {
- checkPluginClass();
-
File jarFile = getJarFile(getOutputDirectory(), getFinalName(), getClassifier());
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
@@ -236,12 +238,25 @@ public class SonarPluginMojo extends AbstractSonarPluginMojo {
return null;
}
+ private void checkPluginKey() throws MojoExecutionException {
+ if ( StringUtils.isNotBlank(getExplicitPluginKey()) && !PluginKeyUtils.isValid(getExplicitPluginKey())) {
+ throw new MojoExecutionException("Plugin key is badly formatted. Please use ascii letters and digits only. Value: " + getExplicitPluginKey());
+ }
+ }
+
private void checkPluginClass() throws MojoExecutionException {
if ( !new File(getClassesDirectory(), getPluginClass().replace('.', '/') + ".class").exists()) {
throw new MojoExecutionException("Error assembling Sonar-plugin: Plugin-Class '" + getPluginClass() + "' not found");
}
}
+ private String getPluginKey() {
+ if ( StringUtils.isNotBlank(getExplicitPluginKey())) {
+ return getExplicitPluginKey();
+ }
+ return PluginKeyUtils.sanitize(getProject().getArtifactId());
+ }
+
protected static File getJarFile(File basedir, String finalName, String classifier) {
if (classifier == null) {
classifier = "";