1
2
3
4
5 package org.apache.maven.api.model;
6
7 import java.io.Serializable;
8 import java.util.Collections;
9 import java.util.HashMap;
10 import java.util.Map;
11 import org.apache.maven.api.annotations.Experimental;
12 import org.apache.maven.api.annotations.Generated;
13 import org.apache.maven.api.annotations.Immutable;
14 import org.apache.maven.api.annotations.Nonnull;
15 import org.apache.maven.api.annotations.NotThreadSafe;
16 import org.apache.maven.api.annotations.ThreadSafe;
17
18
19
20
21
22
23 @Experimental
24 @Generated @ThreadSafe @Immutable
25 public class Activation
26 implements Serializable, InputLocationTracker
27 {
28
29
30
31
32
33 final boolean activeByDefault;
34
35
36
37
38
39
40 final String jdk;
41
42
43
44
45 final ActivationOS os;
46
47
48
49
50 final ActivationProperty property;
51
52
53
54 final ActivationFile file;
55
56
57
58 final String packaging;
59
60 final Map<Object, InputLocation> locations;
61
62
63
64
65
66 Activation(
67 boolean activeByDefault,
68 String jdk,
69 ActivationOS os,
70 ActivationProperty property,
71 ActivationFile file,
72 String packaging,
73 Map<Object, InputLocation> locations
74 ) {
75 this.activeByDefault = activeByDefault;
76 this.jdk = jdk;
77 this.os = os;
78 this.property = property;
79 this.file = file;
80 this.packaging = packaging;
81 this.locations = ImmutableCollections.copy(locations);
82 }
83
84
85
86
87
88
89
90
91 public boolean isActiveByDefault() {
92 return this.activeByDefault;
93 }
94
95
96
97
98
99
100
101
102
103 public String getJdk() {
104 return this.jdk;
105 }
106
107
108
109
110
111
112
113 public ActivationOS getOs() {
114 return this.os;
115 }
116
117
118
119
120
121
122
123 public ActivationProperty getProperty() {
124 return this.property;
125 }
126
127
128
129
130
131
132 public ActivationFile getFile() {
133 return this.file;
134 }
135
136
137
138
139
140
141 public String getPackaging() {
142 return this.packaging;
143 }
144
145
146
147
148 public InputLocation getLocation(Object key) {
149 return locations != null ? locations.get(key) : null;
150 }
151
152
153
154
155
156
157 @Nonnull
158 public Builder with() {
159 return newBuilder(this);
160 }
161
162
163
164
165
166
167 @Nonnull
168 public Activation withActiveByDefault(boolean activeByDefault) {
169 return newBuilder(this, true).activeByDefault(activeByDefault).build();
170 }
171
172
173
174
175
176
177 @Nonnull
178 public Activation withJdk(String jdk) {
179 return newBuilder(this, true).jdk(jdk).build();
180 }
181
182
183
184
185
186
187 @Nonnull
188 public Activation withOs(ActivationOS os) {
189 return newBuilder(this, true).os(os).build();
190 }
191
192
193
194
195
196
197 @Nonnull
198 public Activation withProperty(ActivationProperty property) {
199 return newBuilder(this, true).property(property).build();
200 }
201
202
203
204
205
206
207 @Nonnull
208 public Activation withFile(ActivationFile file) {
209 return newBuilder(this, true).file(file).build();
210 }
211
212
213
214
215
216
217 @Nonnull
218 public Activation withPackaging(String packaging) {
219 return newBuilder(this, true).packaging(packaging).build();
220 }
221
222
223
224
225
226
227
228
229 @Nonnull
230 public static Activation newInstance() {
231 return newInstance(true);
232 }
233
234
235
236
237
238
239
240
241 @Nonnull
242 public static Activation newInstance(boolean withDefaults) {
243 return newBuilder(withDefaults).build();
244 }
245
246
247
248
249
250
251
252
253 @Nonnull
254 public static Builder newBuilder() {
255 return newBuilder(true);
256 }
257
258
259
260
261
262
263
264 @Nonnull
265 public static Builder newBuilder(boolean withDefaults) {
266 return new Builder(withDefaults);
267 }
268
269
270
271
272
273
274
275
276 @Nonnull
277 public static Builder newBuilder(Activation from) {
278 return newBuilder(from, false);
279 }
280
281
282
283
284
285
286
287
288 @Nonnull
289 public static Builder newBuilder(Activation from, boolean forceCopy) {
290 return new Builder(from, forceCopy);
291 }
292
293
294
295
296
297
298 @NotThreadSafe
299 public static class Builder
300 {
301 Activation base;
302 Boolean activeByDefault;
303 String jdk;
304 ActivationOS os;
305 ActivationProperty property;
306 ActivationFile file;
307 String packaging;
308 Map<Object, InputLocation> locations;
309
310 Builder(boolean withDefaults) {
311 if (withDefaults) {
312 this.activeByDefault = false;
313 }
314 }
315
316 Builder(Activation base, boolean forceCopy) {
317 if (forceCopy) {
318 this.activeByDefault = base.activeByDefault;
319 this.jdk = base.jdk;
320 this.os = base.os;
321 this.property = base.property;
322 this.file = base.file;
323 this.packaging = base.packaging;
324 this.locations = base.locations;
325 } else {
326 this.base = base;
327 }
328 }
329
330 @Nonnull
331 public Builder activeByDefault(boolean activeByDefault) {
332 this.activeByDefault = activeByDefault;
333 return this;
334 }
335
336 @Nonnull
337 public Builder jdk(String jdk) {
338 this.jdk = jdk;
339 return this;
340 }
341
342 @Nonnull
343 public Builder os(ActivationOS os) {
344 this.os = os;
345 return this;
346 }
347
348 @Nonnull
349 public Builder property(ActivationProperty property) {
350 this.property = property;
351 return this;
352 }
353
354 @Nonnull
355 public Builder file(ActivationFile file) {
356 this.file = file;
357 return this;
358 }
359
360 @Nonnull
361 public Builder packaging(String packaging) {
362 this.packaging = packaging;
363 return this;
364 }
365
366
367 @Nonnull
368 public Builder location(Object key, InputLocation location) {
369 if (location != null) {
370 if (!(this.locations instanceof HashMap)) {
371 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
372 }
373 this.locations.put(key, location);
374 }
375 return this;
376 }
377
378 @Nonnull
379 public Activation build() {
380 if (base != null
381 && (activeByDefault == null || activeByDefault == base.activeByDefault)
382 && (jdk == null || jdk == base.jdk)
383 && (os == null || os == base.os)
384 && (property == null || property == base.property)
385 && (file == null || file == base.file)
386 && (packaging == null || packaging == base.packaging)
387 ) {
388 return base;
389 }
390 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
391 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
392 Map<Object, InputLocation> locations = new HashMap<>();
393 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
394 locations.put("activeByDefault", newlocs.containsKey("activeByDefault") ? newlocs.get("activeByDefault") : oldlocs.get("activeByDefault"));
395 locations.put("jdk", newlocs.containsKey("jdk") ? newlocs.get("jdk") : oldlocs.get("jdk"));
396 locations.put("os", newlocs.containsKey("os") ? newlocs.get("os") : oldlocs.get("os"));
397 locations.put("property", newlocs.containsKey("property") ? newlocs.get("property") : oldlocs.get("property"));
398 locations.put("file", newlocs.containsKey("file") ? newlocs.get("file") : oldlocs.get("file"));
399 locations.put("packaging", newlocs.containsKey("packaging") ? newlocs.get("packaging") : oldlocs.get("packaging"));
400 return new Activation(
401 activeByDefault != null ? activeByDefault : (base != null ? base.activeByDefault : false),
402 jdk != null ? jdk : (base != null ? base.jdk : null),
403 os != null ? os : (base != null ? base.os : null),
404 property != null ? property : (base != null ? base.property : null),
405 file != null ? file : (base != null ? base.file : null),
406 packaging != null ? packaging : (base != null ? base.packaging : null),
407 locations
408 );
409 }
410 }
411
412 }