This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch inject
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 00fcbeea6ad309c986f537734e596beaa9cc3bad
Author: Elliotte Rusty Harold <elh...@ibiblio.org>
AuthorDate: Tue Nov 26 04:06:23 2024 -0500

    Prefer exceptions more appropriate to context
---
 .../java/org/apache/maven/plugin/failsafe/VerifyMojo.java    | 12 ++++++------
 .../maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java  | 11 +++++++++--
 2 files changed, 15 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..8bfa5a62f 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,8 @@ 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..30d65330e 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,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;
@@ -72,7 +74,8 @@ 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,12 +95,16 @@ 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 );
+        }
     }
 
     public static void fromRunResultToFile(RunResult fromRunResult, File 
toFailsafeSummaryXml) throws IOException {

Reply via email to