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.model;
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 activated based on environmental
28   * parameters or command line arguments.
29   */
30  @Experimental
31  @Generated @ThreadSafe @Immutable
32  public class Profile
33      extends ModelBase
34      implements Serializable, InputLocationTracker
35  {
36      /**
37       * The identifier of this build profile. This is used for command line
38       * activation, and identifies profiles to be merged.
39       */
40      final String id;
41      /**
42       * The conditional logic which will automatically trigger the inclusion of this
43       * profile.
44       */
45      final Activation activation;
46      /**
47       * Information required to build the project.
48       */
49      final BuildBase build;
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.id = builder.id != null ? builder.id : (builder.base != null ? builder.base.id : null);
58          this.activation = builder.activation != null ? builder.activation : (builder.base != null ? builder.base.activation : null);
59          this.build = builder.build != null ? builder.build : (builder.base != null ? builder.base.build : null);
60      }
61  
62      /**
63       * The identifier of this build profile. This is used for command line
64       * activation, and identifies profiles to be merged.
65       *
66       * @return a {@code String}
67       */
68      public String getId() {
69          return this.id;
70      }
71  
72      /**
73       * The conditional logic which will automatically trigger the inclusion of this
74       * profile.
75       *
76       * @return a {@code Activation}
77       */
78      public Activation getActivation() {
79          return this.activation;
80      }
81  
82      /**
83       * Information required to build the project.
84       *
85       * @return a {@code BuildBase}
86       */
87      public BuildBase getBuild() {
88          return this.build;
89      }
90  
91      /**
92       * Creates a new builder with this object as the basis.
93       *
94       * @return a {@code Builder}
95       */
96      @Nonnull
97      public Builder with() {
98          return newBuilder(this);
99      }
100     /**
101      * Creates a new {@code Profile} instance using the specified modules.
102      *
103      * @param modules the new {@code Collection<String>} to use
104      * @return a {@code Profile} with the specified modules
105      */
106     @Deprecated
107     @Nonnull
108     public Profile withModules(Collection<String> modules) {
109         return newBuilder(this, true).modules(modules).build();
110     }
111     /**
112      * Creates a new {@code Profile} instance using the specified subprojects.
113      *
114      * @param subprojects the new {@code Collection<String>} to use
115      * @return a {@code Profile} with the specified subprojects
116      */
117     @Nonnull
118     public Profile withSubprojects(Collection<String> subprojects) {
119         return newBuilder(this, true).subprojects(subprojects).build();
120     }
121     /**
122      * Creates a new {@code Profile} instance using the specified distributionManagement.
123      *
124      * @param distributionManagement the new {@code DistributionManagement} to use
125      * @return a {@code Profile} with the specified distributionManagement
126      */
127     @Nonnull
128     public Profile withDistributionManagement(DistributionManagement distributionManagement) {
129         return newBuilder(this, true).distributionManagement(distributionManagement).build();
130     }
131     /**
132      * Creates a new {@code Profile} instance using the specified properties.
133      *
134      * @param properties the new {@code Map<String, String>} to use
135      * @return a {@code Profile} with the specified properties
136      */
137     @Nonnull
138     public Profile withProperties(Map<String, String> properties) {
139         return newBuilder(this, true).properties(properties).build();
140     }
141     /**
142      * Creates a new {@code Profile} instance using the specified dependencyManagement.
143      *
144      * @param dependencyManagement the new {@code DependencyManagement} to use
145      * @return a {@code Profile} with the specified dependencyManagement
146      */
147     @Nonnull
148     public Profile withDependencyManagement(DependencyManagement dependencyManagement) {
149         return newBuilder(this, true).dependencyManagement(dependencyManagement).build();
150     }
151     /**
152      * Creates a new {@code Profile} instance using the specified dependencies.
153      *
154      * @param dependencies the new {@code Collection<Dependency>} to use
155      * @return a {@code Profile} with the specified dependencies
156      */
157     @Nonnull
158     public Profile withDependencies(Collection<Dependency> dependencies) {
159         return newBuilder(this, true).dependencies(dependencies).build();
160     }
161     /**
162      * Creates a new {@code Profile} instance using the specified repositories.
163      *
164      * @param repositories the new {@code Collection<Repository>} to use
165      * @return a {@code Profile} with the specified repositories
166      */
167     @Nonnull
168     public Profile withRepositories(Collection<Repository> repositories) {
169         return newBuilder(this, true).repositories(repositories).build();
170     }
171     /**
172      * Creates a new {@code Profile} instance using the specified pluginRepositories.
173      *
174      * @param pluginRepositories the new {@code Collection<Repository>} to use
175      * @return a {@code Profile} with the specified pluginRepositories
176      */
177     @Nonnull
178     public Profile withPluginRepositories(Collection<Repository> pluginRepositories) {
179         return newBuilder(this, true).pluginRepositories(pluginRepositories).build();
180     }
181     /**
182      * Creates a new {@code Profile} instance using the specified reporting.
183      *
184      * @param reporting the new {@code Reporting} to use
185      * @return a {@code Profile} with the specified reporting
186      */
187     @Nonnull
188     public Profile withReporting(Reporting reporting) {
189         return newBuilder(this, true).reporting(reporting).build();
190     }
191     /**
192      * Creates a new {@code Profile} instance using the specified id.
193      *
194      * @param id the new {@code String} to use
195      * @return a {@code Profile} with the specified id
196      */
197     @Nonnull
198     public Profile withId(String id) {
199         return newBuilder(this, true).id(id).build();
200     }
201     /**
202      * Creates a new {@code Profile} instance using the specified activation.
203      *
204      * @param activation the new {@code Activation} to use
205      * @return a {@code Profile} with the specified activation
206      */
207     @Nonnull
208     public Profile withActivation(Activation activation) {
209         return newBuilder(this, true).activation(activation).build();
210     }
211     /**
212      * Creates a new {@code Profile} instance using the specified build.
213      *
214      * @param build the new {@code BuildBase} to use
215      * @return a {@code Profile} with the specified build
216      */
217     @Nonnull
218     public Profile withBuild(BuildBase build) {
219         return newBuilder(this, true).build(build).build();
220     }
221 
222     /**
223      * Creates a new {@code Profile} instance.
224      * Equivalent to {@code newInstance(true)}.
225      * @see #newInstance(boolean)
226      *
227      * @return a new {@code Profile}
228      */
229     @Nonnull
230     public static Profile newInstance() {
231         return newInstance(true);
232     }
233 
234     /**
235      * Creates a new {@code Profile} instance using default values or not.
236      * Equivalent to {@code newBuilder(withDefaults).build()}.
237      *
238      * @param withDefaults the boolean indicating whether default values should be used
239      * @return a new {@code Profile}
240      */
241     @Nonnull
242     public static Profile newInstance(boolean withDefaults) {
243         return newBuilder(withDefaults).build();
244     }
245 
246     /**
247      * Creates a new {@code Profile} builder instance.
248      * Equivalent to {@code newBuilder(true)}.
249      * @see #newBuilder(boolean)
250      *
251      * @return a new {@code Builder}
252      */
253     @Nonnull
254     public static Builder newBuilder() {
255         return newBuilder(true);
256     }
257 
258     /**
259      * Creates a new {@code Profile} builder instance using default values or not.
260      *
261      * @param withDefaults the boolean indicating whether default values should be used
262      * @return a new {@code Builder}
263      */
264     @Nonnull
265     public static Builder newBuilder(boolean withDefaults) {
266         return new Builder(withDefaults);
267     }
268 
269     /**
270      * Creates a new {@code Profile} builder instance using the specified object as a basis.
271      * Equivalent to {@code newBuilder(from, false)}.
272      *
273      * @param from the {@code Profile} instance to use as a basis
274      * @return a new {@code Builder}
275      */
276     @Nonnull
277     public static Builder newBuilder(Profile from) {
278         return newBuilder(from, false);
279     }
280 
281     /**
282      * Creates a new {@code Profile} builder instance using the specified object as a basis.
283      *
284      * @param from the {@code Profile} instance to use as a basis
285      * @param forceCopy the boolean indicating if a copy should be forced
286      * @return a new {@code Builder}
287      */
288     @Nonnull
289     public static Builder newBuilder(Profile from, boolean forceCopy) {
290         return new Builder(from, forceCopy);
291     }
292 
293     /**
294      * Builder class used to create Profile instances.
295      * @see #with()
296      * @see #newBuilder()
297      */
298     @NotThreadSafe
299     public static class Builder
300         extends ModelBase.Builder
301     {
302         Profile base;
303         String id;
304         Activation activation;
305         BuildBase build;
306 
307         protected Builder(boolean withDefaults) {
308             super(withDefaults);
309             if (withDefaults) {
310                 this.id = "default";
311             }
312         }
313 
314         protected Builder(Profile base, boolean forceCopy) {
315             super(base, forceCopy);
316             if (forceCopy) {
317                 this.id = base.id;
318                 this.activation = base.activation;
319                 this.build = base.build;
320                 this.locations = base.locations;
321                 this.importedFrom = base.importedFrom;
322             } else {
323                 this.base = base;
324             }
325         }
326 
327         @Deprecated
328         @Nonnull
329         public Builder modules(Collection<String> modules) {
330             this.modules = modules;
331             return this;
332         }
333 
334         @Nonnull
335         public Builder subprojects(Collection<String> subprojects) {
336             this.subprojects = subprojects;
337             return this;
338         }
339 
340         @Nonnull
341         public Builder distributionManagement(DistributionManagement distributionManagement) {
342             this.distributionManagement = distributionManagement;
343             return this;
344         }
345 
346         @Nonnull
347         public Builder properties(Map<String, String> properties) {
348             this.properties = properties;
349             return this;
350         }
351 
352         @Nonnull
353         public Builder dependencyManagement(DependencyManagement dependencyManagement) {
354             this.dependencyManagement = dependencyManagement;
355             return this;
356         }
357 
358         @Nonnull
359         public Builder dependencies(Collection<Dependency> dependencies) {
360             this.dependencies = dependencies;
361             return this;
362         }
363 
364         @Nonnull
365         public Builder repositories(Collection<Repository> repositories) {
366             this.repositories = repositories;
367             return this;
368         }
369 
370         @Nonnull
371         public Builder pluginRepositories(Collection<Repository> pluginRepositories) {
372             this.pluginRepositories = pluginRepositories;
373             return this;
374         }
375 
376         @Nonnull
377         public Builder reporting(Reporting reporting) {
378             this.reporting = reporting;
379             return this;
380         }
381 
382         @Nonnull
383         public Builder id(String id) {
384             this.id = id;
385             return this;
386         }
387 
388         @Nonnull
389         public Builder activation(Activation activation) {
390             this.activation = activation;
391             return this;
392         }
393 
394         @Nonnull
395         public Builder build(BuildBase build) {
396             this.build = build;
397             return this;
398         }
399 
400 
401         @Nonnull
402         public Builder location(Object key, InputLocation location) {
403             if (location != null) {
404                 if (!(this.locations instanceof HashMap)) {
405                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
406                 }
407                 this.locations.put(key, location);
408             }
409             return this;
410         }
411 
412         @Nonnull
413         public Builder importedFrom(InputLocation importedFrom) {
414             this.importedFrom = importedFrom;
415             return this;
416         }
417 
418         @Nonnull
419         public Profile build() {
420             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
421             if (base != null
422                     && (modules == null || modules == base.modules)
423                     && (subprojects == null || subprojects == base.subprojects)
424                     && (distributionManagement == null || distributionManagement == base.distributionManagement)
425                     && (properties == null || properties == base.properties)
426                     && (dependencyManagement == null || dependencyManagement == base.dependencyManagement)
427                     && (dependencies == null || dependencies == base.dependencies)
428                     && (repositories == null || repositories == base.repositories)
429                     && (pluginRepositories == null || pluginRepositories == base.pluginRepositories)
430                     && (reporting == null || reporting == base.reporting)
431                     && (id == null || id == base.id)
432                     && (activation == null || activation == base.activation)
433                     && (build == null || build == base.build)
434             ) {
435                 return base;
436             }
437             return new Profile(this);
438         }
439 
440     }
441 
442 
443             
444     public static final String SOURCE_POM = "pom";
445 
446     public static final String SOURCE_SETTINGS = "settings.xml";
447 
448     // We don't want this to be parseable...it's sort of 'hidden'
449     // default source for this profile is in the pom itself.
450     private String source = SOURCE_POM;
451 
452     public void setSource(String source) {
453         this.source = source;
454     }
455 
456     public String getSource() {
457         return source;
458     }
459 
460     /**
461      * @see java.lang.Object#toString()
462      */
463     public String toString() {
464         return "Profile {id: " + getId() + ", source: " + getSource() + "}";
465     }
466             
467           
468 }