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