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 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
25
26
27 @Experimental
28 @Generated @ThreadSafe @Immutable
29 public class PluginExecution
30 extends ConfigurationContainer
31 implements Serializable, InputLocationTracker
32 {
33
34
35
36
37 final String id;
38
39
40
41
42 final String phase;
43
44
45
46
47
48
49 final int priority;
50
51
52
53 final List<String> goals;
54
55 final Map<Object, InputLocation> locations;
56
57
58
59
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
79
80
81
82
83 public String getId() {
84 return this.id;
85 }
86
87
88
89
90
91
92
93 public String getPhase() {
94 return this.phase;
95 }
96
97
98
99
100
101
102
103
104
105 public int getPriority() {
106 return this.priority;
107 }
108
109
110
111
112
113
114 @Nonnull
115 public List<String> getGoals() {
116 return this.goals;
117 }
118
119
120
121
122 public InputLocation getLocation(Object key) {
123 return locations != null ? locations.get(key) : null;
124 }
125
126
127
128
129 public Set<Object> getLocationKeys() {
130 return locations != null ? locations.keySet() : null;
131 }
132
133
134
135
136
137
138 @Nonnull
139 public Builder with() {
140 return newBuilder(this);
141 }
142
143
144
145
146
147
148 @Nonnull
149 public PluginExecution withInherited(String inherited) {
150 return newBuilder(this, true).inherited(inherited).build();
151 }
152
153
154
155
156
157
158 @Nonnull
159 public PluginExecution withConfiguration(XmlNode configuration) {
160 return newBuilder(this, true).configuration(configuration).build();
161 }
162
163
164
165
166
167
168 @Nonnull
169 public PluginExecution withId(String id) {
170 return newBuilder(this, true).id(id).build();
171 }
172
173
174
175
176
177
178 @Nonnull
179 public PluginExecution withPhase(String phase) {
180 return newBuilder(this, true).phase(phase).build();
181 }
182
183
184
185
186
187
188 @Nonnull
189 public PluginExecution withPriority(int priority) {
190 return newBuilder(this, true).priority(priority).build();
191 }
192
193
194
195
196
197
198 @Nonnull
199 public PluginExecution withGoals(Collection<String> goals) {
200 return newBuilder(this, true).goals(goals).build();
201 }
202
203
204
205
206
207
208
209
210 @Nonnull
211 public static PluginExecution newInstance() {
212 return newInstance(true);
213 }
214
215
216
217
218
219
220
221
222 @Nonnull
223 public static PluginExecution newInstance(boolean withDefaults) {
224 return newBuilder(withDefaults).build();
225 }
226
227
228
229
230
231
232
233
234 @Nonnull
235 public static Builder newBuilder() {
236 return newBuilder(true);
237 }
238
239
240
241
242
243
244
245 @Nonnull
246 public static Builder newBuilder(boolean withDefaults) {
247 return new Builder(withDefaults);
248 }
249
250
251
252
253
254
255
256
257 @Nonnull
258 public static Builder newBuilder(PluginExecution from) {
259 return newBuilder(from, false);
260 }
261
262
263
264
265
266
267
268
269 @Nonnull
270 public static Builder newBuilder(PluginExecution from, boolean forceCopy) {
271 return new Builder(from, forceCopy);
272 }
273
274
275
276
277
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
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 }