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.List;
46 import java.util.Map;
47 import java.util.Set;
48
49
50
51
52
53
54
55
56
57
58 @Component( role = LifecycleExecutor.class )
59 public class DefaultLifecycleExecutor
60 implements LifecycleExecutor
61 {
62
63 @Requirement
64 private LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer;
65
66 @Requirement
67 private DefaultLifecycles defaultLifeCycles;
68
69 @Requirement
70 private LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator;
71
72 @Requirement
73 private LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator;
74
75 @Requirement
76 private MojoExecutor mojoExecutor;
77
78 @Requirement
79 private LifecycleStarter lifecycleStarter;
80
81
82 public void execute( MavenSession session )
83 {
84 lifecycleStarter.execute( session );
85 }
86
87 @Requirement
88 private MojoDescriptorCreator mojoDescriptorCreator;
89
90
91
92
93
94
95
96
97
98
99
100
101
102 public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
103 {
104 return lifeCyclePluginAnalyzer.getPluginsBoundByDefaultToAllLifecycles( packaging );
105 }
106
107
108
109 @SuppressWarnings( { "UnusedDeclaration" } )
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, String... tasks )
132 throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
133 MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
134 PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
135 PluginVersionResolutionException
136 {
137
138 List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session );
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() );
149 }
150
151
152 public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
153 throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
154 PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
155 LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
156 {
157 lifecycleExecutionPlanCalculator.calculateForkedExecutions( mojoExecution, session );
158 }
159
160
161
162 public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
163 throws LifecycleExecutionException
164 {
165 return mojoExecutor.executeForkedExecutions( mojoExecution, session, new ProjectIndex( session.getProjects() ) );
166 }
167
168 }