Skip to content

Commit 3dff59f

Browse files
committedJun 11, 2023
[MINVOKER-342] Use ChoiceFormat to selectively render elapsed time in AbstractInvokerMojo
This closes #192
1 parent 26f2dcf commit 3dff59f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed
 

‎src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java

+16-12
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
import java.nio.file.Files;
3232
import java.nio.file.Path;
3333
import java.nio.file.Paths;
34-
import java.text.DecimalFormat;
35-
import java.text.DecimalFormatSymbols;
34+
import java.text.MessageFormat;
3635
import java.util.ArrayList;
3736
import java.util.Arrays;
3837
import java.util.Collection;
@@ -704,11 +703,6 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
704703
*/
705704
private String filteredPomPrefix = "interpolated-";
706705

707-
/**
708-
* The format for elapsed build time.
709-
*/
710-
private final DecimalFormat secFormat = new DecimalFormat("(0.0 s)", new DecimalFormatSymbols(Locale.ENGLISH));
711-
712706
/**
713707
* The version of Maven which is used to run the builds
714708
*/
@@ -1560,13 +1554,15 @@ private void runBuild(
15601554
buildJob.setResult(BuildJob.Result.SUCCESS);
15611555

15621556
if (!suppressSummaries) {
1563-
getLog().info(pad(buildJob).success("SUCCESS").a(' ') + formatTime(buildJob.getTime()));
1557+
getLog().info(pad(buildJob).success("SUCCESS").a(' ') + "("
1558+
+ formatElapsedTime(buildJob.getTime()) + ")");
15641559
}
15651560
} else {
15661561
buildJob.setResult(BuildJob.Result.SKIPPED);
15671562

15681563
if (!suppressSummaries) {
1569-
getLog().info(pad(buildJob).warning("SKIPPED").a(' ') + formatTime(buildJob.getTime()));
1564+
getLog().info(pad(buildJob).warning("SKIPPED").a(' ') + "("
1565+
+ formatElapsedTime(buildJob.getTime()) + ")");
15701566
}
15711567
}
15721568
} else {
@@ -1606,7 +1602,8 @@ private void runBuild(
16061602

16071603
if (!suppressSummaries) {
16081604
getLog().info(" " + e.getMessage());
1609-
getLog().info(pad(buildJob).failure("FAILED").a(' ') + formatTime(buildJob.getTime()));
1605+
getLog().info(pad(buildJob).failure("FAILED").a(' ') + "(" + formatElapsedTime(buildJob.getTime())
1606+
+ ")");
16101607
}
16111608
} finally {
16121609
deleteInterpolatedPomFile(interpolatedPomFile);
@@ -1762,8 +1759,15 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj
17621759
* @param time The eapsed time of the build.
17631760
* @return The formatted time, never <code>null</code>.
17641761
*/
1765-
private String formatTime(float time) {
1766-
return secFormat.format(time);
1762+
private String formatElapsedTime(float time) {
1763+
/*
1764+
* Rationale: The idea is to always display four digits for visually consistent output
1765+
* Important: Keep in sync with src/main/resources/invoker-report.properties
1766+
*/
1767+
final MessageFormat elapsedTimeFormat = new MessageFormat(
1768+
"{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",
1769+
Locale.ROOT);
1770+
return elapsedTimeFormat.format(new Object[] {time});
17671771
}
17681772

17691773
/**

0 commit comments

Comments
 (0)