1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
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 }