1
2
3
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
24
25
26 @Experimental
27 @Generated @ThreadSafe @Immutable
28 public class PluginExecution
29 extends ConfigurationContainer
30 implements Serializable, InputLocationTracker
31 {
32
33
34
35
36 final String id;
37
38
39
40
41 final String phase;
42
43
44
45
46
47
48 final int priority;
49
50
51
52 final List<String> goals;
53
54 final InputLocation idLocation;
55
56 final InputLocation phaseLocation;
57
58 final InputLocation priorityLocation;
59
60 final InputLocation goalsLocation;
61
62
63
64
65
66 PluginExecution(
67 String inherited,
68 XmlNode configuration,
69 String id,
70 String phase,
71 int priority,
72 Collection<String> goals,
73 Map<Object, InputLocation> locations,
74 InputLocation location,
75 InputLocation inheritedLocation,
76 InputLocation configurationLocation,
77 InputLocation idLocation,
78 InputLocation phaseLocation,
79 InputLocation priorityLocation,
80 InputLocation goalsLocation
81 )
82 {
83 super(
84 inherited,
85 configuration,
86 locations,
87 location,
88 inheritedLocation,
89 configurationLocation
90 );
91 this.id = id;
92 this.phase = phase;
93 this.priority = priority;
94 this.goals = ImmutableCollections.copy( goals );
95 this.idLocation = idLocation;
96 this.phaseLocation = phaseLocation;
97 this.priorityLocation = priorityLocation;
98 this.goalsLocation = goalsLocation;
99 }
100
101
102
103
104
105
106
107 public String getId()
108 {
109 return this.id;
110 }
111
112
113
114
115
116
117
118 public String getPhase()
119 {
120 return this.phase;
121 }
122
123
124
125
126
127
128
129
130
131 public int getPriority()
132 {
133 return this.priority;
134 }
135
136
137
138
139
140
141 @Nonnull
142 public List<String> getGoals()
143 {
144 return this.goals;
145 }
146
147
148
149
150 public InputLocation getLocation( Object key )
151 {
152 if ( key instanceof String )
153 {
154 switch ( ( String ) key )
155 {
156 case "id":
157 return idLocation;
158 case "phase":
159 return phaseLocation;
160 case "priority":
161 return priorityLocation;
162 case "goals":
163 return goalsLocation;
164 }
165 }
166 return super.getLocation( key );
167 }
168
169
170
171
172
173
174 @Nonnull
175 public Builder with()
176 {
177 return newBuilder( this );
178 }
179
180
181
182
183
184
185 @Nonnull
186 public PluginExecution withInherited( String inherited )
187 {
188 return with().inherited( inherited ).build();
189 }
190
191
192
193
194
195
196 @Nonnull
197 public PluginExecution withConfiguration( XmlNode configuration )
198 {
199 return with().configuration( configuration ).build();
200 }
201
202
203
204
205
206
207 @Nonnull
208 public PluginExecution withId( String id )
209 {
210 return with().id( id ).build();
211 }
212
213
214
215
216
217
218 @Nonnull
219 public PluginExecution withPhase( String phase )
220 {
221 return with().phase( phase ).build();
222 }
223
224
225
226
227
228
229 @Nonnull
230 public PluginExecution withPriority( int priority )
231 {
232 return with().priority( priority ).build();
233 }
234
235
236
237
238
239
240 @Nonnull
241 public PluginExecution withGoals( Collection<String> goals )
242 {
243 return with().goals( goals ).build();
244 }
245
246
247
248
249
250
251
252
253 @Nonnull
254 public static PluginExecution newInstance()
255 {
256 return newInstance( true );
257 }
258
259
260
261
262
263
264
265
266 @Nonnull
267 public static PluginExecution newInstance( boolean withDefaults )
268 {
269 return newBuilder( withDefaults ).build();
270 }
271
272
273
274
275
276
277
278
279 @Nonnull
280 public static Builder newBuilder()
281 {
282 return newBuilder( true );
283 }
284
285
286
287
288
289
290
291 @Nonnull
292 public static Builder newBuilder( boolean withDefaults )
293 {
294 return new Builder( withDefaults );
295 }
296
297
298
299
300
301
302
303
304 @Nonnull
305 public static Builder newBuilder( PluginExecution from )
306 {
307 return newBuilder( from, false );
308 }
309
310
311
312
313
314
315
316
317 @Nonnull
318 public static Builder newBuilder( PluginExecution from, boolean forceCopy )
319 {
320 return new Builder( from, forceCopy );
321 }
322
323
324
325
326
327
328 @NotThreadSafe
329 public static class Builder
330 extends ConfigurationContainer.Builder
331 {
332 PluginExecution base;
333 String id;
334 String phase;
335 Integer priority;
336 Collection<String> goals;
337
338 Builder( boolean withDefaults )
339 {
340 super( withDefaults );
341 if ( withDefaults )
342 {
343 this.id = "default";
344 this.priority = 0;
345 }
346 }
347
348 Builder( PluginExecution base, boolean forceCopy )
349 {
350 super( base, forceCopy );
351 if ( forceCopy )
352 {
353 this.id = base.id;
354 this.phase = base.phase;
355 this.priority = base.priority;
356 this.goals = base.goals;
357 }
358 else
359 {
360 this.base = base;
361 }
362 }
363
364 @Nonnull
365 public Builder inherited( String inherited )
366 {
367 this.inherited = inherited;
368 return this;
369 }
370
371 @Nonnull
372 public Builder configuration( XmlNode configuration )
373 {
374 this.configuration = configuration;
375 return this;
376 }
377
378 @Nonnull
379 public Builder id( String id )
380 {
381 this.id = id;
382 return this;
383 }
384
385 @Nonnull
386 public Builder phase( String phase )
387 {
388 this.phase = phase;
389 return this;
390 }
391
392 @Nonnull
393 public Builder priority( int priority )
394 {
395 this.priority = priority;
396 return this;
397 }
398
399 @Nonnull
400 public Builder goals( Collection<String> goals )
401 {
402 this.goals = goals;
403 return this;
404 }
405
406
407 @Nonnull
408 public Builder location( Object key, InputLocation location )
409 {
410 if ( location != null )
411 {
412 if ( this.locations == null )
413 {
414 this.locations = new HashMap<>();
415 }
416 this.locations.put( key, location );
417 }
418 return this;
419 }
420
421 @Nonnull
422 public PluginExecution build()
423 {
424 if ( base != null
425 && ( inherited == null || inherited == base.inherited )
426 && ( configuration == null || configuration == base.configuration )
427 && ( id == null || id == base.id )
428 && ( phase == null || phase == base.phase )
429 && ( priority == null || priority == base.priority )
430 && ( goals == null || goals == base.goals )
431 )
432 {
433 return base;
434 }
435 Map<Object, InputLocation> locations = null;
436 InputLocation location = null;
437 InputLocation inheritedLocation = null;
438 InputLocation configurationLocation = null;
439 InputLocation idLocation = null;
440 InputLocation phaseLocation = null;
441 InputLocation priorityLocation = null;
442 InputLocation goalsLocation = null;
443 if ( this.locations != null )
444 {
445 locations = this.locations;
446 location = locations.remove( "" );
447 inheritedLocation = locations.remove( "inherited" );
448 configurationLocation = locations.remove( "configuration" );
449 idLocation = locations.remove( "id" );
450 phaseLocation = locations.remove( "phase" );
451 priorityLocation = locations.remove( "priority" );
452 goalsLocation = locations.remove( "goals" );
453 }
454 return new PluginExecution(
455 inherited != null ? inherited : ( base != null ? base.inherited : null ),
456 configuration != null ? configuration : ( base != null ? base.configuration : null ),
457 id != null ? id : ( base != null ? base.id : null ),
458 phase != null ? phase : ( base != null ? base.phase : null ),
459 priority != null ? priority : ( base != null ? base.priority : 0 ),
460 goals != null ? goals : ( base != null ? base.goals : null ),
461 locations != null ? locations : ( base != null ? base.locations : null ),
462 location != null ? location : ( base != null ? base.location : null ),
463 inheritedLocation != null ? inheritedLocation : ( base != null ? base.inheritedLocation : null ),
464 configurationLocation != null ? configurationLocation : ( base != null ? base.configurationLocation : null ),
465 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
466 phaseLocation != null ? phaseLocation : ( base != null ? base.phaseLocation : null ),
467 priorityLocation != null ? priorityLocation : ( base != null ? base.priorityLocation : null ),
468 goalsLocation != null ? goalsLocation : ( base != null ? base.goalsLocation : null )
469 );
470 }
471 }
472
473
474
475 public static final String DEFAULT_EXECUTION_ID = "default";
476
477 @Override
478 public String toString()
479 {
480 return getId();
481 }
482
483
484 }