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 java.util.Set;
12  import org.apache.maven.api.annotations.Experimental;
13  import org.apache.maven.api.annotations.Generated;
14  import org.apache.maven.api.annotations.Immutable;
15  import org.apache.maven.api.annotations.Nonnull;
16  import org.apache.maven.api.annotations.NotThreadSafe;
17  import org.apache.maven.api.annotations.ThreadSafe;
18  
19  /**
20   * The conditions within the build runtime environment which will trigger the
21   * automatic inclusion of the build profile. Multiple conditions can be defined, which must
22   * be all satisfied to activate the profile.
23   */
24  @Experimental
25  @Generated @ThreadSafe @Immutable
26  public class Activation
27      implements Serializable, InputLocationTracker
28  {
29      /**
30       * If set to true, this profile will be active unless another profile in this
31       * pom is activated using the command line -P option or by one of that profile's
32       * activators.
33       */
34      final boolean activeByDefault;
35      /**
36       * Specifies that this profile will be activated when a matching JDK is detected.
37       * For example, {@code 1.4} only activates on JDKs versioned 1.4,
38       * while {@code !1.4} matches any JDK that is not version 1.4. Ranges are supported too:
39       * {@code [1.5,)} activates when the JDK is 1.5 minimum.
40       */
41      final String jdk;
42      /**
43       * Specifies that this profile will be activated when matching operating system
44       * attributes are detected.
45       */
46      final ActivationOS os;
47      /**
48       * Specifies that this profile will be activated when this property is
49       * specified.
50       */
51      final ActivationProperty property;
52      /**
53       * Specifies that this profile will be activated based on existence of a file.
54       */
55      final ActivationFile file;
56      /**
57       * Specifies that this profile will be activated based on the project's packaging.
58       */
59      final String packaging;
60      /** Locations (this potentially hides the same name field from the super class) */
61      final Map<Object, InputLocation> locations;
62      /** Location tracking */
63      final InputLocation importedFrom;
64  
65      /**
66        * Constructor for this class, to be called from its subclasses and {@link Builder}.
67        * @see Builder#build()
68        */
69      protected Activation(Builder builder) {
70          this.activeByDefault = builder.activeByDefault != null ? builder.activeByDefault : (builder.base != null ? builder.base.activeByDefault : false);
71          this.jdk = builder.jdk != null ? builder.jdk : (builder.base != null ? builder.base.jdk : null);
72          this.os = builder.os != null ? builder.os : (builder.base != null ? builder.base.os : null);
73          this.property = builder.property != null ? builder.property : (builder.base != null ? builder.base.property : null);
74          this.file = builder.file != null ? builder.file : (builder.base != null ? builder.base.file : null);
75          this.packaging = builder.packaging != null ? builder.packaging : (builder.base != null ? builder.base.packaging : null);
76          Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
77          Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
78          Map<Object, InputLocation> mutableLocations = new HashMap<>();
79          this.importedFrom = builder.importedFrom;
80          mutableLocations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
81          mutableLocations.put("activeByDefault", newlocs.containsKey("activeByDefault") ? newlocs.get("activeByDefault") : oldlocs.get("activeByDefault"));
82          mutableLocations.put("jdk", newlocs.containsKey("jdk") ? newlocs.get("jdk") : oldlocs.get("jdk"));
83          mutableLocations.put("os", newlocs.containsKey("os") ? newlocs.get("os") : oldlocs.get("os"));
84          mutableLocations.put("property", newlocs.containsKey("property") ? newlocs.get("property") : oldlocs.get("property"));
85          mutableLocations.put("file", newlocs.containsKey("file") ? newlocs.get("file") : oldlocs.get("file"));
86          mutableLocations.put("packaging", newlocs.containsKey("packaging") ? newlocs.get("packaging") : oldlocs.get("packaging"));
87          this.locations = Collections.unmodifiableMap(mutableLocations);
88      }
89  
90      /**
91       * If set to true, this profile will be active unless another profile in this
92       * pom is activated using the command line -P option or by one of that profile's
93       * activators.
94       *
95       * @return a {@code boolean}
96       */
97      public boolean isActiveByDefault() {
98          return this.activeByDefault;
99      }
100 
101     /**
102      * Specifies that this profile will be activated when a matching JDK is detected.
103      * For example, {@code 1.4} only activates on JDKs versioned 1.4,
104      * while {@code !1.4} matches any JDK that is not version 1.4. Ranges are supported too:
105      * {@code [1.5,)} activates when the JDK is 1.5 minimum.
106      *
107      * @return a {@code String}
108      */
109     public String getJdk() {
110         return this.jdk;
111     }
112 
113     /**
114      * Specifies that this profile will be activated when matching operating system
115      * attributes are detected.
116      *
117      * @return a {@code ActivationOS}
118      */
119     public ActivationOS getOs() {
120         return this.os;
121     }
122 
123     /**
124      * Specifies that this profile will be activated when this property is
125      * specified.
126      *
127      * @return a {@code ActivationProperty}
128      */
129     public ActivationProperty getProperty() {
130         return this.property;
131     }
132 
133     /**
134      * Specifies that this profile will be activated based on existence of a file.
135      *
136      * @return a {@code ActivationFile}
137      */
138     public ActivationFile getFile() {
139         return this.file;
140     }
141 
142     /**
143      * Specifies that this profile will be activated based on the project's packaging.
144      *
145      * @return a {@code String}
146      */
147     public String getPackaging() {
148         return this.packaging;
149     }
150 
151     /**
152      * Gets the location of the specified field in the input source.
153      */
154     public InputLocation getLocation(Object key) {
155         return locations != null ? locations.get(key) : null;
156     }
157 
158     /**
159     * Gets the keys of the locations of the input source.
160     */
161     public Set<Object> getLocationKeys() {
162         return locations != null ? locations.keySet() : null;
163     }
164 
165     /**
166      * Gets the input location that caused this model to be read.
167      */
168     public InputLocation getImportedFrom()
169     {
170         return importedFrom;
171     }
172 
173     /**
174      * Creates a new builder with this object as the basis.
175      *
176      * @return a {@code Builder}
177      */
178     @Nonnull
179     public Builder with() {
180         return newBuilder(this);
181     }
182     /**
183      * Creates a new {@code Activation} instance using the specified activeByDefault.
184      *
185      * @param activeByDefault the new {@code boolean} to use
186      * @return a {@code Activation} with the specified activeByDefault
187      */
188     @Nonnull
189     public Activation withActiveByDefault(boolean activeByDefault) {
190         return newBuilder(this, true).activeByDefault(activeByDefault).build();
191     }
192     /**
193      * Creates a new {@code Activation} instance using the specified jdk.
194      *
195      * @param jdk the new {@code String} to use
196      * @return a {@code Activation} with the specified jdk
197      */
198     @Nonnull
199     public Activation withJdk(String jdk) {
200         return newBuilder(this, true).jdk(jdk).build();
201     }
202     /**
203      * Creates a new {@code Activation} instance using the specified os.
204      *
205      * @param os the new {@code ActivationOS} to use
206      * @return a {@code Activation} with the specified os
207      */
208     @Nonnull
209     public Activation withOs(ActivationOS os) {
210         return newBuilder(this, true).os(os).build();
211     }
212     /**
213      * Creates a new {@code Activation} instance using the specified property.
214      *
215      * @param property the new {@code ActivationProperty} to use
216      * @return a {@code Activation} with the specified property
217      */
218     @Nonnull
219     public Activation withProperty(ActivationProperty property) {
220         return newBuilder(this, true).property(property).build();
221     }
222     /**
223      * Creates a new {@code Activation} instance using the specified file.
224      *
225      * @param file the new {@code ActivationFile} to use
226      * @return a {@code Activation} with the specified file
227      */
228     @Nonnull
229     public Activation withFile(ActivationFile file) {
230         return newBuilder(this, true).file(file).build();
231     }
232     /**
233      * Creates a new {@code Activation} instance using the specified packaging.
234      *
235      * @param packaging the new {@code String} to use
236      * @return a {@code Activation} with the specified packaging
237      */
238     @Nonnull
239     public Activation withPackaging(String packaging) {
240         return newBuilder(this, true).packaging(packaging).build();
241     }
242 
243     /**
244      * Creates a new {@code Activation} instance.
245      * Equivalent to {@code newInstance(true)}.
246      * @see #newInstance(boolean)
247      *
248      * @return a new {@code Activation}
249      */
250     @Nonnull
251     public static Activation newInstance() {
252         return newInstance(true);
253     }
254 
255     /**
256      * Creates a new {@code Activation} instance using default values or not.
257      * Equivalent to {@code newBuilder(withDefaults).build()}.
258      *
259      * @param withDefaults the boolean indicating whether default values should be used
260      * @return a new {@code Activation}
261      */
262     @Nonnull
263     public static Activation newInstance(boolean withDefaults) {
264         return newBuilder(withDefaults).build();
265     }
266 
267     /**
268      * Creates a new {@code Activation} builder instance.
269      * Equivalent to {@code newBuilder(true)}.
270      * @see #newBuilder(boolean)
271      *
272      * @return a new {@code Builder}
273      */
274     @Nonnull
275     public static Builder newBuilder() {
276         return newBuilder(true);
277     }
278 
279     /**
280      * Creates a new {@code Activation} builder instance using default values or not.
281      *
282      * @param withDefaults the boolean indicating whether default values should be used
283      * @return a new {@code Builder}
284      */
285     @Nonnull
286     public static Builder newBuilder(boolean withDefaults) {
287         return new Builder(withDefaults);
288     }
289 
290     /**
291      * Creates a new {@code Activation} builder instance using the specified object as a basis.
292      * Equivalent to {@code newBuilder(from, false)}.
293      *
294      * @param from the {@code Activation} instance to use as a basis
295      * @return a new {@code Builder}
296      */
297     @Nonnull
298     public static Builder newBuilder(Activation from) {
299         return newBuilder(from, false);
300     }
301 
302     /**
303      * Creates a new {@code Activation} builder instance using the specified object as a basis.
304      *
305      * @param from the {@code Activation} instance to use as a basis
306      * @param forceCopy the boolean indicating if a copy should be forced
307      * @return a new {@code Builder}
308      */
309     @Nonnull
310     public static Builder newBuilder(Activation from, boolean forceCopy) {
311         return new Builder(from, forceCopy);
312     }
313 
314     /**
315      * Builder class used to create Activation instances.
316      * @see #with()
317      * @see #newBuilder()
318      */
319     @NotThreadSafe
320     public static class Builder
321     {
322         Activation base;
323         Boolean activeByDefault;
324         String jdk;
325         ActivationOS os;
326         ActivationProperty property;
327         ActivationFile file;
328         String packaging;
329         Map<Object, InputLocation> locations;
330         InputLocation importedFrom;
331 
332         protected Builder(boolean withDefaults) {
333             if (withDefaults) {
334                 this.activeByDefault = false;
335             }
336         }
337 
338         protected Builder(Activation base, boolean forceCopy) {
339             if (forceCopy) {
340                 this.activeByDefault = base.activeByDefault;
341                 this.jdk = base.jdk;
342                 this.os = base.os;
343                 this.property = base.property;
344                 this.file = base.file;
345                 this.packaging = base.packaging;
346                 this.locations = base.locations;
347                 this.importedFrom = base.importedFrom;
348             } else {
349                 this.base = base;
350             }
351         }
352 
353         @Nonnull
354         public Builder activeByDefault(boolean activeByDefault) {
355             this.activeByDefault = activeByDefault;
356             return this;
357         }
358 
359         @Nonnull
360         public Builder jdk(String jdk) {
361             this.jdk = jdk;
362             return this;
363         }
364 
365         @Nonnull
366         public Builder os(ActivationOS os) {
367             this.os = os;
368             return this;
369         }
370 
371         @Nonnull
372         public Builder property(ActivationProperty property) {
373             this.property = property;
374             return this;
375         }
376 
377         @Nonnull
378         public Builder file(ActivationFile file) {
379             this.file = file;
380             return this;
381         }
382 
383         @Nonnull
384         public Builder packaging(String packaging) {
385             this.packaging = packaging;
386             return this;
387         }
388 
389 
390         @Nonnull
391         public Builder location(Object key, InputLocation location) {
392             if (location != null) {
393                 if (!(this.locations instanceof HashMap)) {
394                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
395                 }
396                 this.locations.put(key, location);
397             }
398             return this;
399         }
400 
401         @Nonnull
402         public Builder importedFrom(InputLocation importedFrom) {
403             this.importedFrom = importedFrom;
404             return this;
405         }
406 
407         @Nonnull
408         public Activation build() {
409             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
410             if (base != null
411                     && (activeByDefault == null || activeByDefault == base.activeByDefault)
412                     && (jdk == null || jdk == base.jdk)
413                     && (os == null || os == base.os)
414                     && (property == null || property == base.property)
415                     && (file == null || file == base.file)
416                     && (packaging == null || packaging == base.packaging)
417             ) {
418                 return base;
419             }
420             return new Activation(this);
421         }
422     }
423 
424 }