import source plugin

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@169839 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-05-12 15:59:36 +00:00
parent e186806889
commit f1ddecc967
10 changed files with 201 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-plugin-parent</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>maven-source-plugin</artifactId>
<version>2.0-alpha-1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>Maven Source Plug-In</name>
<dependencies>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>1.0-alpha-1</version>
</dependency>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<version>1.0-alpha-2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,81 @@
package org.apache.maven.plugin.source;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import java.io.File;
import java.util.Iterator;
import java.util.List;
/**
* This plugin bundles all the generated sources into a jar archive.
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$
* @goal jar
*/
public class JarSourceMojo
extends AbstractMojo
{
/**
* @parameter expression="${project.build.finalName}"
* @required
*/
private String finalName;
/**
* @parameter expression="${project.compileSourceRoots}"
* @required
*/
private List compileSourceRoots;
/**
* @parameter expression="${project.build.output}"
* @required
*/
private File outputDirectory;
public void execute()
throws MojoExecutionException
{
// TODO: use a component lookup?
JarArchiver archiver = new JarArchiver();
SourceBundler sourceBundler = new SourceBundler();
File outputFile = new File( outputDirectory, finalName + "-sources.jar" );
File[] sourceDirectories = new File[compileSourceRoots.size()];
int count = 0;
for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); count++ )
{
sourceDirectories[count] = new File( (String) i.next() );
}
try
{
sourceBundler.makeSourceBundle( outputFile, sourceDirectories, archiver );
}
catch ( Exception e )
{
throw new MojoExecutionException( "Error building source JAR", e );
}
}
}

View File

@ -0,0 +1,38 @@
package org.apache.maven.plugin.source;
import java.io.File;
import org.codehaus.plexus.archiver.Archiver;
/**
* @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_EXCLUDES = new String[]{
"**/CVS/**",
"**/.svn/**",
};
public void makeSourceBundle( File outputFile, File[] sourceDirectories, Archiver archiver )
throws Exception
{
String[] includes = DEFAULT_INCLUDES;
String[] excludes = DEFAULT_EXCLUDES;
for ( int i = 0; i < sourceDirectories.length; i++ )
{
archiver.addDirectory( sourceDirectories[ i ], includes, excludes );
}
archiver.setDestFile( outputFile );
archiver.createArchive();
}
}

View File

@ -0,0 +1,4 @@
<component-set>
<components>
</components>
</component-set>

View File

@ -0,0 +1,40 @@
package org.apache.maven.plugin.source;
import org.codehaus.plexus.PlexusTestCase;
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 SourceBundlerTest
extends PlexusTestCase
{
public void testNormalProject()
throws Exception
{
SourceBundler sourceBundler = new SourceBundler();
Archiver archiver = (Archiver) lookup( Archiver.ROLE, "jar" );
File outputFile = getTestFile( "target/source-bundler-test/normal.jar" );
File sourceDirectories[] = {
getTestFile( "src/test/projects/normal/src/main/java" ),
getTestFile( "src/test/projects/normal/src/main/resources" ),
getTestFile( "src/test/projects/normal/src/test/java" ),
getTestFile( "src/test/projects/normal/src/test/resources" ),
};
if ( outputFile.exists() )
{
assertTrue( "Could not delete output file: " + outputFile.getAbsolutePath(), outputFile.delete() );
}
sourceBundler.makeSourceBundle( outputFile, sourceDirectories, archiver );
assertTrue( "Missing output file: " + outputFile.getAbsolutePath(), outputFile.isFile() );
}
}

View File

@ -0,0 +1,7 @@
<model>
<modelVersion>4.0.0</modelVersion>
<groupId>mojo-test</groupId>
<artifactId>maven-sources-plugin-test-zip</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
</model>

View File

@ -0,0 +1,3 @@
public class App
{
}

View File

@ -0,0 +1,3 @@
public class Test
{
}