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       * Executions derived from the default lifecycle have a negative priority by default so that they are executed
45       * before any custom plugin executions.
46       * <br><b>Since</b>: Maven 4.0.0
47       */
48      final int priority;
49      /**
50       * The goals to execute with the given configuration.
51       */
52      final List<String> goals;
53  
54      /**
55        * Constructor for this class, package protected.
56        * @see Builder#build()
57        */
58      PluginExecution(
59          String inherited,
60          XmlNode configuration,
61          String id,
62          String phase,
63          int priority,
64          Collection<String> goals,
65          Map<Object, InputLocation> locations
66      ) {
67          super(
68              inherited,
69              configuration,
70              locations
71          );
72          this.id = id;
73          this.phase = phase;
74          this.priority = priority;
75          this.goals = ImmutableCollections.copy(goals);
76      }
77  
78      /**
79       * The identifier of this execution for labelling the goals during the build,
80       * and for matching executions to merge during inheritance and profile injection.
81       *
82       * @return a {@code String}
83       */
84      public String getId() {
85          return this.id;
86      }
87  
88      /**
89       * The build lifecycle phase to bind the goals in this execution to. If omitted,
90       * the goals will be bound to the default phase specified by the plugin.
91       *
92       * @return a {@code String}
93       */
94      public String getPhase() {
95          return this.phase;
96      }
97  
98      /**
99       * The priority of this execution compared to other executions which are bound to the same phase.
100      * Executions derived from the default lifecycle have a negative priority by default so that they are executed
101      * before any custom plugin executions.
102      * <br><b>Since</b>: Maven 4.0.0
103      *
104      * @return a {@code int}
105      */
106     public int getPriority() {
107         return this.priority;
108     }
109 
110     /**
111      * The goals to execute with the given configuration.
112      *
113      * @return a {@code List<String>}
114      */
115     @Nonnull
116     public List<String> getGoals() {
117         return this.goals;
118     }
119 
120     /**
121      * Creates a new builder with this object as the basis.
122      *
123      * @return a {@code Builder}
124      */
125     @Nonnull
126     public Builder with() {
127         return newBuilder(this);
128     }
129     /**
130      * Creates a new {@code PluginExecution} instance using the specified inherited.
131      *
132      * @param inherited the new {@code String} to use
133      * @return a {@code PluginExecution} with the specified inherited
134      */
135     @Nonnull
136     public PluginExecution withInherited(String inherited) {
137         return newBuilder(this, true).inherited(inherited).build();
138     }
139     /**
140      * Creates a new {@code PluginExecution} instance using the specified configuration.
141      *
142      * @param configuration the new {@code XmlNode} to use
143      * @return a {@code PluginExecution} with the specified configuration
144      */
145     @Nonnull
146     public PluginExecution withConfiguration(XmlNode configuration) {
147         return newBuilder(this, true).configuration(configuration).build();
148     }
149     /**
150      * Creates a new {@code PluginExecution} instance using the specified id.
151      *
152      * @param id the new {@code String} to use
153      * @return a {@code PluginExecution} with the specified id
154      */
155     @Nonnull
156     public PluginExecution withId(String id) {
157         return newBuilder(this, true).id(id).build();
158     }
159     /**
160      * Creates a new {@code PluginExecution} instance using the specified phase.
161      *
162      * @param phase the new {@code String} to use
163      * @return a {@code PluginExecution} with the specified phase
164      */
165     @Nonnull
166     public PluginExecution withPhase(String phase) {
167         return newBuilder(this, true).phase(phase).build();
168     }
169     /**
170      * Creates a new {@code PluginExecution} instance using the specified priority.
171      *
172      * @param priority the new {@code int} to use
173      * @return a {@code PluginExecution} with the specified priority
174      */
175     @Nonnull
176     public PluginExecution withPriority(int priority) {
177         return newBuilder(this, true).priority(priority).build();
178     }
179     /**
180      * Creates a new {@code PluginExecution} instance using the specified goals.
181      *
182      * @param goals the new {@code Collection<String>} to use
183      * @return a {@code PluginExecution} with the specified goals
184      */
185     @Nonnull
186     public PluginExecution withGoals(Collection<String> goals) {
187         return newBuilder(this, true).goals(goals).build();
188     }
189 
190     /**
191      * Creates a new {@code PluginExecution} instance.
192      * Equivalent to {@code newInstance(true)}.
193      * @see #newInstance(boolean)
194      *
195      * @return a new {@code PluginExecution}
196      */
197     @Nonnull
198     public static PluginExecution newInstance() {
199         return newInstance(true);
200     }
201 
202     /**
203      * Creates a new {@code PluginExecution} instance using default values or not.
204      * Equivalent to {@code newBuilder(withDefaults).build()}.
205      *
206      * @param withDefaults the boolean indicating whether default values should be used
207      * @return a new {@code PluginExecution}
208      */
209     @Nonnull
210     public static PluginExecution newInstance(boolean withDefaults) {
211         return newBuilder(withDefaults).build();
212     }
213 
214     /**
215      * Creates a new {@code PluginExecution} builder instance.
216      * Equivalent to {@code newBuilder(true)}.
217      * @see #newBuilder(boolean)
218      *
219      * @return a new {@code Builder}
220      */
221     @Nonnull
222     public static Builder newBuilder() {
223         return newBuilder(true);
224     }
225 
226     /**
227      * Creates a new {@code PluginExecution} builder instance using default values or not.
228      *
229      * @param withDefaults the boolean indicating whether default values should be used
230      * @return a new {@code Builder}
231      */
232     @Nonnull
233     public static Builder newBuilder(boolean withDefaults) {
234         return new Builder(withDefaults);
235     }
236 
237     /**
238      * Creates a new {@code PluginExecution} builder instance using the specified object as a basis.
239      * Equivalent to {@code newBuilder(from, false)}.
240      *
241      * @param from the {@code PluginExecution} instance to use as a basis
242      * @return a new {@code Builder}
243      */
244     @Nonnull
245     public static Builder newBuilder(PluginExecution from) {
246         return newBuilder(from, false);
247     }
248 
249     /**
250      * Creates a new {@code PluginExecution} builder instance using the specified object as a basis.
251      *
252      * @param from the {@code PluginExecution} instance to use as a basis
253      * @param forceCopy the boolean indicating if a copy should be forced
254      * @return a new {@code Builder}
255      */
256     @Nonnull
257     public static Builder newBuilder(PluginExecution from, boolean forceCopy) {
258         return new Builder(from, forceCopy);
259     }
260 
261     /**
262      * Builder class used to create PluginExecution instances.
263      * @see #with()
264      * @see #newBuilder()
265      */
266     @NotThreadSafe
267     public static class Builder
268         extends ConfigurationContainer.Builder
269     {
270         PluginExecution base;
271         String id;
272         String phase;
273         Integer priority;
274         Collection<String> goals;
275 
276         Builder(boolean withDefaults) {
277             super(withDefaults);
278             if (withDefaults) {
279                 this.id = "default";
280                 this.priority = 0;
281             }
282         }
283 
284         Builder(PluginExecution base, boolean forceCopy) {
285             super(base, forceCopy);
286             if (forceCopy) {
287                 this.id = base.id;
288                 this.phase = base.phase;
289                 this.priority = base.priority;
290                 this.goals = base.goals;
291                 this.locations = base.locations;
292             } else {
293                 this.base = base;
294             }
295         }
296 
297         @Nonnull
298         public Builder inherited(String inherited) {
299             this.inherited = inherited;
300             return this;
301         }
302 
303         @Nonnull
304         public Builder configuration(XmlNode configuration) {
305             this.configuration = configuration;
306             return this;
307         }
308 
309         @Nonnull
310         public Builder id(String id) {
311             this.id = id;
312             return this;
313         }
314 
315         @Nonnull
316         public Builder phase(String phase) {
317             this.phase = phase;
318             return this;
319         }
320 
321         @Nonnull
322         public Builder priority(int priority) {
323             this.priority = priority;
324             return this;
325         }
326 
327         @Nonnull
328         public Builder goals(Collection<String> goals) {
329             this.goals = goals;
330             return this;
331         }
332 
333 
334         @Nonnull
335         public Builder location(Object key, InputLocation location) {
336             if (location != null) {
337                 if (!(this.locations instanceof HashMap)) {
338                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
339                 }
340                 this.locations.put(key, location);
341             }
342             return this;
343         }
344 
345         @Nonnull
346         public PluginExecution build() {
347             if (base != null
348                     && (inherited == null || inherited == base.inherited)
349                     && (configuration == null || configuration == base.configuration)
350                     && (id == null || id == base.id)
351                     && (phase == null || phase == base.phase)
352                     && (priority == null || priority == base.priority)
353                     && (goals == null || goals == base.goals)
354             ) {
355                 return base;
356             }
357             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
358             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
359             Map<Object, InputLocation> locations = new HashMap<>();
360             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
361             locations.put("inherited", newlocs.containsKey("inherited") ? newlocs.get("inherited") : oldlocs.get("inherited"));
362             locations.put("configuration", newlocs.containsKey("configuration") ? newlocs.get("configuration") : oldlocs.get("configuration"));
363             locations.put("id", newlocs.containsKey("id") ? newlocs.get("id") : oldlocs.get("id"));
364             locations.put("phase", newlocs.containsKey("phase") ? newlocs.get("phase") : oldlocs.get("phase"));
365             locations.put("priority", newlocs.containsKey("priority") ? newlocs.get("priority") : oldlocs.get("priority"));
366             locations.put("goals", newlocs.containsKey("goals") ? newlocs.get("goals") : oldlocs.get("goals"));
367             return new PluginExecution(
368                 inherited != null ? inherited : (base != null ? base.inherited : null),
369                 configuration != null ? configuration : (base != null ? base.configuration : null),
370                 id != null ? id : (base != null ? base.id : null),
371                 phase != null ? phase : (base != null ? base.phase : null),
372                 priority != null ? priority : (base != null ? base.priority : 0),
373                 goals != null ? goals : (base != null ? base.goals : null),
374                 locations
375             );
376         }
377     }
378 
379 
380             
381     public static final String DEFAULT_EXECUTION_ID = "default";
382 
383     @Override
384     public String toString()
385     {
386         return getId();
387     }
388             
389           
390 }