1 package org.apache.maven.lifecycle.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import junit.framework.TestCase;
19 import org.apache.maven.execution.MavenSession;
20 import org.apache.maven.lifecycle.MavenExecutionPlan;
21 import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
22 import org.apache.maven.project.MavenProject;
23
24 import java.util.Iterator;
25
26
27
28
29 public class ConcurrentBuildLoggerTest
30 extends TestCase
31 {
32 public void testToGraph()
33 throws Exception
34 {
35 ConcurrentBuildLogger concurrentBuildLogger = new ConcurrentBuildLogger();
36
37 MojoDescriptorCreator mojoDescriptorCreator =
38 LifecycleExecutionPlanCalculatorTest.createMojoDescriptorCreator();
39 LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator =
40 LifecycleExecutionPlanCalculatorTest.createExecutionPlaceCalculator( mojoDescriptorCreator );
41
42 MavenProject A = ProjectDependencyGraphStub.B;
43 MavenProject B = ProjectDependencyGraphStub.C;
44
45 final MavenSession session1 = ProjectDependencyGraphStub.getMavenSession( A );
46
47 final GoalTask goalTask1 = new GoalTask( "compiler:compile" );
48 final GoalTask goalTask2 = new GoalTask( "surefire:test" );
49 final TaskSegment taskSegment1 = new TaskSegment( false, goalTask1, goalTask2 );
50
51 MavenExecutionPlan executionPlan =
52 lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, A, taskSegment1.getTasks() );
53
54 MavenExecutionPlan executionPlan2 =
55 lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, B, taskSegment1.getTasks() );
56
57 final Iterator<ExecutionPlanItem> planItemIterator = executionPlan.iterator();
58 final BuildLogItem a1 = concurrentBuildLogger.createBuildLogItem( A, planItemIterator.next() );
59
60 final BuildLogItem a2 = concurrentBuildLogger.createBuildLogItem( A, planItemIterator.next() );
61
62 final Iterator<ExecutionPlanItem> plan2ItemIterator = executionPlan.iterator();
63 final BuildLogItem b1 = concurrentBuildLogger.createBuildLogItem( B, plan2ItemIterator.next() );
64 final BuildLogItem b2 = concurrentBuildLogger.createBuildLogItem( B, plan2ItemIterator.next() );
65
66 b1.addDependency( A, "Project dependency" );
67 final Iterator<ExecutionPlanItem> aPlan = executionPlan.iterator();
68 b1.addWait( A, aPlan.next(), System.currentTimeMillis() );
69 b2.addWait( A, aPlan.next(), System.currentTimeMillis() );
70 final String response = concurrentBuildLogger.toGraph();
71 assertTrue( response.indexOf( "digraph" ) >= 0 );
72 }
73 }