Author: jdcasey
Date: Thu May  4 15:23:13 2006
New Revision: 399870

URL: http://svn.apache.org/viewcvs?rev=399870&view=rev
Log:
Fixing tests, and adding code for module source inclusion back to the plugin, 
in a different way...will add tests next.

Removed:
    
maven/plugins/trunk/maven-assembly-plugin/src/test/plugin-configs/basicAbstractAssemblyMojoFeaturesTest/outputFileNameMappingWithTwoDependencySets-pluginConfig.xml
    
maven/plugins/trunk/maven-assembly-plugin/src/test/resources/basicAbstractAssemblyMojoFeaturesTest/outputFileNameMappingWithTwoDependencySets-assemblyDescriptor.xml
Modified:
    maven/plugins/trunk/maven-assembly-plugin/pom.xml
    
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/mdo/descriptor.mdo
    
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/BasicAbstractAssemblyMojoFeaturesTest.java
    
maven/plugins/trunk/maven-assembly-plugin/src/test/plugin-configs/basicAbstractAssemblyMojoFeaturesTest/outputFileNameMapping-pluginConfig.xml

Modified: maven/plugins/trunk/maven-assembly-plugin/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-assembly-plugin/pom.xml?rev=399870&r1=399869&r2=399870&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-assembly-plugin/pom.xml Thu May  4 15:23:13 2006
@@ -10,11 +10,6 @@
   <name>Maven Assembly Plugin</name>
   <version>2.1-SNAPSHOT</version>
   <build>
-    <!--testResources>
-      <testResource>
-        <directory>src/test/plugin-configs</directory>
-      </testResource>
-    </testResources-->
     <plugins>
       <plugin>
         <groupId>org.codehaus.modello</groupId>

Modified: 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java?rev=399870&r1=399869&r2=399870&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java
 Thu May  4 15:23:13 2006
@@ -46,6 +46,7 @@
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectHelper;
 import org.apache.maven.shared.model.fileset.util.FileSetManager;
+import org.apache.maven.wagon.PathUtils;
 import org.codehaus.plexus.archiver.Archiver;
 import org.codehaus.plexus.archiver.ArchiverException;
 import org.codehaus.plexus.archiver.jar.JarArchiver;
@@ -485,6 +486,9 @@
             ModuleSet moduleSet = (ModuleSet) i.next();
             String output = moduleSet.getOutputDirectory();
             output = getOutputDirectory( output, includeBaseDirectory );
+            
+            String sourceOutput = moduleSet.getSourceOutputDirectory();
+            sourceOutput = getOutputDirectory( sourceOutput, 
includeBaseDirectory );
 
             archiver.setDefaultDirectoryMode( Integer.parseInt( 
moduleSet.getDirectoryMode(), 8 ) );
 
@@ -507,7 +511,8 @@
 
             Set set = getModulesFromReactor( getExecutedProject() );
 
