You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2006/11/29 07:28:51 UTC

svn commit: r480430 - in /maven/plugins/trunk/maven-source-plugin: ./ src/main/java/org/apache/maven/plugin/source/ src/test/java/org/apache/maven/plugin/source/

Author: jvanzyl
Date: Tue Nov 28 22:28:49 2006
New Revision: 480430

URL: http://svn.apache.org/viewvc?view=rev&rev=480430
Log:
o the source jar creation will now pick up archiver instructions via dot files and so can package up
  any resources produced like license files.

Removed:
    maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/SourceBundler.java
    maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugin/source/SourceBundlerTest.java
Modified:
    maven/plugins/trunk/maven-source-plugin/pom.xml
    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

Modified: maven/plugins/trunk/maven-source-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/pom.xml?view=diff&rev=480430&r1=480429&r2=480430
==============================================================================
--- maven/plugins/trunk/maven-source-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-source-plugin/pom.xml Tue Nov 28 22:28:49 2006
@@ -30,7 +30,7 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-archiver</artifactId>
-      <version>1.0-alpha-3</version>
+      <version>1.0-alpha-8-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>

Modified: maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractJarSourceMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/AbstractJarSourceMojo.java?view=diff&rev=480430&r1=480429&r2=480430
==============================================================================
--- 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 Tue Nov 28 22:28:49 2006
@@ -23,6 +23,8 @@
 import org.apache.maven.project.MavenProjectHelper;
 import org.codehaus.plexus.archiver.Archiver;
 import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -32,6 +34,8 @@
 public abstract class AbstractJarSourceMojo
     extends AbstractMojo
 {
+    private static final String[] DEFAULT_INCLUDES = new String[]{"**/*",};
+
     /**
      * @parameter expression="${project}"
      * @readonly
@@ -62,9 +66,7 @@
      */
     private boolean attach = true;
 
-    /**
-     * @component
-     */
+    /** @component */
     private MavenProjectHelper projectHelper;
 
     /**
@@ -89,9 +91,7 @@
      */
     protected String finalName;
 
-    /**
-     * @see org.apache.maven.plugin.AbstractMojo#execute()
-     */
+    /** @see org.apache.maven.plugin.AbstractMojo#execute() */
     public abstract void execute()
         throws MojoExecutionException;
 
@@ -133,7 +133,9 @@
      * @param sourceDirectories
      * @return an array of File objects that contains the directories that will be included in the jar file
      */
-    protected File[] addDirectories( List compileSourceRoots, List resources, File[] sourceDirectories )
+    protected File[] addDirectories( List compileSourceRoots,
+                                     List resources,
+                                     File[] sourceDirectories )
     {
         int count = 0;
         for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); )
@@ -190,11 +192,12 @@
      * @param outputFile        the file name of the jar
      * @param sourceDirectories the source directories that will be included in the jar file
      */
-    protected void createJar( File outputFile, File[] sourceDirectories, Archiver archiver )
+    protected void createJar( File outputFile,
+                              File[] sourceDirectories,
+                              Archiver archiver )
         throws IOException, ArchiverException
     {
-        SourceBundler sourceBundler = new SourceBundler();
-        sourceBundler.makeSourceBundle( outputFile, sourceDirectories, archiver );
+        makeSourceBundle( outputFile, sourceDirectories, archiver );
     }
 
     /**
@@ -203,7 +206,8 @@
      * @param outputFile the artifact file to be attached
      * @param classifier
      */
-    protected void attachArtifact( File outputFile, String classifier )
+    protected void attachArtifact( File outputFile,
+                                   String classifier )
     {
         if ( !attach )
         {
@@ -217,4 +221,44 @@
         }
     }
 
+    /**
+     * Method to create an archive of the specified files
+     *
+     * @param outputFile        the destination file of the generated archive
+     * @param sourceDirectories the directory where the files to be archived are located
+     * @param archiver          the archiver object that will create the archive
+     * @throws ArchiverException
+     * @throws IOException
+     */
+    protected void makeSourceBundle( File outputFile,
+                                     File[] sourceDirectories,
+                                     Archiver archiver )
+        throws ArchiverException, IOException
+    {
+        String[] includes = DEFAULT_INCLUDES;
+
+        for ( int i = 0; i < sourceDirectories.length; i++ )
+        {
+            if ( sourceDirectories[i].exists() )
+            {
+                archiver.addDirectory( sourceDirectories[i], includes, FileUtils.getDefaultExcludes() );
+            }
+        }
+
+        archiver.setDestFile( outputFile );
+
+        archiver.createArchive();
+    }
+
+    protected Archiver createArchiver()
+    {
+        Archiver archiver = new JarArchiver();
+
+        if ( project.getBuild() != null )
+        {
+            archiver.setDotFileDirectory( new File( project.getBuild().getDirectory() ) );
+        }
+
+        return archiver;
+    }
 }

Modified: maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarDefaultSourceMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarDefaultSourceMojo.java?view=diff&rev=480430&r1=480429&r2=480430
==============================================================================
--- 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 Tue Nov 28 22:28:49 2006
@@ -58,11 +58,12 @@
             else
             {
                 File outputFile = new File( outputDirectory, finalName + "-sources.jar" );
+
                 File[] sourceDirectories = getDefaultSources();
 
                 try
                 {
-                    createJar( outputFile, sourceDirectories, new JarArchiver() );
+                    createJar( outputFile, sourceDirectories, createArchiver() );
                 }
                 catch ( IOException e )
                 {

Modified: maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarTestSourceMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarTestSourceMojo.java?view=diff&rev=480430&r1=480429&r2=480430
==============================================================================
--- 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 Tue Nov 28 22:28:49 2006
@@ -50,7 +50,7 @@
 
             try
             {
-                createJar( outputFile, testSourceDirectories, new JarArchiver() );
+                createJar( outputFile, testSourceDirectories, createArchiver() );
             }
             catch ( IOException e )
             {