Browse Source

- Introducing i18 resources management. I'm using

the i18n package from Excalibur there is no point
in reinventing the wheel.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270750 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 23 years ago
parent
commit
e8768da3a9
6 changed files with 42 additions and 29 deletions
  1. +8
    -2
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  2. +3
    -0
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/Resources.properties
  3. +10
    -10
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BriefFormatter.java
  4. +7
    -0
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/Resources.properties
  5. +11
    -17
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/SummaryFormatter.java
  6. +3
    -0
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/XMLFormatter.java

+ 8
- 2
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -74,6 +74,8 @@ import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.FileUtils;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;

/**
* The core JUnit task.
@@ -82,6 +84,9 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class JUnitTask extends Task {

private final static Resources RES =
ResourceManager.getPackageResources( JUnitTask.class );

/** port to run the server on */
private int port = -1;

@@ -111,12 +116,13 @@ public class JUnitTask extends Task {
execute.setCommandline(cmd.getCommandline());
execute.setAntRun(project);

log("Executing: " + cmd.toString(), Project.MSG_VERBOSE);
log(RES.getString("task.process-cmdline.log", cmd.toString()), Project.MSG_VERBOSE);
int retVal;
try {
retVal = execute.execute();
} catch (IOException e) {
throw new BuildException("Process fork failed.", e, location);
String msg = RES.getString("task.process-failed.error");
throw new BuildException(msg, e, location);
} finally {
tmp.delete();
}


+ 3
- 0
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/Resources.properties View File

@@ -0,0 +1,3 @@
# task
task.process-cmdline.log = Executing {0}
task.process-failed.error = Process failed.

+ 10
- 10
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BriefFormatter.java View File

@@ -55,6 +55,8 @@ package org.apache.tools.ant.taskdefs.optional.junit.formatter;

import java.io.PrintWriter;

import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.i18n.ResourceManager;

/**
* Display additional messages from a <tt>SummaryFormatter</tt>
@@ -64,19 +66,17 @@ import java.io.PrintWriter;
*/
public class BriefFormatter extends SummaryFormatter {

private final static Resources RES =
ResourceManager.getPackageResources( BriefFormatter.class );

public void onTestFailed(int status, String testname, String trace) {
PrintWriter writer = getWriter();
writer.print("TestCase: ");
writer.print(testname);
String msg = null;
if (status == STATUS_ERROR) {
writer.print("\tCaused an ERROR");
} else if (status == STATUS_FAILURE) {
writer.write("\tFAILED");
msg = RES.getString("brief.status-error.msg", testname, trace);
} else {
msg = RES.getString("brief.status-failure.msg", testname, trace);
}
writer.println();
writer.print(trace);
writer.println();
writer.println();
getWriter().println(msg);
super.onTestFailed(status, testname, trace);
}



+ 7
- 0
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/Resources.properties View File

@@ -0,0 +1,7 @@
# Summary formatter
summary.finished.msg = TestSuite: \nTests run: {0, number, integer}, Failures: {1, number, integer}, Errors: {2, number, integer}, Time elapsed: {3, number, integer} sec\n

# Brief formatter
brief.status-error.msg = TestCase: {0}\tCaused an ERROR\n{1}\n
brief.status-failure.msg = TestCase: {0}\tFAILED\n{1}\n


+ 11
- 17
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/SummaryFormatter.java View File

@@ -56,6 +56,9 @@ package org.apache.tools.ant.taskdefs.optional.junit.formatter;
import java.io.PrintWriter;
import java.text.MessageFormat;

import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.i18n.ResourceManager;

/**
* Display a summary message at the end of a testsuite stating
* runs, failures, errors, and elapsed time.
@@ -64,25 +67,16 @@ import java.text.MessageFormat;
*/
public class SummaryFormatter extends BaseFormatter {

protected final MessageFormat mf = new MessageFormat(
"Tests run: {0, number, integer}" +
", Failures: {1, number, integer}" +
", Errors: {2, number, integer}" +
", Time elapsed: {3, number, integer} sec");
private final static Resources RES =
ResourceManager.getPackageResources( SummaryFormatter.class );

protected void finished(long elapsedtime) {
PrintWriter writer = getWriter();
writer.print("Testsuite: ");
writer.println();
String line = mf.format(new Object[]{
new Integer(getRunCount()),
new Integer(getFailureCount()),
new Integer(getErrorCount()),
new Long(elapsedtime / 1000)
});
writer.print(line);
writer.println();
writer.println();
String msg = RES.getString("summary.finished.msg",
new Integer(getRunCount()),
new Integer(getFailureCount()),
new Integer(getErrorCount()),
new Long(elapsedtime / 1000) );
getWriter().println(msg);
close();
}



+ 3
- 0
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/XMLFormatter.java View File

@@ -62,6 +62,9 @@ import org.w3c.dom.Element;
import org.w3c.dom.Text;

/**
* XML Formatter. Due to the nature of the XML we are forced to store
* everything in memory until it is finished. It might be resource
* intensive when running lots of testcases.
*
* @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
*/


Loading…
Cancel
Save