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 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} >
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 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} >
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 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      * @throws CloneNotSupportedException
1156      * @since 2.0.9
1157      */
1158     @Override
1159     public MavenProject clone()
1160     {
1161         MavenProject clone;
1162         try
1163         {
1164             clone = (MavenProject) super.clone();
1165         }
1166         catch ( CloneNotSupportedException e )
1167         {
1168             throw new UnsupportedOperationException( e );
1169         }
1170 
1171         clone.deepCopy( this );
1172 
1173         return clone;
1174     }
1175 
1176     public void setModel( Model model )
1177     {
1178         this.model = model;
1179     }
1180 
1181     protected void setAttachedArtifacts( List<Artifact> attachedArtifacts )
1182     {
1183         this.attachedArtifacts = attachedArtifacts;
1184     }
1185 
1186     protected void setCompileSourceRoots( List<String> compileSourceRoots )
1187     {
1188         this.compileSourceRoots = compileSourceRoots;
1189     }
1190 
1191     protected void setTestCompileSourceRoots( List<String> testCompileSourceRoots )
1192     {
1193         this.testCompileSourceRoots = testCompileSourceRoots;
1194     }
1195 
1196     protected ArtifactRepository getReleaseArtifactRepository()
1197     {
1198         return releaseArtifactRepository;
1199     }
1200 
1201     protected ArtifactRepository getSnapshotArtifactRepository()
1202     {
1203         return snapshotArtifactRepository;
1204     }
1205 
1206     private void deepCopy( MavenProject project )
1207     {
1208         // disown the parent
1209 
1210         // copy fields
1211         setFile( project.getFile() );
1212 
1213         // don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be
1214         // sure!
1215         if ( project.getDependencyArtifacts() != null )
1216         {
1217             setDependencyArtifacts( Collections.unmodifiableSet( project.getDependencyArtifacts() ) );
1218         }
1219 
1220         if ( project.getArtifacts() != null )
1221         {
1222             setArtifacts( Collections.unmodifiableSet( project.getArtifacts() ) );
1223         }
1224 
1225         if ( project.getParentFile() != null )
1226         {
1227             parentFile = new File( project.getParentFile().getAbsolutePath() );
1228         }
1229 
1230         if ( project.getPluginArtifacts() != null )
1231         {
1232             setPluginArtifacts( Collections.unmodifiableSet( project.getPluginArtifacts() ) );
1233         }
1234 
1235         if ( project.getReportArtifacts() != null )
1236         {
1237             setReportArtifacts( Collections.unmodifiableSet( project.getReportArtifacts() ) );
1238         }
1239 
1240         if ( project.getExtensionArtifacts() != null )
1241         {
1242             setExtensionArtifacts( Collections.unmodifiableSet( project.getExtensionArtifacts() ) );
1243         }
1244 
1245         setParentArtifact( ( project.getParentArtifact() ) );
1246 
1247         if ( project.getRemoteArtifactRepositories() != null )
1248         {
1249             setRemoteArtifactRepositories( Collections.unmodifiableList( project.getRemoteArtifactRepositories() ) );
1250         }
1251 
1252         if ( project.getPluginArtifactRepositories() != null )
1253         {
1254             setPluginArtifactRepositories( Collections.unmodifiableList( project.getPluginArtifactRepositories() ) );
1255         }
1256 
1257         if ( project.getActiveProfiles() != null )
1258         {
1259             setActiveProfiles( ( Collections.unmodifiableList( project.getActiveProfiles() ) ) );
1260         }
1261 
1262         if ( project.getAttachedArtifacts() != null )
1263         {
1264             // clone properties modifyable by plugins in a forked lifecycle
1265             setAttachedArtifacts( new ArrayList<>( project.getAttachedArtifacts() ) );
1266         }
1267 
1268         if ( project.getCompileSourceRoots() != null )
1269         {
1270             // clone source roots
1271             setCompileSourceRoots( ( new ArrayList<>( project.getCompileSourceRoots() ) ) );
1272         }
1273 
1274         if ( project.getTestCompileSourceRoots() != null )
1275         {
1276             setTestCompileSourceRoots( ( new ArrayList<>( project.getTestCompileSourceRoots() ) ) );
1277         }
1278 
1279         if ( project.getScriptSourceRoots() != null )
1280         {
1281             setScriptSourceRoots( ( new ArrayList<>( project.getScriptSourceRoots() ) ) );
1282         }
1283 
1284         if ( project.getModel() != null )
1285         {
1286             setModel( project.getModel().clone() );
1287         }
1288 
1289         if ( project.getOriginalModel() != null )
1290         {
1291             setOriginalModel( project.getOriginalModel() );
1292         }
1293 
1294         setExecutionRoot( project.isExecutionRoot() );
1295 
1296         if ( project.getArtifact() != null )
1297         {
1298             setArtifact( ArtifactUtils.copyArtifact( project.getArtifact() ) );
1299         }
1300 
1301         if ( project.getManagedVersionMap() != null )
1302         {
1303             setManagedVersionMap( new HashMap<>( project.getManagedVersionMap() ) );
1304         }
1305 
1306         lifecyclePhases.addAll( project.lifecyclePhases );
1307     }
1308 
1309     private void addArtifactPath( Artifact artifact, List<String> classpath )
1310     {
1311         File file = artifact.getFile();
1312         if ( file != null )
1313         {
1314             classpath.add( file.getPath() );
1315         }
1316     }
1317 
1318     private static String getProjectReferenceId( String groupId, String artifactId, String version )
1319     {
1320         StringBuilder buffer = new StringBuilder( 128 );
1321         buffer.append( groupId ).append( ':' ).append( artifactId ).append( ':' ).append( version );
1322         return buffer.toString();
1323     }
1324 
1325     /**
1326      * Sets the value of the context value of this project identified by the given key. If the supplied value is
1327      * <code>null</code>, the context value is removed from this project. Context values are intended to allow core
1328      * extensions to associate derived state with project instances.
1329      */
1330     public void setContextValue( String key, Object value )
1331     {
1332         if ( context == null )
1333         {
1334             context = new HashMap<>();
1335         }
1336         if ( value != null )
1337         {
1338             context.put( key, value );
1339         }
1340         else
1341         {
1342             context.remove( key );
1343         }
1344     }
1345 
1346     /**
1347      * Returns context value of this project associated with the given key or null if this project has no such value.
1348      */
1349     public Object getContextValue( String key )
1350     {
1351         if ( context == null )
1352         {
1353             return null;
1354         }
1355         return context.get( key );
1356     }
1357 
1358     /**
1359      * Sets the project's class realm. <strong>Warning:</strong> This is an internal utility method that is only public
1360      * for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted
1361      * without prior notice and must not be used by plugins.
1362      *
1363      * @param classRealm The class realm hosting the build extensions of this project, may be {@code null}.
1364      */
1365     public void setClassRealm( ClassRealm classRealm )
1366     {
1367         this.classRealm = classRealm;
1368     }
1369 
1370     /**
1371      * Gets the project's class realm. This class realm hosts the build extensions of the project.
1372      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1373      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1374      * used by plugins.
1375      *
1376      * @return The project's class realm or {@code null}.
1377      */
1378     public ClassRealm getClassRealm()
1379     {
1380         return classRealm;
1381     }
1382 
1383     /**
1384      * Sets the artifact filter used to exclude shared extension artifacts from plugin realms. <strong>Warning:</strong>
1385      * This is an internal utility method that is only public for technical reasons, it is not part of the public API.
1386      * In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
1387      *
1388      * @param extensionDependencyFilter The dependency filter to apply to plugins, may be {@code null}.
1389      */
1390     public void setExtensionDependencyFilter( DependencyFilter extensionDependencyFilter )
1391     {
1392         this.extensionDependencyFilter = extensionDependencyFilter;
1393     }
1394 
1395     /**
1396      * Gets the dependency filter used to exclude shared extension artifacts from plugin realms.
1397      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1398      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1399      * used by plugins.
1400      *
1401      * @return The dependency filter or {@code null}.
1402      */
1403     public DependencyFilter getExtensionDependencyFilter()
1404     {
1405         return extensionDependencyFilter;
1406     }
1407 
1408     /**
1409      * Sets the transitive dependency artifacts that have been resolved/collected for this project.
1410      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1411      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1412      * used by plugins.
1413      *
1414      * @param artifacts The set of artifacts, may be {@code null}.
1415      */
1416     public void setResolvedArtifacts( Set<Artifact> artifacts )
1417     {
1418         this.resolvedArtifacts = ( artifacts != null ) ? artifacts : Collections.<Artifact>emptySet();
1419         this.artifacts = null;
1420         this.artifactMap = null;
1421     }
1422 
1423     /**
1424      * Sets the scope filter to select the artifacts being exposed to the currently executed mojo.
1425      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1426      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1427      * used by plugins.
1428      *
1429      * @param artifactFilter The artifact filter, may be {@code null} to exclude all artifacts.
1430      */
1431     public void setArtifactFilter( ArtifactFilter artifactFilter )
1432     {
1433         this.artifactFilter = artifactFilter;
1434         this.artifacts = null;
1435         this.artifactMap = null;
1436     }
1437 
1438     /**
1439      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1440      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1441      * used by plugins.
1442      *
1443      * @param phase The phase to check for, must not be {@code null}.
1444      * @return {@code true} if the phase has been seen.
1445      */
1446     public boolean hasLifecyclePhase( String phase )
1447     {
1448         return lifecyclePhases.contains( phase );
1449     }
1450 
1451     /**
1452      * <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
1453      * part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
1454      * used by plugins.
1455      *
1456      * @param lifecyclePhase The lifecycle phase to add, must not be {@code null}.
1457      */
1458     public void addLifecyclePhase( String lifecyclePhase )
1459     {
1460         lifecyclePhases.add( lifecyclePhase );
1461     }
1462 
1463     // ----------------------------------------------------------------------------------------------------------------
1464     //
1465     //
1466     // D E P R E C A T E D
1467     //
1468     //
1469     // ----------------------------------------------------------------------------------------------------------------
1470     //
1471     // Everything below will be removed for Maven 4.0.0
1472     //
1473     // ----------------------------------------------------------------------------------------------------------------
1474 
1475     private ProjectBuildingRequest projectBuilderConfiguration;
1476 
1477     private Map<String, String> moduleAdjustments;
1478 
1479     @Deprecated // This appears only to be used in test code
1480     public String getModulePathAdjustment( MavenProject moduleProject )
1481         throws IOException
1482     {
1483         // FIXME: This is hacky. What if module directory doesn't match artifactid, and parent
1484         // is coming from the repository??
1485         String module = moduleProject.getArtifactId();
1486 
1487         File moduleFile = moduleProject.getFile();
1488 
1489         if ( moduleFile != null )
1490         {
1491             File moduleDir = moduleFile.getCanonicalFile().getParentFile();
1492 
1493             module = moduleDir.getName();
1494         }
1495 
1496         if ( moduleAdjustments == null )
1497         {
1498             moduleAdjustments = new HashMap<>();
1499 
1500             List<String> modules = getModules();
1501             if ( modules != null )
1502             {
1503                 for ( String modulePath : modules )
1504                 {
1505                     String moduleName = modulePath;
1506 
1507                     if ( moduleName.endsWith( "/" ) || moduleName.endsWith( "\\" ) )
1508                     {
1509                         moduleName = moduleName.substring( 0, moduleName.length() - 1 );
1510                     }
1511 
1512                     int lastSlash = moduleName.lastIndexOf( '/' );
1513 
1514                     if ( lastSlash < 0 )
1515                     {
1516                         lastSlash = moduleName.lastIndexOf( '\\' );
1517                     }
1518 
1519                     String adjustment = null;
1520 
1521                     if ( lastSlash > -1 )
1522                     {
1523                         moduleName = moduleName.substring( lastSlash + 1 );
1524                         adjustment = modulePath.substring( 0, lastSlash );
1525                     }
1526 
1527                     moduleAdjustments.put( moduleName, adjustment );
1528                 }
1529             }
1530         }
1531 
1532         return moduleAdjustments.get( module );
1533     }
1534 
1535     @Deprecated
1536     public Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, String inheritedScope,
1537                                           ArtifactFilter filter )
1538         throws InvalidDependencyVersionException
1539     {
1540         return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), inheritedScope, filter, this );
1541     }
1542 
1543     @Deprecated
1544     protected void setScriptSourceRoots( List<String> scriptSourceRoots )
1545     {
1546         this.scriptSourceRoots = scriptSourceRoots;
1547     }
1548 
1549     @Deprecated
1550     public void addScriptSourceRoot( String path )
1551     {
1552         if ( path != null )
1553         {
1554             path = path.trim();
1555             if ( path.length() != 0 )
1556             {
1557                 if ( !getScriptSourceRoots().contains( path ) )
1558                 {
1559                     getScriptSourceRoots().add( path );
1560                 }
1561             }
1562         }
1563     }
1564 
1565     @Deprecated
1566     public List<String> getScriptSourceRoots()
1567     {
1568         return scriptSourceRoots;
1569     }
1570 
1571     @Deprecated
1572     public List<Artifact> getCompileArtifacts()
1573     {
1574         List<Artifact> list = new ArrayList<>( getArtifacts().size() );
1575 
1576         for ( Artifact a : getArtifacts() )
1577         {
1578             // TODO classpath check doesn't belong here - that's the other method
1579             if ( a.getArtifactHandler().isAddedToClasspath() )
1580             {
1581                 // TODO let the scope handler deal with this
1582                 if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
1583                     || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
1584                 {
1585                     list.add( a );
1586                 }
1587             }
1588         }
1589         return list;
1590     }
1591 
1592     @Deprecated
1593     public List<Dependency> getCompileDependencies()
1594     {
1595         Set<Artifact> artifacts = getArtifacts();
1596 
1597         if ( ( artifacts == null ) || artifacts.isEmpty() )
1598         {
1599             return Collections.emptyList();
1600         }
1601 
1602         List<Dependency> list = new ArrayList<>( artifacts.size() );
1603 
1604         for ( Artifact a : getArtifacts() )
1605         {
1606             // TODO let the scope handler deal with this
1607             if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
1608                 || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
1609             {
1610                 Dependency dependency = new Dependency();
1611 
1612                 dependency.setArtifactId( a.getArtifactId() );
1613                 dependency.setGroupId( a.getGroupId() );
1614                 dependency.setVersion( a.getVersion() );
1615                 dependency.setScope( a.getScope() );
1616                 dependency.setType( a.getType() );
1617                 dependency.setClassifier( a.getClassifier() );
1618 
1619                 list.add( dependency );
1620             }
1621         }
1622         return list;
1623     }
1624 
1625     @Deprecated
1626     public List<Artifact> getTestArtifacts()
1627     {
1628         List<Artifact> list = new ArrayList<>( getArtifacts().size() );
1629 
1630         for ( Artifact a : getArtifacts() )
1631         {
1632             // TODO classpath check doesn't belong here - that's the other method
1633             if ( a.getArtifactHandler().isAddedToClasspath() )
1634             {
1635                 list.add( a );
1636             }
1637         }
1638         return list;
1639     }
1640 
1641     @Deprecated
1642     public List<Dependency> getTestDependencies()
1643     {
1644         Set<Artifact> artifacts = getArtifacts();
1645 
1646         if ( ( artifacts == null ) || artifacts.isEmpty() )
1647         {
1648             return Collections.emptyList();
1649         }
1650 
1651         List<Dependency> list = new ArrayList<>( artifacts.size() );
1652 
1653         for ( Artifact a : getArtifacts() )
1654         {
1655             Dependency dependency = new Dependency();
1656 
1657             dependency.setArtifactId( a.getArtifactId() );
1658             dependency.setGroupId( a.getGroupId() );
1659             dependency.setVersion( a.getVersion() );
1660             dependency.setScope( a.getScope() );
1661             dependency.setType( a.getType() );
1662             dependency.setClassifier( a.getClassifier() );
1663 
1664             list.add( dependency );
1665         }
1666         return list;
1667     }
1668 
1669     @Deprecated // used by the Maven ITs
1670     public List<Dependency> getRuntimeDependencies()
1671     {
1672         Set<Artifact> artifacts = getArtifacts();
1673 
1674         if ( ( artifacts == null ) || artifacts.isEmpty() )
1675         {
1676             return Collections.emptyList();
1677         }
1678 
1679         List<Dependency> list = new ArrayList<>( artifacts.size() );
1680 
1681         for ( Artifact a : getArtifacts()  )
1682         {
1683             // TODO let the scope handler deal with this
1684             if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
1685             {
1686                 Dependency dependency = new Dependency();
1687 
1688                 dependency.setArtifactId( a.getArtifactId() );
1689                 dependency.setGroupId( a.getGroupId() );
1690                 dependency.setVersion( a.getVersion() );
1691                 dependency.setScope( a.getScope() );
1692                 dependency.setType( a.getType() );
1693                 dependency.setClassifier( a.getClassifier() );
1694 
1695                 list.add( dependency );
1696             }
1697         }
1698         return list;
1699     }
1700 
1701     @Deprecated
1702     public List<Artifact> getRuntimeArtifacts()
1703     {
1704         List<Artifact> list = new ArrayList<>( getArtifacts().size() );
1705 
1706         for ( Artifact a : getArtifacts()  )
1707         {
1708             // TODO classpath check doesn't belong here - that's the other method
1709             if ( a.getArtifactHandler().isAddedToClasspath()
1710             // TODO let the scope handler deal with this
1711                 && ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) )
1712             {
1713                 list.add( a );
1714             }
1715         }
1716         return list;
1717     }
1718 
1719     @Deprecated
1720     public List<String> getSystemClasspathElements()
1721         throws DependencyResolutionRequiredException
1722     {
1723         List<String> list = new ArrayList<>( getArtifacts().size() );
1724 
1725         String d = getBuild().getOutputDirectory();
1726         if ( d != null )
1727         {
1728             list.add( d );
1729         }
1730 
1731         for ( Artifact a : getArtifacts() )
1732         {
1733             if ( a.getArtifactHandler().isAddedToClasspath() )
1734             {
1735                 // TODO let the scope handler deal with this
1736                 if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
1737                 {
1738                     addArtifactPath( a, list );
1739                 }
1740             }
1741         }
1742         return list;
1743     }
1744 
1745     @Deprecated
1746     public List<Artifact> getSystemArtifacts()
1747     {
1748         List<Artifact> list = new ArrayList<>( getArtifacts().size() );
1749 
1750         for ( Artifact a : getArtifacts() )
1751         {
1752             // TODO classpath check doesn't belong here - that's the other method
1753             if ( a.getArtifactHandler().isAddedToClasspath() )
1754             {
1755                 // TODO let the scope handler deal with this
1756                 if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
1757                 {
1758                     list.add( a );
1759                 }
1760             }
1761         }
1762         return list;
1763     }
1764 
1765     @Deprecated
1766     public List<Dependency> getSystemDependencies()
1767     {
1768         Set<Artifact> artifacts = getArtifacts();
1769 
1770         if ( ( artifacts == null ) || artifacts.isEmpty() )
1771         {
1772             return Collections.emptyList();
1773         }
1774 
1775         List<Dependency> list = new ArrayList<>( artifacts.size() );
1776 
1777         for ( Artifact a : getArtifacts() )
1778         {
1779             // TODO let the scope handler deal with this
1780             if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
1781             {
1782                 Dependency dependency = new Dependency();
1783 
1784                 dependency.setArtifactId( a.getArtifactId() );
1785                 dependency.setGroupId( a.getGroupId() );
1786                 dependency.setVersion( a.getVersion() );
1787                 dependency.setScope( a.getScope() );
1788                 dependency.setType( a.getType() );
1789                 dependency.setClassifier( a.getClassifier() );
1790 
1791                 list.add( dependency );
1792             }
1793         }
1794         return list;
1795     }
1796 
1797     @Deprecated
1798     public void setReporting( Reporting reporting )
1799     {
1800         getModel().setReporting( reporting );
1801     }
1802 
1803     @Deprecated
1804     public Reporting getReporting()
1805     {
1806         return getModel().getReporting();
1807     }
1808 
1809     @Deprecated
1810     public void setReportArtifacts( Set<Artifact> reportArtifacts )
1811     {
1812         this.reportArtifacts = reportArtifacts;
1813 
1814         reportArtifactMap = null;
1815     }
1816 
1817     @Deprecated
1818     public Set<Artifact> getReportArtifacts()
1819     {
1820         return reportArtifacts;
1821     }
1822 
1823     @Deprecated
1824     public Map<String, Artifact> getReportArtifactMap()
1825     {
1826         if ( reportArtifactMap == null )
1827         {
1828             reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getReportArtifacts() );
1829         }
1830 
1831         return reportArtifactMap;
1832     }
1833 
1834     @Deprecated
1835     public void setExtensionArtifacts( Set<Artifact> extensionArtifacts )
1836     {
1837         this.extensionArtifacts = extensionArtifacts;
1838 
1839         extensionArtifactMap = null;
1840     }
1841 
1842     @Deprecated
1843     public Set<Artifact> getExtensionArtifacts()
1844     {
1845         return extensionArtifacts;
1846     }
1847 
1848     @Deprecated
1849     public Map<String, Artifact> getExtensionArtifactMap()
1850     {
1851         if ( extensionArtifactMap == null )
1852         {
1853             extensionArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getExtensionArtifacts() );
1854         }
1855 
1856         return extensionArtifactMap;
1857     }
1858 
1859     @Deprecated
1860     public List<ReportPlugin> getReportPlugins()
1861     {
1862         if ( getModel().getReporting() == null )
1863         {
1864             return Collections.emptyList();
1865         }
1866         return getModel().getReporting().getPlugins();
1867 
1868     }
1869 
1870     @Deprecated
1871     public Xpp3Dom getReportConfiguration( String pluginGroupId, String pluginArtifactId, String reportSetId )
1872     {
1873         Xpp3Dom dom = null;
1874 
1875         // ----------------------------------------------------------------------
1876         // I would like to be able to lookup the Mojo object using a key but
1877         // we have a limitation in modello that will be remedied shortly. So
1878         // for now I have to iterate through and see what we have.
1879         // ----------------------------------------------------------------------
1880 
1881         if ( getReportPlugins() != null )
1882         {
1883             for ( ReportPlugin plugin : getReportPlugins() )
1884             {
1885                 if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) )
1886                 {
1887                     dom = (Xpp3Dom) plugin.getConfiguration();
1888 
1889                     if ( reportSetId != null )
1890                     {
1891                         ReportSet reportSet = plugin.getReportSetsAsMap().get( reportSetId );
1892                         if ( reportSet != null )
1893                         {
1894                             Xpp3Dom executionConfiguration = (Xpp3Dom) reportSet.getConfiguration();
1895                             if ( executionConfiguration != null )
1896                             {
1897                                 Xpp3Dom newDom = new Xpp3Dom( executionConfiguration );
1898                                 dom = Xpp3Dom.mergeXpp3Dom( newDom, dom );
1899                             }
1900                         }
1901                     }
1902                     break;
1903                 }
1904             }
1905         }
1906 
1907         if ( dom != null )
1908         {
1909             // make a copy so the original in the POM doesn't get messed with
1910             dom = new Xpp3Dom( dom );
1911         }
1912 
1913         return dom;
1914     }
1915 
1916     /**
1917      * @deprecated Use MavenProjectHelper.attachArtifact(..) instead.
1918      */
1919     @Deprecated
1920     public void attachArtifact( String type, String classifier, File file )
1921     {
1922     }
1923 
1924     /**
1925      * @deprecated Use {@link org.apache.maven.model.io.ModelWriter}.
1926      */
1927     @Deprecated
1928     public void writeModel( Writer writer )
1929         throws IOException
1930     {
1931         MavenXpp3Writer pomWriter = new MavenXpp3Writer();
1932         pomWriter.write( writer, getModel() );
1933     }
1934 
1935     /**
1936      * @deprecated Use {@link org.apache.maven.model.io.ModelWriter}.
1937      */
1938     @Deprecated
1939     public void writeOriginalModel( Writer writer )
1940         throws IOException
1941     {
1942         MavenXpp3Writer pomWriter = new MavenXpp3Writer();
1943         pomWriter.write( writer, getOriginalModel() );
1944     }
1945 
1946     @Deprecated
1947     public Artifact replaceWithActiveArtifact( Artifact pluginArtifact )
1948     {
1949         return pluginArtifact;
1950     }
1951 
1952     /**
1953      * Gets the project building request from which this project instance was created. <strong>Warning:</strong> This is
1954      * an utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
1955      *
1956      * @return The project building request or {@code null}.
1957      * @since 2.1
1958      */
1959     @Deprecated
1960     public ProjectBuildingRequest getProjectBuildingRequest()
1961     {
1962         return projectBuilderConfiguration;
1963     }
1964 
1965     /**
1966      * Sets the project building request from which this project instance was created. <strong>Warning:</strong> This is
1967      * an utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
1968      *
1969      * @param projectBuildingRequest The project building request, may be {@code null}.
1970      * @since 2.1
1971      */
1972     // used by maven-dependency-tree
1973     @Deprecated
1974     public void setProjectBuildingRequest( ProjectBuildingRequest projectBuildingRequest )
1975     {
1976         this.projectBuilderConfiguration = projectBuildingRequest;
1977     }
1978 }