You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/02/21 16:36:07 UTC

svn commit: r379491 - in /maven/components/trunk: maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java maven-plugin-descriptor/src/main/mdo/lifecycle.mdo

Author: brett
Date: Tue Feb 21 07:36:04 2006
New Revision: 379491

URL: http://svn.apache.org/viewcvs?rev=379491&view=rev
Log:
[MNG-2096] allow <configuration> with <execution> in a lifecycle overlay, like a plugin allows

Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java
    maven/components/trunk/maven-plugin-descriptor/src/main/mdo/lifecycle.mdo

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=379491&r1=379490&r2=379491&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 Tue Feb 21 07:36:04 2006
@@ -55,9 +55,9 @@
 import org.codehaus.plexus.PlexusContainerException;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import org.codehaus.plexus.util.StringUtils;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -95,7 +95,7 @@
     private List defaultReports;
 
     private Map phaseToLifecycleMap;
-    
+
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
@@ -181,11 +181,8 @@
         }
     }
 
-    private void executeTaskSegments( List taskSegments,
-                                      ReactorManager rm,
-                                      MavenSession session,
-                                      MavenProject rootProject,
-                                      EventDispatcher dispatcher )
+    private void executeTaskSegments( List taskSegments, ReactorManager rm, MavenSession session,
+                                      MavenProject rootProject, EventDispatcher dispatcher )
         throws LifecycleExecutionException, BuildFailureException
     {
         for ( Iterator it = taskSegments.iterator(); it.hasNext(); )
@@ -219,7 +216,8 @@
                     {
                         String task = (String) goalIterator.next();
 
-                        executeGoalAndHandleFailures( task, session, rootProject, dispatcher, event, rm, buildStartTime,target );
+                        executeGoalAndHandleFailures( task, session, rootProject, dispatcher, event, rm, buildStartTime,
+                                                      target );
                     }
 
                     rm.registerBuildSuccess( rootProject, System.currentTimeMillis() - buildStartTime );
@@ -234,7 +232,8 @@
 
                     getLogger().info( "  " + segment );
 
-                    getLogger().info("This project has been banned from further executions due to previous failures." );
+                    getLogger().info(
+                        "This project has been banned from further executions due to previous failures." );
 
                     line();
                 }
@@ -287,7 +286,8 @@
 
                         getLogger().info( "  " + segment );
 
-                        getLogger().info( "This project has been banned from further executions due to previous failures." );
+                        getLogger().info(
+                            "This project has been banned from further executions due to previous failures." );
 
                         line();
                     }
@@ -296,14 +296,9 @@
         }
     }
 
-    private void executeGoalAndHandleFailures( String task,
-                                               MavenSession session,
-                                               MavenProject project,
-                                               EventDispatcher dispatcher,
-                                               String event,
-                                               ReactorManager rm,
-                                               long buildStartTime,
-                                               String target )
+    private void executeGoalAndHandleFailures( String task, MavenSession session, MavenProject project,
+                                               EventDispatcher dispatcher, String event, ReactorManager rm,
+                                               long buildStartTime, String target )
         throws BuildFailureException, LifecycleExecutionException
     {
         try
@@ -847,12 +842,41 @@
                                 lifecycleGoal = goal;
                             }
 
+                            Xpp3Dom configuration = (Xpp3Dom) exec.getConfiguration();
+                            if ( phase.getConfiguration() != null )
+                            {
+                                configuration = Xpp3Dom.mergeXpp3Dom( new Xpp3Dom( (Xpp3Dom) phase.getConfiguration() ),
+                                                                      configuration );
+                            }
+
                             MojoDescriptor desc = getMojoDescriptor( lifecyclePluginDescriptor, lifecycleGoal );
-                            MojoExecution mojoExecution = new MojoExecution( desc, (Xpp3Dom) exec.getConfiguration() );
+                            MojoExecution mojoExecution = new MojoExecution( desc, configuration );
                             addToLifecycleMappings( lifecycleMappings, phase.getId(), mojoExecution,
                                                     session.getSettings() );
                         }
                     }