-            // TODO: includes and excludes
+            List moduleFileSets = new ArrayList();
+
             for ( Iterator j = set.iterator(); j.hasNext(); )
             {
                 MavenProject reactorProject = (MavenProject) j.next();
@@ -517,118 +522,144 @@
                 if ( filter.include( artifact ) && artifact.getFile() != null )
                 {
                     String name = artifact.getFile().getName();
-
-                    if ( moduleSet.isUnpack() )
+                    
+                    if ( moduleSet.isIncludeSources() )
                     {
-                        // TODO: something like zipfileset in plexus-archiver
-                        //                        archiver.addJar(  )
+                        FileSet moduleFileSet = new FileSet();
 
-                        // TODO refactor into the AbstractUnpackMojo
-                        File tempLocation = new File( workDirectory, 
name.substring( 0, name.lastIndexOf( '.' ) ) );
-                        boolean process = false;
-                        if ( !tempLocation.exists() )
-                        {
-                            tempLocation.mkdirs();
-                            process = true;
-                        }
-                        else if ( artifact.getFile().lastModified() > 
tempLocation.lastModified() )
-                        {
-                            process = true;
-                        }
+                        moduleFileSet.setDirectory( 
reactorProject.getBasedir().getAbsolutePath() );
+                        moduleFileSet.setOutputDirectory( sourceOutput );
 
-                        if ( process )
+                        List excludesList = new ArrayList();
+                        excludesList.add( PathUtils.toRelative( 
reactorProject.getBasedir(), reactorProject.getBuild().getDirectory() ) + "/**" 
);
+                        excludesList.add( PathUtils.toRelative( 
reactorProject.getBasedir(), reactorProject.getBuild().getOutputDirectory() ) + 
"/**" );
+                        excludesList.add( PathUtils.toRelative( 
reactorProject.getBasedir(), reactorProject.getBuild().getTestOutputDirectory() 
) + "/**" );
+                        excludesList.add( PathUtils.toRelative( 
reactorProject.getBasedir(), reactorProject.getReporting().getOutputDirectory() 
) + "/**" );
+                        moduleFileSet.setExcludes( excludesList );
+
+                        moduleFileSets.add( moduleFileSet );
+                    }
+                    
+                    if ( moduleSet.isIncludeBinaries() )
+                    {
+                        if ( moduleSet.isUnpack() )
                         {
-                            try
+                            // TODO: something like zipfileset in 
plexus-archiver
+                            //                        archiver.addJar(  )
+
+                            // TODO refactor into the AbstractUnpackMojo
+                            File tempLocation = new File( workDirectory, 
name.substring( 0, name.lastIndexOf( '.' ) ) );
+                            boolean process = false;
+                            if ( !tempLocation.exists() )
                             {
-                                unpack( artifact.getFile(), tempLocation );
+                                tempLocation.mkdirs();
+                                process = true;
+                            }
+                            else if ( artifact.getFile().lastModified() > 
tempLocation.lastModified() )
+                            {
+                                process = true;
+                            }
 
-                                if ( moduleSet.isIncludeDependencies() )
+                            if ( process )
+                            {
+                                try
                                 {
-                                    Set artifactSet = 
reactorProject.getArtifacts();
+                                    unpack( artifact.getFile(), tempLocation );
 
-                                    for ( Iterator artifacts = 
artifactSet.iterator(); artifacts.hasNext(); )
+                                    if ( moduleSet.isIncludeDependencies() )
                                     {
-                                        Artifact dependencyArtifact = 
(Artifact) artifacts.next();
-
-                                        unpack( dependencyArtifact.getFile(), 
tempLocation );
-                                    }
-                                }
+                                        Set artifactSet = 
reactorProject.getArtifacts();
 
-                                /*
-                                 * If the assembly is 'jar-with-dependencies', 
remove the security files in all dependencies
-                                 * that will prevent the uberjar to execute.  
Please see MASSEMBLY-64 for details.
-                                 */
-                                if ( archiver instanceof JarArchiver )
-                                {
-                                    String[] securityFiles = { "*.RSA", 
"*.DSA", "*.SF", "*.rsa", "*.dsa", "*.sf" };
-                                    
org.apache.maven.shared.model.fileset.FileSet securityFileSet = new 
org.apache.maven.shared.model.fileset.FileSet();
-                                    
securityFileSet.setDirectory(tempLocation.getAbsolutePath() + "/META-INF/" );
+                                        for ( Iterator artifacts = 
artifactSet.iterator(); artifacts.hasNext(); )
+                                        {
+                                            Artifact dependencyArtifact = 
(Artifact) artifacts.next();
 
-                                    for ( int sfsi = 0; sfsi < 
securityFiles.length; sfsi++ )
-                                    {
-                                        securityFileSet.addInclude( 
securityFiles[sfsi] );
+                                            unpack( 
dependencyArtifact.getFile(), tempLocation );
+                                        }
                                     }
 
-                                    FileSetManager fsm = new FileSetManager( 
getLog() );
-                                    try
-                                    {
-                                        fsm.delete( securityFileSet );
-                                    }
-                                    catch ( IOException e )
+                                    /*
+                                     * If the assembly is 
'jar-with-dependencies', remove the security files in all dependencies
+                                     * that will prevent the uberjar to 
execute.  Please see MASSEMBLY-64 for details.
+                                     */
+                                    if ( archiver instanceof JarArchiver )
                                     {
-                                        throw new 
MojoExecutionException("Failed to delete security files: " + e.getMessage(), e);
+                                        String[] securityFiles = { "*.RSA", 
"*.DSA", "*.SF", "*.rsa", "*.dsa", "*.sf" };
+                                        
org.apache.maven.shared.model.fileset.FileSet securityFileSet = new 
org.apache.maven.shared.model.fileset.FileSet();
+                                        
securityFileSet.setDirectory(tempLocation.getAbsolutePath() + "/META-INF/" );
+
+                                        for ( int sfsi = 0; sfsi < 
securityFiles.length; sfsi++ )
+                                        {
+                                            securityFileSet.addInclude( 
securityFiles[sfsi] );
+                                        }
+
+                                        FileSetManager fsm = new 
FileSetManager( getLog() );
+                                        try
+                                        {
+                                            fsm.delete( securityFileSet );
+                                        }
+                                        catch ( IOException e )
+                                        {
+                                            throw new 
MojoExecutionException("Failed to delete security files: " + e.getMessage(), e);
+                                        }
                                     }
                                 }
+                                catch ( NoSuchArchiverException e )
+                                {
+                                    throw new MojoExecutionException(
+                                        "Unable to obtain unarchiver for file 
'" + artifact.getFile() + "'" );
+                                }
                             }
-                            catch ( NoSuchArchiverException e )
-                            {
-                                throw new MojoExecutionException(
-                                    "Unable to obtain unarchiver for file '" + 
artifact.getFile() + "'" );
-                            }
-                        }
 
-                        addDirectory( archiver, tempLocation, output, null, 
FileUtils.getDefaultExcludesAsList() );
-                    }
-                    else
-                    {
-                        String outputFileNameMapping = 
moduleSet.getOutputFileNameMapping();
-
-                        //insert the classifier if exist
-                        if ( !StringUtils.isEmpty( artifact.getClassifier() ) )
+                            addDirectory( archiver, tempLocation, output, 
null, FileUtils.getDefaultExcludesAsList() );
+                        }
+                        else
                         {
-                            int dotIdx = outputFileNameMapping.lastIndexOf( 
"." );
+                            String outputFileNameMapping = 
moduleSet.getOutputFileNameMapping();
 
-                            String extension =
-                                outputFileNameMapping.substring( dotIdx + 1, 
outputFileNameMapping.length() );
-                            String artifactWithoutExt = 
outputFileNameMapping.substring( 0, dotIdx );
+                            //insert the classifier if exist
+                            if ( !StringUtils.isEmpty( 
artifact.getClassifier() ) )
+                            {
+                                int dotIdx = 
outputFileNameMapping.lastIndexOf( "." );
 
-                            outputFileNameMapping =
-                                artifactWithoutExt + "-" + 
artifact.getClassifier() + "." + extension;
-                        }
+                                String extension =
+                                    outputFileNameMapping.substring( dotIdx + 
1, outputFileNameMapping.length() );
+                                String artifactWithoutExt = 
outputFileNameMapping.substring( 0, dotIdx );
 
-                        archiver.addFile( artifact.getFile(),
-                                          output + evaluateFileNameMapping( 
outputFileNameMapping, artifact ) );
+                                outputFileNameMapping =
+                                    artifactWithoutExt + "-" + 
artifact.getClassifier() + "." + extension;
+                            }
 
-                        if ( moduleSet.isIncludeDependencies() )
-                        {
-                            Set artifactSet = reactorProject.getArtifacts();
+                            archiver.addFile( artifact.getFile(),
+                                              output + 
evaluateFileNameMapping( outputFileNameMapping, artifact ) );
 
-                            for ( Iterator artifacts = artifactSet.iterator(); 
artifacts.hasNext(); )
+                            if ( moduleSet.isIncludeDependencies() )
                             {
-                                Artifact dependencyArtifact = (Artifact) 
artifacts.next();
+                                Set artifactSet = 
reactorProject.getArtifacts();
+
+                                for ( Iterator artifacts = 
artifactSet.iterator(); artifacts.hasNext(); )
+                                {
+                                    Artifact dependencyArtifact = (Artifact) 
artifacts.next();
 
-                                File artifactFile = 
dependencyArtifact.getFile();
+                                    File artifactFile = 
dependencyArtifact.getFile();
 
-                                archiver.addFile( artifactFile, 
artifactFile.getName() );
+                                    archiver.addFile( artifactFile, 
artifactFile.getName() );
+                                }
                             }
                         }
                     }
+
                 }
                 else
                 {
                     // would be better to have a way to find out when a 
specified include or exclude
                     // is never triggered and warn() it.
                     getLog().debug( "artifact: " + artifact + " not included" 
);
+                }
+                
+                if ( !moduleFileSets.isEmpty() )
+                {
+                    processFileSets( archiver, moduleFileSets, 
includeBaseDirectory );            // TODO: includes and excludes
                 }
             }
         }

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/mdo/descriptor.mdo
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-assembly-plugin/src/main/mdo/descriptor.mdo?rev=399870&r1=399869&r2=399870&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/mdo/descriptor.mdo 
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/mdo/descriptor.mdo Thu 
May  4 15:23:13 2006
@@ -402,6 +402,35 @@
       <superClass>SetBase</superClass>
       <fields>
         <field>
