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 java.io.File;
23 import java.io.FileInputStream;
24 import java.io.InputStreamReader;
25 import java.util.Collections;
26 import java.util.List;
27 import java.util.Properties;
28
29 import org.apache.maven.artifact.Artifact;
30 import org.apache.maven.artifact.DefaultArtifact;
31 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
32 import org.apache.maven.artifact.versioning.VersionRange;
33 import org.apache.maven.model.Build;
34 import org.apache.maven.model.Model;
35 import org.apache.maven.model.Reporting;
36 import org.apache.maven.model.Repository;
37 import org.apache.maven.model.Resource;
38 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
39 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
40 import org.codehaus.plexus.PlexusTestCase;
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 = null;
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 basedir.mkdirs();
124 }
125
126 return basedir;
127 }
128
129
130
131
132 public List getCompileSourceRoots()
133 {
134 File src = new File( PlexusTestCase.getBasedir() + "/src/test/resources/unit/" + getProjetPath() + "src/main/java" );
135 return Collections.singletonList( src.getAbsolutePath() );
136 }
137
138
139
140
141 public List getTestCompileSourceRoots()
142 {
143 File test = new File( PlexusTestCase.getBasedir() + "/src/test/resources/unit/" + getProjetPath() + "src/test/java" );
144 return Collections.singletonList( test.getAbsolutePath() );
145 }
146
147
148
149
150 public List getCompileArtifacts()
151 {
152 Artifact junit = new DefaultArtifact( "junit", "junit", VersionRange.createFromVersion( "3.8.2" ),
153 Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler( "jar" ),
154 false );
155 junit.setFile( new File( "junit/junit/3.8.2/junit-3.8.2.jar" ) );
156
157 return Collections.singletonList( junit );
158 }
159
160
161
162
163 public List getTestArtifacts()
164 {
165 Artifact junit = new DefaultArtifact( "junit", "junit", VersionRange.createFromVersion( "3.8.2" ),
166 Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler( "jar" ),
167 false );
168 junit.setFile( new File( "junit/junit/3.8.2/junit-3.8.2.jar" ) );
169
170 return Collections.singletonList( junit );
171 }
172
173
174
175
176 public List getRepositories()
177 {
178 Repository repo = new Repository();
179 repo.setId( "central" );
180 repo.setName( "central" );
181 repo.setUrl( "http://repo1.maven.org/maven2" );
182
183 return Collections.singletonList( repo );
184 }
185
186
187
188
189 public Properties getProperties()
190 {
191 return getModel().getProperties();
192 }
193
194
195
196
197 public Reporting getReporting()
198 {
199 return getModel().getReporting();
200 }
201
202
203
204
205 public abstract String getProjetPath();
206 }