+
+                    if ( phase.getConfiguration() != null )
+                    {
+                        // Merge in general configuration for a phase.
+                        // TODO: this is all kind of backwards from the POMM. Let's align it all under 2.1.
+                        //   We should create a new lifecycle executor for modelVersion >5.0.0
+                        for ( Iterator j = lifecycleMappings.values().iterator(); j.hasNext(); )
+                        {
+                            List tasks = (List) j.next();
+
+                            for ( Iterator k = tasks.iterator(); k.hasNext(); )
+                            {
+                                MojoExecution exec = (MojoExecution) k.next();
+
+                                Xpp3Dom configuration = Xpp3Dom.mergeXpp3Dom(
+                                    new Xpp3Dom( (Xpp3Dom) phase.getConfiguration() ), exec.getConfiguration() );
+
+                                exec.setConfiguration( configuration );
+                            }
+                        }
+                    }
+
                 }
             }
 
@@ -966,9 +990,9 @@
         throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
     {
         Map mappings = findMappingsForLifecycle( session, project, lifecycle );
-        
+
         List optionalMojos = findOptionalMojosForLifecycle( session, project, lifecycle );
-        
+
         Map lifecycleMappings = new HashMap();
 
         for ( Iterator i = lifecycle.getPhases().iterator(); i.hasNext(); )
@@ -984,8 +1008,9 @@
                     String goal = tok.nextToken().trim();
 
                     // Not from the CLI, don't use prefix
-                    MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, project, selectedPhase, false, optionalMojos.contains( goal ) );
-                    
+                    MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, project, selectedPhase, false,
+                                                                       optionalMojos.contains( goal ) );
+
                     if ( mojoDescriptor == null )
                     {
                         continue;
@@ -1068,7 +1093,7 @@
 
         LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session
             .getSettings(), session.getLocalRepository() );
-        
+
         if ( m != null )
         {
             optionalMojos = m.getOptionalMojos( lifecycle.getId() );
@@ -1083,10 +1108,11 @@
             }
             catch ( ComponentLookupException e )
             {
-                getLogger().debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " + lifecycle.getId() + ". Error: " + e.getMessage(), e );
+                getLogger().debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " +
+                    lifecycle.getId() + ". Error: " + e.getMessage(), e );
             }
         }
-        
+
         if ( optionalMojos == null )
         {
             optionalMojos = Collections.EMPTY_LIST;
@@ -1401,9 +1427,9 @@
             {
                 if ( !canUsePrefix )
                 {
-                    String msg = "Mapped-prefix lookup of mojos are only supported from direct invocation. "
-                        + "Please use specification of the form groupId:artifactId[:version]:goal instead. "
-                        + "(Offending mojo: \'" + task + "\', invoked via: \'" + invokedVia + "\')";
+                    String msg = "Mapped-prefix lookup of mojos are only supported from direct invocation. " +
+                        "Please use specification of the form groupId:artifactId[:version]:goal instead. " +
+                        "(Offending mojo: \'" + task + "\', invoked via: \'" + invokedVia + "\')";
                     throw new LifecycleExecutionException( msg );
                 }
 
@@ -1479,8 +1505,8 @@
             }
             else
             {
-                String message = "Invalid task '" + task + "': you must specify a valid lifecycle phase, or"
-                    + " a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
+                String message = "Invalid task '" + task + "': you must specify a valid lifecycle phase, or" +
+                    " a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
                 throw new BuildFailureException( message );
             }
 
@@ -1522,7 +1548,7 @@
                 throw e;
             }
         }
-        
+
         return null;
     }
 

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java?rev=379491&r1=379490&r2=379491&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java Tue Feb 21 07:36:04 2006
@@ -34,7 +34,7 @@
 
     private final MojoDescriptor mojoDescriptor;
 
-    private final Xpp3Dom configuration;
+    private Xpp3Dom configuration;
 
     private List forkedExecutions = new ArrayList();
 
@@ -94,5 +94,10 @@
     public List getForkedExecutions()
     {
         return forkedExecutions;
+    }
+
+    public void setConfiguration( Xpp3Dom configuration )
+    {
+        this.configuration = configuration;
     }
 }

Modified: maven/components/trunk/maven-plugin-descriptor/src/main/mdo/lifecycle.mdo
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/mdo/lifecycle.mdo?rev=379491&r1=379490&r2=379491&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-descriptor/src/main/mdo/lifecycle.mdo (original)
+++ maven/components/trunk/maven-plugin-descriptor/src/main/mdo/lifecycle.mdo Tue Feb 21 07:36:04 2006
@@ -72,6 +72,12 @@
             <multiplicity>*</multiplicity>
           </association>
         </field>
+        <field>
+          <name>configuration</name>
+          <version>1.0.0</version>
+          <type>DOM</type>
+          <description>Configuration to pass to all goals run in this phase.</description>
+        </field>
       </fields>
     </class>
     <class>