1 package org.apache.maven.project;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
80
81
82
83
84
85
86
87
88
89
90
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
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<String>() );
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( Model model )
197 {
198 setModel( model );
199 }
200
201 public MavenProject( MavenProject project )
202 {
203 deepCopy( project );
204 }
205
206 public File getParentFile()
207 {
208 return parentFile;
209 }
210
211 public void setParentFile( File parentFile )
212 {
213 this.parentFile = parentFile;
214 }
215
216
217
218
219
220 public Artifact getArtifact()
221 {
222 return artifact;
223 }
224
225 public void setArtifact( Artifact artifact )
226 {
227 this.artifact = artifact;
228 }
229
230
231 public Model getModel()
232 {
233 return model;
234 }
235
236
237
238
239
240
241 public MavenProject getParent()
242 {
243 return parent;
244 }
245
246 public void setParent( MavenProject parent )
247 {
248 this.parent = parent;
249 }
250
251 public boolean hasParent()
252 {
253 return getParent() != null;
254 }
255
256 public File getFile()
257 {
258 return file;
259 }
260
261 public void setFile( File file )
262 {
263 this.file = file;
264 this.basedir = file != null ? file.getParentFile() : null;
265 }
266
267
268
269
270
271
272 public void setPomFile( File file )
273 {
274 this.file = file;
275 }
276
277 public File getBasedir()
278 {
279 return basedir;
280 }
281
282 public void setDependencies( List<Dependency> dependencies )
283 {
284 getModel().setDependencies( dependencies );
285 }
286
287 public List<Dependency> getDependencies()
288 {
289 return getModel().getDependencies();
290 }
291
292 public DependencyManagement getDependencyManagement()
293 {
294 return getModel().getDependencyManagement();
295 }
296
297
298
299
300
301 private void addPath( List<String> paths, String path )
302 {
303 if ( path != null )
304 {
305 path = path.trim();
306 if ( path.length() > 0 )
307 {
308 File file = new File( path );
309 if ( file.isAbsolute() )
310 {
311 path = file.getAbsolutePath();
312 }
313 else if ( ".".equals( path ) )
314 {
315 path = getBasedir().getAbsolutePath();
316 }
317 else
318 {
319 path = new File( getBasedir(), path ).getAbsolutePath();
320 }
321
322 if ( !paths.contains( path ) )
323 {
324 paths.add( path );
325 }
326 }
327 }
328 }
329
330 public void addCompileSourceRoot( String path )
331 {
332 addPath( getCompileSourceRoots(), path );
333 }
334
335 public void addTestCompileSourceRoot( String path )
336 {
337 addPath( getTestCompileSourceRoots(), path );
338 }
339
340 public List<String> getCompileSourceRoots()
341 {
342 return compileSourceRoots;
343 }
344
345 public List<String> getTestCompileSourceRoots()
346 {
347 return testCompileSourceRoots;
348 }
349
350 public List<String> getCompileClasspathElements()
351 throws DependencyResolutionRequiredException
352 {
353 List<String> list = new ArrayList<>( getArtifacts().size() + 1 );
354
355 String d = getBuild().getOutputDirectory();
356 if ( d != null )
357 {
358 list.add( d );
359 }
360
361 for ( Artifact a : getArtifacts() )
362 {
363 if ( a.getArtifactHandler().isAddedToClasspath() )
364 {
365
366 if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
367 || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
368 {
369 addArtifactPath( a, list );
370 }
371 }
372 }
373
374 return list;
375 }
376
377
378
379 public List<String> getTestClasspathElements()
380 throws DependencyResolutionRequiredException
381 {
382 List<String> list = new ArrayList<>( getArtifacts().size() + 2 );
383
384 String d = getBuild().getTestOutputDirectory();
385 if ( d != null )
386 {
387 list.add( d );
388 }
389
390 d = getBuild().getOutputDirectory();
391 if ( d != null )
392 {
393 list.add( d );
394 }
395
396 for ( Artifact a : getArtifacts() )
397 {
398 if ( a.getArtifactHandler().isAddedToClasspath() )
399 {
400 addArtifactPath( a, list );
401 }
402 }
403
404 return list;
405 }
406
407 public List<String> getRuntimeClasspathElements()
408 throws DependencyResolutionRequiredException
409 {
410 List<String> list = new ArrayList<>( getArtifacts().size() + 1 );
411
412 String d = getBuild().getOutputDirectory();
413 if ( d != null )
414 {
415 list.add( d );
416 }
417
418 for ( Artifact a : getArtifacts() )
419 {
420 if ( a.getArtifactHandler().isAddedToClasspath()
421
422 && ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) )
423 {
424 addArtifactPath( a, list );
425 }
426 }
427 return list;
428 }
429
430
431
432
433
434 public void setModelVersion( String pomVersion )
435 {
436 getModel().setModelVersion( pomVersion );
437 }
438
439 public String getModelVersion()
440 {
441 return getModel().getModelVersion();
442 }
443
444 public String getId()
445 {
446 return getModel().getId();
447 }
448
449 public void setGroupId( String groupId )
450 {
451 getModel().setGroupId( groupId );
452 }
453
454 public String getGroupId()
455 {
456 String groupId = getModel().getGroupId();
457
458 if ( ( groupId == null ) && ( getModel().getParent() != null ) )
459 {
460 groupId = getModel().getParent().getGroupId();
461 }
462
463 return groupId;
464 }
465
466 public void setArtifactId( String artifactId )
467 {
468 getModel().setArtifactId( artifactId );
469 }
470
471 public String getArtifactId()
472 {
473 return getModel().getArtifactId();
474 }
475
476 public void setName( String name )
477 {
478 getModel().setName( name );
479 }
480
481 public String getName()
482 {
483
484 if ( getModel().getName() != null )
485 {
486 return getModel().getName();
487 }
488 else
489 {
490 return getArtifactId();
491 }
492 }
493
494 public void setVersion( String version )
495 {
496 getModel().setVersion( version );
497 }
498
499 public String getVersion()
500 {
501 String version = getModel().getVersion();
502
503 if ( ( version == null ) && ( getModel().getParent() != null ) )
504 {
505 version = getModel().getParent().getVersion();
506 }
507
508 return version;
509 }
510
511 public String getPackaging()
512 {
513 return getModel().getPackaging();
514 }
515
516 public void setPackaging( String packaging )
517 {
518 getModel().setPackaging( packaging );
519 }
520
521 public void setInceptionYear( String inceptionYear )
522 {
523 getModel().setInceptionYear( inceptionYear );
524 }
525
526 public String getInceptionYear()
527 {
528 return getModel().getInceptionYear();
529 }
530
531 public void setUrl( String url )
532 {
533 getModel().setUrl( url );
534 }
535
536 public String getUrl()
537 {
538 return getModel().getUrl();
539 }
540
541 public Prerequisites getPrerequisites()
542 {
543 return getModel().getPrerequisites();
544 }
545
546 public void setIssueManagement( IssueManagement issueManagement )
547 {
548 getModel().setIssueManagement( issueManagement );
549 }
550
551 public CiManagement getCiManagement()
552 {
553 return getModel().getCiManagement();
554 }
555
556 public void setCiManagement( CiManagement ciManagement )
557 {
558 getModel().setCiManagement( ciManagement );
559 }
560
561 public IssueManagement getIssueManagement()
562 {
563 return getModel().getIssueManagement();
564 }
565
566 public void setDistributionManagement( DistributionManagement distributionManagement )
567 {
568 getModel().setDistributionManagement( distributionManagement );
569 }
570
571 public DistributionManagement getDistributionManagement()
572 {
573 return getModel().getDistributionManagement();
574 }
575
576 public void setDescription( String description )
577 {
578 getModel().setDescription( description );
579 }
580
581 public String getDescription()
582 {
583 return getModel().getDescription();
584 }
585
586 public void setOrganization( Organization organization )
587 {
588 getModel().setOrganization( organization );
589 }
590
591 public Organization getOrganization()
592 {
593 return getModel().getOrganization();
594 }
595
596 public void setScm( Scm scm )
597 {
598 getModel().setScm( scm );
599 }
600
601 public Scm getScm()
602 {
603 return getModel().getScm();
604 }
605
606 public void setMailingLists( List<MailingList> mailingLists )
607 {
608 getModel().setMailingLists( mailingLists );
609 }
610
611 public List<MailingList> getMailingLists()
612 {
613 return getModel().getMailingLists();
614 }
615
616 public void addMailingList( MailingList mailingList )
617 {
618 getModel().addMailingList( mailingList );
619 }
620
621 public void setDevelopers( List<Developer> developers )
622 {
623 getModel().setDevelopers( developers );
624 }
625
626 public List<Developer> getDevelopers()
627 {
628 return getModel().getDevelopers();
629 }
630
631 public void addDeveloper( Developer developer )
632 {
633 getModel().addDeveloper( developer );
634 }
635
636 public void setContributors( List<Contributor> contributors )
637 {
638 getModel().setContributors( contributors );
639 }
640
641 public List<Contributor> getContributors()
642 {
643 return getModel().getContributors();
644 }
645
646 public void addContributor( Contributor contributor )
647 {
648 getModel().addContributor( contributor );
649 }
650
651 public void setBuild( Build build )
652 {
653 getModel().setBuild( build );
654 }
655
656 public Build getBuild()
657 {
658 return getModelBuild();
659 }
660
661 public List<Resource> getResources()
662 {
663 return getBuild().getResources();
664 }
665
666 public List<Resource> getTestResources()
667 {
668 return getBuild().getTestResources();
669 }
670
671 public void addResource( Resource resource )
672 {
673 getBuild().addResource( resource );
674 }
675
676 public void addTestResource( Resource testResource )
677 {
678 getBuild().addTestResource( testResource );
679 }
680
681 public void setLicenses( List<License> licenses )
682 {
683 getModel().setLicenses( licenses );
684 }
685
686 public List<License> getLicenses()
687 {
688 return getModel().getLicenses();
689 }
690
691 public void addLicense( License license )
692 {
693 getModel().addLicense( license );
694 }
695
696 public void setArtifacts( Set<Artifact> artifacts )
697 {
698 this.artifacts = artifacts;
699
700
701 artifactMap = null;
702 }
703
704
705
706
707
708
709
710
711
712 public Set<Artifact> getArtifacts()
713 {
714 if ( artifacts == null )
715 {
716 if ( artifactFilter == null || resolvedArtifacts == null )
717 {
718 artifacts = new LinkedHashSet<>();
719 }
720 else
721 {
722 artifacts = new LinkedHashSet<>( resolvedArtifacts.size() * 2 );
723 for ( Artifact artifact : resolvedArtifacts )
724 {
725 if ( artifactFilter.include( artifact ) )
726 {
727 artifacts.add( artifact );
728 }
729 }
730 }
731 }
732 return artifacts;
733 }
734
735 public Map<String, Artifact> getArtifactMap()
736 {
737 if ( artifactMap == null )
738 {
739 artifactMap = ArtifactUtils.artifactMapByVersionlessId( getArtifacts() );
740 }
741 return artifactMap;
742 }
743
744 public void setPluginArtifacts( Set<Artifact> pluginArtifacts )
745 {
746 this.pluginArtifacts = pluginArtifacts;
747
748 this.pluginArtifactMap = null;
749 }
750
751 public Set<Artifact> getPluginArtifacts()
752 {
753 return pluginArtifacts;
754 }
755
756 public Map<String, Artifact> getPluginArtifactMap()
757 {
758 if ( pluginArtifactMap == null )
759 {
760 pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getPluginArtifacts() );
761 }
762
763 return pluginArtifactMap;
764 }
765
766 public void setParentArtifact( Artifact parentArtifact )
767 {
768 this.parentArtifact = parentArtifact;
769 }
770
771 public Artifact getParentArtifact()
772 {
773 return parentArtifact;
774 }
775
776 public List<Repository> getRepositories()
777 {
778 return getModel().getRepositories();
779 }
780
781
782
783
784
785 public List<Plugin> getBuildPlugins()
786 {
787 if ( getModel().getBuild() == null )
788 {
789 return Collections.emptyList();
790 }
791 return Collections.unmodifiableList( getModel().getBuild().getPlugins() );
792 }
793
794 public List<String> getModules()
795 {
796 return getModel().getModules();
797 }
798
799 public PluginManagement getPluginManagement()
800 {
801 PluginManagement pluginMgmt = null;
802
803 Build build = getModel().getBuild();
804 if ( build != null )
805 {
806 pluginMgmt = build.getPluginManagement();
807 }
808
809 return pluginMgmt;
810 }
811
812 private Build getModelBuild()
813 {
814 Build build = getModel().getBuild();
815
816 if ( build == null )
817 {
818 build = new Build();
819
820 getModel().setBuild( build );
821 }
822
823 return build;
824 }
825
826 public void setRemoteArtifactRepositories( List<ArtifactRepository> remoteArtifactRepositories )
827 {
828 this.remoteArtifactRepositories = remoteArtifactRepositories;
829 this.remoteProjectRepositories = RepositoryUtils.toRepos( getRemoteArtifactRepositories() );
830 }
831
832 public List<ArtifactRepository> getRemoteArtifactRepositories()
833 {
834 if ( remoteArtifactRepositories == null )
835 {
836 remoteArtifactRepositories = new ArrayList<>();
837 }
838
839 return remoteArtifactRepositories;
840 }
841
842 public void setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories )
843 {
844 this.pluginArtifactRepositories = pluginArtifactRepositories;
845 this.remotePluginRepositories = RepositoryUtils.toRepos( getPluginArtifactRepositories() );
846 }
847
848
849
850
851
852 public List<ArtifactRepository> getPluginArtifactRepositories()
853 {
854 if ( pluginArtifactRepositories == null )
855 {
856 pluginArtifactRepositories = new ArrayList<>();
857 }
858
859 return pluginArtifactRepositories;
860 }
861
862 public ArtifactRepository getDistributionManagementArtifactRepository()
863 {
864 return getArtifact().isSnapshot() && ( getSnapshotArtifactRepository() != null )
865 ? getSnapshotArtifactRepository()
866 : getReleaseArtifactRepository();
867 }
868
869 public List<Repository> getPluginRepositories()
870 {
871 return getModel().getPluginRepositories();
872 }
873
874 public List<RemoteRepository> getRemoteProjectRepositories()
875 {
876 return remoteProjectRepositories;
877 }
878
879 public List<RemoteRepository> getRemotePluginRepositories()
880 {
881 return remotePluginRepositories;
882 }
883
884 public void setActiveProfiles( List<Profile> activeProfiles )
885 {
886 this.activeProfiles = activeProfiles;
887 }
888
889 public List<Profile> getActiveProfiles()
890 {
891 return activeProfiles;
892 }
893
894 public void setInjectedProfileIds( String source, List<String> injectedProfileIds )
895 {
896 if ( injectedProfileIds != null )
897 {
898 this.injectedProfileIds.put( source, new ArrayList<>( injectedProfileIds ) );
899 }
900 else
901 {
902 this.injectedProfileIds.remove( source );
903 }
904 }
905
906
907
908
909
910
911
912
913
914
915
916 public Map<String, List<String>> getInjectedProfileIds()
917 {
918 return this.injectedProfileIds;
919 }
920
921
922
923
924
925
926
927
928
929
930
931
932 public void addAttachedArtifact( Artifact artifact )
933 throws DuplicateArtifactAttachmentException
934 {
935
936 int index = attachedArtifacts.indexOf( artifact );
937 if ( index >= 0 )
938 {
939 LOGGER.warn( "artifact {} already attached, replace previous instance", artifact );
940 attachedArtifacts.set( index, artifact );
941 }
942 else
943 {
944 attachedArtifacts.add( artifact );
945 }
946 }
947
948
949
950
951
952
953
954
955
956 public List<Artifact> getAttachedArtifacts()
957 {
958 if ( attachedArtifacts == null )
959 {
960 attachedArtifacts = new ArrayList<>();
961 }
962 return attachedArtifacts;
963 }
964
965 public Xpp3Dom getGoalConfiguration( String pluginGroupId, String pluginArtifactId, String executionId,
966 String goalId )
967 {
968 Xpp3Dom dom = null;
969
970 if ( getBuildPlugins() != null )
971 {
972 for ( Plugin plugin : getBuildPlugins() )
973 {
974 if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) )
975 {
976 dom = (Xpp3Dom) plugin.getConfiguration();
977
978 if ( executionId != null )
979 {
980 PluginExecution execution = plugin.getExecutionsAsMap().get( executionId );
981 if ( execution != null )
982 {
983
984 dom = (Xpp3Dom) execution.getConfiguration();
985 }
986 }
987 break;
988 }
989 }
990 }
991
992 if ( dom != null )
993 {
994
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
1023
1024
1025
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 return Objects.hash( getGroupId(), getArtifactId(), getVersion() );
1092 }
1093
1094 public List<Extension> getBuildExtensions()
1095 {
1096 Build build = getBuild();
1097 if ( ( build == null ) || ( build.getExtensions() == null ) )
1098 {
1099 return Collections.emptyList();
1100 }
1101 else
1102 {
1103 return Collections.unmodifiableList( build.getExtensions() );
1104 }
1105 }
1106
1107 public void addProjectReference( MavenProject project )
1108 {
1109 projectReferences.put( getProjectReferenceId( project.getGroupId(), project.getArtifactId(),
1110 project.getVersion() ), project );
1111 }
1112
1113 public Properties getProperties()
1114 {
1115 return getModel().getProperties();
1116 }
1117
1118 public List<String> getFilters()
1119 {
1120 return getBuild().getFilters();
1121 }
1122
1123 public Map<String, MavenProject> getProjectReferences()
1124 {
1125 return projectReferences;
1126 }
1127
1128 public boolean isExecutionRoot()
1129 {
1130 return executionRoot;
1131 }
1132
1133 public void setExecutionRoot( boolean executionRoot )
1134 {
1135 this.executionRoot = executionRoot;
1136 }
1137
1138 public String getDefaultGoal()
1139 {
1140 return getBuild() != null ? getBuild().getDefaultGoal() : null;
1141 }
1142
1143 public Plugin getPlugin( String pluginKey )
1144 {
1145 return getBuild().getPluginsAsMap().get( pluginKey );
1146 }
1147
1148
1149
1150
1151 @Override
1152 public String toString()
1153 {
1154 StringBuilder sb = new StringBuilder( 128 );
1155 sb.append( "MavenProject: " );
1156 sb.append( getGroupId() );
1157 sb.append( ':' );
1158 sb.append( getArtifactId() );
1159 sb.append( ':' );
1160 sb.append( getVersion() );
1161 sb.append( " @ " );
1162
1163 try
1164 {
1165 sb.append( getFile().getPath() );
1166 }
1167 catch ( NullPointerException e )
1168 {
1169
1170 }
1171
1172 return sb.toString();
1173 }
1174
1175
1176
1177
1178 @Override
1179 public MavenProject clone()
1180 {
1181 MavenProject clone;
1182 try
1183 {
1184 clone = (MavenProject) super.clone();
1185 }
1186 catch ( CloneNotSupportedException e )
1187 {
1188 throw new UnsupportedOperationException( e );
1189 }
1190
1191 clone.deepCopy( this );
1192
1193 return clone;
1194 }
1195
1196 public void setModel( Model model )
1197 {
1198 this.model = model;
1199 }
1200
1201 protected void setAttachedArtifacts( List<Artifact> attachedArtifacts )
1202 {
1203 this.attachedArtifacts = attachedArtifacts;
1204 }
1205
1206 protected void setCompileSourceRoots( List<String> compileSourceRoots )
1207 {
1208 this.compileSourceRoots = compileSourceRoots;
1209 }
1210
1211 protected void setTestCompileSourceRoots( List<String> testCompileSourceRoots )
1212 {
1213 this.testCompileSourceRoots = testCompileSourceRoots;
1214 }
1215
1216 protected ArtifactRepository getReleaseArtifactRepository()
1217 {
1218 return releaseArtifactRepository;
1219 }
1220
1221 protected ArtifactRepository getSnapshotArtifactRepository()
1222 {
1223 return snapshotArtifactRepository;
1224 }
1225
1226 private void deepCopy( MavenProject project )
1227 {
1228
1229
1230
1231 file = project.file;
1232 basedir = project.basedir;
1233
1234
1235
1236 if ( project.getDependencyArtifacts() != null )
1237 {
1238 setDependencyArtifacts( Collections.unmodifiableSet( project.getDependencyArtifacts() ) );
1239 }
1240
1241 if ( project.getArtifacts() != null )
1242 {
1243 setArtifacts( Collections.unmodifiableSet( project.getArtifacts() ) );
1244 }
1245
1246 if ( project.getParentFile() != null )
1247 {
1248 parentFile = new File( project.getParentFile().getAbsolutePath() );
1249 }
1250
1251 if ( project.getPluginArtifacts() != null )
1252 {
1253 setPluginArtifacts( Collections.unmodifiableSet( project.getPluginArtifacts() ) );
1254 }
1255
1256 if ( project.getReportArtifacts() != null )
1257 {
1258 setReportArtifacts( Collections.unmodifiableSet( project.getReportArtifacts() ) );
1259 }
1260
1261 if ( project.getExtensionArtifacts() != null )
1262 {
1263 setExtensionArtifacts( Collections.unmodifiableSet( project.getExtensionArtifacts() ) );
1264 }
1265
1266 setParentArtifact( ( project.getParentArtifact() ) );
1267
1268 if ( project.getRemoteArtifactRepositories() != null )
1269 {
1270 setRemoteArtifactRepositories( Collections.unmodifiableList( project.getRemoteArtifactRepositories() ) );
1271 }
1272
1273 if ( project.getPluginArtifactRepositories() != null )
1274 {
1275 setPluginArtifactRepositories( Collections.unmodifiableList( project.getPluginArtifactRepositories() ) );
1276 }
1277
1278 if ( project.getActiveProfiles() != null )
1279 {
1280 setActiveProfiles( ( Collections.unmodifiableList( project.getActiveProfiles() ) ) );
1281 }
1282
1283 if ( project.getAttachedArtifacts() != null )
1284 {
1285
1286 setAttachedArtifacts( new ArrayList<>( project.getAttachedArtifacts() ) );
1287 }
1288
1289 if ( project.getCompileSourceRoots() != null )
1290 {
1291
1292 setCompileSourceRoots( ( new ArrayList<>( project.getCompileSourceRoots() ) ) );
1293 }
1294
1295 if ( project.getTestCompileSourceRoots() != null )
1296 {
1297 setTestCompileSourceRoots( ( new ArrayList<>( project.getTestCompileSourceRoots() ) ) );
1298 }
1299
1300 if ( project.getScriptSourceRoots() != null )
1301 {
1302 setScriptSourceRoots( ( new ArrayList<>( project.getScriptSourceRoots() ) ) );
1303 }
1304
1305 if ( project.getModel() != null )
1306 {
1307 setModel( project.getModel().clone() );
1308 }
1309
1310 if ( project.getOriginalModel() != null )
1311 {
1312 setOriginalModel( project.getOriginalModel() );
1313 }
1314
1315 setExecutionRoot( project.isExecutionRoot() );
1316
1317 if ( project.getArtifact() != null )
1318 {
1319 setArtifact( ArtifactUtils.copyArtifact( project.getArtifact() ) );
1320 }
1321
1322 if ( project.getManagedVersionMap() != null )
1323 {
1324 setManagedVersionMap( project.getManagedVersionMap() );
1325 }
1326
1327 lifecyclePhases.addAll( project.lifecyclePhases );
1328 }
1329
1330 private void addArtifactPath( Artifact artifact, List<String> classpath )
1331 {
1332 File file = artifact.getFile();
1333 if ( file != null )
1334 {
1335 classpath.add( file.getPath() );
1336 }
1337 }
1338
1339 private static String getProjectReferenceId( String groupId, String artifactId, String version )
1340 {
1341 StringBuilder buffer = new StringBuilder( 128 );
1342 buffer.append( groupId ).append( ':' ).append( artifactId ).append( ':' ).append( version );
1343 return buffer.toString();
1344 }
1345
1346
1347
1348
1349
1350
1351 public void setContextValue( String key, Object value )
1352 {
1353 if ( context == null )
1354 {
1355 context = new HashMap<>();
1356 }
1357 if ( value != null )
1358 {
1359 context.put( key, value );
1360 }
1361 else
1362 {
1363 context.remove( key );
1364 }
1365 }
1366
1367
1368
1369
1370 public Object getContextValue( String key )
1371 {
1372 if ( context == null )
1373 {
1374 return null;
1375 }
1376 return context.get( key );
1377 }
1378
1379
1380
1381
1382
1383
1384
1385
1386 public void setClassRealm( ClassRealm classRealm )
1387 {
1388 this.classRealm = classRealm;
1389 }
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399 public ClassRealm getClassRealm()
1400 {
1401 return classRealm;
1402 }
1403
1404
1405
1406
1407
1408
1409
1410
1411 public void setExtensionDependencyFilter( DependencyFilter extensionDependencyFilter )
1412 {
1413 this.extensionDependencyFilter = extensionDependencyFilter;
1414 }
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424 public DependencyFilter getExtensionDependencyFilter()
1425 {
1426 return extensionDependencyFilter;
1427 }
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437 public void setResolvedArtifacts( Set<Artifact> artifacts )
1438 {
1439 this.resolvedArtifacts = ( artifacts != null ) ? artifacts : Collections.<Artifact>emptySet();
1440 this.artifacts = null;
1441 this.artifactMap = null;
1442 }
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452 public void setArtifactFilter( ArtifactFilter artifactFilter )
1453 {
1454 this.artifactFilter = artifactFilter;
1455 this.artifacts = null;
1456 this.artifactMap = null;
1457 }
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467 public boolean hasLifecyclePhase( String phase )
1468 {
1469 return lifecyclePhases.contains( phase );
1470 }
1471
1472
1473
1474
1475
1476
1477
1478
1479 public void addLifecyclePhase( String lifecyclePhase )
1480 {
1481 lifecyclePhases.add( lifecyclePhase );
1482 }
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495 private ProjectBuildingRequest projectBuilderConfiguration;
1496
1497 private Map<String, String> moduleAdjustments;
1498
1499 @Deprecated
1500 public String getModulePathAdjustment( MavenProject moduleProject )
1501 throws IOException
1502 {
1503
1504
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, getDependencies(), inheritedScope, filter, this );
1561 }
1562
1563 @Deprecated
1564 protected void setScriptSourceRoots( List<String> scriptSourceRoots )
1565 {
1566 this.scriptSourceRoots = scriptSourceRoots;
1567 }
1568
1569 @Deprecated
1570 public void addScriptSourceRoot( String path )
1571 {
1572 if ( path != null )
1573 {
1574 path = path.trim();
1575 if ( path.length() != 0 )
1576 {
1577 if ( !getScriptSourceRoots().contains( path ) )
1578 {
1579 getScriptSourceRoots().add( path );
1580 }
1581 }
1582 }
1583 }
1584
1585 @Deprecated
1586 public List<String> getScriptSourceRoots()
1587 {
1588 return scriptSourceRoots;
1589 }
1590
1591 @Deprecated
1592 public List<Artifact> getCompileArtifacts()
1593 {
1594 List<Artifact> list = new ArrayList<>( getArtifacts().size() );
1595
1596 for ( Artifact a : getArtifacts() )
1597 {
1598
1599 if ( a.getArtifactHandler().isAddedToClasspath() )
1600 {
1601
1602 if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
1603 || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
1604 {
1605 list.add( a );
1606 }
1607 }
1608 }
1609 return list;
1610 }
1611
1612 @Deprecated
1613 public List<Dependency> getCompileDependencies()
1614 {
1615 Set<Artifact> artifacts = getArtifacts();
1616
1617 if ( ( artifacts == null ) || artifacts.isEmpty() )
1618 {
1619 return Collections.emptyList();
1620 }
1621
1622 List<Dependency> list = new ArrayList<>( artifacts.size() );
1623
1624 for ( Artifact a : getArtifacts() )
1625 {
1626
1627 if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
1628 || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
1629 {
1630 Dependency dependency = new Dependency();
1631
1632 dependency.setArtifactId( a.getArtifactId() );
1633 dependency.setGroupId( a.getGroupId() );
1634 dependency.setVersion( a.getVersion() );
1635 dependency.setScope( a.getScope() );
1636 dependency.setType( a.getType() );
1637 dependency.setClassifier( a.getClassifier() );
1638
1639 list.add( dependency );
1640 }
1641 }
1642 return Collections.unmodifiableList( list );
1643 }
1644
1645 @Deprecated
1646 public List<Artifact> getTestArtifacts()
1647 {
1648 List<Artifact> list = new ArrayList<>( getArtifacts().size() );
1649
1650 for ( Artifact a : getArtifacts() )
1651 {
1652
1653 if ( a.getArtifactHandler().isAddedToClasspath() )
1654 {
1655 list.add( a );
1656 }
1657 }
1658 return list;
1659 }
1660
1661 @Deprecated
1662 public List<Dependency> getTestDependencies()
1663 {
1664 Set<Artifact> artifacts = getArtifacts();
1665
1666 if ( ( artifacts == null ) || artifacts.isEmpty() )
1667 {
1668 return Collections.emptyList();
1669 }
1670
1671 List<Dependency> list = new ArrayList<>( artifacts.size() );
1672
1673 for ( Artifact a : getArtifacts() )
1674 {
1675 Dependency dependency = new Dependency();
1676
1677 dependency.setArtifactId( a.getArtifactId() );
1678 dependency.setGroupId( a.getGroupId() );
1679 dependency.setVersion( a.getVersion() );
1680 dependency.setScope( a.getScope() );
1681 dependency.setType( a.getType() );
1682 dependency.setClassifier( a.getClassifier() );
1683
1684 list.add( dependency );
1685 }
1686 return Collections.unmodifiableList( list );
1687 }
1688
1689 @Deprecated
1690 public List<Dependency> getRuntimeDependencies()
1691 {
1692 Set<Artifact> artifacts = getArtifacts();
1693
1694 if ( ( artifacts == null ) || artifacts.isEmpty() )
1695 {
1696 return Collections.emptyList();
1697 }
1698
1699 List<Dependency> list = new ArrayList<>( artifacts.size() );
1700
1701 for ( Artifact a : getArtifacts() )
1702 {
1703
1704 if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
1705 {
1706 Dependency dependency = new Dependency();
1707
1708 dependency.setArtifactId( a.getArtifactId() );
1709 dependency.setGroupId( a.getGroupId() );
1710 dependency.setVersion( a.getVersion() );
1711 dependency.setScope( a.getScope() );
1712 dependency.setType( a.getType() );
1713 dependency.setClassifier( a.getClassifier() );
1714
1715 list.add( dependency );
1716 }
1717 }
1718 return Collections.unmodifiableList( list );
1719 }
1720
1721 @Deprecated
1722 public List<Artifact> getRuntimeArtifacts()
1723 {
1724 List<Artifact> list = new ArrayList<>( getArtifacts().size() );
1725
1726 for ( Artifact a : getArtifacts() )
1727 {
1728
1729 if ( a.getArtifactHandler().isAddedToClasspath()
1730
1731 && ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) )
1732 {
1733 list.add( a );
1734 }
1735 }
1736 return list;
1737 }
1738
1739 @Deprecated
1740 public List<String> getSystemClasspathElements()
1741 throws DependencyResolutionRequiredException
1742 {
1743 List<String> list = new ArrayList<>( getArtifacts().size() );
1744
1745 String d = getBuild().getOutputDirectory();
1746 if ( d != null )
1747 {
1748 list.add( d );
1749 }
1750
1751 for ( Artifact a : getArtifacts() )
1752 {
1753 if ( a.getArtifactHandler().isAddedToClasspath() )
1754 {
1755
1756 if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
1757 {
1758 addArtifactPath( a, list );
1759 }
1760 }
1761 }
1762 return list;
1763 }
1764
1765 @Deprecated
1766 public List<Artifact> getSystemArtifacts()
1767 {
1768 List<Artifact> list = new ArrayList<>( getArtifacts().size() );
1769
1770 for ( Artifact a : getArtifacts() )
1771 {
1772
1773 if ( a.getArtifactHandler().isAddedToClasspath() )
1774 {
1775
1776 if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
1777 {
1778 list.add( a );
1779 }
1780 }
1781 }
1782 return list;
1783 }
1784
1785 @Deprecated
1786 public List<Dependency> getSystemDependencies()
1787 {
1788 Set<Artifact> artifacts = getArtifacts();
1789
1790 if ( ( artifacts == null ) || artifacts.isEmpty() )
1791 {
1792 return Collections.emptyList();
1793 }
1794
1795 List<Dependency> list = new ArrayList<>( artifacts.size() );
1796
1797 for ( Artifact a : getArtifacts() )
1798 {
1799
1800 if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
1801 {
1802 Dependency dependency = new Dependency();
1803
1804 dependency.setArtifactId( a.getArtifactId() );
1805 dependency.setGroupId( a.getGroupId() );
1806 dependency.setVersion( a.getVersion() );
1807 dependency.setScope( a.getScope() );
1808 dependency.setType( a.getType() );
1809 dependency.setClassifier( a.getClassifier() );
1810
1811 list.add( dependency );
1812 }
1813 }
1814 return Collections.unmodifiableList( list );
1815 }
1816
1817 @Deprecated
1818 public void setReporting( Reporting reporting )
1819 {
1820 getModel().setReporting( reporting );
1821 }
1822
1823 @Deprecated
1824 public Reporting getReporting()
1825 {
1826 return getModel().getReporting();
1827 }
1828
1829 @Deprecated
1830 public void setReportArtifacts( Set<Artifact> reportArtifacts )
1831 {
1832 this.reportArtifacts = reportArtifacts;
1833
1834 reportArtifactMap = null;
1835 }
1836
1837 @Deprecated
1838 public Set<Artifact> getReportArtifacts()
1839 {
1840 return reportArtifacts;
1841 }
1842
1843 @Deprecated
1844 public Map<String, Artifact> getReportArtifactMap()
1845 {
1846 if ( reportArtifactMap == null )
1847 {
1848 reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getReportArtifacts() );
1849 }
1850
1851 return reportArtifactMap;
1852 }
1853
1854 @Deprecated
1855 public void setExtensionArtifacts( Set<Artifact> extensionArtifacts )
1856 {
1857 this.extensionArtifacts = extensionArtifacts;
1858
1859 extensionArtifactMap = null;
1860 }
1861
1862 @Deprecated
1863 public Set<Artifact> getExtensionArtifacts()
1864 {
1865 return extensionArtifacts;
1866 }
1867
1868 @Deprecated
1869 public Map<String, Artifact> getExtensionArtifactMap()
1870 {
1871 if ( extensionArtifactMap == null )
1872 {
1873 extensionArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getExtensionArtifacts() );
1874 }
1875
1876 return extensionArtifactMap;
1877 }
1878
1879 @Deprecated
1880 public List<ReportPlugin> getReportPlugins()
1881 {
1882 if ( getModel().getReporting() == null )
1883 {
1884 return Collections.emptyList();
1885 }
1886 return Collections.unmodifiableList( getModel().getReporting().getPlugins() );
1887 }
1888
1889 @Deprecated
1890 public Xpp3Dom getReportConfiguration( String pluginGroupId, String pluginArtifactId, String reportSetId )
1891 {
1892 Xpp3Dom dom = null;
1893
1894
1895
1896
1897
1898
1899 if ( getReportPlugins() != null )
1900 {
1901 for ( ReportPlugin plugin : getReportPlugins() )
1902 {
1903 if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) )
1904 {
1905 dom = (Xpp3Dom) plugin.getConfiguration();
1906
1907 if ( reportSetId != null )
1908 {
1909 ReportSet reportSet = plugin.getReportSetsAsMap().get( reportSetId );
1910 if ( reportSet != null )
1911 {
1912 Xpp3Dom executionConfiguration = (Xpp3Dom) reportSet.getConfiguration();
1913 if ( executionConfiguration != null )
1914 {
1915 Xpp3Dom newDom = new Xpp3Dom( executionConfiguration );
1916 dom = Xpp3Dom.mergeXpp3Dom( newDom, dom );
1917 }
1918 }
1919 }
1920 break;
1921 }
1922 }
1923 }
1924
1925 if ( dom != null )
1926 {
1927
1928 dom = new Xpp3Dom( dom );
1929 }
1930
1931 return dom;
1932 }
1933
1934
1935
1936
1937 @Deprecated
1938 public void attachArtifact( String type, String classifier, File file )
1939 {
1940 }
1941
1942
1943
1944
1945 @Deprecated
1946 public void writeModel( Writer writer )
1947 throws IOException
1948 {
1949 MavenXpp3Writer pomWriter = new MavenXpp3Writer();
1950 pomWriter.write( writer, getModel() );
1951 }
1952
1953
1954
1955
1956 @Deprecated
1957 public void writeOriginalModel( Writer writer )
1958 throws IOException
1959 {
1960 MavenXpp3Writer pomWriter = new MavenXpp3Writer();
1961 pomWriter.write( writer, getOriginalModel() );
1962 }
1963
1964 @Deprecated
1965 public Artifact replaceWithActiveArtifact( Artifact pluginArtifact )
1966 {
1967 return pluginArtifact;
1968 }
1969
1970
1971
1972
1973
1974
1975
1976
1977 @Deprecated
1978 public ProjectBuildingRequest getProjectBuildingRequest()
1979 {
1980 return projectBuilderConfiguration;
1981 }
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991 @Deprecated
1992 public void setProjectBuildingRequest( ProjectBuildingRequest projectBuildingRequest )
1993 {
1994 this.projectBuilderConfiguration = projectBuildingRequest;
1995 }
1996 }