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