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.doxia.module.xhtml.decoration.render.RenderingContext; |
23 | |
import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink; |
24 | |
import org.apache.maven.plugin.MojoExecutionException; |
25 | |
import org.apache.maven.plugin.MojoFailureException; |
26 | |
import org.apache.maven.plugins.annotations.Execute; |
27 | |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
28 | |
import org.apache.maven.plugins.annotations.Mojo; |
29 | |
import org.apache.maven.plugins.annotations.Parameter; |
30 | |
import org.apache.maven.plugins.annotations.ResolutionScope; |
31 | |
import org.apache.maven.reporting.MavenReport; |
32 | |
import org.apache.maven.reporting.MavenReportException; |
33 | |
import org.codehaus.doxia.sink.Sink; |
34 | |
import org.codehaus.plexus.util.StringUtils; |
35 | |
|
36 | |
import java.io.File; |
37 | |
import java.util.List; |
38 | |
import java.util.Locale; |
39 | |
import java.util.ResourceBundle; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
@Mojo( name = "javadoc", requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true ) |
53 | |
@Execute( phase = LifecyclePhase.GENERATE_SOURCES ) |
54 | 35 | public class JavadocReport |
55 | |
extends AbstractJavadocMojo |
56 | |
implements MavenReport |
57 | |
{ |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
@Parameter( property = "reportOutputDirectory", defaultValue = "${project.reporting.outputDirectory}/apidocs", |
66 | |
required = true ) |
67 | |
private File reportOutputDirectory; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
@Parameter( property = "destDir", defaultValue = "apidocs" ) |
76 | |
private String destDir; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
@Parameter( property = "name" ) |
85 | |
private String name; |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
@Parameter( property = "description" ) |
94 | |
private String description; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public String getName( Locale locale ) |
102 | |
{ |
103 | 6 | if ( StringUtils.isEmpty( name ) ) |
104 | |
{ |
105 | 6 | return getBundle( locale ).getString( "report.javadoc.name" ); |
106 | |
} |
107 | |
|
108 | 0 | return name; |
109 | |
} |
110 | |
|
111 | |
|
112 | |
public String getDescription( Locale locale ) |
113 | |
{ |
114 | 0 | if ( StringUtils.isEmpty( description ) ) |
115 | |
{ |
116 | 0 | return getBundle( locale ).getString( "report.javadoc.description" ); |
117 | |
} |
118 | |
|
119 | 0 | return description; |
120 | |
} |
121 | |
|
122 | |
|
123 | |
public void generate( Sink sink, Locale locale ) |
124 | |
throws MavenReportException |
125 | |
{ |
126 | 42 | outputDirectory = getReportOutputDirectory(); |
127 | |
|
128 | |
try |
129 | |
{ |
130 | 42 | executeReport( locale ); |
131 | |
} |
132 | 6 | catch ( MavenReportException e ) |
133 | |
{ |
134 | 6 | if ( failOnError ) |
135 | |
{ |
136 | 6 | throw e; |
137 | |
} |
138 | 0 | getLog().error( "Error while creating javadoc report: " + e.getMessage(), e ); |
139 | |
} |
140 | 0 | catch ( RuntimeException e ) |
141 | |
{ |
142 | 0 | if ( failOnError ) |
143 | |
{ |
144 | 0 | throw e; |
145 | |
} |
146 | 0 | getLog().error( "Error while creating javadoc report: " + e.getMessage(), e ); |
147 | 36 | } |
148 | 36 | } |
149 | |
|
150 | |
|
151 | |
public String getOutputName() |
152 | |
{ |
153 | 41 | return destDir + "/index"; |
154 | |
} |
155 | |
|
156 | |
|
157 | |
public boolean isExternalReport() |
158 | |
{ |
159 | 0 | return true; |
160 | |
} |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
public boolean canGenerateReport() |
227 | |
{ |
228 | 0 | boolean canGenerate = false; |
229 | |
|
230 | 0 | if ( !this.isAggregator() || ( this.isAggregator() && this.project.isExecutionRoot() ) ) |
231 | |
{ |
232 | |
List<String> sourcePaths; |
233 | |
List<String> files; |
234 | |
try |
235 | |
{ |
236 | 0 | sourcePaths = getSourcePaths(); |
237 | 0 | files = getFiles( sourcePaths ); |
238 | |
} |
239 | 0 | catch ( MavenReportException e ) |
240 | |
{ |
241 | 0 | getLog().error( e.getMessage(), e ); |
242 | 0 | return false; |
243 | 0 | } |
244 | |
|
245 | 0 | canGenerate = canGenerateReport( files ); |
246 | |
} |
247 | 0 | if ( getLog().isDebugEnabled() ) |
248 | |
{ |
249 | 0 | getLog().debug( " canGenerateReport " + canGenerate + " project " + this.project ); |
250 | |
} |
251 | 0 | return canGenerate; |
252 | |
} |
253 | |
|
254 | |
|
255 | |
public String getCategoryName() |
256 | |
{ |
257 | 0 | return CATEGORY_PROJECT_REPORTS; |
258 | |
} |
259 | |
|
260 | |
|
261 | |
public File getReportOutputDirectory() |
262 | |
{ |
263 | 41 | if ( reportOutputDirectory == null ) |
264 | |
{ |
265 | 41 | return outputDirectory; |
266 | |
} |
267 | |
|
268 | 0 | return reportOutputDirectory; |
269 | |
} |
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
public void setReportOutputDirectory( File reportOutputDirectory ) |
277 | |
{ |
278 | 0 | updateReportOutputDirectory( reportOutputDirectory, destDir ); |
279 | 0 | } |
280 | |
|
281 | |
public void setDestDir( String destDir ) |
282 | |
{ |
283 | 0 | this.destDir = destDir; |
284 | 0 | updateReportOutputDirectory( reportOutputDirectory, destDir ); |
285 | 0 | } |
286 | |
|
287 | |
private void updateReportOutputDirectory( File reportOutputDirectory, String destDir ) |
288 | |
{ |
289 | 0 | if ( reportOutputDirectory != null && destDir != null |
290 | |
&& !reportOutputDirectory.getAbsolutePath().endsWith( destDir ) ) |
291 | |
{ |
292 | 0 | this.reportOutputDirectory = new File( reportOutputDirectory, destDir ); |
293 | |
} |
294 | |
else |
295 | |
{ |
296 | 0 | this.reportOutputDirectory = reportOutputDirectory; |
297 | |
} |
298 | 0 | } |
299 | |
|
300 | |
|
301 | |
public void execute() |
302 | |
throws MojoExecutionException, MojoFailureException |
303 | |
{ |
304 | 42 | if ( skip ) |
305 | |
{ |
306 | 0 | getLog().info( "Skipping javadoc generation" ); |
307 | 0 | return; |
308 | |
} |
309 | |
|
310 | |
try |
311 | |
{ |
312 | 42 | RenderingContext context = new RenderingContext( outputDirectory, getOutputName() + ".html" ); |
313 | 42 | SiteRendererSink sink = new SiteRendererSink( context ); |
314 | 42 | Locale locale = Locale.getDefault(); |
315 | 42 | generate( sink, locale ); |
316 | |
} |
317 | 6 | catch ( MavenReportException e ) |
318 | |
{ |
319 | 6 | failOnError( "An error has occurred in " + getName( Locale.ENGLISH ) + " report generation", e ); |
320 | |
} |
321 | 0 | catch ( RuntimeException e ) |
322 | |
{ |
323 | 0 | failOnError( "An error has occurred in " + getName( Locale.ENGLISH ) + " report generation", e ); |
324 | 36 | } |
325 | 36 | } |
326 | |
|
327 | |
@Override |
328 | |
protected boolean isAggregator() |
329 | |
{ |
330 | |
|
331 | 119 | return aggregate; |
332 | |
} |
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
private ResourceBundle getBundle( Locale locale ) |
341 | |
{ |
342 | 6 | return ResourceBundle.getBundle( "javadoc-report", locale, getClass().getClassLoader() ); |
343 | |
} |
344 | |
} |