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