From 80fa5ad89eda2d01a418770be23284ff9fb2df82 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 17 Jun 2005 08:44:39 +0000 Subject: [PATCH] - fix issues with source mojo - attach source artifact for install/deploy git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191113 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugins/maven-source-plugin/pom.xml | 10 ++++++++ .../maven/plugin/source/JarSourceMojo.java | 24 +++++++++++++++---- .../maven/plugin/source/SourceBundler.java | 18 +++++++------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/maven-plugins/maven-source-plugin/pom.xml b/maven-plugins/maven-source-plugin/pom.xml index 2e2395c7e9..76cfa1801d 100644 --- a/maven-plugins/maven-source-plugin/pom.xml +++ b/maven-plugins/maven-source-plugin/pom.xml @@ -21,5 +21,15 @@ 1.0-alpha-4-SNAPSHOT test + + org.apache.maven + maven-project + 2.0-SNAPSHOT + + + org.apache.maven + maven-artifact + 2.0-SNAPSHOT + diff --git a/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java b/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java index 801f70962c..01c93831fc 100644 --- a/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java +++ b/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java @@ -16,8 +16,11 @@ package org.apache.maven.plugin.source; * limitations under the License. */ +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.archiver.jar.JarArchiver; import java.io.File; @@ -35,11 +38,16 @@ public class JarSourceMojo extends AbstractMojo { /** - * @parameter expression="${project.version}" + * @parameter expression="${project}" * @readonly * @required */ - private String version; + private MavenProject project; + + /** + * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory} + */ + private ArtifactFactory artifactFactory; /** * @parameter expression="${project.build.finalName}" @@ -54,7 +62,7 @@ public class JarSourceMojo private List compileSourceRoots; /** - * @parameter expression="${project.build.outputDirectory}" + * @parameter expression="${project.build.directory}" * @required */ private File outputDirectory; @@ -63,7 +71,7 @@ public class JarSourceMojo throws MojoExecutionException { // TODO: this should be via a release profile instead - if ( version.indexOf( "SNAPSHOT" ) < 0 ) + if ( project.getVersion().indexOf( "SNAPSHOT" ) < 0 ) { // TODO: use a component lookup? JarArchiver archiver = new JarArchiver(); @@ -87,6 +95,14 @@ public class JarSourceMojo { throw new MojoExecutionException( "Error building source JAR", e ); } + + // TODO: these introduced dependencies on the project are going to become problematic - can we export it + // through metadata instead? + Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(), + project.getArtifactId(), + project.getVersion(), null, "java-source", + "sources" ); + project.addAttachedArtifact( artifact ); } else { diff --git a/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/SourceBundler.java b/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/SourceBundler.java index dd9b1fd5e7..0712792c42 100644 --- a/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/SourceBundler.java +++ b/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/SourceBundler.java @@ -1,23 +1,18 @@ package org.apache.maven.plugin.source; -import java.io.File; - import org.codehaus.plexus.archiver.Archiver; +import java.io.File; + /** * @author Trygve Laugstøl * @version $Id$ */ public class SourceBundler { - private final static String[] DEFAULT_INCLUDES = new String[]{ - "**/*", - }; + private final static String[] DEFAULT_INCLUDES = new String[]{"**/*",}; - private final static String[] DEFAULT_EXCLUDES = new String[]{ - "**/CVS/**", - "**/.svn/**", - }; + private final static String[] DEFAULT_EXCLUDES = new String[]{"**/CVS/**", "**/.svn/**",}; public void makeSourceBundle( File outputFile, File[] sourceDirectories, Archiver archiver ) throws Exception @@ -28,7 +23,10 @@ public class SourceBundler for ( int i = 0; i < sourceDirectories.length; i++ ) { - archiver.addDirectory( sourceDirectories[ i ], includes, excludes ); + if ( sourceDirectories[i].exists() ) + { + archiver.addDirectory( sourceDirectories[i], includes, excludes ); + } } archiver.setDestFile( outputFile );