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