1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.project;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.io.Writer;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.LinkedHashMap;
28 import java.util.LinkedHashSet;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Objects;
32 import java.util.Properties;
33 import java.util.Set;
34
35 import org.apache.maven.RepositoryUtils;
36 import org.apache.maven.artifact.Artifact;
37 import org.apache.maven.artifact.ArtifactUtils;
38 import org.apache.maven.artifact.DependencyResolutionRequiredException;
39 import org.apache.maven.artifact.factory.ArtifactFactory;
40 import org.apache.maven.artifact.repository.ArtifactRepository;
41 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
42 import org.apache.maven.model.Build;
43 import org.apache.maven.model.CiManagement;
44 import org.apache.maven.model.Contributor;
45 import org.apache.maven.model.Dependency;
46 import org.apache.maven.model.DependencyManagement;
47 import org.apache.maven.model.Developer;
48 import org.apache.maven.model.DistributionManagement;
49 import org.apache.maven.model.Extension;
50 import org.apache.maven.model.IssueManagement;
51 import org.apache.maven.model.License;
52 import org.apache.maven.model.MailingList;
53 import org.apache.maven.model.Model;
54 import org.apache.maven.model.Organization;
55 import org.apache.maven.model.Plugin;
56 import org.apache.maven.model.PluginExecution;
57 import org.apache.maven.model.PluginManagement;
58 import org.apache.maven.model.Prerequisites;
59 import org.apache.maven.model.Profile;
60 import org.apache.maven.model.ReportPlugin;
61 import org.apache.maven.model.ReportSet;
62 import org.apache.maven.model.Reporting;
63 import org.apache.maven.model.Repository;
64 import org.apache.maven.model.Resource;
65 import org.apache.maven.model.Scm;
66 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
67 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
68 import org.apache.maven.project.artifact.MavenMetadataSource;
69 import org.codehaus.plexus.classworlds.realm.ClassRealm;
70 import org.codehaus.plexus.util.xml.Xpp3Dom;
71 import org.eclipse.aether.graph.DependencyFilter;
72 import org.eclipse.aether.repository.RemoteRepository;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 public class MavenProject implements Cloneable {
91
92 private static final Logger LOGGER = LoggerFactory.getLogger(MavenProject.class);
93
94 public static final String EMPTY_PROJECT_GROUP_ID = "unknown";
95
96 public static final String EMPTY_PROJECT_ARTIFACT_ID = "empty-project";
97
98 public static final String EMPTY_PROJECT_VERSION = "0";
99
100 private Model model;
101
102 private MavenProject parent;
103
104 private File file;
105
106 private File basedir;
107
108 private Set<Artifact> resolvedArtifacts;
109
110 private ArtifactFilter artifactFilter;
111
112 private Set<Artifact> artifacts;
113
114 private Artifact parentArtifact;
115
116 private Set<Artifact> pluginArtifacts;
117
118 private List<ArtifactRepository> remoteArtifactRepositories;
119
120 private List<ArtifactRepository> pluginArtifactRepositories;
121
122 private List<RemoteRepository> remoteProjectRepositories;
123
124 private List<RemoteRepository> remotePluginRepositories;
125
126 private List<Artifact> attachedArtifacts = new ArrayList<>();
127
128 private MavenProject executionProject;
129
130 private List<MavenProject> collectedProjects;
131
132 private List<String> compileSourceRoots = new ArrayList<>();
133
134 private List<String> testCompileSourceRoots = new ArrayList<>();
135
136 private List<String> scriptSourceRoots = new ArrayList<>();
137
138 private ArtifactRepository releaseArtifactRepository;
139
140 private ArtifactRepository snapshotArtifactRepository;
141
142 private List<Profile> activeProfiles = new ArrayList<>();
143
144 private Map<String, List<String>> injectedProfileIds = new LinkedHashMap<>();
145
146 private Set<Artifact> dependencyArtifacts;
147
148 private Artifact artifact;
149
150
151 private Map<String, Artifact> artifactMap;
152
153 private Model originalModel;
154
155 private Map<String, Artifact> pluginArtifactMap;
156
157 private Set<Artifact> reportArtifacts;
158
159 private Map<String, Artifact> reportArtifactMap;
160
161 private Set<Artifact> extensionArtifacts;
162
163 private Map<String, Artifact> extensionArtifactMap;
164
165 private Map<String, Artifact> managedVersionMap;
166
167 private Map<String, MavenProject> projectReferences = new HashMap<>();
168
169 private boolean executionRoot;
170
171 private File parentFile;
172
173 private Map<String, Object> context;
174
175 private ClassRealm classRealm;
176
177 private DependencyFilter extensionDependencyFilter;
178
179 private final Set<String> lifecyclePhases = Collections.synchronizedSet(new LinkedHashSet<>());
180
181 public MavenProject() {
182 Model model = new Model();
183
184 model.setGroupId(EMPTY_PROJECT_GROUP_ID);
185 model.setArtifactId(EMPTY_PROJECT_ARTIFACT_ID);
186 model.setVersion(EMPTY_PROJECT_VERSION);
187
188 setModel(model);
189 }
190
191 public MavenProject(org.apache.maven.api.model.Model model) {
192 this(new Model(model));
193 }
194
195 public MavenProject(Model model) {
196 setModel(model);
197 }
198
199 public MavenProject(MavenProject project) {
200 deepCopy(project);
201 }
202
203 public File getParentFile() {
204 return parentFile;
205 }
206
207 public void setParentFile(File parentFile) {
208 this.parentFile = parentFile;
209 }
210
211
212
213
214
215 public Artifact getArtifact() {
216 return artifact;
217 }
218
219 public void setArtifact(Artifact artifact) {
220 this.artifact = artifact;
221 }
222
223
224 public Model getModel() {
225 return model;
226 }
227
228
229
230
231
232
233 public MavenProject getParent() {
234 return parent;
235 }
236
237 public void setParent(MavenProject parent) {
238 this.parent = parent;
239 }
240
241 public boolean hasParent() {
242 return getParent() != null;
243 }
244
245 public File getFile() {
246 return file;
247 }
248
249 public void setFile(File file) {
250 this.file = file;
251 this.basedir = file != null ? file.getParentFile() : null;
252 }
253
254
255
256
257
258
259 public void setPomFile(File file) {
260 this.file = file;
261 }
262
263 public File getBasedir() {
264 return basedir;
265 }
266
267 public void setDependencies(List<Dependency> dependencies) {
268 getModel().setDependencies(dependencies);
269 }
270
271 public List<Dependency> getDependencies() {
272 return getModel().getDependencies();
273 }
274
275 public DependencyManagement getDependencyManagement() {
276 return getModel().getDependencyManagement();
277 }
278
279
280
281
282
283 private void addPath(List<String> paths, String path) {
284 if (path != null) {
285 path = path.trim();
286 if (path.length() > 0) {
287 File file = new File(path);
288 if (file.isAbsolute()) {
289 path = file.getAbsolutePath();
290 } else if (".".equals(path)) {
291 path = getBasedir().getAbsolutePath();
292 } else {
293 path = new File(getBasedir(), path).getAbsolutePath();
294 }
295
296 if (!paths.contains(path)) {
297 paths.add(path);
298 }
299 }
300 }
301 }
302
303 public void addCompileSourceRoot(String path) {
304 addPath(getCompileSourceRoots(), path);
305 }
306
307 public void addTestCompileSourceRoot(String path) {
308 addPath(getTestCompileSourceRoots(), path);
309 }
310
311 public List<String> getCompileSourceRoots() {
312 return compileSourceRoots;
313 }
314
315 public List<String> getTestCompileSourceRoots() {
316 return testCompileSourceRoots;
317 }
318
319 public List<String> getCompileClasspathElements() throws DependencyResolutionRequiredException {
320 List<String> list = new ArrayList<>(getArtifacts().size() + 1);
321
322 String d = getBuild().getOutputDirectory();
323 if (d != null) {
324 list.add(d);
325 }
326
327 for (Artifact a : getArtifacts()) {
328 if (a.getArtifactHandler().isAddedToClasspath()) {
329
330 if (Artifact.SCOPE_COMPILE.equals(a.getScope())
331 || Artifact.SCOPE_PROVIDED.equals(a.getScope())
332 || Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
333 addArtifactPath(a, list);
334 }
335 }
336 }
337
338 return list;
339 }
340
341
342
343 public List<String> getTestClasspathElements() throws DependencyResolutionRequiredException {
344 List<String> list = new ArrayList<>(getArtifacts().size() + 2);
345
346 String d = getBuild().getTestOutputDirectory();
347 if (d != null) {
348 list.add(d);
349 }
350
351 d = getBuild().getOutputDirectory();
352 if (d != null) {
353 list.add(d);
354 }
355
356 for (Artifact a : getArtifacts()) {
357 if (a.getArtifactHandler().isAddedToClasspath()) {
358 addArtifactPath(a, list);
359 }
360 }
361
362 return list;
363 }
364
365 public List<String> getRuntimeClasspathElements() throws DependencyResolutionRequiredException {
366 List<String> list = new ArrayList<>(getArtifacts().size() + 1);
367
368 String d = getBuild().getOutputDirectory();
369 if (d != null) {
370 list.add(d);
371 }
372
373 for (Artifact a : getArtifacts()) {
374 if (a.getArtifactHandler().isAddedToClasspath()
375
376 && (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope()))) {
377 addArtifactPath(a, list);
378 }
379 }
380 return list;
381 }
382
383
384
385
386
387 public void setModelVersion(String pomVersion) {
388 getModel().setModelVersion(pomVersion);
389 }
390
391 public String getModelVersion() {
392 return getModel().getModelVersion();
393 }
394
395 public String getId() {
396 return getModel().getId();
397 }
398
399 public void setGroupId(String groupId) {
400 getModel().setGroupId(groupId);
401 }
402
403 public String getGroupId() {
404 String groupId = getModel().getGroupId();
405
406 if ((groupId == null) && (getModel().getParent() != null)) {
407 groupId = getModel().getParent().getGroupId();
408 }
409
410 return groupId;
411 }
412
413 public void setArtifactId(String artifactId) {
414 getModel().setArtifactId(artifactId);
415 }
416
417 public String getArtifactId() {
418 return getModel().getArtifactId();
419 }
420
421 public void setName(String name) {
422 getModel().setName(name);
423 }
424
425 public String getName() {
426
427 if (getModel().getName() != null) {
428 return getModel().getName();
429 } else {
430 return getArtifactId();
431 }
432 }
433
434 public void setVersion(String version) {
435 getModel().setVersion(version);
436 }
437
438 public String getVersion() {
439 String version = getModel().getVersion();
440
441 if ((version == null) && (getModel().getParent() != null)) {
442 version = getModel().getParent().getVersion();
443 }
444
445 return version;
446 }
447
448 public String getPackaging() {
449 return getModel().getPackaging();
450 }
451
452 public void setPackaging(String packaging) {
453 getModel().setPackaging(packaging);
454 }
455
456 public void setInceptionYear(String inceptionYear) {
457 getModel().setInceptionYear(inceptionYear);
458 }
459
460 public String getInceptionYear() {
461 return getModel().getInceptionYear();
462 }
463
464 public void setUrl(String url) {
465 getModel().setUrl(url);
466 }
467
468 public String getUrl() {
469 return getModel().getUrl();
470 }
471
472 public Prerequisites getPrerequisites() {
473 return getModel().getPrerequisites();
474 }
475
476 public void setIssueManagement(IssueManagement issueManagement) {
477 getModel().setIssueManagement(issueManagement);
478 }
479
480 public CiManagement getCiManagement() {
481 return getModel().getCiManagement();
482 }
483
484 public void setCiManagement(CiManagement ciManagement) {
485 getModel().setCiManagement(ciManagement);
486 }
487
488 public IssueManagement getIssueManagement() {
489 return getModel().getIssueManagement();
490 }
491
492 public void setDistributionManagement(DistributionManagement distributionManagement) {
493 getModel().setDistributionManagement(distributionManagement);
494 }
495
496 public DistributionManagement getDistributionManagement() {
497 return getModel().getDistributionManagement();
498 }
499
500 public void setDescription(String description) {
501 getModel().setDescription(description);
502 }
503
504 public String getDescription() {
505 return getModel().getDescription();
506 }
507
508 public void setOrganization(Organization organization) {
509 getModel().setOrganization(organization);
510 }
511
512 public Organization getOrganization() {
513 return getModel().getOrganization();
514 }
515
516 public void setScm(Scm scm) {
517 getModel().setScm(scm);
518 }
519
520 public Scm getScm() {
521 return getModel().getScm();
522 }
523
524 public void setMailingLists(List<MailingList> mailingLists) {
525 getModel().setMailingLists(mailingLists);
526 }
527
528 public List<MailingList> getMailingLists() {
529 return getModel().getMailingLists();
530 }
531
532 public void addMailingList(MailingList mailingList) {
533 getModel().addMailingList(mailingList);
534 }
535
536 public void setDevelopers(List<Developer> developers) {
537 getModel().setDevelopers(developers);
538 }
539
540 public List<Developer> getDevelopers() {
541 return getModel().getDevelopers();
542 }
543
544 public void addDeveloper(Developer developer) {
545 getModel().addDeveloper(developer);
546 }
547
548 public void setContributors(List<Contributor> contributors) {
549 getModel().setContributors(contributors);
550 }
551
552 public List<Contributor> getContributors() {
553 return getModel().getContributors();
554 }
555
556 public void addContributor(Contributor contributor) {
557 getModel().addContributor(contributor);
558 }
559
560 public void setBuild(Build build) {
561 getModel().setBuild(build);
562 }
563
564 public Build getBuild() {
565 return getModelBuild();
566 }
567
568 public List<Resource> getResources() {
569 return getBuild().getResources();
570 }
571
572 public List<Resource> getTestResources() {
573 return getBuild().getTestResources();
574 }
575
576 public void addResource(Resource resource) {
577 getBuild().addResource(resource);
578 }
579
580 public void addTestResource(Resource testResource) {
581 getBuild().addTestResource(testResource);
582 }
583
584 public void setLicenses(List<License> licenses) {
585 getModel().setLicenses(licenses);
586 }
587
588 public List<License> getLicenses() {
589 return getModel().getLicenses();
590 }
591
592 public void addLicense(License license) {
593 getModel().addLicense(license);
594 }
595
596 public void setArtifacts(Set<Artifact> artifacts) {
597 this.artifacts = artifacts;
598
599
600 artifactMap = null;
601 }
602
603
604
605
606
607
608
609
610
611 public Set<Artifact> getArtifacts() {
612 if (artifacts == null) {
613 if (artifactFilter == null || resolvedArtifacts == null) {
614 artifacts = new LinkedHashSet<>();
615 } else {
616 artifacts = new LinkedHashSet<>(resolvedArtifacts.size() * 2);
617 for (Artifact artifact : resolvedArtifacts) {
618 if (artifactFilter.include(artifact)) {
619 artifacts.add(artifact);
620 }
621 }
622 }
623 }
624 return artifacts;
625 }
626
627 public Map<String, Artifact> getArtifactMap() {
628 if (artifactMap == null) {
629 artifactMap = ArtifactUtils.artifactMapByVersionlessId(getArtifacts());
630 }
631 return artifactMap;
632 }
633
634 public void setPluginArtifacts(Set<Artifact> pluginArtifacts) {
635 this.pluginArtifacts = pluginArtifacts;
636
637 this.pluginArtifactMap = null;
638 }
639
640 public Set<Artifact> getPluginArtifacts() {
641 return pluginArtifacts;
642 }
643
644 public Map<String, Artifact> getPluginArtifactMap() {
645 if (pluginArtifactMap == null) {
646 pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId(getPluginArtifacts());
647 }
648
649 return pluginArtifactMap;
650 }
651
652 public void setParentArtifact(Artifact parentArtifact) {
653 this.parentArtifact = parentArtifact;
654 }
655
656 public Artifact getParentArtifact() {
657 return parentArtifact;
658 }
659
660 public List<Repository> getRepositories() {
661 return getModel().getRepositories();
662 }
663
664
665
666
667
668 public List<Plugin> getBuildPlugins() {
669 if (getModel().getBuild() == null) {
670 return Collections.emptyList();
671 }
672 return Collections.unmodifiableList(getModel().getBuild().getPlugins());
673 }
674
675 public List<String> getModules() {
676 return getModel().getModules();
677 }
678
679 public PluginManagement getPluginManagement() {
680 PluginManagement pluginMgmt = null;
681
682 Build build = getModel().getBuild();
683 if (build != null) {
684 pluginMgmt = build.getPluginManagement();
685 }
686
687 return pluginMgmt;
688 }
689
690 private Build getModelBuild() {
691 Build build = getModel().getBuild();
692
693 if (build == null) {
694 build = new Build();
695
696 getModel().setBuild(build);
697 }
698
699 return build;
700 }
701
702 public void setRemoteArtifactRepositories(List<ArtifactRepository> remoteArtifactRepositories) {
703 this.remoteArtifactRepositories = remoteArtifactRepositories;
704 this.remoteProjectRepositories = RepositoryUtils.toRepos(getRemoteArtifactRepositories());
705 }
706
707 public List<ArtifactRepository> getRemoteArtifactRepositories() {
708 if (remoteArtifactRepositories == null) {
709 remoteArtifactRepositories = new ArrayList<>();
710 }
711
712 return remoteArtifactRepositories;
713 }
714
715 public void setPluginArtifactRepositories(List<ArtifactRepository> pluginArtifactRepositories) {
716 this.pluginArtifactRepositories = pluginArtifactRepositories;
717 this.remotePluginRepositories = RepositoryUtils.toRepos(getPluginArtifactRepositories());
718 }
719
720
721
722
723
724 public List<ArtifactRepository> getPluginArtifactRepositories() {
725 if (pluginArtifactRepositories == null) {
726 pluginArtifactRepositories = new ArrayList<>();
727 }
728
729 return pluginArtifactRepositories;
730 }
731
732 public ArtifactRepository getDistributionManagementArtifactRepository() {
733 return getArtifact().isSnapshot() && (getSnapshotArtifactRepository() != null)
734 ? getSnapshotArtifactRepository()
735 : getReleaseArtifactRepository();
736 }
737
738 public List<Repository> getPluginRepositories() {
739 return getModel().getPluginRepositories();
740 }
741
742 public List<RemoteRepository> getRemoteProjectRepositories() {
743 return remoteProjectRepositories;
744 }
745
746 public List<RemoteRepository> getRemotePluginRepositories() {
747 return remotePluginRepositories;
748 }
749
750 public void setActiveProfiles(List<Profile> activeProfiles) {
751 this.activeProfiles = activeProfiles;
752 }
753
754 public List<Profile> getActiveProfiles() {
755 return activeProfiles;
756 }
757
758 public void setInjectedProfileIds(String source, List<String> injectedProfileIds) {
759 if (injectedProfileIds != null) {
760 this.injectedProfileIds.put(source, new ArrayList<>(injectedProfileIds));
761 } else {
762 this.injectedProfileIds.remove(source);
763 }
764 }
765
766
767
768
769
770
771
772
773
774
775
776 public Map<String, List<String>> getInjectedProfileIds() {
777 return this.injectedProfileIds;
778 }
779
780
781
782
783
784
785
786
787
788
789
790
791 public void addAttachedArtifact(Artifact artifact) throws DuplicateArtifactAttachmentException {
792
793 int index = attachedArtifacts.indexOf(artifact);
794 if (index >= 0) {
795 LOGGER.warn("artifact '{}' already attached, replacing previous instance", artifact);
796 attachedArtifacts.set(index, artifact);
797 } else {
798 attachedArtifacts.add(artifact);
799 }
800 }
801
802
803
804
805
806
807 public List<Artifact> getAttachedArtifacts() {
808 if (attachedArtifacts == null) {
809 attachedArtifacts = new ArrayList<>();
810 }
811 return Collections.unmodifiableList(attachedArtifacts);
812 }
813
814 public Xpp3Dom getGoalConfiguration(
815 String pluginGroupId, String pluginArtifactId, String executionId, String goalId) {
816 Xpp3Dom dom = null;
817
818 if (getBuildPlugins() != null) {
819 for (Plugin plugin : getBuildPlugins()) {
820 if (pluginGroupId.equals(plugin.getGroupId()) && pluginArtifactId.equals(plugin.getArtifactId())) {
821 dom = (Xpp3Dom) plugin.getConfiguration();
822
823 if (executionId != null) {
824 for (PluginExecution execution : plugin.getExecutions()) {
825 if (executionId.equals(execution.getId())) {
826
827 dom = (Xpp3Dom) execution.getConfiguration();
828 break;
829 }
830 }
831 }
832 break;
833 }
834 }
835 }
836
837 if (dom != null) {
838
839 dom = new Xpp3Dom(dom);
840 }
841
842 return dom;
843 }
844
845 public MavenProject getExecutionProject() {
846 return (executionProject == null ? this : executionProject);
847 }
848
849 public void setExecutionProject(MavenProject executionProject) {
850 this.executionProject = executionProject;
851 }
852
853 public List<MavenProject> getCollectedProjects() {
854 return collectedProjects;
855 }
856
857 public void setCollectedProjects(List<MavenProject> collectedProjects) {
858 this.collectedProjects = collectedProjects;
859 }
860
861
862
863
864
865
866
867 @Deprecated
868 public Set<Artifact> getDependencyArtifacts() {
869 return dependencyArtifacts;
870 }
871
872 @Deprecated
873 public void setDependencyArtifacts(Set<Artifact> dependencyArtifacts) {
874 this.dependencyArtifacts = dependencyArtifacts;
875 }
876
877 public void setReleaseArtifactRepository(ArtifactRepository releaseArtifactRepository) {
878 this.releaseArtifactRepository = releaseArtifactRepository;
879 }
880
881 public void setSnapshotArtifactRepository(ArtifactRepository snapshotArtifactRepository) {
882 this.snapshotArtifactRepository = snapshotArtifactRepository;
883 }
884
885 public void setOriginalModel(Model originalModel) {
886 this.originalModel = originalModel;
887 }
888
889 public Model getOriginalModel() {
890 return originalModel;
891 }
892
893 public void setManagedVersionMap(Map<String, Artifact> map) {
894 managedVersionMap = map;
895 }
896
897 public Map<String, Artifact> getManagedVersionMap() {
898 return managedVersionMap;
899 }
900
901 @Override
902 public boolean equals(Object other) {
903 if (other == this) {
904 return true;
905 } else if (!(other instanceof MavenProject)) {
906 return false;
907 }
908
909 MavenProject that = (MavenProject) other;
910
911 return Objects.equals(getArtifactId(), that.getArtifactId())
912 && Objects.equals(getGroupId(), that.getGroupId())
913 && Objects.equals(getVersion(), that.getVersion());
914 }
915
916 @Override
917 public int hashCode() {
918 return Objects.hash(getGroupId(), getArtifactId(), getVersion());
919 }
920
921 public List<Extension> getBuildExtensions() {
922 Build build = getBuild();
923 if ((build == null) || (build.getExtensions() == null)) {
924 return Collections.emptyList();
925 } else {
926 return Collections.unmodifiableList(build.getExtensions());
927 }
928 }
929
930 public void addProjectReference(MavenProject project) {
931 projectReferences.put(
932 getProjectReferenceId(project.getGroupId(), project.getArtifactId(), project.getVersion()), project);
933 }
934
935 public Properties getProperties() {
936 return getModel().getProperties();
937 }
938
939 public List<String> getFilters() {
940 return getBuild().getFilters();
941 }
942
943 public Map<String, MavenProject> getProjectReferences() {
944 return projectReferences;
945 }
946
947 public boolean isExecutionRoot() {
948 return executionRoot;
949 }
950
951 public void setExecutionRoot(boolean executionRoot) {
952 this.executionRoot = executionRoot;
953 }
954
955 public String getDefaultGoal() {
956 return getBuild() != null ? getBuild().getDefaultGoal() : null;
957 }
958
959 public Plugin getPlugin(String pluginKey) {
960 return getBuild().getPluginsAsMap().get(pluginKey);
961 }
962
963
964
965
966 @Override
967 public String toString() {
968 StringBuilder sb = new StringBuilder(128);
969 sb.append("MavenProject: ");
970 sb.append(getGroupId());
971 sb.append(':');
972 sb.append(getArtifactId());
973 sb.append(':');
974 sb.append(getVersion());
975 if (getFile() != null) {
976 sb.append(" @ ");
977 sb.append(getFile().getPath());
978 }
979
980 return sb.toString();
981 }
982
983
984
985
986 @Override
987 public MavenProject clone() {
988 MavenProject clone;
989 try {
990 clone = (MavenProject) super.clone();
991 } catch (CloneNotSupportedException e) {
992 throw new UnsupportedOperationException(e);
993 }
994
995 clone.deepCopy(this);
996
997 return clone;
998 }
999
1000 public void setModel(Model model) {
1001 this.model = model;
1002 }
1003
1004 protected void setAttachedArtifacts(List<Artifact> attachedArtifacts) {
1005 this.attachedArtifacts = attachedArtifacts;
1006 }
1007
1008 protected void setCompileSourceRoots(List<String> compileSourceRoots) {
1009 this.compileSourceRoots = compileSourceRoots;
1010 }
1011
1012 protected void setTestCompileSourceRoots(List<String> testCompileSourceRoots) {
1013 this.testCompileSourceRoots = testCompileSourceRoots;
1014 }
1015
1016 protected ArtifactRepository getReleaseArtifactRepository() {
1017 return releaseArtifactRepository;
1018 }
1019
1020 protected ArtifactRepository getSnapshotArtifactRepository() {
1021 return snapshotArtifactRepository;
1022 }
1023
1024 private void deepCopy(MavenProject project) {
1025
1026
1027
1028 file = project.file;
1029 basedir = project.basedir;
1030
1031
1032
1033 if (project.getDependencyArtifacts() != null) {
1034 setDependencyArtifacts(Collections.unmodifiableSet(project.getDependencyArtifacts()));
1035 }
1036
1037 if (project.getArtifacts() != null) {
1038 setArtifacts(Collections.unmodifiableSet(project.getArtifacts()));
1039 }
1040
1041 if (project.getParentFile() != null) {
1042 parentFile = new File(project.getParentFile().getAbsolutePath());
1043 }
1044
1045 if (project.getPluginArtifacts() != null) {
1046 setPluginArtifacts(Collections.unmodifiableSet(project.getPluginArtifacts()));
1047 }
1048
1049 if (project.getReportArtifacts() != null) {
1050 setReportArtifacts(Collections.unmodifiableSet(project.getReportArtifacts()));
1051 }
1052
1053 if (project.getExtensionArtifacts() != null) {
1054 setExtensionArtifacts(Collections.unmodifiableSet(project.getExtensionArtifacts()));
1055 }
1056
1057 setParentArtifact((project.getParentArtifact()));
1058
1059 if (project.getRemoteArtifactRepositories() != null) {
1060 setRemoteArtifactRepositories(Collections.unmodifiableList(project.getRemoteArtifactRepositories()));
1061 }
1062
1063 if (project.getPluginArtifactRepositories() != null) {
1064 setPluginArtifactRepositories(Collections.unmodifiableList(project.getPluginArtifactRepositories()));
1065 }
1066
1067 if (project.getActiveProfiles() != null) {
1068 setActiveProfiles((Collections.unmodifiableList(project.getActiveProfiles())));
1069 }
1070
1071 if (project.getAttachedArtifacts() != null) {
1072
1073 setAttachedArtifacts(new ArrayList<>(project.getAttachedArtifacts()));
1074 }
1075
1076 if (project.getCompileSourceRoots() != null) {
1077
1078 setCompileSourceRoots((new ArrayList<>(project.getCompileSourceRoots())));
1079 }
1080
1081 if (project.getTestCompileSourceRoots() != null) {
1082 setTestCompileSourceRoots((new ArrayList<>(project.getTestCompileSourceRoots())));
1083 }
1084
1085 if (project.getScriptSourceRoots() != null) {
1086 setScriptSourceRoots((new ArrayList<>(project.getScriptSourceRoots())));
1087 }
1088
1089 if (project.getModel() != null) {
1090 setModel(project.getModel().clone());
1091 }
1092
1093 if (project.getOriginalModel() != null) {
1094 setOriginalModel(project.getOriginalModel());
1095 }
1096
1097 setExecutionRoot(project.isExecutionRoot());
1098
1099 if (project.getArtifact() != null) {
1100 setArtifact(ArtifactUtils.copyArtifact(project.getArtifact()));
1101 }
1102
1103 if (project.getManagedVersionMap() != null) {
1104 setManagedVersionMap(project.getManagedVersionMap());
1105 }
1106
1107 lifecyclePhases.addAll(project.lifecyclePhases);
1108 }
1109
1110 private void addArtifactPath(Artifact artifact, List<String> classpath) {
1111 File file = artifact.getFile();
1112 if (file != null) {
1113 classpath.add(file.getPath());
1114 }
1115 }
1116
1117 private static String getProjectReferenceId(String groupId, String artifactId, String version) {
1118 StringBuilder buffer = new StringBuilder(128);
1119 buffer.append(groupId).append(':').append(artifactId).append(':').append(version);
1120 return buffer.toString();
1121 }
1122
1123
1124
1125
1126
1127
1128 public void setContextValue(String key, Object value) {
1129 if (context == null) {
1130 context = new HashMap<>();
1131 }
1132 if (value != null) {
1133 context.put(key, value);
1134 } else {
1135 context.remove(key);
1136 }
1137 }
1138
1139
1140
1141
1142 public Object getContextValue(String key) {
1143 if (context == null) {
1144 return null;
1145 }
1146 return context.get(key);
1147 }
1148
1149
1150
1151
1152
1153
1154
1155
1156 public void setClassRealm(ClassRealm classRealm) {
1157 this.classRealm = classRealm;
1158 }
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168 public ClassRealm getClassRealm() {
1169 return classRealm;
1170 }
1171
1172
1173
1174
1175
1176
1177
1178
1179 public void setExtensionDependencyFilter(DependencyFilter extensionDependencyFilter) {
1180 this.extensionDependencyFilter = extensionDependencyFilter;
1181 }
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191 public DependencyFilter getExtensionDependencyFilter() {
1192 return extensionDependencyFilter;
1193 }
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203 public void setResolvedArtifacts(Set<Artifact> artifacts) {
1204 this.resolvedArtifacts = (artifacts != null) ? artifacts : Collections.<Artifact>emptySet();
1205 this.artifacts = null;
1206 this.artifactMap = null;
1207 }
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217 public void setArtifactFilter(ArtifactFilter artifactFilter) {
1218 this.artifactFilter = artifactFilter;
1219 this.artifacts = null;
1220 this.artifactMap = null;
1221 }
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231 public boolean hasLifecyclePhase(String phase) {
1232 return lifecyclePhases.contains(phase);
1233 }
1234
1235
1236
1237
1238
1239
1240
1241
1242 public void addLifecyclePhase(String lifecyclePhase) {
1243 lifecyclePhases.add(lifecyclePhase);
1244 }
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258 private ProjectBuildingRequest projectBuilderConfiguration;
1259
1260 private Map<String, String> moduleAdjustments;
1261
1262 @Deprecated
1263 public String getModulePathAdjustment(MavenProject moduleProject) throws IOException {
1264
1265
1266 String module = moduleProject.getArtifactId();
1267
1268 File moduleFile = moduleProject.getFile();
1269
1270 if (moduleFile != null) {
1271 File moduleDir = moduleFile.getCanonicalFile().getParentFile();
1272
1273 module = moduleDir.getName();
1274 }
1275
1276 if (moduleAdjustments == null) {
1277 moduleAdjustments = new HashMap<>();
1278
1279 List<String> modules = getModules();
1280 if (modules != null) {
1281 for (String modulePath : modules) {
1282 String moduleName = modulePath;
1283
1284 if (moduleName.endsWith("/") || moduleName.endsWith("\\")) {
1285 moduleName = moduleName.substring(0, moduleName.length() - 1);
1286 }
1287
1288 int lastSlash = moduleName.lastIndexOf('/');
1289
1290 if (lastSlash < 0) {
1291 lastSlash = moduleName.lastIndexOf('\\');
1292 }
1293
1294 String adjustment = null;
1295
1296 if (lastSlash > -1) {
1297 moduleName = moduleName.substring(lastSlash + 1);
1298 adjustment = modulePath.substring(0, lastSlash);
1299 }
1300
1301 moduleAdjustments.put(moduleName, adjustment);
1302 }
1303 }
1304 }
1305
1306 return moduleAdjustments.get(module);
1307 }
1308
1309 @Deprecated
1310 public Set<Artifact> createArtifacts(ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter)
1311 throws InvalidDependencyVersionException {
1312 return MavenMetadataSource.createArtifacts(
1313 artifactFactory, getModel().getDependencies(), inheritedScope, filter, this);
1314 }
1315
1316 @Deprecated
1317 protected void setScriptSourceRoots(List<String> scriptSourceRoots) {
1318 this.scriptSourceRoots = scriptSourceRoots;
1319 }
1320
1321 @Deprecated
1322 public void addScriptSourceRoot(String path) {
1323 if (path != null) {
1324 path = path.trim();
1325 if (path.length() != 0) {
1326 if (!getScriptSourceRoots().contains(path)) {
1327 getScriptSourceRoots().add(path);
1328 }
1329 }
1330 }
1331 }
1332
1333 @Deprecated
1334 public List<String> getScriptSourceRoots() {
1335 return scriptSourceRoots;
1336 }
1337
1338 @Deprecated
1339 public List<Artifact> getCompileArtifacts() {
1340 List<Artifact> list = new ArrayList<>(getArtifacts().size());
1341
1342 for (Artifact a : getArtifacts()) {
1343
1344 if (a.getArtifactHandler().isAddedToClasspath()) {
1345
1346 if (Artifact.SCOPE_COMPILE.equals(a.getScope())
1347 || Artifact.SCOPE_PROVIDED.equals(a.getScope())
1348 || Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
1349 list.add(a);
1350 }
1351 }
1352 }
1353 return list;
1354 }
1355
1356 @Deprecated
1357 public List<Dependency> getCompileDependencies() {
1358 Set<Artifact> artifacts = getArtifacts();
1359
1360 if ((artifacts == null) || artifacts.isEmpty()) {
1361 return Collections.emptyList();
1362 }
1363
1364 List<Dependency> list = new ArrayList<>(artifacts.size());
1365
1366 for (Artifact a : getArtifacts()) {
1367
1368 if (Artifact.SCOPE_COMPILE.equals(a.getScope())
1369 || Artifact.SCOPE_PROVIDED.equals(a.getScope())
1370 || Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
1371 Dependency dependency = new Dependency();
1372
1373 dependency.setArtifactId(a.getArtifactId());
1374 dependency.setGroupId(a.getGroupId());
1375 dependency.setVersion(a.getVersion());
1376 dependency.setScope(a.getScope());
1377 dependency.setType(a.getType());
1378 dependency.setClassifier(a.getClassifier());
1379
1380 list.add(dependency);
1381 }
1382 }
1383 return Collections.unmodifiableList(list);
1384 }
1385
1386 @Deprecated
1387 public List<Artifact> getTestArtifacts() {
1388 List<Artifact> list = new ArrayList<>(getArtifacts().size());
1389
1390 for (Artifact a : getArtifacts()) {
1391
1392 if (a.getArtifactHandler().isAddedToClasspath()) {
1393 list.add(a);
1394 }
1395 }
1396 return list;
1397 }
1398
1399 @Deprecated
1400 public List<Dependency> getTestDependencies() {
1401 Set<Artifact> artifacts = getArtifacts();
1402
1403 if ((artifacts == null) || artifacts.isEmpty()) {
1404 return Collections.emptyList();
1405 }
1406
1407 List<Dependency> list = new ArrayList<>(artifacts.size());
1408
1409 for (Artifact a : getArtifacts()) {
1410 Dependency dependency = new Dependency();
1411
1412 dependency.setArtifactId(a.getArtifactId());
1413 dependency.setGroupId(a.getGroupId());
1414 dependency.setVersion(a.getVersion());
1415 dependency.setScope(a.getScope());
1416 dependency.setType(a.getType());
1417 dependency.setClassifier(a.getClassifier());
1418
1419 list.add(dependency);
1420 }
1421 return Collections.unmodifiableList(list);
1422 }
1423
1424 @Deprecated
1425 public List<Dependency> getRuntimeDependencies() {
1426 Set<Artifact> artifacts = getArtifacts();
1427
1428 if ((artifacts == null) || artifacts.isEmpty()) {
1429 return Collections.emptyList();
1430 }
1431
1432 List<Dependency> list = new ArrayList<>(artifacts.size());
1433
1434 for (Artifact a : getArtifacts()) {
1435
1436 if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope())) {
1437 Dependency dependency = new Dependency();
1438
1439 dependency.setArtifactId(a.getArtifactId());
1440 dependency.setGroupId(a.getGroupId());
1441 dependency.setVersion(a.getVersion());
1442 dependency.setScope(a.getScope());
1443 dependency.setType(a.getType());
1444 dependency.setClassifier(a.getClassifier());
1445
1446 list.add(dependency);
1447 }
1448 }
1449 return Collections.unmodifiableList(list);
1450 }
1451
1452 @Deprecated
1453 public List<Artifact> getRuntimeArtifacts() {
1454 List<Artifact> list = new ArrayList<>(getArtifacts().size());
1455
1456 for (Artifact a : getArtifacts()) {
1457
1458 if (a.getArtifactHandler().isAddedToClasspath()
1459
1460 && (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope()))) {
1461 list.add(a);
1462 }
1463 }
1464 return list;
1465 }
1466
1467 @Deprecated
1468 public List<String> getSystemClasspathElements() throws DependencyResolutionRequiredException {
1469 List<String> list = new ArrayList<>(getArtifacts().size());
1470
1471 String d = getBuild().getOutputDirectory();
1472 if (d != null) {
1473 list.add(d);
1474 }
1475
1476 for (Artifact a : getArtifacts()) {
1477 if (a.getArtifactHandler().isAddedToClasspath()) {
1478
1479 if (Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
1480 addArtifactPath(a, list);
1481 }
1482 }
1483 }
1484 return list;
1485 }
1486
1487 @Deprecated
1488 public List<Artifact> getSystemArtifacts() {
1489 List<Artifact> list = new ArrayList<>(getArtifacts().size());
1490
1491 for (Artifact a : getArtifacts()) {
1492
1493 if (a.getArtifactHandler().isAddedToClasspath()) {
1494
1495 if (Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
1496 list.add(a);
1497 }
1498 }
1499 }
1500 return list;
1501 }
1502
1503 @Deprecated
1504 public List<Dependency> getSystemDependencies() {
1505 Set<Artifact> artifacts = getArtifacts();
1506
1507 if ((artifacts == null) || artifacts.isEmpty()) {
1508 return Collections.emptyList();
1509 }
1510
1511 List<Dependency> list = new ArrayList<>(artifacts.size());
1512
1513 for (Artifact a : getArtifacts()) {
1514
1515 if (Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
1516 Dependency dependency = new Dependency();
1517
1518 dependency.setArtifactId(a.getArtifactId());
1519 dependency.setGroupId(a.getGroupId());
1520 dependency.setVersion(a.getVersion());
1521 dependency.setScope(a.getScope());
1522 dependency.setType(a.getType());
1523 dependency.setClassifier(a.getClassifier());
1524
1525 list.add(dependency);
1526 }
1527 }
1528 return Collections.unmodifiableList(list);
1529 }
1530
1531 @Deprecated
1532 public void setReporting(Reporting reporting) {
1533 getModel().setReporting(reporting);
1534 }
1535
1536 @Deprecated
1537 public Reporting getReporting() {
1538 return getModel().getReporting();
1539 }
1540
1541 @Deprecated
1542 public void setReportArtifacts(Set<Artifact> reportArtifacts) {
1543 this.reportArtifacts = reportArtifacts;
1544
1545 reportArtifactMap = null;
1546 }
1547
1548 @Deprecated
1549 public Set<Artifact> getReportArtifacts() {
1550 return reportArtifacts;
1551 }
1552
1553 @Deprecated
1554 public Map<String, Artifact> getReportArtifactMap() {
1555 if (reportArtifactMap == null) {
1556 reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId(getReportArtifacts());
1557 }
1558
1559 return reportArtifactMap;
1560 }
1561
1562 @Deprecated
1563 public void setExtensionArtifacts(Set<Artifact> extensionArtifacts) {
1564 this.extensionArtifacts = extensionArtifacts;
1565
1566 extensionArtifactMap = null;
1567 }
1568
1569 @Deprecated
1570 public Set<Artifact> getExtensionArtifacts() {
1571 return extensionArtifacts;
1572 }
1573
1574 @Deprecated
1575 public Map<String, Artifact> getExtensionArtifactMap() {
1576 if (extensionArtifactMap == null) {
1577 extensionArtifactMap = ArtifactUtils.artifactMapByVersionlessId(getExtensionArtifacts());
1578 }
1579
1580 return extensionArtifactMap;
1581 }
1582
1583 @Deprecated
1584 public List<ReportPlugin> getReportPlugins() {
1585 if (getModel().getReporting() == null) {
1586 return Collections.emptyList();
1587 }
1588 return Collections.unmodifiableList(getModel().getReporting().getPlugins());
1589 }
1590
1591 @Deprecated
1592 public Xpp3Dom getReportConfiguration(String pluginGroupId, String pluginArtifactId, String reportSetId) {
1593 Xpp3Dom dom = null;
1594
1595
1596
1597
1598
1599
1600
1601 if (getReportPlugins() != null) {
1602 for (ReportPlugin plugin : getReportPlugins()) {
1603 if (pluginGroupId.equals(plugin.getGroupId()) && pluginArtifactId.equals(plugin.getArtifactId())) {
1604 dom = (Xpp3Dom) plugin.getConfiguration();
1605
1606 if (reportSetId != null) {
1607 ReportSet reportSet = plugin.getReportSetsAsMap().get(reportSetId);
1608 if (reportSet != null) {
1609 Xpp3Dom executionConfiguration = (Xpp3Dom) reportSet.getConfiguration();
1610 if (executionConfiguration != null) {
1611 Xpp3Dom newDom = new Xpp3Dom(executionConfiguration);
1612 dom = Xpp3Dom.mergeXpp3Dom(newDom, dom);
1613 }
1614 }
1615 }
1616 break;
1617 }
1618 }
1619 }
1620
1621 if (dom != null) {
1622
1623 dom = new Xpp3Dom(dom);
1624 }
1625
1626 return dom;
1627 }
1628
1629
1630
1631
1632 @Deprecated
1633 public void attachArtifact(String type, String classifier, File file) {}
1634
1635
1636
1637
1638 @Deprecated
1639 public void writeModel(Writer writer) throws IOException {
1640 MavenXpp3Writer pomWriter = new MavenXpp3Writer();
1641 pomWriter.write(writer, getModel());
1642 }
1643
1644
1645
1646
1647 @Deprecated
1648 public void writeOriginalModel(Writer writer) throws IOException {
1649 MavenXpp3Writer pomWriter = new MavenXpp3Writer();
1650 pomWriter.write(writer, getOriginalModel());
1651 }
1652
1653 @Deprecated
1654 public Artifact replaceWithActiveArtifact(Artifact pluginArtifact) {
1655 return pluginArtifact;
1656 }
1657
1658
1659
1660
1661
1662
1663
1664
1665 @Deprecated
1666 public ProjectBuildingRequest getProjectBuildingRequest() {
1667 return projectBuilderConfiguration;
1668 }
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678 @Deprecated
1679 public void setProjectBuildingRequest(ProjectBuildingRequest projectBuildingRequest) {
1680 this.projectBuilderConfiguration = projectBuildingRequest;
1681 }
1682 }