maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r416562 - in /maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly: ./ filter/ repository/ utils/
Date Fri, 23 Jun 2006 04:33:56 GMT
Author: jdcasey
Date: Thu Jun 22 21:33:55 2006
New Revision: 416562

URL: http://svn.apache.org/viewvc?rev=416562&view=rev
Log:
Adding includes/excludes implementation to repository assembly.

Added:
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/FilterUtils.java
  (with props)
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java
  (with props)
Modified:
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AssemblyIncludesArtifactFilter.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/repository/DefaultRepositoryAssembler.java

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java?rev=416562&r1=416561&r2=416562&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 Jun 22 21:33:55 2006
@@ -34,6 +34,8 @@
 import org.apache.maven.plugin.assembly.interpolation.ReflectionProperties;
 import org.apache.maven.plugin.assembly.repository.RepositoryAssembler;
 import org.apache.maven.plugin.assembly.repository.RepositoryAssemblyException;
+import org.apache.maven.plugin.assembly.utils.FilterUtils;
+import org.apache.maven.plugin.assembly.utils.ProjectUtils;
 import org.apache.maven.plugin.assembly.utils.PropertyUtils;
 import org.apache.maven.plugins.assembly.model.Assembly;
 import org.apache.maven.plugins.assembly.model.Component;
@@ -394,37 +396,6 @@
         {
             Repository repository = (Repository) i.next();
 
-            AndArtifactFilter filter = new AndArtifactFilter();
-
-            // ----------------------------------------------------------------------------
-            // Includes
-            //
-            // We'll take everything if no includes are specified to try and make this
-            // process more maintainable. Don't want to have to update the assembly
-            // descriptor everytime the POM is updated.
-            // ----------------------------------------------------------------------------
-
-            if ( repository.getIncludes().isEmpty() )
-            {
-                filter.add( new AssemblyIncludesArtifactFilter( getDependenciesIncludeList()
) );
-            }
-            else
-            {
-                filter.add( new AssemblyIncludesArtifactFilter( repository.getIncludes()
) );
-            }
-
-            // ----------------------------------------------------------------------------
-            // Excludes
-            //
-            // We still want to make it easy to exclude a few things even if we slurp
-            // up everything.
-            // ----------------------------------------------------------------------------
-
-            if ( !repository.getExcludes().isEmpty() )
-            {
-                filter.add( new AssemblyExcludesArtifactFilter( repository.getExcludes()
) );
-            }
-
             File repositoryDirectory = new File( tempRoot, repository.getOutputDirectory()
);
 
             if ( !repositoryDirectory.exists() )
@@ -432,7 +403,7 @@
                 repositoryDirectory.mkdirs();
             }
 
-            repositoryAssembler.assemble( repositoryDirectory, repository, project, localRepository
);
+            repositoryAssembler.assemble( repositoryDirectory, repository, getExecutedProject(),
localRepository );
 
             try
             {
@@ -474,7 +445,7 @@
             
             Set moduleProjects = new HashSet( allModuleProjects );
             
-            filterProjects( moduleProjects, moduleSet.getIncludes(), moduleSet.getExcludes(),
false );
+            FilterUtils.filterProjects( moduleProjects, moduleSet.getIncludes(), moduleSet.getExcludes(),
false );
 
             List moduleFileSets = new ArrayList();
 
@@ -541,7 +512,7 @@
                     List includes = binaries.getIncludes();
                     List excludes = binaries.getExcludes();
                     
-                    filterArtifacts( binaryDependencies, includes, excludes, true, Collections.EMPTY_LIST
);
+                    FilterUtils.filterArtifacts( binaryDependencies, includes, excludes,
true, Collections.EMPTY_LIST );
                     
                     if ( binaries.isUnpack() )
                     {
@@ -662,65 +633,6 @@
         }
     }
 
