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