1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  
16  package org.apache.maven.lifecycle.internal;
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.BuildPluginManagerStub;
22  import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub;
23  import org.apache.maven.lifecycle.internal.stub.DefaultSchedulesStub;
24  import org.apache.maven.lifecycle.internal.stub.PluginPrefixResolverStub;
25  import org.apache.maven.lifecycle.internal.stub.PluginVersionResolverStub;
26  import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
27  
28  /**
29   * @author Kristian Rosenvold>
30   */
31  public class LifecycleExecutionPlanCalculatorTest
32      extends TestCase
33  {
34  
35      public void testCalculateExecutionPlanWithGoalTasks()
36          throws Exception
37      {
38          MojoDescriptorCreator mojoDescriptorCreator = createMojoDescriptorCreator();
39          LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator =
40              createExecutionPlaceCalculator( mojoDescriptorCreator );
41  
42          final GoalTask goalTask1 = new GoalTask( "compiler:compile" );
43          final GoalTask goalTask2 = new GoalTask( "surefire:test" );
44          final TaskSegment taskSegment1 = new TaskSegment( false, goalTask1, goalTask2 );
45          final MavenSession session1 = ProjectDependencyGraphStub.getMavenSession( ProjectDependencyGraphStub.A );
46  
47          MavenExecutionPlan executionPlan =
48              lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A,
49                                                                       taskSegment1.getTasks() );
50          assertEquals( 2, executionPlan.size() );
51  
52          final GoalTask goalTask3 = new GoalTask( "surefire:test" );
53          final TaskSegment taskSegment2 = new TaskSegment( false, goalTask1, goalTask2, goalTask3 );
54          MavenExecutionPlan executionPlan2 =
55              lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A,
56                                                                       taskSegment2.getTasks() );
57          assertEquals( 3, executionPlan2.size() );
58      }
59  
60      // Maybe also make one with LifeCycleTasks
61  
62      public static LifecycleExecutionPlanCalculator createExecutionPlaceCalculator(
63          MojoDescriptorCreator mojoDescriptorCreator )
64      {
65          LifecyclePluginResolver lifecyclePluginResolver =
66              new LifecyclePluginResolver( new PluginVersionResolverStub() );
67          return new DefaultLifecycleExecutionPlanCalculator( new BuildPluginManagerStub(),
68                                                              DefaultLifecyclesStub.createDefaultLifecycles(),
69                                                              mojoDescriptorCreator, lifecyclePluginResolver,
70                                                              DefaultSchedulesStub.createDefaultSchedules() );
71      }
72  
73      public static MojoDescriptorCreator createMojoDescriptorCreator()
74      {
75          return new MojoDescriptorCreator( new PluginVersionResolverStub(), new BuildPluginManagerStub(),
76                                            new PluginPrefixResolverStub(),
77                                            new LifecyclePluginResolver( new PluginVersionResolverStub() ) );
78      }
79  }