Skip to content

Commit 93c0b30

Browse files
committed
Dynamically calculate xrefTestLocation
@kriegaex
1 parent 6a5f590 commit 93c0b30

File tree

12 files changed

+37
-27
lines changed

12 files changed

+37
-27
lines changed

maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/AbstractSurefireReport.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
import java.net.URLClassLoader;
2626
import java.text.MessageFormat;
2727
import java.util.ArrayList;
28+
import java.util.Collections;
2829
import java.util.Iterator;
2930
import java.util.List;
3031
import java.util.Locale;
3132
import java.util.MissingResourceException;
3233
import java.util.ResourceBundle;
3334

3435
import org.apache.maven.model.ReportPlugin;
36+
import org.apache.maven.model.Reporting;
3537
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
3638
import org.apache.maven.plugins.annotations.Component;
3739
import org.apache.maven.plugins.annotations.Parameter;
@@ -78,16 +80,18 @@ public abstract class AbstractSurefireReport extends AbstractMavenReport {
7880
private File reportsDirectory;
7981

8082
/**
81-
* Location of the Xrefs to link.
83+
* Link the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is
84+
* being used.
8285
*/
83-
@Parameter(defaultValue = "${project.reporting.outputDirectory}/xref-test")
84-
private File xrefLocation;
86+
@Parameter(property = "linkXRef", defaultValue = "true")
87+
private boolean linkXRef;
8588

8689
/**
87-
* Whether to link the XRef if found.
90+
* Location where Test Source XRef is generated for this project. The default value is calculated from
91+
* {@link #getReportOutputDirectory()} and concatenated with {@code xref-test}.
8892
*/
89-
@Parameter(defaultValue = "true", property = "linkXRef")
90-
private boolean linkXRef;
93+
@Parameter
94+
private File xrefTestLocation;
9195

9296
/**
9397
* Whether to build an aggregated report at the root, or build individual reports.
@@ -150,7 +154,7 @@ public void executeReport(Locale locale) throws MavenReportException {
150154
locale,
151155
getConsoleLogger(),
152156
getReportsDirectories(),
153-
determineXrefLocation(),
157+
constructXrefTestLocation(),
154158
showSuccess);
155159
r.render();
156160
}
@@ -252,12 +256,13 @@ private List<MavenProject> getProjectsWithoutRoot() {
252256
return result;
253257
}
254258

255-
private String determineXrefLocation() {
259+
private String constructXrefTestLocation() {
256260
String location = null;
257-
258261
if (linkXRef) {
259-
String relativePath = PathTool.getRelativePath(
260-
getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath());
262+
File xrefLocation = getXrefTestLocation();
263+
264+
String relativePath =
265+
PathTool.getRelativePath(getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath());
261266
if (relativePath == null || relativePath.isEmpty()) {
262267
relativePath = ".";
263268
}
@@ -267,10 +272,11 @@ private String determineXrefLocation() {
267272
location = relativePath;
268273
} else {
269274
// Not yet generated - check if the report is on its way
270-
for (Object o : project.getReportPlugins()) {
271-
ReportPlugin report = (ReportPlugin) o;
272-
273-
String artifactId = report.getArtifactId();
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();
274280
if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) {
275281
location = relativePath;
276282
}
@@ -284,6 +290,10 @@ private String determineXrefLocation() {
284290
return location;
285291
}
286292

293+
private File getXrefTestLocation() {
294+
return xrefTestLocation != null ? xrefTestLocation : new File(getReportOutputDirectory(), "xref-test" );
295+
}
296+
287297
/**
288298
* @param locale The locale
289299
* @param key The key to search for

maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void testBasicSurefireReport() throws Exception {
9090
File outputDir = (File) getVariableValueFromObject(mojo, "outputDirectory");
9191
boolean showSuccess = (Boolean) getVariableValueFromObject(mojo, "showSuccess");
9292
File reportsDir = (File) getVariableValueFromObject(mojo, "reportsDirectory");
93-
File xrefLocation = (File) getVariableValueFromObject(mojo, "xrefLocation");
93+
File xrefTestLocation = (File) getVariableValueFromObject(mojo, "xrefTestLocation");
9494
boolean linkXRef = (Boolean) getVariableValueFromObject(mojo, "linkXRef");
9595

9696
assertEquals(new File(getBasedir() + "/target/site/unit/basic-surefire-report-test"), outputDir);
@@ -101,7 +101,7 @@ public void testBasicSurefireReport() throws Exception {
101101
reportsDir.getAbsolutePath());
102102
assertEquals(
103103
new File(getBasedir() + "/target/site/unit/basic-surefire-report-test/xref-test").getAbsolutePath(),
104-
xrefLocation.getAbsolutePath());
104+
xrefTestLocation.getAbsolutePath());
105105
assertTrue(linkXRef);
106106

107107
mojo.execute();

maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-anchor-test-cases/plugin-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<reportsDirectory>${basedir}/src/test/resources/unit/basic-surefire-report-anchor-test-cases/surefire-reports
3030
</reportsDirectory>
3131
<outputName>surefire-report</outputName>
32-
<xrefLocation>${basedir}/target/site/unit/basic-surefire-report-anchor-test-cases/xref-test</xrefLocation>
32+
<xrefTestLocation>${basedir}/target/site/unit/basic-surefire-report-anchor-test-cases/xref-test</xrefTestLocation>
3333
</configuration>
3434
</plugin>
3535
</plugins>

maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-linkxref-false/plugin-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<reportsDirectory>${basedir}/src/test/resources/unit/basic-surefire-report-linkxref-false/surefire-reports
3030
</reportsDirectory>
3131
<outputName>surefire-report</outputName>
32-
<xrefLocation>${basedir}/target/site/unit/basic-surefire-report-linkxref-false/xref-test</xrefLocation>
32+
<xrefTestLocation>${basedir}/target/site/unit/basic-surefire-report-linkxref-false/xref-test</xrefTestLocation>
3333
<linkXRef>false</linkXRef>
3434
</configuration>
3535
</plugin>

maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-reporting-null/plugin-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<reportsDirectory>${basedir}/src/test/resources/unit/basic-surefire-report-reporting-null/surefire-reports
3030
</reportsDirectory>
3131
<outputName>surefire-report</outputName>
32-
<xrefLocation>${basedir}/target/site/unit/basic-surefire-report-test/xref-test</xrefLocation>
32+
<xrefTestLocation>${basedir}/target/site/unit/basic-surefire-report-test/xref-test</xrefTestLocation>
3333
<linkXRef>true</linkXRef>
3434
</configuration>
3535
</plugin>

maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-success-false/plugin-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<reportsDirectory>${basedir}/src/test/resources/unit/basic-surefire-report-success-false/surefire-reports
3030
</reportsDirectory>
3131
<outputName>surefire-report</outputName>
32-
<xrefLocation>${basedir}/target/site/unit/basic-surefire-report-success-false/xref-test</xrefLocation>
32+
<xrefTestLocation>${basedir}/target/site/unit/basic-surefire-report-success-false/xref-test</xrefTestLocation>
3333
<linkXRef>true</linkXRef>
3434
</configuration>
3535
</plugin>

maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-test/plugin-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<reportsDirectory>${basedir}/src/test/resources/unit/basic-surefire-report-test/surefire-reports
3030
</reportsDirectory>
3131
<outputName>surefire-report</outputName>
32-
<xrefLocation>${basedir}/target/site/unit/basic-surefire-report-test/xref-test</xrefLocation>
32+
<xrefTestLocation>${basedir}/target/site/unit/basic-surefire-report-test/xref-test</xrefTestLocation>
3333
<linkXRef>true</linkXRef>
3434
</configuration>
3535
</plugin>

maven-surefire-report-plugin/src/test/resources/unit/surefire-report-enclosed-trimStackTrace/plugin-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<reportsDirectory>${basedir}/src/test/resources/unit/surefire-report-enclosed-trimStackTrace/surefire-reports
3030
</reportsDirectory>
3131
<outputName>surefire-report</outputName>
32-
<xrefLocation>${basedir}/target/site/unit/surefire-report-enclosed-trimStackTrace/xref-test</xrefLocation>
32+
<xrefTestLocation>${basedir}/target/site/unit/surefire-report-enclosed-trimStackTrace/xref-test</xrefTestLocation>
3333
<linkXRef>true</linkXRef>
3434
</configuration>
3535
</plugin>

maven-surefire-report-plugin/src/test/resources/unit/surefire-report-enclosed/plugin-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<reportsDirectory>${basedir}/src/test/resources/unit/surefire-report-enclosed/surefire-reports
3030
</reportsDirectory>
3131
<outputName>surefire-report</outputName>
32-
<xrefLocation>${basedir}/target/site/unit/surefire-report-enclosed/xref-test</xrefLocation>
32+
<xrefTestLocation>${basedir}/target/site/unit/surefire-report-enclosed/xref-test</xrefTestLocation>
3333
<linkXRef>true</linkXRef>
3434
</configuration>
3535
</plugin>

maven-surefire-report-plugin/src/test/resources/unit/surefire-report-nestedClass-trimStackTrace/plugin-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<reportsDirectory>${basedir}/src/test/resources/unit/surefire-report-nestedClass-trimStackTrace/surefire-reports
3030
</reportsDirectory>
3131
<outputName>surefire-report</outputName>
32-
<xrefLocation>${basedir}/target/site/unit/surefire-report-nestedClass-trimStackTrace/xref-test</xrefLocation>
32+
<xrefTestLocation>${basedir}/target/site/unit/surefire-report-nestedClass-trimStackTrace/xref-test</xrefTestLocation>
3333
<linkXRef>true</linkXRef>
3434
</configuration>
3535
</plugin>

0 commit comments

Comments
 (0)