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