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