Skip to content

Commit

Permalink
[MINVOKER-345] Use ChoiceFormat to selectively render percentage and …
Browse files Browse the repository at this point in the history
…elapsed time in InvokerReportRenderer

This closes #194
  • Loading branch information
michael-o committed Jun 11, 2023
1 parent a154e5b commit 3df7c38
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -84,11 +65,6 @@ private String formatI18nString(String key, Object... args) {

@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"));

Expand Down Expand Up @@ -139,9 +115,9 @@ private void renderSectionSummary() {
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();
Expand Down Expand Up @@ -175,7 +151,7 @@ private void renderBuildJob(BuildJob buildJob) {
getBuildJobReportName(buildJob),
// FIXME image
buildJob.getResult(),
secondsFormat.format(buildJob.getTime()),
formatI18nString("value.time", buildJob.getTime()),
buildJob.getFailureMessage()
});
}
Expand All @@ -187,7 +163,7 @@ private String getBuildJobReportName(BuildJob buildJob) {
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) {
Expand All @@ -203,8 +179,4 @@ private static String incompleteNameWarning(String missing, String pom) {
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});
}
}
10 changes: 7 additions & 3 deletions src/main/resources/invoker-report.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion src/main/resources/invoker-report_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}}
4 changes: 2 additions & 2 deletions src/main/resources/invoker-report_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 3df7c38

Please sign in to comment.