View Javadoc
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      Collection<Phase> phases();
71  
72      /**
73       * Collection of main phases for this lifecycle used with the Maven 3 builders.
74       * Those builders does not operate on a graph, but on the list and expect a slightly
75       * different ordering (mainly unit test being executed before packaging).
76       */
77      default Collection<Phase> v3phases() {
78          return phases();
79      }
80  
81      /**
82       * Stream of phases containing all child phases recursively.
83       */
84      default Stream<Phase> allPhases() {
85          return phases().stream().flatMap(Phase::allPhases);
86      }
87  
88      /**
89       * Collection of aliases.
90       */
91      Collection<Alias> aliases();
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 ALL = "all";
105         String BUILD = "build";
106         String INITIALIZE = "initialize";
107         String VALIDATE = "validate";
108         String SOURCES = "sources";
109         String RESOURCES = "resources";
110         String COMPILE = "compile";
111         String READY = "ready";
112         String PACKAGE = "package";
113         String VERIFY = "verify";
114         String UNIT_TEST = "unit-test";
115         String TEST_SOURCES = "test-sources";
116         String TEST_RESOURCES = "test-resources";
117         String TEST_COMPILE = "test-compile";
118         String TEST = "test";
119         String INTEGRATION_TEST = "integration-test";
120         String INSTALL = "install";
121         String DEPLOY = "deploy";
122         String CLEAN = "clean";
123 
124         @Nonnull
125         String name();
126 
127         @Nonnull
128         List<Plugin> plugins();
129 
130         @Nonnull
131         Collection<Link> links();
132 
133         /**
134          * {@return the list of sub-phases}
135          */
136         @Nonnull
137         List<Phase> phases();
138 
139         @Nonnull
140         Stream<Phase> allPhases();
141     }
142 
143     /**
144      * A phase alias, mostly used to support the Maven 3 phases which are mapped
145      * to dynamic phases in Maven 4.
146      */
147     interface Alias {
148         String v3Phase();
149 
150         String v4Phase();
151     }
152 
153     /**
154      * A link from a phase to another phase, consisting of a type which can be
155      * {@link Kind#BEFORE} or {@link Kind#AFTER}, and a {@link Pointer} to
156      * another phase.
157      */
158     interface Link {
159         enum Kind {
160             BEFORE,
161             AFTER
162         }
163 
164         Kind kind();
165 
166         Pointer pointer();
167     }
168 
169     interface Pointer {
170         enum Type {
171             PROJECT,
172             DEPENDENCIES,
173             CHILDREN
174         }
175 
176         String phase();
177 
178         Type type();
179     }
180 
181     interface PhasePointer extends Pointer {
182         default Type type() {
183             return Type.PROJECT;
184         }
185     }
186 
187     interface DependenciesPointer extends Pointer {
188         String scope(); // default: all
189 
190         default Type type() {
191             return Type.DEPENDENCIES;
192         }
193     }
194 
195     interface ChildrenPointer extends Pointer {
196         default Type type() {
197             return Type.CHILDREN;
198         }
199     }
200 }