|
25 | 25 | import java.net.URLClassLoader; |
26 | 26 | import java.text.MessageFormat; |
27 | 27 | import java.util.ArrayList; |
| 28 | +import java.util.Collections; |
28 | 29 | import java.util.Iterator; |
29 | 30 | import java.util.List; |
30 | 31 | import java.util.Locale; |
31 | 32 | import java.util.MissingResourceException; |
32 | 33 | import java.util.ResourceBundle; |
33 | 34 |
|
34 | 35 | import org.apache.maven.model.ReportPlugin; |
| 36 | +import org.apache.maven.model.Reporting; |
35 | 37 | import org.apache.maven.plugin.surefire.log.api.ConsoleLogger; |
36 | 38 | import org.apache.maven.plugins.annotations.Component; |
37 | 39 | import org.apache.maven.plugins.annotations.Parameter; |
@@ -77,23 +79,19 @@ public abstract class AbstractSurefireReport extends AbstractMavenReport { |
77 | 79 | private File reportsDirectory; |
78 | 80 |
|
79 | 81 | /** |
80 | | - * The projects in the reactor for aggregation report. |
| 82 | + * Link the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is |
| 83 | + * being used. |
81 | 84 | */ |
82 | | - @Parameter(defaultValue = "${reactorProjects}", readonly = true) |
83 | | - private List<MavenProject> reactorProjects; |
84 | | - |
85 | | - /** |
86 | | - * Link the failed tests line numbers to the source xref. Will link |
87 | | - * automatically if Maven JXR plugin is being used. |
88 | | - */ |
89 | | - @Parameter(defaultValue = "true", property = "linkXRef") |
| 85 | + @Parameter(property = "linkXRef", defaultValue = "true") |
90 | 86 | private boolean linkXRef; |
91 | 87 |
|
92 | 88 | /** |
93 | | - * Location of the Xrefs to link. |
| 89 | + * Location where Test Source XRef is generated for this project. |
| 90 | + * <br> |
| 91 | + * <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /xref-test} |
94 | 92 | */ |
95 | | - @Parameter(defaultValue = "${project.reporting.outputDirectory}/xref-test") |
96 | | - private File xrefLocation; |
| 93 | + @Parameter |
| 94 | + private File xrefTestLocation; |
97 | 95 |
|
98 | 96 | /** |
99 | 97 | * Whether to build an aggregated report at the root, or build individual reports. |
@@ -156,7 +154,7 @@ public void executeReport(Locale locale) { |
156 | 154 | locale, |
157 | 155 | getConsoleLogger(), |
158 | 156 | getReportsDirectories(), |
159 | | - determineXrefLocation(), |
| 157 | + constructXrefTestLocation(), |
160 | 158 | showSuccess); |
161 | 159 | r.render(); |
162 | 160 | } |
@@ -258,26 +256,28 @@ private List<MavenProject> getProjectsWithoutRoot() { |
258 | 256 | return result; |
259 | 257 | } |
260 | 258 |
|
261 | | - private String determineXrefLocation() { |
| 259 | + private String constructXrefTestLocation() { |
262 | 260 | String location = null; |
263 | | - |
264 | 261 | if (linkXRef) { |
| 262 | + File xrefTestLocation = getXrefTestLocation(); |
| 263 | + |
265 | 264 | String relativePath = PathTool.getRelativePath( |
266 | | - getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath()); |
| 265 | + getReportOutputDirectory().getAbsolutePath(), xrefTestLocation.getAbsolutePath()); |
267 | 266 | if (relativePath == null || relativePath.isEmpty()) { |
268 | 267 | relativePath = "."; |
269 | 268 | } |
270 | | - relativePath = relativePath + "/" + xrefLocation.getName(); |
271 | | - if (xrefLocation.exists()) { |
| 269 | + relativePath = relativePath + "/" + xrefTestLocation.getName(); |
| 270 | + if (xrefTestLocation.exists()) { |
272 | 271 | // XRef was already generated by manual execution of a lifecycle binding |
273 | 272 | location = relativePath; |
274 | 273 | } else { |
275 | 274 | // Not yet generated - check if the report is on its way |
276 | | - for (Object o : project.getReportPlugins()) { |
277 | | - ReportPlugin report = (ReportPlugin) o; |
278 | | - |
279 | | - String artifactId = report.getArtifactId(); |
280 | | - if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) { |
| 275 | + Reporting reporting = project.getModel().getReporting(); |
| 276 | + List<ReportPlugin> reportPlugins = |
| 277 | + reporting != null ? reporting.getPlugins() : Collections.<ReportPlugin>emptyList(); |
| 278 | + for (ReportPlugin plugin : reportPlugins) { |
| 279 | + String artifactId = plugin.getArtifactId(); |
| 280 | + if ("maven-jxr-plugin".equals(artifactId)) { |
281 | 281 | location = relativePath; |
282 | 282 | } |
283 | 283 | } |
@@ -290,6 +290,10 @@ private String determineXrefLocation() { |
290 | 290 | return location; |
291 | 291 | } |
292 | 292 |
|
| 293 | + private File getXrefTestLocation() { |
| 294 | + return xrefTestLocation != null ? xrefTestLocation : new File(getReportOutputDirectory(), "xref-test"); |
| 295 | + } |
| 296 | + |
293 | 297 | /** |
294 | 298 | * @param locale The locale |
295 | 299 | * @param key The key to search for |
|