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