View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.project;
20  
21  import java.io.File;
22  import java.io.IOException;
23  import java.io.Writer;
24  import java.util.ArrayList;
25  import java.util.Collections;
26  import java.util.HashMap;
27  import java.util.LinkedHashMap;
28  import java.util.LinkedHashSet;
29  import java.util.List;
30  import java.util.Map;
31  import java.util.Objects;
32  import java.util.Properties;
33  import java.util.Set;
34  import org.apache.maven.RepositoryUtils;
35  import org.apache.maven.artifact.Artifact;
36  import org.apache.maven.artifact.ArtifactUtils;
37  import org.apache.maven.artifact.DependencyResolutionRequiredException;
38  import org.apache.maven.artifact.factory.ArtifactFactory;
39  import org.apache.maven.artifact.repository.ArtifactRepository;
40  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
41  import org.apache.maven.model.Build;
42  import org.apache.maven.model.CiManagement;
43  import org.apache.maven.model.Contributor;
44  import org.apache.maven.model.Dependency;
45  import org.apache.maven.model.DependencyManagement;
46  import org.apache.maven.model.Developer;
47  import org.apache.maven.model.DistributionManagement;
48  import org.apache.maven.model.Extension;
49  import org.apache.maven.model.IssueManagement;
50  import org.apache.maven.model.License;
51  import org.apache.maven.model.MailingList;
52  import org.apache.maven.model.Model;
53  import org.apache.maven.model.Organization;
54  import org.apache.maven.model.Plugin;
55  import org.apache.maven.model.PluginExecution;
56  import org.apache.maven.model.PluginManagement;
57  import org.apache.maven.model.Prerequisites;
58  import org.apache.maven.model.Profile;
59  import org.apache.maven.model.ReportPlugin;
60  import org.apache.maven.model.ReportSet;
61  import org.apache.maven.model.Reporting;
62  import org.apache.maven.model.Repository;
63  import org.apache.maven.model.Resource;
64  import org.apache.maven.model.Scm;
65  import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
66  import org.apache.maven.project.artifact.InvalidDependencyVersionException;
67  import org.apache.maven.project.artifact.MavenMetadataSource;
68  import org.codehaus.plexus.classworlds.realm.ClassRealm;
69  import org.codehaus.plexus.util.xml.Xpp3Dom;
70  import org.eclipse.aether.graph.DependencyFilter;
71  import org.eclipse.aether.repository.RemoteRepository;
72  import org.slf4j.Logger;
73  import org.slf4j.LoggerFactory;
74  
75  /**
76   * The concern of the project is provide runtime values based on the model.
77   * <p>
78   * The values in the model remain untouched but during the process of building a project notions like inheritance and
79   * interpolation can be added. This allows to have an entity which is useful in a runtime while preserving the model so
80   * that it can be marshalled and unmarshalled without being tainted by runtime requirements.
81   * </p>
82   * <p>
83   * With changes during 3.2.2 release MavenProject is closer to being immutable after construction with the removal of
84   * all components from this class, and the upfront construction taken care of entirely by the {@link ProjectBuilder}.
85   * There is still the issue of having to run the lifecycle in order to find all the compile source roots and resource
86   * directories but I hope to take care of this during the Maven 4.0 release (jvz).
87   * </p>
88   */
89  public class MavenProject implements Cloneable {
90  
91      private static final Logger LOGGER = LoggerFactory.getLogger(MavenProject.class);
92  
93      public static final String EMPTY_PROJECT_GROUP_ID = "unknown";
94  
95      public static final String EMPTY_PROJECT_ARTIFACT_ID = "empty-project";
96  
97      public static final String EMPTY_PROJECT_VERSION = "0";
98  
99      private Model model;
100 
101     private MavenProject parent;
102 
103     private File file;
104 
105     private File basedir;
106 
107     private Set<Artifact> resolvedArtifacts;
108 
109     private ArtifactFilter artifactFilter;
110 
111     private Set<Artifact> artifacts;
112 
113     private Artifact parentArtifact;
114 
115     private Set<Artifact> pluginArtifacts;
116 
117     private List<ArtifactRepository> remoteArtifactRepositories;
118 
119     private List<ArtifactRepository> pluginArtifactRepositories;
120 
121     private List<RemoteRepository> remoteProjectRepositories;
122 
123     private List<RemoteRepository> remotePluginRepositories;
124 
125     private List<Artifact> attachedArtifacts = new ArrayList<>();
126 
127     private MavenProject executionProject;
128 
129     private List<MavenProject> collectedProjects;
130 
131     private List<String> compileSourceRoots = new ArrayList<>();
132 
133     private List<String> testCompileSourceRoots = new ArrayList<>();
134 
135     private List<String> scriptSourceRoots = new ArrayList<>();
136 
137     private ArtifactRepository releaseArtifactRepository;
138 
139     private ArtifactRepository snapshotArtifactRepository;
140 
141     private List<Profile> activeProfiles = new ArrayList<>();
142 
143     private Map<String, List<String>> injectedProfileIds = new LinkedHashMap<>();
144 
145     private Set<Artifact> dependencyArtifacts;
146 
147     private Artifact artifact;
148 
149     // calculated.
150     private Map<String, Artifact> artifactMap;
151 
152     private Model originalModel;
153 
154     private Map<String, Artifact> pluginArtifactMap;
155 
156     private Set<Artifact> reportArtifacts;
157 
158     private Map<String, Artifact> reportArtifactMap;
159 
160     private Set<Artifact> extensionArtifacts;
161 
162     private Map<String, Artifact> extensionArtifactMap;
163 
164     private Map<String, Artifact> managedVersionMap;
165 
166     private Map<String, MavenProject> projectReferences = new HashMap<>();
167 
168     private boolean executionRoot;
169 
170     private File parentFile;
171 
172     private Map<String, Object> context;
173 
174     private ClassRealm classRealm;
175 
176     private DependencyFilter extensionDependencyFilter;
177 
178     private final Set<String> lifecyclePhases = Collections.synchronizedSet(new LinkedHashSet<>());
179 
180     public MavenProject() {
181         Model model = new Model();
182 
183         model.setGroupId(EMPTY_PROJECT_GROUP_ID);
184         model.setArtifactId(EMPTY_PROJECT_ARTIFACT_ID);
185         model.setVersion(EMPTY_PROJECT_VERSION);
186 
187         setModel(model);
188     }
189 
190     public MavenProject(org.apache.maven.api.model.Model model) {
191         this(new Model(model));
192     }
193 
194     public MavenProject(Model model) {
195         setModel(model);
196     }
197 
198     public MavenProject(MavenProject project) {
199         deepCopy(project);
200     }
201 
202     public File getParentFile() {
203         return parentFile;
204     }
205 
206     public void setParentFile(File parentFile) {
207         this.parentFile = parentFile;
208     }
209 
210     // ----------------------------------------------------------------------
211     // Accessors
212     // ----------------------------------------------------------------------
213 
214     public Artifact getArtifact() {
215         return artifact;
216     }
217 
218     public void setArtifact(Artifact artifact) {
219         this.artifact = artifact;
220     }
221 
222     // TODO I would like to get rid of this. jvz.
223     public Model getModel() {
224         return model;
225     }
226 
227     /**
228      * Returns the project corresponding to a declared parent.
229      *
230      * @return the parent, or null if no parent is declared or there was an error building it
231      */
232     public MavenProject getParent() {
233         return parent;
234     }
235 
236     public void setParent(MavenProject parent) {
237         this.parent = parent;
238     }
239 
240     public boolean hasParent() {
241         return getParent() != null;
242     }
243 
244     public File getFile() {
245         return file;
246     }
247 
248     public void setFile(File file) {
249         this.file = file;
250         this.basedir = file != null ? file.getParentFile() : null;
251     }
252 
253     /**
254      * Sets project {@code file} without changing project {@code basedir}.
255      *
256      * @since 3.2.4
257      */
258     public void setPomFile(File file) {
259         this.file = file;
260     }
261 
262     public File getBasedir() {
263         return basedir;
264     }
265 
266     public void setDependencies(List<Dependency> dependencies) {
267         getModel().setDependencies(dependencies);
268     }
269 
270     public List<Dependency> getDependencies() {
271         return getModel().getDependencies();
272     }
273 
274     public DependencyManagement getDependencyManagement() {
275         return getModel().getDependencyManagement();
276     }
277 
278     // ----------------------------------------------------------------------
279     // Test and compile source roots.
280     // ----------------------------------------------------------------------
281 
282     private void addPath(List<String> paths, String path) {
283         if (path != null) {
284             path = path.trim();
285             if (path.length() > 0) {
286                 File file = new File(path);
287                 if (file.isAbsolute()) {
288                     path = file.getAbsolutePath();
289                 } else if (".".equals(path)) {
290                     path = getBasedir().getAbsolutePath();
291                 } else {
292                     path = new File(getBasedir(), path).getAbsolutePath();
293                 }
294 
295                 if (!paths.contains(path)) {
296                     paths.add(path);
297                 }
298             }
299         }
300     }
301 
302     public void addCompileSourceRoot(String path) {
303         addPath(getCompileSourceRoots(), path);
304     }
305 
306     public void addTestCompileSourceRoot(String path) {
307         addPath(getTestCompileSourceRoots(), path);
308     }
309 
310     public List<String> getCompileSourceRoots() {
311         return compileSourceRoots;
312     }
313 
314     public List<String> getTestCompileSourceRoots() {
315         return testCompileSourceRoots;
316     }
317 
318     public List<String> getCompileClasspathElements() throws DependencyResolutionRequiredException {
319         List<String> list = new ArrayList<>(getArtifacts().size() + 1);
320 
321         String d = getBuild().getOutputDirectory();
322         if (d != null) {
323             list.add(d);
324         }
325 
326         for (Artifact a : getArtifacts()) {
327             if (a.getArtifactHandler().isAddedToClasspath()) {
328                 // TODO let the scope handler deal with this
329                 if (Artifact.SCOPE_COMPILE.equals(a.getScope())
330                         || Artifact.SCOPE_PROVIDED.equals(a.getScope())
331                         || Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
332                     addArtifactPath(a, list);
333                 }
334             }
335         }
336 
337         return list;
338     }
339 
340     // TODO this checking for file == null happens because the resolver has been confused about the root
341     // artifact or not. things like the stupid dummy artifact coming from surefire.
342     public List<String> getTestClasspathElements() throws DependencyResolutionRequiredException {
343         List<String> list = new ArrayList<>(getArtifacts().size() + 2);
344 
345         String d = getBuild().getTestOutputDirectory();
346         if (d != null) {
347             list.add(d);
348         }
349 
350         d = getBuild().getOutputDirectory();
351         if (d != null) {
352             list.add(d);
353         }
354 
355         for (Artifact a : getArtifacts()) {
356             if (a.getArtifactHandler().isAddedToClasspath()) {
357                 addArtifactPath(a, list);
358             }
359         }
360 
361         return list;
362     }
363 
364     public List<String> getRuntimeClasspathElements() throws DependencyResolutionRequiredException {
365         List<String> list = new ArrayList<>(getArtifacts().size() + 1);
366 
367         String d = getBuild().getOutputDirectory();
368         if (d != null) {
369             list.add(d);
370         }
371 
372         for (Artifact a : getArtifacts()) {
373             if (a.getArtifactHandler().isAddedToClasspath()
374                     // TODO let the scope handler deal with this
375                     && (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope()))) {
376                 addArtifactPath(a, list);
377             }
378         }
379         return list;
380     }
381 
382     // ----------------------------------------------------------------------
383     // Delegate to the model
384     // ----------------------------------------------------------------------
385 
386     public void setModelVersion(String pomVersion) {
387         getModel().setModelVersion(pomVersion);
388     }
389 
390     public String getModelVersion() {
391         return getModel().getModelVersion();
392     }
393 
394     public String getId() {
395         return getModel().getId();
396     }
397 
398     public void setGroupId(String groupId) {
399         getModel().setGroupId(groupId);
400     }
401 
402     public String getGroupId() {
403         String groupId = getModel().getGroupId();
404 
405         if ((groupId == null) && (getModel().getParent() != null)) {
406             groupId = getModel().getParent().getGroupId();
407         }
408 
409         return groupId;
410     }
411 
412     public void setArtifactId(String artifactId) {
413         getModel().setArtifactId(artifactId);
414     }
415 
416     public String getArtifactId() {
417         return getModel().getArtifactId();
418     }
419 
420     public void setName(String name) {
421         getModel().setName(name);
422     }
423 
424     public String getName() {
425         // TODO this should not be allowed to be null.
426         if (getModel().getName() != null) {
427             return getModel().getName();
428         } else {
429             return getArtifactId();
430         }
431     }
432 
433     public void setVersion(String version) {
434         getModel().setVersion(version);
435     }
436 
437     public String getVersion() {
438         String version = getModel().getVersion();
439 
440         if ((version == null) && (getModel().getParent() != null)) {
441             version = getModel().getParent().getVersion();
442         }
443 
444         return version;
445     }
446 
447     public String getPackaging() {
448         return getModel().getPackaging();
449     }
450 
451     public void setPackaging(String packaging) {
452         getModel().setPackaging(packaging);
453     }
454 
455     public void setInceptionYear(String inceptionYear) {
456         getModel().setInceptionYear(inceptionYear);
457     }
458 
459     public String getInceptionYear() {
460         return getModel().getInceptionYear();
461     }
462 
463     public void setUrl(String url) {
464         getModel().setUrl(url);
465     }
466 
467     public String getUrl() {
468         return getModel().getUrl();
469     }
470 
471     public Prerequisites getPrerequisites() {
472         return getModel().getPrerequisites();
473     }
474 
475     public void setIssueManagement(IssueManagement issueManagement) {
476         getModel().setIssueManagement(issueManagement);
477     }
478 
479     public CiManagement getCiManagement() {
480         return getModel().getCiManagement();
481     }
482 
483     public void setCiManagement(CiManagement ciManagement) {
484         getModel().setCiManagement(ciManagement);
485     }
486 
487     public IssueManagement getIssueManagement() {
488         return getModel().getIssueManagement();
489     }
490 
491     public void setDistributionManagement(DistributionManagement distributionManagement) {
492         getModel().setDistributionManagement(distributionManagement);
493     }
494 
495     public DistributionManagement getDistributionManagement() {
496         return getModel().getDistributionManagement();
497     }
498 
499     public void setDescription(String description) {
500         getModel().setDescription(description);
501     }
502 
503     public String getDescription() {
504         return getModel().getDescription();
505     }
506 
507     public void setOrganization(Organization organization) {
508         getModel().setOrganization(organization);
509     }
510 
511     public Organization getOrganization() {
512         return getModel().getOrganization();
513     }
514 
515     public void setScm(Scm scm) {
516         getModel().setScm(scm);
517     }
518 
519     public Scm getScm() {
520         return getModel().getScm();
521     }
522 
523     public void setMailingLists(List<MailingList> mailingLists) {
524         getModel().setMailingLists(mailingLists);
525     }
526 
527     public List<MailingList> getMailingLists() {
528         return getModel().getMailingLists();
529     }
530 
531     public void addMailingList(MailingList mailingList) {
532         getModel().addMailingList(mailingList);
533     }
534 
535     public void setDevelopers(List<Developer> developers) {
536         getModel().setDevelopers(developers);
537     }
538 
539     public List<Developer> getDevelopers() {
540         return getModel().getDevelopers();
541     }
542 
543     public void addDeveloper(Developer developer) {
544         getModel().addDeveloper(developer);
545     }
546 
547     public void setContributors(List<Contributor> contributors) {
548         getModel().setContributors(contributors);
549     }
550 
551     public List<Contributor> getContributors() {
552         return getModel().getContributors();
553     }
554 
555     public void addContributor(Contributor contributor) {
556         getModel().addContributor(contributor);
557     }
558 
559     public void setBuild(Build build) {
560         getModel().setBuild(build);
561     }
562 
563     public Build getBuild() {
564         return getModelBuild();
565     }
566 
567     public List<Resource> getResources() {
568         return getBuild().getResources();
569     }
570 
571     public List<Resource> getTestResources() {
572         return getBuild().getTestResources();
573     }
574 
575     public void addResource(Resource resource) {
576         getBuild().addResource(resource);
577     }
578 
579     public void addTestResource(Resource testResource) {
580         getBuild().addTestResource(testResource);
581     }
582 
583     public void setLicenses(List<License> licenses) {
584         getModel().setLicenses(licenses);
585     }
586 
587     public List<License> getLicenses() {
588         return getModel().getLicenses();
589     }
590 
591     public void addLicense(License license) {
592         getModel().addLicense(license);
593     }
594 
595     public void setArtifacts(Set<Artifact> artifacts) {
596         this.artifacts = artifacts;
597 
598         // flush the calculated artifactMap
599         artifactMap = null;
600     }
601 
602     /**
603      * All dependencies that this project has, including transitive ones. Contents are lazily populated, so depending on
604      * what phases have run dependencies in some scopes won't be included. e.g. if only compile phase has run,
605      * dependencies with scope test won't be included.
606      *
607      * @return {@link Set} &lt; {@link Artifact} &gt;
608      * @see #getDependencyArtifacts() to get only direct dependencies
609      */
610     public Set<Artifact> getArtifacts() {
611         if (artifacts == null) {
612             if (artifactFilter == null || resolvedArtifacts == null) {
613                 artifacts = new LinkedHashSet<>();
614             } else {
615                 artifacts = new LinkedHashSet<>(resolvedArtifacts.size() * 2);
616                 for (Artifact artifact : resolvedArtifacts) {
617                     if (artifactFilter.include(artifact)) {
618                         artifacts.add(artifact);
619                     }
620                 }
621             }
622         }
623         return artifacts;
624     }
625 
626     public Map<String, Artifact> getArtifactMap() {
627         if (artifactMap == null) {
628             artifactMap = ArtifactUtils.artifactMapByVersionlessId(getArtifacts());
629         }
630         return artifactMap;
631     }
632 
633     public void setPluginArtifacts(Set<Artifact> pluginArtifacts) {
634         this.pluginArtifacts = pluginArtifacts;
635 
636         this.pluginArtifactMap = null;
637     }
638 
639     public Set<Artifact> getPluginArtifacts() {
640         return pluginArtifacts;
641     }
642 
643     public Map<String, Artifact> getPluginArtifactMap() {
644         if (pluginArtifactMap == null) {
645             pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId(getPluginArtifacts());
646         }
647 
648         return pluginArtifactMap;
649     }
650 
651     public void setParentArtifact(Artifact parentArtifact) {
652         this.parentArtifact = parentArtifact;
653     }
654 
655     public Artifact getParentArtifact() {
656         return parentArtifact;
657     }
658 
659     public List<Repository> getRepositories() {
660         return getModel().getRepositories();
661     }
662 
663     // ----------------------------------------------------------------------
664     // Plugins
665     // ----------------------------------------------------------------------
666 
667     public List<Plugin> getBuildPlugins() {
668         if (getModel().getBuild() == null) {
669             return Collections.emptyList();
670         }
671         return Collections.unmodifiableList(getModel().getBuild().getPlugins());
672     }
673 
674     public List<String> getModules() {
675         return getModel().getModules();
676     }
677 
678     public PluginManagement getPluginManagement() {
679         PluginManagement pluginMgmt = null;
680 
681         Build build = getModel().getBuild();
682         if (build != null) {
683             pluginMgmt = build.getPluginManagement();
684         }
685 
686         return pluginMgmt;
687     }
688 
689     private Build getModelBuild() {
690         Build build = getModel().getBuild();
691 
692         if (build == null) {
693             build = new Build();
694 
695             getModel().setBuild(build);
696         }
697 
698         return build;
699     }
700 
701     public void setRemoteArtifactRepositories(List<ArtifactRepository> remoteArtifactRepositories) {
702         this.remoteArtifactRepositories = remoteArtifactRepositories;
703         this.remoteProjectRepositories = RepositoryUtils.toRepos(getRemoteArtifactRepositories());
704     }
705 
706     public List<ArtifactRepository> getRemoteArtifactRepositories() {
707         if (remoteArtifactRepositories == null) {
708             remoteArtifactRepositories = new ArrayList<>();
709         }
710 
711         return remoteArtifactRepositories;
712     }
713 
714     public void setPluginArtifactRepositories(List<ArtifactRepository> pluginArtifactRepositories) {
715         this.pluginArtifactRepositories = pluginArtifactRepositories;
716         this.remotePluginRepositories = RepositoryUtils.toRepos(getPluginArtifactRepositories());
717     }
718 
719     /**
720      * @return a list of ArtifactRepository objects constructed from the Repository objects returned by
721      *         getPluginRepositories.
722      */
723     public List<ArtifactRepository> getPluginArtifactRepositories() {
724         if (pluginArtifactRepositories == null) {
725             pluginArtifactRepositories = new ArrayList<>();
726         }
727 
728         return pluginArtifactRepositories;
729     }
730 
731     public ArtifactRepository getDistributionManagementArtifactRepository() {
732         return getArtifact().isSnapshot() && (getSnapshotArtifactRepository() != null)
733                 ? getSnapshotArtifactRepository()
734                 : getReleaseArtifactRepository();
735     }
736 
737     public List<Repository> getPluginRepositories() {
738         return getModel().getPluginRepositories();
739     }
740 
741     public List<RemoteRepository> getRemoteProjectRepositories() {
742         return remoteProjectRepositories;
743     }
744 
745     public List<RemoteRepository> getRemotePluginRepositories() {
746         return remotePluginRepositories;
747     }
748 
749     public void setActiveProfiles(List<Profile> activeProfiles) {
750         this.activeProfiles = activeProfiles;
751     }
752 
753     public List<Profile> getActiveProfiles() {
754         return activeProfiles;
755     }
756 
757     public void setInjectedProfileIds(String source, List<String> injectedProfileIds) {
758         if (injectedProfileIds != null) {
759             this.injectedProfileIds.put(source, new ArrayList<>(injectedProfileIds));
760         } else {
761             this.injectedProfileIds.remove(source);
762         }
763     }
764 
765     /**
766      * Gets the identifiers of all profiles that contributed to this project's effective model. This includes active
767      * profiles from the project's POM and all its parent POMs as well as from external sources like the
768      * {@code settings.xml}. The profile identifiers are grouped by the identifier of their source, e.g.
769      * {@code <groupId>:<artifactId>:<version>} for a POM profile or {@code external} for profiles from the
770      * {@code settings.xml}.
771      *
772      * @return The identifiers of all injected profiles, indexed by the source from which the profiles originated, never
773      *         {@code null}.
774      */
775     public Map<String, List<String>> getInjectedProfileIds() {
776         return this.injectedProfileIds;
777     }
778 
779     /**
780      * Add or replace an artifact. This method is now deprecated. Use the @{MavenProjectHelper} to attach artifacts to a
781      * project. In spite of the 'throws' declaration on this API, this method has never thrown an exception since Maven
782      * 3.0.x. Historically, it logged and ignored a second addition of the same g/a/v/c/t. Now it replaces the file for
783      * the artifact, so that plugins (e.g. shade) can change the pathname of the file for a particular set of
784      * coordinates.
785      *
786      * @param artifact the artifact to add or replace.
787      * @deprecated Please use {@link MavenProjectHelper}
788      * @throws DuplicateArtifactAttachmentException will never happen but leave it for backward compatibility
789      */
790     public void addAttachedArtifact(Artifact artifact) throws DuplicateArtifactAttachmentException {
791         // if already there we remove it and add again
792         int index = attachedArtifacts.indexOf(artifact);
793         if (index >= 0) {
794             LOGGER.warn("artifact '{}' already attached, replacing previous instance", artifact);
795             attachedArtifacts.set(index, artifact);
796         } else {
797             attachedArtifacts.add(artifact);
798         }
799     }
800 
801     public List<Artifact> getAttachedArtifacts() {
802         if (attachedArtifacts == null) {
803             attachedArtifacts = new ArrayList<>();
804         }
805         return Collections.unmodifiableList(attachedArtifacts);
806     }
807 
808     public Xpp3Dom getGoalConfiguration(
809             String pluginGroupId, String pluginArtifactId, String executionId, String goalId) {
810         Xpp3Dom dom = null;
811 
812         if (getBuildPlugins() != null) {
813             for (Plugin plugin : getBuildPlugins()) {
814                 if (pluginGroupId.equals(plugin.getGroupId()) && pluginArtifactId.equals(plugin.getArtifactId())) {
815                     dom = (Xpp3Dom) plugin.getConfiguration();
816 
817                     if (executionId != null) {
818                         for (PluginExecution execution : plugin.getExecutions()) {
819                             if (executionId.equals(execution.getId())) {
820                                 // NOTE: The PluginConfigurationExpander already merged the plugin-level config in
821                                 dom = (Xpp3Dom) execution.getConfiguration();
822                                 break;
823                             }
824                         }
825                     }
826                     break;
827                 }
828             }
829         }
830 
831         if (dom != null) {
832             // make a copy so the original in the POM doesn't get messed with
833             dom = new Xpp3Dom(dom);
834         }
835 
836         return dom;
837     }
838 
839     public MavenProject getExecutionProject() {
840         return (executionProject == null ? this : executionProject);
841     }
842 
843     public void setExecutionProject(MavenProject executionProject) {
844         this.executionProject = executionProject;
845     }
846 
847     public List<MavenProject> getCollectedProjects() {
848         return collectedProjects;
849     }
850 
851     public void setCollectedProjects(List<MavenProject> collectedProjects) {
852         this.collectedProjects = collectedProjects;
853     }
854 
855     /**
856      * Direct dependencies that this project has.
857      *
858      * @return {@link Set} &lt; {@link Artifact} &gt;
859      * @see #getArtifacts() to get all transitive dependencies
860      */
861     @Deprecated
862     public Set<Artifact> getDependencyArtifacts() {
863         return dependencyArtifacts;
864     }
865 
866     @Deprecated
867     public void setDependencyArtifacts(Set<Artifact> dependencyArtifacts) {
868         this.dependencyArtifacts = dependencyArtifacts;
869     }
870 
871     public void setReleaseArtifactRepository(ArtifactRepository releaseArtifactRepository) {
872         this.releaseArtifactRepository = releaseArtifactRepository;
873     }
874 
875     public void setSnapshotArtifactRepository(ArtifactRepository snapshotArtifactRepository) {
876         this.snapshotArtifactRepository = snapshotArtifactRepository;
877     }
878 
879     public void setOriginalModel(Model originalModel) {
880         this.originalModel = originalModel;
881     }
882 
883     public Model getOriginalModel() {
884         return originalModel;
885     }
886 
887     public void setManagedVersionMap(Map<String, Artifact> map) {
888         managedVersionMap = map;
889     }
890 
891     public Map<String, Artifact> getManagedVersionMap() {
892         return managedVersionMap;
893     }
894 
895     @Override
896     public boolean equals(Object other) {
897         if (other == this) {
898             return true;
899         } else if (!(other instanceof MavenProject)) {
900             return false;
901         }
902 
903         MavenProject that = (MavenProject) other;
904 
905         return Objects.equals(getArtifactId(), that.getArtifactId())
906                 && Objects.equals(getGroupId(), that.getGroupId())
907                 && Objects.equals(getVersion(), that.getVersion());
908     }
909 
910     @Override
911     public int hashCode() {
912         int hash = 17;
913         hash = 31 * hash + getGroupId().hashCode();
914         hash = 31 * hash + getArtifactId().hashCode();
915         hash = 31 * hash + getVersion().hashCode();
916         return hash;
917     }
918 
919     public List<Extension> getBuildExtensions() {
920         Build build = getBuild();
921         if ((build == null) || (build.getExtensions() == null)) {
922             return Collections.emptyList();
923         } else {
924             return Collections.unmodifiableList(build.getExtensions());
925         }
926     }
927 
928     public void addProjectReference(MavenProject project) {
929         projectReferences.put(
930                 getProjectReferenceId(project.getGroupId(), project.getArtifactId(), project.getVersion()), project);
931     }
932 
933     public Properties getProperties() {
934         return getModel().getProperties();
935     }
936 
937     public List<String> getFilters() {
938         return getBuild().getFilters();
939     }
940 
941     public Map<String, MavenProject> getProjectReferences() {
942         return projectReferences;
943     }
944 
945     public boolean isExecutionRoot() {
946         return executionRoot;
947     }
948 
949     public void setExecutionRoot(boolean executionRoot) {
950         this.executionRoot = executionRoot;
951     }
952 
953     public String getDefaultGoal() {
954         return getBuild() != null ? getBuild().getDefaultGoal() : null;
955     }
956 
957     public Plugin getPlugin(String pluginKey) {
958         return getBuild().getPluginsAsMap().get(pluginKey);
959     }
960 
961     /**
962      * Default toString
963      */
964     @Override
965     public String toString() {
966         StringBuilder sb = new StringBuilder(128);
967         sb.append("MavenProject: ");
968         sb.append(getGroupId());
969         sb.append(':');
970         sb.append(getArtifactId());
971         sb.append(':');
972         sb.append(getVersion());
973         if (getFile() != null) {
974             sb.append(" @ ");
975             sb.append(getFile().getPath());
976         }
977 
978         return sb.toString();
979     }
980 
981     /**
982      * @since 2.0.9
983      */
984     @Override
985     public MavenProject clone() {
986         MavenProject clone;
987         try {
988             clone = (MavenProject) super.clone();
989         } catch (CloneNotSupportedException e) {
990             throw new UnsupportedOperationException(e);
991         }
992 
993         clone.deepCopy(this);
994 
995         return clone;
996     }
997 
998     public void setModel(Model model) {
999         this.model = model;
1000     }
1001 
1002     protected void setAttachedArtifacts(List<Artifact> attachedArtifacts) {
1003         this.attachedArtifacts = attachedArtifacts;
1004     }
1005 
1006     protected void setCompileSourceRoots(List<String> compileSourceRoots) {
1007         this.compileSourceRoots = compileSourceRoots;
1008     }
1009 
1010     protected void setTestCompileSourceRoots(List<String> testCompileSourceRoots) {
1011         this.testCompileSourceRoots = testCompileSourceRoots;
1012     }
1013 
1014     protected ArtifactRepository getReleaseArtifactRepository() {
1015         return releaseArtifactRepository;
1016     }
1017 
1018     protected ArtifactRepository getSnapshotArtifactRepository() {
1019         return snapshotArtifactRepository;
1020     }
1021 
1022     private void deepCopy(MavenProject project) {
1023         // disown the parent
1024 
1025         // copy fields
1026         file = project.file;
1027         basedir = project.basedir;
1028 
1029         // don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be
1030         // sure!
1031         if (project.getDependencyArtifacts() != null) {
1032             setDependencyArtifacts(Collections.unmodifiableSet(project.getDependencyArtifacts()));
1033         }
1034 
1035         if (project.getArtifacts() != null) {
1036             setArtifacts(Collections.unmodifiableSet(project.getArtifacts()));
1037         }
1038 
1039         if (project.getParentFile() != null) {
1040             parentFile = new File(project.getParentFile().getAbsolutePath());
1041         }
1042 
1043         if (project.getPluginArtifacts() != null) {
1044             setPluginArtifacts(Collections.unmodifiableSet(project.getPluginArtifacts()));
1045         }
1046 
1047         if (project.getReportArtifacts() != null) {
1048             setReportArtifacts(Collections.unmodifiableSet(project.getReportArtifacts()));
1049         }
1050 
1051         if (project.getExtensionArtifacts() != null) {
1052             setExtensionArtifacts(Collections.unmodifiableSet(project.getExtensionArtifacts()));
1053         }
1054 
1055         setParentArtifact((project.getParentArtifact()));
1056 
1057         if (project.getRemoteArtifactRepositories() != null) {
1058             setRemoteArtifactRepositories(Collections.unmodifiableList(project.getRemoteArtifactRepositories()));
1059         }
1060 
1061         if (project.getPluginArtifactRepositories() != null) {
1062             setPluginArtifactRepositories(Collections.unmodifiableList(project.getPluginArtifactRepositories()));
1063         }
1064 
1065         if (project.getActiveProfiles() != null) {
1066             setActiveProfiles((Collections.unmodifiableList(project.getActiveProfiles())));
1067         }
1068 
1069         if (project.getAttachedArtifacts() != null) {
1070             // clone properties modifiable by plugins in a forked lifecycle
1071             setAttachedArtifacts(new ArrayList<>(project.getAttachedArtifacts()));
1072         }
1073 
1074         if (project.getCompileSourceRoots() != null) {
1075             // clone source roots
1076             setCompileSourceRoots((new ArrayList<>(project.getCompileSourceRoots())));
1077         }
1078 
1079         if (project.getTestCompileSourceRoots() != null) {
1080             setTestCompileSourceRoots((new ArrayList<>(project.getTestCompileSourceRoots())));
1081         }
1082 
1083         if (project.getScriptSourceRoots() != null) {
1084             setScriptSourceRoots((new ArrayList<>(project.getScriptSourceRoots())));
1085         }
1086 
1087         if (project.getModel() != null) {
1088             setModel(project.getModel().clone());
1089         }
1090 
1091         if (project.getOriginalModel() != null) {
1092             setOriginalModel(project.getOriginalModel());
1093         }
1094 
1095         setExecutionRoot(project.isExecutionRoot());
1096 
1097         if (project.getArtifact() != null) {
1098             setArtifact(ArtifactUtils.copyArtifact(project.getArtifact()));
1099         }
1100 
1101         if (project.getManagedVersionMap() != null) {
1102             setManagedVersionMap(project.getManagedVersionMap());
1103         }
1104 
1105         lifecyclePhases.addAll(project.lifecyclePhases);
1106     }
1107 
1108     private void addArtifactPath(Artifact artifact, List<String> classpath) {
1109         File file = artifact.getFile();
1110         if (file != null) {
1111             classpath.add(file.getPath());
1112         }
1113     }
1114 
1115     private static String getProjectReferenceId(String groupId, String artifactId, String version) {
1116         StringBuilder buffer = new StringBuilder(128);
1117         buffer.append(groupId).append(':').append(artifactId).append(':').append(version);
1118         return buffer.toString();
1119     }
1120 
1121     /**
1122      * Sets the value of the context value of this project identified by the given key. If the supplied value is
1123      * <code>null</code>, the context value is removed from this project. Context values are intended to allow core
1124      * extensions to associate derived state with project instances.
1125      */
1126     public void setContextValue(String key, Object value) {
1127         if (context == null) {
1128             context = new HashMap<>();
1129         }
1130         if (value != null) {
1131             context.put(key, value);
1132         } else {
1133             context.remove(key);
1134         }
1135     }
1136 
1137     /**
1138      * Returns context value of this project associated with the given key or null if this project has no such value.
1139      */
1140     public Object getContextValue(String key) {
1141         if (context == null) {
1142             return null;
1143         }
1144         return context.get(key);
1145     }
1146 
1147     /**
1148      * Sets the project's class realm. <strong>Warning:</strong> This is an internal utility method that is only public
1149      * for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted
1150      * without prior notice and must not be used by plugins.
1151      *
1152      * @param classRealm The class realm hosting the build extensions of this project, may be {@code null}.
1153      */
1154     public void setClassRealm(ClassRealm classRealm) {
1155         this.classRealm = classRealm;
1156     }
1157 
1158     /**
1159      * Gets the project's class realm. This class realm hosts the build extensions of the project.
1160      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1161      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1162      * used by plugins.
1163      *
1164      * @return The project's class realm or {@code null}.
1165      */
1166     public ClassRealm getClassRealm() {
1167         return classRealm;
1168     }
1169 
1170     /**
1171      * Sets the artifact filter used to exclude shared extension artifacts from plugin realms. <strong>Warning:</strong>
1172      * This is an internal utility method that is only public for technical reasons, it is not part of the public API.
1173      * In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
1174      *
1175      * @param extensionDependencyFilter The dependency filter to apply to plugins, may be {@code null}.
1176      */
1177     public void setExtensionDependencyFilter(DependencyFilter extensionDependencyFilter) {
1178         this.extensionDependencyFilter = extensionDependencyFilter;
1179     }
1180 
1181     /**
1182      * Gets the dependency filter used to exclude shared extension artifacts from plugin realms.
1183      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1184      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1185      * used by plugins.
1186      *
1187      * @return The dependency filter or {@code null}.
1188      */
1189     public DependencyFilter getExtensionDependencyFilter() {
1190         return extensionDependencyFilter;
1191     }
1192 
1193     /**
1194      * Sets the transitive dependency artifacts that have been resolved/collected for this project.
1195      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1196      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1197      * used by plugins.
1198      *
1199      * @param artifacts The set of artifacts, may be {@code null}.
1200      */
1201     public void setResolvedArtifacts(Set<Artifact> artifacts) {
1202         this.resolvedArtifacts = (artifacts != null) ? artifacts : Collections.<Artifact>emptySet();
1203         this.artifacts = null;
1204         this.artifactMap = null;
1205     }
1206 
1207     /**
1208      * Sets the scope filter to select the artifacts being exposed to the currently executed mojo.
1209      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1210      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1211      * used by plugins.
1212      *
1213      * @param artifactFilter The artifact filter, may be {@code null} to exclude all artifacts.
1214      */
1215     public void setArtifactFilter(ArtifactFilter artifactFilter) {
1216         this.artifactFilter = artifactFilter;
1217         this.artifacts = null;
1218         this.artifactMap = null;
1219     }
1220 
1221     /**
1222      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1223      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1224      * used by plugins.
1225      *
1226      * @param phase The phase to check for, must not be {@code null}.
1227      * @return {@code true} if the phase has been seen.
1228      */
1229     public boolean hasLifecyclePhase(String phase) {
1230         return lifecyclePhases.contains(phase);
1231     }
1232 
1233     /**
1234      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1235      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1236      * used by plugins.
1237      *
1238      * @param lifecyclePhase The lifecycle phase to add, must not be {@code null}.
1239      */
1240     public void addLifecyclePhase(String lifecyclePhase) {
1241         lifecyclePhases.add(lifecyclePhase);
1242     }
1243 
1244     // ----------------------------------------------------------------------------------------------------------------
1245     //
1246     //
1247     // D E P R E C A T E D
1248     //
1249     //
1250     // ----------------------------------------------------------------------------------------------------------------
1251     //
1252     // Everything below will be removed for Maven 4.0.0
1253     //
1254     // ----------------------------------------------------------------------------------------------------------------
1255 
1256     private ProjectBuildingRequest projectBuilderConfiguration;
1257 
1258     private Map<String, String> moduleAdjustments;
1259 
1260     @Deprecated // This appears only to be used in test code
1261     public String getModulePathAdjustment(MavenProject moduleProject) throws IOException {
1262         // FIXME: This is hacky. What if module directory doesn't match artifactid, and parent
1263         // is coming from the repository??
1264         String module = moduleProject.getArtifactId();
1265 
1266         File moduleFile = moduleProject.getFile();
1267 
1268         if (moduleFile != null) {
1269             File moduleDir = moduleFile.getCanonicalFile().getParentFile();
1270 
1271             module = moduleDir.getName();
1272         }
1273 
1274         if (moduleAdjustments == null) {
1275             moduleAdjustments = new HashMap<>();
1276 
1277             List<String> modules = getModules();
1278             if (modules != null) {
1279                 for (String modulePath : modules) {
1280                     String moduleName = modulePath;
1281 
1282                     if (moduleName.endsWith("/") || moduleName.endsWith("\\")) {
1283                         moduleName = moduleName.substring(0, moduleName.length() - 1);
1284                     }
1285 
1286                     int lastSlash = moduleName.lastIndexOf('/');
1287 
1288                     if (lastSlash < 0) {
1289                         lastSlash = moduleName.lastIndexOf('\\');
1290                     }
1291 
1292                     String adjustment = null;
1293 
1294                     if (lastSlash > -1) {
1295                         moduleName = moduleName.substring(lastSlash + 1);
1296                         adjustment = modulePath.substring(0, lastSlash);
1297                     }
1298 
1299                     moduleAdjustments.put(moduleName, adjustment);
1300                 }
1301             }
1302         }
1303 
1304         return moduleAdjustments.get(module);
1305     }
1306 
1307     @Deprecated
1308     public Set<Artifact> createArtifacts(ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter)
1309             throws InvalidDependencyVersionException {
1310         return MavenMetadataSource.createArtifacts(
1311                 artifactFactory, getModel().getDependencies(), inheritedScope, filter, this);
1312     }
1313 
1314     @Deprecated
1315     protected void setScriptSourceRoots(List<String> scriptSourceRoots) {
1316         this.scriptSourceRoots = scriptSourceRoots;
1317     }
1318 
1319     @Deprecated
1320     public void addScriptSourceRoot(String path) {
1321         if (path != null) {
1322             path = path.trim();
1323             if (path.length() != 0) {
1324                 if (!getScriptSourceRoots().contains(path)) {
1325                     getScriptSourceRoots().add(path);
1326                 }
1327             }
1328         }
1329     }
1330 
1331     @Deprecated
1332     public List<String> getScriptSourceRoots() {
1333         return scriptSourceRoots;
1334     }
1335 
1336     @Deprecated
1337     public List<Artifact> getCompileArtifacts() {
1338         List<Artifact> list = new ArrayList<>(getArtifacts().size());
1339 
1340         for (Artifact a : getArtifacts()) {
1341             // TODO classpath check doesn't belong here - that's the other method
1342             if (a.getArtifactHandler().isAddedToClasspath()) {
1343                 // TODO let the scope handler deal with this
1344                 if (Artifact.SCOPE_COMPILE.equals(a.getScope())
1345                         || Artifact.SCOPE_PROVIDED.equals(a.getScope())
1346                         || Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
1347                     list.add(a);
1348                 }
1349             }
1350         }
1351         return list;
1352     }
1353 
1354     @Deprecated
1355     public List<Dependency> getCompileDependencies() {
1356         Set<Artifact> artifacts = getArtifacts();
1357 
1358         if ((artifacts == null) || artifacts.isEmpty()) {
1359             return Collections.emptyList();
1360         }
1361 
1362         List<Dependency> list = new ArrayList<>(artifacts.size());
1363 
1364         for (Artifact a : getArtifacts()) {
1365             // TODO let the scope handler deal with this
1366             if (Artifact.SCOPE_COMPILE.equals(a.getScope())
1367                     || Artifact.SCOPE_PROVIDED.equals(a.getScope())
1368                     || Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
1369                 Dependency dependency = new Dependency();
1370 
1371                 dependency.setArtifactId(a.getArtifactId());
1372                 dependency.setGroupId(a.getGroupId());
1373                 dependency.setVersion(a.getVersion());
1374                 dependency.setScope(a.getScope());
1375                 dependency.setType(a.getType());
1376                 dependency.setClassifier(a.getClassifier());
1377 
1378                 list.add(dependency);
1379             }
1380         }
1381         return Collections.unmodifiableList(list);
1382     }
1383 
1384     @Deprecated
1385     public List<Artifact> getTestArtifacts() {
1386         List<Artifact> list = new ArrayList<>(getArtifacts().size());
1387 
1388         for (Artifact a : getArtifacts()) {
1389             // TODO classpath check doesn't belong here - that's the other method
1390             if (a.getArtifactHandler().isAddedToClasspath()) {
1391                 list.add(a);
1392             }
1393         }
1394         return list;
1395     }
1396 
1397     @Deprecated
1398     public List<Dependency> getTestDependencies() {
1399         Set<Artifact> artifacts = getArtifacts();
1400 
1401         if ((artifacts == null) || artifacts.isEmpty()) {
1402             return Collections.emptyList();
1403         }
1404 
1405         List<Dependency> list = new ArrayList<>(artifacts.size());
1406 
1407         for (Artifact a : getArtifacts()) {
1408             Dependency dependency = new Dependency();
1409 
1410             dependency.setArtifactId(a.getArtifactId());
1411             dependency.setGroupId(a.getGroupId());
1412             dependency.setVersion(a.getVersion());
1413             dependency.setScope(a.getScope());
1414             dependency.setType(a.getType());
1415             dependency.setClassifier(a.getClassifier());
1416 
1417             list.add(dependency);
1418         }
1419         return Collections.unmodifiableList(list);
1420     }
1421 
1422     @Deprecated // used by the Maven ITs
1423     public List<Dependency> getRuntimeDependencies() {
1424         Set<Artifact> artifacts = getArtifacts();
1425 
1426         if ((artifacts == null) || artifacts.isEmpty()) {
1427             return Collections.emptyList();
1428         }
1429 
1430         List<Dependency> list = new ArrayList<>(artifacts.size());
1431 
1432         for (Artifact a : getArtifacts()) {
1433             // TODO let the scope handler deal with this
1434             if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope())) {
1435                 Dependency dependency = new Dependency();
1436 
1437                 dependency.setArtifactId(a.getArtifactId());
1438                 dependency.setGroupId(a.getGroupId());
1439                 dependency.setVersion(a.getVersion());
1440                 dependency.setScope(a.getScope());
1441                 dependency.setType(a.getType());
1442                 dependency.setClassifier(a.getClassifier());
1443 
1444                 list.add(dependency);
1445             }
1446         }
1447         return Collections.unmodifiableList(list);
1448     }
1449 
1450     @Deprecated
1451     public List<Artifact> getRuntimeArtifacts() {
1452         List<Artifact> list = new ArrayList<>(getArtifacts().size());
1453 
1454         for (Artifact a : getArtifacts()) {
1455             // TODO classpath check doesn't belong here - that's the other method
1456             if (a.getArtifactHandler().isAddedToClasspath()
1457                     // TODO let the scope handler deal with this
1458                     && (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope()))) {
1459                 list.add(a);
1460             }
1461         }
1462         return list;
1463     }
1464 
1465     @Deprecated
1466     public List<String> getSystemClasspathElements() throws DependencyResolutionRequiredException {
1467         List<String> list = new ArrayList<>(getArtifacts().size());
1468 
1469         String d = getBuild().getOutputDirectory();
1470         if (d != null) {
1471             list.add(d);
1472         }
1473 
1474         for (Artifact a : getArtifacts()) {
1475             if (a.getArtifactHandler().isAddedToClasspath()) {
1476                 // TODO let the scope handler deal with this
1477                 if (Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
1478                     addArtifactPath(a, list);
1479                 }
1480             }
1481         }
1482         return list;
1483     }
1484 
1485     @Deprecated
1486     public List<Artifact> getSystemArtifacts() {
1487         List<Artifact> list = new ArrayList<>(getArtifacts().size());
1488 
1489         for (Artifact a : getArtifacts()) {
1490             // TODO classpath check doesn't belong here - that's the other method
1491             if (a.getArtifactHandler().isAddedToClasspath()) {
1492                 // TODO let the scope handler deal with this
1493                 if (Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
1494                     list.add(a);
1495                 }
1496             }
1497         }
1498         return list;
1499     }
1500 
1501     @Deprecated
1502     public List<Dependency> getSystemDependencies() {
1503         Set<Artifact> artifacts = getArtifacts();
1504 
1505         if ((artifacts == null) || artifacts.isEmpty()) {
1506             return Collections.emptyList();
1507         }
1508 
1509         List<Dependency> list = new ArrayList<>(artifacts.size());
1510 
1511         for (Artifact a : getArtifacts()) {
1512             // TODO let the scope handler deal with this
1513             if (Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
1514                 Dependency dependency = new Dependency();
1515 
1516                 dependency.setArtifactId(a.getArtifactId());
1517                 dependency.setGroupId(a.getGroupId());
1518                 dependency.setVersion(a.getVersion());
1519                 dependency.setScope(a.getScope());
1520                 dependency.setType(a.getType());
1521                 dependency.setClassifier(a.getClassifier());
1522 
1523                 list.add(dependency);
1524             }
1525         }
1526         return Collections.unmodifiableList(list);
1527     }
1528 
1529     @Deprecated
1530     public void setReporting(Reporting reporting) {
1531         getModel().setReporting(reporting);
1532     }
1533 
1534     @Deprecated
1535     public Reporting getReporting() {
1536         return getModel().getReporting();
1537     }
1538 
1539     @Deprecated
1540     public void setReportArtifacts(Set<Artifact> reportArtifacts) {
1541         this.reportArtifacts = reportArtifacts;
1542 
1543         reportArtifactMap = null;
1544     }
1545 
1546     @Deprecated
1547     public Set<Artifact> getReportArtifacts() {
1548         return reportArtifacts;
1549     }
1550 
1551     @Deprecated
1552     public Map<String, Artifact> getReportArtifactMap() {
1553         if (reportArtifactMap == null) {
1554             reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId(getReportArtifacts());
1555         }
1556 
1557         return reportArtifactMap;
1558     }
1559 
1560     @Deprecated
1561     public void setExtensionArtifacts(Set<Artifact> extensionArtifacts) {
1562         this.extensionArtifacts = extensionArtifacts;
1563 
1564         extensionArtifactMap = null;
1565     }
1566 
1567     @Deprecated
1568     public Set<Artifact> getExtensionArtifacts() {
1569         return extensionArtifacts;
1570     }
1571 
1572     @Deprecated
1573     public Map<String, Artifact> getExtensionArtifactMap() {
1574         if (extensionArtifactMap == null) {
1575             extensionArtifactMap = ArtifactUtils.artifactMapByVersionlessId(getExtensionArtifacts());
1576         }
1577 
1578         return extensionArtifactMap;
1579     }
1580 
1581     @Deprecated
1582     public List<ReportPlugin> getReportPlugins() {
1583         if (getModel().getReporting() == null) {
1584             return Collections.emptyList();
1585         }
1586         return Collections.unmodifiableList(getModel().getReporting().getPlugins());
1587     }
1588 
1589     @Deprecated
1590     public Xpp3Dom getReportConfiguration(String pluginGroupId, String pluginArtifactId, String reportSetId) {
1591         Xpp3Dom dom = null;
1592 
1593         // ----------------------------------------------------------------------
1594         // I would like to be able to look up the Mojo object using a key but
1595         // we have a limitation in modello that will be remedied shortly. So
1596         // for now I have to iterate through and see what we have.
1597         // ----------------------------------------------------------------------
1598 
1599         if (getReportPlugins() != null) {
1600             for (ReportPlugin plugin : getReportPlugins()) {
1601                 if (pluginGroupId.equals(plugin.getGroupId()) && pluginArtifactId.equals(plugin.getArtifactId())) {
1602                     dom = (Xpp3Dom) plugin.getConfiguration();
1603 
1604                     if (reportSetId != null) {
1605                         ReportSet reportSet = plugin.getReportSetsAsMap().get(reportSetId);
1606                         if (reportSet != null) {
1607                             Xpp3Dom executionConfiguration = (Xpp3Dom) reportSet.getConfiguration();
1608                             if (executionConfiguration != null) {
1609                                 Xpp3Dom newDom = new Xpp3Dom(executionConfiguration);
1610                                 dom = Xpp3Dom.mergeXpp3Dom(newDom, dom);
1611                             }
1612                         }
1613                     }
1614                     break;
1615                 }
1616             }
1617         }
1618 
1619         if (dom != null) {
1620             // make a copy so the original in the POM doesn't get messed with
1621             dom = new Xpp3Dom(dom);
1622         }
1623 
1624         return dom;
1625     }
1626 
1627     /**
1628      * @deprecated Use MavenProjectHelper.attachArtifact(..) instead.
1629      */
1630     @Deprecated
1631     public void attachArtifact(String type, String classifier, File file) {}
1632 
1633     /**
1634      * @deprecated Use {@link org.apache.maven.model.io.ModelWriter}.
1635      */
1636     @Deprecated
1637     public void writeModel(Writer writer) throws IOException {
1638         MavenXpp3Writer pomWriter = new MavenXpp3Writer();
1639         pomWriter.write(writer, getModel());
1640     }
1641 
1642     /**
1643      * @deprecated Use {@link org.apache.maven.model.io.ModelWriter}.
1644      */
1645     @Deprecated
1646     public void writeOriginalModel(Writer writer) throws IOException {
1647         MavenXpp3Writer pomWriter = new MavenXpp3Writer();
1648         pomWriter.write(writer, getOriginalModel());
1649     }
1650 
1651     @Deprecated
1652     public Artifact replaceWithActiveArtifact(Artifact pluginArtifact) {
1653         return pluginArtifact;
1654     }
1655 
1656     /**
1657      * Gets the project building request from which this project instance was created. <strong>Warning:</strong> This is
1658      * a utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
1659      *
1660      * @return The project building request or {@code null}.
1661      * @since 2.1
1662      */
1663     @Deprecated
1664     public ProjectBuildingRequest getProjectBuildingRequest() {
1665         return projectBuilderConfiguration;
1666     }
1667 
1668     /**
1669      * Sets the project building request from which this project instance was created. <strong>Warning:</strong> This is
1670      * a utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
1671      *
1672      * @param projectBuildingRequest The project building request, may be {@code null}.
1673      * @since 2.1
1674      */
1675     // used by maven-dependency-tree
1676     @Deprecated
1677     public void setProjectBuildingRequest(ProjectBuildingRequest projectBuildingRequest) {
1678         this.projectBuilderConfiguration = projectBuildingRequest;
1679     }
1680 }