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