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