o have the build plan take into consideration multiple tasks, so the calculation of the build plan can take in any number lifecycle phases, or individual goals and you will get the fully fleshed out configurations

o one thing that's apparent is that it is not possible to only collect the metadata about the plugins that will execute. if the plugin.xml files were actually available in the repository outside of the plugin's JAR then the calculation could be made without having to crack open the JAR. i can't have a real plan per se when i have to grab the plugin JAR anywhere to open it and get the metadata. ideally someone should be able to see the build plan and optimize it and if plugins were removed they those will never have a requirement of being downloaded. Deploying the plugin metadata along side the plugin as an attached artifact or indexing the information and made available for querying would be very useful.

o now that the build plan is calculated and the project dependencies downloading has been decoupled from the plugin manager i can make a proper analysis of all he dependencies for all the project and start making optimized requests for downloading



git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@776690 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-05-20 13:23:56 +00:00
parent 8637701384
commit 397dc841a7
4 changed files with 270 additions and 276 deletions

View File

@ -116,12 +116,17 @@ public class DefaultLifecycleExecutor
public void execute( MavenSession session )
{
// TODO: Use a listener here instead of loggers
logger.info( "Build Order:" );
logger.info( "" );
for( MavenProject project : session.getProjects() )
{
logger.info( project.getName() );
}
logger.info( "" );
MavenProject rootProject = session.getTopLevelProject();
@ -146,13 +151,11 @@ public class DefaultLifecycleExecutor
{
session.setCurrentProject( currentProject );
for ( String goal : goals )
{
List<MojoExecution> lifecyclePlan;
try
{
lifecyclePlan = calculateBuildPlan( goal, session );
lifecyclePlan = calculateBuildPlan( session, goals.toArray( new String[] {} ) );
}
catch ( Exception e )
{
@ -167,7 +170,7 @@ public class DefaultLifecycleExecutor
// mojoDescriptor.isDependencyResolutionRequired() is actually the scope of the dependency resolution required, not a boolean ... yah.
try
{
downloadProjectDependencies( session, Artifact.SCOPE_TEST /**mojoDescriptor.isDependencyResolutionRequired()*/ );
downloadProjectDependencies( session, Artifact.SCOPE_TEST /** mojoDescriptor.isDependencyResolutionRequired()*/ );
}
catch ( ArtifactNotFoundException e )
{
@ -189,9 +192,8 @@ public class DefaultLifecycleExecutor
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
logger.debug( "------------------" );
logger.debug( "Goal: " + pluginDescriptor.getGroupId() + ':' + pluginDescriptor.getArtifactId() + ':'
+ pluginDescriptor.getVersion() + ':' + mojoDescriptor.getGoal() + ':'
+ mojoExecution.getExecutionId() );
logger.debug( "Goal: " + pluginDescriptor.getGroupId() + ':' + pluginDescriptor.getArtifactId() + ':' + pluginDescriptor.getVersion() + ':' + mojoDescriptor.getGoal()
+ ':' + mojoExecution.getExecutionId() );
logger.debug( "Configuration: " + String.valueOf( mojoExecution.getConfiguration() ) );
}
logger.debug( "==================" );
@ -210,7 +212,7 @@ public class DefaultLifecycleExecutor
return;
}
}
}
}
finally
{
@ -219,20 +221,12 @@ public class DefaultLifecycleExecutor
}
}
private String executionDescription( MojoExecution me, MavenProject project )
{
PluginDescriptor pd = me.getMojoDescriptor().getPluginDescriptor();
StringBuffer sb = new StringBuffer();
sb.append( "Executing " + pd.getArtifactId() + "[" + pd.getVersion() + "]: " + me.getMojoDescriptor().getGoal() + " on " + project.getArtifactId() );
return sb.toString();
}
// 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
public List<MojoExecution> calculateBuildPlan( String task, MavenSession session )
public List<MojoExecution> calculateBuildPlan( MavenSession session, String... tasks )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException
{
MavenProject project = session.getCurrentProject();
@ -241,6 +235,9 @@ public class DefaultLifecycleExecutor
List<MojoExecution> lifecyclePlan = new ArrayList<MojoExecution>();
for ( String task : tasks )
{
if ( task.indexOf( ":" ) > 0 )
{
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session );
@ -251,7 +248,6 @@ public class DefaultLifecycleExecutor
}
else
{
// 1.
//
// Based on the lifecycle phase we are given, let's find the corresponding lifecycle.
@ -357,6 +353,9 @@ public class DefaultLifecycleExecutor
}
}
}
}
// 7. Now we create the correct configuration for the mojo to execute.
//TODO: this needs to go to the model builder.
@ -373,11 +372,18 @@ public class DefaultLifecycleExecutor
lifecyclePlan.add( mojoExecution );
}
}
return lifecyclePlan;
}
private String executionDescription( MojoExecution me, MavenProject project )
{
PluginDescriptor pd = me.getMojoDescriptor().getPluginDescriptor();
StringBuffer sb = new StringBuffer();
sb.append( "Executing " + pd.getArtifactId() + "[" + pd.getVersion() + "]: " + me.getMojoDescriptor().getGoal() + " on " + project.getArtifactId() );
return sb.toString();
}
private MojoExecution getMojoExecution( MavenProject project, MojoDescriptor mojoDescriptor )
{
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
@ -743,62 +749,12 @@ public class DefaultLifecycleExecutor
return dom;
}
// assign all values
// validate everything is fine
private Xpp3Dom processConfiguration( MavenSession session, MojoExecution mojoExecution )
{
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoExecution );
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
Map<String,Parameter> parameters = mojoDescriptor.getParameterMap();
Xpp3Dom configuration = mojoExecution.getConfiguration();
for( Xpp3Dom c : configuration.getChildren() )
{
String configurationName = c.getName();
Parameter parameter = parameters.get( configurationName );
// Read-only
if ( !parameter.isEditable() )
{
}
try
{
Object value = expressionEvaluator.evaluate( c.getValue() );
if ( value == null )
{
String e = c.getAttribute( "default-value" );
if ( e != null )
{
value = expressionEvaluator.evaluate( e );
}
}
if ( value instanceof String || value instanceof File )
c.setValue( value.toString() );
}
catch ( ExpressionEvaluationException e )
{
// do nothing
}
}
return mojoExecution.getConfiguration();
}
private void downloadProjectDependencies( MavenSession session, String scope )
throws ArtifactResolutionException, ArtifactNotFoundException
{
MavenProject project = session.getCurrentProject();
Artifact artifact =
repositorySystem.createProjectArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion() );
Artifact artifact = repositorySystem.createProjectArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion() );
artifact.setFile( project.getFile() );
ArtifactFilter filter = new ScopeArtifactFilter( scope );

