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 2009/04/28 02:48:53 UTC

svn commit: r769214 - in /maven/components/branches/MNG-2766/maven-core/src: main/java/org/apache/maven/lifecycle/ test/java/org/apache/maven/lifecycle/

Author: jvanzyl
Date: Tue Apr 28 00:48:53 2009
New Revision: 769214

URL: http://svn.apache.org/viewvc?rev=769214&view=rev
Log:
o adding method to get a list of plugins that correspond to a lifecycle for configuration merging by the builder

Modified:
    maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
    maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
    maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java

Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=769214&r1=769213&r2=769214&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java Tue Apr 28 00:48:53 2009
@@ -19,8 +19,10 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 
 import org.apache.maven.execution.MavenSession;
@@ -41,11 +43,13 @@
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.util.StringUtils;
 
 //TODO: The configuration for the lifecycle needs to be externalized so that I can use the annotations
 //      properly for the wiring and reference and external source for the lifecycle configuration.
 //TODO: Inside an IDE we are replacing the notion of our reactor with a workspace. In both of these cases
 //      we need to layer these as local repositories.
+//TODO: Cache the lookups of the PluginDescriptors
 
 /**
  * @author Jason van Zyl
@@ -69,6 +73,8 @@
     // @Configuration(source="org/apache/maven/lifecycle/lifecycles.xml")    
     private List<Lifecycle> lifecycles;
 
+    private Map<String,Lifecycle> lifecycleMap;
+    
     private Map<String, Lifecycle> phaseToLifecycleMap;
 
     public void execute( MavenSession session )
@@ -186,7 +192,29 @@
             }
         }         
     }
-
+      
+    public Set<Plugin> lifecyclePlugins( String lifecycleId, String packaging )
+    {
+        Set<Plugin> plugins = new LinkedHashSet<Plugin>();
+        
+        Lifecycle lifecycle = lifecycleMap.get( lifecycleId );                
+                
+        LifecycleMapping lifecycleMappingForPackaging = lifecycleMappings.get( packaging );
+          
+        Map<String, String> lifecyclePhasesForPackaging = lifecycleMappingForPackaging.getLifecycles().get( lifecycleId ).getPhases();            
+        
+        for ( String s : lifecyclePhasesForPackaging.values() )
+        {
+            String[] p = StringUtils.split( s, ":" );
+            Plugin plugin = new Plugin();        
+            plugin.setGroupId( p[0] );
+            plugin.setArtifactId( p[1] );
+            plugins.add( plugin );
+        }
+        
+        return plugins;
+    }        
+    
     // 1. Find the lifecycle given the phase (default lifecycle when given install)
     // 2. Find the lifecycle mapping that corresponds to the project packaging (jar lifecycle mapping given the jar packaging)
     // 3. Find the mojos associated with the lifecycle given the project packaging (jar lifecycle mapping for the default lifecycle)
@@ -293,14 +321,9 @@
                     {
                         String s = plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() + ":" + goal;
                         MojoDescriptor md = getMojoDescriptor( s, session, project );
-                        
-                        boolean include = lifecycle.getPhases().contains( md.getPhase() );                        
-//                        System.out.println( ">>> " + goal );
-//                        System.out.println( ">>> " + md.getPhase() );                                                
-//                        System.out.println( ">>> " + include );
-                        
+                                                
                         // need to know if this plugin belongs to a phase in the lifecycle that's running
-                        if ( md.getPhase() != null && include )
+                        if ( md.getPhase() != null && lifecycle.getPhases().contains( md.getPhase() ) )
                         {
                             phaseToMojoMapping.get( md.getPhase() ).add( s );
                         }
@@ -423,17 +446,19 @@
                 
         return mojoDescriptor;
     }
-
+    
     public void initialize()
         throws InitializationException
     {
+        lifecycleMap = new HashMap<String,Lifecycle>();
+        
         // If people are going to make their own lifecycles then we need to tell people how to namespace them correctly so
         // that they don't interfere with internally defined lifecycles.
 
         phaseToLifecycleMap = new HashMap<String,Lifecycle>();
 
         for ( Lifecycle lifecycle : lifecycles )
-        {
+        {                        
             for ( String phase : lifecycle.getPhases() )
             {                
                 // The first definition wins.
@@ -442,6 +467,8 @@
                     phaseToLifecycleMap.put( phase, lifecycle );
                 }
             }
+            
+            lifecycleMap.put( lifecycle.getId(), lifecycle );
         }
     }   
     

Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java?rev=769214&r1=769213&r2=769214&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java Tue Apr 28 00:48:53 2009
@@ -20,11 +20,14 @@
  */
 
 import java.util.List;
+import java.util.Set;
 
 import org.apache.maven.BuildFailureException;
 import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.project.MavenProject;
 
 /**
  * @author Jason van  Zyl
@@ -44,6 +47,8 @@
     List<MojoDescriptor> calculateLifecyclePlan( String lifecyclePhase, MavenSession session )
         throws LifecycleExecutionException;
         
+    Set<Plugin> lifecyclePlugins( String lifecycleId, String packaging );
+    
     void execute( MavenSession session )
         throws LifecycleExecutionException, MojoFailureException;
 }

Modified: maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java?rev=769214&r1=769213&r2=769214&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java Tue Apr 28 00:48:53 2009
@@ -1,10 +1,13 @@
 package org.apache.maven.lifecycle;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.maven.AbstractCoreMavenComponentTestCase;
 import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.PluginManager;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
@@ -79,4 +82,12 @@
         assertEquals( "1.0", session.getCurrentProject().getVersion() );                                
         lifecycleExecutor.execute( session );
     }    
+    
+    public void testLifecyclePluginsRetrievalForDefaultLifecycle()
+        throws Exception
+    {
+        List<Plugin> plugins = new ArrayList<Plugin>( lifecycleExecutor.lifecyclePlugins( "default", "jar" ) );  
+        
+        assertEquals( 6, plugins.size() );
+    }
 }