-    private void filterProjects( Set moduleProjects, List includes, List excludes, boolean
actTransitively )
-    {
-        AndArtifactFilter filter = new AndArtifactFilter();
-
-        if ( !includes.isEmpty() )
-        {
-            filter.add( new AssemblyIncludesArtifactFilter( includes, actTransitively ) );
-        }
-        if ( !excludes.isEmpty() )
-        {
-            filter.add( new AssemblyExcludesArtifactFilter( excludes, actTransitively ) );
-        }
-        
-        for ( Iterator it = moduleProjects.iterator(); it.hasNext(); )
-        {
-            MavenProject project = (MavenProject) it.next();
-            Artifact artifact = project.getArtifact();
-            
-            if ( !filter.include( artifact ) )
-            {
-                it.remove();
-            }
-        }
-    }
-
-    private void filterArtifacts( Set artifacts, List includes, List excludes, boolean actTransitively,
List additionalFilters )
-    {
-        AndArtifactFilter filter = new AndArtifactFilter();
-        
-        if ( additionalFilters != null && !additionalFilters.isEmpty() )
-        {
-            for ( Iterator it = additionalFilters.iterator(); it.hasNext(); )
-            {
-                ArtifactFilter additionalFilter = (ArtifactFilter) it.next();
-                
-                filter.add( additionalFilter );
-            }
-        }
-
-        if ( !includes.isEmpty() )
-        {
-            filter.add( new AssemblyIncludesArtifactFilter( includes, actTransitively ) );
-        }
-        if ( !excludes.isEmpty() )
-        {
-            filter.add( new AssemblyExcludesArtifactFilter( excludes, actTransitively ) );
-        }
-        
-        for ( Iterator it = artifacts.iterator(); it.hasNext(); )
-        {
-            Artifact artifact = (Artifact) it.next();
-            
-            if ( !filter.include( artifact ) )
-            {
-                it.remove();
-            }
-        }
-    }
-
     private static String evaluateFileNameMapping( Artifact artifact, String mapping )
         throws MojoExecutionException
     {
@@ -1057,12 +969,12 @@
                 Integer.toString( archiver.getDefaultDirectoryMode(), 8 ) + " file perms:
" +
                 Integer.toString( archiver.getDefaultFileMode(), 8 ) );
 
-            Set allDependencyArtifacts = getDependencies();
+            Set allDependencyArtifacts = ProjectUtils.getDependencies( getExecutedProject()
);
             Set dependencyArtifacts = new HashSet( allDependencyArtifacts );
             
             AssemblyScopeArtifactFilter scopeFilter = new AssemblyScopeArtifactFilter( dependencySet.getScope()
);
             
-            filterArtifacts( dependencyArtifacts, dependencySet.getIncludes(), dependencySet.getExcludes(),
true, Collections.singletonList( scopeFilter ) );
+            FilterUtils.filterArtifacts( dependencyArtifacts, dependencySet.getIncludes(),
dependencySet.getExcludes(), true, Collections.singletonList( scopeFilter ) );
 
             for ( Iterator j = dependencyArtifacts.iterator(); j.hasNext(); )
             {
@@ -1155,29 +1067,6 @@
                 getLog().debug( "artifact: " + artifact + " not included" );
             }
         }
-    }
-
-    /**
-     * Retrieves an includes list generated from the existing depedencies in a project.
-     *
-     * @return A List of includes
-     */
-    private List getDependenciesIncludeList()
-    {
-        List includes = new ArrayList();
-
-        for ( Iterator i = getDependencies().iterator(); i.hasNext(); )
-        {
-            Artifact a = (Artifact) i.next();
-
-            if ( !project.getGroupId().equals( a.getGroupId() ) ||
-                !project.getArtifactId().equals( a.getArtifactId() ) )
-            {
-                includes.add( a.getGroupId() + ":" + a.getArtifactId() );
-            }
-        }
-
-        return includes;
     }
 
     private void addDirectory( Archiver archiver, File directory, String output, String[]
includes, List excludes )

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java?rev=416562&r1=416561&r2=416562&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java
Thu Jun 22 21:33:55 2006
@@ -109,32 +109,10 @@
     protected MavenProject project;
 
 
