Throwing exception if infinite loop detected in phase vs. executePhase...this is probably not optimal, but it's a start.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@233104 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-08-17 02:05:04 +00:00
parent 345798c7ab
commit 2adbbad9da
1 changed files with 54 additions and 6 deletions

View File

@ -524,12 +524,51 @@ public class DefaultLifecycleExecutor
} }
} }
} }
String mojoPhase = findFirstPhaseBindingForMojo( mojoDescriptor, lifecycleMappings );
int mojoPhaseIdx = phases.indexOf( mojoPhase );
int execPhaseIdx = phases.indexOf( task );
if ( mojoPhaseIdx > -1 && mojoPhaseIdx <= execPhaseIdx )
{
throw new LifecycleExecutionException( "Infinite loop detected in build process. Mojo: \'"
+ mojoDescriptor.getGoal() + "\' declares executePhase of: \'" + task
+ "\' but is itself bound to phase: \'" + mojoPhase
+ "\'. This will result in infinite forking of build execution." );
}
MavenProject executionProject = new MavenProject( project ); MavenProject executionProject = new MavenProject( project );
executeGoalWithLifecycle( task, session, lifecycleMappings, executionProject ); executeGoalWithLifecycle( task, session, lifecycleMappings, executionProject );
project.setExecutionProject( executionProject ); project.setExecutionProject( executionProject );
} }
private String findFirstPhaseBindingForMojo( MojoDescriptor mojoDescriptor, Map lifecycleMappings )
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
String mojoIdWithVersion = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId() + ":"
+ pluginDescriptor.getVersion() + ":" + mojoDescriptor.getGoal();
String mojoIdWithoutVersion = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId() + ":"
+ mojoDescriptor.getGoal();
for ( Iterator it = lifecycleMappings.entrySet().iterator(); it.hasNext(); )
{
Map.Entry entry = (Map.Entry) it.next();
String phase = (String) entry.getKey();
List tasks = (List) entry.getValue();
if ( tasks.contains( mojoIdWithVersion ) || tasks.contains( mojoIdWithoutVersion ) )
{
return phase;
}
}
return null;
}
private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project ) private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project )
throws ArtifactResolutionException, LifecycleExecutionException throws ArtifactResolutionException, LifecycleExecutionException
{ {
@ -792,14 +831,23 @@ public class DefaultLifecycleExecutor
if ( execution.isInheritanceApplied() || mojoDescriptor.isInheritedByDefault() ) if ( execution.isInheritanceApplied() || mojoDescriptor.isInheritedByDefault() )
{ {
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() ); MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() );
if ( execution.getPhase() != null )
{ String phase = execution.getPhase();
addToLifecycleMappings( phaseMap, execution.getPhase(), mojoExecution, settings );
} if ( phase == null )
else if ( mojoDescriptor.getPhase() != null )
{ {
// if the phase was not in the configuration, use the phase in the descriptor // if the phase was not in the configuration, use the phase in the descriptor
addToLifecycleMappings( phaseMap, mojoDescriptor.getPhase(), mojoExecution, settings ); phase = mojoDescriptor.getPhase();
}
if ( phase != null )
{
if ( mojoDescriptor.isDirectInvocationOnly() )
{
throw new LifecycleExecutionException( "Mojo: \'" + goal + "\' requires direct invocation. It cannot be used as part of the lifecycle (it was included via the POM)." );
}
addToLifecycleMappings( phaseMap, phase, mojoExecution, settings );
} }
} }
} }