diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ExecutionPlanItem.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ExecutionPlanItem.java index d4b0d87fcb..5cd0b5c4fb 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ExecutionPlanItem.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ExecutionPlanItem.java @@ -19,7 +19,7 @@ import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.descriptor.MojoDescriptor; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.CountDownLatch; /** * Wraps individual MojoExecutions, containing information about completion status and scheduling. @@ -35,9 +35,7 @@ public class ExecutionPlanItem private final Schedule schedule; // Completeness just indicates that it has been run or failed - private final AtomicBoolean complete = new AtomicBoolean( false ); - - private final Object monitor = new Object(); + private final CountDownLatch done = new CountDownLatch( 1 ); public ExecutionPlanItem( MojoExecution mojoExecution, Schedule schedule ) { @@ -57,47 +55,23 @@ public String getLifecyclePhase() public void setComplete() { - boolean transitionSuccessful = ensureComplete(); - if ( !transitionSuccessful ) - { - throw new IllegalStateException( "Expected to be able to setComplete node, but was complete already" ); - } + done.countDown(); } - public boolean ensureComplete() + public boolean isDone() { - boolean f = complete.compareAndSet( false, true ); - notifyListeners(); - return f; - } - - private void notifyListeners() - { - synchronized ( monitor ) - { - monitor.notifyAll(); - } + return done.getCount() < 1; } public void forceComplete() { - final boolean b = complete.getAndSet( true ); - if ( !b ) - { - notifyListeners(); - } // Release anyone waiting for us + setComplete(); } public void waitUntilDone() throws InterruptedException { - synchronized ( monitor ) - { - while ( !complete.get() ) - { - monitor.wait( 100 ); - } - } + done.await(); } public Schedule getSchedule() diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilder.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilder.java index b89caf2bc6..39795b6168 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilder.java @@ -205,7 +205,7 @@ public ProjectSegment call() builtLogItem.setComplete(); ExecutionPlanItem nextPlanItem = planItems.hasNext() ? planItems.next() : null; - if ( nextPlanItem != null ) + if ( nextPlanItem != null && phaseRecorder.isDifferentPhase( nextPlanItem.getMojoExecution() ) ) { final Schedule scheduleOfNext = nextPlanItem.getSchedule(); @@ -215,12 +215,9 @@ public ProjectSegment call() projectBuild ); } - if ( phaseRecorder.isDifferentPhase( nextPlanItem.getMojoExecution() ) ) + for ( ArtifactLink dependencyLink : dependencyLinks ) { - for ( ArtifactLink dependencyLink : dependencyLinks ) - { - dependencyLink.resolveFromUpstream(); - } + dependencyLink.resolveFromUpstream(); } } current = nextPlanItem; @@ -259,13 +256,13 @@ private void waitForAppropriateUpstreamExecutionsToFinish( BuildLogItem builtLog { final MavenExecutionPlan upstreamPlan = executionPlans.get( upstreamProject ); final String nextPhase = nextPlanItem.getLifecyclePhase(); - final ExecutionPlanItem inSchedule = upstreamPlan.findLastInPhase( nextPhase ); + final ExecutionPlanItem upstream = upstreamPlan.findLastInPhase( nextPhase ); - if ( inSchedule != null ) + if ( upstream != null ) { long startWait = System.currentTimeMillis(); - inSchedule.waitUntilDone(); - builtLogItem.addWait( upstreamProject, inSchedule, startWait ); + upstream.waitUntilDone(); + builtLogItem.addWait( upstreamProject, upstream, startWait ); } else if ( !upstreamPlan.containsPhase( nextPhase ) ) { diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java index 278473c49b..5728c80a71 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java @@ -46,8 +46,8 @@ public void testForceAllComplete() MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan(); plan.forceAllComplete(); final Iterator planItemIterator = plan.iterator(); - assertFalse( planItemIterator.next().ensureComplete() ); - assertFalse( planItemIterator.next().ensureComplete() ); + assertTrue( planItemIterator.next().isDone() ); + assertTrue( planItemIterator.next().isDone() ); } public void testFindLastInPhase() diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ExecutionPlanItemTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ExecutionPlanItemTest.java index e8333501d1..b7eacea5db 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ExecutionPlanItemTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ExecutionPlanItemTest.java @@ -31,7 +31,7 @@ public void testSetComplete() { ExecutionPlanItem item = createExecutionPlanItem( "testMojo", null ); item.setComplete(); // This itself is a valid test - assertFalse( item.ensureComplete() ); + assertTrue( item.isDone() ); } public void testWaitUntilDone()