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