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.List;
24 import java.util.Locale;
25 import java.util.ResourceBundle;
26
27 import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
28 import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugin.MojoFailureException;
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
37
38
39
40
41
42
43
44
45
46
47
48
49 public class JavadocReport
50 extends AbstractJavadocMojo
51 implements MavenReport
52 {
53
54
55
56
57
58
59
60
61
62
63 private File reportOutputDirectory;
64
65
66
67
68
69
70
71
72 private String destDir;
73
74
75
76
77
78
79
80 private String name;
81
82
83
84
85
86
87
88 private String description;
89
90
91
92
93
94
95 public String getName( Locale locale )
96 {
97 if ( StringUtils.isEmpty( name ) )
98 {
99 return getBundle( locale ).getString( "report.javadoc.name" );
100 }
101
102 return name;
103 }
104
105
106 public String getDescription( Locale locale )
107 {
108 if ( StringUtils.isEmpty( description ) )
109 {
110 return getBundle( locale ).getString( "report.javadoc.description" );
111 }
112
113 return description;
114 }
115
116
117 public void generate( Sink sink, Locale locale )
118 throws MavenReportException
119 {
120 outputDirectory = getReportOutputDirectory();
121
122 executeReport( locale );
123 }
124
125
126 public String getOutputName()
127 {
128 return destDir + "/index";
129 }
130
131
132 public boolean isExternalReport()
133 {
134 return true;
135 }
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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 public boolean canGenerateReport()
202 {
203 boolean canGenerate = false;
204
205 if ( !this.isAggregator() || ( this.isAggregator() && this.project.isExecutionRoot() ) )
206 {
207 List sourcePaths = getSourcePaths();
208
209 List files = getFiles( sourcePaths );
210
211 canGenerate = canGenerateReport( files );
212 }
213 return canGenerate;
214 }
215
216
217 public String getCategoryName()
218 {
219 return CATEGORY_PROJECT_REPORTS;
220 }
221
222
223 public File getReportOutputDirectory()
224 {
225 if ( reportOutputDirectory == null )
226 {
227 return outputDirectory;
228 }
229
230 return reportOutputDirectory;
231 }
232
233
234
235
236
237
238 public void setReportOutputDirectory( File reportOutputDirectory )
239 {
240 if ( ( reportOutputDirectory != null ) && ( !reportOutputDirectory.getAbsolutePath().endsWith( destDir ) ) )
241 {
242 this.reportOutputDirectory = new File( reportOutputDirectory, destDir );
243 }
244 else
245 {
246 this.reportOutputDirectory = reportOutputDirectory;
247 }
248 }
249
250
251 public void execute()
252 throws MojoExecutionException, MojoFailureException
253 {
254 if ( skip )
255 {
256 getLog().info( "Skipping javadoc generation" );
257 return;
258 }
259
260 try
261 {
262 RenderingContext context = new RenderingContext( outputDirectory, getOutputName() + ".html" );
263 SiteRendererSink sink = new SiteRendererSink( context );
264 Locale locale = Locale.getDefault();
265 generate( sink, locale );
266 }
267 catch ( MavenReportException e )
268 {
269 if ( failOnError )
270 {
271 throw new MojoExecutionException( "An error has occurred in " + getName( Locale.ENGLISH )
272 + " report generation:" + e.getMessage(), e );
273 }
274
275 getLog().error( "An error has occurred in " + getName( Locale.ENGLISH )
276 + " report generation:" + e.getMessage(), e );
277 }
278 catch ( RuntimeException e )
279 {
280 if ( failOnError )
281 {
282 throw e;
283 }
284
285 getLog().error( e.getMessage(), e );
286 }
287 }
288
289
290 protected boolean isAggregator()
291 {
292
293 return aggregate;
294 }
295
296
297
298
299
300
301
302 private ResourceBundle getBundle( Locale locale )
303 {
304 return ResourceBundle.getBundle( "javadoc-report", locale, getClass().getClassLoader() );
305 }
306 }