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