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