-    /**
-     * Retrieves all artifact dependencies.
-     *
-     * @return A HashSet of artifacts
-     */
-    protected Set getDependencies()
+    protected MavenProject getExecutedProject()
     {
-        MavenProject project = getExecutedProject();
-
-        Set dependenciesSet = new HashSet();
-
-        if ( project.getArtifact() != null && project.getArtifact().getFile() !=
null )
-        {
-            dependenciesSet.add( project.getArtifact() );
-        }
-
-        Set projectArtifacts = project.getArtifacts();
-        if ( projectArtifacts != null )
-        {
-            dependenciesSet.addAll( projectArtifacts );
-        }
-
-        return dependenciesSet;
+        return project;
     }
-
-    protected abstract MavenProject getExecutedProject();
 
     /**
      * Unpacks the archive file.

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java?rev=416562&r1=416561&r2=416562&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java
Thu Jun 22 21:33:55 2006
@@ -19,6 +19,7 @@
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.assembly.utils.ProjectUtils;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 
@@ -48,7 +49,7 @@
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
-        for ( Iterator j = getDependencies().iterator(); j.hasNext(); )
+        for ( Iterator j = ProjectUtils.getDependencies( project ).iterator(); j.hasNext();
)
         {
             Artifact artifact = (Artifact) j.next();
 

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AssemblyIncludesArtifactFilter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AssemblyIncludesArtifactFilter.java?rev=416562&r1=416561&r2=416562&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AssemblyIncludesArtifactFilter.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/filter/AssemblyIncludesArtifactFilter.java
Thu Jun 22 21:33:55 2006
@@ -51,12 +51,13 @@
     {
         String shortId = artifact.getGroupId() + ":" + artifact.getArtifactId();
         String id = artifact.getDependencyConflictId();
-
+        
         boolean matched = false;
         for ( Iterator i = patterns.iterator(); i.hasNext() && !matched; )
         {
             // TODO: what about wildcards? Just specifying groups? versions?
             String pattern = (String) i.next();
+            
             if ( id.equals( pattern ) )
             {
                 matched = true;

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/repository/DefaultRepositoryAssembler.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/repository/DefaultRepositoryAssembler.java?rev=416562&r1=416561&r2=416562&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/repository/DefaultRepositoryAssembler.java
(original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/repository/DefaultRepositoryAssembler.java
Thu Jun 22 21:33:55 2006
@@ -16,7 +16,25 @@
  * limitations under the License.
  */
 
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.lang.reflect.Field;
+import java.security.NoSuchAlgorithmException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TimeZone;
+
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -31,8 +49,11 @@
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.plugin.assembly.filter.AssemblyExcludesArtifactFilter;
+import org.apache.maven.plugin.assembly.filter.AssemblyIncludesArtifactFilter;
 import org.apache.maven.plugin.assembly.utils.DigestUtils;
 import org.apache.maven.plugins.assembly.model.GroupVersionAlignment;
 import org.apache.maven.plugins.assembly.model.Repository;
@@ -44,21 +65,6 @@
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-import java.lang.reflect.Field;
-import java.security.NoSuchAlgorithmException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-
 /**
  * @author Jason van Zyl
  */
@@ -128,7 +134,56 @@
             throw new RepositoryAssemblyException( "Error invalidating the processed project
cache.", e );
         }
 
