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