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