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