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