1
2
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
23
24
25 @Experimental
26 @Generated @ThreadSafe @Immutable
27 public class PluginExecution
28 extends ConfigurationContainer
29 implements Serializable, InputLocationTracker
30 {
31
32
33
34
35 final String id;
36
37
38
39
40 final String phase;
41
42
43
44
45
46
47 final int priority;
48
49
50
51 final List<String> goals;
52
53 final InputLocation idLocation;
54
55 final InputLocation phaseLocation;
56
57 final InputLocation priorityLocation;
58
59 final InputLocation goalsLocation;
60
61
62
63
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
102
103
104
105
106 public String getId()
107 {
108 return this.id;
109 }
110
111
112
113
114
115
116
117 public String getPhase()
118 {
119 return this.phase;
120 }
121
122
123
124
125
126
127
128
129
130 public int getPriority()
131 {
132 return this.priority;
133 }
134
135
136
137
138
139
140 @Nonnull
141 public List<String> getGoals()
142 {
143 return this.goals;
144 }
145
146
147
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
170
171
172
173 @Nonnull
174 public Builder with()
175 {
176 return newBuilder( this );
177 }
178
179
180
181
182
183
184 @Nonnull
185 public PluginExecution withInherited( String inherited )
186 {
187 return with().inherited( inherited ).build();
188 }
189
190
191
192
193
194
195 @Nonnull
196 public PluginExecution withConfiguration( Dom configuration )
197 {
198 return with().configuration( configuration ).build();
199 }
200
201
202
203
204
205
206 @Nonnull
207 public PluginExecution withId( String id )
208 {
209 return with().id( id ).build();
210 }
211
212
213
214
215
216
217 @Nonnull
218 public PluginExecution withPhase( String phase )
219 {
220 return with().phase( phase ).build();
221 }
222
223
224
225
226
227
228 @Nonnull
229 public PluginExecution withPriority( int priority )
230 {
231 return with().priority( priority ).build();
232 }
233
234
235
236
237
238
239 @Nonnull
240 public PluginExecution withGoals( Collection<String> goals )
241 {
242 return with().goals( goals ).build();
243 }
244
245
246
247
248
249
250
251
252 @Nonnull
253 public static PluginExecution newInstance()
254 {
255 return newInstance( true );
256 }
257
258
259
260
261
262
263
264
265 @Nonnull
266 public static PluginExecution newInstance( boolean withDefaults )
267 {
268 return newBuilder( withDefaults ).build();
269 }
270
271
272
273
274
275
276
277
278 @Nonnull
279 public static Builder newBuilder()
280 {
281 return newBuilder( true );
282 }
283
284
285
286
287
288
289
290 @Nonnull
291 public static Builder newBuilder( boolean withDefaults )
292 {
293 return new Builder( withDefaults );
294 }
295
296
297
298
299
300
301
302
303 @Nonnull
304 public static Builder newBuilder( PluginExecution from )
305 {
306 return newBuilder( from, false );
307 }
308
309
310
311
312
313
314
315
316 @Nonnull
317 public static Builder newBuilder( PluginExecution from, boolean forceCopy )
318 {
319 return new Builder( from, forceCopy );
320 }
321
322
323
324
325
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 }