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 | 24 | 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 | 2 | if ( StringUtils.isEmpty( name ) ) |
98 | |
{ |
99 | 2 | return getBundle( locale ).getString( "report.javadoc.name" ); |
100 | |
} |
101 | |
|
102 | 0 | return name; |
103 | |
} |
104 | |
|
105 | |
|
106 | |
public String getDescription( Locale locale ) |
107 | |
{ |
108 | 0 | if ( StringUtils.isEmpty( description ) ) |
109 | |
{ |
110 | 0 | return getBundle( locale ).getString( "report.javadoc.description" ); |
111 | |
} |
112 | |
|
113 | 0 | return description; |
114 | |
} |
115 | |
|
116 | |
|
117 | |
public void generate( Sink sink, Locale locale ) |
118 | |
throws MavenReportException |
119 | |
{ |
120 | 23 | outputDirectory = getReportOutputDirectory(); |
121 | |
|
122 | 23 | executeReport( locale ); |
123 | 21 | } |
124 | |
|
125 | |
|
126 | |
public String getOutputName() |
127 | |
{ |
128 | 22 | return destDir + "/index"; |
129 | |
} |
130 | |
|
131 | |
|
132 | |
public boolean isExternalReport() |
133 | |
{ |
134 | 0 | return true; |
135 | |
} |
136 | |
|
137 | |
|
138 | |
public boolean canGenerateReport() |
139 | |
{ |
140 | |
boolean canGenerate; |
141 | 0 | if ( aggregate != isAggregator() ) |
142 | |
{ |
143 | 0 | canGenerate = false; |
144 | |
} |
145 | 0 | else if ( isAggregator() && !project.isExecutionRoot() ) |
146 | |
{ |
147 | 0 | canGenerate = false; |
148 | |
} |
149 | |
else |
150 | |
{ |
151 | 0 | List sourcePaths = getSourcePaths(); |
152 | |
|
153 | 0 | List files = getFiles( sourcePaths ); |
154 | |
|
155 | 0 | canGenerate = canGenerateReport( files ); |
156 | |
} |
157 | 0 | return canGenerate; |
158 | |
} |
159 | |
|
160 | |
|
161 | |
public String getCategoryName() |
162 | |
{ |
163 | 0 | return CATEGORY_PROJECT_REPORTS; |
164 | |
} |
165 | |
|
166 | |
|
167 | |
public File getReportOutputDirectory() |
168 | |
{ |
169 | 22 | if ( reportOutputDirectory == null ) |
170 | |
{ |
171 | 22 | return outputDirectory; |
172 | |
} |
173 | |
|
174 | 0 | return reportOutputDirectory; |
175 | |
} |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
public void setReportOutputDirectory( File reportOutputDirectory ) |
183 | |
{ |
184 | 0 | if ( ( reportOutputDirectory != null ) && ( !reportOutputDirectory.getAbsolutePath().endsWith( destDir ) ) ) |
185 | |
{ |
186 | 0 | this.reportOutputDirectory = new File( reportOutputDirectory, destDir ); |
187 | |
} |
188 | |
else |
189 | |
{ |
190 | 0 | this.reportOutputDirectory = reportOutputDirectory; |
191 | |
} |
192 | 0 | } |
193 | |
|
194 | |
|
195 | |
public void execute() |
196 | |
throws MojoExecutionException, MojoFailureException |
197 | |
{ |
198 | 23 | if ( skip ) |
199 | |
{ |
200 | 0 | getLog().info( "Skipping javadoc generation" ); |
201 | 0 | return; |
202 | |
} |
203 | |
|
204 | |
try |
205 | |
{ |
206 | 23 | RenderingContext context = new RenderingContext( outputDirectory, getOutputName() + ".html" ); |
207 | 23 | SiteRendererSink sink = new SiteRendererSink( context ); |
208 | 23 | Locale locale = Locale.getDefault(); |
209 | 23 | generate( sink, locale ); |
210 | |
} |
211 | 2 | catch ( MavenReportException e ) |
212 | |
{ |
213 | 2 | if ( failOnError ) |
214 | |
{ |
215 | 2 | throw new MojoExecutionException( "An error has occurred in " + getName( Locale.ENGLISH ) |
216 | |
+ " report generation:" + e.getMessage(), e ); |
217 | |
} |
218 | |
|
219 | 0 | getLog().error( "An error has occurred in " + getName( Locale.ENGLISH ) |
220 | |
+ " report generation:" + e.getMessage(), e ); |
221 | |
} |
222 | 0 | catch ( RuntimeException e ) |
223 | |
{ |
224 | 0 | if ( failOnError ) |
225 | |
{ |
226 | 0 | throw e; |
227 | |
} |
228 | |
|
229 | 0 | getLog().error( e.getMessage(), e ); |
230 | 21 | } |
231 | 21 | } |
232 | |
|
233 | |
|
234 | |
protected boolean isAggregator() |
235 | |
{ |
236 | |
|
237 | 79 | return aggregate; |
238 | |
} |
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
private ResourceBundle getBundle( Locale locale ) |
247 | |
{ |
248 | 2 | return ResourceBundle.getBundle( "javadoc-report", locale, getClass().getClassLoader() ); |
249 | |
} |
250 | |
} |