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.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      String WRAPPER = "wrapper";
53  
54      // ======================
55      // Phase qualifiers
56      // ======================
57      String BEFORE = "before:";
58      String AFTER = "after:";
59      String AT = "at:";
60  
61      /**
62       * Name or identifier of this lifecycle.
63       *
64       * @return the unique identifier for this lifecycle
65       */
66      @Override
67      String id();
68  
69      /**
70       * Collection of phases for this lifecycle
71       */
72      Collection<Phase> phases();
73  
74      /**
75       * Stream of phases containing all child phases recursively.
76       */
77      default Stream<Phase> allPhases() {
78          return phases().stream().flatMap(Phase::allPhases);
79      }
80  
81      /**
82       * Collection of aliases.
83       */
84      Collection<Alias> aliases();
85  
86      /**
87       * Pre-ordered list of phases.
88       * If not provided, a default order will be computed.
89       */
90      default Optional<List<String>> orderedPhases() {
91          return Optional.empty();
92      }
93  
94      /**
95       * A phase in the lifecycle.
96       *
97       * A phase is identified by its name. It also contains a list of plugins bound to that phase,
98       * a list of {@link Link links}, and a list of sub-phases.  This forms a tree of phases.
99       */
100     interface Phase {
101 
102         // ======================
103         // Maven defined phases
104         // ======================
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 }