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