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.Optional;
24 import java.util.stream.Stream;
25
26 import org.apache.maven.api.annotations.Experimental;
27 import org.apache.maven.api.annotations.Immutable;
28 import org.apache.maven.api.annotations.Nonnull;
29 import org.apache.maven.api.model.Plugin;
30
31 /**
32 * A Maven lifecycle is a sequence of predefined phases that govern the build process
33 * of a Maven project. Each phase represents a specific step, such as compiling the
34 * code, running tests, packaging the project, and deploying it. Executing a phase
35 * triggers all preceding phases, ensuring that each step of the build process is
36 * completed in the correct order. The three main lifecycles in Maven are
37 * {@link #DEFAULT default}, {@link #CLEAN clean}, and {@link #SITE site}, with the
38 * {@code default} lifecycle being the most commonly used for project builds.
39 *
40 * @since 4.0.0
41 */
42 @Experimental
43 @Immutable
44 public interface Lifecycle extends ExtensibleEnum {
45
46 // =========================
47 // Maven defined lifecycles
48 // =========================
49 String CLEAN = "clean";
50 String DEFAULT = "default";
51 String SITE = "site";
52
53 // ======================
54 // Phase qualifiers
55 // ======================
56 String BEFORE = "before:";
57 String AFTER = "after:";
58 String AT = "at:";
59
60 /**
61 * Name or identifier of this lifecycle.
62 *
63 * @return the unique identifier for this lifecycle
64 */
65 @Override
66 String id();
67
68 /**
69 * Collection of phases for this lifecycle
70 */
71 Collection<Phase> phases();
72
73 /**
74 * Stream of phases containing all child phases recursively.
75 */
76 default Stream<Phase> allPhases() {
77 return phases().stream().flatMap(Phase::allPhases);
78 }
79
80 /**
81 * Collection of aliases.
82 */
83 Collection<Alias> aliases();
84
85 /**
86 * Pre-ordered list of phases.
87 * If not provided, a default order will be computed.
88 */
89 default Optional<List<String>> orderedPhases() {
90 return Optional.empty();
91 }
92
93 /**
94 * A phase in the lifecycle.
95 *
96 * A phase is identified by its name. It also contains a list of plugins bound to that phase,
97 * a list of {@link Link links}, and a list of sub-phases. This forms a tree of phases.
98 */
99 interface Phase {
100
101 // ======================
102 // Maven defined phases
103 // ======================
104 String BUILD = "build";
105 String INITIALIZE = "initialize";
106 String VALIDATE = "validate";
107 String SOURCES = "sources";
108 String RESOURCES = "resources";
109 String COMPILE = "compile";
110 String READY = "ready";
111 String PACKAGE = "package";
112 String VERIFY = "verify";
113 String UNIT_TEST = "unit-test";
114 String TEST_SOURCES = "test-sources";
115 String TEST_RESOURCES = "test-resources";
116 String TEST_COMPILE = "test-compile";
117 String TEST = "test";
118 String INTEGRATION_TEST = "integration-test";
119 String INSTALL = "install";
120 String DEPLOY = "deploy";
121 String CLEAN = "clean";
122
123 @Nonnull
124 String name();
125
126 @Nonnull
127 List<Plugin> plugins();
128
129 @Nonnull
130 Collection<Link> links();
131
132 /**
133 * {@return the list of sub-phases}
134 */
135 @Nonnull
136 List<Phase> phases();
137
138 @Nonnull
139 Stream<Phase> allPhases();
140 }
141
142 /**
143 * A phase alias, mostly used to support the Maven 3 phases which are mapped
144 * to dynamic phases in Maven 4.
145 */
146 interface Alias {
147 String v3Phase();
148
149 String v4Phase();
150 }
151
152 /**
153 * A link from a phase to another phase, consisting of a type which can be
154 * {@link Kind#BEFORE} or {@link Kind#AFTER}, and a {@link Pointer} to
155 * another phase.
156 */
157 interface Link {
158 enum Kind {
159 BEFORE,
160 AFTER
161 }
162
163 Kind kind();
164
165 Pointer pointer();
166 }
167
168 interface Pointer {
169 enum Type {
170 PROJECT,
171 DEPENDENCIES,
172 CHILDREN
173 }
174
175 String phase();
176
177 Type type();
178 }
179
180 interface PhasePointer extends Pointer {
181 default Type type() {
182 return Type.PROJECT;
183 }
184 }
185
186 interface DependenciesPointer extends Pointer {
187 String scope(); // default: all
188
189 default Type type() {
190 return Type.DEPENDENCIES;
191 }
192 }
193
194 interface ChildrenPointer extends Pointer {
195 default Type type() {
196 return Type.CHILDREN;
197 }
198 }
199 }