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