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

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new b80af6e  Report jobs that end with an error and count them in verify
b80af6e is described below

commit b80af6ef2ecd17a2dbd0c631c71d3f10a796c0fd
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Thu Nov 26 12:45:37 2026 +0000

    Report jobs that end with an error and count them in verify
    
    A job that failed with anything but a RunFailureException was written to 
its BUILD report without a result, so invoker:verify counted it as nothing. The 
result is now set to error before the report is written, a job without a result 
counts as an error, and non-String values from script user properties are 
converted to Strings.
---
 src/it/errored-job-reported/invoker.properties     |  18 +++
 src/it/errored-job-reported/pom.xml                |  66 ++++++++++
 .../src/it/project/invoker.properties              |  19 +++
 src/it/errored-job-reported/src/it/project/pom.xml |  28 +++++
 src/it/errored-job-reported/verify.groovy          |  28 +++++
 src/it/user-properties-non-string/pom.xml          |  63 ++++++++++
 .../src/it/project/pom.xml                         |  54 ++++++++
 .../src/it/project/prebuild.groovy                 |  24 ++++
 .../maven/plugins/invoker/AbstractInvokerMojo.java |  35 ++++--
 .../maven/plugins/invoker/InvokerSession.java      |   5 +-
 .../maven/plugins/invoker/ErroredJobTest.java      | 138 +++++++++++++++++++++
 .../maven/plugins/invoker/InvokerSessionTest.java  |  17 +++
 12 files changed, 485 insertions(+), 10 deletions(-)

diff --git a/src/it/errored-job-reported/invoker.properties 
b/src/it/errored-job-reported/invoker.properties
new file mode 100644
index 0000000..e64d99e
--- /dev/null
+++ b/src/it/errored-job-reported/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.buildResult = failure
diff --git a/src/it/errored-job-reported/pom.xml 
b/src/it/errored-job-reported/pom.xml
new file mode 100644
index 0000000..c4520a3
--- /dev/null
+++ b/src/it/errored-job-reported/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.invoker</groupId>
+  <artifactId>errored-job-reported</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <description>Test to check that a job which ends with an error instead of a 
build failure is reported as an error and fails verify.</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <debug>true</debug>
+          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+          <pomIncludes>
+            <pomInclude>*/pom.xml</pomInclude>
+          </pomIncludes>
+          <goals>
+            <goal>validate</goal>
+          </goals>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>integration-test</goal>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/errored-job-reported/src/it/project/invoker.properties 
b/src/it/errored-job-reported/src/it/project/invoker.properties
new file mode 100644
index 0000000..18df0fe
--- /dev/null
+++ b/src/it/errored-job-reported/src/it/project/invoker.properties
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# not a number, so the job ends with a NumberFormatException and not with a 
build failure
+invoker.timeoutInSeconds = soon
diff --git a/src/it/errored-job-reported/src/it/project/pom.xml 
b/src/it/errored-job-reported/src/it/project/pom.xml
new file mode 100644
index 0000000..5e042b0
--- /dev/null
+++ b/src/it/errored-job-reported/src/it/project/pom.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>test</groupId>
+  <artifactId>errored-job</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+</project>
diff --git a/src/it/errored-job-reported/verify.groovy 
b/src/it/errored-job-reported/verify.groovy
new file mode 100644
index 0000000..461f7bb
--- /dev/null
+++ b/src/it/errored-job-reported/verify.groovy
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import groovy.xml.XmlSlurper
+
+// the timeout of the cloned project is not a number, so the job ends with an 
error and not a build failure
+def report = new XmlSlurper().parse(new File(basedir, 
'target/invoker-reports-test/BUILD-project.xml'))
+assert [email protected]() == 'error'
+assert report.failureMessage.text() != ''
+
+def buildLog = new File(basedir, 'build.log').text
+assert buildLog.contains('Errors: 1')
diff --git a/src/it/user-properties-non-string/pom.xml 
b/src/it/user-properties-non-string/pom.xml
new file mode 100644
index 0000000..7329d1e
--- /dev/null
+++ b/src/it/user-properties-non-string/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.invoker.its</groupId>
+  <artifactId>user-properties-non-string</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <description>
+    Test to check that non-String values put into the user properties by a 
pre-build script are passed as Strings
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    
<version.maven-enforcer-plugin>@version.maven-enforcer-plugin@</version.maven-enforcer-plugin>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <goals>
+            <goal>initialize</goal>
+          </goals>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/user-properties-non-string/src/it/project/pom.xml 
b/src/it/user-properties-non-string/src/it/project/pom.xml
new file mode 100644
index 0000000..ea2ce30
--- /dev/null
+++ b/src/it/user-properties-non-string/src/it/project/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins.invoker.its</groupId>
+  <artifactId>user-properties-non-string</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@version.maven-enforcer-plugin@</version>
+        <executions>
+          <execution>
+            <phase>initialize</phase>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <rules>
+            <requireProperty>
+              <property>gstring</property>
+              <regex>val-x</regex>
+            </requireProperty>
+          </rules>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/user-properties-non-string/src/it/project/prebuild.groovy 
b/src/it/user-properties-non-string/src/it/project/prebuild.groovy
new file mode 100644
index 0000000..3a69993
--- /dev/null
+++ b/src/it/user-properties-non-string/src/it/project/prebuild.groovy
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+def userProperties = context.get('userProperties')
+
+// a GString is not a String
+def v = 'x'
+userProperties.put('gstring', "val-${v}")
diff --git 
a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java 
b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
index 11c3e3e..415fe07 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -1633,7 +1633,7 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
      * @param globalInvokerProperties
      * @throws org.apache.maven.plugin.MojoExecutionException If the project 
