- 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
This commit is contained in:
Brett Leslie Porter 2005-06-17 08:44:39 +00:00
parent fb065d7858
commit 80fa5ad89e
3 changed files with 38 additions and 14 deletions

View File

@ -21,5 +21,15 @@
<version>1.0-alpha-4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -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
{

View File

@ -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 <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @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 );