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