You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/08/24 20:17:13 UTC

svn commit: r807327 - /maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java

Author: bentmann
Date: Mon Aug 24 18:17:13 2009
New Revision: 807327

URL: http://svn.apache.org/viewvc?rev=807327&view=rev
Log:
o Cleaned up code

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

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=807327&r1=807326&r2=807327&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 Aug 24 18:17:13 2009
@@ -17,6 +17,7 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -163,6 +164,20 @@
             return;
         }
 
+        if ( logger.isDebugEnabled() )
+        {
+            logger.debug( "=== REACTOR BUILD PLAN ===" );
+
+            for ( ProjectBuild projectBuild : projectBuilds )
+            {
+                logger.debug( "------------------" );
+                logger.debug( "Project: " + projectBuild.project.getId() );
+                logger.debug( "Tasks:   " + projectBuild.taskSegment.tasks );
+            }
+
+            logger.debug( "==========================" );
+        }
+
         ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
 
         RepositoryRequest repositoryRequest = getRepositoryRequest( session, null );
@@ -196,20 +211,11 @@
                 }
 
                 MavenExecutionPlan executionPlan =
-                    calculateProjectExecutionPlan( session, currentProject, projectBuild.taskSegment );
-
-                // TODO: once we have calculated the build plan then we should accurately be able to download
-                // the project dependencies. Having it happen in the plugin manager is a tangled mess. We can optimize
-                // this later by looking at the build plan. Would be better to just batch download everything required
-                // by the reactor.
-
-                repositoryRequest.setRemoteRepositories( currentProject.getRemoteArtifactRepositories() );
-                projectDependenciesResolver.resolve( currentProject, executionPlan.getRequiredResolutionScopes(),
-                                                     repositoryRequest );
+                    calculateExecutionPlan( session, currentProject, projectBuild.taskSegment );
 
                 if ( logger.isDebugEnabled() )
                 {
-                    logger.debug( "=== BUILD PLAN ===" );
+                    logger.debug( "=== PROJECT BUILD PLAN ===" );
                     logger.debug( "Project:       " + currentProject );
 
                     for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
@@ -221,9 +227,18 @@
                         logger.debug( "Configuration: " + String.valueOf( mojoExecution.getConfiguration() ) );
                     }
 
-                    logger.debug( "==================" );
+                    logger.debug( "==========================" );
                 }
 
+                // TODO: once we have calculated the build plan then we should accurately be able to download
+                // the project dependencies. Having it happen in the plugin manager is a tangled mess. We can optimize
+                // this later by looking at the build plan. Would be better to just batch download everything required
+                // by the reactor.
+
+                repositoryRequest.setRemoteRepositories( currentProject.getRemoteArtifactRepositories() );
+                projectDependenciesResolver.resolve( currentProject, executionPlan.getRequiredResolutionScopes(),
+                                                     repositoryRequest );
+
                 for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
                 {
                     execute( currentProject, session, mojoExecution );
@@ -428,8 +443,8 @@
         return projectBuilds;
     }
 
-    private MavenExecutionPlan calculateProjectExecutionPlan( MavenSession session, MavenProject project,
-                                                              TaskSegment taskSegment )
+    private MavenExecutionPlan calculateExecutionPlan( MavenSession session, MavenProject project,
+                                                       TaskSegment taskSegment )
         throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
         PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
         NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
@@ -625,62 +640,22 @@
 
     }
 
