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