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