You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by um...@apache.org on 2002/02/01 00:56:26 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant DefaultLogger.java
umagesh 02/01/31 15:56:26
Modified: src/main/org/apache/tools/ant DefaultLogger.java
Log:
Qualify total time spent on build with proper English.
PR: 5901
Revision Changes Path
1.31 +30 -15 jakarta-ant/src/main/org/apache/tools/ant/DefaultLogger.java
Index: DefaultLogger.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/DefaultLogger.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- DefaultLogger.java 31 Jan 2002 20:24:49 -0000 1.30
+++ DefaultLogger.java 31 Jan 2002 23:56:26 -0000 1.31
@@ -55,8 +55,8 @@
package org.apache.tools.ant;
import java.io.PrintStream;
-
-
+import java.text.ChoiceFormat;
+import java.text.MessageFormat;
import org.apache.tools.ant.util.StringUtils;
@@ -66,6 +66,28 @@
* any messages that get logged.
*/
public class DefaultLogger implements BuildLogger {
+ private final static MessageFormat MINUTE_SECONDS =
+ new MessageFormat("Total time: {0}{1}.");
+
+ private final static double[] LIMITS = {0, 1, 2};
+
+ private final static String[] MINUTES_PART =
+ {"", "1 minute, ", "{0,number} minutes, "};
+
+ private final static String[] SECONDS_PART =
+ {"no seconds", "1 second", "{1,number} seconds"};
+
+ private final static ChoiceFormat MINUTES_FORMAT =
+ new ChoiceFormat(LIMITS, MINUTES_PART);
+
+ private final static ChoiceFormat SECONDS_FORMAT =
+ new ChoiceFormat(LIMITS, SECONDS_PART);
+
+ static {
+ MINUTE_SECONDS.setFormat(0, MINUTES_FORMAT);
+ MINUTE_SECONDS.setFormat(1, SECONDS_FORMAT);
+ }
+
private static int LEFT_COLUMN_SIZE = 12;
protected PrintStream out;
@@ -159,8 +181,7 @@
}
}
message.append(StringUtils.LINE_SEP);
- message.append("Total time: "
- + formatTime(System.currentTimeMillis() - startTime));
+ message.append(formatTime(System.currentTimeMillis() - startTime));
String msg = message.toString();
if (error == null) {
@@ -219,18 +240,12 @@
long seconds = millis / 1000;
long minutes = seconds / 60;
+ Object[] args = {
+ new Long(minutes),
+ new Long(seconds % 60)
+ };
- if (minutes > 0) {
- return Long.toString(minutes) + " minute"
- + (minutes == 1 ? " " : "s ")
- + Long.toString(seconds%60) + " second"
- + (seconds%60 > 1 ? "s" : "");
- }
- else {
- return Long.toString(seconds) + " second"
- + (seconds%60 > 1 ? "s" : "");
- }
-
+ return MINUTE_SECONDS.format(args);
}
protected void printMessage(final String message,
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>