Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-2228] Upgrade to Doxia 2.0.0 Milestone Stack #629

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
* Abstract base class for running tests using Surefire.
*
* @author Stephen Connolly
* @version $Id: SurefirePlugin.java 945065 2010-05-17 10:26:22Z stephenc $
*/
public abstract class AbstractSurefireMojo extends AbstractMojo implements SurefireExecutionParameters {
private static final Map<String, String> JAVA_9_MATCHER_OLD_NOTATION = singletonMap("version", "[1.9,)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
defaultPhase = LifecyclePhase.TEST,
threadSafe = true,
requiresDependencyResolution = ResolutionScope.TEST)
public class SurefirePlugin extends AbstractSurefireMojo implements SurefireReportParameters {
public class SurefireMojo extends AbstractSurefireMojo implements SurefireReportParameters {

/**
* The directory containing generated classes of the project being tested. This will be included after the test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@
/**
*
*/
public class SurefirePluginTest extends TestCase {
public class SurefireMojoTest extends TestCase {
@Rule
public final ExpectedException e = ExpectedException.none();

public void testDefaultIncludes() {
assertThat(new SurefirePlugin().getDefaultIncludes())
assertThat(new SurefireMojo().getDefaultIncludes())
.containsOnly("**/Test*.java", "**/*Test.java", "**/*Tests.java", "**/*TestCase.java");
}

public void testReportSchemaLocation() {
assertThat(new SurefirePlugin().getReportSchemaLocation())
assertThat(new SurefireMojo().getReportSchemaLocation())
.isEqualTo("https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd");
}

public void testFailIfNoTests() throws Exception {
RunResult runResult = new RunResult(0, 0, 0, 0);
try {
SurefirePlugin plugin = new SurefirePlugin();
plugin.setFailIfNoTests(true);
plugin.handleSummary(runResult, null);
SurefireMojo mojo = new SurefireMojo();
mojo.setFailIfNoTests(true);
mojo.handleSummary(runResult, null);
} catch (MojoFailureException e) {
assertThat(e.getLocalizedMessage())
.isEqualTo("No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)");
Expand All @@ -63,8 +63,8 @@ public void testFailIfNoTests() throws Exception {
public void testTestFailure() throws Exception {
RunResult runResult = new RunResult(1, 0, 1, 0);
try {
SurefirePlugin plugin = new SurefirePlugin();
plugin.handleSummary(runResult, null);
SurefireMojo mojo = new SurefireMojo();
mojo.handleSummary(runResult, null);
} catch (MojoFailureException e) {
assertThat(e.getLocalizedMessage())
.isEqualTo("There are test failures.\n\nPlease refer to null "
Expand All @@ -79,47 +79,47 @@ public void testTestFailure() throws Exception {
}

public void testPluginName() {
assertThat(new SurefirePlugin().getPluginName()).isEqualTo("surefire");
assertThat(new SurefireMojo().getPluginName()).isEqualTo("surefire");
}

public void testShouldGetNullEnv() {
SurefirePlugin plugin = new SurefirePlugin();
assertThat(plugin.getExcludedEnvironmentVariables()).hasSize(0);
SurefireMojo mojo = new SurefireMojo();
assertThat(mojo.getExcludedEnvironmentVariables()).hasSize(0);
}

public void testShouldGetEnv() {
SurefirePlugin plugin = new SurefirePlugin();
plugin.setExcludedEnvironmentVariables(new String[] {"ABC", "KLM"});
assertThat(plugin.getExcludedEnvironmentVariables()).hasSize(2).contains("ABC", "KLM");
SurefireMojo mojo = new SurefireMojo();
mojo.setExcludedEnvironmentVariables(new String[] {"ABC", "KLM"});
assertThat(mojo.getExcludedEnvironmentVariables()).hasSize(2).contains("ABC", "KLM");
}

public void testShouldGetPropertyFile() {
SurefirePlugin plugin = new SurefirePlugin();
plugin.setSystemPropertiesFile(new File("testShouldGetPropertyFile"));
assertThat(plugin.getSystemPropertiesFile()).isEqualTo(new File("testShouldGetPropertyFile"));
SurefireMojo mojo = new SurefireMojo();
mojo.setSystemPropertiesFile(new File("testShouldGetPropertyFile"));
assertThat(mojo.getSystemPropertiesFile()).isEqualTo(new File("testShouldGetPropertyFile"));
}

public void testNegativeFailOnFlakeCount() {
SurefirePlugin plugin = new SurefirePlugin();
plugin.setFailOnFlakeCount(-1);
SurefireMojo mojo = new SurefireMojo();
mojo.setFailOnFlakeCount(-1);
e.expect(MojoFailureException.class);
e.expectMessage("Parameter \"failOnFlakeCount\" should not be negative.");
}

public void testFailOnFlakeCountWithoutRerun() {
SurefirePlugin plugin = new SurefirePlugin();
plugin.setFailOnFlakeCount(1);
SurefireMojo mojo = new SurefireMojo();
mojo.setFailOnFlakeCount(1);
e.expect(MojoFailureException.class);
e.expectMessage("\"failOnFlakeCount\" requires rerunFailingTestsCount to be at least 1.");
}

public void testShouldHaveJUnit5EnginesFilter() {
SurefirePlugin plugin = new SurefirePlugin();
SurefireMojo mojo = new SurefireMojo();

plugin.setIncludeJUnit5Engines(new String[] {"e1", "e2"});
assertThat(plugin.getIncludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});
mojo.setIncludeJUnit5Engines(new String[] {"e1", "e2"});
assertThat(mojo.getIncludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});

plugin.setExcludeJUnit5Engines(new String[] {"e1", "e2"});
assertThat(plugin.getExcludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});
mojo.setExcludeJUnit5Engines(new String[] {"e1", "e2"});
assertThat(mojo.getExcludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});
}
}
7 changes: 2 additions & 5 deletions maven-surefire-report-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</prerequisites>

<properties>
<doxiaVersion>1.12.0</doxiaVersion>
<doxiaVersion>2.0.0-M12</doxiaVersion>
</properties>

<dependencies>
Expand Down Expand Up @@ -111,13 +111,10 @@
<artifactId>doxia-core</artifactId>
<version>${doxiaVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>4.0.0-M15</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@
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;
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;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.settings.Settings;
import org.apache.maven.shared.utils.PathTool;
import org.codehaus.plexus.i18n.I18N;
Expand All @@ -55,7 +56,7 @@
*
* @author Stephen Connolly
*/
public abstract class AbstractSurefireReportMojo extends AbstractMavenReport {
public abstract class AbstractSurefireReport extends AbstractMavenReport {

/**
* If set to false, only failures are shown.
Expand All @@ -78,23 +79,19 @@ public abstract class AbstractSurefireReportMojo extends AbstractMavenReport {
private File reportsDirectory;

/**
* The projects in the reactor for aggregation report.
* Link the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is
* being used.
*/
@Parameter(defaultValue = "${reactorProjects}", readonly = true)
private List<MavenProject> reactorProjects;

/**
* Link the failed tests line numbers to the source xref. Will link
* automatically if Maven JXR plugin is being used.
*/
@Parameter(defaultValue = "true", property = "linkXRef")
@Parameter(property = "linkXRef", defaultValue = "true")
private boolean linkXRef;

/**
* Location of the Xrefs to link.
* Location where Test Source XRef is generated for this project.
* <br>
* <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /xref-test}
*/
@Parameter(defaultValue = "${project.reporting.outputDirectory}/xref-test")
private File xrefLocation;
@Parameter
private File xrefTestLocation;

/**
* Whether to build an aggregated report at the root, or build individual reports.
Expand Down Expand Up @@ -149,16 +146,16 @@ protected boolean isGeneratedWhenNoResults() {
* {@inheritDoc}
*/
@Override
public void executeReport(Locale locale) throws MavenReportException {
public void executeReport(Locale locale) {
SurefireReportRenderer r = new SurefireReportRenderer(
getSink(),
getI18N(locale),
getI18Nsection(),
locale,
getConsoleLogger(),
showSuccess,
getReportsDirectories(),
determineXrefLocation());
constructXrefTestLocation(),
showSuccess);
r.render();
}

Expand Down Expand Up @@ -259,25 +256,28 @@ private List<MavenProject> getProjectsWithoutRoot() {
return result;
}

private String determineXrefLocation() {
private String constructXrefTestLocation() {
String location = null;

if (linkXRef) {
String relativePath = PathTool.getRelativePath(getOutputDirectory(), xrefLocation.getAbsolutePath());
File xrefTestLocation = getXrefTestLocation();

String relativePath = PathTool.getRelativePath(
getReportOutputDirectory().getAbsolutePath(), xrefTestLocation.getAbsolutePath());
if (relativePath == null || relativePath.isEmpty()) {
relativePath = ".";
}
relativePath = relativePath + "/" + xrefLocation.getName();
if (xrefLocation.exists()) {
relativePath = relativePath + "/" + xrefTestLocation.getName();
if (xrefTestLocation.exists()) {
// XRef was already generated by manual execution of a lifecycle binding
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();
if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) {
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)) {
location = relativePath;
}
}
Expand All @@ -290,6 +290,10 @@ private String determineXrefLocation() {
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
Expand Down Expand Up @@ -346,6 +350,10 @@ protected MavenProject getProject() {
return project;
}

protected List<MavenProject> getReactorProjects() {
return reactorProjects;
}

// TODO Review, especially Locale.getDefault()
private static class CustomI18N implements I18N {
private final MavenProject project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
*/
@Mojo(name = "failsafe-report-only")
@SuppressWarnings("unused")
public class FailsafeReportMojo extends AbstractSurefireReportMojo {
public class FailsafeOnlyReport extends AbstractSurefireReport {

/**
* The filename to use for the report.
*/
@Parameter(defaultValue = "failsafe-report", property = "outputName", required = true)
@Parameter(defaultValue = "failsafe", property = "outputName", required = true)
private String outputName;

/**
Expand All @@ -61,7 +61,7 @@ public class FailsafeReportMojo extends AbstractSurefireReportMojo {
@Override
protected File getSurefireReportsDirectory(MavenProject subProject) {
String buildDir = subProject.getBuild().getDirectory();
return new File(buildDir + "/failsafe-reports");
return new File(buildDir, "failsafe-reports");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
@Mojo(name = "report-only")
@Execute(phase = LifecyclePhase.NONE)
@SuppressWarnings("unused")
public class SurefireReportOnlyMojo extends SurefireReportMojo {}
public class SurefireOnlyReport extends SurefireReport {}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
@Mojo(name = "report", inheritByDefault = false)
@Execute(lifecycle = "surefire", phase = LifecyclePhase.TEST)
@SuppressWarnings("unused")
public class SurefireReportMojo extends AbstractSurefireReportMojo {
public class SurefireReport extends AbstractSurefireReport {

/**
* The filename to use for the report.
*/
@Parameter(defaultValue = "surefire-report", property = "outputName", required = true)
@Parameter(defaultValue = "surefire", property = "outputName", required = true)
private String outputName;

/**
Expand Down
Loading