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