From 9f8c7e326a9bcdc9c2873de967835c6b3bfaa665 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Tue, 4 Oct 2005 05:43:58 +0000 Subject: [PATCH] PR: MNG-816 allow attachment of another jar during the build process git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@293542 13f79535-47bb-0310-9956-ffa450edef68 --- maven-model/pom.xml | 15 +++++- .../maven/plugin/jar/AbstractJarMojo.java | 47 ++++++++++++++----- .../org/apache/maven/plugin/jar/JarMojo.java | 13 +++-- .../apache/maven/plugin/jar/TestJarMojo.java | 20 -------- 4 files changed, 55 insertions(+), 40 deletions(-) diff --git a/maven-model/pom.xml b/maven-model/pom.xml index 2d27816e9c..729c6d4cc5 100644 --- a/maven-model/pom.xml +++ b/maven-model/pom.xml @@ -36,7 +36,6 @@ all-models - ${pom.artifactId}-${pom.version}-all org.codehaus.modello @@ -57,6 +56,20 @@ + + maven-jar-plugin + + + package + + all + + + jar + + + + diff --git a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java index 6119d02b98..a2470402b0 100644 --- a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java +++ b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java @@ -21,13 +21,14 @@ import org.apache.maven.archiver.MavenArchiver; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.archiver.jar.JarArchiver; import java.io.File; /** * Base class for creating a jar from project classes. - * + * * @author Emmanuel Venisse * @version $Id$ */ @@ -45,7 +46,6 @@ public abstract class AbstractJarMojo * @parameter expression="${project.build.directory}" * @required * @readonly - * * @todo Change type to File */ private String basedir; @@ -81,24 +81,26 @@ public abstract class AbstractJarMojo * @parameter */ private MavenArchiveConfiguration archive = new MavenArchiveConfiguration(); - + + /** + * @component + */ + private MavenProjectHelper projectHelper; + /** * Return the specific output directory to serve as the root for the archive. */ protected abstract File getOutputDirectory(); - + protected final MavenProject getProject() { return project; } - + /** * Overload this to produce a test-jar, for example. */ - protected String getClassifier() - { - return ""; - } + protected abstract String getClassifier(); /** * Generates the JAR. @@ -109,7 +111,7 @@ public abstract class AbstractJarMojo throws MojoExecutionException { String classifier = getClassifier(); - + if ( classifier == null ) { classifier = ""; @@ -118,7 +120,7 @@ public abstract class AbstractJarMojo { classifier = "-" + classifier; } - + File jarFile = new File( basedir, finalName + classifier + ".jar" ); MavenArchiver archiver = new MavenArchiver(); @@ -140,7 +142,7 @@ public abstract class AbstractJarMojo } archiver.createArchive( project, archive ); - + return jarFile; } catch ( Exception e ) @@ -149,4 +151,25 @@ public abstract class AbstractJarMojo throw new MojoExecutionException( "Error assembling JAR", e ); } } + + /** + * Generates the JAR. + * + * @todo Add license files in META-INF directory. + */ + public void execute() + throws MojoExecutionException + { + File jarFile = createArchive(); + + String classifier = getClassifier(); + if ( classifier != null ) + { + projectHelper.attachArtifact( getProject(), "jar", classifier, jarFile ); + } + else + { + getProject().getArtifact().setFile( jarFile ); + } + } } diff --git a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java index 00bdd96c26..1a31198cef 100644 --- a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java +++ b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java @@ -42,16 +42,15 @@ public class JarMojo private File outputDirectory; /** - * Generates the JAR. + * Classifier to add to the artifact generated. If given, the artifact will be an attachment instead. * - * @todo Add license files in META-INF directory. + * @parameter */ - public void execute() - throws MojoExecutionException + private String classifier; + + protected String getClassifier() { - File jarFile = createArchive(); - - getProject().getArtifact().setFile( jarFile ); + return classifier; } /** diff --git a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/TestJarMojo.java b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/TestJarMojo.java index d17c7a572d..34adbaa513 100644 --- a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/TestJarMojo.java +++ b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/TestJarMojo.java @@ -42,31 +42,11 @@ public class TestJarMojo */ private File testOutputDirectory; - /** - * @component role="org.apache.maven.project.MavenProjectHelper" - */ - private MavenProjectHelper projectHelper; - protected String getClassifier() { return "tests"; } - /** - * Generates the JAR. - * - * @todo Add license files in META-INF directory. - */ - public void execute() - throws MojoExecutionException - { - getLog().info( "Creating a jar containing the test classes for this project." ); - - File jarFile = createArchive(); - - projectHelper.attachArtifact( getProject(), "jar", "tests", jarFile ); - } - /** * Return the test-classes directory, to serve as the root of the tests jar. */