Skip to content

Commit 3df7c38

Browse files
committed
[MINVOKER-345] Use ChoiceFormat to selectively render percentage and elapsed time in InvokerReportRenderer
This closes #194
1 parent a154e5b commit 3df7c38

File tree

4 files changed

+14
-38
lines changed

4 files changed

+14
-38
lines changed

src/main/java/org/apache/maven/plugins/invoker/InvokerReportRenderer.java

+4-32
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
*/
1919
package org.apache.maven.plugins.invoker;
2020

21-
import java.text.DecimalFormat;
22-
import java.text.DecimalFormatSymbols;
23-
import java.text.MessageFormat;
24-
import java.text.NumberFormat;
2521
import java.util.List;
2622
import java.util.Locale;
2723

@@ -37,21 +33,6 @@ public class InvokerReportRenderer extends AbstractMavenReportRenderer {
3733
private final Log log;
3834
private final List<BuildJob> buildJobs;
3935

40-
/**
41-
* The number format used to print percent values in the report locale.
42-
*/
43-
private NumberFormat percentFormat;
44-
45-
/**
46-
* The number format used to print time values in the report locale.
47-
*/
48-
private NumberFormat secondsFormat;
49-
50-
/**
51-
* The format used to print build name and description.
52-
*/
53-
private MessageFormat nameAndDescriptionFormat;
54-
5536
public InvokerReportRenderer(Sink sink, I18N i18n, Locale locale, Log log, List<BuildJob> buildJobs) {
5637
super(sink);
5738
this.i18n = i18n;
@@ -84,11 +65,6 @@ private String formatI18nString(String key, Object... args) {
8465

8566
@Override
8667
protected void renderBody() {
87-
DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
88-
percentFormat = new DecimalFormat(getI18nString("format.percent"), symbols);
89-
secondsFormat = new DecimalFormat(getI18nString("format.seconds"), symbols);
90-
nameAndDescriptionFormat = new MessageFormat(getI18nString("format.name_with_description"));
91-
9268
startSection(getTitle());
9369
paragraph(getI18nString("description"));
9470

@@ -139,9 +115,9 @@ private void renderSectionSummary() {
139115
Integer.toString(totalFailures),
140116
Integer.toString(totalSkipped),
141117
(totalSuccess + totalFailures > 0)
142-
? percentFormat.format(totalSuccess / (float) (totalSuccess + totalFailures))
118+
? formatI18nString("value.successrate", (totalSuccess / (float) (totalSuccess + totalFailures)))
143119
: "",
144-
secondsFormat.format(totalTime)
120+
formatI18nString("value.time", totalTime)
145121
});
146122

147123
endTable();
@@ -175,7 +151,7 @@ private void renderBuildJob(BuildJob buildJob) {
175151
getBuildJobReportName(buildJob),
176152
// FIXME image
177153
buildJob.getResult(),
178-
secondsFormat.format(buildJob.getTime()),
154+
formatI18nString("value.time", buildJob.getTime()),
179155
buildJob.getFailureMessage()
180156
});
181157
}
@@ -187,7 +163,7 @@ private String getBuildJobReportName(BuildJob buildJob) {
187163
boolean emptyJobDescription = buildJobDescription == null || buildJobDescription.isEmpty();
188164
boolean isReportJobNameComplete = !emptyJobName && !emptyJobDescription;
189165
if (isReportJobNameComplete) {
190-
return getFormattedName(buildJobName, buildJobDescription);
166+
return formatI18nString("text.name_with_description", buildJobName, buildJobDescription);
191167
} else {
192168
String buildJobProject = buildJob.getProject();
193169
if (!emptyJobName) {
@@ -203,8 +179,4 @@ private static String incompleteNameWarning(String missing, String pom) {
203179
return "Incomplete job name-description: " + missing + " is missing. POM (" + pom
204180
+ ") will be used in place of job name!";
205181
}
206-
207-
private String getFormattedName(String name, String description) {
208-
return nameAndDescriptionFormat.format(new Object[] {name, description});
209-
}
210182
}

src/main/resources/invoker-report.properties

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ report.invoker.detail.name=Name
3030
report.invoker.detail.result=Result
3131
report.invoker.detail.time=Time
3232
report.invoker.detail.message=Message
33-
report.invoker.format.percent=0.0%
34-
report.invoker.format.seconds=0.0\u00A0s
35-
report.invoker.format.name_with_description={0}: {1}
33+
report.invoker.value.successrate={0,choice,0#0%|0.0<{0,number,0.0%}|1#{0,number,0%}}
34+
# Rationale: The idea is to always display four digits for visually consistent output
35+
# Important:
36+
# * Keep in sync with org.apache.maven.plugins.invoker.AbstractInvokerMojo
37+
# * Needs to be copied into other bundles only if non-Latin script is used
38+
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
39+
report.invoker.text.name_with_description={0}: {1}

src/main/resources/invoker-report_de.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ report.invoker.detail.name=Name
2929
report.invoker.detail.result=Ergebnis
3030
report.invoker.detail.time=Zeit
3131
report.invoker.detail.message=Meldung
32-
report.invoker.format.percent=0.0\u00A0%
32+
report.invoker.value.successrate={0,choice,0#0 %|0.0<{0,number,0.0 %}|1#{0,number,0 %}}

src/main/resources/invoker-report_fr.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ report.invoker.detail.name=Nom
2929
report.invoker.detail.result=Résultat
3030
report.invoker.detail.time=Durée
3131
report.invoker.detail.message=Message
32-
report.invoker.format.percent=0.0\u00A0%
33-
report.invoker.format.name_with_description={0} : {1}
32+
report.invoker.value.successrate={0,choice,0#0 %|0.0<{0,number,0.0 %}|1#{0,number,0 %}}
33+
report.invoker.text.name_with_description={0} : {1}

0 commit comments

Comments
 (0)