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.model;
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   * The {@code <execution>} element contains informations required for the
24   * execution of a plugin.
25   */
26  @Experimental
27  @Generated @ThreadSafe @Immutable
28  public class PluginExecution
29      extends ConfigurationContainer
30      implements Serializable, InputLocationTracker
31  {
32      /**
33       * The identifier of this execution for labelling the goals during the build,
34       * and for matching executions to merge during inheritance and profile injection.
35       */
36      final String id;
37      /**
38       * The build lifecycle phase to bind the goals in this execution to. If omitted,
39       * the goals will be bound to the default phase specified by the plugin.
40       */
41      final String phase;
42      /**
43       * The priority of this execution compared to other executions which are bound to the same phase.
44       * <strong>Warning:</strong> This is an internal utility property that is only public for technical reasons,
45       * it is not part of the public API. In particular, this property can be changed or deleted without prior
46       * notice.
47       */
48      final int priority;
49      /**
50       * The goals to execute with the given configuration.
51       */
52      final List<String> goals;
53      /** Location of the xml element for the field id. */
54      final InputLocation idLocation;
55      /** Location of the xml element for the field phase. */
56      final InputLocation phaseLocation;
57      /** Location of the xml element for the field priority. */
58      final InputLocation priorityLocation;
59      /** Location of the xml element for the field goals. */
60      final InputLocation goalsLocation;
61  
62      /**
63        * Constructor for this class, package protected.
64        * @see Builder#build()
65        */
66      PluginExecution(
67          String inherited,
68          XmlNode configuration,
69          String id,
70          String phase,
71          int priority,
72          Collection<String> goals,
73          Map<Object, InputLocation> locations,
74          InputLocation location,
75          InputLocation inheritedLocation,
76          InputLocation configurationLocation,
77          InputLocation idLocation,
78          InputLocation phaseLocation,
79          InputLocation priorityLocation,
80          InputLocation goalsLocation
81      )
82      {
83          super(
84              inherited,
85              configuration,
86              locations,
87              location,
88              inheritedLocation,
89              configurationLocation
90          );
91          this.id = id;
92          this.phase = phase;
93          this.priority = priority;
94          this.goals = ImmutableCollections.copy( goals );
95          this.idLocation = idLocation;
96          this.phaseLocation = phaseLocation;
97          this.priorityLocation = priorityLocation;
98          this.goalsLocation = goalsLocation;
99      }
100 
101     /**
102      * The identifier of this execution for labelling the goals during the build,
103      * and for matching executions to merge during inheritance and profile injection.
104      *
105      * @return a {@code String}
106      */
107     public String getId()
108     {
109         return this.id;
110     }
111 
112     /**
113      * The build lifecycle phase to bind the goals in this execution to. If omitted,
114      * the goals will be bound to the default phase specified by the plugin.
115      *
116      * @return a {@code String}
117      */
118     public String getPhase()
119     {
120         return this.phase;
121     }
122 
123     /**
124      * The priority of this execution compared to other executions which are bound to the same phase.
125      * <strong>Warning:</strong> This is an internal utility property that is only public for technical reasons,
126      * it is not part of the public API. In particular, this property can be changed or deleted without prior
127      * notice.
128      *
129      * @return a {@code int}
130      */
131     public int getPriority()
132     {
133         return this.priority;
134     }
135 
136     /**
137      * The goals to execute with the given configuration.
138      *
139      * @return a {@code List<String>}
140      */
141     @Nonnull
142     public List<String> getGoals()
143     {
144         return this.goals;
145     }
146 
147     /**
148      * Gets the location of the specified field in the input source.
149      */
150     public InputLocation getLocation( Object key )
151     {
152         if ( key instanceof String )
153         {
154             switch ( ( String ) key )
155             {
156                 case "id":
157                     return idLocation;
158                 case "phase":
159                     return phaseLocation;
160                 case "priority":
161                     return priorityLocation;
162                 case "goals":
163                     return goalsLocation;
164             }
165         }
166         return super.getLocation( key );
167     }
168 
169     /**
170      * Creates a new builder with this object as the basis.
171      *
172      * @return a {@code Builder}
173      */
174     @Nonnull
175     public Builder with()
176     {
177         return newBuilder( this );
178     }
179     /**
180      * Creates a new {@code PluginExecution} instance using the specified inherited.
181      *
182      * @param inherited the new {@code String} to use
183      * @return a {@code PluginExecution} with the specified inherited
184      */
185     @Nonnull
186     public PluginExecution withInherited( String inherited )
187     {
188         return with().inherited( inherited ).build();
189     }
190     /**
191      * Creates a new {@code PluginExecution} instance using the specified configuration.
192      *
193      * @param configuration the new {@code XmlNode} to use
194      * @return a {@code PluginExecution} with the specified configuration
195      */
196     @Nonnull
197     public PluginExecution withConfiguration( XmlNode configuration )
198     {
199         return with().configuration( configuration ).build();
200     }
201     /**
202      * Creates a new {@code PluginExecution} instance using the specified id.
203      *
204      * @param id the new {@code String} to use
205      * @return a {@code PluginExecution} with the specified id
206      */
207     @Nonnull
208     public PluginExecution withId( String id )
209     {
210         return with().id( id ).build();
211     }
212     /**
213      * Creates a new {@code PluginExecution} instance using the specified phase.
214      *
215      * @param phase the new {@code String} to use
216      * @return a {@code PluginExecution} with the specified phase
217      */
218     @Nonnull
219     public PluginExecution withPhase( String phase )
220     {
221         return with().phase( phase ).build();
222     }
223     /**
224      * Creates a new {@code PluginExecution} instance using the specified priority.
225      *
226      * @param priority the new {@code int} to use
227      * @return a {@code PluginExecution} with the specified priority
228      */
229     @Nonnull
230     public PluginExecution withPriority( int priority )
231     {
232         return with().priority( priority ).build();
233     }
234     /**
235      * Creates a new {@code PluginExecution} instance using the specified goals.
236      *
237      * @param goals the new {@code Collection<String>} to use
238      * @return a {@code PluginExecution} with the specified goals
239      */
240     @Nonnull
241     public PluginExecution withGoals( Collection<String> goals )
242     {
243         return with().goals( goals ).build();
244     }
245 
246     /**
247      * Creates a new {@code PluginExecution} instance.
248      * Equivalent to {@code newInstance( true )}.
249      * @see #newInstance(boolean)
250      *
251      * @return a new {@code PluginExecution}
252      */
253     @Nonnull
254     public static PluginExecution newInstance()
255     {
256         return newInstance( true );
257     }
258 
259     /**
260      * Creates a new {@code PluginExecution} instance using default values or not.
261      * Equivalent to {@code newBuilder( withDefaults ).build()}.
262      *
263      * @param withDefaults the boolean indicating whether default values should be used
264      * @return a new {@code PluginExecution}
265      */
266     @Nonnull
267     public static PluginExecution newInstance( boolean withDefaults )
268     {
269         return newBuilder( withDefaults ).build();
270     }
271 
272     /**
273      * Creates a new {@code PluginExecution} builder instance.
274      * Equivalent to {@code newBuilder( true )}.
275      * @see #newBuilder(boolean)
276      *
277      * @return a new {@code Builder}
278      */
279     @Nonnull
280     public static Builder newBuilder()
281     {
282         return newBuilder( true );
283     }
284 
285     /**
286      * Creates a new {@code PluginExecution} builder instance using default values or not.
287      *
288      * @param withDefaults the boolean indicating whether default values should be used
289      * @return a new {@code Builder}
290      */
291     @Nonnull
292     public static Builder newBuilder( boolean withDefaults )
293     {
294         return new Builder( withDefaults );
295     }
296 
297     /**
298      * Creates a new {@code PluginExecution} builder instance using the specified object as a basis.
299      * Equivalent to {@code newBuilder( from, false )}.
300      *
301      * @param from the {@code PluginExecution} instance to use as a basis
302      * @return a new {@code Builder}
303      */
304     @Nonnull
305     public static Builder newBuilder( PluginExecution from )
306     {
307         return newBuilder( from, false );
308     }
309 
310     /**
311      * Creates a new {@code PluginExecution} builder instance using the specified object as a basis.
312      *
313      * @param from the {@code PluginExecution} instance to use as a basis
314      * @param forceCopy the boolean indicating if a copy should be forced
315      * @return a new {@code Builder}
316      */
317     @Nonnull
318     public static Builder newBuilder( PluginExecution from, boolean forceCopy )
319     {
320         return new Builder( from, forceCopy );
321     }
322 
323     /**
324      * Builder class used to create PluginExecution instances.
325      * @see #with()
326      * @see #newBuilder()
327      */
328     @NotThreadSafe
329     public static class Builder
330         extends ConfigurationContainer.Builder
331     {
332         PluginExecution base;
333         String id;
334         String phase;
335         Integer priority;
336         Collection<String> goals;
337 
338         Builder( boolean withDefaults )
339         {
340             super( withDefaults );
341             if ( withDefaults )
342             {
343                 this.id = "default";
344                 this.priority = 0;
345             }
346         }
347 
348         Builder( PluginExecution base, boolean forceCopy )
349         {
350             super( base, forceCopy );
351             if ( forceCopy )
352             {
353                 this.id = base.id;
354                 this.phase = base.phase;
355                 this.priority = base.priority;
356                 this.goals = base.goals;
357             }
358             else
359             {
360                 this.base = base;
361             }
362         }
363 
364         @Nonnull
365         public Builder inherited( String inherited )
366         {
367             this.inherited = inherited;
368             return this;
369         }
370 
371         @Nonnull
372         public Builder configuration( XmlNode configuration )
373         {
374             this.configuration = configuration;
375             return this;
376         }
377 
378         @Nonnull
379         public Builder id( String id )
380         {
381             this.id = id;
382             return this;
383         }
384 
385         @Nonnull
386         public Builder phase( String phase )
387         {
388             this.phase = phase;
389             return this;
390         }
391 
392         @Nonnull
393         public Builder priority( int priority )
394         {
395             this.priority = priority;
396             return this;
397         }
398 
399         @Nonnull
400         public Builder goals( Collection<String> goals )
401         {
402             this.goals = goals;
403             return this;
404         }
405 
406 
407         @Nonnull
408         public Builder location( Object key, InputLocation location )
409         {
410             if ( location != null )
411             {
412                 if ( this.locations == null )
413                 {
414                     this.locations = new HashMap<>();
415                 }
416                 this.locations.put( key, location );
417             }
418             return this;
419         }
420 
421         @Nonnull
422         public PluginExecution build()
423         {
424             if ( base != null
425                     && ( inherited == null || inherited == base.inherited )
426                     && ( configuration == null || configuration == base.configuration )
427                     && ( id == null || id == base.id )
428                     && ( phase == null || phase == base.phase )
429                     && ( priority == null || priority == base.priority )
430                     && ( goals == null || goals == base.goals )
431             )
432             {
433                 return base;
434             }
435             Map<Object, InputLocation> locations = null;
436             InputLocation location = null;
437             InputLocation inheritedLocation = null;
438             InputLocation configurationLocation = null;
439             InputLocation idLocation = null;
440             InputLocation phaseLocation = null;
441             InputLocation priorityLocation = null;
442             InputLocation goalsLocation = null;
443             if ( this.locations != null )
444             {
445                 locations = this.locations;
446                 location = locations.remove( "" );
447                 inheritedLocation = locations.remove( "inherited" );
448                 configurationLocation = locations.remove( "configuration" );
449                 idLocation = locations.remove( "id" );
450                 phaseLocation = locations.remove( "phase" );
451                 priorityLocation = locations.remove( "priority" );
452                 goalsLocation = locations.remove( "goals" );
453             }
454             return new PluginExecution(
455                 inherited != null ? inherited : ( base != null ? base.inherited : null ),
456                 configuration != null ? configuration : ( base != null ? base.configuration : null ),
457                 id != null ? id : ( base != null ? base.id : null ),
458                 phase != null ? phase : ( base != null ? base.phase : null ),
459                 priority != null ? priority : ( base != null ? base.priority : 0 ),
460                 goals != null ? goals : ( base != null ? base.goals : null ),
461                 locations != null ? locations : ( base != null ? base.locations : null ),
462                 location != null ? location : ( base != null ? base.location : null ),
463                 inheritedLocation != null ? inheritedLocation : ( base != null ? base.inheritedLocation : null ),
464                 configurationLocation != null ? configurationLocation : ( base != null ? base.configurationLocation : null ),
465                 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
466                 phaseLocation != null ? phaseLocation : ( base != null ? base.phaseLocation : null ),
467                 priorityLocation != null ? priorityLocation : ( base != null ? base.priorityLocation : null ),
468                 goalsLocation != null ? goalsLocation : ( base != null ? base.goalsLocation : null )
469             );
470         }
471     }
472 
473 
474             
475     public static final String DEFAULT_EXECUTION_ID = "default";
476 
477     @Override
478     public String toString()
479     {
480         return getId();
481     }
482             
483           
484 }