+          <name>includeSources</name>
+          <version>1.0.0</version>
+          <type>boolean</type>
+          <defaultValue>false</defaultValue>
+          <description>
+            When set to true, the plugin will include the source files for 
modules included in this
+            set. Otherwise, it will only include binaries.
+          </description>
+        </field>
+        <field>
+          <name>sourceOutputDirectory</name>
+          <version>1.0.0</version>
+          <type>String</type>
+          <description>
+            The output directory in the assembly for the module-sources 
included by this set.
+          </description>
+        </field>
+        <field>
+          <name>includeBinaries</name>
+          <version>1.0.0</version>
+          <type>boolean</type>
+          <defaultValue>true</defaultValue>
+          <description>
+            When set to true, the plugin will include the binaries for the 
included modules, according to other 
+            configuration in this set. This includes the module artifacts, 
along with the dependency artifacts 
+            (optionally).
+          </description>
+        </field>
+        <field>
           <name>includeDependencies</name>
           <version>1.0.0</version>
           <type>boolean</type>

Modified: 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/BasicAbstractAssemblyMojoFeaturesTest.java
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/BasicAbstractAssemblyMojoFeaturesTest.java?rev=399870&r1=399869&r2=399870&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/BasicAbstractAssemblyMojoFeaturesTest.java
 (original)
