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 the file specification used to activate the profile. The {@code missing} value
21   * is the location of a file that needs to exist, and if it doesn't, the profile will be
22   * activated. On the other hand, {@code exists} will test for the existence of the file and if it is
23   * there, the profile will be activated.
24   * <p>Variable interpolation for these file specifications is limited to {@code ${project.basedir}},
25   * system properties and user properties.</p>
26   */
27  @Experimental
28  @Generated @ThreadSafe @Immutable
29  public class ActivationFile
30      implements Serializable, InputLocationTracker
31  {
32      /**
33       * The name of the file that must be missing to activate the profile. Please note, that missing and exists
34       * fields cannot be used together. Only one of them should be used at any one time.
35       */
36      final String missing;
37      /**
38       * The name of the file that must exist to activate the profile. Please note, that missing and exists
39       * fields cannot be used together. Only one of them should be used at any one time.
40       */
41      final String exists;
42      /** Locations (this potentially hides the same name field from the super class) */
43      final Map<Object, InputLocation> locations;
44      /** Location tracking */
45      final InputLocation importedFrom;
46  
47      /**
48        * Constructor for this class, to be called from its subclasses and {@link Builder}.
49        * @see Builder#build()
50        */
51      protected ActivationFile(Builder builder) {
52          this.missing = builder.missing != null ? builder.missing : (builder.base != null ? builder.base.missing : null);
53          this.exists = builder.exists != null ? builder.exists : (builder.base != null ? builder.base.exists : null);
54          Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
55          Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
56          Map<Object, InputLocation> mutableLocations = new HashMap<>();
57          this.importedFrom = builder.importedFrom;
58          mutableLocations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
59          mutableLocations.put("missing", newlocs.containsKey("missing") ? newlocs.get("missing") : oldlocs.get("missing"));
60          mutableLocations.put("exists", newlocs.containsKey("exists") ? newlocs.get("exists") : oldlocs.get("exists"));
61          this.locations = Collections.unmodifiableMap(mutableLocations);
62      }
63  
64      /**
65       * The name of the file that must be missing to activate the profile. Please note, that missing and exists
66       * fields cannot be used together. Only one of them should be used at any one time.
67       *
68       * @return a {@code String}
69       */
70      public String getMissing() {
71          return this.missing;
72      }
73  
74      /**
75       * The name of the file that must exist to activate the profile. Please note, that missing and exists
76       * fields cannot be used together. Only one of them should be used at any one time.
77       *
78       * @return a {@code String}
79       */
80      public String getExists() {
81          return this.exists;
82      }
83  
84      /**
85       * Gets the location of the specified field in the input source.
86       */
87      public InputLocation getLocation(Object key) {
88          return locations != null ? locations.get(key) : null;
89      }
90  
91      /**
92      * Gets the keys of the locations of the input source.
93      */
94      public Set<Object> getLocationKeys() {
95          return locations != null ? locations.keySet() : null;
96      }
97  
98      /**
99       * Gets the input location that caused this model to be read.
100      */
101     public InputLocation getImportedFrom()
102     {
103         return importedFrom;
104     }
105 
106     /**
107      * Creates a new builder with this object as the basis.
108      *
109      * @return a {@code Builder}
110      */
111     @Nonnull
112     public Builder with() {
113         return newBuilder(this);
114     }
115     /**
116      * Creates a new {@code ActivationFile} instance using the specified missing.
117      *
118      * @param missing the new {@code String} to use
119      * @return a {@code ActivationFile} with the specified missing
120      */
121     @Nonnull
122     public ActivationFile withMissing(String missing) {
123         return newBuilder(this, true).missing(missing).build();
124     }
125     /**
126      * Creates a new {@code ActivationFile} instance using the specified exists.
127      *
128      * @param exists the new {@code String} to use
129      * @return a {@code ActivationFile} with the specified exists
130      */
131     @Nonnull
132     public ActivationFile withExists(String exists) {
133         return newBuilder(this, true).exists(exists).build();
134     }
135 
136     /**
137      * Creates a new {@code ActivationFile} instance.
138      * Equivalent to {@code newInstance(true)}.
139      * @see #newInstance(boolean)
140      *
141      * @return a new {@code ActivationFile}
142      */
143     @Nonnull
144     public static ActivationFile newInstance() {
145         return newInstance(true);
146     }
147 
148     /**
149      * Creates a new {@code ActivationFile} instance using default values or not.
150      * Equivalent to {@code newBuilder(withDefaults).build()}.
151      *
152      * @param withDefaults the boolean indicating whether default values should be used
153      * @return a new {@code ActivationFile}
154      */
155     @Nonnull
156     public static ActivationFile newInstance(boolean withDefaults) {
157         return newBuilder(withDefaults).build();
158     }
159 
160     /**
161      * Creates a new {@code ActivationFile} builder instance.
162      * Equivalent to {@code newBuilder(true)}.
163      * @see #newBuilder(boolean)
164      *
165      * @return a new {@code Builder}
166      */
167     @Nonnull
168     public static Builder newBuilder() {
169         return newBuilder(true);
170     }
171 
172     /**
173      * Creates a new {@code ActivationFile} builder instance using default values or not.
174      *
175      * @param withDefaults the boolean indicating whether default values should be used
176      * @return a new {@code Builder}
177      */
178     @Nonnull
179     public static Builder newBuilder(boolean withDefaults) {
180         return new Builder(withDefaults);
181     }
182 
183     /**
184      * Creates a new {@code ActivationFile} builder instance using the specified object as a basis.
185      * Equivalent to {@code newBuilder(from, false)}.
186      *
187      * @param from the {@code ActivationFile} instance to use as a basis
188      * @return a new {@code Builder}
189      */
190     @Nonnull
191     public static Builder newBuilder(ActivationFile from) {
192         return newBuilder(from, false);
193     }
194 
195     /**
196      * Creates a new {@code ActivationFile} builder instance using the specified object as a basis.
197      *
198      * @param from the {@code ActivationFile} instance to use as a basis
199      * @param forceCopy the boolean indicating if a copy should be forced
200      * @return a new {@code Builder}
201      */
202     @Nonnull
203     public static Builder newBuilder(ActivationFile from, boolean forceCopy) {
204         return new Builder(from, forceCopy);
205     }
206 
207     /**
208      * Builder class used to create ActivationFile instances.
209      * @see #with()
210      * @see #newBuilder()
211      */
212     @NotThreadSafe
213     public static class Builder
214     {
215         ActivationFile base;
216         String missing;
217         String exists;
218         Map<Object, InputLocation> locations;
219         InputLocation importedFrom;
220 
221         protected Builder(boolean withDefaults) {
222             if (withDefaults) {
223             }
224         }
225 
226         protected Builder(ActivationFile base, boolean forceCopy) {
227             if (forceCopy) {
228                 this.missing = base.missing;
229                 this.exists = base.exists;
230                 this.locations = base.locations;
231                 this.importedFrom = base.importedFrom;
232             } else {
233                 this.base = base;
234             }
235         }
236 
237         @Nonnull
238         public Builder missing(String missing) {
239             this.missing = missing;
240             return this;
241         }
242 
243         @Nonnull
244         public Builder exists(String exists) {
245             this.exists = exists;
246             return this;
247         }
248 
249 
250         @Nonnull
251         public Builder location(Object key, InputLocation location) {
252             if (location != null) {
253                 if (!(this.locations instanceof HashMap)) {
254                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
255                 }
256                 this.locations.put(key, location);
257             }
258             return this;
259         }
260 
261         @Nonnull
262         public Builder importedFrom(InputLocation importedFrom) {
263             this.importedFrom = importedFrom;
264             return this;
265         }
266 
267         @Nonnull
268         public ActivationFile build() {
269             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
270             if (base != null
271                     && (missing == null || missing == base.missing)
272                     && (exists == null || exists == base.exists)
273             ) {
274                 return base;
275             }
276             return new ActivationFile(this);
277         }
278     }
279 
280 }