Skip to content

Commit

Permalink
Prefer exceptions more appropriate to context
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Nov 26, 2024
1 parent 9aa6967 commit 00fcbee
Show file tree
Hide file tree
Showing 2 changed files with 15 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,8 @@ 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,10 +19,12 @@
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;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
Expand Down Expand Up @@ -72,7 +74,8 @@ 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,12 +95,16 @@ 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 );
}
}

public static void fromRunResultToFile(RunResult fromRunResult, File toFailsafeSummaryXml) throws IOException {
Expand Down

0 comments on commit 00fcbee

Please sign in to comment.