1 package org.apache.maven.lifecycle;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.execution.MavenSession;
23 import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
24 import org.apache.maven.lifecycle.internal.LifecycleStarter;
25 import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
26 import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
27 import org.apache.maven.lifecycle.internal.MojoExecutor;
28 import org.apache.maven.lifecycle.internal.ProjectIndex;
29 import org.apache.maven.lifecycle.internal.TaskSegment;
30 import org.apache.maven.model.Plugin;
31 import org.apache.maven.plugin.InvalidPluginDescriptorException;
32 import org.apache.maven.plugin.MojoExecution;
33 import org.apache.maven.plugin.MojoNotFoundException;
34 import org.apache.maven.plugin.PluginDescriptorParsingException;
35 import org.apache.maven.plugin.PluginManagerException;
36 import org.apache.maven.plugin.PluginNotFoundException;
37 import org.apache.maven.plugin.PluginResolutionException;
38 import org.apache.maven.plugin.descriptor.MojoDescriptor;
39 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
40 import org.apache.maven.plugin.version.PluginVersionResolutionException;
41 import org.apache.maven.project.MavenProject;
42 import org.codehaus.plexus.component.annotations.Component;
43 import org.codehaus.plexus.component.annotations.Requirement;
44
45 import java.util.Arrays;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.Set;
49
50
51
52
53
54
55
56
57
58
59 @Component( role = LifecycleExecutor.class )
60 public class DefaultLifecycleExecutor
61 implements LifecycleExecutor
62 {
63
64 @Requirement
65 private LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer;
66
67 @Requirement
68 private DefaultLifecycles defaultLifeCycles;
69
70 @Requirement
71 private LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator;
72
73 @Requirement
74 private LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator;
75
76 @Requirement
77 private MojoExecutor mojoExecutor;
78
79 @Requirement
80 private LifecycleStarter lifecycleStarter;
81
82
83 public void execute( MavenSession session )
84 {
85 lifecycleStarter.execute( session );
86 }
87
88 @Requirement
89 private MojoDescriptorCreator mojoDescriptorCreator;
90
91
92
93
94
95
96
97
98
99
100
101
102
103 public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
104 {
105 return lifeCyclePluginAnalyzer.getPluginsBoundByDefaultToAllLifecycles( packaging );
106 }
107
108
109
110 @Deprecated
111 public Map<String, Lifecycle> getPhaseToLifecycleMap()
112 {
113 return defaultLifeCycles.getPhaseToLifecycleMap();
114 }
115
116
117
118 @SuppressWarnings( { "UnusedDeclaration" } )
119 MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project, String invokedVia,
120 boolean canUsePrefix, boolean isOptionalMojo )
121 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
122 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
123 PluginVersionResolutionException
124 {
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 {
137 List<TaskSegment> taskSegments =
138 lifecycleTaskSegmentCalculator.calculateTaskSegments( session, Arrays.asList( tasks ) );
139
140 TaskSegment mergedSegment = new TaskSegment( false );
141
142 for ( TaskSegment taskSegment : taskSegments )
143 {
144 mergedSegment.getTasks().addAll( taskSegment.getTasks() );
145 }
146
147 return lifecycleExecutionPlanCalculator.calculateExecutionPlan( session, session.getCurrentProject(),
148 mergedSegment.getTasks(), setup );
149 }
150
151 public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
152 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
153 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
154 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
155 PluginVersionResolutionException
156 {
157 return calculateExecutionPlan( session, true, tasks );
158 }
159
160
161 public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
162 throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
163 PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
164 LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
165 {
166 lifecycleExecutionPlanCalculator.calculateForkedExecutions( mojoExecution, session );
167 }
168
169
170 public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
171 throws LifecycleExecutionException
172 {
173 return mojoExecutor.executeForkedExecutions( mojoExecution, session,
174 new ProjectIndex( session.getProjects() ) );
175 }
176
177 }