1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.api;
20
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.stream.Stream;
24
25 import org.apache.maven.api.annotations.Experimental;
26 import org.apache.maven.api.annotations.Immutable;
27 import org.apache.maven.api.annotations.Nonnull;
28 import org.apache.maven.api.model.Plugin;
29
30 /**
31 * A Maven lifecycle is a sequence of predefined phases that govern the build process
32 * of a Maven project. Each phase represents a specific step, such as compiling the
33 * code, running tests, packaging the project, and deploying it. Executing a phase
34 * triggers all preceding phases, ensuring that each step of the build process is
35 * completed in the correct order. The three main lifecycles in Maven are
36 * {@link #DEFAULT default}, {@link #CLEAN clean}, and {@link #SITE site}, with the
37 * {@code default} lifecycle being the most commonly used for project builds.
38 *
39 * @since 4.0.0
40 */
41 @Experimental
42 @Immutable
43 public interface Lifecycle extends ExtensibleEnum {
44
45 // =========================
46 // Maven defined lifecycles
47 // =========================
48 String CLEAN = "clean";
49 String DEFAULT = "default";
50 String SITE = "site";
51
52 // ======================
53 // Phase qualifiers
54 // ======================
55 String BEFORE = "before:";
56 String AFTER = "after:";
57 String AT = "at:";
58
59 /**
60 * Name or identifier of this lifecycle.
61 *
62 * @return the unique identifier for this lifecycle
63 */
64 @Override
65 String id();
66
67 /**
68 * Collection of main phases for this lifecycle.
69 *
70 * @return the collection of top-level phases in this lifecycle
71 */
72 Collection<Phase> phases();
73
74 /**
75 * Collection of main phases for this lifecycle used with the Maven 3 builders.
76 * Those builders do not operate on a graph, but on the list and expect a slightly
77 * different ordering (mainly unit test being executed before packaging).
78 *
79 * @return the collection of phases in Maven 3 compatible ordering
80 */
81 default Collection<Phase> v3phases() {
82 return phases();
83 }
84
85 /**
86 * Stream of phases containing all child phases recursively.
87 *
88 * @return a stream of all phases in this lifecycle, including nested phases
89 */
90 default Stream<Phase> allPhases() {
91 return phases().stream().flatMap(Phase::allPhases);
92 }
93
94 /**
95 * Collection of aliases for this lifecycle.
96 * Aliases map Maven 3 phase names to their Maven 4 equivalents.
97 *
98 * @return the collection of phase aliases
99 */
100 Collection<Alias> aliases();
101
102 /**
103 * A phase in the lifecycle.
104 *
105 * A phase is identified by its name. It also contains a list of plugins bound to that phase,
106 * a list of {@link Link links}, and a list of sub-phases. This forms a tree of phases.
107 */
108 interface Phase {
109
110 // ======================
111 // Maven defined phases
112 // ======================
113 String ALL = "all";
114 String EACH = "each";
115 String BUILD = "build";
116 String INITIALIZE = "initialize";
117 String VALIDATE = "validate";
118 String SOURCES = "sources";
119 String RESOURCES = "resources";
120 String COMPILE = "compile";
121 String READY = "ready";
122 String PACKAGE = "package";
123 String VERIFY = "verify";
124 String UNIT_TEST = "unit-test";
125 String TEST_SOURCES = "test-sources";
126 String TEST_RESOURCES = "test-resources";
127 String TEST_COMPILE = "test-compile";
128 String TEST = "test";
129 String INTEGRATION_TEST = "integration-test";
130 String INSTALL = "install";
131 String DEPLOY = "deploy";
132 String CLEAN = "clean";
133
134 /**
135 * Returns the name of this phase.
136 *
137 * @return the phase name
138 */
139 @Nonnull
140 String name();
141
142 /**
143 * Returns the list of plugins bound to this phase.
144 *
145 * @return the list of plugins
146 */
147 @Nonnull
148 List<Plugin> plugins();
149
150 /**
151 * Returns the collection of links from this phase to other phases.
152 *
153 * @return the collection of links
154 */
155 @Nonnull
156 Collection<Link> links();
157
158 /**
159 * {@return the list of sub-phases}
160 */
161 @Nonnull
162 List<Phase> phases();
163
164 /**
165 * Returns a stream of all phases, including this phase and all nested phases.
166 *
167 * @return a stream of all phases
168 */
169 @Nonnull
170 Stream<Phase> allPhases();
171 }
172
173 /**
174 * A phase alias, mostly used to support the Maven 3 phases which are mapped
175 * to dynamic phases in Maven 4.
176 */
177 interface Alias {
178 /**
179 * Returns the Maven 3 phase name.
180 *
181 * @return the Maven 3 phase name
182 */
183 String v3Phase();
184
185 /**
186 * Returns the Maven 4 phase name.
187 *
188 * @return the Maven 4 phase name
189 */
190 String v4Phase();
191 }
192
193 /**
194 * A link from a phase to another phase, consisting of a type which can be
195 * {@link Kind#BEFORE} or {@link Kind#AFTER}, and a {@link Pointer} to
196 * another phase.
197 */
198 interface Link {
199 enum Kind {
200 BEFORE,
201 AFTER
202 }
203
204 /**
205 * Returns the kind of link (BEFORE or AFTER).
206 *
207 * @return the link kind
208 */
209 Kind kind();
210
211 /**
212 * Returns the pointer to the target phase.
213 *
214 * @return the phase pointer
215 */
216 Pointer pointer();
217 }
218
219 interface Pointer {
220 enum Type {
221 PROJECT,
222 DEPENDENCIES,
223 CHILDREN
224 }
225
226 /**
227 * Returns the name of the target phase.
228 *
229 * @return the phase name
230 */
231 String phase();
232
233 /**
234 * Returns the type of pointer (PROJECT, DEPENDENCIES, or CHILDREN).
235 *
236 * @return the pointer type
237 */
238 Type type();
239 }
240
241 interface PhasePointer extends Pointer {
242 /**
243 * Returns the type of pointer, which is always PROJECT for a PhasePointer.
244 *
245 * @return the PROJECT pointer type
246 */
247 @Override
248 default Type type() {
249 return Type.PROJECT;
250 }
251 }
252
253 interface DependenciesPointer extends Pointer {
254 /**
255 * Returns the dependency scope this pointer applies to.
256 *
257 * @return the dependency scope, or "all" if not specified
258 */
259 String scope(); // default: all
260
261 /**
262 * Returns the type of pointer, which is always DEPENDENCIES for a DependenciesPointer.
263 *
264 * @return the DEPENDENCIES pointer type
265 */
266 @Override
267 default Type type() {
268 return Type.DEPENDENCIES;
269 }
270 }
271
272 interface ChildrenPointer extends Pointer {
273 /**
274 * Returns the type of pointer, which is always CHILDREN for a ChildrenPointer.
275 *
276 * @return the CHILDREN pointer type
277 */
278 @Override
279 default Type type() {
280 return Type.CHILDREN;
281 }
282 }
283 }