1   package org.apache.maven.lifecycle.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
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   * @author Kristian Rosenvold
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  }