From 6a7fdf038e4e708658d4d2251eea979e41f657c2 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Mon, 24 Aug 2009 18:17:13 +0000 Subject: [PATCH] o Cleaned up code git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@807327 13f79535-47bb-0310-9956-ffa450edef68 --- .../lifecycle/DefaultLifecycleExecutor.java | 156 ++++-------------- 1 file changed, 34 insertions(+), 122 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 17165172ee..1d9a485d62 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -17,6 +17,7 @@ package org.apache.maven.lifecycle; 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 @@ public class DefaultLifecycleExecutor 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 @@ public class DefaultLifecycleExecutor } 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 @@ public class DefaultLifecycleExecutor 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 @@ public class DefaultLifecycleExecutor 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 @@ public class DefaultLifecycleExecutor } - // 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 taskSegments = calculateTaskSegments( session, Arrays.asList( tasks ) ); - List lifecyclePlan = new ArrayList(); + TaskSegment mergedSegment = new TaskSegment( false ); - Set requiredDependencyResolutionScopes = new HashSet(); - - for ( String task : tasks ) + for ( TaskSegment taskSegment : taskSegments ) { - if ( task.indexOf( ":" ) > 0 ) - { - calculateExecutionForIndividualGoal( session, lifecyclePlan, task ); - } - else - { - calculateExecutionForLifecyclePhase( session, project, lifecyclePlan, task ); - } + mergedSegment.tasks.addAll( taskSegment.tasks ); } - // 7. Now we create the correct configuration for the mojo to execute. - // - for ( MojoExecution mojoExecution : lifecyclePlan ) - { - // 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() ); - - collectDependencyResolutionScopes( requiredDependencyResolutionScopes, mojoExecution ); - } - - return new MavenExecutionPlan( lifecyclePlan, requiredDependencyResolutionScopes ); + return calculateExecutionPlan( session, session.getCurrentProject(), mergedSegment ); } private RepositoryRequest getRepositoryRequest( MavenSession session, MavenProject project ) @@ -714,69 +689,6 @@ public class DefaultLifecycleExecutor } } - private void calculateExecutionForIndividualGoal( MavenSession session, List 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: - // - // - // 4.0.0 - // org.apache.maven.plugins - // project-plugin-level-configuration-only - // 1.0.1 - // - // - // - // org.codehaus.modello - // modello-maven-plugin - // 1.0.1 - // - // 1.1.0 - // - // src/main/mdo/remote-resources.mdo - // - // - // - // - // - // - // - // 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-. - - 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 lifecyclePlan, String lifecyclePhase ) - throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, - MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, - LifecyclePhaseNotFoundException - { - Map> phaseToMojoMapping = - calculateLifecycleMappings( session, project, lifecyclePhase ); - - for ( List mojoExecutions : phaseToMojoMapping.values() ) - { - lifecyclePlan.addAll( mojoExecutions ); - } - } - private Map> calculateLifecycleMappings( MavenSession session, MavenProject project, String lifecyclePhase ) throws LifecyclePhaseNotFoundException, PluginNotFoundException, PluginResolutionException,