You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/12/03 19:36:58 UTC
(maven-surefire) 02/02: Dynamically calculate xrefTestLocation
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch doxia-2.0.0
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit e06e3c44bd33516b99f79d9d0c443ad5bf3a4e88
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Thu Nov 16 21:39:41 2023 +0100
Dynamically calculate xrefTestLocation
@kriegaex
---
.../surefire/report/AbstractSurefireReport.java | 41 ++++++++++++++--------
.../surefire/report/SurefireReportTest.java | 4 +--
.../plugin-config.xml | 2 +-
.../plugin-config.xml | 2 +-
.../plugin-config.xml | 2 +-
.../plugin-config.xml | 2 +-
.../basic-surefire-report-test/plugin-config.xml | 2 +-
.../plugin-config.xml | 2 +-
.../surefire-report-enclosed/plugin-config.xml | 2 +-
.../plugin-config.xml | 2 +-
.../surefire-report-nestedClass/plugin-config.xml | 2 +-
.../surefire-report-single-error/plugin-config.xml | 2 +-
12 files changed, 38 insertions(+), 27 deletions(-)
diff --git a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/AbstractSurefireReport.java b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/AbstractSurefireReport.java
index a12949af6..b3ab9b1e2 100644
--- a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/AbstractSurefireReport.java
+++ b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/AbstractSurefireReport.java
@@ -25,6 +25,7 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -32,6 +33,7 @@ import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.Reporting;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
@@ -78,16 +80,19 @@ public abstract class AbstractSurefireReport extends AbstractMavenReport {
private File reportsDirectory;
/**
- * Location of the Xrefs to link.
+ * Link the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is
+ * being used.
*/
- @Parameter(defaultValue = "${project.reporting.outputDirectory}/xref-test")
- private File xrefLocation;
+ @Parameter(property = "linkXRef", defaultValue = "true")
+ private boolean linkXRef;
/**
- * Whether to link the XRef if found.
+ * Location where Test Source XRef is generated for this project.
+ * <br>
+ * <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /xref-test}
*/
- @Parameter(defaultValue = "true", property = "linkXRef")
- private boolean linkXRef;
+ @Parameter
+ private File xrefTestLocation;
/**
* Whether to build an aggregated report at the root, or build individual reports.
@@ -150,7 +155,7 @@ public abstract class AbstractSurefireReport extends AbstractMavenReport {
locale,
getConsoleLogger(),
getReportsDirectories(),
- determineXrefLocation(),
+ constructXrefTestLocation(),
showSuccess);
r.render();
}
@@ -252,12 +257,13 @@ public abstract class AbstractSurefireReport extends AbstractMavenReport {
return result;
}
- private String determineXrefLocation() {
+ private String constructXrefTestLocation() {
String location = null;
-
if (linkXRef) {
- String relativePath = PathTool.getRelativePath(
- getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath());
+ File xrefLocation = getXrefTestLocation();
+
+ String relativePath =
+ PathTool.getRelativePath(getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath());
if (relativePath == null || relativePath.isEmpty()) {
relativePath = ".";
}
@@ -267,10 +273,11 @@ public abstract class AbstractSurefireReport extends AbstractMavenReport {
location = relativePath;
} else {
// Not yet generated - check if the report is on its way
- for (Object o : project.getReportPlugins()) {
- ReportPlugin report = (ReportPlugin) o;
-
- String artifactId = report.getArtifactId();
+ Reporting reporting = project.getModel().getReporting();
+ List<ReportPlugin> reportPlugins =
+ reporting != null ? reporting.getPlugins() : Collections.<ReportPlugin>emptyList();
+ for (ReportPlugin plugin : reportPlugins) {
+ String artifactId = plugin.getArtifactId();
if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) {
location = relativePath;
}
@@ -284,6 +291,10 @@ public abstract class AbstractSurefireReport extends AbstractMavenReport {
return location;
}
+ private File getXrefTestLocation() {
+ return xrefTestLocation != null ? xrefTestLocation : new File(getReportOutputDirectory(), "xref-test" );
+ }
+
/**
* @param locale The locale
* @param key The key to search for
diff --git a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportTest.java b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportTest.java
index 1f42a6076..f84d504b3 100644
--- a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportTest.java
+++ b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportTest.java
@@ -90,7 +90,7 @@ public class SurefireReportTest extends AbstractMojoTestCase {
File outputDir = (File) getVariableValueFromObject(mojo, "outputDirectory");
boolean showSuccess = (Boolean) getVariableValueFromObject(mojo, "showSuccess");
File reportsDir = (File) getVariableValueFromObject(mojo, "reportsDirectory");
- File xrefLocation = (File) getVariableValueFromObject(mojo, "xrefLocation");
+ File xrefTestLocation = (File) getVariableValueFromObject(mojo, "xrefTestLocation");
boolean linkXRef = (Boolean) getVariableValueFromObject(mojo, "linkXRef");
assertEquals(new File(getBasedir() + "/target/site/unit/basic-surefire-report-test"), outputDir);
@@ -101,7 +101,7 @@ public class SurefireReportTest extends AbstractMojoTestCase {
reportsDir.getAbsolutePath());
assertEquals(
new File(getBasedir() + "/target/site/unit/basic-surefire-report-test/xref-test").getAbsolutePath(),
- xrefLocation.getAbsolutePath());
+ xrefTestLocation.getAbsolutePath());
assertTrue(linkXRef);
mojo.execute();
diff --git a/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-anchor-test-cases/plugin-config.xml b/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-anchor-test-cases/plugin-config.xml
index fe0e78d7f..a215e335a 100644
--- a/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-anchor-test-cases/plugin-config.xml
+++ b/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-anchor-test-cases/plugin-config.xml
@@ -29,7 +29,7 @@
<reportsDirectory>${basedir}/src/test/resources/unit/basic-surefire-report-anchor-test-cases/surefire-reports
</reportsDirectory>
<outputName>surefire-report</outputName>
- <xrefLocation>${basedir}/target/site/unit/basic-surefire-report-anchor-test-cases/xref-test</xrefLocation>
+ <xrefTestLocation>${basedir}/target/site/unit/basic-surefire-report-anchor-test-cases/xref-test</xrefTestLocation>
</configuration>
</plugin>
</plugins>
diff --git a/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-linkxref-false/plugin-config.xml b/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-linkxref-false/plugin-config.xml
index 01f10b34a..b1fd94a51 100644
--- a/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-linkxref-false/plugin-config.xml
+++ b/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-linkxref-false/plugin-config.xml
@@ -29,7 +29,7 @@
<reportsDirectory>${basedir}/src/test/resources/unit/basic-surefire-report-linkxref-false/surefire-reports
</reportsDirectory>
<outputName>surefire-report</outputName>
- <xrefLocation>${basedir}/target/site/unit/basic-surefire-report-linkxref-false/xref-test</xrefLocation>
+ <xrefTestLocation>${basedir}/target/site/unit/basic-surefire-report-linkxref-false/xref-test</xrefTestLocation>
<linkXRef>false</linkXRef>
</configuration>
</plugin>
diff --git a/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-reporting-null/plugin-config.xml b/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-reporting-null/plugin-config.xml
index f53e5dfea..ee4e97417 100644
--- a/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-reporting-null/plugin-config.xml
+++ b/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-reporting-null/plugin-config.xml
@@ -29,7 +29,7 @@
<reportsDirectory>${basedir}/src/test/resources/unit/basic-surefire-report-reporting-null/surefire-reports
</reportsDirectory>
<outputName>surefire-report</outputName>
- <xrefLocation>${basedir}/target/site/unit/basic-surefire-report-test/xref-test</xrefLocation>
+ <xrefTestLocation>${basedir}/target/site/unit/basic-surefire-report-test/xref-test</xrefTestLocation>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
diff --git a/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-success-false/plugin-config.xml b/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-success-false/plugin-config.xml
index 27d6b2e38..452fb0516 100644
--- a/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-success-false/plugin-config.xml
+++ b/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-success-false/plugin-config.xml
@@ -29,7 +29,7 @@
<reportsDirectory>${basedir}/src/test/resources/unit/basic-surefire-report-success-false/surefire-reports
</reportsDirectory>
<outputName>surefire-report</outputName>
- <xrefLocation>${basedir}/target/site/unit/basic-surefire-report-success-false/xref-test</xrefLocation>
+ <xrefTestLocation>${basedir}/target/site/unit/basic-surefire-report-success-false/xref-test</xrefTestLocation>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
diff --git a/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-test/plugin-config.xml b/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-test/plugin-config.xml
index 782c972c8..5a4f3fb56 100644
--- a/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-test/plugin-config.xml
+++ b/maven-surefire-report-plugin/src/test/resources/unit/basic-surefire-report-test/plugin-config.xml
@@ -29,7 +29,7 @@
<reportsDirectory>${basedir}/src/test/resources/unit/basic-surefire-report-test/surefire-reports
</reportsDirectory>
<outputName>surefire-report</outputName>
- <xrefLocation>${basedir}/target/site/unit/basic-surefire-report-test/xref-test</xrefLocation>
+ <xrefTestLocation>${basedir}/target/site/unit/basic-surefire-report-test/xref-test</xrefTestLocation>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
diff --git a/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-enclosed-trimStackTrace/plugin-config.xml b/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-enclosed-trimStackTrace/plugin-config.xml
index d02fe60da..eca42f021 100644
--- a/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-enclosed-trimStackTrace/plugin-config.xml
+++ b/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-enclosed-trimStackTrace/plugin-config.xml
@@ -29,7 +29,7 @@
<reportsDirectory>${basedir}/src/test/resources/unit/surefire-report-enclosed-trimStackTrace/surefire-reports
</reportsDirectory>
<outputName>surefire-report</outputName>
- <xrefLocation>${basedir}/target/site/unit/surefire-report-enclosed-trimStackTrace/xref-test</xrefLocation>
+ <xrefTestLocation>${basedir}/target/site/unit/surefire-report-enclosed-trimStackTrace/xref-test</xrefTestLocation>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
diff --git a/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-enclosed/plugin-config.xml b/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-enclosed/plugin-config.xml
index 5bb6b5ab6..0424ef127 100644
--- a/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-enclosed/plugin-config.xml
+++ b/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-enclosed/plugin-config.xml
@@ -29,7 +29,7 @@
<reportsDirectory>${basedir}/src/test/resources/unit/surefire-report-enclosed/surefire-reports
</reportsDirectory>
<outputName>surefire-report</outputName>
- <xrefLocation>${basedir}/target/site/unit/surefire-report-enclosed/xref-test</xrefLocation>
+ <xrefTestLocation>${basedir}/target/site/unit/surefire-report-enclosed/xref-test</xrefTestLocation>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
diff --git a/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-nestedClass-trimStackTrace/plugin-config.xml b/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-nestedClass-trimStackTrace/plugin-config.xml
index 7e6c0a506..e1657df72 100644
--- a/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-nestedClass-trimStackTrace/plugin-config.xml
+++ b/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-nestedClass-trimStackTrace/plugin-config.xml
@@ -29,7 +29,7 @@
<reportsDirectory>${basedir}/src/test/resources/unit/surefire-report-nestedClass-trimStackTrace/surefire-reports
</reportsDirectory>
<outputName>surefire-report</outputName>
- <xrefLocation>${basedir}/target/site/unit/surefire-report-nestedClass-trimStackTrace/xref-test</xrefLocation>
+ <xrefTestLocation>${basedir}/target/site/unit/surefire-report-nestedClass-trimStackTrace/xref-test</xrefTestLocation>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
diff --git a/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-nestedClass/plugin-config.xml b/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-nestedClass/plugin-config.xml
index 5b577227c..f8e4752b0 100644
--- a/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-nestedClass/plugin-config.xml
+++ b/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-nestedClass/plugin-config.xml
@@ -29,7 +29,7 @@
<reportsDirectory>${basedir}/src/test/resources/unit/surefire-report-nestedClass/surefire-reports
</reportsDirectory>
<outputName>surefire-report</outputName>
- <xrefLocation>${basedir}/target/site/unit/surefire-report-nestedClass/xref-test</xrefLocation>
+ <xrefTestLocation>${basedir}/target/site/unit/surefire-report-nestedClass/xref-test</xrefTestLocation>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
diff --git a/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-single-error/plugin-config.xml b/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-single-error/plugin-config.xml
index cfb5505a2..df3e56899 100644
--- a/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-single-error/plugin-config.xml
+++ b/maven-surefire-report-plugin/src/test/resources/unit/surefire-report-single-error/plugin-config.xml
@@ -29,7 +29,7 @@
<reportsDirectory>${basedir}/src/test/resources/unit/surefire-report-single-error/surefire-reports
</reportsDirectory>
<outputName>surefire-report</outputName>
- <xrefLocation>${basedir}/target/site/unit/surefire-report-single-error/xref-test</xrefLocation>
+ <xrefTestLocation>${basedir}/target/site/unit/surefire-report-single-error/xref-test</xrefTestLocation>
<linkXRef>true</linkXRef>
</configuration>
</plugin>