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      /** Locations */
56      final Map<Object, InputLocation> locations;
57  
58      /**
59        * Constructor for this class, package protected.
60        * @see Builder#build()
61        */
62      Activation(
63          boolean activeByDefault,
64          String jdk,
65          ActivationOS os,
66          ActivationProperty property,
67          ActivationFile file,
68          Map<Object, InputLocation> locations
69      ) {
70          this.activeByDefault = activeByDefault;
71          this.jdk = jdk;
72          this.os = os;
73          this.property = property;
74          this.file = file;
75          this.locations = ImmutableCollections.copy(locations);
76      }
77  
78      /**
79       * If set to true, this profile will be active unless another profile in this
80       * pom is activated using the command line -P option or by one of that profile's
81       * activators.
82       *
83       * @return a {@code boolean}
84       */
85      public boolean isActiveByDefault() {
86          return this.activeByDefault;
87      }
88  
89      /**
90       * Specifies that this profile will be activated when a matching JDK is detected.
91       * For example, {@code 1.4} only activates on JDKs versioned 1.4,
92       * while {@code !1.4} matches any JDK that is not version 1.4. Ranges are supported too:
93       * {@code [1.5,)} activates when the JDK is 1.5 minimum.
94       *
95       * @return a {@code String}
96       */
97      public String getJdk() {
98          return this.jdk;
99      }
100 
101     /**
102      * Specifies that this profile will be activated when matching operating system
103      * attributes are detected.
104      *
105      * @return a {@code ActivationOS}
106      */
107     public ActivationOS getOs() {
108         return this.os;
109     }
110 
111     /**
112      * Specifies that this profile will be activated when this property is
113      * specified.
114      *
115      * @return a {@code ActivationProperty}
116      */
117     public ActivationProperty getProperty() {
118         return this.property;
119     }
120 
121     /**
122      * Specifies that this profile will be activated based on existence of a file.
123      *
124      * @return a {@code ActivationFile}
125      */
126     public ActivationFile getFile() {
127         return this.file;
128     }
129 
130     /**
131      * Gets the location of the specified field in the input source.
132      */
133     public InputLocation getLocation(Object key) {
134         return locations != null ? locations.get(key) : null;
135     }
136 
137     /**
138      * Creates a new builder with this object as the basis.
139      *
140      * @return a {@code Builder}
141      */
142     @Nonnull
143     public Builder with() {
144         return newBuilder(this);
145     }
146     /**
147      * Creates a new {@code Activation} instance using the specified activeByDefault.
148      *
149      * @param activeByDefault the new {@code boolean} to use
150      * @return a {@code Activation} with the specified activeByDefault
151      */
152     @Nonnull
153     public Activation withActiveByDefault(boolean activeByDefault) {
154         return newBuilder(this, true).activeByDefault(activeByDefault).build();
155     }
156     /**
157      * Creates a new {@code Activation} instance using the specified jdk.
158      *
159      * @param jdk the new {@code String} to use
160      * @return a {@code Activation} with the specified jdk
161      */
162     @Nonnull
163     public Activation withJdk(String jdk) {
164         return newBuilder(this, true).jdk(jdk).build();
165     }
166     /**
167      * Creates a new {@code Activation} instance using the specified os.
168      *
169      * @param os the new {@code ActivationOS} to use
170      * @return a {@code Activation} with the specified os
171      */
172     @Nonnull
173     public Activation withOs(ActivationOS os) {
174         return newBuilder(this, true).os(os).build();
175     }
176     /**
177      * Creates a new {@code Activation} instance using the specified property.
178      *
179      * @param property the new {@code ActivationProperty} to use
180      * @return a {@code Activation} with the specified property
181      */
182     @Nonnull
183     public Activation withProperty(ActivationProperty property) {
184         return newBuilder(this, true).property(property).build();
185     }
186     /**
187      * Creates a new {@code Activation} instance using the specified file.
188      *
189      * @param file the new {@code ActivationFile} to use
190      * @return a {@code Activation} with the specified file
191      */
192     @Nonnull
193     public Activation withFile(ActivationFile file) {
194         return newBuilder(this, true).file(file).build();
195     }
196 
197     /**
198      * Creates a new {@code Activation} instance.
199      * Equivalent to {@code newInstance(true)}.
200      * @see #newInstance(boolean)
201      *
202      * @return a new {@code Activation}
203      */
204     @Nonnull
205     public static Activation newInstance() {
206         return newInstance(true);
207     }
208 
209     /**
210      * Creates a new {@code Activation} instance using default values or not.
211      * Equivalent to {@code newBuilder(withDefaults).build()}.
212      *
213      * @param withDefaults the boolean indicating whether default values should be used
214      * @return a new {@code Activation}
215      */
216     @Nonnull
217     public static Activation newInstance(boolean withDefaults) {
218         return newBuilder(withDefaults).build();
219     }
220 
221     /**
222      * Creates a new {@code Activation} builder instance.
223      * Equivalent to {@code newBuilder(true)}.
224      * @see #newBuilder(boolean)
225      *
226      * @return a new {@code Builder}
227      */
228     @Nonnull
229     public static Builder newBuilder() {
230         return newBuilder(true);
231     }
232 
233     /**
234      * Creates a new {@code Activation} builder instance using default values or not.
235      *
236      * @param withDefaults the boolean indicating whether default values should be used
237      * @return a new {@code Builder}
238      */
239     @Nonnull
240     public static Builder newBuilder(boolean withDefaults) {
241         return new Builder(withDefaults);
242     }
243 
244     /**
245      * Creates a new {@code Activation} builder instance using the specified object as a basis.
246      * Equivalent to {@code newBuilder(from, false)}.
247      *
248      * @param from the {@code Activation} instance to use as a basis
249      * @return a new {@code Builder}
250      */
251     @Nonnull
252     public static Builder newBuilder(Activation from) {
253         return newBuilder(from, false);
254     }
255 
256     /**
257      * Creates a new {@code Activation} builder instance using the specified object as a basis.
258      *
259      * @param from the {@code Activation} instance to use as a basis
260      * @param forceCopy the boolean indicating if a copy should be forced
261      * @return a new {@code Builder}
262      */
263     @Nonnull
264     public static Builder newBuilder(Activation from, boolean forceCopy) {
265         return new Builder(from, forceCopy);
266     }
267 
268     /**
269      * Builder class used to create Activation instances.
270      * @see #with()
271      * @see #newBuilder()
272      */
273     @NotThreadSafe
274     public static class Builder
275     {
276         Activation base;
277         Boolean activeByDefault;
278         String jdk;
279         ActivationOS os;
280         ActivationProperty property;
281         ActivationFile file;
282         Map<Object, InputLocation> locations;
283 
284         Builder(boolean withDefaults) {
285             if (withDefaults) {
286                 this.activeByDefault = false;
287             }
288         }
289 
290         Builder(Activation base, boolean forceCopy) {
291             if (forceCopy) {
292                 this.activeByDefault = base.activeByDefault;
293                 this.jdk = base.jdk;
294                 this.os = base.os;
295                 this.property = base.property;
296                 this.file = base.file;
297                 this.locations = base.locations;
298             } else {
299                 this.base = base;
300             }
301         }
302 
303         @Nonnull
304         public Builder activeByDefault(boolean activeByDefault) {
305             this.activeByDefault = activeByDefault;
306             return this;
307         }
308 
309         @Nonnull
310         public Builder jdk(String jdk) {
311             this.jdk = jdk;
312             return this;
313         }
314 
315         @Nonnull
316         public Builder os(ActivationOS os) {
317             this.os = os;
318             return this;
319         }
320 
321         @Nonnull
322         public Builder property(ActivationProperty property) {
323             this.property = property;
324             return this;
325         }
326 
327         @Nonnull
328         public Builder file(ActivationFile file) {
329             this.file = file;
330             return this;
331         }
332 
333 
334         @Nonnull
335         public Builder location(Object key, InputLocation location) {
336             if (location != null) {
337                 if (!(this.locations instanceof HashMap)) {
338                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
339                 }
340                 this.locations.put(key, location);
341             }
342             return this;
343         }
344 
345         @Nonnull
346         public Activation build() {
347             if (base != null
348                     && (activeByDefault == null || activeByDefault == base.activeByDefault)
349                     && (jdk == null || jdk == base.jdk)
350                     && (os == null || os == base.os)
351                     && (property == null || property == base.property)
352                     && (file == null || file == base.file)
353             ) {
354                 return base;
355             }
356             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
357             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
358             Map<Object, InputLocation> locations = new HashMap<>();
359             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
360             locations.put("activeByDefault", newlocs.containsKey("activeByDefault") ? newlocs.get("activeByDefault") : oldlocs.get("activeByDefault"));
361             locations.put("jdk", newlocs.containsKey("jdk") ? newlocs.get("jdk") : oldlocs.get("jdk"));
362             locations.put("os", newlocs.containsKey("os") ? newlocs.get("os") : oldlocs.get("os"));
363             locations.put("property", newlocs.containsKey("property") ? newlocs.get("property") : oldlocs.get("property"));
364             locations.put("file", newlocs.containsKey("file") ? newlocs.get("file") : oldlocs.get("file"));
365             return new Activation(
366                 activeByDefault != null ? activeByDefault : (base != null ? base.activeByDefault : false),
367                 jdk != null ? jdk : (base != null ? base.jdk : null),
368                 os != null ? os : (base != null ? base.os : null),
369                 property != null ? property : (base != null ? base.property : null),
370                 file != null ? file : (base != null ? base.file : null),
371                 locations
372             );
373         }
374     }
375 
376 }