+++ 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/BasicAbstractAssemblyMojoFeaturesTest.java
 Thu May  4 15:23:13 2006
@@ -6,19 +6,18 @@
 import org.apache.maven.plugin.assembly.stubs.ArchiverManagerStub;
 import org.apache.maven.plugin.assembly.stubs.ArchiverStub;
 import org.apache.maven.plugin.assembly.stubs.ArtifactStub;
-import org.apache.maven.plugin.assembly.stubs.ReactorMavenProjectStub;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.codehaus.plexus.archiver.Archiver;
 import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.UnArchiver;
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 
 import java.io.File;
-import java.net.URL;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -46,32 +45,16 @@
         testDependencyMapping( pluginConfig, requiredDependencies );
     }
 
-    public void testOutputFileNameMappingWithTwoDependencySets() throws 
Exception
-    {
-        String pluginConfig = 
"outputFileNameMappingWithTwoDependencySets-pluginConfig.xml";
-        
-        List requiredDependencies = new ArrayList();
-        
-        requiredDependencies.add( "dependencies/test.jar" );
-        requiredDependencies.add( "dependencies/test2.jar" );
-        requiredDependencies.add( "dependencies/test3-3.jar" );
-        requiredDependencies.add( "dependencies/test4-4.jar" );
-        
-        testDependencyMapping( pluginConfig, requiredDependencies );
-    }
-
     private void testDependencyMapping( String pluginConfig, List 
requiredDependencies ) throws Exception
     {
-        ClassLoader cloader = Thread.currentThread().getContextClassLoader();
-        
         String pluginConfigResource = "basicAbstractAssemblyMojoFeaturesTest/" 
+ pluginConfig;
         
-        URL resource = cloader.getResource( pluginConfigResource );
+        File pluginConfigFile = new File( getBasedir(), 
"src/test/plugin-configs/" + pluginConfigResource );
         
-        assertNotNull( "Cannot find plugin-configuration: \'" + 
pluginConfigResource + "\' in context-classloader\'s classpath.", resource );
+        assertTrue( "Cannot find plugin-configuration: \'" + 
pluginConfigResource + "\' in context-classloader\'s classpath.", 
pluginConfigFile.exists() );
         
         // TODO: Need to replace this with test-only mojos...
-        DirectoryMojo mojo = (DirectoryMojo) lookupMojo( "directory", 
resource.getPath() );
+        DirectoryMojo mojo = (DirectoryMojo) lookupMojo( "directory", 
pluginConfigFile.getAbsolutePath() );
 
         FileLoggingArchiverManagerStub archiverManager = 
(FileLoggingArchiverManagerStub) getVariableValueFromObject( mojo, 
"archiverManager" );
         archiverManager.clearArchiver();
@@ -93,7 +76,7 @@
     }
 
     public static final class FileLoggingArchiverManagerStub
