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.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 implements LifecycleExecutor {
62
63 private final LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer;
64 private final DefaultLifecycles defaultLifeCycles;
65 private final LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator;
66 private final LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator;
67 private final MojoExecutor mojoExecutor;
68 private final LifecycleStarter lifecycleStarter;
69 private final MojoDescriptorCreator mojoDescriptorCreator;
70
71 @Inject
72 public DefaultLifecycleExecutor(
73 LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer,
74 DefaultLifecycles defaultLifeCycles,
75 LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator,
76 LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator,
77 MojoExecutor mojoExecutor,
78 LifecycleStarter lifecycleStarter,
79 MojoDescriptorCreator mojoDescriptorCreator) {
80 this.lifeCyclePluginAnalyzer = lifeCyclePluginAnalyzer;
81 this.defaultLifeCycles = defaultLifeCycles;
82 this.lifecycleTaskSegmentCalculator = lifecycleTaskSegmentCalculator;
83 this.lifecycleExecutionPlanCalculator = lifecycleExecutionPlanCalculator;
84 this.mojoExecutor = mojoExecutor;
85 this.lifecycleStarter = lifecycleStarter;
86 this.mojoDescriptorCreator = mojoDescriptorCreator;
87 }
88
89 public void execute(MavenSession session) {
90 lifecycleStarter.execute(session);
91 }
92
93
94
95
96
97
98
99
100
101
102
103
104
105 public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles(String packaging) {
106 return lifeCyclePluginAnalyzer.getPluginsBoundByDefaultToAllLifecycles(packaging);
107 }
108
109
110
111 @Deprecated
112 public Map<String, Lifecycle> getPhaseToLifecycleMap() {
113 return defaultLifeCycles.getPhaseToLifecycleMap();
114 }
115
116
117
118 @SuppressWarnings({"UnusedDeclaration"})
119 public MavenExecutionPlan calculateExecutionPlan(MavenSession session, boolean setup, String... tasks)
120 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
121 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
122 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
123 PluginVersionResolutionException {
124 List<TaskSegment> taskSegments =
125 lifecycleTaskSegmentCalculator.calculateTaskSegments(session, Arrays.asList(tasks));
126
127 TaskSegment mergedSegment = new TaskSegment(false);
128
129 for (TaskSegment taskSegment : taskSegments) {
130 mergedSegment.getTasks().addAll(taskSegment.getTasks());
131 }
132
133 return lifecycleExecutionPlanCalculator.calculateExecutionPlan(
134 session, session.getCurrentProject(), 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 return calculateExecutionPlan(session, true, tasks);
143 }
144
145
146 public void calculateForkedExecutions(MojoExecution mojoExecution, MavenSession session)
147 throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
148 PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
149 LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException {
150 lifecycleExecutionPlanCalculator.calculateForkedExecutions(mojoExecution, session);
151 }
152
153
154 public List<MavenProject> executeForkedExecutions(MojoExecution mojoExecution, MavenSession session)
155 throws LifecycleExecutionException {
156 return mojoExecutor.executeForkedExecutions(mojoExecution, session, new ProjectIndex(session.getProjects()));
157 }
158 }