could not be launched.
      */
-    private void runBuild(
+    void runBuild(
             File projectsDir,
             BuildJob buildJob,
             File settingsFile,
@@ -1656,18 +1656,21 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
             basedir = pomFile.getParentFile();
         }
 
-        File interpolatedPomFile = interpolatePomFile(pomFile, basedir);
         // FIXME: Think about the following code part -- ^^^^^^^ END
 
         getLog().info(buffer().a("Building: 
").strong(buildJob.getProject()).build());
 
-        InvokerProperties invokerProperties = getInvokerProperties(basedir, 
globalInvokerProperties);
+        File interpolatedPomFile = null;
+        try {
+            // inside the try, so that a job that cannot even be set up is 
written to the report as an error
+            interpolatedPomFile = interpolatePomFile(pomFile, basedir);
 
-        // let's set what details we can
-        buildJob.setName(invokerProperties.getJobName());
-        buildJob.setDescription(invokerProperties.getJobDescription());
+            InvokerProperties invokerProperties = 
getInvokerProperties(basedir, globalInvokerProperties);
+
+            // let's set what details we can
+            buildJob.setName(invokerProperties.getJobName());
+            buildJob.setDescription(invokerProperties.getJobDescription());
 
-        try {
             int selection = getSelection(invokerProperties, actualJreVersion);
             if (selection == 0) {
                 long startTime = System.currentTimeMillis();
@@ -1746,6 +1749,14 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
                 getLog().info(pad(buildJob).failure("FAILED").a(' ') + "(" + 
formatElapsedTime(buildJob.getTime())
                         + ")");
             }
+        } catch (Exception | Error e) {
+            // The report is written below while the exception is still 
propagating, so the result has to be set here.
+            buildJob.setResult(BuildJob.Result.ERROR);
+            buildJob.setFailureMessage(String.valueOf(e));
+
+            getLog().error(pad(buildJob).failure("ERROR").a(' ') + "(" + 
formatElapsedTime(buildJob.getTime()) + ")");
+            getLog().error("  " + e);
+            throw e;
         } finally {
             deleteInterpolatedPomFile(interpolatedPomFile);
             writeBuildReport(buildJob);
@@ -1988,7 +1999,7 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
 
                 Properties userProperties =
                         getUserProperties(basedir, 
invokerProperties.getUserPropertiesFile(invocationIndex));
-                userProperties.putAll(scriptUserProperties);
+                addScriptUserProperties(userProperties, scriptUserProperties);
                 request.setProperties(userProperties);
 
                 // Isolate the forked build from the environment that is 
invoking this plugin: clear
@@ -2026,6 +2037,14 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
         return true;
     }
 
+    /**
+     * Copies the user properties set by the scripts to the properties of the 
invocation. Scripts can put any object
+     * into the properties, for example a Groovy GString, but the invoker 
accepts only Strings.
+     */
+    static void addScriptUserProperties(Properties userProperties, Properties 
scriptUserProperties) {
+        scriptUserProperties.forEach((key, value) -> 
userProperties.put(String.valueOf(key), String.valueOf(value)));
+    }
+
     int getParallelThreadsCount() {
         if (parallelThreads.endsWith("C")) {
             float parallelThreadsMultiple =
diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerSession.java 
b/src/main/java/org/apache/maven/plugins/invoker/InvokerSession.java
index 96dff59..4d60687 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InvokerSession.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerSession.java
@@ -165,9 +165,10 @@ class InvokerSession {
                 successfulJobs.add(buildJob);
             } else if (BuildJob.Result.SKIPPED.equals(buildJob.getResult())) {
                 skippedJobs.add(buildJob);
-            } else if (BuildJob.Result.ERROR.equals(buildJob.getResult())) {
+            } else if (buildJob.getResult() == null || 
BuildJob.Result.ERROR.equals(buildJob.getResult())) {
+                // a job without a result did not finish, it must not vanish 
from the summary
                 errorJobs.add(buildJob);
-            } else if (buildJob.getResult() != null) {
+            } else {
                 failedJobs.add(buildJob);
             }
         }
diff --git a/src/test/java/org/apache/maven/plugins/invoker/ErroredJobTest.java 
b/src/test/java/org/apache/maven/plugins/invoker/ErroredJobTest.java
new file mode 100644
index 0000000..7ecbc12
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/invoker/ErroredJobTest.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.invoker;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Properties;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.invoker.model.BuildJob;
+import org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Reader;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.shared.invoker.Invoker;
+import org.apache.maven.shared.scriptinterpreter.ScriptRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static 
org.apache.maven.plugins.invoker.TestUtil.setVariableValueToObject;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests how a job is reported when it ends with something else than a build 
failure.
+ */
+class ErroredJobTest {
+
+    @TempDir
+    Path tempDir;
+
+    private Invoker invoker;
+
+    private Log log;
+
+    private InvokerMojo mojo;
+
+    private File reportsDirectory;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        invoker = mock(Invoker.class);
+        MavenProject mavenProject = new MavenProject();
+        mavenProject.setFile(tempDir.resolve("pom.xml").toFile());
+        mojo = new InvokerMojo(invoker, null, null, new 
InterpolatorUtils(mavenProject));
+
+        Path projects = Files.createDirectories(tempDir.resolve("src/it"));
+        Files.createDirectories(projects.resolve("job"));
+        Files.write(projects.resolve("job/pom.xml"), "<project/>".getBytes());
+        reportsDirectory = 
Files.createDirectories(tempDir.resolve("reports")).toFile();
+
+        setVariableValueToObject(mojo, "projectsDirectory", projects.toFile());
+        setVariableValueToObject(mojo, "reportsDirectory", reportsDirectory);
+        setVariableValueToObject(mojo, "invokerPropertiesFile", 
"invoker.properties");
+        setVariableValueToObject(mojo, "project", mavenProject);
+        setVariableValueToObject(mojo, "settings", new Settings());
+        setVariableValueToObject(mojo, "filteredPomPrefix", "");
+        setVariableValueToObject(mojo, "noLog", true);
+        setVariableValueToObject(mojo, "suppressSummaries", true);
+        setVariableValueToObject(mojo, "scriptRunner", new ScriptRunner());
+        setVariableValueToObject(mojo, "actualMavenVersion", "3.9.0");
+        log = mock(Log.class);
+        mojo.setLog(log);
+    }
+
+    private BuildJob readReport() throws Exception {
+        File report = new File(reportsDirectory, "BUILD-job.xml");
+        assertThat(report).isFile();
+        return new 
BuildJobXpp3Reader().read(Files.newBufferedReader(report.toPath()));
+    }
+
+    @Test
+    void runtimeExceptionIsWrittenToTheReportAsError() throws Exception {
+        when(invoker.execute(any())).thenThrow(new 
IllegalStateException("boom"));
+        BuildJob job = new BuildJob("job");
+
+        assertThatThrownBy(() ->
+                        mojo.runBuild(tempDir.resolve("src/it").toFile(), job, 
null, null, "21", new Properties()))
+                .isInstanceOf(IllegalStateException.class);
+
+        BuildJob reported = readReport();
+        assertThat(reported.getResult()).isEqualTo(BuildJob.Result.ERROR);
+        
assertThat(reported.getFailureMessage()).contains("IllegalStateException", 
"boom");
+        verify(log).error((CharSequence) contains("IllegalStateException: 
boom"));
+    }
+
+    @Test
+    void jobThatCannotBeSetUpIsWrittenToTheReportAsError() throws Exception {
+        // a malformed unicode escape, so reading the invoker properties fails 
before the build starts
+        Files.write(tempDir.resolve("src/it/job/invoker.properties"), 
"invoker.name = \\uZZZZ\n".getBytes());
+        BuildJob job = new BuildJob("job");
+
+        assertThatThrownBy(() ->
+                        mojo.runBuild(tempDir.resolve("src/it").toFile(), job, 
null, null, "21", new Properties()))
+                .isInstanceOf(IllegalArgumentException.class);
+
+        assertThat(readReport().getResult()).isEqualTo(BuildJob.Result.ERROR);
+    }
+
+    @Test
+    void scriptUserPropertiesArePassedAsStrings() {
+        Properties scriptProperties = new Properties();
+        scriptProperties.put("text", "plain");
+        scriptProperties.put("number", 42);
+        scriptProperties.put("charSequence", new StringBuilder("builder"));
+        Properties userProperties = new Properties();
+        userProperties.setProperty("existing", "kept");
+
+        AbstractInvokerMojo.addScriptUserProperties(userProperties, 
scriptProperties);
+
+        assertThat(userProperties.get("text")).isEqualTo("plain");
+        assertThat(userProperties.get("number")).isEqualTo("42");
+        assertThat(userProperties.get("charSequence")).isEqualTo("builder");
+        assertThat(userProperties.get("existing")).isEqualTo("kept");
+    }
+}
diff --git 
a/src/test/java/org/apache/maven/plugins/invoker/InvokerSessionTest.java 
b/src/test/java/org/apache/maven/plugins/invoker/InvokerSessionTest.java
index 9220735..faff55e 100644
--- a/src/test/java/org/apache/maven/plugins/invoker/InvokerSessionTest.java
+++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerSessionTest.java
@@ -24,6 +24,7 @@ import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.plugins.invoker.model.BuildJob;
 import org.junit.jupiter.api.Test;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -47,4 +48,20 @@ class InvokerSessionTest {
         verify(logger).warn("*  minvoker-279");
         verify(logger, never()).error(anyString());
     }
+
+    @Test
+    void jobWithoutResultCountsAsError() {
+        Log logger = mock(Log.class);
+        BuildJob unfinishedBuildJob = new BuildJob("minvoker-no-result");
+        InvokerSession session = new 
InvokerSession(Collections.singletonList(unfinishedBuildJob));
+
+        assertThat(session.getErrorJobs()).containsExactly(unfinishedBuildJob);
+        assertThat(session.getFailedJobs()).isEmpty();
+        assertThat(session.getSuccessfulJobs()).isEmpty();
+
+        session.logSummary(logger, false);
+
+        verify(logger).info("  Passed: 0, Failed: 0, Errors: 1, Skipped: 0");
+        verify(logger).error("*  minvoker-no-result");
+    }
 }

Reply via email to