-        extends ArchiverManagerStub
+        implements ArchiverManager
     {
         private FileLoggingArchiverStub archiverStub;
 
@@ -111,10 +94,16 @@
         {
             archiverStub = null;
         }
+
+        public UnArchiver getUnArchiver( String arg0 ) throws 
NoSuchArchiverException
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
     }
 
     public static final class FileLoggingArchiverStub
-        extends ArchiverStub
+        implements Archiver
     {
 
         private Set files = new LinkedHashSet();
@@ -132,6 +121,90 @@
         public Set getAddedFiles()
         {
             return files;
+        }
+
+        public void addDirectory( File arg0 ) throws ArchiverException
+        {
+            // TODO Auto-generated method stub
+            
+        }
+
+        public void addDirectory( File arg0, String arg1 ) throws 
ArchiverException
+        {
+            // TODO Auto-generated method stub
+            
+        }
+
+        public void addDirectory( File arg0, String[] arg1, String[] arg2 ) 
throws ArchiverException
+        {
+            // TODO Auto-generated method stub
+            
+        }
+
+        public void addDirectory( File arg0, String arg1, String[] arg2, 
String[] arg3 ) throws ArchiverException
+        {
+            // TODO Auto-generated method stub
+            
+        }
+
+        public void createArchive() throws ArchiverException, IOException
+        {
+            // TODO Auto-generated method stub
+            
+        }
+
+        public int getDefaultDirectoryMode()
+        {
+            // TODO Auto-generated method stub
+            return 0;
+        }
+
+        public int getDefaultFileMode()
+        {
+            // TODO Auto-generated method stub
+            return 0;
+        }
+
+        public File getDestFile()
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public Map getFiles()
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public boolean getIncludeEmptyDirs()
+        {
+            // TODO Auto-generated method stub
+            return false;
+        }
+
+        public void setDefaultDirectoryMode( int arg0 )
+        {
+            // TODO Auto-generated method stub
+            
+        }
+
+        public void setDefaultFileMode( int arg0 )
+        {
+            // TODO Auto-generated method stub
+            
+        }
+
+        public void setDestFile( File arg0 )
+        {
+            // TODO Auto-generated method stub
+            
+        }
+
+        public void setIncludeEmptyDirs( boolean arg0 )
+        {
+            // TODO Auto-generated method stub
+            
         }
 
     }

Modified: 
maven/plugins/trunk/maven-assembly-plugin/src/test/plugin-configs/basicAbstractAssemblyMojoFeaturesTest/outputFileNameMapping-pluginConfig.xml
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-assembly-plugin/src/test/plugin-configs/basicAbstractAssemblyMojoFeaturesTest/outputFileNameMapping-pluginConfig.xml?rev=399870&r1=399869&r2=399870&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-assembly-plugin/src/test/plugin-configs/basicAbstractAssemblyMojoFeaturesTest/outputFileNameMapping-pluginConfig.xml
 (original)
+++ 
maven/plugins/trunk/maven-assembly-plugin/src/test/plugin-configs/basicAbstractAssemblyMojoFeaturesTest/outputFileNameMapping-pluginConfig.xml
 Thu May  4 15:23:13 2006
@@ -28,6 +28,14 @@
             <depTwoGroupId>org.test.2</depTwoGroupId>
             <depTwoVersion>2</depTwoVersion>
           </project>
+          <executedProject 
implementation="org.apache.maven.plugin.assembly.BasicAbstractAssemblyMojoFeaturesTest$TwoDependencyReactorProjectStub">
+            <depOneArtifactId>test</depOneArtifactId>
+            <depOneGroupId>org.test</depOneGroupId>
+            <depOneVersion>1</depOneVersion>
+            <depTwoArtifactId>test2</depTwoArtifactId>
+            <depTwoGroupId>org.test.2</depTwoGroupId>
+            <depTwoVersion>2</depTwoVersion>
+          </executedProject>
           <descriptors>
             
<descriptor>${basedir}/src/test/resources/basicAbstractAssemblyMojoFeaturesTest/outputFileNameMapping-assemblyDescriptor.xml</descriptor>
           </descriptors>


Reply via email to