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