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