View Javadoc

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 java.io.File;
19  
20  import org.apache.maven.AbstractCoreMavenComponentTestCase;
21  import org.apache.maven.execution.MavenSession;
22  import org.apache.maven.lifecycle.MavenExecutionPlan;
23  import org.apache.maven.lifecycle.internal.stub.BuildPluginManagerStub;
24  import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub;
25  import org.apache.maven.lifecycle.internal.stub.DefaultSchedulesStub;
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
34      extends AbstractCoreMavenComponentTestCase
35  {
36  
37      public void testCalculateExecutionPlanWithGoalTasks()
38          throws Exception
39      {
40          MojoDescriptorCreator mojoDescriptorCreator = createMojoDescriptorCreator();
41          LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator =
42              createExecutionPlaceCalculator( mojoDescriptorCreator );
43  
44          final GoalTask goalTask1 = new GoalTask( "compiler:compile" );
45          final GoalTask goalTask2 = new GoalTask( "surefire:test" );
46          final TaskSegment taskSegment1 = new TaskSegment( false, goalTask1, goalTask2 );
47          final MavenSession session1 = ProjectDependencyGraphStub.getMavenSession( ProjectDependencyGraphStub.A );
48  
49          MavenExecutionPlan executionPlan =
50              lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A,
51                                                                       taskSegment1.getTasks() );
52          assertEquals( 2, executionPlan.size() );
53  
54          final GoalTask goalTask3 = new GoalTask( "surefire:test" );
55          final TaskSegment taskSegment2 = new TaskSegment( false, goalTask1, goalTask2, goalTask3 );
56          MavenExecutionPlan executionPlan2 =
57              lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A,
58                                                                       taskSegment2.getTasks() );
59          assertEquals( 3, executionPlan2.size() );
60      }
61  
62      // Maybe also make one with LifeCycleTasks
63  
64      public static LifecycleExecutionPlanCalculator createExecutionPlaceCalculator( MojoDescriptorCreator mojoDescriptorCreator )
65      {
66          LifecyclePluginResolver lifecyclePluginResolver = 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  
80      @Override
81      protected String getProjectsDirectory()
82      {
83          return "src/test/projects/lifecycle-executor";
84      }
85  
86  }