View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //   Generated by Maven, any modifications will be overwritten.
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   * The conditions within the build runtime environment which will trigger the
19   * automatic inclusion of the build profile. Multiple conditions can be defined, which must
20   * be all satisfied to activate the profile.
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class Activation
25      implements Serializable, InputLocationTracker
26  {
27      /**
28       * If set to true, this profile will be active unless another profile in this
29       * pom is activated using the command line -P option or by one of that profile's
30       * activators.
31       */
32      final boolean activeByDefault;
33      /**
34       * Specifies that this profile will be activated when a matching JDK is detected.
35       * For example, {@code 1.4} only activates on JDKs versioned 1.4,
36       * while {@code !1.4} matches any JDK that is not version 1.4. Ranges are supported too:
37       * {@code [1.5,)} activates when the JDK is 1.5 minimum.
38       */
39      final String jdk;
40      /**
41       * Specifies that this profile will be activated when matching operating system
42       * attributes are detected.
43       */
44      final ActivationOS os;
45      /**
46       * Specifies that this profile will be activated when this property is
47       * specified.
48       */
49      final ActivationProperty property;
50      /**
51       * Specifies that this profile will be activated based on existence of a file.
52       */
53      final ActivationFile file;
54      /** Location of the xml element for this object. */
55      final InputLocation location;
56      /** Location of the xml element for the field activeByDefault. */
57      final InputLocation activeByDefaultLocation;
58      /** Location of the xml element for the field jdk. */
59      final InputLocation jdkLocation;
60      /** Location of the xml element for the field os. */
61      final InputLocation osLocation;
62      /** Location of the xml element for the field property. */
63      final InputLocation propertyLocation;
64      /** Location of the xml element for the field file. */
65      final InputLocation fileLocation;
66      /** Other locations */
67      final Map<Object, InputLocation> locations;
68  
69      /**
70        * Constructor for this class, package protected.
71        * @see Builder#build()
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      * If set to true, this profile will be active unless another profile in this
104      * pom is activated using the command line -P option or by one of that profile's
105      * activators.
106      *
107      * @return a {@code boolean}
108      */
109     public boolean isActiveByDefault()
110     {
111         return this.activeByDefault;
112     }
113 
114     /**
115      * Specifies that this profile will be activated when a matching JDK is detected.
116      * For example, {@code 1.4} only activates on JDKs versioned 1.4,
117      * while {@code !1.4} matches any JDK that is not version 1.4. Ranges are supported too:
118      * {@code [1.5,)} activates when the JDK is 1.5 minimum.
119      *
120      * @return a {@code String}
121      */
122     public String getJdk()
123     {
124         return this.jdk;
125     }
126 
127     /**
128      * Specifies that this profile will be activated when matching operating system
129      * attributes are detected.
130      *
131      * @return a {@code ActivationOS}
132      */
133     public ActivationOS getOs()
134     {
135         return this.os;
136     }
137 
138     /**
139      * Specifies that this profile will be activated when this property is
140      * specified.
141      *
142      * @return a {@code ActivationProperty}
143      */
144     public ActivationProperty getProperty()
145     {
146         return this.property;
147     }
148 
149     /**
150      * Specifies that this profile will be activated based on existence of a file.
151      *
152      * @return a {@code ActivationFile}
153      */
154     public ActivationFile getFile()
155     {
156         return this.file;
157     }
158 
159     /**
160      * Gets the location of the specified field in the input source.
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      * Creates a new builder with this object as the basis.
187      *
188      * @return a {@code Builder}
189      */
190     @Nonnull
191     public Builder with()
192     {
193         return newBuilder( this );
194     }
195     /**
196      * Creates a new {@code Activation} instance using the specified activeByDefault.
197      *
198      * @param activeByDefault the new {@code boolean} to use
199      * @return a {@code Activation} with the specified activeByDefault
200      */
201     @Nonnull
202     public Activation withActiveByDefault( boolean activeByDefault )
203     {
204         return with().activeByDefault( activeByDefault ).build();
205     }
206     /**
207      * Creates a new {@code Activation} instance using the specified jdk.
208      *
209      * @param jdk the new {@code String} to use
210      * @return a {@code Activation} with the specified jdk
211      */
212     @Nonnull
213     public Activation withJdk( String jdk )
214     {
215         return with().jdk( jdk ).build();
216     }
217     /**
218      * Creates a new {@code Activation} instance using the specified os.
219      *
220      * @param os the new {@code ActivationOS} to use
221      * @return a {@code Activation} with the specified os
222      */
223     @Nonnull
224     public Activation withOs( ActivationOS os )
225     {
226         return with().os( os ).build();
227     }
228     /**
229      * Creates a new {@code Activation} instance using the specified property.
230      *
231      * @param property the new {@code ActivationProperty} to use
232      * @return a {@code Activation} with the specified property
233      */
234     @Nonnull
235     public Activation withProperty( ActivationProperty property )
236     {
237         return with().property( property ).build();
238     }
239     /**
240      * Creates a new {@code Activation} instance using the specified file.
241      *
242      * @param file the new {@code ActivationFile} to use
243      * @return a {@code Activation} with the specified file
244      */
245     @Nonnull
246     public Activation withFile( ActivationFile file )
247     {
248         return with().file( file ).build();
249     }
250 
251     /**
252      * Creates a new {@code Activation} instance.
253      * Equivalent to {@code newInstance( true )}.
254      * @see #newInstance(boolean)
255      *
256      * @return a new {@code Activation}
257      */
258     @Nonnull
259     public static Activation newInstance()
260     {
261         return newInstance( true );
262     }
263 
264     /**
265      * Creates a new {@code Activation} instance using default values or not.
266      * Equivalent to {@code newBuilder( withDefaults ).build()}.
267      *
268      * @param withDefaults the boolean indicating whether default values should be used
269      * @return a new {@code Activation}
270      */
271     @Nonnull
272     public static Activation newInstance( boolean withDefaults )
273     {
274         return newBuilder( withDefaults ).build();
275     }
276 
277     /**
278      * Creates a new {@code Activation} builder instance.
279      * Equivalent to {@code newBuilder( true )}.
280      * @see #newBuilder(boolean)
281      *
282      * @return a new {@code Builder}
283      */
284     @Nonnull
285     public static Builder newBuilder()
286     {
287         return newBuilder( true );
288     }
289 
290     /**
291      * Creates a new {@code Activation} builder instance using default values or not.
292      *
293      * @param withDefaults the boolean indicating whether default values should be used
294      * @return a new {@code Builder}
295      */
296     @Nonnull
297     public static Builder newBuilder( boolean withDefaults )
298     {
299         return new Builder( withDefaults );
300     }
301 
302     /**
303      * Creates a new {@code Activation} builder instance using the specified object as a basis.
304      * Equivalent to {@code newBuilder( from, false )}.
305      *
306      * @param from the {@code Activation} instance to use as a basis
307      * @return a new {@code Builder}
308      */
309     @Nonnull
310     public static Builder newBuilder( Activation from )
311     {
312         return newBuilder( from, false );
313     }
314 
315     /**
316      * Creates a new {@code Activation} builder instance using the specified object as a basis.
317      *
318      * @param from the {@code Activation} instance to use as a basis
319      * @param forceCopy the boolean indicating if a copy should be forced
320      * @return a new {@code Builder}
321      */
322     @Nonnull
323     public static Builder newBuilder( Activation from, boolean forceCopy )
324     {
325         return new Builder( from, forceCopy );
326     }
327 
328     /**
329      * Builder class used to create Activation instances.
330      * @see #with()
331      * @see #newBuilder()
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 }