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