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