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