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