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 @SuppressWarnings( { "UnusedDeclaration" } )
111 @Deprecated
112 public Map<String, Lifecycle> getPhaseToLifecycleMap()
113 {
114 return defaultLifeCycles.getPhaseToLifecycleMap();
115 }
116
117
118
119 @SuppressWarnings( { "UnusedDeclaration" } )
120 MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project, String invokedVia,
121 boolean canUsePrefix, boolean isOptionalMojo )
122 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
123 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
124 PluginVersionResolutionException
125 {
126 return mojoDescriptorCreator.getMojoDescriptor( task, session, project );
127 }
128
129
130
131 @SuppressWarnings( { "UnusedDeclaration" } )
132 public MavenExecutionPlan calculateExecutionPlan( MavenSession session, boolean setup, String... tasks )
133 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
134 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
135 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
136 PluginVersionResolutionException
137 {
138 List<TaskSegment> taskSegments =
139 lifecycleTaskSegmentCalculator.calculateTaskSegments( session, Arrays.asList( tasks ) );
140
141 TaskSegment mergedSegment = new TaskSegment( false );
142
143 for ( TaskSegment taskSegment : taskSegments )
144 {
145 mergedSegment.getTasks().addAll( taskSegment.getTasks() );
146 }
147
148 return lifecycleExecutionPlanCalculator.calculateExecutionPlan( session, session.getCurrentProject(),
149 mergedSegment.getTasks(), setup );
150 }
151
152 public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
153 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
154 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
155 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
156 PluginVersionResolutionException
157 {
158 return calculateExecutionPlan( session, true, tasks );
159 }
160
161
162 public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
163 throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
164 PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
165 LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
166 {
167 lifecycleExecutionPlanCalculator.calculateForkedExecutions( mojoExecution, session );
168 }
169
170
171
172 public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
173 throws LifecycleExecutionException
174 {
175 return mojoExecutor.executeForkedExecutions( mojoExecution, session, new ProjectIndex( session.getProjects() ) );
176 }
177
178 }