1
2
3
4
5 package org.apache.maven.api.plugin.descriptor.lifecycle;
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 @Experimental
31 @Generated @ThreadSafe @Immutable
32 public class Phase
33 implements Serializable
34 {
35
36
37
38 final String id;
39
40
41
42 final String executionPoint;
43
44
45
46 final int priority;
47
48
49
50 final List<Execution> executions;
51
52
53
54 final XmlNode configuration;
55
56
57
58
59
60 protected Phase(Builder builder) {
61 this.id = builder.id != null ? builder.id : (builder.base != null ? builder.base.id : null);
62 this.executionPoint = builder.executionPoint != null ? builder.executionPoint : (builder.base != null ? builder.base.executionPoint : null);
63 this.priority = builder.priority != null ? builder.priority : (builder.base != null ? builder.base.priority : 0);
64 this.executions = ImmutableCollections.copy(builder.executions != null ? builder.executions : (builder.base != null ? builder.base.executions : null));
65 this.configuration = builder.configuration != null ? builder.configuration : (builder.base != null ? builder.base.configuration : null);
66 }
67
68
69
70
71
72
73 public String getId() {
74 return this.id;
75 }
76
77
78
79
80
81
82 public String getExecutionPoint() {
83 return this.executionPoint;
84 }
85
86
87
88
89
90
91 public int getPriority() {
92 return this.priority;
93 }
94
95
96
97
98
99
100 @Nonnull
101 public List<Execution> getExecutions() {
102 return this.executions;
103 }
104
105
106
107
108
109
110 public XmlNode getConfiguration() {
111 return this.configuration;
112 }
113
114
115
116
117
118
119 @Nonnull
120 public Builder with() {
121 return newBuilder(this);
122 }
123
124
125
126
127
128
129 @Nonnull
130 public Phase withId(String id) {
131 return newBuilder(this, true).id(id).build();
132 }
133
134
135
136
137
138
139 @Nonnull
140 public Phase withExecutionPoint(String executionPoint) {
141 return newBuilder(this, true).executionPoint(executionPoint).build();
142 }
143
144
145
146
147
148
149 @Nonnull
150 public Phase withPriority(int priority) {
151 return newBuilder(this, true).priority(priority).build();
152 }
153
154
155
156
157
158
159 @Nonnull
160 public Phase withExecutions(Collection<Execution> executions) {
161 return newBuilder(this, true).executions(executions).build();
162 }
163
164
165
166
167
168
169 @Nonnull
170 public Phase withConfiguration(XmlNode configuration) {
171 return newBuilder(this, true).configuration(configuration).build();
172 }
173
174
175
176
177
178
179
180
181 @Nonnull
182 public static Phase newInstance() {
183 return newInstance(true);
184 }
185
186
187
188
189
190
191
192
193 @Nonnull
194 public static Phase newInstance(boolean withDefaults) {
195 return newBuilder(withDefaults).build();
196 }
197
198
199
200
201
202
203
204
205 @Nonnull
206 public static Builder newBuilder() {
207 return newBuilder(true);
208 }
209
210
211
212
213
214
215
216 @Nonnull
217 public static Builder newBuilder(boolean withDefaults) {
218 return new Builder(withDefaults);
219 }
220
221
222
223
224
225
226
227
228 @Nonnull
229 public static Builder newBuilder(Phase from) {
230 return newBuilder(from, false);
231 }
232
233
234
235
236
237
238
239
240 @Nonnull
241 public static Builder newBuilder(Phase from, boolean forceCopy) {
242 return new Builder(from, forceCopy);
243 }
244
245
246
247
248
249
250 @NotThreadSafe
251 public static class Builder
252 {
253 Phase base;
254 String id;
255 String executionPoint;
256 Integer priority;
257 Collection<Execution> executions;
258 XmlNode configuration;
259
260 protected Builder(boolean withDefaults) {
261 if (withDefaults) {
262 this.priority = 0;
263 }
264 }
265
266 protected Builder(Phase base, boolean forceCopy) {
267 if (forceCopy) {
268 this.id = base.id;
269 this.executionPoint = base.executionPoint;
270 this.priority = base.priority;
271 this.executions = base.executions;
272 this.configuration = base.configuration;
273 } else {
274 this.base = base;
275 }
276 }
277
278 @Nonnull
279 public Builder id(String id) {
280 this.id = id;
281 return this;
282 }
283
284 @Nonnull
285 public Builder executionPoint(String executionPoint) {
286 this.executionPoint = executionPoint;
287 return this;
288 }
289
290 @Nonnull
291 public Builder priority(int priority) {
292 this.priority = priority;
293 return this;
294 }
295
296 @Nonnull
297 public Builder executions(Collection<Execution> executions) {
298 this.executions = executions;
299 return this;
300 }
301
302 @Nonnull
303 public Builder configuration(XmlNode configuration) {
304 this.configuration = configuration;
305 return this;
306 }
307
308
309 @Nonnull
310 public Phase build() {
311
312 if (base != null
313 && (id == null || id == base.id)
314 && (executionPoint == null || executionPoint == base.executionPoint)
315 && (priority == null || priority == base.priority)
316 && (executions == null || executions == base.executions)
317 && (configuration == null || configuration == base.configuration)
318 ) {
319 return base;
320 }
321 return new Phase(this);
322 }
323
324 }
325
326
327
328
329
330
331
332
333 public String getEffectiveId() {
334 if (executionPoint == null) {
335 if (priority == 0) {
336 return id;
337 }
338 return id + '[' + priority + ']';
339 }
340 if (priority == 0) {
341 return executionPoint + ':' + id;
342 }
343 return executionPoint + ':' + id + '[' + priority + ']';
344 }
345
346 }