View File

@ -52,7 +52,7 @@ public interface LifecycleExecutor
* @return
* @throws LifecycleExecutionException
*/
List<MojoExecution> calculateBuildPlan( String lifecyclePhase, MavenSession session )
List<MojoExecution> calculateBuildPlan( MavenSession session, String... tasks )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException;
// For a given project packaging find all the plugins that are bound to any registered

View File

@ -62,7 +62,7 @@ public class LifecycleExecutorTest
MavenSession session = createMavenSession( pom );
assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0", session.getCurrentProject().getVersion() );
List<MojoExecution> lifecyclePlan = lifecycleExecutor.calculateBuildPlan( "resources:resources", session );
List<MojoExecution> lifecyclePlan = lifecycleExecutor.calculateBuildPlan( session, "resources:resources" );
assertEquals( 1, lifecyclePlan.size() );
MojoExecution mojoExecution = lifecyclePlan.get( 0 );
assertNotNull( mojoExecution );
@ -80,7 +80,7 @@ public class LifecycleExecutorTest
MavenSession session = createMavenSession( pom );
assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0", session.getCurrentProject().getVersion() );
List<MojoExecution> lifecyclePlan = lifecycleExecutor.calculateBuildPlan( "clean", session );
List<MojoExecution> lifecyclePlan = lifecycleExecutor.calculateBuildPlan( session, "clean" );
assertEquals( 1, lifecyclePlan.size() );
MojoExecution mojoExecution = lifecyclePlan.get( 0 );
assertNotNull( mojoExecution );
@ -89,6 +89,42 @@ public class LifecycleExecutorTest
assertEquals( "2.2", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() );
}
// We need to take in multiple lifecycles
public void testCalculationOfBuildPlanTasksOfTheCleanLifecycleAndTheInstallLifecycle()
throws Exception
{
File pom = getProject( "project-with-additional-lifecycle-elements" );
MavenSession session = createMavenSession( pom );
assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0", session.getCurrentProject().getVersion() );
List<MojoExecution> lifecyclePlan = lifecycleExecutor.calculateBuildPlan( session, "clean", "install" );
//[01] clean:clean
//[02] resources:resources
//[03] compiler:compile
//[04] plexus-component-metadata:generate-metadata
//[05] resources:testResources
//[06] compiler:testCompile
//[07] plexus-component-metadata:generate-test-metadata
//[08] surefire:test
//[09] jar:jar
//[10] install:install
//
assertEquals( 10, lifecyclePlan.size() );
assertEquals( "clean:clean", lifecyclePlan.get( 0 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "resources:resources", lifecyclePlan.get( 1 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "compiler:compile", lifecyclePlan.get( 2 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "plexus-component-metadata:generate-metadata", lifecyclePlan.get( 3 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "resources:testResources", lifecyclePlan.get( 4 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "compiler:testCompile", lifecyclePlan.get( 5 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "plexus-component-metadata:generate-test-metadata", lifecyclePlan.get( 6 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "surefire:test", lifecyclePlan.get( 7 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "jar:jar", lifecyclePlan.get( 8 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "install:install", lifecyclePlan.get( 9 ).getMojoDescriptor().getFullGoalName() );
}
public void testCalculationOfBuildPlanWithIndividualTaskOfTheCleanCleanGoal()
throws Exception
{
@ -98,7 +134,7 @@ public class LifecycleExecutorTest
MavenSession session = createMavenSession( pom );
assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0", session.getCurrentProject().getVersion() );
List<MojoExecution> lifecyclePlan = lifecycleExecutor.calculateBuildPlan( "clean:clean", session );
List<MojoExecution> lifecyclePlan = lifecycleExecutor.calculateBuildPlan( session, "clean:clean" );
assertEquals( 1, lifecyclePlan.size() );
MojoExecution mojoExecution = lifecyclePlan.get( 0 );
assertNotNull( mojoExecution );
@ -114,16 +150,18 @@ public class LifecycleExecutorTest
MavenSession session = createMavenSession( pom );
assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0", session.getCurrentProject().getVersion() );
List<MojoExecution> lifecyclePlan = lifecycleExecutor.calculateBuildPlan( "package", session );
List<MojoExecution> lifecyclePlan = lifecycleExecutor.calculateBuildPlan( session, "package" );
// resources:resources
// compiler:compile
// plexus-component-metadata:generate-metadata
// resources:testResources
// compiler:testCompile
// plexus-component-metadata:generate-test-metadata
// surefire:test
// jar:jar
//[01] resources:resources
//[02] compiler:compile
//[03] plexus-component-metadata:generate-metadata
//[04] resources:testResources
//[05] compiler:testCompile
//[06] plexus-component-metadata:generate-test-metadata
//[07] surefire:test
//[08] jar:jar
//
assertEquals( 8, lifecyclePlan.size() );
assertEquals( "resources:resources", lifecyclePlan.get( 0 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "compiler:compile", lifecyclePlan.get( 1 ).getMojoDescriptor().getFullGoalName() );

View File

@ -49,7 +49,7 @@ public class EmptyLifecycleExecutor
implements LifecycleExecutor
{
public List<MojoExecution> calculateBuildPlan( String lifecyclePhase, MavenSession session )
public List<MojoExecution> calculateBuildPlan( MavenSession session, String... tasks )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException
{
return Collections.emptyList();