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