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
55
56
57
58 PluginExecution(
59 String inherited,
60 XmlNode configuration,
61 String id,
62 String phase,
63 int priority,
64 Collection<String> goals,
65 Map<Object, InputLocation> locations
66 ) {
67 super(
68 inherited,
69 configuration,
70 locations
71 );
72 this.id = id;
73 this.phase = phase;
74 this.priority = priority;
75 this.goals = ImmutableCollections.copy(goals);
76 }
77
78
79
80
81
82
83
84 public String getId() {
85 return this.id;
86 }
87
88
89
90
91
92
93
94 public String getPhase() {
95 return this.phase;
96 }
97
98
99
100
101
102
103
104
105
106 public int getPriority() {
107 return this.priority;
108 }
109
110
111
112
113
114
115 @Nonnull
116 public List<String> getGoals() {
117 return this.goals;
118 }
119
120
121
122
123
124
125 @Nonnull
126 public Builder with() {
127 return newBuilder(this);
128 }
129
130
131
132
133
134
135 @Nonnull
136 public PluginExecution withInherited(String inherited) {
137 return newBuilder(this, true).inherited(inherited).build();
138 }
139
140
141
142
143
144
145 @Nonnull
146 public PluginExecution withConfiguration(XmlNode configuration) {
147 return newBuilder(this, true).configuration(configuration).build();
148 }
149
150
151
152
153
154
155 @Nonnull
156 public PluginExecution withId(String id) {
157 return newBuilder(this, true).id(id).build();
158 }
159
160
161
162
163
164
165 @Nonnull
166 public PluginExecution withPhase(String phase) {
167 return newBuilder(this, true).phase(phase).build();
168 }
169
170
171
172
173
174
175 @Nonnull
176 public PluginExecution withPriority(int priority) {
177 return newBuilder(this, true).priority(priority).build();
178 }
179
180
181
182
183
184
185 @Nonnull
186 public PluginExecution withGoals(Collection<String> goals) {
187 return newBuilder(this, true).goals(goals).build();
188 }
189
190
191
192
193
194
195
196
197 @Nonnull
198 public static PluginExecution newInstance() {
199 return newInstance(true);
200 }
201
202
203
204
205
206
207
208
209 @Nonnull
210 public static PluginExecution newInstance(boolean withDefaults) {
211 return newBuilder(withDefaults).build();
212 }
213
214
215
216
217
218
219
220
221 @Nonnull
222 public static Builder newBuilder() {
223 return newBuilder(true);
224 }
225
226
227
228
229
230
231
232 @Nonnull
233 public static Builder newBuilder(boolean withDefaults) {
234 return new Builder(withDefaults);
235 }
236
237
238
239
240
241
242
243
244 @Nonnull
245 public static Builder newBuilder(PluginExecution from) {
246 return newBuilder(from, false);
247 }
248
249
250
251
252
253
254
255
256 @Nonnull
257 public static Builder newBuilder(PluginExecution from, boolean forceCopy) {
258 return new Builder(from, forceCopy);
259 }
260
261
262
263
264
265
266 @NotThreadSafe
267 public static class Builder
268 extends ConfigurationContainer.Builder
269 {
270 PluginExecution base;
271 String id;
272 String phase;
273 Integer priority;
274 Collection<String> goals;
275
276 Builder(boolean withDefaults) {
277 super(withDefaults);
278 if (withDefaults) {
279 this.id = "default";
280 this.priority = 0;
281 }
282 }
283
284 Builder(PluginExecution base, boolean forceCopy) {
285 super(base, forceCopy);
286 if (forceCopy) {
287 this.id = base.id;
288 this.phase = base.phase;
289 this.priority = base.priority;
290 this.goals = base.goals;
291 this.locations = base.locations;
292 } else {
293 this.base = base;
294 }
295 }
296
297 @Nonnull
298 public Builder inherited(String inherited) {
299 this.inherited = inherited;
300 return this;
301 }
302
303 @Nonnull
304 public Builder configuration(XmlNode configuration) {
305 this.configuration = configuration;
306 return this;
307 }
308
309 @Nonnull
310 public Builder id(String id) {
311 this.id = id;
312 return this;
313 }
314
315 @Nonnull
316 public Builder phase(String phase) {
317 this.phase = phase;
318 return this;
319 }
320
321 @Nonnull
322 public Builder priority(int priority) {
323 this.priority = priority;
324 return this;
325 }
326
327 @Nonnull
328 public Builder goals(Collection<String> goals) {
329 this.goals = goals;
330 return this;
331 }
332
333
334 @Nonnull
335 public Builder location(Object key, InputLocation location) {
336 if (location != null) {
337 if (!(this.locations instanceof HashMap)) {
338 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
339 }
340 this.locations.put(key, location);
341 }
342 return this;
343 }
344
345 @Nonnull
346 public PluginExecution build() {
347 if (base != null
348 && (inherited == null || inherited == base.inherited)
349 && (configuration == null || configuration == base.configuration)
350 && (id == null || id == base.id)
351 && (phase == null || phase == base.phase)
352 && (priority == null || priority == base.priority)
353 && (goals == null || goals == base.goals)
354 ) {
355 return base;
356 }
357 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
358 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
359 Map<Object, InputLocation> locations = new HashMap<>();
360 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
361 locations.put("inherited", newlocs.containsKey("inherited") ? newlocs.get("inherited") : oldlocs.get("inherited"));
362 locations.put("configuration", newlocs.containsKey("configuration") ? newlocs.get("configuration") : oldlocs.get("configuration"));
363 locations.put("id", newlocs.containsKey("id") ? newlocs.get("id") : oldlocs.get("id"));
364 locations.put("phase", newlocs.containsKey("phase") ? newlocs.get("phase") : oldlocs.get("phase"));
365 locations.put("priority", newlocs.containsKey("priority") ? newlocs.get("priority") : oldlocs.get("priority"));
366 locations.put("goals", newlocs.containsKey("goals") ? newlocs.get("goals") : oldlocs.get("goals"));
367 return new PluginExecution(
368 inherited != null ? inherited : (base != null ? base.inherited : null),
369 configuration != null ? configuration : (base != null ? base.configuration : null),
370 id != null ? id : (base != null ? base.id : null),
371 phase != null ? phase : (base != null ? base.phase : null),
372 priority != null ? priority : (base != null ? base.priority : 0),
373 goals != null ? goals : (base != null ? base.goals : null),
374 locations
375 );
376 }
377 }
378
379
380
381 public static final String DEFAULT_EXECUTION_ID = "default";
382
383 @Override
384 public String toString()
385 {
386 return getId();
387 }
388
389
390 }