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.MojoExecutor;
35 import org.apache.maven.lifecycle.internal.ProjectIndex;
36 import org.apache.maven.lifecycle.internal.TaskSegment;
37 import org.apache.maven.model.Plugin;
38 import org.apache.maven.plugin.InvalidPluginDescriptorException;
39 import org.apache.maven.plugin.MojoExecution;
40 import org.apache.maven.plugin.MojoNotFoundException;
41 import org.apache.maven.plugin.PluginDescriptorParsingException;
42 import org.apache.maven.plugin.PluginManagerException;
43 import org.apache.maven.plugin.PluginNotFoundException;
44 import org.apache.maven.plugin.PluginResolutionException;
45 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
46 import org.apache.maven.plugin.version.PluginVersionResolutionException;
47 import org.apache.maven.project.MavenProject;
48
49
50
51
52
53
54
55 @Named
56 @Singleton
57 public class DefaultLifecycleExecutor implements LifecycleExecutor {
58
59 private final LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer;
60 private final DefaultLifecycles defaultLifeCycles;
61 private final LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator;
62 private final LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator;
63 private final MojoExecutor mojoExecutor;
64 private final LifecycleStarter lifecycleStarter;
65
66 @Inject
67 public DefaultLifecycleExecutor(
68 LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer,
69 DefaultLifecycles defaultLifeCycles,
70 LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator,
71 LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator,
72 MojoExecutor mojoExecutor,
73 LifecycleStarter lifecycleStarter) {
74 this.lifeCyclePluginAnalyzer = lifeCyclePluginAnalyzer;
75 this.defaultLifeCycles = defaultLifeCycles;
76 this.lifecycleTaskSegmentCalculator = lifecycleTaskSegmentCalculator;
77 this.lifecycleExecutionPlanCalculator = lifecycleExecutionPlanCalculator;
78 this.mojoExecutor = mojoExecutor;
79 this.lifecycleStarter = lifecycleStarter;
80 }
81
82 public void execute(MavenSession session) {
83 lifecycleStarter.execute(session);
84 }
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 public MavenExecutionPlan calculateExecutionPlan(MavenSession session, boolean setup, String... tasks)
113 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
114 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
115 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
116 PluginVersionResolutionException {
117 List<TaskSegment> taskSegments =
118 lifecycleTaskSegmentCalculator.calculateTaskSegments(session, Arrays.asList(tasks));
119
120 TaskSegment mergedSegment = new TaskSegment(false);
121
122 for (TaskSegment taskSegment : taskSegments) {
123 mergedSegment.getTasks().addAll(taskSegment.getTasks());
124 }
125
126 return lifecycleExecutionPlanCalculator.calculateExecutionPlan(
127 session, session.getCurrentProject(), mergedSegment.getTasks(), setup);
128 }
129
130 public MavenExecutionPlan calculateExecutionPlan(MavenSession session, String... tasks)
131 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
132 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
133 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
134 PluginVersionResolutionException {
135 return calculateExecutionPlan(session, true, tasks);
136 }
137
138
139 public void calculateForkedExecutions(MojoExecution mojoExecution, MavenSession session)
140 throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
141 PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
142 LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException {
143 lifecycleExecutionPlanCalculator.calculateForkedExecutions(mojoExecution, session);
144 }
145
146
147 public List<MavenProject> executeForkedExecutions(MojoExecution mojoExecution, MavenSession session)
148 throws LifecycleExecutionException {
149 return mojoExecutor.executeForkedExecutions(mojoExecution, session, new ProjectIndex(session.getProjects()));
150 }
151 }