This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push: new 6271ca1e5 [SUREFIRE-2289] Make exceptions more appropriate to context (#798) 6271ca1e5 is described below commit 6271ca1e5d336ffacc2f280ab42b138fe34a810e Author: Elliotte Rusty Harold <elh...@users.noreply.github.com> AuthorDate: Sun Dec 8 15:30:15 2024 +0000 [SUREFIRE-2289] Make exceptions more appropriate to context (#798) * Prefer exceptions more appropriate to context --- .../java/org/apache/maven/plugin/failsafe/VerifyMojo.java | 11 +++++------ .../maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java | 7 +++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java index cef6391ec..4c2664f57 100644 --- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java +++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java @@ -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; @@ -174,20 +175,18 @@ public class VerifyMojo extends AbstractMojo implements SurefireReportParameters 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)); } } @@ -215,7 +214,7 @@ public class VerifyMojo extends AbstractMojo implements SurefireReportParameters return consoleLogger; } - private RunResult readSummary(File summaryFile) throws Exception { + private RunResult readSummary(File summaryFile) throws IOException { return FailsafeSummaryXmlUtils.toRunResult(summaryFile); } diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java index fac986b39..e72d34fcf 100644 --- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java +++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java @@ -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; @@ -72,7 +73,7 @@ public final class 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(); @@ -92,11 +93,13 @@ public final class FailsafeSummaryXmlUtils { 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); } }