1 package org.apache.maven.report.projectinfo.stubs;
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.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Set;
27
28 import org.apache.maven.artifact.Artifact;
29 import org.apache.maven.artifact.DefaultArtifact;
30 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
31 import org.apache.maven.artifact.repository.ArtifactRepository;
32 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
33 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
34 import org.apache.maven.artifact.versioning.VersionRange;
35 import org.apache.maven.model.Build;
36 import org.apache.maven.model.DependencyManagement;
37 import org.apache.maven.model.Model;
38 import org.apache.maven.model.PluginManagement;
39 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
40 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
41 import org.codehaus.plexus.util.ReaderFactory;
42
43
44
45
46
47
48
49 public abstract class ProjectInfoProjectStub
50 extends MavenProjectStub
51 {
52 private Model model;
53
54 private Build build;
55
56
57
58
59 public ProjectInfoProjectStub()
60 {
61 MavenXpp3Reader pomReader = new MavenXpp3Reader();
62 try
63 {
64 model = pomReader.read( ReaderFactory.newXmlReader( new File( getBasedir(), getPOM() ) ) );
65 setModel( model );
66 }
67 catch ( Exception e )
68 {
69 throw new RuntimeException( e );
70 }
71
72 setGroupId( model.getGroupId() );
73 setArtifactId( model.getArtifactId() );
74 setVersion( model.getVersion() );
75 setName( model.getName() );
76 setUrl( model.getUrl() );
77 setPackaging( model.getPackaging() );
78
79 Artifact artifact = new ProjectInfoPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(),
80 getPackaging() );
81 artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
82 setArtifact( artifact );
83
84 Build build = new Build();
85 build.setFinalName( model.getArtifactId() );
86 build.setDirectory( super.getBasedir() + "/target/test/unit/" + model.getArtifactId() + "/target" );
87 build.setSourceDirectory( getBasedir() + "/src/main/java" );
88 build.setOutputDirectory( super.getBasedir() + "/target/test/unit/" + model.getArtifactId()
89 + "/target/classes" );
90 build.setTestSourceDirectory( getBasedir() + "/src/test/java" );
91 build.setTestOutputDirectory( super.getBasedir() + "/target/test/unit/" + model.getArtifactId()
92 + "/target/test-classes" );
93 setBuild( build );
94
95 List compileSourceRoots = new ArrayList();
96 compileSourceRoots.add( getBasedir() + "/src/main/java" );
97 setCompileSourceRoots( compileSourceRoots );
98
99 List testCompileSourceRoots = new ArrayList();
100 testCompileSourceRoots.add( getBasedir() + "/src/test/java" );
101 setTestCompileSourceRoots( testCompileSourceRoots );
102 }
103
104
105
106
107 protected abstract String getPOM();
108
109
110 public Model getModel()
111 {
112 return model;
113 }
114
115
116 public Build getBuild()
117 {
118 return build;
119 }
120
121
122 public void setBuild( Build build )
123 {
124 this.build = build;
125 }
126
127
128 public File getBasedir()
129 {
130 return new File( super.getBasedir() + "/src/test/resources/plugin-configs/" );
131 }
132
133
134 public Set getArtifacts()
135 {
136 return Collections.EMPTY_SET;
137 }
138
139
140 public List getRemoteArtifactRepositories()
141 {
142 ArtifactRepository repository = new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
143 new DefaultRepositoryLayout() );
144
145 return Collections.singletonList( repository );
146 }
147
148
149 public Set getDependencyArtifacts()
150 {
151 return Collections.singleton( new DefaultArtifact( "junit", "junit", VersionRange.createFromVersion( "3.8.1" ),
152 Artifact.SCOPE_TEST, "jar", null,
153 new DefaultArtifactHandler( "jar" ), false ) );
154 }
155
156
157 public DependencyManagement getDependencyManagement()
158 {
159 return model.getDependencyManagement();
160 }
161
162
163 public PluginManagement getPluginManagement()
164 {
165 PluginManagement pluginMgmt = null;
166
167 Build build = model.getBuild();
168 if ( build != null )
169 {
170 pluginMgmt = build.getPluginManagement();
171 }
172
173 return pluginMgmt;
174 }
175
176 }