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