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