o slight lifecycle mixup with executions, temporary fix but the bootstrap works

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@771991 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-05-05 22:22:06 +00:00
parent 5ec5c90c89
commit 5d077ce8e5
1 changed files with 78 additions and 51 deletions

View File

@ -202,7 +202,7 @@ public class DefaultLifecycleExecutor
logger.info( executionDescription( mojoExecution, project ) ); logger.info( executionDescription( mojoExecution, project ) );
// mojoExecution.getMojoDescriptor().getRealm().display(); // mojoExecution.getMojoDescriptor().getRealm().display();
// System.out.println( "!!!"); // System.out.println( "!!!");
System.out.println( mojoExecution.getConfiguration() ); // System.out.println( mojoExecution.getConfiguration() );
pluginManager.executeMojo( session, mojoExecution ); pluginManager.executeMojo( session, mojoExecution );
} }
catch ( PluginExecutionException e ) catch ( PluginExecutionException e )
@ -278,9 +278,12 @@ public class DefaultLifecycleExecutor
// Create an ordered Map of the phases in the lifecycle to a list of mojos to execute. // Create an ordered Map of the phases in the lifecycle to a list of mojos to execute.
Map<String,List<String>> phaseToMojoMapping = new LinkedHashMap<String,List<String>>(); Map<String,List<String>> phaseToMojoMapping = new LinkedHashMap<String,List<String>>();
// 4. // 4.
//TODO: need to separate the lifecycles
for ( String phase : lifecycle.getPhases() ) for ( String phase : lifecycle.getPhases() )
{ {
List<String> mojos = new ArrayList<String>(); List<String> mojos = new ArrayList<String>();
// Bind the mojos in the lifecycle mapping for the packaging to the lifecycle itself. If // Bind the mojos in the lifecycle mapping for the packaging to the lifecycle itself. If
@ -293,19 +296,12 @@ public class DefaultLifecycleExecutor
mojos.add( mojo ); mojos.add( mojo );
} }
phaseToMojoMapping.put( phase, mojos ); phaseToMojoMapping.put( phase, mojos );
// We only want to execute up to and including the specified lifecycle phase.
if ( phase.equals( lifecyclePhase ) )
{
break;
}
} }
// 5. // 5. Just build up the list of mojos that will execute for every phase.
// //
// We are only interested in the phases that correspond to the lifecycle we are trying to run. If we are running the "clean" // This will be useful for having the complete build plan and then we can filter/optimize later.
// lifecycle we are not interested in goals -- like "generate-sources -- that belong to the default lifecycle.
// //
for( Plugin plugin : project.getBuild().getPlugins() ) for( Plugin plugin : project.getBuild().getPlugins() )
{ {
@ -313,12 +309,23 @@ public class DefaultLifecycleExecutor
{ {
// if the phase is specified then I don't have to go fetch the plugin yet and pull it down // if the phase is specified then I don't have to go fetch the plugin yet and pull it down
// to examine the phase it is associated to. // to examine the phase it is associated to.
if ( execution.getPhase() != null && execution.getPhase().equals( lifecyclePhase ) ) if ( execution.getPhase() != null )
{ {
for( String goal : execution.getGoals() ) for( String goal : execution.getGoals() )
{ {
String s = plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() + ":" + goal; String s = plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() + ":" + goal;
phaseToMojoMapping.get( execution.getPhase() ).add( s );
if ( phaseToMojoMapping.get( execution.getPhase() ) == null )
{
// This is happening because executions in the POM are getting mixed into the clean lifecycle
// So for the lifecycle mapping we need a map with the phases as keys so we can easily check
// if this phase belongs to the given lifecycle. this shows the system is messed up. this
// shouldn't happen.
System.out.println( execution.getPhase() + "?????????????");
phaseToMojoMapping.put( execution.getPhase(), new ArrayList<String>() );
}
phaseToMojoMapping.get( execution.getPhase() ).add( s );
} }
} }
// if not then i need to grab the mojo descriptor and look at // if not then i need to grab the mojo descriptor and look at
@ -330,58 +337,78 @@ public class DefaultLifecycleExecutor
String s = plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() + ":" + goal; String s = plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() + ":" + goal;
MojoDescriptor md = getMojoDescriptor( s, session.getCurrentProject(), session.getLocalRepository() ); MojoDescriptor md = getMojoDescriptor( s, session.getCurrentProject(), session.getLocalRepository() );
// need to know if this plugin belongs to a phase in the lifecycle that's running
if ( md.getPhase() != null && phaseToMojoMapping.get( md.getPhase() ) != null ) if ( md.getPhase() != null && phaseToMojoMapping.get( md.getPhase() ) != null )
{ {
phaseToMojoMapping.get( md.getPhase() ).add( s ); phaseToMojoMapping.get( md.getPhase() ).add( s );
} }
//TODO Here we need to break when we have reached the desired phase.
} }
} }
} }
} }
List<MojoExecution> lifecyclePlan = new ArrayList<MojoExecution>(); // 6.
//
// We need to turn this into a set of MojoExecutions // We are only interested in the phases that correspond to the lifecycle we are trying to run. If we are running the "clean"
for( List<String> mojos : phaseToMojoMapping.values() ) // lifecycle we are not interested in goals -- like "generate-sources -- that belong to the default lifecycle.
//
// We only want to execute up to and including the specified lifecycle phase.
// if ( phase.equals( lifecyclePhase ) )
//{
// break;
//}
List<String> phasesWithMojosToExecute = new ArrayList<String>();
for( String phase : phaseToMojoMapping.keySet() )
{ {
for( String mojo : mojos ) phasesWithMojosToExecute.addAll( phaseToMojoMapping.get( phase ) );
if ( phase.equals( lifecyclePhase ) )
{ {
// These are bits that look like this: break;
// }
// org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process }
//
MojoDescriptor mojoDescriptor = getMojoDescriptor( mojo, project, session.getLocalRepository() );
// 7. Now we create the correct configuration for the mojo to execute.
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor ); //TODO: this needs to go to the model builder.
String g = mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId(); List<MojoExecution> lifecyclePlan = new ArrayList<MojoExecution>();
String a = mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId(); for ( String mojo : phasesWithMojosToExecute )
{
Plugin p = project.getPlugin( g + ":" + a ); // These are bits that look like this:
//
for( PluginExecution e : p.getExecutions() ) // org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
//
MojoDescriptor mojoDescriptor = getMojoDescriptor( mojo, project, session.getLocalRepository() );
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
String g = mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId();
String a = mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId();
Plugin p = project.getPlugin( g + ":" + a );
for ( PluginExecution e : p.getExecutions() )
{
for ( String goal : e.getGoals() )
{ {
for( String goal : e.getGoals() ) if ( mojoDescriptor.getGoal().equals( goal ) )
{ {
if ( mojoDescriptor.getGoal().equals( goal ) ) Xpp3Dom executionConfiguration = (Xpp3Dom) e.getConfiguration();
{
Xpp3Dom executionConfiguration = (Xpp3Dom) e.getConfiguration();
Xpp3Dom mojoConfiguration = Xpp3Dom mojoConfiguration = extractMojoConfiguration( executionConfiguration, mojoDescriptor );
extractMojoConfiguration( executionConfiguration, mojoDescriptor );
mojoExecution.setConfiguration( mojoConfiguration ); mojoExecution.setConfiguration( mojoConfiguration );
}
} }
} }
lifecyclePlan.add( mojoExecution );
} }
}
lifecyclePlan.add( mojoExecution );
}
return lifecyclePlan; return lifecyclePlan;
} }