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.plugin.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 org.apache.maven.api.annotations.Experimental;
15  import org.apache.maven.api.annotations.Generated;
16  import org.apache.maven.api.annotations.Immutable;
17  import org.apache.maven.api.annotations.Nonnull;
18  import org.apache.maven.api.annotations.NotThreadSafe;
19  import org.apache.maven.api.annotations.ThreadSafe;
20  import org.apache.maven.api.xml.XmlNode;
21  
22  /**
23   * A phase mapping definition.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class Phase
28      implements Serializable
29  {
30      /**
31       * The ID of this phase, e.g., <code>generate-sources</code>.
32       */
33      final String id;
34      /**
35       * The goals to execute within the phase.
36       */
37      final List<Execution> executions;
38      /**
39       * Configuration to pass to all goals run in this phase.
40       */
41      final XmlNode configuration;
42  
43      /**
44        * Constructor for this class, package protected.
45        * @see Builder#build()
46        */
47      Phase(
48          String id,
49          Collection<Execution> executions,
50          XmlNode configuration
51      )
52      {
53          this.id = id;
54          this.executions = ImmutableCollections.copy( executions );
55          this.configuration = configuration;
56      }
57  
58      /**
59       * The ID of this phase, e.g., <code>generate-sources</code>.
60       *
61       * @return a {@code String}
62       */
63      public String getId()
64      {
65          return this.id;
66      }
67  
68      /**
69       * The goals to execute within the phase.
70       *
71       * @return a {@code List<Execution>}
72       */
73      @Nonnull
74      public List<Execution> getExecutions()
75      {
76          return this.executions;
77      }
78  
79      /**
80       * Configuration to pass to all goals run in this phase.
81       *
82       * @return a {@code XmlNode}
83       */
84      public XmlNode getConfiguration()
85      {
86          return this.configuration;
87      }
88  
89      /**
90       * Creates a new builder with this object as the basis.
91       *
92       * @return a {@code Builder}
93       */
94      @Nonnull
95      public Builder with()
96      {
97          return newBuilder( this );
98      }
99      /**
100      * Creates a new {@code Phase} instance using the specified id.
101      *
102      * @param id the new {@code String} to use
103      * @return a {@code Phase} with the specified id
104      */
105     @Nonnull
106     public Phase withId( String id )
107     {
108         return with().id( id ).build();
109     }
110     /**
111      * Creates a new {@code Phase} instance using the specified executions.
112      *
113      * @param executions the new {@code Collection<Execution>} to use
114      * @return a {@code Phase} with the specified executions
115      */
116     @Nonnull
117     public Phase withExecutions( Collection<Execution> executions )
118     {
119         return with().executions( executions ).build();
120     }
121     /**
122      * Creates a new {@code Phase} instance using the specified configuration.
123      *
124      * @param configuration the new {@code XmlNode} to use
125      * @return a {@code Phase} with the specified configuration
126      */
127     @Nonnull
128     public Phase withConfiguration( XmlNode configuration )
129     {
130         return with().configuration( configuration ).build();
131     }
132 
133     /**
134      * Creates a new {@code Phase} instance.
135      * Equivalent to {@code newInstance( true )}.
136      * @see #newInstance(boolean)
137      *
138      * @return a new {@code Phase}
139      */
140     @Nonnull
141     public static Phase newInstance()
142     {
143         return newInstance( true );
144     }
145 
146     /**
147      * Creates a new {@code Phase} instance using default values or not.
148      * Equivalent to {@code newBuilder( withDefaults ).build()}.
149      *
150      * @param withDefaults the boolean indicating whether default values should be used
151      * @return a new {@code Phase}
152      */
153     @Nonnull
154     public static Phase newInstance( boolean withDefaults )
155     {
156         return newBuilder( withDefaults ).build();
157     }
158 
159     /**
160      * Creates a new {@code Phase} builder instance.
161      * Equivalent to {@code newBuilder( true )}.
162      * @see #newBuilder(boolean)
163      *
164      * @return a new {@code Builder}
165      */
166     @Nonnull
167     public static Builder newBuilder()
168     {
169         return newBuilder( true );
170     }
171 
172     /**
173      * Creates a new {@code Phase} builder instance using default values or not.
174      *
175      * @param withDefaults the boolean indicating whether default values should be used
176      * @return a new {@code Builder}
177      */
178     @Nonnull
179     public static Builder newBuilder( boolean withDefaults )
180     {
181         return new Builder( withDefaults );
182     }
183 
184     /**
185      * Creates a new {@code Phase} builder instance using the specified object as a basis.
186      * Equivalent to {@code newBuilder( from, false )}.
187      *
188      * @param from the {@code Phase} instance to use as a basis
189      * @return a new {@code Builder}
190      */
191     @Nonnull
192     public static Builder newBuilder( Phase from )
193     {
194         return newBuilder( from, false );
195     }
196 
197     /**
198      * Creates a new {@code Phase} builder instance using the specified object as a basis.
199      *
200      * @param from the {@code Phase} instance to use as a basis
201      * @param forceCopy the boolean indicating if a copy should be forced
202      * @return a new {@code Builder}
203      */
204     @Nonnull
205     public static Builder newBuilder( Phase from, boolean forceCopy )
206     {
207         return new Builder( from, forceCopy );
208     }
209 
210     /**
211      * Builder class used to create Phase instances.
212      * @see #with()
213      * @see #newBuilder()
214      */
215     @NotThreadSafe
216     public static class Builder
217     {
218         Phase base;
219         String id;
220         Collection<Execution> executions;
221         XmlNode configuration;
222 
223         Builder( boolean withDefaults )
224         {
225             if ( withDefaults )
226             {
227             }
228         }
229 
230         Builder( Phase base, boolean forceCopy )
231         {
232             if ( forceCopy )
233             {
234                 this.id = base.id;
235                 this.executions = base.executions;
236                 this.configuration = base.configuration;
237             }
238             else
239             {
240                 this.base = base;
241             }
242         }
243 
244         @Nonnull
245         public Builder id( String id )
246         {
247             this.id = id;
248             return this;
249         }
250 
251         @Nonnull
252         public Builder executions( Collection<Execution> executions )
253         {
254             this.executions = executions;
255             return this;
256         }
257 
258         @Nonnull
259         public Builder configuration( XmlNode configuration )
260         {
261             this.configuration = configuration;
262             return this;
263         }
264 
265 
266         @Nonnull
267         public Phase build()
268         {
269             if ( base != null
270                     && ( id == null || id == base.id )
271                     && ( executions == null || executions == base.executions )
272                     && ( configuration == null || configuration == base.configuration )
273             )
274             {
275                 return base;
276             }
277             return new Phase(
278                 id != null ? id : ( base != null ? base.id : null ),
279                 executions != null ? executions : ( base != null ? base.executions : null ),
280                 configuration != null ? configuration : ( base != null ? base.configuration : null )
281             );
282         }
283     }
284 
285 }