You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/06/20 10:00:54 UTC

svn commit: r191416 - in /maven/components/trunk: maven-core/src/main/java/org/apache/maven/lifecycle/ maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/ maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/to...

Author: brett
Date: Mon Jun 20 01:00:53 2005
New Revision: 191416

URL: http://svn.apache.org/viewcvs?rev=191416&view=rev
Log:
PR: MNG-471

- correct the lifecycle instantiation
- read/write executeLifecycle in the plugin descriptor

Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
    maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
    maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=191416&r1=191415&r2=191416&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java Mon Jun 20 01:00:53 2005
@@ -116,41 +116,37 @@
     private void executeGoal( String task, MavenSession session, MavenProject project )
         throws LifecycleExecutionException, PluginNotFoundException, MojoExecutionException, ArtifactResolutionException
     {
-        Map phaseMap = new HashMap();
-
-        for ( Iterator i = phases.iterator(); i.hasNext(); )
+        if ( phases.contains( task ) )
         {
-            String p = (String) i.next();
-
-            // Make a copy of the phase as we will modify it
-            phaseMap.put( p, new ArrayList() );
+            // we have a lifecycle phase, so lets bind all the necessary goals
+            Map lifecycleMappings = constructLifecycleMappings( session, task, project );
+            executeGoalWithLifecycle( task, session, lifecycleMappings, project );
         }
-
-        if ( phaseMap.containsKey( task ) )
+        else
         {
-            // we have a lifecycle phase, so lets bind all the necessary goals
-            constructLifecyclePhaseMap( session, phaseMap, task, project );
+            executeStandaloneGoal( task, session, project );
         }
-
-        executeGoalWithLifecycle( task, session, phaseMap, project );
     }
 
     private void executeGoalWithLifecycle( String task, MavenSession session, Map lifecycleMappings,
                                            MavenProject project )
         throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException
     {
-        List goals;
+        List goals = processGoalChain( task, lifecycleMappings );
 
-        if ( lifecycleMappings.containsKey( task ) )
-        {
-            goals = processGoalChain( task, lifecycleMappings );
-        }
-        else
-        {
-            MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session, project );
-            goals = Collections.singletonList( new MojoExecution( mojoDescriptor ) );
-        }
+        executeGoals( goals, session, project );
+    }
 
+    private void executeStandaloneGoal( String task, MavenSession session, MavenProject project )
+        throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException
+    {
+        MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session, project );
+        executeGoals( Collections.singletonList( new MojoExecution( mojoDescriptor ) ), session, project );
+    }
+
+    private void executeGoals( List goals, MavenSession session, MavenProject project )
+        throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException
+    {
         for ( Iterator i = goals.iterator(); i.hasNext(); )
         {
             MojoExecution mojoExecution = (MojoExecution) i.next();
@@ -160,8 +156,7 @@
 
             if ( executePhase != null )
             {
-                forkLifecycle( executePhase, mojoDescriptor.getExecuteLifecycle(), session, lifecycleMappings,
-                               project );
+                forkLifecycle( executePhase, mojoDescriptor.getExecuteLifecycle(), session, project );
             }
 
             try
@@ -175,18 +170,12 @@
         }
     }
 
-    private void forkLifecycle( String executePhase, String executeLifecycle, MavenSession session,
-                                Map lifecycleMappings, MavenProject project )
+    private void forkLifecycle( String task, String executeLifecycle, MavenSession session,
+                                MavenProject project )
         throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException
     {
-        // Deep copy of the lifecycle
-        Map phaseMap = new HashMap();
-        for ( Iterator i = lifecycleMappings.keySet().iterator(); i.hasNext(); )
-        {
-            String phase = (String) i.next();
-            List mappings = (List) lifecycleMappings.get( phase );
-            phaseMap.put( phase, new ArrayList( mappings ) );
-        }
+        // Create new lifecycle
+        Map lifecycleMappings = constructLifecycleMappings( session, task, project );
 
         if ( executeLifecycle != null )
         {
@@ -194,27 +183,27 @@
         }
 
         // TODO: clone project
-        executeGoalWithLifecycle( executePhase, session, phaseMap, project );
+        executeGoalWithLifecycle( task, session, lifecycleMappings, project );
     }
 
