1 package org.apache.maven.plugin.ant.stubs;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.DefaultArtifact;
24 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
25 import org.apache.maven.artifact.versioning.VersionRange;
26 import org.apache.maven.model.Build;
27 import org.apache.maven.model.Model;
28 import org.apache.maven.model.Reporting;
29 import org.apache.maven.model.Repository;
30 import org.apache.maven.model.Resource;
31 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
32 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
33 import org.codehaus.plexus.PlexusTestCase;
34
35 import java.io.File;
36 import java.io.FileInputStream;
37 import java.io.InputStreamReader;
38 import java.util.Collections;
39 import java.util.List;
40 import java.util.Properties;
41
42
43
44
45
46 public abstract class AbstractAntTestMavenProjectStub
47 extends MavenProjectStub
48 {
49 private Build build;
50
51
52
53
54 public AbstractAntTestMavenProjectStub()
55 {
56 File antTestDir = new File( PlexusTestCase.getBasedir() + "/src/test/resources/unit/" + getProjetPath() + "/" );
57
58 MavenXpp3Reader pomReader = new MavenXpp3Reader();
59 Model model;
60
61 try
62 {
63 File pomFile = new File( antTestDir, "pom.xml" );
64
65 model = pomReader.read( new InputStreamReader( new FileInputStream( pomFile ), "UTF-8" ) );
66 setModel( model );
67 }
68 catch ( Exception e )
69 {
70 throw new RuntimeException( e );
71 }
72
73 setGroupId( model.getGroupId() );
74 setArtifactId( model.getArtifactId() );
75 setVersion( model.getVersion() );
76 setName( model.getName() );
77 setUrl( model.getUrl() );
78 setPackaging( model.getPackaging() );
79
80 build = new Build();
81 Resource resource = new Resource();
82
83 build.setFinalName( model.getArtifactId() );
84 build.setDirectory( getBasedir().getAbsolutePath() + "/target" );
85
86 build.setSourceDirectory( antTestDir + "/src/main/java" );
87 resource.setDirectory( antTestDir + "/src/main/resources" );
88 build.setResources( Collections.singletonList( resource ) );
89 build.setOutputDirectory( getBasedir().getAbsolutePath() + "/target/classes" );
90
91 build.setTestSourceDirectory( antTestDir + "/src/test/java" );
92 resource = new Resource();
93 resource.setDirectory( antTestDir + "/src/test/resources" );
94 build.setTestResources( Collections.singletonList( resource ) );
95 build.setTestOutputDirectory( getBasedir().getAbsolutePath() + "/target/test-classes" );
96
97 setBuild( build );
98
99 Reporting reporting = new Reporting();
100
101 reporting.setOutputDirectory( getBasedir().getAbsolutePath() + "/target/site" );
102
103 getModel().setReporting( reporting );
104 }
105
106
107
108
109 public Build getBuild()
110 {
111 return build;
112 }
113
114
115
116
117 public File getBasedir()
118 {
119 File basedir = new File( PlexusTestCase.getBasedir(), "/target/test/unit/" + getProjetPath() + "/" );
120
121 if ( !basedir.exists() )
122 {
123
124 basedir.mkdirs();
125 }
126
127 return basedir;
128 }
129
130
131
132
133 public List getCompileSourceRoots()
134 {
135 File src =
136 new File( PlexusTestCase.getBasedir() + "/src/test/resources/unit/" + getProjetPath() + "src/main/java" );
137 return Collections.singletonList( src.getAbsolutePath() );
138 }
139
140
141
142
143 public List getTestCompileSourceRoots()
144 {
145 File test =
146 new File( PlexusTestCase.getBasedir() + "/src/test/resources/unit/" + getProjetPath() + "src/test/java" );
147 return Collections.singletonList( test.getAbsolutePath() );
148 }
149
150
151
152
153 public List getCompileArtifacts()
154 {
155 Artifact junit =
156 new DefaultArtifact( "junit", "junit", VersionRange.createFromVersion( "3.8.2" ), Artifact.SCOPE_TEST,
157 "jar", null, new DefaultArtifactHandler( "jar" ), false );
158 junit.setFile( new File( "junit/junit/3.8.2/junit-3.8.2.jar" ) );
159
160 return Collections.singletonList( junit );
161 }
162
163
164
165
166 public List getTestArtifacts()
167 {
168 Artifact junit =
169 new DefaultArtifact( "junit", "junit", VersionRange.createFromVersion( "3.8.2" ), Artifact.SCOPE_TEST,
170 "jar", null, new DefaultArtifactHandler( "jar" ), false );
171 junit.setFile( new File( "junit/junit/3.8.2/junit-3.8.2.jar" ) );
172
173 return Collections.singletonList( junit );
174 }
175
176
177
178
179 public List getRepositories()
180 {
181 Repository repo = new Repository();
182 repo.setId( "central" );
183 repo.setName( "central" );
184 repo.setUrl( "http://repo1.maven.org/maven2" );
185
186 return Collections.singletonList( repo );
187 }
188
189
190
191
192 public Properties getProperties()
193 {
194 return getModel().getProperties();
195 }
196
197
198
199
200 public Reporting getReporting()
201 {
202 return getModel().getReporting();
203 }
204
205
206
207
208 public abstract String getProjetPath();
209 }