1 | |
package org.apache.maven.plugin.javadoc; |
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.resolver.ArtifactResolutionResult; |
24 | |
import org.apache.maven.plugin.javadoc.resolver.SourceResolverConfig; |
25 | |
import org.apache.maven.plugins.annotations.Execute; |
26 | |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
27 | |
import org.apache.maven.plugins.annotations.Mojo; |
28 | |
import org.apache.maven.plugins.annotations.Parameter; |
29 | |
import org.apache.maven.plugins.annotations.ResolutionScope; |
30 | |
import org.apache.maven.project.MavenProject; |
31 | |
import org.apache.maven.reporting.MavenReportException; |
32 | |
import org.codehaus.plexus.util.StringUtils; |
33 | |
|
34 | |
import java.io.File; |
35 | |
import java.util.ArrayList; |
36 | |
import java.util.Collections; |
37 | |
import java.util.LinkedList; |
38 | |
import java.util.List; |
39 | |
import java.util.Locale; |
40 | |
import java.util.ResourceBundle; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
@Mojo( name = "test-javadoc", requiresDependencyResolution = ResolutionScope.TEST ) |
53 | |
@Execute( phase = LifecyclePhase.GENERATE_TEST_SOURCES ) |
54 | 1 | public class TestJavadocReport |
55 | |
extends JavadocReport |
56 | |
{ |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
@Parameter( property = "testDoctitle", alias = "doctitle", |
70 | |
defaultValue = "${project.name} ${project.version} Test API" ) |
71 | |
private String testDoctitle; |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
@Parameter( property = "testOverview", alias = "overview", |
85 | |
defaultValue = "${basedir}/src/test/javadoc/overview.html" ) |
86 | |
private File testOverview; |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
@Parameter( property = "testWindowtitle", alias = "windowtitle", |
97 | |
defaultValue = "${project.name} ${project.version} Test API" ) |
98 | |
private String testWindowtitle; |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
@Parameter( property = "reportTestOutputDirectory", |
108 | |
defaultValue = "${project.reporting.outputDirectory}/testapidocs", required = true ) |
109 | |
private File reportOutputDirectory; |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
@Parameter( property = "destDir", defaultValue = "testapidocs" ) |
116 | |
private String destDir; |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
@Parameter( alias = "javadocDirectory", defaultValue = "${basedir}/src/test/javadoc" ) |
128 | |
private File testJavadocDirectory; |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
@Parameter( property = "testName", alias = "name" ) |
141 | |
private String testName; |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
@Parameter( property = "testDescription", alias = "description" ) |
150 | |
private String testDescription; |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
@Override |
157 | |
protected void executeReport( Locale unusedLocale ) |
158 | |
throws MavenReportException |
159 | |
{ |
160 | 1 | addMainJavadocLink(); |
161 | |
|
162 | 1 | super.executeReport( unusedLocale ); |
163 | 1 | } |
164 | |
|
165 | |
@Override |
166 | |
public String getName( Locale locale ) |
167 | |
{ |
168 | 0 | if ( StringUtils.isEmpty( testName ) ) |
169 | |
{ |
170 | 0 | return getBundle( locale ).getString( "report.test-javadoc.name" ); |
171 | |
} |
172 | |
|
173 | 0 | return testName; |
174 | |
} |
175 | |
|
176 | |
@Override |
177 | |
public String getDescription( Locale locale ) |
178 | |
{ |
179 | 0 | if ( StringUtils.isEmpty( testDescription ) ) |
180 | |
{ |
181 | 0 | return getBundle( locale ).getString( "report.test-javadoc.description" ); |
182 | |
} |
183 | |
|
184 | 0 | return testDescription; |
185 | |
} |
186 | |
|
187 | |
@Override |
188 | |
public String getOutputName() |
189 | |
{ |
190 | 1 | return destDir + "/index"; |
191 | |
} |
192 | |
|
193 | |
@Override |
194 | |
public File getReportOutputDirectory() |
195 | |
{ |
196 | 2 | if ( reportOutputDirectory == null ) |
197 | |
{ |
198 | 2 | return outputDirectory; |
199 | |
} |
200 | |
|
201 | 0 | return reportOutputDirectory; |
202 | |
} |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
@Override |
210 | |
public void setReportOutputDirectory( File reportOutputDirectory ) |
211 | |
{ |
212 | 0 | updateReportOutputDirectory( reportOutputDirectory, destDir ); |
213 | 0 | } |
214 | |
|
215 | |
@Override |
216 | |
public void setDestDir( String destDir ) |
217 | |
{ |
218 | 0 | this.destDir = destDir; |
219 | 0 | updateReportOutputDirectory( reportOutputDirectory, destDir ); |
220 | 0 | } |
221 | |
|
222 | |
private void updateReportOutputDirectory( File reportOutputDirectory, String destDir ) |
223 | |
{ |
224 | 0 | if ( reportOutputDirectory != null && destDir != null |
225 | |
&& !reportOutputDirectory.getAbsolutePath().endsWith( destDir ) ) |
226 | |
{ |
227 | 0 | this.reportOutputDirectory = new File( reportOutputDirectory, destDir ); |
228 | |
} |
229 | |
else |
230 | |
{ |
231 | 0 | this.reportOutputDirectory = reportOutputDirectory; |
232 | |
} |
233 | 0 | } |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
@Override |
241 | |
protected List<String> getProjectBuildOutputDirs( MavenProject p ) |
242 | |
{ |
243 | 1 | List<String> dirs = new ArrayList<String>(); |
244 | 1 | if ( StringUtils.isNotEmpty( p.getBuild().getOutputDirectory() ) ) |
245 | |
{ |
246 | 1 | dirs.add( p.getBuild().getOutputDirectory() ); |
247 | |
} |
248 | 1 | if ( StringUtils.isNotEmpty( p.getBuild().getTestOutputDirectory() ) ) |
249 | |
{ |
250 | 1 | dirs.add( p.getBuild().getTestOutputDirectory() ); |
251 | |
} |
252 | |
|
253 | 1 | return dirs; |
254 | |
} |
255 | |
|
256 | |
@Override |
257 | |
protected List<String> getProjectSourceRoots( MavenProject p ) |
258 | |
{ |
259 | 1 | if ( "pom".equals( p.getPackaging().toLowerCase() ) ) |
260 | |
{ |
261 | 0 | return Collections.emptyList(); |
262 | |
} |
263 | |
|
264 | 1 | return ( p.getTestCompileSourceRoots() == null ? Collections.<String>emptyList() |
265 | |
: new LinkedList<String>( p.getTestCompileSourceRoots() ) ); |
266 | |
} |
267 | |
|
268 | |
@Override |
269 | |
protected List<String> getExecutionProjectSourceRoots( MavenProject p ) |
270 | |
{ |
271 | 1 | if ( "pom".equals( p.getExecutionProject().getPackaging().toLowerCase() ) ) |
272 | |
{ |
273 | 0 | return Collections.emptyList(); |
274 | |
} |
275 | |
|
276 | 1 | return ( p.getExecutionProject().getTestCompileSourceRoots() == null ? Collections.<String>emptyList() |
277 | |
: new LinkedList<String>( p.getExecutionProject().getTestCompileSourceRoots() ) ); |
278 | |
} |
279 | |
|
280 | |
@Override |
281 | |
protected List<Artifact> getProjectArtifacts( MavenProject p ) |
282 | |
{ |
283 | 1 | return ( p.getTestArtifacts() == null ? Collections.<Artifact>emptyList() |
284 | |
: new LinkedList<Artifact>( p.getTestArtifacts() ) ); |
285 | |
} |
286 | |
|
287 | |
@Override |
288 | |
protected File getJavadocDirectory() |
289 | |
{ |
290 | 2 | return testJavadocDirectory; |
291 | |
} |
292 | |
|
293 | |
@Override |
294 | |
protected String getDoctitle() |
295 | |
{ |
296 | 1 | return testDoctitle; |
297 | |
} |
298 | |
|
299 | |
@Override |
300 | |
protected File getOverview() |
301 | |
{ |
302 | 2 | return testOverview; |
303 | |
} |
304 | |
|
305 | |
@Override |
306 | |
protected String getWindowtitle() |
307 | |
{ |
308 | 1 | return testWindowtitle; |
309 | |
} |
310 | |
|
311 | |
@Override |
312 | |
protected List<Artifact> getCompileArtifacts( ArtifactResolutionResult result ) |
313 | |
{ |
314 | 0 | return JavadocUtil.getCompileArtifacts( result.getArtifacts(), true ); |
315 | |
} |
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
private ResourceBundle getBundle( Locale locale ) |
324 | |
{ |
325 | 0 | return ResourceBundle.getBundle( "test-javadoc-report", locale, getClass().getClassLoader() ); |
326 | |
} |
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
private void addMainJavadocLink() |
332 | |
{ |
333 | 1 | if ( links == null ) |
334 | |
{ |
335 | 1 | links = new ArrayList<String>(); |
336 | |
} |
337 | |
|
338 | |
|
339 | 1 | File apidocs = new File( getReportOutputDirectory().getParentFile(), "apidocs" ); |
340 | 1 | if ( apidocs.isDirectory() && !links.contains( "../apidocs" ) ) |
341 | |
{ |
342 | 1 | links.add( "../apidocs" ); |
343 | |
} |
344 | 1 | } |
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
@Override |
352 | |
protected SourceResolverConfig configureDependencySourceResolution( final SourceResolverConfig config ) |
353 | |
{ |
354 | 0 | return super.configureDependencySourceResolution( config ).withoutCompileSources().withTestSources(); |
355 | |
} |
356 | |
} |