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.ArrayList;
9   import java.util.Collection;
10  import java.util.Collections;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.Set;
15  import org.apache.maven.api.annotations.Experimental;
16  import org.apache.maven.api.annotations.Generated;
17  import org.apache.maven.api.annotations.Immutable;
18  import org.apache.maven.api.annotations.Nonnull;
19  import org.apache.maven.api.annotations.NotThreadSafe;
20  import org.apache.maven.api.annotations.ThreadSafe;
21  
22  /**
23   * Modifications to the build process which is keyed on some sort of environmental parameter.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class Profile
28      extends IdentifiableBase
29      implements Serializable, InputLocationTracker
30  {
31      /**
32       * The conditional logic which will automatically trigger the inclusion of this profile.
33       */
34      final Activation activation;
35      /**
36       * Extended configuration specific to this profile goes here.
37       * Contents take the form of {@code <property.name>property.value</property.name>}
38       */
39      final Map<String, String> properties;
40      /**
41       * The lists of the remote repositories.
42       */
43      final List<Repository> repositories;
44      /**
45       * The lists of the remote repositories for discovering plugins.
46       */
47      final List<Repository> pluginRepositories;
48      /** Locations (this potentially hides the same name field from the super class) */
49      final Map<Object, InputLocation> locations;
50  
51      /**
52        * Constructor for this class, to be called from its subclasses and {@link Builder}.
53        * @see Builder#build()
54        */
55      protected Profile(Builder builder) {
56          super(builder);
57          this.activation = builder.activation != null ? builder.activation : (builder.base != null ? builder.base.activation : null);
58          this.properties = ImmutableCollections.copy(builder.properties != null ? builder.properties : (builder.base != null ? builder.base.properties : null));
59          this.repositories = ImmutableCollections.copy(builder.repositories != null ? builder.repositories : (builder.base != null ? builder.base.repositories : null));
60          this.pluginRepositories = ImmutableCollections.copy(builder.pluginRepositories != null ? builder.pluginRepositories : (builder.base != null ? builder.base.pluginRepositories : null));
61          Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
62          Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
63          Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
64          mutableLocations.put("activation", newlocs.containsKey("activation") ? newlocs.get("activation") : oldlocs.get("activation"));
65          mutableLocations.put("properties", newlocs.containsKey("properties") ? newlocs.get("properties") : oldlocs.get("properties"));
66          mutableLocations.put("repositories", newlocs.containsKey("repositories") ? newlocs.get("repositories") : oldlocs.get("repositories"));
67          mutableLocations.put("pluginRepositories", newlocs.containsKey("pluginRepositories") ? newlocs.get("pluginRepositories") : oldlocs.get("pluginRepositories"));
68          this.locations = Collections.unmodifiableMap(mutableLocations);
69      }
70  
71      /**
72       * The conditional logic which will automatically trigger the inclusion of this profile.
73       *
74       * @return a {@code Activation}
75       */
76      public Activation getActivation() {
77          return this.activation;
78      }
79  
80      /**
81       * Extended configuration specific to this profile goes here.
82       * Contents take the form of {@code <property.name>property.value</property.name>}
83       *
84       * @return a {@code Map<String, String>}
85       */
86      @Nonnull
87      public Map<String, String> getProperties() {
88          return this.properties;
89      }
90  
91      /**
92       * The lists of the remote repositories.
93       *
94       * @return a {@code List<Repository>}
95       */
96      @Nonnull
97      public List<Repository> getRepositories() {
98          return this.repositories;
99      }
100 
101     /**
102      * The lists of the remote repositories for discovering plugins.
103      *
104      * @return a {@code List<Repository>}
105      */
106     @Nonnull
107     public List<Repository> getPluginRepositories() {
108         return this.pluginRepositories;
109     }
110 
111     /**
112      * Gets the location of the specified field in the input source.
113      */
114     public InputLocation getLocation(Object key) {
115         return locations != null ? locations.get(key) : null;
116     }
117 
118     /**
119     * Gets the keys of the locations of the input source.
120     */
121     public Set<Object> getLocationKeys() {
122         return locations != null ? locations.keySet() : null;
123     }
124 
125     /**
126      * Creates a new builder with this object as the basis.
127      *
128      * @return a {@code Builder}
129      */
130     @Nonnull
131     public Builder with() {
132         return newBuilder(this);
133     }
134     /**
135      * Creates a new {@code Profile} instance using the specified id.
136      *
137      * @param id the new {@code String} to use
138      * @return a {@code Profile} with the specified id
139      */
140     @Nonnull
141     public Profile withId(String id) {
142         return newBuilder(this, true).id(id).build();
143     }
144     /**
145      * Creates a new {@code Profile} instance using the specified activation.
146      *
147      * @param activation the new {@code Activation} to use
148      * @return a {@code Profile} with the specified activation
149      */
150     @Nonnull
151     public Profile withActivation(Activation activation) {
152         return newBuilder(this, true).activation(activation).build();
153     }
154     /**
155      * Creates a new {@code Profile} instance using the specified properties.
156      *
157      * @param properties the new {@code Map<String, String>} to use
158      * @return a {@code Profile} with the specified properties
159      */
160     @Nonnull
161     public Profile withProperties(Map<String, String> properties) {
162         return newBuilder(this, true).properties(properties).build();
163     }
164     /**
165      * Creates a new {@code Profile} instance using the specified repositories.
166      *
167      * @param repositories the new {@code Collection<Repository>} to use
168      * @return a {@code Profile} with the specified repositories
169      */
170     @Nonnull
171     public Profile withRepositories(Collection<Repository> repositories) {
172         return newBuilder(this, true).repositories(repositories).build();
173     }
174     /**
175      * Creates a new {@code Profile} instance using the specified pluginRepositories.
176      *
177      * @param pluginRepositories the new {@code Collection<Repository>} to use
178      * @return a {@code Profile} with the specified pluginRepositories
179      */
180     @Nonnull
181     public Profile withPluginRepositories(Collection<Repository> pluginRepositories) {
182         return newBuilder(this, true).pluginRepositories(pluginRepositories).build();
183     }
184 
185     /**
186      * Creates a new {@code Profile} instance.
187      * Equivalent to {@code newInstance(true)}.
188      * @see #newInstance(boolean)
189      *
190      * @return a new {@code Profile}
191      */
192     @Nonnull
193     public static Profile newInstance() {
194         return newInstance(true);
195     }
196 
197     /**
198      * Creates a new {@code Profile} instance using default values or not.
199      * Equivalent to {@code newBuilder(withDefaults).build()}.
200      *
201      * @param withDefaults the boolean indicating whether default values should be used
202      * @return a new {@code Profile}
203      */
204     @Nonnull
205     public static Profile newInstance(boolean withDefaults) {
206         return newBuilder(withDefaults).build();
207     }
208 
209     /**
210      * Creates a new {@code Profile} builder instance.
211      * Equivalent to {@code newBuilder(true)}.
212      * @see #newBuilder(boolean)
213      *
214      * @return a new {@code Builder}
215      */
216     @Nonnull
217     public static Builder newBuilder() {
218         return newBuilder(true);
219     }
220 
221     /**
222      * Creates a new {@code Profile} builder instance using default values or not.
223      *
224      * @param withDefaults the boolean indicating whether default values should be used
225      * @return a new {@code Builder}
226      */
227     @Nonnull
228     public static Builder newBuilder(boolean withDefaults) {
229         return new Builder(withDefaults);
230     }
231 
232     /**
233      * Creates a new {@code Profile} builder instance using the specified object as a basis.
234      * Equivalent to {@code newBuilder(from, false)}.
235      *
236      * @param from the {@code Profile} instance to use as a basis
237      * @return a new {@code Builder}
238      */
239     @Nonnull
240     public static Builder newBuilder(Profile from) {
241         return newBuilder(from, false);
242     }
243 
244     /**
245      * Creates a new {@code Profile} builder instance using the specified object as a basis.
246      *
247      * @param from the {@code Profile} instance to use as a basis
248      * @param forceCopy the boolean indicating if a copy should be forced
249      * @return a new {@code Builder}
250      */
251     @Nonnull
252     public static Builder newBuilder(Profile from, boolean forceCopy) {
253         return new Builder(from, forceCopy);
254     }
255 
256     /**
257      * Builder class used to create Profile instances.
258      * @see #with()
259      * @see #newBuilder()
260      */
261     @NotThreadSafe
262     public static class Builder
263         extends IdentifiableBase.Builder
264     {
265         Profile base;
266         Activation activation;
267         Map<String, String> properties;
268         Collection<Repository> repositories;
269         Collection<Repository> pluginRepositories;
270 
271         protected Builder(boolean withDefaults) {
272             super(withDefaults);
273             if (withDefaults) {
274             }
275         }
276 
277         protected Builder(Profile base, boolean forceCopy) {
278             super(base, forceCopy);
279             if (forceCopy) {
280                 this.activation = base.activation;
281                 this.properties = base.properties;
282                 this.repositories = base.repositories;
283                 this.pluginRepositories = base.pluginRepositories;
284                 this.locations = base.locations;
285                 this.importedFrom = base.importedFrom;
286             } else {
287                 this.base = base;
288             }
289         }
290 
291         @Nonnull
292         public Builder id(String id) {
293             this.id = id;
294             return this;
295         }
296 
297         @Nonnull
298         public Builder activation(Activation activation) {
299             this.activation = activation;
300             return this;
301         }
302 
303         @Nonnull
304         public Builder properties(Map<String, String> properties) {
305             this.properties = properties;
306             return this;
307         }
308 
309         @Nonnull
310         public Builder repositories(Collection<Repository> repositories) {
311             this.repositories = repositories;
312             return this;
313         }
314 
315         @Nonnull
316         public Builder pluginRepositories(Collection<Repository> pluginRepositories) {
317             this.pluginRepositories = pluginRepositories;
318             return this;
319         }
320 
321 
322         @Nonnull
323         public Builder location(Object key, InputLocation location) {
324             if (location != null) {
325                 if (!(this.locations instanceof HashMap)) {
326                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
327                 }
328                 this.locations.put(key, location);
329             }
330             return this;
331         }
332 
333         @Nonnull
334         public Builder importedFrom(InputLocation importedFrom) {
335             this.importedFrom = importedFrom;
336             return this;
337         }
338 
339         @Nonnull
340         public Profile build() {
341             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
342             if (base != null
343                     && (id == null || id == base.id)
344                     && (activation == null || activation == base.activation)
345                     && (properties == null || properties == base.properties)
346                     && (repositories == null || repositories == base.repositories)
347                     && (pluginRepositories == null || pluginRepositories == base.pluginRepositories)
348             ) {
349                 return base;
350             }
351             return new Profile(this);
352         }
353     }
354 
355 }