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-2289] Make exceptions more appropriate to context #798

Merged
merged 3 commits into from
Dec 8, 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 @@ -19,6 +19,7 @@
package org.apache.maven.plugin.failsafe;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

import org.apache.maven.execution.MavenSession;
Expand Down Expand Up @@ -174,20 +175,18 @@ public void execute() throws MojoExecutionException, MojoFailureException {
logDebugOrCliShowErrors(
capitalizeFirstLetter(getPluginName()) + " report directory: " + getReportsDirectory());

RunResult summary;
try {
summary = existsSummaryFile() ? readSummary(summaryFile) : noTestsRun();
RunResult summary = existsSummaryFile() ? readSummary(summaryFile) : noTestsRun();

if (existsSummaryFiles()) {
for (final File summaryFile : summaryFiles) {
summary = summary.aggregate(readSummary(summaryFile));
}
}
} catch (Exception e) {
reportExecution(this, summary, getConsoleLogger(), getBooterForkException(summary));
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}

reportExecution(this, summary, getConsoleLogger(), getBooterForkException(summary));
}
}

Expand Down Expand Up @@ -215,7 +214,7 @@ private PluginConsoleLogger getConsoleLogger() {
return consoleLogger;
}

private RunResult readSummary(File summaryFile) throws Exception {
private RunResult readSummary(File summaryFile) throws IOException {
return FailsafeSummaryXmlUtils.toRunResult(summaryFile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.maven.plugin.failsafe.util;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import java.io.File;
Expand Down Expand Up @@ -72,7 +73,7 @@ private FailsafeSummaryXmlUtils() {
throw new IllegalStateException("No instantiable constructor.");
}

public static RunResult toRunResult(File failsafeSummaryXml) throws Exception {
public static RunResult toRunResult(File failsafeSummaryXml) throws IOException {
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();

Expand All @@ -92,11 +93,13 @@ public static RunResult toRunResult(File failsafeSummaryXml) throws Exception {
parseInt(errors),
parseInt(failures),
parseInt(skipped),
// FIXME Backwards compatability: to be replaced with parseInt in a future release
// FIXME Backwards compatibility: to be replaced with parseInt in a future release
// synchronize with maven-surefire-plugin/src/site/resources/xsd/failsafe-summary.xsd
isBlank(flakes) ? 0 : parseInt(flakes),
isBlank(failureMessage) ? null : unescapeXml(failureMessage),
parseBoolean(timeout));
} catch (XPathExpressionException | NumberFormatException e) {
throw new IOException("Could not parse " + failsafeSummaryXml.getPath(), e);
}
}

Expand Down