001 package org.apache.maven.lifecycle.internal;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
005 * agreements. See the NOTICE file distributed with this work for additional information regarding
006 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance with the License. You may obtain a
008 * copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed under the License
013 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
014 * or implied. See the License for the specific language governing permissions and limitations under
015 * the License.
016 */
017
018 import junit.framework.TestCase;
019 import org.apache.maven.execution.MavenSession;
020 import org.apache.maven.lifecycle.MavenExecutionPlan;
021 import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
022 import org.apache.maven.project.MavenProject;
023
024 import java.util.Iterator;
025
026 /**
027 * @author Kristian Rosenvold
028 */
029 public class ConcurrentBuildLoggerTest
030 extends TestCase
031 {
032 @SuppressWarnings( "unused" )
033 public void testToGraph()
034 throws Exception
035 {
036 ConcurrentBuildLogger concurrentBuildLogger = new ConcurrentBuildLogger();
037
038 MojoDescriptorCreator mojoDescriptorCreator =
039 LifecycleExecutionPlanCalculatorTest.createMojoDescriptorCreator();
040 LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator =
041 LifecycleExecutionPlanCalculatorTest.createExecutionPlaceCalculator( mojoDescriptorCreator );
042
043 MavenProject A = ProjectDependencyGraphStub.B;
044 MavenProject B = ProjectDependencyGraphStub.C;
045
046 final MavenSession session1 = ProjectDependencyGraphStub.getMavenSession( A );
047
048 final GoalTask goalTask1 = new GoalTask( "compiler:compile" );
049 final GoalTask goalTask2 = new GoalTask( "surefire:test" );
050 final TaskSegment taskSegment1 = new TaskSegment( false, goalTask1, goalTask2 );
051
052 MavenExecutionPlan executionPlan =
053 lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, A, taskSegment1.getTasks() );
054
055 MavenExecutionPlan executionPlan2 =
056 lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, B, taskSegment1.getTasks() );
057
058 final Iterator<ExecutionPlanItem> planItemIterator = executionPlan.iterator();
059 final BuildLogItem a1 = concurrentBuildLogger.createBuildLogItem( A, planItemIterator.next() );
060
061 final BuildLogItem a2 = concurrentBuildLogger.createBuildLogItem( A, planItemIterator.next() );
062
063 final Iterator<ExecutionPlanItem> plan2ItemIterator = executionPlan.iterator();
064 final BuildLogItem b1 = concurrentBuildLogger.createBuildLogItem( B, plan2ItemIterator.next() );
065 final BuildLogItem b2 = concurrentBuildLogger.createBuildLogItem( B, plan2ItemIterator.next() );
066
067 b1.addDependency( A, "Project dependency" );
068 final Iterator<ExecutionPlanItem> aPlan = executionPlan.iterator();
069 b1.addWait( A, aPlan.next(), System.currentTimeMillis() );
070 b2.addWait( A, aPlan.next(), System.currentTimeMillis() );
071 final String response = concurrentBuildLogger.toGraph();
072 assertTrue( response.contains( "digraph" ) );
073 }
074 }