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        public void testToGraph()
033            throws Exception
034        {
035            ConcurrentBuildLogger concurrentBuildLogger = new ConcurrentBuildLogger();
036    
037            MojoDescriptorCreator mojoDescriptorCreator =
038                LifecycleExecutionPlanCalculatorTest.createMojoDescriptorCreator();
039            LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator =
040                LifecycleExecutionPlanCalculatorTest.createExecutionPlaceCalculator( mojoDescriptorCreator );
041    
042            MavenProject A = ProjectDependencyGraphStub.B;
043            MavenProject B = ProjectDependencyGraphStub.C;
044    
045            final MavenSession session1 = ProjectDependencyGraphStub.getMavenSession( A );
046    
047            final GoalTask goalTask1 = new GoalTask( "compiler:compile" );
048            final GoalTask goalTask2 = new GoalTask( "surefire:test" );
049            final TaskSegment taskSegment1 = new TaskSegment( false, goalTask1, goalTask2 );
050    
051            MavenExecutionPlan executionPlan =
052                lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, A, taskSegment1.getTasks() );
053    
054            MavenExecutionPlan executionPlan2 =
055                lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, B, taskSegment1.getTasks() );
056    
057            final Iterator<ExecutionPlanItem> planItemIterator = executionPlan.iterator();
058            final BuildLogItem a1 = concurrentBuildLogger.createBuildLogItem( A, planItemIterator.next() );
059    
060            final BuildLogItem a2 = concurrentBuildLogger.createBuildLogItem( A, planItemIterator.next() );
061    
062            final Iterator<ExecutionPlanItem> plan2ItemIterator = executionPlan.iterator();
063            final BuildLogItem b1 = concurrentBuildLogger.createBuildLogItem( B, plan2ItemIterator.next() );
064            final BuildLogItem b2 = concurrentBuildLogger.createBuildLogItem( B, plan2ItemIterator.next() );
065    
066            b1.addDependency( A, "Project dependency" );
067            final Iterator<ExecutionPlanItem> aPlan = executionPlan.iterator();
068            b1.addWait( A, aPlan.next(), System.currentTimeMillis() );
069            b2.addWait( A, aPlan.next(), System.currentTimeMillis() );
070            final String response = concurrentBuildLogger.toGraph();
071            assertTrue( response.indexOf( "digraph" ) >= 0 );
072        }
073    }