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 javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.util.Arrays;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
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.descriptor.MojoDescriptor;
47 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
48 import org.apache.maven.plugin.version.PluginVersionResolutionException;
49 import org.apache.maven.project.MavenProject;
50
51
52
53
54
55
56
57
58
59
60 @Singleton
61 @Named
62 public class DefaultLifecycleExecutor implements LifecycleExecutor {
63
64 @Inject
65 private LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer;
66
67 @Inject
68 private DefaultLifecycles defaultLifeCycles;
69
70 @Inject
71 private LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator;
72
73 @Inject
74 private LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator;
75
76 @Inject
77 private MojoExecutor mojoExecutor;
78
79 @Inject
80 private LifecycleStarter lifecycleStarter;
81
82 public void execute(MavenSession session) {
83 lifecycleStarter.execute(session);
84 }
85
86 @Inject
87 private MojoDescriptorCreator mojoDescriptorCreator;
88
89
90
91
92
93
94
95
96
97
98
99
100
101 public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles(String packaging) {
102 return lifeCyclePluginAnalyzer.getPluginsBoundByDefaultToAllLifecycles(packaging);
103 }
104
105
106
107 @Deprecated
108 public Map<String, Lifecycle> getPhaseToLifecycleMap() {
109 return defaultLifeCycles.getPhaseToLifecycleMap();
110 }
111
112
113
114 @SuppressWarnings({"UnusedDeclaration"})
115 MojoDescriptor getMojoDescriptor(
116 String task,
117 MavenSession session,
118 MavenProject project,
119 String invokedVia,
120 boolean canUsePrefix,
121 boolean isOptionalMojo)
122 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
123 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
124 PluginVersionResolutionException {
125 return mojoDescriptorCreator.getMojoDescriptor(task, session, project);
126 }
127
128
129
130 @SuppressWarnings({"UnusedDeclaration"})
131 public MavenExecutionPlan calculateExecutionPlan(MavenSession session, boolean setup, String... tasks)
132 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
133 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
134 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
135 PluginVersionResolutionException {
136 List<TaskSegment> taskSegments =
137 lifecycleTaskSegmentCalculator.calculateTaskSegments(session, Arrays.asList(tasks));
138
139 TaskSegment mergedSegment = new TaskSegment(false);
140
141 for (TaskSegment taskSegment : taskSegments) {
142 mergedSegment.getTasks().addAll(taskSegment.getTasks());
143 }
144
145 return lifecycleExecutionPlanCalculator.calculateExecutionPlan(
146 session, session.getCurrentProject(), mergedSegment.getTasks(), setup);
147 }
148
149 public MavenExecutionPlan calculateExecutionPlan(MavenSession session, String... tasks)
150 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
151 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
152 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
153 PluginVersionResolutionException {
154 return calculateExecutionPlan(session, true, tasks);
155 }
156
157
158 public void calculateForkedExecutions(MojoExecution mojoExecution, MavenSession session)
159 throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
160 PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
161 LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException {
162 lifecycleExecutionPlanCalculator.calculateForkedExecutions(mojoExecution, session);
163 }
164
165
166 public List<MavenProject> executeForkedExecutions(MojoExecution mojoExecution, MavenSession session)
167 throws LifecycleExecutionException {
168 return mojoExecutor.executeForkedExecutions(mojoExecution, session, new ProjectIndex(session.getProjects()));
169 }
170 }