View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model.vm
3   //  template, any modifications will be overwritten.
4   // ==============================================================
5   package org.apache.maven.api.plugin.descriptor.lifecycle;
6   
7   import java.io.Serializable;
8   import java.util.ArrayList;
9   import java.util.Collection;
10  import java.util.Collections;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.Objects;
15  import java.util.Optional;
16  import java.util.Set;
17  import java.util.stream.Collectors;
18  import java.util.stream.Stream;
19  import org.apache.maven.api.annotations.Experimental;
20  import org.apache.maven.api.annotations.Generated;
21  import org.apache.maven.api.annotations.Immutable;
22  import org.apache.maven.api.annotations.Nonnull;
23  import org.apache.maven.api.annotations.NotThreadSafe;
24  import org.apache.maven.api.annotations.ThreadSafe;
25  import org.apache.maven.api.xml.XmlNode;
26  
27  /**
28   * A phase mapping definition.
29   */
30  @Experimental
31  @Generated @ThreadSafe @Immutable
32  public class Phase
33      implements Serializable
34  {
35      /**
36       * The ID of this phase, e.g., {@code generate-sources}.
37       */
38      final String id;
39      /**
40       * If specified, identifies this phase as a dynamic phase to decorate the specified phase id, e.g. {@code after} or {@code before}.
41       */
42      final String executionPoint;
43      /**
44       * If specified, identifies a within phase prioritization of executions.
45       */
46      final int priority;
47      /**
48       * The goals to execute within the phase.
49       */
50      final List<Execution> executions;
51      /**
52       * Configuration to pass to all goals run in this phase.
53       */
54      final XmlNode configuration;
55  
56      /**
57        * Constructor for this class, to be called from its subclasses and {@link Builder}.
58        * @see Builder#build()
59        */
60      protected Phase(Builder builder) {
61          this.id = builder.id != null ? builder.id : (builder.base != null ? builder.base.id : null);
62          this.executionPoint = builder.executionPoint != null ? builder.executionPoint : (builder.base != null ? builder.base.executionPoint : null);
63          this.priority = builder.priority != null ? builder.priority : (builder.base != null ? builder.base.priority : 0);
64          this.executions = ImmutableCollections.copy(builder.executions != null ? builder.executions : (builder.base != null ? builder.base.executions : null));
65          this.configuration = builder.configuration != null ? builder.configuration : (builder.base != null ? builder.base.configuration : null);
66      }
67  
68      /**
69       * The ID of this phase, e.g., {@code generate-sources}.
70       *
71       * @return a {@code String}
72       */
73      public String getId() {
74          return this.id;
75      }
76  
77      /**
78       * If specified, identifies this phase as a dynamic phase to decorate the specified phase id, e.g. {@code after} or {@code before}.
79       *
80       * @return a {@code String}
81       */
82      public String getExecutionPoint() {
83          return this.executionPoint;
84      }
85  
86      /**
87       * If specified, identifies a within phase prioritization of executions.
88       *
89       * @return a {@code int}
90       */
91      public int getPriority() {
92          return this.priority;
93      }
94  
95      /**
96       * The goals to execute within the phase.
97       *
98       * @return a {@code List<Execution>}
99       */
100     @Nonnull
101     public List<Execution> getExecutions() {
102         return this.executions;
103     }
104 
105     /**
106      * Configuration to pass to all goals run in this phase.
107      *
108      * @return a {@code XmlNode}
109      */
110     public XmlNode getConfiguration() {
111         return this.configuration;
112     }
113 
114     /**
115      * Creates a new builder with this object as the basis.
116      *
117      * @return a {@code Builder}
118      */
119     @Nonnull
120     public Builder with() {
121         return newBuilder(this);
122     }
123     /**
124      * Creates a new {@code Phase} instance using the specified id.
125      *
126      * @param id the new {@code String} to use
127      * @return a {@code Phase} with the specified id
128      */
129     @Nonnull
130     public Phase withId(String id) {
131         return newBuilder(this, true).id(id).build();
132     }
133     /**
134      * Creates a new {@code Phase} instance using the specified executionPoint.
135      *
136      * @param executionPoint the new {@code String} to use
137      * @return a {@code Phase} with the specified executionPoint
138      */
139     @Nonnull
140     public Phase withExecutionPoint(String executionPoint) {
141         return newBuilder(this, true).executionPoint(executionPoint).build();
142     }
143     /**
144      * Creates a new {@code Phase} instance using the specified priority.
145      *
146      * @param priority the new {@code int} to use
147      * @return a {@code Phase} with the specified priority
148      */
149     @Nonnull
150     public Phase withPriority(int priority) {
151         return newBuilder(this, true).priority(priority).build();
152     }
153     /**
154      * Creates a new {@code Phase} instance using the specified executions.
155      *
156      * @param executions the new {@code Collection<Execution>} to use
157      * @return a {@code Phase} with the specified executions
158      */
159     @Nonnull
160     public Phase withExecutions(Collection<Execution> executions) {
161         return newBuilder(this, true).executions(executions).build();
162     }
163     /**
164      * Creates a new {@code Phase} instance using the specified configuration.
165      *
166      * @param configuration the new {@code XmlNode} to use
167      * @return a {@code Phase} with the specified configuration
168      */
169     @Nonnull
170     public Phase withConfiguration(XmlNode configuration) {
171         return newBuilder(this, true).configuration(configuration).build();
172     }
173 
174     /**
175      * Creates a new {@code Phase} instance.
176      * Equivalent to {@code newInstance(true)}.
177      * @see #newInstance(boolean)
178      *
179      * @return a new {@code Phase}
180      */
181     @Nonnull
182     public static Phase newInstance() {
183         return newInstance(true);
184     }
185 
186     /**
187      * Creates a new {@code Phase} instance using default values or not.
188      * Equivalent to {@code newBuilder(withDefaults).build()}.
189      *
190      * @param withDefaults the boolean indicating whether default values should be used
191      * @return a new {@code Phase}
192      */
193     @Nonnull
194     public static Phase newInstance(boolean withDefaults) {
195         return newBuilder(withDefaults).build();
196     }
197 
198     /**
199      * Creates a new {@code Phase} builder instance.
200      * Equivalent to {@code newBuilder(true)}.
201      * @see #newBuilder(boolean)
202      *
203      * @return a new {@code Builder}
204      */
205     @Nonnull
206     public static Builder newBuilder() {
207         return newBuilder(true);
208     }
209 
210     /**
211      * Creates a new {@code Phase} builder instance using default values or not.
212      *
213      * @param withDefaults the boolean indicating whether default values should be used
214      * @return a new {@code Builder}
215      */
216     @Nonnull
217     public static Builder newBuilder(boolean withDefaults) {
218         return new Builder(withDefaults);
219     }
220 
221     /**
222      * Creates a new {@code Phase} builder instance using the specified object as a basis.
223      * Equivalent to {@code newBuilder(from, false)}.
224      *
225      * @param from the {@code Phase} instance to use as a basis
226      * @return a new {@code Builder}
227      */
228     @Nonnull
229     public static Builder newBuilder(Phase from) {
230         return newBuilder(from, false);
231     }
232 
233     /**
234      * Creates a new {@code Phase} builder instance using the specified object as a basis.
235      *
236      * @param from the {@code Phase} instance to use as a basis
237      * @param forceCopy the boolean indicating if a copy should be forced
238      * @return a new {@code Builder}
239      */
240     @Nonnull
241     public static Builder newBuilder(Phase from, boolean forceCopy) {
242         return new Builder(from, forceCopy);
243     }
244 
245     /**
246      * Builder class used to create Phase instances.
247      * @see #with()
248      * @see #newBuilder()
249      */
250     @NotThreadSafe
251     public static class Builder
252     {
253         Phase base;
254         String id;
255         String executionPoint;
256         Integer priority;
257         Collection<Execution> executions;
258         XmlNode configuration;
259 
260         protected Builder(boolean withDefaults) {
261             if (withDefaults) {
262                 this.priority = 0;
263             }
264         }
265 
266         protected Builder(Phase base, boolean forceCopy) {
267             if (forceCopy) {
268                 this.id = base.id;
269                 this.executionPoint = base.executionPoint;
270                 this.priority = base.priority;
271                 this.executions = base.executions;
272                 this.configuration = base.configuration;
273             } else {
274                 this.base = base;
275             }
276         }
277 
278         @Nonnull
279         public Builder id(String id) {
280             this.id = id;
281             return this;
282         }
283 
284         @Nonnull
285         public Builder executionPoint(String executionPoint) {
286             this.executionPoint = executionPoint;
287             return this;
288         }
289 
290         @Nonnull
291         public Builder priority(int priority) {
292             this.priority = priority;
293             return this;
294         }
295 
296         @Nonnull
297         public Builder executions(Collection<Execution> executions) {
298             this.executions = executions;
299             return this;
300         }
301 
302         @Nonnull
303         public Builder configuration(XmlNode configuration) {
304             this.configuration = configuration;
305             return this;
306         }
307 
308 
309         @Nonnull
310         public Phase build() {
311             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
312             if (base != null
313                     && (id == null || id == base.id)
314                     && (executionPoint == null || executionPoint == base.executionPoint)
315                     && (priority == null || priority == base.priority)
316                     && (executions == null || executions == base.executions)
317                     && (configuration == null || configuration == base.configuration)
318             ) {
319                 return base;
320             }
321             return new Phase(this);
322         }
323 
324     }
325 
326 
327     /**
328      * Get the effective ID of this phase, e.g.,
329      * {@code generate-sources} or {@code after:integration-test[1000]}.
330      *
331      * @return String
332      */
333     public String getEffectiveId() {
334         if (executionPoint == null) {
335             if (priority == 0) {
336                 return id;
337             }
338             return id + '[' + priority + ']';
339         }
340         if (priority == 0) {
341             return executionPoint + ':' + id;
342         }
343         return executionPoint + ':' + id + '[' + priority + ']';
344     }
345 
346 }