mirror of https://github.com/apache/maven.git
PR: MNG-1311
Added a stack of lifecycle fork-points that will be removed from each successively deeper level of forking in a cumulative manner, to prevent multi-node cycles in addition to simply blocking two-node cycles. The basic problem with the recursion check that was in there was a type mismatch on the contents of a java.util.List. It's fixed now. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@355383 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f4e9b5b409
commit
2e89dadbce
|
@ -65,6 +65,7 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Stack;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -439,17 +440,18 @@ public class DefaultLifecycleExecutor
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Stack forkEntryPoints = new Stack();
|
||||||
if ( getPhaseToLifecycleMap().containsKey( task ) )
|
if ( getPhaseToLifecycleMap().containsKey( task ) )
|
||||||
{
|
{
|
||||||
Lifecycle lifecycle = getLifecycleForPhase( task );
|
Lifecycle lifecycle = getLifecycleForPhase( task );
|
||||||
|
|
||||||
// we have a lifecycle phase, so lets bind all the necessary goals
|
// we have a lifecycle phase, so lets bind all the necessary goals
|
||||||
Map lifecycleMappings = constructLifecycleMappings( session, task, project, lifecycle );
|
Map lifecycleMappings = constructLifecycleMappings( session, task, project, lifecycle );
|
||||||
executeGoalWithLifecycle( task, session, lifecycleMappings, project, lifecycle );
|
executeGoalWithLifecycle( task, forkEntryPoints, session, lifecycleMappings, project, lifecycle );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
executeStandaloneGoal( task, session, project );
|
executeStandaloneGoal( task, forkEntryPoints, session, project );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( PluginNotFoundException e )
|
catch ( PluginNotFoundException e )
|
||||||
|
@ -458,15 +460,15 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeGoalWithLifecycle( String task, MavenSession session, Map lifecycleMappings,
|
private void executeGoalWithLifecycle( String task, Stack forkEntryPoints, MavenSession session,
|
||||||
MavenProject project, Lifecycle lifecycle )
|
Map lifecycleMappings, MavenProject project, Lifecycle lifecycle )
|
||||||
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
||||||
{
|
{
|
||||||
List goals = processGoalChain( task, lifecycleMappings, lifecycle );
|
List goals = processGoalChain( task, lifecycleMappings, lifecycle );
|
||||||
|
|
||||||
if ( !goals.isEmpty() )
|
if ( !goals.isEmpty() )
|
||||||
{
|
{
|
||||||
executeGoals( goals, session, project );
|
executeGoals( goals, forkEntryPoints, session, project );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -474,15 +476,15 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeStandaloneGoal( String task, MavenSession session, MavenProject project )
|
private void executeStandaloneGoal( String task, Stack forkEntryPoints, MavenSession session, MavenProject project )
|
||||||
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
||||||
{
|
{
|
||||||
// guaranteed to come from the CLI and not be part of a phase
|
// guaranteed to come from the CLI and not be part of a phase
|
||||||
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session, project, task, true );
|
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session, project, task, true );
|
||||||
executeGoals( Collections.singletonList( new MojoExecution( mojoDescriptor ) ), session, project );
|
executeGoals( Collections.singletonList( new MojoExecution( mojoDescriptor ) ), forkEntryPoints, session, project );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeGoals( List goals, MavenSession session, MavenProject project )
|
private void executeGoals( List goals, Stack forkEntryPoints, MavenSession session, MavenProject project )
|
||||||
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
||||||
{
|
{
|
||||||
for ( Iterator i = goals.iterator(); i.hasNext(); )
|
for ( Iterator i = goals.iterator(); i.hasNext(); )
|
||||||
|
@ -493,7 +495,11 @@ public class DefaultLifecycleExecutor
|
||||||
|
|
||||||
if ( mojoDescriptor.getExecutePhase() != null || mojoDescriptor.getExecuteGoal() != null )
|
if ( mojoDescriptor.getExecutePhase() != null || mojoDescriptor.getExecuteGoal() != null )
|
||||||
{
|
{
|
||||||
forkLifecycle( mojoDescriptor, session, project );
|
forkEntryPoints.push( mojoDescriptor );
|
||||||
|
|
||||||
|
forkLifecycle( mojoDescriptor, forkEntryPoints, session, project );
|
||||||
|
|
||||||
|
forkEntryPoints.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mojoDescriptor.isRequiresReports() )
|
if ( mojoDescriptor.isRequiresReports() )
|
||||||
|
@ -509,7 +515,11 @@ public class DefaultLifecycleExecutor
|
||||||
|
|
||||||
if ( descriptor.getExecutePhase() != null )
|
if ( descriptor.getExecutePhase() != null )
|
||||||
{
|
{
|
||||||
forkLifecycle( descriptor, session, project );
|
forkEntryPoints.push( descriptor );
|
||||||
|
|
||||||
|
forkLifecycle( descriptor, forkEntryPoints, session, project );
|
||||||
|
|
||||||
|
forkEntryPoints.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -692,7 +702,7 @@ public class DefaultLifecycleExecutor
|
||||||
return reports;
|
return reports;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forkLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project )
|
private void forkLifecycle( MojoDescriptor mojoDescriptor, Stack ancestorLifecycleForkers, MavenSession session, MavenProject project )
|
||||||
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
||||||
{
|
{
|
||||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
||||||
|
@ -710,18 +720,20 @@ public class DefaultLifecycleExecutor
|
||||||
|
|
||||||
line();
|
line();
|
||||||
|
|
||||||
forkProjectLifecycle( mojoDescriptor, session, reactorProject );
|
forkProjectLifecycle( mojoDescriptor, ancestorLifecycleForkers, session, reactorProject );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
forkProjectLifecycle( mojoDescriptor, session, project );
|
forkProjectLifecycle( mojoDescriptor, ancestorLifecycleForkers, session, project );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forkProjectLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project )
|
private void forkProjectLifecycle( MojoDescriptor mojoDescriptor, Stack forkEntryPoints, MavenSession session, MavenProject project )
|
||||||
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
|
||||||
{
|
{
|
||||||
|
forkEntryPoints.push( mojoDescriptor );
|
||||||
|
|
||||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
||||||
|
|
||||||
String targetPhase = mojoDescriptor.getExecutePhase();
|
String targetPhase = mojoDescriptor.getExecutePhase();
|
||||||
|
@ -778,7 +790,7 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
removeFromLifecycle( mojoDescriptor, lifecycleMappings );
|
removeFromLifecycle( forkEntryPoints, lifecycleMappings );
|
||||||
}
|
}
|
||||||
|
|
||||||
MavenProject executionProject = new MavenProject( project );
|
MavenProject executionProject = new MavenProject( project );
|
||||||
|
@ -786,13 +798,13 @@ public class DefaultLifecycleExecutor
|
||||||
{
|
{
|
||||||
Lifecycle lifecycle = getLifecycleForPhase( targetPhase );
|
Lifecycle lifecycle = getLifecycleForPhase( targetPhase );
|
||||||
|
|
||||||
executeGoalWithLifecycle( targetPhase, session, lifecycleMappings, executionProject, lifecycle );
|
executeGoalWithLifecycle( targetPhase, forkEntryPoints, session, lifecycleMappings, executionProject, lifecycle );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String goal = mojoDescriptor.getExecuteGoal();
|
String goal = mojoDescriptor.getExecuteGoal();
|
||||||
MojoDescriptor desc = getMojoDescriptor( pluginDescriptor, goal );
|
MojoDescriptor desc = getMojoDescriptor( pluginDescriptor, goal );
|
||||||
executeGoals( Collections.singletonList( new MojoExecution( desc ) ), session, executionProject );
|
executeGoals( Collections.singletonList( new MojoExecution( desc ) ), forkEntryPoints, session, executionProject );
|
||||||
}
|
}
|
||||||
project.setExecutionProject( executionProject );
|
project.setExecutionProject( executionProject );
|
||||||
}
|
}
|
||||||
|
@ -832,24 +844,34 @@ public class DefaultLifecycleExecutor
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeFromLifecycle( MojoDescriptor mojoDescriptor, Map lifecycleMappings )
|
private void removeFromLifecycle( Stack lifecycleForkers, Map lifecycleMappings )
|
||||||
{
|
{
|
||||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
for ( Iterator it = lifecycleForkers.iterator(); it.hasNext(); )
|
||||||
|
|
||||||
String mojoIdWithVersion = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId() + ":" +
|
|
||||||
pluginDescriptor.getVersion() + ":" + mojoDescriptor.getGoal();
|
|
||||||
|
|
||||||
String mojoIdWithoutVersion =
|
|
||||||
pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId() + ":" + mojoDescriptor.getGoal();
|
|
||||||
|
|
||||||
for ( Iterator it = lifecycleMappings.values().iterator(); it.hasNext(); )
|
|
||||||
{
|
{
|
||||||
List tasks = (List) it.next();
|
MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next();
|
||||||
|
|
||||||
if ( tasks.remove( mojoIdWithVersion ) || tasks.remove( mojoIdWithoutVersion ) )
|
for ( Iterator lifecycleIterator = lifecycleMappings.values().iterator(); lifecycleIterator.hasNext(); )
|
||||||
{
|
{
|
||||||
getLogger().warn( "Removing: " + mojoDescriptor.getGoal() +
|
List tasks = (List) lifecycleIterator.next();
|
||||||
" from forked lifecycle, to prevent recursive invocation of this mojo." );
|
|
||||||
|
boolean removed = false;
|
||||||
|
for ( Iterator taskIterator = tasks.iterator(); taskIterator.hasNext(); )
|
||||||
|
{
|
||||||
|
MojoExecution execution = (MojoExecution) taskIterator.next();
|
||||||
|
|
||||||
|
if ( mojoDescriptor.equals( execution.getMojoDescriptor() ) )
|
||||||
|
{
|
||||||
|
taskIterator.remove();
|
||||||
|
removed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( removed )
|
||||||
|
{
|
||||||
|
getLogger().warn(
|
||||||
|
"Removing: " + mojoDescriptor.getGoal()
|
||||||
|
+ " from forked lifecycle, to prevent recursive invocation." );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue