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.nio.file.Path;
9   import java.util.ArrayList;
10  import java.util.Collection;
11  import java.util.Collections;
12  import java.util.HashMap;
13  import java.util.List;
14  import java.util.Map;
15  import java.util.Objects;
16  import java.util.Optional;
17  import java.util.Set;
18  import java.util.stream.Collectors;
19  import java.util.stream.Stream;
20  import org.apache.maven.api.annotations.Experimental;
21  import org.apache.maven.api.annotations.Generated;
22  import org.apache.maven.api.annotations.Immutable;
23  import org.apache.maven.api.annotations.Nonnull;
24  import org.apache.maven.api.annotations.NotThreadSafe;
25  import org.apache.maven.api.annotations.ThreadSafe;
26  
27  /**
28   * The {@code <project>} element is the root of the descriptor.
29   * The following table lists all of the possible child elements.
30   */
31  @Experimental
32  @Generated @ThreadSafe @Immutable
33  public class Model
34      extends ModelBase
35      implements Serializable, InputLocationTracker
36  {
37      final String namespaceUri;
38      final String modelEncoding;
39      /**
40       * Originating POM file
41       */
42      final Path pomFile;
43      /**
44       * Declares to which version of project descriptor this POM conforms.
45       */
46      final String modelVersion;
47      /**
48       * The location of the parent project, if one exists. Values from the parent
49       * project will be the default for this project if they are left unspecified. The location
50       * is given as a group ID, artifact ID and version.
51       */
52      final Parent parent;
53      /**
54       * A universally unique identifier for a project. It is normal to
55       * use a fully-qualified package name to distinguish it from other
56       * projects with a similar name (eg. {@code org.apache.maven}).
57       */
58      final String groupId;
59      /**
60       * The identifier for this artifact that is unique within the group given by the
61       * group ID. An artifact is something that is either produced or used by a project.
62       * Examples of artifacts produced by Maven for a project include: JARs, source and binary
63       * distributions, and WARs.
64       */
65      final String artifactId;
66      /**
67       * The current version of the artifact produced by this project.
68       */
69      final String version;
70      /**
71       * The type of artifact this project produces, for example {@code jar},
72       * {@code war},
73       * {@code ear},
74       * {@code pom}.
75       * Plugins can create their own packaging, and
76       * therefore their own packaging types,
77       * so this list does not contain all possible types.
78       */
79      final String packaging;
80      /**
81       * The full name of the project.
82       */
83      final String name;
84      /**
85       * A detailed description of the project, used by Maven whenever it needs to
86       * describe the project, such as on the website. While this element can be specified as
87       * CDATA to enable the use of HTML tags within the description, it is discouraged to allow
88       * plain text representation. If you need to modify the index page of the generated website,
89       * you are able to specify your own instead of adjusting this text.
90       */
91      final String description;
92      /**
93       * The URL to the project's homepage.
94       * <p><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
95       * project's {@code child.project.url.inherit.append.path="false"}</p>
96       */
97      final String url;
98      /**
99       * When children inherit from project's url, append path or not? Note: While the type
100      * of this field is {@code String} for technical reasons, the semantic type is actually
101      * {@code Boolean}
102      * <p><b>Default value is</b>: {@code true}</p>
103      * @since Maven 3.6.1
104      */
105     final String childProjectUrlInheritAppendPath;
106     /**
107      * Indicates that this project is the root project, located in the upper directory of the source tree.
108      * This is the directory which may contain the .mvn directory.
109      * 
110      * @since Maven 4.0.0
111      */
112     final boolean root;
113     /**
114      * Indicates if the build POM for this project should be preserved or downgraded to the lowest
115      * compatible version.
116      * @since Maven 4.0.0
117      */
118     final boolean preserveModelVersion;
119     /**
120      * The year of the project's inception, specified with 4 digits. This value is
121      * used when generating copyright notices as well as being informational.
122      */
123     final String inceptionYear;
124     /**
125      * This element describes various attributes of the organization to which the
126      * project belongs. These attributes are utilized when documentation is created (for
127      * copyright notices and links).
128      */
129     final Organization organization;
130     /**
131      * This element describes all the licenses for this project.
132      * Each license is described by a {@code license} element, which
133      * is then described by additional elements.
134      * Projects should only list the license(s) that applies to the project
135      * and not the licenses that apply to dependencies.
136      * If multiple licenses are listed, it is assumed that the user can select
137      * any of them, not that they must accept all.
138      */
139     final List<License> licenses;
140     /**
141      * Describes the committers of a project.
142      */
143     final List<Developer> developers;
144     /**
145      * Describes the contributors to a project that are not yet committers.
146      */
147     final List<Contributor> contributors;
148     /**
149      * Contains information about a project's mailing lists.
150      */
151     final List<MailingList> mailingLists;
152     /**
153      * Describes the prerequisites in the build environment for this project.
154      */
155     final Prerequisites prerequisites;
156     /**
157      * Specification for the SCM used by the project, such as CVS, Subversion, etc.
158      */
159     final Scm scm;
160     /**
161      * The project's issue management system information.
162      */
163     final IssueManagement issueManagement;
164     /**
165      * The project's continuous integration information.
166      */
167     final CiManagement ciManagement;
168     /**
169      * Information required to build the project.
170      */
171     final Build build;
172     /**
173      * A listing of project-local build profiles which will modify the build process
174      * when activated.
175      */
176     final List<Profile> profiles;
177 
178     /**
179       * Constructor for this class, to be called from its subclasses and {@link Builder}.
180       * @see Builder#build()
181       */
182     protected Model(Builder builder) {
183         super(builder);
184         this.namespaceUri = builder.namespaceUri != null ? builder.namespaceUri : (builder.base != null ? builder.base.namespaceUri : null);
185         this.modelEncoding = builder.modelEncoding != null ? builder.modelEncoding : (builder.base != null ? builder.base.modelEncoding :  "UTF-8");
186         this.pomFile = builder.pomFile != null ? builder.pomFile : (builder.base != null ? builder.base.pomFile : null);
187         this.modelVersion = builder.modelVersion != null ? builder.modelVersion : (builder.base != null ? builder.base.modelVersion : null);
188         this.parent = builder.parent != null ? builder.parent : (builder.base != null ? builder.base.parent : null);
189         this.groupId = builder.groupId != null ? builder.groupId : (builder.base != null ? builder.base.groupId : null);
190         this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
191         this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
192         this.packaging = builder.packaging != null ? builder.packaging : (builder.base != null ? builder.base.packaging : null);
193         this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
194         this.description = builder.description != null ? builder.description : (builder.base != null ? builder.base.description : null);
195         this.url = builder.url != null ? builder.url : (builder.base != null ? builder.base.url : null);
196         this.childProjectUrlInheritAppendPath = builder.childProjectUrlInheritAppendPath != null ? builder.childProjectUrlInheritAppendPath : (builder.base != null ? builder.base.childProjectUrlInheritAppendPath : null);
197         this.root = builder.root != null ? builder.root : (builder.base != null ? builder.base.root : false);
198         this.preserveModelVersion = builder.preserveModelVersion != null ? builder.preserveModelVersion : (builder.base != null ? builder.base.preserveModelVersion : false);
199         this.inceptionYear = builder.inceptionYear != null ? builder.inceptionYear : (builder.base != null ? builder.base.inceptionYear : null);
200         this.organization = builder.organization != null ? builder.organization : (builder.base != null ? builder.base.organization : null);
201         this.licenses = ImmutableCollections.copy(builder.licenses != null ? builder.licenses : (builder.base != null ? builder.base.licenses : null));
202         this.developers = ImmutableCollections.copy(builder.developers != null ? builder.developers : (builder.base != null ? builder.base.developers : null));
203         this.contributors = ImmutableCollections.copy(builder.contributors != null ? builder.contributors : (builder.base != null ? builder.base.contributors : null));
204         this.mailingLists = ImmutableCollections.copy(builder.mailingLists != null ? builder.mailingLists : (builder.base != null ? builder.base.mailingLists : null));
205         this.prerequisites = builder.prerequisites != null ? builder.prerequisites : (builder.base != null ? builder.base.prerequisites : null);
206         this.scm = builder.scm != null ? builder.scm : (builder.base != null ? builder.base.scm : null);
207         this.issueManagement = builder.issueManagement != null ? builder.issueManagement : (builder.base != null ? builder.base.issueManagement : null);
208         this.ciManagement = builder.ciManagement != null ? builder.ciManagement : (builder.base != null ? builder.base.ciManagement : null);
209         this.build = builder.build != null ? builder.build : (builder.base != null ? builder.base.build : null);
210         this.profiles = ImmutableCollections.copy(builder.profiles != null ? builder.profiles : (builder.base != null ? builder.base.profiles : null));
211     }
212 
213     public String getNamespaceUri() {
214         return namespaceUri;
215     }
216 
217     public String getModelEncoding() {
218         return modelEncoding;
219     }
220 
221     /**
222      * Originating POM file
223      *
224      * @return a {@code Path}
225      */
226     public Path getPomFile() {
227         return this.pomFile;
228     }
229 
230     /**
231      * Declares to which version of project descriptor this POM conforms.
232      *
233      * @return a {@code String}
234      */
235     public String getModelVersion() {
236         return this.modelVersion;
237     }
238 
239     /**
240      * The location of the parent project, if one exists. Values from the parent
241      * project will be the default for this project if they are left unspecified. The location
242      * is given as a group ID, artifact ID and version.
243      *
244      * @return a {@code Parent}
245      */
246     public Parent getParent() {
247         return this.parent;
248     }
249 
250     /**
251      * A universally unique identifier for a project. It is normal to
252      * use a fully-qualified package name to distinguish it from other
253      * projects with a similar name (eg. {@code org.apache.maven}).
254      *
255      * @return a {@code String}
256      */
257     public String getGroupId() {
258         return this.groupId;
259     }
260 
261     /**
262      * The identifier for this artifact that is unique within the group given by the
263      * group ID. An artifact is something that is either produced or used by a project.
264      * Examples of artifacts produced by Maven for a project include: JARs, source and binary
265      * distributions, and WARs.
266      *
267      * @return a {@code String}
268      */
269     public String getArtifactId() {
270         return this.artifactId;
271     }
272 
273     /**
274      * The current version of the artifact produced by this project.
275      *
276      * @return a {@code String}
277      */
278     public String getVersion() {
279         return this.version;
280     }
281 
282     /**
283      * The type of artifact this project produces, for example {@code jar},
284      * {@code war},
285      * {@code ear},
286      * {@code pom}.
287      * Plugins can create their own packaging, and
288      * therefore their own packaging types,
289      * so this list does not contain all possible types.
290      *
291      * @return a {@code String}
292      */
293     public String getPackaging() {
294         return this.packaging;
295     }
296 
297     /**
298      * The full name of the project.
299      *
300      * @return a {@code String}
301      */
302     public String getName() {
303         return this.name;
304     }
305 
306     /**
307      * A detailed description of the project, used by Maven whenever it needs to
308      * describe the project, such as on the website. While this element can be specified as
309      * CDATA to enable the use of HTML tags within the description, it is discouraged to allow
310      * plain text representation. If you need to modify the index page of the generated website,
311      * you are able to specify your own instead of adjusting this text.
312      *
313      * @return a {@code String}
314      */
315     public String getDescription() {
316         return this.description;
317     }
318 
319     /**
320      * The URL to the project's homepage.
321      * <p><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
322      * project's {@code child.project.url.inherit.append.path="false"}</p>
323      *
324      * @return a {@code String}
325      */
326     public String getUrl() {
327         return this.url;
328     }
329 
330     /**
331      * When children inherit from project's url, append path or not? Note: While the type
332      * of this field is {@code String} for technical reasons, the semantic type is actually
333      * {@code Boolean}
334      * <p><b>Default value is</b>: {@code true}</p>
335      * @since Maven 3.6.1
336      *
337      * @return a {@code String}
338      */
339     public String getChildProjectUrlInheritAppendPath() {
340         return this.childProjectUrlInheritAppendPath;
341     }
342 
343     /**
344      * Indicates that this project is the root project, located in the upper directory of the source tree.
345      * This is the directory which may contain the .mvn directory.
346      * 
347      * @since Maven 4.0.0
348      *
349      * @return a {@code boolean}
350      */
351     public boolean isRoot() {
352         return this.root;
353     }
354 
355     /**
356      * Indicates if the build POM for this project should be preserved or downgraded to the lowest
357      * compatible version.
358      * @since Maven 4.0.0
359      *
360      * @return a {@code boolean}
361      */
362     public boolean isPreserveModelVersion() {
363         return this.preserveModelVersion;
364     }
365 
366     /**
367      * The year of the project's inception, specified with 4 digits. This value is
368      * used when generating copyright notices as well as being informational.
369      *
370      * @return a {@code String}
371      */
372     public String getInceptionYear() {
373         return this.inceptionYear;
374     }
375 
376     /**
377      * This element describes various attributes of the organization to which the
378      * project belongs. These attributes are utilized when documentation is created (for
379      * copyright notices and links).
380      *
381      * @return a {@code Organization}
382      */
383     public Organization getOrganization() {
384         return this.organization;
385     }
386 
387     /**
388      * This element describes all the licenses for this project.
389      * Each license is described by a {@code license} element, which
390      * is then described by additional elements.
391      * Projects should only list the license(s) that applies to the project
392      * and not the licenses that apply to dependencies.
393      * If multiple licenses are listed, it is assumed that the user can select
394      * any of them, not that they must accept all.
395      *
396      * @return a {@code List<License>}
397      */
398     @Nonnull
399     public List<License> getLicenses() {
400         return this.licenses;
401     }
402 
403     /**
404      * Describes the committers of a project.
405      *
406      * @return a {@code List<Developer>}
407      */
408     @Nonnull
409     public List<Developer> getDevelopers() {
410         return this.developers;
411     }
412 
413     /**
414      * Describes the contributors to a project that are not yet committers.
415      *
416      * @return a {@code List<Contributor>}
417      */
418     @Nonnull
419     public List<Contributor> getContributors() {
420         return this.contributors;
421     }
422 
423     /**
424      * Contains information about a project's mailing lists.
425      *
426      * @return a {@code List<MailingList>}
427      */
428     @Nonnull
429     public List<MailingList> getMailingLists() {
430         return this.mailingLists;
431     }
432 
433     /**
434      * Describes the prerequisites in the build environment for this project.
435      *
436      * @return a {@code Prerequisites}
437      */
438     public Prerequisites getPrerequisites() {
439         return this.prerequisites;
440     }
441 
442     /**
443      * Specification for the SCM used by the project, such as CVS, Subversion, etc.
444      *
445      * @return a {@code Scm}
446      */
447     public Scm getScm() {
448         return this.scm;
449     }
450 
451     /**
452      * The project's issue management system information.
453      *
454      * @return a {@code IssueManagement}
455      */
456     public IssueManagement getIssueManagement() {
457         return this.issueManagement;
458     }
459 
460     /**
461      * The project's continuous integration information.
462      *
463      * @return a {@code CiManagement}
464      */
465     public CiManagement getCiManagement() {
466         return this.ciManagement;
467     }
468 
469     /**
470      * Information required to build the project.
471      *
472      * @return a {@code Build}
473      */
474     public Build getBuild() {
475         return this.build;
476     }
477 
478     /**
479      * A listing of project-local build profiles which will modify the build process
480      * when activated.
481      *
482      * @return a {@code List<Profile>}
483      */
484     @Nonnull
485     public List<Profile> getProfiles() {
486         return this.profiles;
487     }
488 
489     /**
490      * Creates a new builder with this object as the basis.
491      *
492      * @return a {@code Builder}
493      */
494     @Nonnull
495     public Builder with() {
496         return newBuilder(this);
497     }
498     /**
499      * Creates a new {@code Model} instance using the specified modules.
500      *
501      * @param modules the new {@code Collection<String>} to use
502      * @return a {@code Model} with the specified modules
503      */
504     @Deprecated
505     @Nonnull
506     public Model withModules(Collection<String> modules) {
507         return newBuilder(this, true).modules(modules).build();
508     }
509     /**
510      * Creates a new {@code Model} instance using the specified subprojects.
511      *
512      * @param subprojects the new {@code Collection<String>} to use
513      * @return a {@code Model} with the specified subprojects
514      */
515     @Nonnull
516     public Model withSubprojects(Collection<String> subprojects) {
517         return newBuilder(this, true).subprojects(subprojects).build();
518     }
519     /**
520      * Creates a new {@code Model} instance using the specified distributionManagement.
521      *
522      * @param distributionManagement the new {@code DistributionManagement} to use
523      * @return a {@code Model} with the specified distributionManagement
524      */
525     @Nonnull
526     public Model withDistributionManagement(DistributionManagement distributionManagement) {
527         return newBuilder(this, true).distributionManagement(distributionManagement).build();
528     }
529     /**
530      * Creates a new {@code Model} instance using the specified properties.
531      *
532      * @param properties the new {@code Map<String, String>} to use
533      * @return a {@code Model} with the specified properties
534      */
535     @Nonnull
536     public Model withProperties(Map<String, String> properties) {
537         return newBuilder(this, true).properties(properties).build();
538     }
539     /**
540      * Creates a new {@code Model} instance using the specified dependencyManagement.
541      *
542      * @param dependencyManagement the new {@code DependencyManagement} to use
543      * @return a {@code Model} with the specified dependencyManagement
544      */
545     @Nonnull
546     public Model withDependencyManagement(DependencyManagement dependencyManagement) {
547         return newBuilder(this, true).dependencyManagement(dependencyManagement).build();
548     }
549     /**
550      * Creates a new {@code Model} instance using the specified dependencies.
551      *
552      * @param dependencies the new {@code Collection<Dependency>} to use
553      * @return a {@code Model} with the specified dependencies
554      */
555     @Nonnull
556     public Model withDependencies(Collection<Dependency> dependencies) {
557         return newBuilder(this, true).dependencies(dependencies).build();
558     }
559     /**
560      * Creates a new {@code Model} instance using the specified repositories.
561      *
562      * @param repositories the new {@code Collection<Repository>} to use
563      * @return a {@code Model} with the specified repositories
564      */
565     @Nonnull
566     public Model withRepositories(Collection<Repository> repositories) {
567         return newBuilder(this, true).repositories(repositories).build();
568     }
569     /**
570      * Creates a new {@code Model} instance using the specified pluginRepositories.
571      *
572      * @param pluginRepositories the new {@code Collection<Repository>} to use
573      * @return a {@code Model} with the specified pluginRepositories
574      */
575     @Nonnull
576     public Model withPluginRepositories(Collection<Repository> pluginRepositories) {
577         return newBuilder(this, true).pluginRepositories(pluginRepositories).build();
578     }
579     /**
580      * Creates a new {@code Model} instance using the specified reporting.
581      *
582      * @param reporting the new {@code Reporting} to use
583      * @return a {@code Model} with the specified reporting
584      */
585     @Nonnull
586     public Model withReporting(Reporting reporting) {
587         return newBuilder(this, true).reporting(reporting).build();
588     }
589     /**
590      * Creates a new {@code Model} instance using the specified pomFile.
591      *
592      * @param pomFile the new {@code Path} to use
593      * @return a {@code Model} with the specified pomFile
594      */
595     @Nonnull
596     public Model withPomFile(Path pomFile) {
597         return newBuilder(this, true).pomFile(pomFile).build();
598     }
599     /**
600      * Creates a new {@code Model} instance using the specified modelVersion.
601      *
602      * @param modelVersion the new {@code String} to use
603      * @return a {@code Model} with the specified modelVersion
604      */
605     @Nonnull
606     public Model withModelVersion(String modelVersion) {
607         return newBuilder(this, true).modelVersion(modelVersion).build();
608     }
609     /**
610      * Creates a new {@code Model} instance using the specified parent.
611      *
612      * @param parent the new {@code Parent} to use
613      * @return a {@code Model} with the specified parent
614      */
615     @Nonnull
616     public Model withParent(Parent parent) {
617         return newBuilder(this, true).parent(parent).build();
618     }
619     /**
620      * Creates a new {@code Model} instance using the specified groupId.
621      *
622      * @param groupId the new {@code String} to use
623      * @return a {@code Model} with the specified groupId
624      */
625     @Nonnull
626     public Model withGroupId(String groupId) {
627         return newBuilder(this, true).groupId(groupId).build();
628     }
629     /**
630      * Creates a new {@code Model} instance using the specified artifactId.
631      *
632      * @param artifactId the new {@code String} to use
633      * @return a {@code Model} with the specified artifactId
634      */
635     @Nonnull
636     public Model withArtifactId(String artifactId) {
637         return newBuilder(this, true).artifactId(artifactId).build();
638     }
639     /**
640      * Creates a new {@code Model} instance using the specified version.
641      *
642      * @param version the new {@code String} to use
643      * @return a {@code Model} with the specified version
644      */
645     @Nonnull
646     public Model withVersion(String version) {
647         return newBuilder(this, true).version(version).build();
648     }
649     /**
650      * Creates a new {@code Model} instance using the specified packaging.
651      *
652      * @param packaging the new {@code String} to use
653      * @return a {@code Model} with the specified packaging
654      */
655     @Nonnull
656     public Model withPackaging(String packaging) {
657         return newBuilder(this, true).packaging(packaging).build();
658     }
659     /**
660      * Creates a new {@code Model} instance using the specified name.
661      *
662      * @param name the new {@code String} to use
663      * @return a {@code Model} with the specified name
664      */
665     @Nonnull
666     public Model withName(String name) {
667         return newBuilder(this, true).name(name).build();
668     }
669     /**
670      * Creates a new {@code Model} instance using the specified description.
671      *
672      * @param description the new {@code String} to use
673      * @return a {@code Model} with the specified description
674      */
675     @Nonnull
676     public Model withDescription(String description) {
677         return newBuilder(this, true).description(description).build();
678     }
679     /**
680      * Creates a new {@code Model} instance using the specified url.
681      *
682      * @param url the new {@code String} to use
683      * @return a {@code Model} with the specified url
684      */
685     @Nonnull
686     public Model withUrl(String url) {
687         return newBuilder(this, true).url(url).build();
688     }
689     /**
690      * Creates a new {@code Model} instance using the specified childProjectUrlInheritAppendPath.
691      *
692      * @param childProjectUrlInheritAppendPath the new {@code String} to use
693      * @return a {@code Model} with the specified childProjectUrlInheritAppendPath
694      */
695     @Nonnull
696     public Model withChildProjectUrlInheritAppendPath(String childProjectUrlInheritAppendPath) {
697         return newBuilder(this, true).childProjectUrlInheritAppendPath(childProjectUrlInheritAppendPath).build();
698     }
699     /**
700      * Creates a new {@code Model} instance using the specified root.
701      *
702      * @param root the new {@code boolean} to use
703      * @return a {@code Model} with the specified root
704      */
705     @Nonnull
706     public Model withRoot(boolean root) {
707         return newBuilder(this, true).root(root).build();
708     }
709     /**
710      * Creates a new {@code Model} instance using the specified preserveModelVersion.
711      *
712      * @param preserveModelVersion the new {@code boolean} to use
713      * @return a {@code Model} with the specified preserveModelVersion
714      */
715     @Nonnull
716     public Model withPreserveModelVersion(boolean preserveModelVersion) {
717         return newBuilder(this, true).preserveModelVersion(preserveModelVersion).build();
718     }
719     /**
720      * Creates a new {@code Model} instance using the specified inceptionYear.
721      *
722      * @param inceptionYear the new {@code String} to use
723      * @return a {@code Model} with the specified inceptionYear
724      */
725     @Nonnull
726     public Model withInceptionYear(String inceptionYear) {
727         return newBuilder(this, true).inceptionYear(inceptionYear).build();
728     }
729     /**
730      * Creates a new {@code Model} instance using the specified organization.
731      *
732      * @param organization the new {@code Organization} to use
733      * @return a {@code Model} with the specified organization
734      */
735     @Nonnull
736     public Model withOrganization(Organization organization) {
737         return newBuilder(this, true).organization(organization).build();
738     }
739     /**
740      * Creates a new {@code Model} instance using the specified licenses.
741      *
742      * @param licenses the new {@code Collection<License>} to use
743      * @return a {@code Model} with the specified licenses
744      */
745     @Nonnull
746     public Model withLicenses(Collection<License> licenses) {
747         return newBuilder(this, true).licenses(licenses).build();
748     }
749     /**
750      * Creates a new {@code Model} instance using the specified developers.
751      *
752      * @param developers the new {@code Collection<Developer>} to use
753      * @return a {@code Model} with the specified developers
754      */
755     @Nonnull
756     public Model withDevelopers(Collection<Developer> developers) {
757         return newBuilder(this, true).developers(developers).build();
758     }
759     /**
760      * Creates a new {@code Model} instance using the specified contributors.
761      *
762      * @param contributors the new {@code Collection<Contributor>} to use
763      * @return a {@code Model} with the specified contributors
764      */
765     @Nonnull
766     public Model withContributors(Collection<Contributor> contributors) {
767         return newBuilder(this, true).contributors(contributors).build();
768     }
769     /**
770      * Creates a new {@code Model} instance using the specified mailingLists.
771      *
772      * @param mailingLists the new {@code Collection<MailingList>} to use
773      * @return a {@code Model} with the specified mailingLists
774      */
775     @Nonnull
776     public Model withMailingLists(Collection<MailingList> mailingLists) {
777         return newBuilder(this, true).mailingLists(mailingLists).build();
778     }
779     /**
780      * Creates a new {@code Model} instance using the specified prerequisites.
781      *
782      * @param prerequisites the new {@code Prerequisites} to use
783      * @return a {@code Model} with the specified prerequisites
784      */
785     @Nonnull
786     public Model withPrerequisites(Prerequisites prerequisites) {
787         return newBuilder(this, true).prerequisites(prerequisites).build();
788     }
789     /**
790      * Creates a new {@code Model} instance using the specified scm.
791      *
792      * @param scm the new {@code Scm} to use
793      * @return a {@code Model} with the specified scm
794      */
795     @Nonnull
796     public Model withScm(Scm scm) {
797         return newBuilder(this, true).scm(scm).build();
798     }
799     /**
800      * Creates a new {@code Model} instance using the specified issueManagement.
801      *
802      * @param issueManagement the new {@code IssueManagement} to use
803      * @return a {@code Model} with the specified issueManagement
804      */
805     @Nonnull
806     public Model withIssueManagement(IssueManagement issueManagement) {
807         return newBuilder(this, true).issueManagement(issueManagement).build();
808     }
809     /**
810      * Creates a new {@code Model} instance using the specified ciManagement.
811      *
812      * @param ciManagement the new {@code CiManagement} to use
813      * @return a {@code Model} with the specified ciManagement
814      */
815     @Nonnull
816     public Model withCiManagement(CiManagement ciManagement) {
817         return newBuilder(this, true).ciManagement(ciManagement).build();
818     }
819     /**
820      * Creates a new {@code Model} instance using the specified build.
821      *
822      * @param build the new {@code Build} to use
823      * @return a {@code Model} with the specified build
824      */
825     @Nonnull
826     public Model withBuild(Build build) {
827         return newBuilder(this, true).build(build).build();
828     }
829     /**
830      * Creates a new {@code Model} instance using the specified profiles.
831      *
832      * @param profiles the new {@code Collection<Profile>} to use
833      * @return a {@code Model} with the specified profiles
834      */
835     @Nonnull
836     public Model withProfiles(Collection<Profile> profiles) {
837         return newBuilder(this, true).profiles(profiles).build();
838     }
839 
840     /**
841      * Creates a new {@code Model} instance.
842      * Equivalent to {@code newInstance(true)}.
843      * @see #newInstance(boolean)
844      *
845      * @return a new {@code Model}
846      */
847     @Nonnull
848     public static Model newInstance() {
849         return newInstance(true);
850     }
851 
852     /**
853      * Creates a new {@code Model} instance using default values or not.
854      * Equivalent to {@code newBuilder(withDefaults).build()}.
855      *
856      * @param withDefaults the boolean indicating whether default values should be used
857      * @return a new {@code Model}
858      */
859     @Nonnull
860     public static Model newInstance(boolean withDefaults) {
861         return newBuilder(withDefaults).build();
862     }
863 
864     /**
865      * Creates a new {@code Model} builder instance.
866      * Equivalent to {@code newBuilder(true)}.
867      * @see #newBuilder(boolean)
868      *
869      * @return a new {@code Builder}
870      */
871     @Nonnull
872     public static Builder newBuilder() {
873         return newBuilder(true);
874     }
875 
876     /**
877      * Creates a new {@code Model} builder instance using default values or not.
878      *
879      * @param withDefaults the boolean indicating whether default values should be used
880      * @return a new {@code Builder}
881      */
882     @Nonnull
883     public static Builder newBuilder(boolean withDefaults) {
884         return new Builder(withDefaults);
885     }
886 
887     /**
888      * Creates a new {@code Model} builder instance using the specified object as a basis.
889      * Equivalent to {@code newBuilder(from, false)}.
890      *
891      * @param from the {@code Model} instance to use as a basis
892      * @return a new {@code Builder}
893      */
894     @Nonnull
895     public static Builder newBuilder(Model from) {
896         return newBuilder(from, false);
897     }
898 
899     /**
900      * Creates a new {@code Model} builder instance using the specified object as a basis.
901      *
902      * @param from the {@code Model} instance to use as a basis
903      * @param forceCopy the boolean indicating if a copy should be forced
904      * @return a new {@code Builder}
905      */
906     @Nonnull
907     public static Builder newBuilder(Model from, boolean forceCopy) {
908         return new Builder(from, forceCopy);
909     }
910 
911     /**
912      * Builder class used to create Model instances.
913      * @see #with()
914      * @see #newBuilder()
915      */
916     @NotThreadSafe
917     public static class Builder
918         extends ModelBase.Builder
919     {
920         Model base;
921         String namespaceUri;
922         String modelEncoding;
923         Path pomFile;
924         String modelVersion;
925         Parent parent;
926         String groupId;
927         String artifactId;
928         String version;
929         String packaging;
930         String name;
931         String description;
932         String url;
933         String childProjectUrlInheritAppendPath;
934         Boolean root;
935         Boolean preserveModelVersion;
936         String inceptionYear;
937         Organization organization;
938         Collection<License> licenses;
939         Collection<Developer> developers;
940         Collection<Contributor> contributors;
941         Collection<MailingList> mailingLists;
942         Prerequisites prerequisites;
943         Scm scm;
944         IssueManagement issueManagement;
945         CiManagement ciManagement;
946         Build build;
947         Collection<Profile> profiles;
948 
949         protected Builder(boolean withDefaults) {
950             super(withDefaults);
951             if (withDefaults) {
952                 this.packaging = "jar";
953                 this.root = false;
954                 this.preserveModelVersion = false;
955             }
956         }
957 
958         protected Builder(Model base, boolean forceCopy) {
959             super(base, forceCopy);
960             this.namespaceUri = base.namespaceUri;
961             this.modelEncoding = base.modelEncoding;
962             if (forceCopy) {
963                 this.pomFile = base.pomFile;
964                 this.modelVersion = base.modelVersion;
965                 this.parent = base.parent;
966                 this.groupId = base.groupId;
967                 this.artifactId = base.artifactId;
968                 this.version = base.version;
969                 this.packaging = base.packaging;
970                 this.name = base.name;
971                 this.description = base.description;
972                 this.url = base.url;
973                 this.childProjectUrlInheritAppendPath = base.childProjectUrlInheritAppendPath;
974                 this.root = base.root;
975                 this.preserveModelVersion = base.preserveModelVersion;
976                 this.inceptionYear = base.inceptionYear;
977                 this.organization = base.organization;
978                 this.licenses = base.licenses;
979                 this.developers = base.developers;
980                 this.contributors = base.contributors;
981                 this.mailingLists = base.mailingLists;
982                 this.prerequisites = base.prerequisites;
983                 this.scm = base.scm;
984                 this.issueManagement = base.issueManagement;
985                 this.ciManagement = base.ciManagement;
986                 this.build = base.build;
987                 this.profiles = base.profiles;
988                 this.locations = base.locations;
989                 this.importedFrom = base.importedFrom;
990             } else {
991                 this.base = base;
992             }
993         }
994 
995         @Nonnull
996         public Builder namespaceUri(String namespaceUri) {
997             this.namespaceUri = namespaceUri;
998             return this;
999         }
1000 
1001         @Nonnull
1002         public Builder modelEncoding(String modelEncoding) {
1003             this.modelEncoding = modelEncoding;
1004             return this;
1005         }
1006 
1007         @Deprecated
1008         @Nonnull
1009         public Builder modules(Collection<String> modules) {
1010             this.modules = modules;
1011             return this;
1012         }
1013 
1014         @Nonnull
1015         public Builder subprojects(Collection<String> subprojects) {
1016             this.subprojects = subprojects;
1017             return this;
1018         }
1019 
1020         @Nonnull
1021         public Builder distributionManagement(DistributionManagement distributionManagement) {
1022             this.distributionManagement = distributionManagement;
1023             return this;
1024         }
1025 
1026         @Nonnull
1027         public Builder properties(Map<String, String> properties) {
1028             this.properties = properties;
1029             return this;
1030         }
1031 
1032         @Nonnull
1033         public Builder dependencyManagement(DependencyManagement dependencyManagement) {
1034             this.dependencyManagement = dependencyManagement;
1035             return this;
1036         }
1037 
1038         @Nonnull
1039         public Builder dependencies(Collection<Dependency> dependencies) {
1040             this.dependencies = dependencies;
1041             return this;
1042         }
1043 
1044         @Nonnull
1045         public Builder repositories(Collection<Repository> repositories) {
1046             this.repositories = repositories;
1047             return this;
1048         }
1049 
1050         @Nonnull
1051         public Builder pluginRepositories(Collection<Repository> pluginRepositories) {
1052             this.pluginRepositories = pluginRepositories;
1053             return this;
1054         }
1055 
1056         @Nonnull
1057         public Builder reporting(Reporting reporting) {
1058             this.reporting = reporting;
1059             return this;
1060         }
1061 
1062         @Nonnull
1063         public Builder pomFile(Path pomFile) {
1064             this.pomFile = pomFile;
1065             return this;
1066         }
1067 
1068         @Nonnull
1069         public Builder modelVersion(String modelVersion) {
1070             this.modelVersion = modelVersion;
1071             return this;
1072         }
1073 
1074         @Nonnull
1075         public Builder parent(Parent parent) {
1076             this.parent = parent;
1077             return this;
1078         }
1079 
1080         @Nonnull
1081         public Builder groupId(String groupId) {
1082             this.groupId = groupId;
1083             return this;
1084         }
1085 
1086         @Nonnull
1087         public Builder artifactId(String artifactId) {
1088             this.artifactId = artifactId;
1089             return this;
1090         }
1091 
1092         @Nonnull
1093         public Builder version(String version) {
1094             this.version = version;
1095             return this;
1096         }
1097 
1098         @Nonnull
1099         public Builder packaging(String packaging) {
1100             this.packaging = packaging;
1101             return this;
1102         }
1103 
1104         @Nonnull
1105         public Builder name(String name) {
1106             this.name = name;
1107             return this;
1108         }
1109 
1110         @Nonnull
1111         public Builder description(String description) {
1112             this.description = description;
1113             return this;
1114         }
1115 
1116         @Nonnull
1117         public Builder url(String url) {
1118             this.url = url;
1119             return this;
1120         }
1121 
1122         @Nonnull
1123         public Builder childProjectUrlInheritAppendPath(String childProjectUrlInheritAppendPath) {
1124             this.childProjectUrlInheritAppendPath = childProjectUrlInheritAppendPath;
1125             return this;
1126         }
1127 
1128         @Nonnull
1129         public Builder root(boolean root) {
1130             this.root = root;
1131             return this;
1132         }
1133 
1134         @Nonnull
1135         public Builder preserveModelVersion(boolean preserveModelVersion) {
1136             this.preserveModelVersion = preserveModelVersion;
1137             return this;
1138         }
1139 
1140         @Nonnull
1141         public Builder inceptionYear(String inceptionYear) {
1142             this.inceptionYear = inceptionYear;
1143             return this;
1144         }
1145 
1146         @Nonnull
1147         public Builder organization(Organization organization) {
1148             this.organization = organization;
1149             return this;
1150         }
1151 
1152         @Nonnull
1153         public Builder licenses(Collection<License> licenses) {
1154             this.licenses = licenses;
1155             return this;
1156         }
1157 
1158         @Nonnull
1159         public Builder developers(Collection<Developer> developers) {
1160             this.developers = developers;
1161             return this;
1162         }
1163 
1164         @Nonnull
1165         public Builder contributors(Collection<Contributor> contributors) {
1166             this.contributors = contributors;
1167             return this;
1168         }
1169 
1170         @Nonnull
1171         public Builder mailingLists(Collection<MailingList> mailingLists) {
1172             this.mailingLists = mailingLists;
1173             return this;
1174         }
1175 
1176         @Nonnull
1177         public Builder prerequisites(Prerequisites prerequisites) {
1178             this.prerequisites = prerequisites;
1179             return this;
1180         }
1181 
1182         @Nonnull
1183         public Builder scm(Scm scm) {
1184             this.scm = scm;
1185             return this;
1186         }
1187 
1188         @Nonnull
1189         public Builder issueManagement(IssueManagement issueManagement) {
1190             this.issueManagement = issueManagement;
1191             return this;
1192         }
1193 
1194         @Nonnull
1195         public Builder ciManagement(CiManagement ciManagement) {
1196             this.ciManagement = ciManagement;
1197             return this;
1198         }
1199 
1200         @Nonnull
1201         public Builder build(Build build) {
1202             this.build = build;
1203             return this;
1204         }
1205 
1206         @Nonnull
1207         public Builder profiles(Collection<Profile> profiles) {
1208             this.profiles = profiles;
1209             return this;
1210         }
1211 
1212 
1213         @Nonnull
1214         public Builder location(Object key, InputLocation location) {
1215             if (location != null) {
1216                 if (!(this.locations instanceof HashMap)) {
1217                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
1218                 }
1219                 this.locations.put(key, location);
1220             }
1221             return this;
1222         }
1223 
1224         @Nonnull
1225         public Builder importedFrom(InputLocation importedFrom) {
1226             this.importedFrom = importedFrom;
1227             return this;
1228         }
1229 
1230         @Nonnull
1231         public Model build() {
1232             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
1233             if (base != null
1234                     && (modules == null || modules == base.modules)
1235                     && (subprojects == null || subprojects == base.subprojects)
1236                     && (distributionManagement == null || distributionManagement == base.distributionManagement)
1237                     && (properties == null || properties == base.properties)
1238                     && (dependencyManagement == null || dependencyManagement == base.dependencyManagement)
1239                     && (dependencies == null || dependencies == base.dependencies)
1240                     && (repositories == null || repositories == base.repositories)
1241                     && (pluginRepositories == null || pluginRepositories == base.pluginRepositories)
1242                     && (reporting == null || reporting == base.reporting)
1243                     && (pomFile == null || pomFile == base.pomFile)
1244                     && (modelVersion == null || modelVersion == base.modelVersion)
1245                     && (parent == null || parent == base.parent)
1246                     && (groupId == null || groupId == base.groupId)
1247                     && (artifactId == null || artifactId == base.artifactId)
1248                     && (version == null || version == base.version)
1249                     && (packaging == null || packaging == base.packaging)
1250                     && (name == null || name == base.name)
1251                     && (description == null || description == base.description)
1252                     && (url == null || url == base.url)
1253                     && (childProjectUrlInheritAppendPath == null || childProjectUrlInheritAppendPath == base.childProjectUrlInheritAppendPath)
1254                     && (root == null || root == base.root)
1255                     && (preserveModelVersion == null || preserveModelVersion == base.preserveModelVersion)
1256                     && (inceptionYear == null || inceptionYear == base.inceptionYear)
1257                     && (organization == null || organization == base.organization)
1258                     && (licenses == null || licenses == base.licenses)
1259                     && (developers == null || developers == base.developers)
1260                     && (contributors == null || contributors == base.contributors)
1261                     && (mailingLists == null || mailingLists == base.mailingLists)
1262                     && (prerequisites == null || prerequisites == base.prerequisites)
1263                     && (scm == null || scm == base.scm)
1264                     && (issueManagement == null || issueManagement == base.issueManagement)
1265                     && (ciManagement == null || ciManagement == base.ciManagement)
1266                     && (build == null || build == base.build)
1267                     && (profiles == null || profiles == base.profiles)
1268             ) {
1269                 return base;
1270             }
1271             return new Model(this);
1272         }
1273 
1274     }
1275 
1276 
1277             
1278     /**
1279      * Gets the base directory for the corresponding project (if any).
1280      *
1281      * @return The base directory for the corresponding project or {@code null} if this model does not belong to a local
1282      *         project (e.g. describes the metadata of some artifact from the repository).
1283      */
1284     public Path getProjectDirectory() {
1285         return (pomFile != null) ? pomFile.getParent() : null;
1286     }
1287 
1288     /**
1289      * @return the model id as {@code groupId:artifactId:packaging:version}
1290      */
1291     public String getId()
1292     {
1293         StringBuilder id = new StringBuilder( 64 );
1294 
1295         id.append( ( getGroupId() == null ) ? "[inherited]" : getGroupId() );
1296         id.append( ":" );
1297         id.append( getArtifactId() );
1298         id.append( ":" );
1299         id.append( getPackaging() );
1300         id.append( ":" );
1301         id.append( ( getVersion() == null ) ? "[inherited]" : getVersion() );
1302 
1303         return id.toString();
1304     }
1305 
1306     @Override
1307     public String toString()
1308     {
1309         return getId();
1310     }
1311 
1312     public boolean isChildProjectUrlInheritAppendPath()
1313     {
1314         return ( getChildProjectUrlInheritAppendPath() != null ) ? Boolean.parseBoolean( getChildProjectUrlInheritAppendPath() ) : true;
1315     }
1316 
1317             
1318           
1319 }