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 15:50:28 UTC
[maven-invoker-plugin] 02/02: [MINVOKER-345] Use ChoiceFormat to selectively render percentage and elapsed time in InvokerReportRenderer
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch MINVOKER-345
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
commit 411b66abf4879ae6608690b8f973ff28229e9587
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Jun 11 17:49:55 2023 +0200
[MINVOKER-345] Use ChoiceFormat to selectively render percentage and elapsed time in InvokerReportRenderer
This closes #194
---
.../plugins/invoker/InvokerReportRenderer.java | 36 +++-------------------
src/main/resources/invoker-report.properties | 10 ++++--
src/main/resources/invoker-report_de.properties | 2 +-
src/main/resources/invoker-report_fr.properties | 4 +--
4 files changed, 14 insertions(+), 38 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerReportRenderer.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerReportRenderer.java
index eae9739..3958a0a 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InvokerReportRenderer.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerReportRenderer.java
@@ -18,10 +18,6 @@
*/
package org.apache.maven.plugins.invoker;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.MessageFormat;
-import java.text.NumberFormat;
import java.util.List;
import java.util.Locale;
@@ -37,21 +33,6 @@ public class InvokerReportRenderer extends AbstractMavenReportRenderer {
private final Log log;
private final List<BuildJob> buildJobs;
- /**
- * The number format used to print percent values in the report locale.
- */
- private NumberFormat percentFormat;
-
- /**
- * The number format used to print time values in the report locale.
- */
- private NumberFormat secondsFormat;
-
- /**
- * The format used to print build name and description.
- */
- private MessageFormat nameAndDescriptionFormat;
-
public InvokerReportRenderer(Sink sink, I18N i18n, Locale locale, Log log, List<BuildJob> buildJobs) {
super(sink);
this.i18n = i18n;
@@ -84,11 +65,6 @@ public class InvokerReportRenderer extends AbstractMavenReportRenderer {
@Override
protected void renderBody() {
- DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
- percentFormat = new DecimalFormat(getI18nString("format.percent"), symbols);
- secondsFormat = new DecimalFormat(getI18nString("format.seconds"), symbols);
- nameAndDescriptionFormat = new MessageFormat(getI18nString("format.name_with_description"));
-
startSection(getTitle());
paragraph(getI18nString("description"));
@@ -139,9 +115,9 @@ public class InvokerReportRenderer extends AbstractMavenReportRenderer {
Integer.toString(totalFailures),
Integer.toString(totalSkipped),
(totalSuccess + totalFailures > 0)
- ? percentFormat.format(totalSuccess / (float) (totalSuccess + totalFailures))
+ ? formatI18nString("value.successrate", (totalSuccess / (float) (totalSuccess + totalFailures)))
: "",
- secondsFormat.format(totalTime)
+ formatI18nString("value.time", totalTime)
});
endTable();
@@ -175,7 +151,7 @@ public class InvokerReportRenderer extends AbstractMavenReportRenderer {
getBuildJobReportName(buildJob),
// FIXME image
buildJob.getResult(),
- secondsFormat.format(buildJob.getTime()),
+ formatI18nString("value.time", buildJob.getTime()),
buildJob.getFailureMessage()
});
}
@@ -187,7 +163,7 @@ public class InvokerReportRenderer extends AbstractMavenReportRenderer {
boolean emptyJobDescription = buildJobDescription == null || buildJobDescription.isEmpty();
boolean isReportJobNameComplete = !emptyJobName && !emptyJobDescription;
if (isReportJobNameComplete) {
- return getFormattedName(buildJobName, buildJobDescription);
+ return formatI18nString("text.name_with_description", buildJobName, buildJobDescription);
} else {
String buildJobProject = buildJob.getProject();
if (!emptyJobName) {
@@ -203,8 +179,4 @@ public class InvokerReportRenderer extends AbstractMavenReportRenderer {
return "Incomplete job name-description: " + missing + " is missing. POM (" + pom
+ ") will be used in place of job name!";
}
-
- private String getFormattedName(String name, String description) {
- return nameAndDescriptionFormat.format(new Object[] {name, description});
- }
}
diff --git a/src/main/resources/invoker-report.properties b/src/main/resources/invoker-report.properties
index e746c3e..9753d83 100644
--- a/src/main/resources/invoker-report.properties
+++ b/src/main/resources/invoker-report.properties
@@ -30,6 +30,10 @@ report.invoker.detail.name=Name
report.invoker.detail.result=Result
report.invoker.detail.time=Time
report.invoker.detail.message=Message
-report.invoker.format.percent=0.0%
-report.invoker.format.seconds=0.0\u00A0s
-report.invoker.format.name_with_description={0}: {1}
+report.invoker.value.successrate={0,choice,0#0%|0.0<{0,number,0.0%}|1#{0,number,0%}}
+# Rationale: The idea is to always display four digits for visually consistent output
+# Important:
+# * Keep in sync with org.apache.maven.plugins.invoker.AbstractInvokerMojo
+# * Needs to be copied into other bundles only if non-Latin script is used
+report.invoker.value.time={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
+report.invoker.text.name_with_description={0}: {1}
diff --git a/src/main/resources/invoker-report_de.properties b/src/main/resources/invoker-report_de.properties
index 41e030b..ed617c3 100644
--- a/src/main/resources/invoker-report_de.properties
+++ b/src/main/resources/invoker-report_de.properties
@@ -29,4 +29,4 @@ report.invoker.detail.name=Name
report.invoker.detail.result=Ergebnis
report.invoker.detail.time=Zeit
report.invoker.detail.message=Meldung
-report.invoker.format.percent=0.0\u00A0%
+report.invoker.value.successrate={0,choice,0#0 %|0.0<{0,number,0.0 %}|1#{0,number,0 %}}
diff --git a/src/main/resources/invoker-report_fr.properties b/src/main/resources/invoker-report_fr.properties
index 7da545a..75b5275 100644
--- a/src/main/resources/invoker-report_fr.properties
+++ b/src/main/resources/invoker-report_fr.properties
@@ -29,5 +29,5 @@ report.invoker.detail.name=Nom
report.invoker.detail.result=R�sultat
report.invoker.detail.time=Dur�e
report.invoker.detail.message=Message
-report.invoker.format.percent=0.0\u00A0%
-report.invoker.format.name_with_description={0} : {1}
+report.invoker.value.successrate={0,choice,0#0 %|0.0<{0,number,0.0 %}|1#{0,number,0 %}}
+report.invoker.text.name_with_description={0} : {1}