-    // TODO: refactor this to reuse the same code as for the reactor build
     public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
         throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
         MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
         PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
         PluginVersionResolutionException
     {
-        MavenProject project = session.getCurrentProject();
+        List<TaskSegment> taskSegments = calculateTaskSegments( session, Arrays.asList( tasks ) );
 
-        List<MojoExecution> lifecyclePlan = new ArrayList<MojoExecution>();
+        TaskSegment mergedSegment = new TaskSegment( false );
 
-        Set<String> requiredDependencyResolutionScopes = new HashSet<String>();
-
-        for ( String task : tasks )
-        {
-            if ( task.indexOf( ":" ) > 0 )
-            {
-                calculateExecutionForIndividualGoal( session, lifecyclePlan, task );
-            }
-            else
-            {
-                calculateExecutionForLifecyclePhase( session, project, lifecyclePlan, task );
-            }
-        }
-
-        // 7. Now we create the correct configuration for the mojo to execute.
-        // 
-        for ( MojoExecution mojoExecution : lifecyclePlan )
+        for ( TaskSegment taskSegment : taskSegments )
         {
-            // These are bits that look like this:
-            //
-            // org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
-            //                        
-
-            MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
-
-            if ( mojoDescriptor == null )
-            {
-                mojoDescriptor =
-                    pluginManager.getMojoDescriptor( mojoExecution.getPlugin(), mojoExecution.getGoal(),
-                                                     getRepositoryRequest( session, project ) );
-
-                mojoExecution.setMojoDescriptor( mojoDescriptor );
-            }
-
-            populateMojoExecutionConfiguration( project, mojoExecution,
-                                                MojoExecution.Source.CLI.equals( mojoExecution.getSource() ) );
-
-            extractMojoConfiguration( mojoExecution );
-
-            calculateForkedExecutions( mojoExecution, session, project, new HashSet<MojoDescriptor>() );
-
-            collectDependencyResolutionScopes( requiredDependencyResolutionScopes, mojoExecution );
+            mergedSegment.tasks.addAll( taskSegment.tasks );
         }
 
-        return new MavenExecutionPlan( lifecyclePlan, requiredDependencyResolutionScopes );
+        return calculateExecutionPlan( session, session.getCurrentProject(), mergedSegment );
     }
 
     private RepositoryRequest getRepositoryRequest( MavenSession session, MavenProject project )
@@ -714,69 +689,6 @@
         }
     }
 
-    private void calculateExecutionForIndividualGoal( MavenSession session, List<MojoExecution> lifecyclePlan,
-                                                      String goal )
-        throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
-        MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
-        PluginVersionResolutionException
-    {
-        // If this is a goal like "mvn modello:java" and the POM looks like the following:
-        //
-        // <project>
-        //   <modelVersion>4.0.0</modelVersion>
-        //   <groupId>org.apache.maven.plugins</groupId>
-        //   <artifactId>project-plugin-level-configuration-only</artifactId>
-        //   <version>1.0.1</version>
-        //   <build>
-        //     <plugins>
-        //       <plugin>
-        //         <groupId>org.codehaus.modello</groupId>
-        //         <artifactId>modello-maven-plugin</artifactId>
-        //         <version>1.0.1</version>
-        //         <configuration>
-        //           <version>1.1.0</version>
-        //           <models>
-        //             <model>src/main/mdo/remote-resources.mdo</model>
-        //           </models>
-        //         </configuration>
-        //       </plugin>
-        //     </plugins>
-        //   </build>
-        // </project>                
-        //
-        // We want to 
-        //
-        // - take the plugin/configuration in the POM and merge it with the plugin's default configuration found in its plugin.xml
-        // - attach that to the MojoExecution for its configuration
-        // - give the MojoExecution an id of default-<goal>.
-        
-        MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, session.getCurrentProject() );
-
-        MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, "default-cli", MojoExecution.Source.CLI );
-
-        lifecyclePlan.add( mojoExecution );        
-    }
-    
-    // 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)
-    // 4. Bind those mojos found in the lifecycle mapping for the packaging to the lifecycle
-    // 5. Bind mojos specified in the project itself to the lifecycle    
-    private void calculateExecutionForLifecyclePhase( MavenSession session, MavenProject project,
-                                                      List<MojoExecution> lifecyclePlan, String lifecyclePhase )
-        throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
-        MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
-        LifecyclePhaseNotFoundException
-    {
-        Map<String, List<MojoExecution>> phaseToMojoMapping =
-            calculateLifecycleMappings( session, project, lifecyclePhase );
-
-        for ( List<MojoExecution> mojoExecutions : phaseToMojoMapping.values() )
-        {
-            lifecyclePlan.addAll( mojoExecutions );
-        }
-    }
-
     private Map<String, List<MojoExecution>> calculateLifecycleMappings( MavenSession session, MavenProject project,
                                                                          String lifecyclePhase )
         throws LifecyclePhaseNotFoundException, PluginNotFoundException, PluginResolutionException,