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