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