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      /** Location of the xml element for this object. */
83      final InputLocation location;
84      /** Location of the xml element for the field modules. */
85      final InputLocation modulesLocation;
86      /** Location of the xml element for the field distributionManagement. */
87      final InputLocation distributionManagementLocation;
88      /** Location of the xml element for the field properties. */
89      final InputLocation propertiesLocation;
90      /** Location of the xml element for the field dependencyManagement. */
91      final InputLocation dependencyManagementLocation;
92      /** Location of the xml element for the field dependencies. */
93      final InputLocation dependenciesLocation;
94      /** Location of the xml element for the field repositories. */
95      final InputLocation repositoriesLocation;
96      /** Location of the xml element for the field pluginRepositories. */
97      final InputLocation pluginRepositoriesLocation;
98      /** Location of the xml element for the field reporting. */
99      final InputLocation reportingLocation;
100     /** Other locations */
101     final Map<Object, InputLocation> locations;
102 
103     /**
104       * Constructor for this class, package protected.
105       * @see Builder#build()
106       */
107     ModelBase(
108         Collection<String> modules,
109         DistributionManagement distributionManagement,
110         Map<String, String> properties,
111         DependencyManagement dependencyManagement,
112         Collection<Dependency> dependencies,
113         Collection<Repository> repositories,
114         Collection<Repository> pluginRepositories,
115         Reporting reporting,
116         Map<Object, InputLocation> locations,
117         InputLocation location,
118         InputLocation modulesLocation,
119         InputLocation distributionManagementLocation,
120         InputLocation propertiesLocation,
121         InputLocation dependencyManagementLocation,
122         InputLocation dependenciesLocation,
123         InputLocation repositoriesLocation,
124         InputLocation pluginRepositoriesLocation,
125         InputLocation reportingLocation
126     )
127     {
128         this.modules = ImmutableCollections.copy( modules );
129         this.distributionManagement = distributionManagement;
130         this.properties = ImmutableCollections.copy( properties );
131         this.dependencyManagement = dependencyManagement;
132         this.dependencies = ImmutableCollections.copy( dependencies );
133         this.repositories = ImmutableCollections.copy( repositories );
134         this.pluginRepositories = ImmutableCollections.copy( pluginRepositories );
135         this.reporting = reporting;
136         this.locations = ImmutableCollections.copy( locations );
137         this.location = location;
138         this.modulesLocation = modulesLocation;
139         this.distributionManagementLocation = distributionManagementLocation;
140         this.propertiesLocation = propertiesLocation;
141         this.dependencyManagementLocation = dependencyManagementLocation;
142         this.dependenciesLocation = dependenciesLocation;
143         this.repositoriesLocation = repositoriesLocation;
144         this.pluginRepositoriesLocation = pluginRepositoriesLocation;
145         this.reportingLocation = reportingLocation;
146     }
147 
148     /**
149      * The modules (sometimes called subprojects) to build as a part of this
150      * project. Each module listed is a relative path to the directory containing the module.
151      * To be consistent with the way default urls are calculated from parent, it is recommended
152      * to have module names match artifact ids.
153      *
154      * @return a {@code List<String>}
155      */
156     @Nonnull
157     public List<String> getModules()
158     {
159         return this.modules;
160     }
161 
162     /**
163      * Distribution information for a project that enables deployment of the site
164      * and artifacts to remote web servers and repositories respectively.
165      *
166      * @return a {@code DistributionManagement}
167      */
168     public DistributionManagement getDistributionManagement()
169     {
170         return this.distributionManagement;
171     }
172 
173     /**
174      * Properties that can be used throughout the POM as a substitution, and
175      * are used as filters in resources if enabled.
176      * The format is {@code <name>value</name>}.
177      *
178      * @return a {@code Map<String, String>}
179      */
180     @Nonnull
181     public Map<String, String> getProperties()
182     {
183         return this.properties;
184     }
185 
186     /**
187      * Default dependency information for projects that inherit from this one. The
188      * dependencies in this section are not immediately resolved. Instead, when a POM derived
189      * from this one declares a dependency described by a matching groupId and artifactId, the
190      * version and other values from this section are used for that dependency if they were not
191      * already specified.
192      *
193      * @return a {@code DependencyManagement}
194      */
195     public DependencyManagement getDependencyManagement()
196     {
197         return this.dependencyManagement;
198     }
199 
200     /**
201      * This element describes all of the dependencies associated with a
202      * project.
203      * These dependencies are used to construct a classpath for your
204      * project during the build process. They are automatically downloaded from the
205      * repositories defined in this project.
206      * See <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html">the
207      * dependency mechanism</a> for more information.
208      *
209      * @return a {@code List<Dependency>}
210      */
211     @Nonnull
212     public List<Dependency> getDependencies()
213     {
214         return this.dependencies;
215     }
216 
217     /**
218      * The lists of the remote repositories for discovering dependencies and
219      * extensions.
220      *
221      * @return a {@code List<Repository>}
222      */
223     @Nonnull
224     public List<Repository> getRepositories()
225     {
226         return this.repositories;
227     }
228 
229     /**
230      * The lists of the remote repositories for discovering plugins for builds and
231      * reports.
232      *
233      * @return a {@code List<Repository>}
234      */
235     @Nonnull
236     public List<Repository> getPluginRepositories()
237     {
238         return this.pluginRepositories;
239     }
240 
241     /**
242      * This element includes the specification of report plugins to use
243      * to generate the reports on the Maven-generated site.
244      * These reports will be run when a user executes {@code mvn site}.
245      * All of the reports will be included in the navigation bar for browsing.
246      *
247      * @return a {@code Reporting}
248      */
249     public Reporting getReporting()
250     {
251         return this.reporting;
252     }
253 
254     /**
255      * Gets the location of the specified field in the input source.
256      */
257     public InputLocation getLocation( Object key )
258     {
259         if ( key instanceof String )
260         {
261             switch ( ( String ) key )
262             {
263                 case "":
264                     return location;
265                 case "modules":
266                     return modulesLocation;
267                 case "distributionManagement":
268                     return distributionManagementLocation;
269                 case "properties":
270                     return propertiesLocation;
271                 case "dependencyManagement":
272                     return dependencyManagementLocation;
273                 case "dependencies":
274                     return dependenciesLocation;
275                 case "repositories":
276                     return repositoriesLocation;
277                 case "pluginRepositories":
278                     return pluginRepositoriesLocation;
279                 case "reporting":
280                     return reportingLocation;
281             }
282         }
283         return locations != null ? locations.get( key ) : null;
284     }
285 
286     /**
287      * Creates a new builder with this object as the basis.
288      *
289      * @return a {@code Builder}
290      */
291     @Nonnull
292     public Builder with()
293     {
294         return newBuilder( this );
295     }
296     /**
297      * Creates a new {@code ModelBase} instance using the specified modules.
298      *
299      * @param modules the new {@code Collection<String>} to use
300      * @return a {@code ModelBase} with the specified modules
301      */
302     @Nonnull
303     public ModelBase withModules( Collection<String> modules )
304     {
305         return with().modules( modules ).build();
306     }
307     /**
308      * Creates a new {@code ModelBase} instance using the specified distributionManagement.
309      *
310      * @param distributionManagement the new {@code DistributionManagement} to use
311      * @return a {@code ModelBase} with the specified distributionManagement
312      */
313     @Nonnull
314     public ModelBase withDistributionManagement( DistributionManagement distributionManagement )
315     {
316         return with().distributionManagement( distributionManagement ).build();
317     }
318     /**
319      * Creates a new {@code ModelBase} instance using the specified properties.
320      *
321      * @param properties the new {@code Map<String, String>} to use
322      * @return a {@code ModelBase} with the specified properties
323      */
324     @Nonnull
325     public ModelBase withProperties( Map<String, String> properties )
326     {
327         return with().properties( properties ).build();
328     }
329     /**
330      * Creates a new {@code ModelBase} instance using the specified dependencyManagement.
331      *
332      * @param dependencyManagement the new {@code DependencyManagement} to use
333      * @return a {@code ModelBase} with the specified dependencyManagement
334      */
335     @Nonnull
336     public ModelBase withDependencyManagement( DependencyManagement dependencyManagement )
337     {
338         return with().dependencyManagement( dependencyManagement ).build();
339     }
340     /**
341      * Creates a new {@code ModelBase} instance using the specified dependencies.
342      *
343      * @param dependencies the new {@code Collection<Dependency>} to use
344      * @return a {@code ModelBase} with the specified dependencies
345      */
346     @Nonnull
347     public ModelBase withDependencies( Collection<Dependency> dependencies )
348     {
349         return with().dependencies( dependencies ).build();
350     }
351     /**
352      * Creates a new {@code ModelBase} instance using the specified repositories.
353      *
354      * @param repositories the new {@code Collection<Repository>} to use
355      * @return a {@code ModelBase} with the specified repositories
356      */
357     @Nonnull
358     public ModelBase withRepositories( Collection<Repository> repositories )
359     {
360         return with().repositories( repositories ).build();
361     }
362     /**
363      * Creates a new {@code ModelBase} instance using the specified pluginRepositories.
364      *
365      * @param pluginRepositories the new {@code Collection<Repository>} to use
366      * @return a {@code ModelBase} with the specified pluginRepositories
367      */
368     @Nonnull
369     public ModelBase withPluginRepositories( Collection<Repository> pluginRepositories )
370     {
371         return with().pluginRepositories( pluginRepositories ).build();
372     }
373     /**
374      * Creates a new {@code ModelBase} instance using the specified reporting.
375      *
376      * @param reporting the new {@code Reporting} to use
377      * @return a {@code ModelBase} with the specified reporting
378      */
379     @Nonnull
380     public ModelBase withReporting( Reporting reporting )
381     {
382         return with().reporting( reporting ).build();
383     }
384 
385     /**
386      * Creates a new {@code ModelBase} instance.
387      * Equivalent to {@code newInstance( true )}.
388      * @see #newInstance(boolean)
389      *
390      * @return a new {@code ModelBase}
391      */
392     @Nonnull
393     public static ModelBase newInstance()
394     {
395         return newInstance( true );
396     }
397 
398     /**
399      * Creates a new {@code ModelBase} instance using default values or not.
400      * Equivalent to {@code newBuilder( withDefaults ).build()}.
401      *
402      * @param withDefaults the boolean indicating whether default values should be used
403      * @return a new {@code ModelBase}
404      */
405     @Nonnull
406     public static ModelBase newInstance( boolean withDefaults )
407     {
408         return newBuilder( withDefaults ).build();
409     }
410 
411     /**
412      * Creates a new {@code ModelBase} builder instance.
413      * Equivalent to {@code newBuilder( true )}.
414      * @see #newBuilder(boolean)
415      *
416      * @return a new {@code Builder}
417      */
418     @Nonnull
419     public static Builder newBuilder()
420     {
421         return newBuilder( true );
422     }
423 
424     /**
425      * Creates a new {@code ModelBase} builder instance using default values or not.
426      *
427      * @param withDefaults the boolean indicating whether default values should be used
428      * @return a new {@code Builder}
429      */
430     @Nonnull
431     public static Builder newBuilder( boolean withDefaults )
432     {
433         return new Builder( withDefaults );
434     }
435 
436     /**
437      * Creates a new {@code ModelBase} builder instance using the specified object as a basis.
438      * Equivalent to {@code newBuilder( from, false )}.
439      *
440      * @param from the {@code ModelBase} instance to use as a basis
441      * @return a new {@code Builder}
442      */
443     @Nonnull
444     public static Builder newBuilder( ModelBase from )
445     {
446         return newBuilder( from, false );
447     }
448 
449     /**
450      * Creates a new {@code ModelBase} builder instance using the specified object as a basis.
451      *
452      * @param from the {@code ModelBase} instance to use as a basis
453      * @param forceCopy the boolean indicating if a copy should be forced
454      * @return a new {@code Builder}
455      */
456     @Nonnull
457     public static Builder newBuilder( ModelBase from, boolean forceCopy )
458     {
459         return new Builder( from, forceCopy );
460     }
461 
462     /**
463      * Builder class used to create ModelBase instances.
464      * @see #with()
465      * @see #newBuilder()
466      */
467     @NotThreadSafe
468     public static class Builder
469     {
470         ModelBase base;
471         Collection<String> modules;
472         DistributionManagement distributionManagement;
473         Map<String, String> properties;
474         DependencyManagement dependencyManagement;
475         Collection<Dependency> dependencies;
476         Collection<Repository> repositories;
477         Collection<Repository> pluginRepositories;
478         Reporting reporting;
479         Map<Object, InputLocation> locations;
480 
481         Builder( boolean withDefaults )
482         {
483             if ( withDefaults )
484             {
485             }
486         }
487 
488         Builder( ModelBase base, boolean forceCopy )
489         {
490             if ( forceCopy )
491             {
492                 this.modules = base.modules;
493                 this.distributionManagement = base.distributionManagement;
494                 this.properties = base.properties;
495                 this.dependencyManagement = base.dependencyManagement;
496                 this.dependencies = base.dependencies;
497                 this.repositories = base.repositories;
498                 this.pluginRepositories = base.pluginRepositories;
499                 this.reporting = base.reporting;
500             }
501             else
502             {
503                 this.base = base;
504             }
505         }
506 
507         @Nonnull
508         public Builder modules( Collection<String> modules )
509         {
510             this.modules = modules;
511             return this;
512         }
513 
514         @Nonnull
515         public Builder distributionManagement( DistributionManagement distributionManagement )
516         {
517             this.distributionManagement = distributionManagement;
518             return this;
519         }
520 
521         @Nonnull
522         public Builder properties( Map<String, String> properties )
523         {
524             this.properties = properties;
525             return this;
526         }
527 
528         @Nonnull
529         public Builder dependencyManagement( DependencyManagement dependencyManagement )
530         {
531             this.dependencyManagement = dependencyManagement;
532             return this;
533         }
534 
535         @Nonnull
536         public Builder dependencies( Collection<Dependency> dependencies )
537         {
538             this.dependencies = dependencies;
539             return this;
540         }
541 
542         @Nonnull
543         public Builder repositories( Collection<Repository> repositories )
544         {
545             this.repositories = repositories;
546             return this;
547         }
548 
549         @Nonnull
550         public Builder pluginRepositories( Collection<Repository> pluginRepositories )
551         {
552             this.pluginRepositories = pluginRepositories;
553             return this;
554         }
555 
556         @Nonnull
557         public Builder reporting( Reporting reporting )
558         {
559             this.reporting = reporting;
560             return this;
561         }
562 
563 
564         @Nonnull
565         public Builder location( Object key, InputLocation location )
566         {
567             if ( location != null )
568             {
569                 if ( this.locations == null )
570                 {
571                     this.locations = new HashMap<>();
572                 }
573                 this.locations.put( key, location );
574             }
575             return this;
576         }
577 
578         @Nonnull
579         public ModelBase build()
580         {
581             if ( base != null
582                     && ( modules == null || modules == base.modules )
583                     && ( distributionManagement == null || distributionManagement == base.distributionManagement )
584                     && ( properties == null || properties == base.properties )
585                     && ( dependencyManagement == null || dependencyManagement == base.dependencyManagement )
586                     && ( dependencies == null || dependencies == base.dependencies )
587                     && ( repositories == null || repositories == base.repositories )
588                     && ( pluginRepositories == null || pluginRepositories == base.pluginRepositories )
589                     && ( reporting == null || reporting == base.reporting )
590             )
591             {
592                 return base;
593             }
594             Map<Object, InputLocation> locations = null;
595             InputLocation location = null;
596             InputLocation modulesLocation = null;
597             InputLocation distributionManagementLocation = null;
598             InputLocation propertiesLocation = null;
599             InputLocation dependencyManagementLocation = null;
600             InputLocation dependenciesLocation = null;
601             InputLocation repositoriesLocation = null;
602             InputLocation pluginRepositoriesLocation = null;
603             InputLocation reportingLocation = null;
604             if ( this.locations != null )
605             {
606                 locations = this.locations;
607                 location = locations.remove( "" );
608                 modulesLocation = locations.remove( "modules" );
609                 distributionManagementLocation = locations.remove( "distributionManagement" );
610                 propertiesLocation = locations.remove( "properties" );
611                 dependencyManagementLocation = locations.remove( "dependencyManagement" );
612                 dependenciesLocation = locations.remove( "dependencies" );
613                 repositoriesLocation = locations.remove( "repositories" );
614                 pluginRepositoriesLocation = locations.remove( "pluginRepositories" );
615                 reportingLocation = locations.remove( "reporting" );
616             }
617             return new ModelBase(
618                 modules != null ? modules : ( base != null ? base.modules : null ),
619                 distributionManagement != null ? distributionManagement : ( base != null ? base.distributionManagement : null ),
620                 properties != null ? properties : ( base != null ? base.properties : null ),
621                 dependencyManagement != null ? dependencyManagement : ( base != null ? base.dependencyManagement : null ),
622                 dependencies != null ? dependencies : ( base != null ? base.dependencies : null ),
623                 repositories != null ? repositories : ( base != null ? base.repositories : null ),
624                 pluginRepositories != null ? pluginRepositories : ( base != null ? base.pluginRepositories : null ),
625                 reporting != null ? reporting : ( base != null ? base.reporting : null ),
626                 locations != null ? locations : ( base != null ? base.locations : null ),
627                 location != null ? location : ( base != null ? base.location : null ),
628                 modulesLocation != null ? modulesLocation : ( base != null ? base.modulesLocation : null ),
629                 distributionManagementLocation != null ? distributionManagementLocation : ( base != null ? base.distributionManagementLocation : null ),
630                 propertiesLocation != null ? propertiesLocation : ( base != null ? base.propertiesLocation : null ),
631                 dependencyManagementLocation != null ? dependencyManagementLocation : ( base != null ? base.dependencyManagementLocation : null ),
632                 dependenciesLocation != null ? dependenciesLocation : ( base != null ? base.dependenciesLocation : null ),
633                 repositoriesLocation != null ? repositoriesLocation : ( base != null ? base.repositoriesLocation : null ),
634                 pluginRepositoriesLocation != null ? pluginRepositoriesLocation : ( base != null ? base.pluginRepositoriesLocation : null ),
635                 reportingLocation != null ? reportingLocation : ( base != null ? base.reportingLocation : null )
636             );
637         }
638     }
639 
640 }