Author: brett
Date: Wed Mar 29 01:28:08 2006
New Revision: 389724
URL: http://svn.apache.org/viewcvs?rev=389724&view=rev
Log:
- fix regression in POM handling
- general clean up
Modified:
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractJarSourceMojo.java
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarDefaultSourceMojo.java
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarTestSourceMojo.java
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/SourceBundler.java
Modified:
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractJarSourceMojo.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractJarSourceMojo.java?rev=389724&r1=389723&r2=389724&view=diff
==============================================================================
---
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractJarSourceMojo.java
(original)
+++
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractJarSourceMojo.java
Wed Mar 29 01:28:08 2006
@@ -22,9 +22,10 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
import java.io.File;
-import java.util.ArrayList;
+import java.io.IOException;
import java.util.Iterator;
import java.util.List;
@@ -32,20 +33,6 @@
extends AbstractMojo
{
/**
- * @deprecated ICK! This needs to be generalized OUTSIDE of this mojo!
- */
- private static final List BANNED_PACKAGINGS;
-
- static
- {
- List banned = new ArrayList();
-
- banned.add( "pom" );
-
- BANNED_PACKAGINGS = banned;
- }
-
- /**
* @parameter expression="${project}"
* @readonly
* @required
@@ -57,7 +44,7 @@
* @readonly
* @required
*/
- private String packaging;
+ protected String packaging;
/**
* @parameter expression="${executedProject}"
@@ -71,11 +58,21 @@
private boolean attach = true;
/**
- * @parameter
expression="${component.org.apache.maven.project.MavenProjectHelper}
+ * @component
*/
private MavenProjectHelper projectHelper;
- private static SourceBundler sourceBundler;
+ /**
+ * @parameter expression="${project.build.directory}"
+ * @required
+ */
+ protected File outputDirectory;
+
+ /**
+ * @parameter expression="${project.build.finalName}"
+ * @required
+ */
+ protected String finalName;
public abstract void execute()
throws MojoExecutionException;
@@ -110,16 +107,6 @@
this.executedProject = executedProject;
}
- protected void validatePackaging()
- {
- if ( BANNED_PACKAGINGS.contains( packaging ) )
- {
- getLog().info( "NOT adding java-sources to attached artifacts for
packaging: \'" + packaging + "\'." );
-
- return;
- }
- }
-
/**
* Add the compile source directories and resource directories that will
be included in the jar file
*
@@ -131,15 +118,17 @@
protected File[] addDirectories( List compileSourceRoots, List resources,
File[] sourceDirectories )
{
int count = 0;
- for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); count++
)
+ for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); )
{
sourceDirectories[count] = new File( (String) i.next() );
+ count++;
}
- for ( Iterator i = resources.iterator(); i.hasNext(); count++ )
+ for ( Iterator i = resources.iterator(); i.hasNext(); )
{
Resource resource = (Resource) i.next();
sourceDirectories[count] = new File( resource.getDirectory() );
+ count++;
}
return sourceDirectories;
@@ -152,8 +141,8 @@
*/
protected File[] getTestSources()
{
- List testCompileSourceRoots =
getExecutedProject().getTestCompileSourceRoots();
- List testResources = getExecutedProject().getTestResources();
+ List testCompileSourceRoots =
executedProject.getTestCompileSourceRoots();
+ List testResources = executedProject.getTestResources();
File[] testSourceDirectories = new File[testCompileSourceRoots.size()
+ testResources.size()];
testSourceDirectories = addDirectories( testCompileSourceRoots,
testResources, testSourceDirectories );
@@ -182,15 +171,11 @@
*
* @param outputFile the file name of the jar
* @param sourceDirectories the source directories that will be included
in the jar file
- * @throws Exception
*/
protected void createJar( File outputFile, File[] sourceDirectories,
Archiver archiver )
- throws Exception
+ throws IOException, ArchiverException
{
- if ( sourceBundler == null )
- {
- sourceBundler = new SourceBundler();
- }
+ SourceBundler sourceBundler = new SourceBundler();
sourceBundler.makeSourceBundle( outputFile, sourceDirectories,
archiver );
}
@@ -209,7 +194,7 @@
{
// TODO: these introduced dependencies on the project are going to
become problematic - can we export it
// through metadata instead?
- projectHelper.attachArtifact( getProject(), "java-source",
"sources", outputFile );
+ projectHelper.attachArtifact( project, "java-source", "sources",
outputFile );
}
}
Modified:
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarDefaultSourceMojo.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarDefaultSourceMojo.java?rev=389724&r1=389723&r2=389724&view=diff
==============================================================================
---
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarDefaultSourceMojo.java
(original)
+++
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarDefaultSourceMojo.java
Wed Mar 29 01:28:08 2006
@@ -17,9 +17,11 @@
*/
import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import java.io.File;
+import java.io.IOException;
/**
* This plugin bundles all the generated sources into a jar archive.
@@ -33,57 +35,33 @@
public class JarDefaultSourceMojo
extends AbstractJarSourceMojo
{
- /**
- * @parameter expression="${project.build.finalName}"
- * @required
- */
- private String finalName;
-
- /**
- * @parameter expression="${project.build.directory}"
- * @required
- */
- private File outputDirectory;
-
- /**
- * @parameter expression="${includeTestSources}" default="false"
- */
- private boolean includeTestSources;
-
public void execute()
throws MojoExecutionException
{
-
- validatePackaging();
-
- File outputFile = new File( outputDirectory, finalName +
"-sources.jar" );
- File[] sourceDirectories = getDefaultSources();
-
- try
+ if ( "pom".equals( packaging ) )
{
- createJar( outputFile, sourceDirectories, new JarArchiver() );
+ getLog().info( "NOT adding sources to attached artifacts for
packaging: \'" + packaging + "\'." );
}
- catch ( Exception e )
+ else
{
- throw new MojoExecutionException( "Error building source JAR", e );
- }
-
- if ( includeTestSources )
- {
- outputFile = new File( outputDirectory, finalName +
"-test-sources.jar" );
- File[] testSourceDirectories = getTestSources();
+ File outputFile = new File( outputDirectory, finalName +
"-sources.jar" );
+ File[] sourceDirectories = getDefaultSources();
try
{
- createJar( outputFile, testSourceDirectories, new
JarArchiver() );
+ createJar( outputFile, sourceDirectories, new JarArchiver() );
}
- catch ( Exception e )
+ catch ( IOException e )
{
- throw new MojoExecutionException( "Error building test source
JAR", e );
+ throw new MojoExecutionException( "Error creating source
archive: " + e.getMessage(), e );
+ }
+ catch ( ArchiverException e )
+ {
+ throw new MojoExecutionException( "Error creating source
archive: " + e.getMessage(), e );
}
- }
- attachArtifact( outputFile );
+ attachArtifact( outputFile );
+ }
}
}
Modified:
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarTestSourceMojo.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarTestSourceMojo.java?rev=389724&r1=389723&r2=389724&view=diff
==============================================================================
---
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarTestSourceMojo.java
(original)
+++
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarTestSourceMojo.java
Wed Mar 29 01:28:08 2006
@@ -17,9 +17,11 @@
*/
import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import java.io.File;
+import java.io.IOException;
/**
* This plugin bundles all the generated test sources into a jar archive.
@@ -31,35 +33,33 @@
public class JarTestSourceMojo
extends AbstractJarSourceMojo
{
- /**
- * @parameter expression="${project.build.finalName}"
- * @required
- */
- private String finalName;
-
- /**
- * @parameter expression="${project.build.directory}"
- * @required
- */
- private File outputDirectory;
-
public void execute()
throws MojoExecutionException
{
- validatePackaging();
- File outputFile = new File( outputDirectory, finalName +
"-test-sources.jar" );
- File[] testSourceDirectories = getTestSources();
-
- try
+ if ( "pom".equals( packaging ) )
{
- createJar( outputFile, testSourceDirectories, new JarArchiver() );
+ getLog().info( "NOT adding test sources to attached artifacts for
packaging: \'" + packaging + "\'." );
}
- catch ( Exception e )
+ else
{
- throw new MojoExecutionException( "Error building test source
JAR", e );
- }
+ File outputFile = new File( outputDirectory, finalName +
"-test-sources.jar" );
+ File[] testSourceDirectories = getTestSources();
+
+ try
+ {
+ createJar( outputFile, testSourceDirectories, new
JarArchiver() );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error creating source
archive: " + e.getMessage(), e );
+ }
+ catch ( ArchiverException e )
+ {
+ throw new MojoExecutionException( "Error creating source
archive: " + e.getMessage(), e );
+ }
- attachArtifact( outputFile );
+ attachArtifact( outputFile );
+ }
}
}
Modified:
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/SourceBundler.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/SourceBundler.java?rev=389724&r1=389723&r2=389724&view=diff
==============================================================================
---
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/SourceBundler.java
(original)
+++
maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/SourceBundler.java
Wed Mar 29 01:28:08 2006
@@ -17,8 +17,11 @@
*/
import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.util.FileUtils;
import java.io.File;
+import java.io.IOException;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trygve Laugstøl</a>
@@ -26,22 +29,18 @@
*/
public class SourceBundler
{
- private final static String[] DEFAULT_INCLUDES = new String[]{"**/*",};
-
- private final static String[] DEFAULT_EXCLUDES = new String[]{"**/CVS/**",
"**/.svn/**",};
+ private static final String[] DEFAULT_INCLUDES = new String[]{"**/*",};
public void makeSourceBundle( File outputFile, File[] sourceDirectories,
Archiver archiver )
- throws Exception
+ throws ArchiverException, IOException
{
String[] includes = DEFAULT_INCLUDES;
- String[] excludes = DEFAULT_EXCLUDES;
-
for ( int i = 0; i < sourceDirectories.length; i++ )
{
if ( sourceDirectories[i].exists() )
{
- archiver.addDirectory( sourceDirectories[i], includes,
excludes );
+ archiver.addDirectory( sourceDirectories[i], includes,
FileUtils.getDefaultExcludes() );
}
}