From: Godin Date: Mon, 27 Dec 2010 16:44:27 +0000 (+0000) Subject: SONAR-2078: Support new manifest entry "Extend-Plugin" X-Git-Tag: 2.6~216 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=35b414ba5736759960925bc06071a89342524f29;p=sonarqube.git SONAR-2078: Support new manifest entry "Extend-Plugin" --- 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 2908c45ad92..1ccbd835643 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,17 +19,16 @@ */ package org.sonar.updatecenter.mavenplugin; -import java.io.File; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; -import org.sonar.updatecenter.common.PluginKeyUtils; + +import java.io.File; +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * Base class for Sonar-plugin-packaging related tasks. @@ -141,6 +140,11 @@ public abstract class AbstractSonarPluginMojo extends AbstractMojo { */ private boolean useChildFirstClassLoader = false; + /** + * @parameter + */ + private String extendPlugin; + /** * @parameter expression="${sonar.skipDependenciesPackaging}" */ @@ -205,6 +209,10 @@ public abstract class AbstractSonarPluginMojo extends AbstractMojo { return useChildFirstClassLoader; } + public String getExtendPlugin() { + return extendPlugin; + } + protected boolean isSkipDependenciesPackaging() { return skipDependenciesPackaging; } 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 494260d139c..274c0d74b02 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 @@ -44,11 +44,7 @@ import org.sonar.updatecenter.common.PluginManifest; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * Build a Sonar Plugin from the current project. @@ -187,12 +183,16 @@ public class SonarPluginMojo extends AbstractSonarPluginMojo { archive.addManifestEntry(PluginManifest.USE_CHILD_FIRST_CLASSLOADER, "true"); } + if (StringUtils.isNotBlank(getExtendPlugin())) { + archive.addManifestEntry(PluginManifest.EXTEND_PLUGIN, getExtendPlugin()); + } + if (isSkipDependenciesPackaging()) { getLog().info("Skip packaging of dependencies"); } else { List libs = copyDependencies(); - if ( !libs.isEmpty()) { + if (!libs.isEmpty()) { archiver.getArchiver().addDirectory(getAppDirectory(), getIncludes(), getExcludes()); archive.addManifestEntry(PluginManifest.DEPENDENCIES, StringUtils.join(libs, " ")); } @@ -239,19 +239,19 @@ public class SonarPluginMojo extends AbstractSonarPluginMojo { } private void checkPluginKey() throws MojoExecutionException { - if ( StringUtils.isNotBlank(getExplicitPluginKey()) && !PluginKeyUtils.isValid(getExplicitPluginKey())) { + 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()) { + 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())) { + if (StringUtils.isNotBlank(getExplicitPluginKey())) { return getExplicitPluginKey(); } return PluginKeyUtils.sanitize(getProject().getArtifactId()); @@ -278,7 +278,7 @@ public class SonarPluginMojo extends AbstractSonarPluginMojo { ids.add(artifact.getDependencyConflictId()); } - if ( !ids.isEmpty()) { + if (!ids.isEmpty()) { getLog().info(getMessage("Following dependencies are packaged in the plugin:", ids)); getLog().info(new StringBuilder() .append("See following page for more details about plugin dependencies:\n") @@ -342,7 +342,7 @@ public class SonarPluginMojo extends AbstractSonarPluginMojo { sonarArtifacts.add(dependency.getArtifact()); } - if ( !Artifact.SCOPE_TEST.equals(dependency.getArtifact().getScope())) { + if (!Artifact.SCOPE_TEST.equals(dependency.getArtifact().getScope())) { for (Object childDep : dependency.getChildren()) { searchForSonarProvidedArtifacts((DependencyNode) childDep, sonarArtifacts, isProvidedBySonar); } diff --git a/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java b/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java index 5fc630a7dd5..c16ecace472 100644 --- a/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java +++ b/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java @@ -19,7 +19,8 @@ */ package org.sonar.updatecenter.common; -import static org.sonar.updatecenter.common.FormatUtils.toDate; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.builder.ReflectionToStringBuilder; import java.io.File; import java.io.IOException; @@ -28,13 +29,10 @@ import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; +import static org.sonar.updatecenter.common.FormatUtils.toDate; /** * This class loads Sonar plugin metadata from JAR manifest. - * - * @since 2.2 */ public final class PluginManifest { @@ -58,6 +56,11 @@ public final class PluginManifest { */ public static final String USE_CHILD_FIRST_CLASSLOADER = "Plugin-ChildFirstClassLoader"; + /** + * @since 1.1 + */ + public static final String EXTEND_PLUGIN = "Extend-Plugin"; + private String key; private String name; private String mainClass; @@ -73,6 +76,7 @@ public final class PluginManifest { private Date buildDate; private String issueTrackerUrl; private boolean useChildFirstClassLoader = false; + private String extendPlugin; /** * Load the manifest from a JAR file. @@ -94,8 +98,7 @@ public final class PluginManifest { } /** - * @param manifest - * , can not be null + * @param manifest can not be null */ public PluginManifest(Manifest manifest) { loadManifest(manifest); @@ -120,6 +123,7 @@ public final class PluginManifest { this.issueTrackerUrl = attributes.getValue(ISSUE_TRACKER_URL); this.buildDate = toDate(attributes.getValue(BUILD_DATE), true); this.useChildFirstClassLoader = StringUtils.equalsIgnoreCase(attributes.getValue(USE_CHILD_FIRST_CLASSLOADER), "true"); + this.extendPlugin = attributes.getValue(EXTEND_PLUGIN); String deps = attributes.getValue(DEPENDENCIES); this.dependencies = StringUtils.split(StringUtils.defaultString(deps), ' '); @@ -251,15 +255,36 @@ public final class PluginManifest { return this; } + /** + * @since 0.3 + */ public boolean isUseChildFirstClassLoader() { return useChildFirstClassLoader; } + /** + * @since 0.3 + */ public PluginManifest setUseChildFirstClassLoader(boolean useChildFirstClassLoader) { this.useChildFirstClassLoader = useChildFirstClassLoader; return this; } + /** + * @since 1.1 + */ + public String getExtendPlugin() { + return extendPlugin; + } + + /** + * @since 1.1 + */ + public PluginManifest setExtendPlugin(String extendPlugin) { + this.extendPlugin = extendPlugin; + return this; + } + @Override public String toString() { return new ReflectionToStringBuilder(this).toString();