mirror of https://github.com/apache/maven.git
[MNG-4633] Changed to use nice clean countdownlatch instead of synchronized booleans
Also updated phase locking to only lock when project being built changes phase git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@939220 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0d7a05f8b2
commit
ab495d4a39
|
@ -19,7 +19,7 @@ import org.apache.maven.model.Plugin;
|
|||
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 class ExecutionPlanItem
|
|||
|
||||
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()
|
||||
|
|
|
@ -205,7 +205,7 @@ public class LifecycleWeaveBuilder
|
|||
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,14 +215,11 @@ public class LifecycleWeaveBuilder
|
|||
projectBuild );
|
||||
}
|
||||
|
||||
if ( phaseRecorder.isDifferentPhase( nextPlanItem.getMojoExecution() ) )
|
||||
{
|
||||
for ( ArtifactLink dependencyLink : dependencyLinks )
|
||||
{
|
||||
dependencyLink.resolveFromUpstream();
|
||||
}
|
||||
}
|
||||
}
|
||||
current = nextPlanItem;
|
||||
}
|
||||
|
||||
|
@ -259,13 +256,13 @@ public class LifecycleWeaveBuilder
|
|||
{
|
||||
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 ) )
|
||||
{
|
||||
|
|
|
@ -46,8 +46,8 @@ public class MavenExecutionPlanTest
|
|||
MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
|
||||
plan.forceAllComplete();
|
||||
final Iterator<ExecutionPlanItem> planItemIterator = plan.iterator();
|
||||
assertFalse( planItemIterator.next().ensureComplete() );
|
||||
assertFalse( planItemIterator.next().ensureComplete() );
|
||||
assertTrue( planItemIterator.next().isDone() );
|
||||
assertTrue( planItemIterator.next().isDone() );
|
||||
}
|
||||
|
||||
public void testFindLastInPhase()
|
||||
|
|
|
@ -31,7 +31,7 @@ public class ExecutionPlanItemTest
|
|||
{
|
||||
ExecutionPlanItem item = createExecutionPlanItem( "testMojo", null );
|
||||
item.setComplete(); // This itself is a valid test
|
||||
assertFalse( item.ensureComplete() );
|
||||
assertTrue( item.isDone() );
|
||||
}
|
||||
|
||||
public void testWaitUntilDone()
|
||||
|
|
Loading…
Reference in New Issue