1 package org.apache.maven.lifecycle;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.Set;
25
26 import javax.inject.Inject;
27 import javax.inject.Named;
28 import javax.inject.Singleton;
29
30 import org.apache.maven.execution.MavenSession;
31 import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
32 import org.apache.maven.lifecycle.internal.LifecycleStarter;
33 import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
34 import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
35 import org.apache.maven.lifecycle.internal.MojoExecutor;
36 import org.apache.maven.lifecycle.internal.ProjectIndex;
37 import org.apache.maven.lifecycle.internal.TaskSegment;
38 import org.apache.maven.model.Plugin;
39 import org.apache.maven.plugin.InvalidPluginDescriptorException;
40 import org.apache.maven.plugin.MojoExecution;
41 import org.apache.maven.plugin.MojoNotFoundException;
42 import org.apache.maven.plugin.PluginDescriptorParsingException;
43 import org.apache.maven.plugin.PluginManagerException;
44 import org.apache.maven.plugin.PluginNotFoundException;
45 import org.apache.maven.plugin.PluginResolutionException;
46 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
47 import org.apache.maven.plugin.version.PluginVersionResolutionException;
48 import org.apache.maven.project.MavenProject;
49
50
51
52
53
54
55
56
57
58
59 @Named
60 @Singleton
61 public class DefaultLifecycleExecutor
62 implements LifecycleExecutor
63 {
64
65 private final LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer;
66 private final DefaultLifecycles defaultLifeCycles;
67 private final LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator;
68 private final LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator;
69 private final MojoExecutor mojoExecutor;
70 private final LifecycleStarter lifecycleStarter;
71 private final MojoDescriptorCreator mojoDescriptorCreator;
72
73 @Inject
74 public DefaultLifecycleExecutor(
75 LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer,
76 DefaultLifecycles defaultLifeCycles,
77 LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator,
78 LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator,
79 MojoExecutor mojoExecutor,
80 LifecycleStarter lifecycleStarter,
81 MojoDescriptorCreator mojoDescriptorCreator )
82 {
83 this.lifeCyclePluginAnalyzer = lifeCyclePluginAnalyzer;
84 this.defaultLifeCycles = defaultLifeCycles;
85 this.lifecycleTaskSegmentCalculator = lifecycleTaskSegmentCalculator;
86 this.lifecycleExecutionPlanCalculator = lifecycleExecutionPlanCalculator;
87 this.mojoExecutor = mojoExecutor;
88 this.lifecycleStarter = lifecycleStarter;
89 this.mojoDescriptorCreator = mojoDescriptorCreator;
90 }
91
92 public void execute( MavenSession session )
93 {
94 lifecycleStarter.execute( session );
95 }
96
97
98
99
100
101
102
103
104
105
106
107
108
109 public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
110 {
111 return lifeCyclePluginAnalyzer.getPluginsBoundByDefaultToAllLifecycles( packaging );
112 }
113
114
115
116 @SuppressWarnings( { "UnusedDeclaration" } )
117 public MavenExecutionPlan calculateExecutionPlan( MavenSession session, boolean setup, String... tasks )
118 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
119 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
120 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
121 PluginVersionResolutionException
122 {
123 List<TaskSegment> taskSegments =
124 lifecycleTaskSegmentCalculator.calculateTaskSegments( session, Arrays.asList( tasks ) );
125
126 TaskSegment mergedSegment = new TaskSegment( false );
127
128 for ( TaskSegment taskSegment : taskSegments )
129 {
130 mergedSegment.getTasks().addAll( taskSegment.getTasks() );
131 }
132
133 return lifecycleExecutionPlanCalculator.calculateExecutionPlan( session, session.getCurrentProject(),
134 mergedSegment.getTasks(), setup );
135 }
136
137 public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
138 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
139 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
140 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
141 PluginVersionResolutionException
142 {
143 return calculateExecutionPlan( session, true, tasks );
144 }
145
146
147 public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
148 throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
149 PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
150 LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
151 {
152 lifecycleExecutionPlanCalculator.calculateForkedExecutions( mojoExecution, session );
153 }
154
155
156 public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
157 throws LifecycleExecutionException
158 {
159 return mojoExecutor.executeForkedExecutions( mojoExecution, session,
160 new ProjectIndex( session.getProjects() ) );
161 }
162
163 }