From: simonbrandhof Date: Mon, 8 Nov 2010 13:38:15 +0000 (+0000) Subject: sonar-update-center subproject: add an integration test to test extraction of plugin... X-Git-Tag: 2.6~629 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a0172bcd669bc80265d35ba1033041c75e659c6d;p=sonarqube.git sonar-update-center subproject: add an integration test to test extraction of plugin key from maven artifact id --- diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/extractPluginKeyFromArtifactId/pom.xml b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/extractPluginKeyFromArtifactId/pom.xml new file mode 100644 index 00000000000..1ea50bd814c --- /dev/null +++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/extractPluginKeyFromArtifactId/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + org.codehaus.sonar + sonar-it-extract-plugin-key-plugin + 1.0 + sonar-plugin + Package dependencies + + + + org.codehaus.sonar + sonar-plugin-api + @sonar.version@ + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + true + + org.sonar.plugins.sample.SamplePlugin + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.1 + + + + diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/extractPluginKeyFromArtifactId/src/main/java/org/sonar/plugins/sample/SamplePlugin.java b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/extractPluginKeyFromArtifactId/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/extractPluginKeyFromArtifactId/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> getExtensions() { + return Collections.emptyList(); + } + + @Override + public String toString() { + return getKey(); + } +} diff --git a/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/extractPluginKeyFromArtifactId/verify.bsh b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/extractPluginKeyFromArtifactId/verify.bsh new file mode 100644 index 00000000000..683a784d2c7 --- /dev/null +++ b/subprojects/sonar-update-center/sonar-packaging-maven-plugin/src/it/extractPluginKeyFromArtifactId/verify.bsh @@ -0,0 +1,23 @@ +import java.io.*; +import java.util.zip.*; +import java.util.jar.Manifest; + +File file = new File( basedir, "target/sonar-it-extract-plugin-key-plugin-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("itextractpluginkey")) { + throw new Exception("Plugin key is not valid: " + key); + } +} finally { + zipFile.close(); + input.close(); +}