1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.testdoc.maven;
17
18 import java.io.File;
19 import java.util.Locale;
20
21 import org.apache.maven.reporting.MavenReportException;
22
23 import de.smartics.maven.util.report.MavenExternalReportFactory;
24 import de.smartics.maven.util.report.link.ExternalReportFactory;
25 import de.smartics.maven.util.report.link.LinkConstructorStrategy;
26 import de.smartics.maven.util.report.link.LinkConstructorStrategyConfig;
27 import de.smartics.maven.util.report.link.ReportId;
28 import de.smartics.maven.util.report.link.strategy.DirectoryPathLinkConstructorStrategy;
29 import de.smartics.maven.util.report.link.strategy.FilePathLinkConstructorStrategy;
30 import de.smartics.maven.util.report.link.strategy.LineNumberDirectoryPathLinkConstructorStrategy;
31 import de.smartics.maven.util.report.link.strategy.SurefireLinkConstructorStrategy;
32 import de.smartics.testdoc.report.export.doc.ExternalReportReferences;
33 import de.smartics.testdoc.report.export.doc.ImageHelper;
34 import de.smartics.testdoc.report.junit.DirectoryJUnitTestCaseManager;
35 import de.smartics.testdoc.report.junit.JUnitTestCaseManager;
36
37
38
39
40
41
42
43 public abstract class AbstractSourceReportMojo extends AbstractReportMojo
44 {
45
46
47
48
49
50
51
52
53
54
55
56 protected File xrefLocation;
57
58
59
60
61
62
63 protected boolean linkXref;
64
65
66
67
68
69
70 protected boolean linkJavadoc;
71
72
73
74
75
76
77 protected File javadocLocation;
78
79
80
81
82
83
84 protected File xrefTestLocation;
85
86
87
88
89
90
91 protected boolean linkXrefTest;
92
93
94
95
96
97
98 protected boolean linkJavadocTest;
99
100
101
102
103
104
105 protected File javadocTestLocation;
106
107
108
109
110
111
112 protected boolean linkSurefire;
113
114
115
116
117
118
119
120 protected File surefireLocation;
121
122
123
124
125
126
127
128 protected boolean presentJUnitReport;
129
130
131
132
133
134
135 protected File junitReportLocation;
136
137
138
139
140
141
142 protected boolean linkCobertura;
143
144
145
146
147
148
149 protected File coberturaLocation;
150
151
152
153
154 protected ExternalReportReferences reports;
155
156
157
158
159
160 protected JUnitTestCaseManager junitManager;
161
162
163
164
165 protected ImageHelper imageHelper = new ImageHelper(null);
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189 @Override
190 protected void executeReport(final Locale locale) throws MavenReportException
191 {
192 super.executeReport(locale);
193
194 final ExternalReportFactory factory =
195 new MavenExternalReportFactory(project, "");
196
197 reports = new ExternalReportReferences(factory);
198
199 addJxrReports();
200 addJavadocReports();
201 addSurefireReport();
202 addCoberturaReport();
203
204 if (presentJUnitReport)
205 {
206 junitManager = new DirectoryJUnitTestCaseManager(junitReportLocation);
207 }
208 }
209
210 private void addJxrReports() throws MavenReportException
211 {
212 final ReportId jxrReport =
213 provideLinkConstructor(linkXref,
214 MavenExternalReportFactory.MAVEN_JXR_PLUGIN,
215 ReportId.NORMAL_REPORT, xrefLocation, true, "report.link.jxr");
216 if (jxrReport != null)
217 {
218 reports.addUutReportId(jxrReport);
219 }
220
221 final ReportId jxrTestReport =
222 provideLinkConstructor(linkXrefTest,
223 MavenExternalReportFactory.MAVEN_JXR_PLUGIN, ReportId.TEST_REPORT,
224 xrefTestLocation, true, "report.link.jxr");
225 if (jxrTestReport != null)
226 {
227 reports.addTestCaseReportId(jxrTestReport);
228 }
229 }
230
231 private void addJavadocReports() throws MavenReportException
232 {
233 final ReportId javadocReport =
234 provideLinkConstructor(linkJavadoc,
235 MavenExternalReportFactory.MAVEN_JAVADOC_PLUGIN,
236 ReportId.NORMAL_REPORT, javadocLocation, true,
237 "report.link.javadoc");
238 if (javadocReport != null)
239 {
240 reports.addUutReportId(javadocReport);
241 }
242
243 final ReportId javadocTestReport =
244 provideLinkConstructor(linkJavadocTest,
245 MavenExternalReportFactory.MAVEN_JAVADOC_PLUGIN,
246 ReportId.TEST_REPORT, javadocTestLocation, true,
247 "report.link.javadoc");
248 if (javadocTestReport != null)
249 {
250 reports.addTestCaseReportId(javadocTestReport);
251 }
252 }
253
254 private void addSurefireReport() throws MavenReportException
255 {
256 final ReportId surefireReport =
257 provideLinkConstructor(linkSurefire,
258 MavenExternalReportFactory.MAVEN_SUREFIRE_PLUGIN,
259 ReportId.NORMAL_REPORT, surefireLocation, false,
260 "report.link.surefire");
261 if (surefireReport != null)
262 {
263 reports.addTestCaseReportId(surefireReport);
264 }
265 }
266
267 private void addCoberturaReport() throws MavenReportException
268 {
269 final ReportId coberturaReport =
270 provideLinkConstructor(linkCobertura,
271 MavenExternalReportFactory.MAVEN_COBERTURA_PLUGIN,
272 ReportId.NORMAL_REPORT, coberturaLocation, false,
273 "report.link.cobertura");
274 if (coberturaReport != null)
275 {
276 reports.addUutReportId(coberturaReport);
277 }
278 }
279
280 private ReportId provideLinkConstructor(
281
282 final boolean addReport, final String reportArtifactId,
283 final String reportType, final File location, final boolean linkToMember,
284 final String labelKey) throws MavenReportException
285 {
286 final LinkConstructorStrategy strategy =
287 createStrategy(reportArtifactId, location, linkToMember, labelKey);
288
289 final ReportId reportId = new ReportId(reportArtifactId, reportType);
290 if (reports.registerReport(addReport, reportId, strategy))
291 {
292 return reportId;
293 }
294 return null;
295 }
296
297 protected LinkConstructorStrategy createStrategy(
298 final String reportArtifactId, final File location,
299 final boolean linkToMember, final String labelKey)
300 throws MavenReportException
301 {
302 final LinkConstructorStrategyConfig.Builder builder =
303 new LinkConstructorStrategyConfig.Builder();
304
305 builder.setReferenceMember(linkToMember);
306 builder.setReportLocation(location);
307 builder.setLabelKey(labelKey);
308 final LinkConstructorStrategyConfig config = builder.build();
309
310 final LinkConstructorStrategy strategy;
311 if (MavenExternalReportFactory.MAVEN_JAVADOC_PLUGIN
312 .equals(reportArtifactId))
313 {
314 strategy = new DirectoryPathLinkConstructorStrategy(config);
315 }
316 else if (MavenExternalReportFactory.MAVEN_COBERTURA_PLUGIN
317 .equals(reportArtifactId))
318 {
319 strategy = new FilePathLinkConstructorStrategy(config);
320 }
321 else if (MavenExternalReportFactory.MAVEN_JXR_PLUGIN
322 .equals(reportArtifactId))
323 {
324 strategy = new LineNumberDirectoryPathLinkConstructorStrategy(config);
325 }
326 else if (MavenExternalReportFactory.MAVEN_SUREFIRE_PLUGIN
327 .equals(reportArtifactId))
328 {
329 strategy = new SurefireLinkConstructorStrategy(config);
330 }
331 else
332 {
333 throw new MavenReportException("Unknown report artifact ID '"
334 + reportArtifactId + "'.");
335 }
336 return strategy;
337 }
338
339
340
341 }