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