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