You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ar...@apache.org on 2006/03/13 12:21:51 UTC

svn commit: r385514 - in /maven/plugins/trunk/maven-assembly-plugin/src: main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java site/apt/howto.apt

Author: aramirez
Date: Mon Mar 13 03:21:49 2006
New Revision: 385514

URL: http://svn.apache.org/viewcvs?rev=385514&view=rev
Log:
PR: MASSEMBLY-68

-added new parameter called projectModulesOnly where it assembles all the project modules without their dependencies.
-also modified the howto doc

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/site/apt/howto.apt

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=385514&r1=385513&r2=385514&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 Mon Mar 13 03:21:49 2006
@@ -599,16 +599,27 @@
             {
                 filter.add( new ExcludesArtifactFilter( dependencySet.getExcludes() ) );
             }
-
+            
+            Set set;
+            
+            if( projectModulesOnly )
+            {
+                set = getModules();
+            }
+            else
+            {
+                set = getDependencies();
+            }
+            
             // TODO: includes and excludes
-            for ( Iterator j = getDependencies().iterator(); j.hasNext(); )
+            for ( Iterator j = set.iterator(); j.hasNext(); )
             {
                 Artifact artifact = (Artifact) j.next();
 
                 if ( filter.include( artifact ) )
                 {
                     String name = artifact.getFile().getName();
-                    
+                                       
                     if ( dependencySet.isUnpack() )
                     {
                         // TODO: something like zipfileset in plexus-archiver

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractUnpackingMojo.java?rev=385514&r1=385513&r2=385514&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 Mon Mar 13 03:21:49 2006
@@ -17,8 +17,13 @@
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.archiver.ArchiverException;
 import org.codehaus.plexus.archiver.UnArchiver;
@@ -62,6 +67,11 @@
     protected String finalName;
 
     /**
+     * @parameter expression="${projectModulesOnly}" default-value="false"
+     */
+    protected boolean projectModulesOnly = false;
+    
+    /**
      * Directory to unpack JARs into if needed
      *
      * @parameter expression="${project.build.directory}/assembly/work"
@@ -77,6 +87,16 @@
      */
 
     protected ArchiverManager archiverManager;
+    
+    /**
+     * @component
+     */
+    protected ArtifactResolver artifactResolver;
+    
+    /**
+     * @parameter expression="${localRepository}"
+     */
+    protected ArtifactRepository localRepository;
 
     /**
      * Contains the full list of projects in the reactor.
@@ -108,11 +128,12 @@
      * @return A HashSet of artifacts
      */
     protected Set getDependencies()
+        throws MojoExecutionException
     {
         Map dependencies = new HashMap();
 
         MavenProject project = getExecutedProject();
-
+        
         // TODO: this is not mediating dependencies versions - first wins. Is there a way we can do that properly from here?
         if ( project != null )
         {
@@ -131,7 +152,7 @@
             MavenProject reactorProject = (MavenProject) i.next();
 
             Artifact artifact = reactorProject.getArtifact();
-
+            
             if ( artifact.getFile() != null )
             {
                 String key = artifact.getDependencyConflictId();
@@ -144,8 +165,8 @@
 
             for ( Iterator j = reactorProject.getArtifacts().iterator(); j.hasNext(); )
             {
-                artifact = (Artifact) j.next();
-
+                artifact = (Artifact) j.next();      
+                
                 String key = artifact.getDependencyConflictId();
 
                 if ( !dependencies.containsKey( key ) )
@@ -154,10 +175,72 @@
                 }
             }
         }
+        return new HashSet( dependencies.values() );
+    }
+
+    protected Set getModules()
+        throws MojoExecutionException, MojoFailureException
+    {
+        Map dependencies = new HashMap();
+      
+        for ( Iterator i = reactorProjects.iterator(); i.hasNext(); )
+        {
+            MavenProject reactorProject = (MavenProject) i.next();
 
+            Artifact artifact = reactorProject.getArtifact();
+    
+            try
+            {
+                artifactResolver.resolve( artifact, project.getRemoteArtifactRepositories(), localRepository );
+            }
+            catch( ArtifactNotFoundException e )
+            {
+                //TODO: Is there a better way to get the artifact if it is not yet installed in the repo?
+                //reactorProject.getArtifact().getFile() is returning null
+                //tried also the project.getArtifact().getFile() but returning same result
+                File fileArtifact = new File( reactorProject.getBuild().getDirectory() + File.separator + 
+                                              reactorProject.getBuild().getFinalName() + "." +
+                                              reactorProject.getPackaging() );
+                
+                getLog().info( "Artifact ( " + artifact.getFile().getName() + " ) not found " +
+                                "in any repository, resolving thru modules..." );
+                
+                artifact.setFile( fileArtifact );
+                
+                if( fileArtifact.exists() )
+                {
+                    if( artifact.getType().equals( "pom" ) )
+                        continue;
+                        
+                    addModuleArtifact( dependencies, artifact );
+                }
+            }
+            catch( ArtifactResolutionException e )
+            {
+                throw new MojoExecutionException( "Failed to resolve artifact", e );
+            }
+            
+            if ( artifact.getFile() != null )
+            {
+                if( artifact.getType().equals( "pom" ) )
+                    continue;
+                
+                addModuleArtifact( dependencies, artifact );
+            }
+        }
         return new HashSet( dependencies.values() );
     }
+    
+    private void addModuleArtifact( Map dependencies, Artifact artifact )
+    {
+        String key = artifact.getDependencyConflictId();
 
+        if ( !dependencies.containsKey( key ) )
+        {
+            dependencies.put( key, artifact );
+        }
+    }
+    
     protected abstract MavenProject getExecutedProject();
 
     /**

Modified: maven/plugins/trunk/maven-assembly-plugin/src/site/apt/howto.apt
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-assembly-plugin/src/site/apt/howto.apt?rev=385514&r1=385513&r2=385514&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/site/apt/howto.apt (original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/site/apt/howto.apt Mon Mar 13 03:21:49 2006
@@ -21,6 +21,19 @@
 -----
 
 
+** How to assemble your project with your project modules only.
+  
+  There may be some situations that you only needed the jars of your project 
+  modules. You may exclude their dependencies but what if you have 10 
+  modules with 10 dependencies each? Isn't it a bit hassle to exclude 100 where 
+  you only needed 10. To achieve this goal, set the "projectModulesOnly" 
+  parameter to true and maven will do it for you.
+
+-----
+ mvn assembly:assembly -DprojectModulesOnly=true
+-----
+
+
 * How to use assembly:assembly using predefined descriptor ids.
 
 ----