View Javadoc

1   package org.apache.maven.plugin.dependency.testUtils.stubs;
2   
3   /* 
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.io.Writer;
25  import java.util.Collections;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.Properties;
29  import java.util.Set;
30  
31  import org.apache.maven.artifact.Artifact;
32  import org.apache.maven.artifact.DefaultArtifact;
33  import org.apache.maven.artifact.DependencyResolutionRequiredException;
34  import org.apache.maven.artifact.factory.ArtifactFactory;
35  import org.apache.maven.artifact.handler.ArtifactHandler;
36  import org.apache.maven.artifact.repository.ArtifactRepository;
37  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
38  import org.apache.maven.artifact.versioning.VersionRange;
39  import org.apache.maven.model.Build;
40  import org.apache.maven.model.CiManagement;
41  import org.apache.maven.model.Contributor;
42  import org.apache.maven.model.DependencyManagement;
43  import org.apache.maven.model.Developer;
44  import org.apache.maven.model.DistributionManagement;
45  import org.apache.maven.model.IssueManagement;
46  import org.apache.maven.model.License;
47  import org.apache.maven.model.MailingList;
48  import org.apache.maven.model.Model;
49  import org.apache.maven.model.Organization;
50  import org.apache.maven.model.Plugin;
51  import org.apache.maven.model.PluginManagement;
52  import org.apache.maven.model.Prerequisites;
53  import org.apache.maven.model.Reporting;
54  import org.apache.maven.model.Resource;
55  import org.apache.maven.model.Scm;
56  import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub;
57  import org.apache.maven.project.MavenProject;
58  import org.apache.maven.project.artifact.InvalidDependencyVersionException;
59  import org.codehaus.plexus.PlexusTestCase;
60  import org.codehaus.plexus.util.xml.Xpp3Dom;
61  
62  /**
63   * very simple stub of maven project, going to take a lot of work to make it
64   * useful as a stub though
65   */
66  public class DependencyProjectStub
67      extends MavenProject
68  {
69      private String groupId;
70  
71      private String artifactId;
72  
73      private String name;
74  
75      private Model model;
76  
77      private MavenProject parent;
78  
79      private List dependencies;
80  
81      private File file;
82  
83      private List collectedProjects;
84  
85      private List attachedArtifacts;
86  
87      private List compileSourceRoots;
88  
89      private List testCompileSourceRoots;
90  
91      private List scriptSourceRoots;
92  
93      private List pluginArtifactRepositories;
94  
95      // private ArtifactRepository releaseArtifactRepository;
96  
97      // private ArtifactRepository snapshotArtifactRepository;
98  
99      private List activeProfiles;
100 
101     private Set dependencyArtifacts;
102 
103     private DependencyManagement dependencyManagement;
104 
105     private Artifact artifact;
106 
107     // private Map artifactMap;
108 
109     private Model originalModel;
110 
111     // private Map pluginArtifactMap;
112 
113     // private Map reportArtifactMap;
114 
115     // private Map extensionArtifactMap;
116 
117     // private Map projectReferences;
118 
119     // private Build buildOverlay;
120 
121     private boolean executionRoot;
122 
123     private List compileArtifacts;
124 
125     private List compileDependencies;
126 
127     private List systemDependencies;
128 
129     private List testClasspathElements;
130 
131     private List testDependencies;
132 
133     private List systemClasspathElements;
134 
135     private List systemArtifacts;
136 
137     private List testArtifacts;
138 
139     private List runtimeArtifacts;
140 
141     private List runtimeDependencies;
142 
143     private List runtimeClasspathElements;
144 
145     private String modelVersion;
146 
147     private String packaging;
148 
149     private String inceptionYear;
150 
151     private String url;
152 
153     private String description;
154 
155     private String version;
156 
157     private String defaultGoal;
158 
159     private Set artifacts;
160 
161     public DependencyProjectStub()
162     {
163         super( (Model) null );
164     }
165 
166     // kinda dangerous...
167     public DependencyProjectStub( Model model )
168     {
169         // super(model);
170         super( (Model) null );
171     }
172 
173     // kinda dangerous...
174     public DependencyProjectStub( MavenProject project )
175     {
176         // super(project);
177         super( (Model) null );
178     }
179 
180     public String getModulePathAdjustment( MavenProject mavenProject )
181         throws IOException
182     {
183         return "";
184     }
185 
186     public Artifact getArtifact()
187     {
188         if ( artifact == null )
189         {
190             ArtifactHandler ah = new DefaultArtifactHandlerStub( "jar", null );
191 
192             VersionRange vr = VersionRange.createFromVersion( "1.0" );
193             Artifact art = new DefaultArtifact( "group", "artifact", vr, Artifact.SCOPE_COMPILE, "jar", null, ah, false );
194             setArtifact( art );
195         }
196         return artifact;
197     }
198 
199     public void setArtifact( Artifact artifact )
200     {
201         this.artifact = artifact;
202     }
203 
204     public Model getModel()
205     {
206         return model;
207     }
208 
209     public MavenProject getParent()
210     {
211         return parent;
212     }
213 
214     public void setParent( MavenProject mavenProject )
215     {
216         this.parent = mavenProject;
217     }
218 
219     public void setRemoteArtifactRepositories( List list )
220     {
221 
222     }
223 
224     public List getRemoteArtifactRepositories()
225     {
226         return Collections.singletonList( "" );
227     }
228 
229     public boolean hasParent()
230     {
231         if ( parent != null )
232         {
233             return true;
234         }
235         else
236         {
237             return false;
238         }
239     }
240 
241     public File getFile()
242     {
243         return file;
244     }
245 
246     public void setFile( File file )
247     {
248         this.file = file;
249     }
250 
251     public File getBasedir()
252     {
253         return new File( PlexusTestCase.getBasedir() );
254     }
255 
256     public void setDependencies( List list )
257     {
258         dependencies = list;
259     }
260 
261     public List getDependencies()
262     {
263         if ( dependencies == null )
264         {
265             dependencies = Collections.EMPTY_LIST;
266         }
267         return dependencies;
268     }
269 
270     public void setDependencyManagement(DependencyManagement depMgt)
271     {
272         this.dependencyManagement = depMgt;
273     }
274     public DependencyManagement getDependencyManagement()
275     {
276         if ( dependencyManagement == null )
277         {
278             dependencyManagement = new DependencyManagement();
279         }
280 
281         return dependencyManagement;
282     }
283 
284     public void addCompileSourceRoot( String string )
285     {
286         if ( compileSourceRoots == null )
287         {
288             compileSourceRoots = Collections.singletonList( string );
289         }
290         else
291         {
292             compileSourceRoots.add( string );
293         }
294     }
295 
296     public void addScriptSourceRoot( String string )
297     {
298         if ( scriptSourceRoots == null )
299         {
300             scriptSourceRoots = Collections.singletonList( string );
301         }
302         else
303         {
304             scriptSourceRoots.add( string );
305         }
306     }
307 
308     public void addTestCompileSourceRoot( String string )
309     {
310         if ( testCompileSourceRoots == null )
311         {
312             testCompileSourceRoots = Collections.singletonList( string );
313         }
314         else
315         {
316             testCompileSourceRoots.add( string );
317         }
318     }
319 
320     public List getCompileSourceRoots()
321     {
322         return compileSourceRoots;
323     }
324 
325     public List getScriptSourceRoots()
326     {
327         return scriptSourceRoots;
328     }
329 
330     public List getTestCompileSourceRoots()
331     {
332         return testCompileSourceRoots;
333     }
334 
335     public List getCompileClasspathElements()
336         throws DependencyResolutionRequiredException
337     {
338         return compileSourceRoots;
339     }
340 
341     public void setCompileArtifacts( List compileArtifacts )
342     {
343         this.compileArtifacts = compileArtifacts;
344     }
345 
346     public List getCompileArtifacts()
347     {
348         return compileArtifacts;
349     }
350 
351     public List getCompileDependencies()
352     {
353         return compileDependencies;
354     }
355 
356     public List getTestClasspathElements()
357         throws DependencyResolutionRequiredException
358     {
359         return testClasspathElements;
360     }
361 
362     public List getTestArtifacts()
363     {
364         return testArtifacts;
365     }
366 
367     public List getTestDependencies()
368     {
369         return testDependencies;
370     }
371 
372     public List getRuntimeClasspathElements()
373         throws DependencyResolutionRequiredException
374     {
375         return runtimeClasspathElements;
376     }
377 
378     public List getRuntimeArtifacts()
379     {
380         return runtimeArtifacts;
381     }
382 
383     public List getRuntimeDependencies()
384     {
385         return runtimeDependencies;
386     }
387 
388     public List getSystemClasspathElements()
389         throws DependencyResolutionRequiredException
390     {
391         return systemClasspathElements;
392     }
393 
394     public List getSystemArtifacts()
395     {
396         return systemArtifacts;
397     }
398 
399     public void setRuntimeClasspathElements( List runtimeClasspathElements )
400     {
401         this.runtimeClasspathElements = runtimeClasspathElements;
402     }
403 
404     public void setAttachedArtifacts( List attachedArtifacts )
405     {
406         this.attachedArtifacts = attachedArtifacts;
407     }
408 
409     public void setCompileSourceRoots( List compileSourceRoots )
410     {
411         this.compileSourceRoots = compileSourceRoots;
412     }
413 
414     public void setTestCompileSourceRoots( List testCompileSourceRoots )
415     {
416         this.testCompileSourceRoots = testCompileSourceRoots;
417     }
418 
419     public void setScriptSourceRoots( List scriptSourceRoots )
420     {
421         this.scriptSourceRoots = scriptSourceRoots;
422     }
423 
424     public void setArtifactMap( Map artifactMap )
425     {
426         // this.artifactMap = artifactMap;
427     }
428 
429     public void setPluginArtifactMap( Map pluginArtifactMap )
430     {
431         // this.pluginArtifactMap = pluginArtifactMap;
432     }
433 
434     public void setReportArtifactMap( Map reportArtifactMap )
435     {
436         // this.reportArtifactMap = reportArtifactMap;
437     }
438 
439     public void setExtensionArtifactMap( Map extensionArtifactMap )
440     {
441         // this.extensionArtifactMap = extensionArtifactMap;
442     }
443 
444     public void setProjectReferences( Map projectReferences )
445     {
446         // this.projectReferences = projectReferences;
447     }
448 
449     public void setBuildOverlay( Build buildOverlay )
450     {
451         // this.buildOverlay = buildOverlay;
452     }
453 
454     public void setCompileDependencies( List compileDependencies )
455     {
456         this.compileDependencies = compileDependencies;
457     }
458 
459     public void setSystemDependencies( List systemDependencies )
460     {
461         this.systemDependencies = systemDependencies;
462     }
463 
464     public void setTestClasspathElements( List testClasspathElements )
465     {
466         this.testClasspathElements = testClasspathElements;
467     }
468 
469     public void setTestDependencies( List testDependencies )
470     {
471         this.testDependencies = testDependencies;
472     }
473 
474     public void setSystemClasspathElements( List systemClasspathElements )
475     {
476         this.systemClasspathElements = systemClasspathElements;
477     }
478 
479     public void setSystemArtifacts( List systemArtifacts )
480     {
481         this.systemArtifacts = systemArtifacts;
482     }
483 
484     public void setTestArtifacts( List testArtifacts )
485     {
486         this.testArtifacts = testArtifacts;
487     }
488 
489     public void setRuntimeArtifacts( List runtimeArtifacts )
490     {
491         this.runtimeArtifacts = runtimeArtifacts;
492     }
493 
494     public void setRuntimeDependencies( List runtimeDependencies )
495     {
496         this.runtimeDependencies = runtimeDependencies;
497     }
498 
499     public void setModel( Model model )
500     {
501         this.model = model;
502     }
503 
504     public List getSystemDependencies()
505     {
506         return systemDependencies;
507     }
508 
509     public void setModelVersion( String string )
510     {
511         this.modelVersion = string;
512     }
513 
514     public String getModelVersion()
515     {
516         return modelVersion;
517     }
518 
519     public String getId()
520     {
521         return "";
522     }
523 
524     public void setGroupId( String string )
525     {
526         this.groupId = string;
527     }
528 
529     public String getGroupId()
530     {
531         return groupId;
532     }
533 
534     public void setArtifactId( String string )
535     {
536         this.artifactId = string;
537     }
538 
539     public String getArtifactId()
540     {
541         return artifactId;
542     }
543 
544     public void setName( String string )
545     {
546         this.name = string;
547     }
548 
549     public String getName()
550     {
551         return name;
552     }
553 
554     public void setVersion( String string )
555     {
556         this.version = string;
557     }
558 
559     public String getVersion()
560     {
561         return version;
562     }
563 
564     public String getPackaging()
565     {
566         return packaging;
567     }
568 
569     public void setPackaging( String string )
570     {
571         this.packaging = string;
572     }
573 
574     public void setInceptionYear( String string )
575     {
576         this.inceptionYear = string;
577     }
578 
579     public String getInceptionYear()
580     {
581         return inceptionYear;
582     }
583 
584     public void setUrl( String string )
585     {
586         this.url = string;
587     }
588 
589     public String getUrl()
590     {
591         return url;
592     }
593 
594     public Prerequisites getPrerequisites()
595     {
596         return null;
597     }
598 
599     public void setIssueManagement( IssueManagement issueManagement )
600     {
601 
602     }
603 
604     public CiManagement getCiManagement()
605     {
606         return null;
607     }
608 
609     public void setCiManagement( CiManagement ciManagement )
610     {
611 
612     }
613 
614     public IssueManagement getIssueManagement()
615     {
616         return null;
617     }
618 
619     public void setDistributionManagement( DistributionManagement distributionManagement )
620     {
621 
622     }
623 
624     public DistributionManagement getDistributionManagement()
625     {
626         return null;
627     }
628 
629     public void setDescription( String string )
630     {
631         this.description = string;
632     }
633 
634     public String getDescription()
635     {
636         return description;
637     }
638 
639     public void setOrganization( Organization organization )
640     {
641 
642     }
643 
644     public Organization getOrganization()
645     {
646         return null;
647     }
648 
649     public void setScm( Scm scm )
650     {
651 
652     }
653 
654     public Scm getScm()
655     {
656         return null;
657     }
658 
659     public void setMailingLists( List list )
660     {
661 
662     }
663 
664     public List getMailingLists()
665     {
666         return Collections.singletonList( "" );
667     }
668 
669     public void addMailingList( MailingList mailingList )
670     {
671 
672     }
673 
674     public void setDevelopers( List list )
675     {
676 
677     }
678 
679     public List getDevelopers()
680     {
681         return Collections.singletonList( "" );
682     }
683 
684     public void addDeveloper( Developer developer )
685     {
686 
687     }
688 
689     public void setContributors( List list )
690     {
691 
692     }
693 
694     public List getContributors()
695     {
696         return Collections.singletonList( "" );
697     }
698 
699     public void addContributor( Contributor contributor )
700     {
701 
702     }
703 
704     public void setBuild( Build build )
705     {
706 
707     }
708 
709     public Build getBuild()
710     {
711         return null;
712     }
713 
714     public List getResources()
715     {
716         return Collections.singletonList( "" );
717     }
718 
719     public List getTestResources()
720     {
721         return Collections.singletonList( "" );
722     }
723 
724     public void addResource( Resource resource )
725     {
726 
727     }
728 
729     public void addTestResource( Resource resource )
730     {
731 
732     }
733 
734     public void setReporting( Reporting reporting )
735     {
736 
737     }
738 
739     public Reporting getReporting()
740     {
741         return null;
742     }
743 
744     public void setLicenses( List list )
745     {
746 
747     }
748 
749     public List getLicenses()
750     {
751         return Collections.singletonList( "" );
752     }
753 
754     public void addLicense( License license )
755     {
756 
757     }
758 
759     public void setArtifacts( Set set )
760     {
761         this.artifacts = set;
762     }
763 
764     public Set getArtifacts()
765     {
766         if ( artifacts == null )
767         {
768             return Collections.EMPTY_SET;
769         }
770         else
771         {
772             return artifacts;
773         }
774     }
775 
776     public Map getArtifactMap()
777     {
778         return Collections.singletonMap( "", "" );
779     }
780 
781     public void setPluginArtifacts( Set set )
782     {
783 
784     }
785 
786     public Set getPluginArtifacts()
787     {
788         return Collections.singleton( "" );
789     }
790 
791     public Map getPluginArtifactMap()
792     {
793         return Collections.singletonMap( "", "" );
794     }
795 
796     public void setReportArtifacts( Set set )
797     {
798 
799     }
800 
801     public Set getReportArtifacts()
802     {
803         return Collections.singleton( "" );
804     }
805 
806     public Map getReportArtifactMap()
807     {
808         return Collections.singletonMap( "", "" );
809     }
810 
811     public void setExtensionArtifacts( Set set )
812     {
813 
814     }
815 
816     public Set getExtensionArtifacts()
817     {
818         return Collections.singleton( "" );
819     }
820 
821     public Map getExtensionArtifactMap()
822     {
823         return Collections.singletonMap( "", "" );
824     }
825 
826     public void setParentArtifact( Artifact artifact )
827     {
828 
829     }
830 
831     public Artifact getParentArtifact()
832     {
833         return null;
834     }
835 
836     public List getRepositories()
837     {
838         return Collections.singletonList( "" );
839     }
840 
841     public List getReportPlugins()
842     {
843         return Collections.singletonList( "" );
844     }
845 
846     public List getBuildPlugins()
847     {
848         return Collections.singletonList( "" );
849     }
850 
851     public List getModules()
852     {
853         return Collections.singletonList( "" );
854     }
855 
856     public PluginManagement getPluginManagement()
857     {
858         return null;
859     }
860 
861     public void addPlugin( Plugin plugin )
862     {
863 
864     }
865 
866     public void injectPluginManagementInfo( Plugin plugin )
867     {
868 
869     }
870 
871     public List getCollectedProjects()
872     {
873         return collectedProjects;
874     }
875 
876     public void setCollectedProjects( List list )
877     {
878         this.collectedProjects = list;
879     }
880 
881     public void setPluginArtifactRepositories( List list )
882     {
883         this.pluginArtifactRepositories = list;
884     }
885 
886     public List getPluginArtifactRepositories()
887     {
888         return pluginArtifactRepositories;
889     }
890 
891     public ArtifactRepository getDistributionManagementArtifactRepository()
892     {
893         return null;
894     }
895 
896     public List getPluginRepositories()
897     {
898         return Collections.singletonList( "" );
899     }
900 
901     public void setActiveProfiles( List list )
902     {
903         activeProfiles = list;
904     }
905 
906     public List getActiveProfiles()
907     {
908         return activeProfiles;
909     }
910 
911     public void addAttachedArtifact( Artifact theArtifact )
912     {
913         if ( attachedArtifacts == null )
914         {
915             this.attachedArtifacts = Collections.singletonList( theArtifact );
916         }
917         else
918         {
919             attachedArtifacts.add( theArtifact );
920         }
921     }
922 
923     public List getAttachedArtifacts()
924     {
925         return attachedArtifacts;
926     }
927 
928     public Xpp3Dom getGoalConfiguration( String string, String string1, String string2, String string3 )
929     {
930         return null;
931     }
932 
933     public Xpp3Dom getReportConfiguration( String string, String string1, String string2 )
934     {
935         return null;
936     }
937 
938     public MavenProject getExecutionProject()
939     {
940         return null;
941     }
942 
943     public void setExecutionProject( MavenProject mavenProject )
944     {
945 
946     }
947 
948     public void writeModel( Writer writer )
949         throws IOException
950     {
951 
952     }
953 
954     public void writeOriginalModel( Writer writer )
955         throws IOException
956     {
957 
958     }
959 
960     public Set getDependencyArtifacts()
961     {
962         return dependencyArtifacts;
963     }
964 
965     public void setDependencyArtifacts( Set set )
966     {
967         this.dependencyArtifacts = set;
968     }
969 
970     public void setReleaseArtifactRepository( ArtifactRepository artifactRepository )
971     {
972         // this.releaseArtifactRepository = artifactRepository;
973     }
974 
975     public void setSnapshotArtifactRepository( ArtifactRepository artifactRepository )
976     {
977         // this.snapshotArtifactRepository = artifactRepository;
978     }
979 
980     public void setOriginalModel( Model model )
981     {
982         this.originalModel = model;
983     }
984 
985     public Model getOriginalModel()
986     {
987         return originalModel;
988     }
989 
990     public List getBuildExtensions()
991     {
992         return Collections.singletonList( "" );
993     }
994 
995     public Set createArtifacts( ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter )
996         throws InvalidDependencyVersionException
997     {
998         return Collections.EMPTY_SET;
999     }
1000 
1001     public void addProjectReference( MavenProject mavenProject )
1002     {
1003 
1004     }
1005 
1006     public void attachArtifact( String string, String string1, File theFile )
1007     {
1008 
1009     }
1010 
1011     public Properties getProperties()
1012     {
1013         return new Properties();
1014     }
1015 
1016     public List getFilters()
1017     {
1018         return Collections.singletonList( "" );
1019     }
1020 
1021     public Map getProjectReferences()
1022     {
1023         return Collections.singletonMap( "", "" );
1024     }
1025 
1026     public boolean isExecutionRoot()
1027     {
1028         return executionRoot;
1029     }
1030 
1031     public void setExecutionRoot( boolean b )
1032     {
1033         this.executionRoot = b;
1034     }
1035 
1036     public String getDefaultGoal()
1037     {
1038         return defaultGoal;
1039     }
1040 
1041     public Artifact replaceWithActiveArtifact( Artifact theArtifact )
1042     {
1043         return null;
1044     }
1045 }