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