-        ArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
+        AndArtifactFilter filter = new AndArtifactFilter();
+
+        ArtifactFilter scopeFilter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
+        filter.add( scopeFilter );
+        
+        // ----------------------------------------------------------------------------
+        // Includes
+        //
+        // We'll take everything if no includes are specified to try and make this
+        // process more maintainable. Don't want to have to update the assembly
+        // descriptor everytime the POM is updated.
+        // ----------------------------------------------------------------------------
+
+        if ( repository.getIncludes().isEmpty() )
+        {
+            List patterns = new ArrayList();
+            
+            Set projectArtifacts = project.getDependencyArtifacts();
+            
+            if ( projectArtifacts != null )
+            {
+                for ( Iterator it = projectArtifacts.iterator(); it.hasNext(); )
+                {
+                    Artifact artifact = (Artifact) it.next();
+                    
+                    patterns.add( artifact.getDependencyConflictId() );
+                }
+            }
+            
+            AssemblyIncludesArtifactFilter includeFilter = new AssemblyIncludesArtifactFilter(
patterns, true );
+            
+            filter.add( includeFilter );
+        }
+        else
+        {
+            filter.add( new AssemblyIncludesArtifactFilter( repository.getIncludes(), true
) );
+        }
+
+        // ----------------------------------------------------------------------------
+        // Excludes
+        //
+        // We still want to make it easy to exclude a few things even if we slurp
+        // up everything.
+        // ----------------------------------------------------------------------------
+
+        if ( !repository.getExcludes().isEmpty() )
+        {
+            filter.add( new AssemblyExcludesArtifactFilter( repository.getExcludes(), true
) );
+        }
+
         try
         {
             // Now that we have the graph, let's try to align it to versions that we want
and remove

Added: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/FilterUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/FilterUtils.java?rev=416562&view=auto
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/FilterUtils.java
(added)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/FilterUtils.java
Thu Jun 22 21:33:55 2006
@@ -0,0 +1,80 @@
+package org.apache.maven.plugin.assembly.utils;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.plugin.assembly.filter.AssemblyExcludesArtifactFilter;
+import org.apache.maven.plugin.assembly.filter.AssemblyIncludesArtifactFilter;
+import org.apache.maven.project.MavenProject;
+
+public final class FilterUtils
+{
+    
+    private FilterUtils()
+    {
+    }
+
+    public static void filterProjects( Set projects, List includes, List excludes, boolean
actTransitively )
+    {
+        AndArtifactFilter filter = new AndArtifactFilter();
+
+        if ( !includes.isEmpty() )
+        {
+            filter.add( new AssemblyIncludesArtifactFilter( includes, actTransitively ) );
+        }
+        if ( !excludes.isEmpty() )
+        {
+            filter.add( new AssemblyExcludesArtifactFilter( excludes, actTransitively ) );
+        }
+        
+        for ( Iterator it = projects.iterator(); it.hasNext(); )
+        {
+            MavenProject project = (MavenProject) it.next();
+            Artifact artifact = project.getArtifact();
+            
+            if ( !filter.include( artifact ) )
+            {
+                it.remove();
+            }
+        }
+    }
+
+    public static void filterArtifacts( Set artifacts, List includes, List excludes, boolean
actTransitively, List additionalFilters )
+    {
+        AndArtifactFilter filter = new AndArtifactFilter();
+        
+        if ( additionalFilters != null && !additionalFilters.isEmpty() )
+        {
+            for ( Iterator it = additionalFilters.iterator(); it.hasNext(); )
+            {
+                ArtifactFilter additionalFilter = (ArtifactFilter) it.next();
+                
+                filter.add( additionalFilter );
+            }
+        }
+
+        if ( !includes.isEmpty() )
+        {
+            filter.add( new AssemblyIncludesArtifactFilter( includes, actTransitively ) );
+        }
+        if ( !excludes.isEmpty() )
+        {
+            filter.add( new AssemblyExcludesArtifactFilter( excludes, actTransitively ) );
+        }
+        
+        for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+        {
+            Artifact artifact = (Artifact) it.next();
+            
+            if ( !filter.include( artifact ) )
+            {
+                it.remove();
+            }
+        }
+    }
+
+}

Propchange: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/FilterUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/FilterUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java?rev=416562&view=auto
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java
(added)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java
Thu Jun 22 21:33:55 2006
@@ -0,0 +1,42 @@
+package org.apache.maven.plugin.assembly.utils;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.project.MavenProject;
+
+public final class ProjectUtils
+{
+    
+    private ProjectUtils()
+    {
+    }
+
+    /**
+     * Retrieves all artifact dependencies.
+     *
+     * @return A HashSet of artifacts
+     */
+    public static Set getDependencies( MavenProject project )
+    {
+        Set dependenciesSet = new HashSet();
+
+        if ( project.getArtifact() != null && project.getArtifact().getFile() !=
null )
+        {
+            dependenciesSet.add( project.getArtifact() );
+        }
+
+        Set projectArtifacts = project.getArtifacts();
+        if ( projectArtifacts != null )
+        {
+            dependenciesSet.addAll( projectArtifacts );
+        }
+
+        return dependenciesSet;
+    }
+
+}

Propchange: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message