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 org.apache.maven.AbstractCoreMavenComponentTestCase;
019    import org.apache.maven.execution.MavenSession;
020    import org.apache.maven.lifecycle.MavenExecutionPlan;
021    import org.apache.maven.lifecycle.internal.stub.BuildPluginManagerStub;
022    import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub;
023    import org.apache.maven.lifecycle.internal.stub.DefaultSchedulesStub;
024    import org.apache.maven.lifecycle.internal.stub.PluginPrefixResolverStub;
025    import org.apache.maven.lifecycle.internal.stub.PluginVersionResolverStub;
026    import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
027    
028    /**
029     * @author Kristian Rosenvold>
030     */
031    public class LifecycleExecutionPlanCalculatorTest
032        extends AbstractCoreMavenComponentTestCase
033    {
034    
035        public void testCalculateExecutionPlanWithGoalTasks()
036            throws Exception
037        {
038            MojoDescriptorCreator mojoDescriptorCreator = createMojoDescriptorCreator();
039            LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator =
040                createExecutionPlaceCalculator( mojoDescriptorCreator );
041    
042            final GoalTask goalTask1 = new GoalTask( "compiler:compile" );
043            final GoalTask goalTask2 = new GoalTask( "surefire:test" );
044            final TaskSegment taskSegment1 = new TaskSegment( false, goalTask1, goalTask2 );
045            final MavenSession session1 = ProjectDependencyGraphStub.getMavenSession( ProjectDependencyGraphStub.A );
046    
047            MavenExecutionPlan executionPlan =
048                lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A,
049                                                                         taskSegment1.getTasks() );
050            assertEquals( 2, executionPlan.size() );
051    
052            final GoalTask goalTask3 = new GoalTask( "surefire:test" );
053            final TaskSegment taskSegment2 = new TaskSegment( false, goalTask1, goalTask2, goalTask3 );
054            MavenExecutionPlan executionPlan2 =
055                lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A,
056                                                                         taskSegment2.getTasks() );
057            assertEquals( 3, executionPlan2.size() );
058        }
059    
060        // Maybe also make one with LifeCycleTasks
061    
062        public static LifecycleExecutionPlanCalculator createExecutionPlaceCalculator( MojoDescriptorCreator mojoDescriptorCreator )
063        {
064            LifecyclePluginResolver lifecyclePluginResolver = new LifecyclePluginResolver( new PluginVersionResolverStub() );
065            return new DefaultLifecycleExecutionPlanCalculator( new BuildPluginManagerStub(),
066                                                                DefaultLifecyclesStub.createDefaultLifecycles(),
067                                                                mojoDescriptorCreator, lifecyclePluginResolver,
068                                                                DefaultSchedulesStub.createDefaultSchedules() );
069        }
070    
071        public static MojoDescriptorCreator createMojoDescriptorCreator()
072        {
073            return new MojoDescriptorCreator( new PluginVersionResolverStub(), new BuildPluginManagerStub(),
074                                              new PluginPrefixResolverStub(),
075                                              new LifecyclePluginResolver( new PluginVersionResolverStub() ) );
076        }
077    
078        @Override
079        protected String getProjectsDirectory()
080        {
081            return "src/test/projects/lifecycle-executor";
082        }
083    
084    }