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