-    private void constructLifecyclePhaseMap( MavenSession session, Map phaseMap, String selectedPhase,
-                                             MavenProject project )
+    private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project )
         throws ArtifactResolutionException, LifecycleExecutionException
     {
         // first, bind those associated with the packaging
-        bindLifecycleForPackaging( session, phaseMap, selectedPhase, project );
+        Map lifecycleMappings = bindLifecycleForPackaging( session, selectedPhase, project );
 
         // next, loop over plugins and for any that have a phase, bind it
         for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
         {
             Plugin plugin = (Plugin) i.next();
 
-            bindPluginToLifecycle( plugin, session, phaseMap, project );
+            bindPluginToLifecycle( plugin, session, lifecycleMappings, project );
         }
+
+        return lifecycleMappings;
     }
 
-    private void bindLifecycleForPackaging( MavenSession session, Map phaseMap, String selectedPhase,
-                                            MavenProject project )
+    private Map bindLifecycleForPackaging( MavenSession session, String selectedPhase, MavenProject project )
         throws ArtifactResolutionException, LifecycleExecutionException
     {
         Map mappings;
@@ -230,6 +219,8 @@
             mappings = defaultPhases;
         }
 
+        Map lifecycleMappings = new HashMap();
+
         boolean finished = false;
         for ( Iterator i = phases.iterator(); i.hasNext() && !finished; )
         {
@@ -244,7 +235,8 @@
                     String goal = tok.nextToken().trim();
 
                     MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, project );
-                    addToPhaseMap( phaseMap, phase, new MojoExecution( mojoDescriptor ), session.getSettings() );
+                    addToLifecycleMappings( lifecycleMappings, phase, new MojoExecution( mojoDescriptor ),
+                                            session.getSettings() );
                 }
             }
 
@@ -253,6 +245,8 @@
                 finished = true;
             }
         }
+
+        return lifecycleMappings;
     }
 
     /**
@@ -347,7 +341,7 @@
                     if ( mojoDescriptor.getPhase() != null )
                     {
                         MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
-                        addToPhaseMap( phaseMap, mojoDescriptor.getPhase(), mojoExecution, settings );
+                        addToLifecycleMappings( phaseMap, mojoDescriptor.getPhase(), mojoExecution, settings );
                     }
                 }
             }
@@ -374,26 +368,26 @@
                 MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() );
                 if ( execution.getPhase() != null )
                 {
-                    addToPhaseMap( phaseMap, execution.getPhase(), mojoExecution, settings );
+                    addToLifecycleMappings( phaseMap, execution.getPhase(), mojoExecution, settings );
                 }
                 else if ( mojoDescriptor.getPhase() != null )
                 {
                     // if the phase was not in the configuration, use the phase in the descriptor
-                    addToPhaseMap( phaseMap, mojoDescriptor.getPhase(), mojoExecution, settings );
+                    addToLifecycleMappings( phaseMap, mojoDescriptor.getPhase(), mojoExecution, settings );
                 }
             }
         }
     }
 
-    private void addToPhaseMap( Map phaseMap, String phase, MojoExecution mojoExecution, Settings settings )
-        throws LifecycleExecutionException
+    private void addToLifecycleMappings( Map lifecycleMappings, String phase, MojoExecution mojoExecution,
+                                         Settings settings )
     {
-        List goals = (List) phaseMap.get( phase );
+        List goals = (List) lifecycleMappings.get( phase );
 
         if ( goals == null )
         {
-            String message = "Required phase '" + phase + "' not found";
-            throw new LifecycleExecutionException( message );
+            goals = new ArrayList();
+            lifecycleMappings.put( phase, goals );
         }
 
         MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

Modified: maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java?rev=191416&r1=191415&r2=191416&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java (original)
+++ maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java Mon Jun 20 01:00:53 2005
@@ -142,6 +142,13 @@
             mojo.setExecutePhase( executePhase );
         }
 
+        String executeLifecycle = c.getChild( "executeLifecycle" ).getValue();
+
+        if ( executeLifecycle != null )
+        {
+            mojo.setExecuteLifecycle( executeLifecycle );
+        }
+
         mojo.setInstantiationStrategy( c.getChild( "instantiationStrategy" ).getValue() );
 
         mojo.setDescription( c.getChild( "description" ).getValue() );

Modified: maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java?rev=191416&r1=191415&r2=191416&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java (original)
+++ maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java Mon Jun 20 01:00:53 2005
@@ -158,6 +158,11 @@
             element( w, "executePhase", mojoDescriptor.getExecutePhase() );
         }
 
+        if ( mojoDescriptor.getExecuteLifecycle() != null )
+        {
+            element( w, "executeLifecycle", mojoDescriptor.getExecuteLifecycle() );
+        }
+
         // ----------------------------------------------------------------------
         //
         // ----------------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org