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