You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/06/11 14:23:05 UTC

[maven-invoker-plugin] 01/01: [MINVOKER-342] Use ChoiceFormat to selectively render elapsed time in AbstractInvokerMojo

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

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

commit 3dff59f19ab1b810a4a300a7f06ee8d90b605782
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Jun 11 13:49:58 2023 +0200

    [MINVOKER-342] Use ChoiceFormat to selectively render elapsed time in AbstractInvokerMojo
    
    This closes #192
---
 .../maven/plugins/invoker/AbstractInvokerMojo.java | 28 ++++++++++++----------
 1 file changed, 16 insertions(+), 12 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 bb51e1b..2632020 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -31,8 +31,7 @@ import java.io.Writer;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -704,11 +703,6 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
      */
     private String filteredPomPrefix = "interpolated-";
 
-    /**
-     * The format for elapsed build time.
-     */
-    private final DecimalFormat secFormat = new DecimalFormat("(0.0 s)", new DecimalFormatSymbols(Locale.ENGLISH));
-
     /**
      * The version of Maven which is used to run the builds
      */
@@ -1560,13 +1554,15 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
                     buildJob.setResult(BuildJob.Result.SUCCESS);
 
                     if (!suppressSummaries) {
-                        getLog().info(pad(buildJob).success("SUCCESS").a(' ') + formatTime(buildJob.getTime()));
+                        getLog().info(pad(buildJob).success("SUCCESS").a(' ') + "("
+                                + formatElapsedTime(buildJob.getTime()) + ")");
                     }
                 } else {
                     buildJob.setResult(BuildJob.Result.SKIPPED);
 
                     if (!suppressSummaries) {
-                        getLog().info(pad(buildJob).warning("SKIPPED").a(' ') + formatTime(buildJob.getTime()));
+                        getLog().info(pad(buildJob).warning("SKIPPED").a(' ') + "("
+                                + formatElapsedTime(buildJob.getTime()) + ")");
                     }
                 }
             } else {
@@ -1606,7 +1602,8 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
 
             if (!suppressSummaries) {
                 getLog().info("  " + e.getMessage());
-                getLog().info(pad(buildJob).failure("FAILED").a(' ') + formatTime(buildJob.getTime()));
+                getLog().info(pad(buildJob).failure("FAILED").a(' ') + "(" + formatElapsedTime(buildJob.getTime())
+                        + ")");
             }
         } finally {
             deleteInterpolatedPomFile(interpolatedPomFile);
@@ -1762,8 +1759,15 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
      * @param time The eapsed time of the build.
      * @return The formatted time, never <code>null</code>.
      */
-    private String formatTime(float time) {
-        return secFormat.format(time);
+    private String formatElapsedTime(float time) {
+        /*
+         * Rationale: The idea is to always display four digits for visually consistent output
+         * Important: Keep in sync with src/main/resources/invoker-report.properties
+         */
+        final MessageFormat elapsedTimeFormat = new MessageFormat(
+                "{0,choice,0#0|0.0<{0,number,0.000}|10#{0,number,0.00}|100#{0,number,0.0}|1000#{0,number,0}} s",
+                Locale.ROOT);
+        return elapsedTimeFormat.format(new Object[] {time});
     }
 
     /**