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