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   * Base class for the {@code Model} and the {@code Profile} objects.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class ModelBase
28      implements Serializable, InputLocationTracker
29  {
30      /**
31       * @deprecated Use {@link #subprojects} instead.
32       */
33      @Deprecated
34      final List<String> modules;
35      /**
36       * The subprojects (formerly called modules) to build as a part of this
37       * project. Each subproject listed is a relative path to the directory containing the subproject.
38       * To be consistent with the way default URLs are calculated from parent, it is recommended
39       * to have subproject names match artifact ids.
40       */
41      final List<String> subprojects;
42      /**
43       * Distribution information for a project that enables deployment of the site
44       * and artifacts to remote web servers and repositories respectively.
45       */
46      final DistributionManagement distributionManagement;
47      /**
48       * Properties that can be used throughout the POM as a substitution, and
49       * are used as filters in resources if enabled.
50       * The format is {@code <name>value</name>}.
51       */
52      final Map<String, String> properties;
53      /**
54       * Default dependency information for projects that inherit from this one. The
55       * dependencies in this section are not immediately resolved. Instead, when a POM derived
56       * from this one declares a dependency described by a matching groupId and artifactId, the
57       * version and other values from this section are used for that dependency if they were not
58       * already specified.
59       */
60      final DependencyManagement dependencyManagement;
61      /**
62       * This element describes all the dependencies associated with a project.
63       * These dependencies are used to construct a classpath for your
64       * project during the build process. They are automatically downloaded from the
65       * repositories defined in this project.
66       * 
67       * @see <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html">Dependency mechanism</a>
68       */
69      final List<Dependency> dependencies;
70      /**
71       * The lists of the remote repositories for discovering dependencies and
72       * extensions.
73       */
74      final List<Repository> repositories;
75      /**
76       * The lists of the remote repositories for discovering plugins for builds and
77       * reports.
78       */
79      final List<Repository> pluginRepositories;
80      /**
81       * This element includes the specification of report plugins to use
82       * to generate the reports on the Maven-generated site.
83       * These reports will be run when a user executes {@code mvn site}.
84       * All the reports will be included in the navigation bar for browsing.
85       */
86      final Reporting reporting;
87      /** Locations (this potentially hides the same name field from the super class) */
88      final Map<Object, InputLocation> locations;
89      /** Location tracking */
90      final InputLocation importedFrom;
91  
92      /**
93        * Constructor for this class, to be called from its subclasses and {@link Builder}.
94        * @see Builder#build()
95        */
96      protected ModelBase(Builder builder) {
97          this.modules = ImmutableCollections.copy(builder.modules != null ? builder.modules : (builder.base != null ? builder.base.modules : null));
98          this.subprojects = ImmutableCollections.copy(builder.subprojects != null ? builder.subprojects : (builder.base != null ? builder.base.subprojects : null));
99          this.distributionManagement = builder.distributionManagement != null ? builder.distributionManagement : (builder.base != null ? builder.base.distributionManagement : null);
100         this.properties = ImmutableCollections.copy(builder.properties != null ? builder.properties : (builder.base != null ? builder.base.properties : null));
101         this.dependencyManagement = builder.dependencyManagement != null ? builder.dependencyManagement : (builder.base != null ? builder.base.dependencyManagement : null);
102         this.dependencies = ImmutableCollections.copy(builder.dependencies != null ? builder.dependencies : (builder.base != null ? builder.base.dependencies : null));
103         this.repositories = ImmutableCollections.copy(builder.repositories != null ? builder.repositories : (builder.base != null ? builder.base.repositories : null));
104         this.pluginRepositories = ImmutableCollections.copy(builder.pluginRepositories != null ? builder.pluginRepositories : (builder.base != null ? builder.base.pluginRepositories : null));
105         this.reporting = builder.reporting != null ? builder.reporting : (builder.base != null ? builder.base.reporting : null);
106         Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
107         Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
108         Map<Object, InputLocation> mutableLocations = new HashMap<>();
109         this.importedFrom = builder.importedFrom;
110         mutableLocations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
111         mutableLocations.put("modules", newlocs.containsKey("modules") ? newlocs.get("modules") : oldlocs.get("modules"));
112         mutableLocations.put("subprojects", newlocs.containsKey("subprojects") ? newlocs.get("subprojects") : oldlocs.get("subprojects"));
113         mutableLocations.put("distributionManagement", newlocs.containsKey("distributionManagement") ? newlocs.get("distributionManagement") : oldlocs.get("distributionManagement"));
114         mutableLocations.put("properties", newlocs.containsKey("properties") ? newlocs.get("properties") : oldlocs.get("properties"));
115         mutableLocations.put("dependencyManagement", newlocs.containsKey("dependencyManagement") ? newlocs.get("dependencyManagement") : oldlocs.get("dependencyManagement"));
116         mutableLocations.put("dependencies", newlocs.containsKey("dependencies") ? newlocs.get("dependencies") : oldlocs.get("dependencies"));
117         mutableLocations.put("repositories", newlocs.containsKey("repositories") ? newlocs.get("repositories") : oldlocs.get("repositories"));
118         mutableLocations.put("pluginRepositories", newlocs.containsKey("pluginRepositories") ? newlocs.get("pluginRepositories") : oldlocs.get("pluginRepositories"));
119         mutableLocations.put("reporting", newlocs.containsKey("reporting") ? newlocs.get("reporting") : oldlocs.get("reporting"));
120         this.locations = Collections.unmodifiableMap(mutableLocations);
121     }
122 
123     /**
124      * @deprecated Use {@link #subprojects} instead.
125      *
126      * @return a {@code List<String>}
127      */
128     @Deprecated
129     @Nonnull
130     public List<String> getModules() {
131         return this.modules;
132     }
133 
134     /**
135      * The subprojects (formerly called modules) to build as a part of this
136      * project. Each subproject listed is a relative path to the directory containing the subproject.
137      * To be consistent with the way default URLs are calculated from parent, it is recommended
138      * to have subproject names match artifact ids.
139      *
140      * @return a {@code List<String>}
141      */
142     @Nonnull
143     public List<String> getSubprojects() {
144         return this.subprojects;
145     }
146 
147     /**
148      * Distribution information for a project that enables deployment of the site
149      * and artifacts to remote web servers and repositories respectively.
150      *
151      * @return a {@code DistributionManagement}
152      */
153     public DistributionManagement getDistributionManagement() {
154         return this.distributionManagement;
155     }
156 
157     /**
158      * Properties that can be used throughout the POM as a substitution, and
159      * are used as filters in resources if enabled.
160      * The format is {@code <name>value</name>}.
161      *
162      * @return a {@code Map<String, String>}
163      */
164     @Nonnull
165     public Map<String, String> getProperties() {
166         return this.properties;
167     }
168 
169     /**
170      * Default dependency information for projects that inherit from this one. The
171      * dependencies in this section are not immediately resolved. Instead, when a POM derived
172      * from this one declares a dependency described by a matching groupId and artifactId, the
173      * version and other values from this section are used for that dependency if they were not
174      * already specified.
175      *
176      * @return a {@code DependencyManagement}
177      */
178     public DependencyManagement getDependencyManagement() {
179         return this.dependencyManagement;
180     }
181 
182     /**
183      * This element describes all the dependencies associated with a project.
184      * These dependencies are used to construct a classpath for your
185      * project during the build process. They are automatically downloaded from the
186      * repositories defined in this project.
187      * 
188      * @see <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html">Dependency mechanism</a>
189      *
190      * @return a {@code List<Dependency>}
191      */
192     @Nonnull
193     public List<Dependency> getDependencies() {
194         return this.dependencies;
195     }
196 
197     /**
198      * The lists of the remote repositories for discovering dependencies and
199      * extensions.
200      *
201      * @return a {@code List<Repository>}
202      */
203     @Nonnull
204     public List<Repository> getRepositories() {
205         return this.repositories;
206     }
207 
208     /**
209      * The lists of the remote repositories for discovering plugins for builds and
210      * reports.
211      *
212      * @return a {@code List<Repository>}
213      */
214     @Nonnull
215     public List<Repository> getPluginRepositories() {
216         return this.pluginRepositories;
217     }
218 
219     /**
220      * This element includes the specification of report plugins to use
221      * to generate the reports on the Maven-generated site.
222      * These reports will be run when a user executes {@code mvn site}.
223      * All the reports will be included in the navigation bar for browsing.
224      *
225      * @return a {@code Reporting}
226      */
227     public Reporting getReporting() {
228         return this.reporting;
229     }
230 
231     /**
232      * Gets the location of the specified field in the input source.
233      */
234     public InputLocation getLocation(Object key) {
235         return locations != null ? locations.get(key) : null;
236     }
237 
238     /**
239     * Gets the keys of the locations of the input source.
240     */
241     public Set<Object> getLocationKeys() {
242         return locations != null ? locations.keySet() : null;
243     }
244 
245     /**
246      * Gets the input location that caused this model to be read.
247      */
248     public InputLocation getImportedFrom()
249     {
250         return importedFrom;
251     }
252 
253     /**
254      * Creates a new builder with this object as the basis.
255      *
256      * @return a {@code Builder}
257      */
258     @Nonnull
259     public Builder with() {
260         return newBuilder(this);
261     }
262     /**
263      * Creates a new {@code ModelBase} instance using the specified modules.
264      *
265      * @param modules the new {@code Collection<String>} to use
266      * @return a {@code ModelBase} with the specified modules
267      */
268     @Deprecated
269     @Nonnull
270     public ModelBase withModules(Collection<String> modules) {
271         return newBuilder(this, true).modules(modules).build();
272     }
273     /**
274      * Creates a new {@code ModelBase} instance using the specified subprojects.
275      *
276      * @param subprojects the new {@code Collection<String>} to use
277      * @return a {@code ModelBase} with the specified subprojects
278      */
279     @Nonnull
280     public ModelBase withSubprojects(Collection<String> subprojects) {
281         return newBuilder(this, true).subprojects(subprojects).build();
282     }
283     /**
284      * Creates a new {@code ModelBase} instance using the specified distributionManagement.
285      *
286      * @param distributionManagement the new {@code DistributionManagement} to use
287      * @return a {@code ModelBase} with the specified distributionManagement
288      */
289     @Nonnull
290     public ModelBase withDistributionManagement(DistributionManagement distributionManagement) {
291         return newBuilder(this, true).distributionManagement(distributionManagement).build();
292     }
293     /**
294      * Creates a new {@code ModelBase} instance using the specified properties.
295      *
296      * @param properties the new {@code Map<String, String>} to use
297      * @return a {@code ModelBase} with the specified properties
298      */
299     @Nonnull
300     public ModelBase withProperties(Map<String, String> properties) {
301         return newBuilder(this, true).properties(properties).build();
302     }
303     /**
304      * Creates a new {@code ModelBase} instance using the specified dependencyManagement.
305      *
306      * @param dependencyManagement the new {@code DependencyManagement} to use
307      * @return a {@code ModelBase} with the specified dependencyManagement
308      */
309     @Nonnull
310     public ModelBase withDependencyManagement(DependencyManagement dependencyManagement) {
311         return newBuilder(this, true).dependencyManagement(dependencyManagement).build();
312     }
313     /**
314      * Creates a new {@code ModelBase} instance using the specified dependencies.
315      *
316      * @param dependencies the new {@code Collection<Dependency>} to use
317      * @return a {@code ModelBase} with the specified dependencies
318      */
319     @Nonnull
320     public ModelBase withDependencies(Collection<Dependency> dependencies) {
321         return newBuilder(this, true).dependencies(dependencies).build();
322     }
323     /**
324      * Creates a new {@code ModelBase} instance using the specified repositories.
325      *
326      * @param repositories the new {@code Collection<Repository>} to use
327      * @return a {@code ModelBase} with the specified repositories
328      */
329     @Nonnull
330     public ModelBase withRepositories(Collection<Repository> repositories) {
331         return newBuilder(this, true).repositories(repositories).build();
332     }
333     /**
334      * Creates a new {@code ModelBase} instance using the specified pluginRepositories.
335      *
336      * @param pluginRepositories the new {@code Collection<Repository>} to use
337      * @return a {@code ModelBase} with the specified pluginRepositories
338      */
339     @Nonnull
340     public ModelBase withPluginRepositories(Collection<Repository> pluginRepositories) {
341         return newBuilder(this, true).pluginRepositories(pluginRepositories).build();
342     }
343     /**
344      * Creates a new {@code ModelBase} instance using the specified reporting.
345      *
346      * @param reporting the new {@code Reporting} to use
347      * @return a {@code ModelBase} with the specified reporting
348      */
349     @Nonnull
350     public ModelBase withReporting(Reporting reporting) {
351         return newBuilder(this, true).reporting(reporting).build();
352     }
353 
354     /**
355      * Creates a new {@code ModelBase} instance.
356      * Equivalent to {@code newInstance(true)}.
357      * @see #newInstance(boolean)
358      *
359      * @return a new {@code ModelBase}
360      */
361     @Nonnull
362     public static ModelBase newInstance() {
363         return newInstance(true);
364     }
365 
366     /**
367      * Creates a new {@code ModelBase} instance using default values or not.
368      * Equivalent to {@code newBuilder(withDefaults).build()}.
369      *
370      * @param withDefaults the boolean indicating whether default values should be used
371      * @return a new {@code ModelBase}
372      */
373     @Nonnull
374     public static ModelBase newInstance(boolean withDefaults) {
375         return newBuilder(withDefaults).build();
376     }
377 
378     /**
379      * Creates a new {@code ModelBase} builder instance.
380      * Equivalent to {@code newBuilder(true)}.
381      * @see #newBuilder(boolean)
382      *
383      * @return a new {@code Builder}
384      */
385     @Nonnull
386     public static Builder newBuilder() {
387         return newBuilder(true);
388     }
389 
390     /**
391      * Creates a new {@code ModelBase} builder instance using default values or not.
392      *
393      * @param withDefaults the boolean indicating whether default values should be used
394      * @return a new {@code Builder}
395      */
396     @Nonnull
397     public static Builder newBuilder(boolean withDefaults) {
398         return new Builder(withDefaults);
399     }
400 
401     /**
402      * Creates a new {@code ModelBase} builder instance using the specified object as a basis.
403      * Equivalent to {@code newBuilder(from, false)}.
404      *
405      * @param from the {@code ModelBase} instance to use as a basis
406      * @return a new {@code Builder}
407      */
408     @Nonnull
409     public static Builder newBuilder(ModelBase from) {
410         return newBuilder(from, false);
411     }
412 
413     /**
414      * Creates a new {@code ModelBase} builder instance using the specified object as a basis.
415      *
416      * @param from the {@code ModelBase} instance to use as a basis
417      * @param forceCopy the boolean indicating if a copy should be forced
418      * @return a new {@code Builder}
419      */
420     @Nonnull
421     public static Builder newBuilder(ModelBase from, boolean forceCopy) {
422         return new Builder(from, forceCopy);
423     }
424 
425     /**
426      * Builder class used to create ModelBase instances.
427      * @see #with()
428      * @see #newBuilder()
429      */
430     @NotThreadSafe
431     public static class Builder
432     {
433         ModelBase base;
434         Collection<String> modules;
435         Collection<String> subprojects;
436         DistributionManagement distributionManagement;
437         Map<String, String> properties;
438         DependencyManagement dependencyManagement;
439         Collection<Dependency> dependencies;
440         Collection<Repository> repositories;
441         Collection<Repository> pluginRepositories;
442         Reporting reporting;
443         Map<Object, InputLocation> locations;
444         InputLocation importedFrom;
445 
446         protected Builder(boolean withDefaults) {
447             if (withDefaults) {
448             }
449         }
450 
451         protected Builder(ModelBase base, boolean forceCopy) {
452             if (forceCopy) {
453                 this.modules = base.modules;
454                 this.subprojects = base.subprojects;
455                 this.distributionManagement = base.distributionManagement;
456                 this.properties = base.properties;
457                 this.dependencyManagement = base.dependencyManagement;
458                 this.dependencies = base.dependencies;
459                 this.repositories = base.repositories;
460                 this.pluginRepositories = base.pluginRepositories;
461                 this.reporting = base.reporting;
462                 this.locations = base.locations;
463                 this.importedFrom = base.importedFrom;
464             } else {
465                 this.base = base;
466             }
467         }
468 
469         @Deprecated
470         @Nonnull
471         public Builder modules(Collection<String> modules) {
472             this.modules = modules;
473             return this;
474         }
475 
476         @Nonnull
477         public Builder subprojects(Collection<String> subprojects) {
478             this.subprojects = subprojects;
479             return this;
480         }
481 
482         @Nonnull
483         public Builder distributionManagement(DistributionManagement distributionManagement) {
484             this.distributionManagement = distributionManagement;
485             return this;
486         }
487 
488         @Nonnull
489         public Builder properties(Map<String, String> properties) {
490             this.properties = properties;
491             return this;
492         }
493 
494         @Nonnull
495         public Builder dependencyManagement(DependencyManagement dependencyManagement) {
496             this.dependencyManagement = dependencyManagement;
497             return this;
498         }
499 
500         @Nonnull
501         public Builder dependencies(Collection<Dependency> dependencies) {
502             this.dependencies = dependencies;
503             return this;
504         }
505 
506         @Nonnull
507         public Builder repositories(Collection<Repository> repositories) {
508             this.repositories = repositories;
509             return this;
510         }
511 
512         @Nonnull
513         public Builder pluginRepositories(Collection<Repository> pluginRepositories) {
514             this.pluginRepositories = pluginRepositories;
515             return this;
516         }
517 
518         @Nonnull
519         public Builder reporting(Reporting reporting) {
520             this.reporting = reporting;
521             return this;
522         }
523 
524 
525         @Nonnull
526         public Builder location(Object key, InputLocation location) {
527             if (location != null) {
528                 if (!(this.locations instanceof HashMap)) {
529                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
530                 }
531                 this.locations.put(key, location);
532             }
533             return this;
534         }
535 
536         @Nonnull
537         public Builder importedFrom(InputLocation importedFrom) {
538             this.importedFrom = importedFrom;
539             return this;
540         }
541 
542         @Nonnull
543         public ModelBase build() {
544             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
545             if (base != null
546                     && (modules == null || modules == base.modules)
547                     && (subprojects == null || subprojects == base.subprojects)
548                     && (distributionManagement == null || distributionManagement == base.distributionManagement)
549                     && (properties == null || properties == base.properties)
550                     && (dependencyManagement == null || dependencyManagement == base.dependencyManagement)
551                     && (dependencies == null || dependencies == base.dependencies)
552                     && (repositories == null || repositories == base.repositories)
553                     && (pluginRepositories == null || pluginRepositories == base.pluginRepositories)
554                     && (reporting == null || reporting == base.reporting)
555             ) {
556                 return base;
557             }
558             return new ModelBase(this);
559         }
560     }
561 
562 }