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

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

commit 449faa6b0f1c4a3f9a268745a522acfdeba2d125
Author: Michael Osipov <[email protected]>
AuthorDate: Sun Jun 11 13:23:20 2023 +0200

    [MINVOKER-341] Make elapsed time field type consistent with Maven Surefire
---
 .../maven/plugins/invoker/AbstractInvokerMojo.java | 24 ++++++++++++----------
 src/main/mdo/invocation.mdo                        |  4 ++--
 2 files changed, 15 insertions(+), 13 deletions(-)

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 b297a2c..bb51e1b 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -111,6 +111,8 @@ import static 
org.apache.maven.shared.utils.logging.MessageUtils.buffer;
  * @since 15-Aug-2009 09:09:29
  */
 public abstract class AbstractInvokerMojo extends AbstractMojo {
+    private static final float ONE_SECOND = 1000.0f;
+
     /**
      * The zero-based column index where to print the invoker result.
      */
@@ -1534,7 +1536,7 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
         try {
             int selection = getSelection(invokerProperties, actualJreVersion);
             if (selection == 0) {
-                long milliseconds = System.currentTimeMillis();
+                long startTime = System.currentTimeMillis();
                 boolean executed;
 
                 FileLogger buildLogger = setupBuildLogFile(basedir);
@@ -1546,8 +1548,8 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
                     executed = runBuild(
                             basedir, interpolatedPomFile, settingsFile, 
actualJavaHome, invokerProperties, buildLogger);
                 } finally {
-                    milliseconds = System.currentTimeMillis() - milliseconds;
-                    buildJob.setTime(milliseconds / 1000.0);
+                    long elapsedTime = System.currentTimeMillis() - startTime;
+                    buildJob.setTime(elapsedTime / ONE_SECOND);
 
                     if (buildLogger != null) {
                         buildLogger.close();
@@ -1697,7 +1699,7 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
         File reportFile = new File(reportsDirectory, "TEST-" + safeFileName + 
".xml");
         Xpp3Dom testsuite = new Xpp3Dom("testsuite");
         testsuite.setAttribute("name", junitPackageName + "." + safeFileName);
-        testsuite.setAttribute("time", Double.toString(buildJob.getTime()));
+        testsuite.setAttribute("time", Float.toString(buildJob.getTime()));
 
         // set default value for required attributes
         testsuite.setAttribute("tests", "1");
@@ -1729,7 +1731,7 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
         }
         testcase.setAttribute("classname", junitPackageName + "." + 
safeFileName);
         testcase.setAttribute("name", safeFileName);
-        testcase.setAttribute("time", Double.toString(buildJob.getTime()));
+        testcase.setAttribute("time", Float.toString(buildJob.getTime()));
         Xpp3Dom systemOut = new Xpp3Dom("system-out");
         testcase.addChild(systemOut);
 
@@ -1755,13 +1757,13 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
     }
 
     /**
-     * Formats the specified build duration time.
+     * Formats the specified elapsed time.
      *
-     * @param seconds The duration of the build.
+     * @param time The eapsed time of the build.
      * @return The formatted time, never <code>null</code>.
      */
-    private String formatTime(double seconds) {
-        return secFormat.format(seconds);
+    private String formatTime(float time) {
+        return secFormat.format(time);
     }
 
     /**
@@ -1882,8 +1884,8 @@ public abstract class AbstractInvokerMojo extends 
AbstractMojo {
 
     int getParallelThreadsCount() {
         if (parallelThreads.endsWith("C")) {
-            double parallelThreadsMultiple =
-                    Double.parseDouble(parallelThreads.substring(0, 
parallelThreads.length() - 1));
+            float parallelThreadsMultiple =
+                    Float.parseFloat(parallelThreads.substring(0, 
parallelThreads.length() - 1));
             return (int) (parallelThreadsMultiple * 
Runtime.getRuntime().availableProcessors());
         } else {
             return Integer.parseInt(parallelThreads);
diff --git a/src/main/mdo/invocation.mdo b/src/main/mdo/invocation.mdo
index 6529e7c..f4af425 100644
--- a/src/main/mdo/invocation.mdo
+++ b/src/main/mdo/invocation.mdo
@@ -86,7 +86,7 @@ under the License.
           <name>time</name>
           <version>1.0.0</version>
           <required>true</required>
-          <type>double</type>
+          <type>float</type>
           <description>The number of seconds that this build job took to 
complete.</description>
         </field>
         <field xml.attribute="true">
@@ -126,7 +126,7 @@ under the License.
 
     /**
      * Creates a new build job with the specified project path.
-     * 
+     *
      * @param project The path to the project.
      */
     public BuildJob( String project )

Reply via email to