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   * This is an activator which will detect an operating system's attributes in order
21   * to activate its profile.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class ActivationOS
26      implements Serializable, InputLocationTracker
27  {
28      /**
29       * The name of the operating system to be used to activate the profile. This must be an exact match
30       * of the {@code ${os.name}} Java property, such as {@code Windows XP}.
31       */
32      final String name;
33      /**
34       * The general family of the OS to be used to activate the profile, such as
35       * {@code windows} or {@code unix}.
36       */
37      final String family;
38      /**
39       * The architecture of the operating system to be used to activate the
40       * profile.
41       */
42      final String arch;
43      /**
44       * The version of the operating system to be used to activate the
45       * profile.
46       */
47      final String version;
48      /** Locations (this potentially hides the same name field from the super class) */
49      final Map<Object, InputLocation> locations;
50      /** Location tracking */
51      final InputLocation importedFrom;
52  
53      /**
54        * Constructor for this class, to be called from its subclasses and {@link Builder}.
55        * @see Builder#build()
56        */
57      protected ActivationOS(Builder builder) {
58          this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
59          this.family = builder.family != null ? builder.family : (builder.base != null ? builder.base.family : null);
60          this.arch = builder.arch != null ? builder.arch : (builder.base != null ? builder.base.arch : null);
61          this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
62          Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
63          Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
64          Map<Object, InputLocation> mutableLocations = new HashMap<>();
65          this.importedFrom = builder.importedFrom;
66          mutableLocations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
67          mutableLocations.put("name", newlocs.containsKey("name") ? newlocs.get("name") : oldlocs.get("name"));
68          mutableLocations.put("family", newlocs.containsKey("family") ? newlocs.get("family") : oldlocs.get("family"));
69          mutableLocations.put("arch", newlocs.containsKey("arch") ? newlocs.get("arch") : oldlocs.get("arch"));
70          mutableLocations.put("version", newlocs.containsKey("version") ? newlocs.get("version") : oldlocs.get("version"));
71          this.locations = Collections.unmodifiableMap(mutableLocations);
72      }
73  
74      /**
75       * The name of the operating system to be used to activate the profile. This must be an exact match
76       * of the {@code ${os.name}} Java property, such as {@code Windows XP}.
77       *
78       * @return a {@code String}
79       */
80      public String getName() {
81          return this.name;
82      }
83  
84      /**
85       * The general family of the OS to be used to activate the profile, such as
86       * {@code windows} or {@code unix}.
87       *
88       * @return a {@code String}
89       */
90      public String getFamily() {
91          return this.family;
92      }
93  
94      /**
95       * The architecture of the operating system to be used to activate the
96       * profile.
97       *
98       * @return a {@code String}
99       */
100     public String getArch() {
101         return this.arch;
102     }
103 
104     /**
105      * The version of the operating system to be used to activate the
106      * profile.
107      *
108      * @return a {@code String}
109      */
110     public String getVersion() {
111         return this.version;
112     }
113 
114     /**
115      * Gets the location of the specified field in the input source.
116      */
117     public InputLocation getLocation(Object key) {
118         return locations != null ? locations.get(key) : null;
119     }
120 
121     /**
122     * Gets the keys of the locations of the input source.
123     */
124     public Set<Object> getLocationKeys() {
125         return locations != null ? locations.keySet() : null;
126     }
127 
128     /**
129      * Gets the input location that caused this model to be read.
130      */
131     public InputLocation getImportedFrom()
132     {
133         return importedFrom;
134     }
135 
136     /**
137      * Creates a new builder with this object as the basis.
138      *
139      * @return a {@code Builder}
140      */
141     @Nonnull
142     public Builder with() {
143         return newBuilder(this);
144     }
145     /**
146      * Creates a new {@code ActivationOS} instance using the specified name.
147      *
148      * @param name the new {@code String} to use
149      * @return a {@code ActivationOS} with the specified name
150      */
151     @Nonnull
152     public ActivationOS withName(String name) {
153         return newBuilder(this, true).name(name).build();
154     }
155     /**
156      * Creates a new {@code ActivationOS} instance using the specified family.
157      *
158      * @param family the new {@code String} to use
159      * @return a {@code ActivationOS} with the specified family
160      */
161     @Nonnull
162     public ActivationOS withFamily(String family) {
163         return newBuilder(this, true).family(family).build();
164     }
165     /**
166      * Creates a new {@code ActivationOS} instance using the specified arch.
167      *
168      * @param arch the new {@code String} to use
169      * @return a {@code ActivationOS} with the specified arch
170      */
171     @Nonnull
172     public ActivationOS withArch(String arch) {
173         return newBuilder(this, true).arch(arch).build();
174     }
175     /**
176      * Creates a new {@code ActivationOS} instance using the specified version.
177      *
178      * @param version the new {@code String} to use
179      * @return a {@code ActivationOS} with the specified version
180      */
181     @Nonnull
182     public ActivationOS withVersion(String version) {
183         return newBuilder(this, true).version(version).build();
184     }
185 
186     /**
187      * Creates a new {@code ActivationOS} instance.
188      * Equivalent to {@code newInstance(true)}.
189      * @see #newInstance(boolean)
190      *
191      * @return a new {@code ActivationOS}
192      */
193     @Nonnull
194     public static ActivationOS newInstance() {
195         return newInstance(true);
196     }
197 
198     /**
199      * Creates a new {@code ActivationOS} instance using default values or not.
200      * Equivalent to {@code newBuilder(withDefaults).build()}.
201      *
202      * @param withDefaults the boolean indicating whether default values should be used
203      * @return a new {@code ActivationOS}
204      */
205     @Nonnull
206     public static ActivationOS newInstance(boolean withDefaults) {
207         return newBuilder(withDefaults).build();
208     }
209 
210     /**
211      * Creates a new {@code ActivationOS} builder instance.
212      * Equivalent to {@code newBuilder(true)}.
213      * @see #newBuilder(boolean)
214      *
215      * @return a new {@code Builder}
216      */
217     @Nonnull
218     public static Builder newBuilder() {
219         return newBuilder(true);
220     }
221 
222     /**
223      * Creates a new {@code ActivationOS} builder instance using default values or not.
224      *
225      * @param withDefaults the boolean indicating whether default values should be used
226      * @return a new {@code Builder}
227      */
228     @Nonnull
229     public static Builder newBuilder(boolean withDefaults) {
230         return new Builder(withDefaults);
231     }
232 
233     /**
234      * Creates a new {@code ActivationOS} builder instance using the specified object as a basis.
235      * Equivalent to {@code newBuilder(from, false)}.
236      *
237      * @param from the {@code ActivationOS} instance to use as a basis
238      * @return a new {@code Builder}
239      */
240     @Nonnull
241     public static Builder newBuilder(ActivationOS from) {
242         return newBuilder(from, false);
243     }
244 
245     /**
246      * Creates a new {@code ActivationOS} builder instance using the specified object as a basis.
247      *
248      * @param from the {@code ActivationOS} instance to use as a basis
249      * @param forceCopy the boolean indicating if a copy should be forced
250      * @return a new {@code Builder}
251      */
252     @Nonnull
253     public static Builder newBuilder(ActivationOS from, boolean forceCopy) {
254         return new Builder(from, forceCopy);
255     }
256 
257     /**
258      * Builder class used to create ActivationOS instances.
259      * @see #with()
260      * @see #newBuilder()
261      */
262     @NotThreadSafe
263     public static class Builder
264     {
265         ActivationOS base;
266         String name;
267         String family;
268         String arch;
269         String version;
270         Map<Object, InputLocation> locations;
271         InputLocation importedFrom;
272 
273         protected Builder(boolean withDefaults) {
274             if (withDefaults) {
275             }
276         }
277 
278         protected Builder(ActivationOS base, boolean forceCopy) {
279             if (forceCopy) {
280                 this.name = base.name;
281                 this.family = base.family;
282                 this.arch = base.arch;
283                 this.version = base.version;
284                 this.locations = base.locations;
285                 this.importedFrom = base.importedFrom;
286             } else {
287                 this.base = base;
288             }
289         }
290 
291         @Nonnull
292         public Builder name(String name) {
293             this.name = name;
294             return this;
295         }
296 
297         @Nonnull
298         public Builder family(String family) {
299             this.family = family;
300             return this;
301         }
302 
303         @Nonnull
304         public Builder arch(String arch) {
305             this.arch = arch;
306             return this;
307         }
308 
309         @Nonnull
310         public Builder version(String version) {
311             this.version = version;
312             return this;
313         }
314 
315 
316         @Nonnull
317         public Builder location(Object key, InputLocation location) {
318             if (location != null) {
319                 if (!(this.locations instanceof HashMap)) {
320                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
321                 }
322                 this.locations.put(key, location);
323             }
324             return this;
325         }
326 
327         @Nonnull
328         public Builder importedFrom(InputLocation importedFrom) {
329             this.importedFrom = importedFrom;
330             return this;
331         }
332 
333         @Nonnull
334         public ActivationOS build() {
335             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
336             if (base != null
337                     && (name == null || name == base.name)
338                     && (family == null || family == base.family)
339                     && (arch == null || arch == base.arch)
340                     && (version == null || version == base.version)
341             ) {
342                 return base;
343             }
344             return new ActivationOS(this);
345         }
346     }
347 
348 }