*/
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.
*/
private boolean useChildFirstClassLoader = false;
+ /**
+ * @parameter
+ */
+ private String extendPlugin;
+
/**
* @parameter expression="${sonar.skipDependenciesPackaging}"
*/
return useChildFirstClassLoader;
}
+ public String getExtendPlugin() {
+ return extendPlugin;
+ }
+
protected boolean isSkipDependenciesPackaging() {
return skipDependenciesPackaging;
}
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.
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<String> libs = copyDependencies();
- if ( !libs.isEmpty()) {
+ if (!libs.isEmpty()) {
archiver.getArchiver().addDirectory(getAppDirectory(), getIncludes(), getExcludes());
archive.addManifestEntry(PluginManifest.DEPENDENCIES, StringUtils.join(libs, " "));
}
}
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());
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")
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);
}
*/
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;
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 {
*/
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;
private Date buildDate;
private String issueTrackerUrl;
private boolean useChildFirstClassLoader = false;
+ private String extendPlugin;
/**
* Load the manifest from a JAR file.
}
/**
- * @param manifest
- * , can not be null
+ * @param manifest can not be null
*/
public PluginManifest(Manifest manifest) {
loadManifest(manifest);
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), ' ');
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();