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 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
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
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 }