Skip to content

Commit

Permalink
[SUREFIRE-2289] Make exceptions more appropriate to context (#798)
Browse files Browse the repository at this point in the history
* Prefer exceptions more appropriate to context
  • Loading branch information
elharo authored Dec 8, 2024
1 parent 9aa6967 commit 6271ca1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
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

0 comments on commit 6271ca1

Please sign in to comment.