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