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-ffa450edef68master
| @@ -74,6 +74,8 @@ import org.apache.tools.ant.types.Commandline; | |||||
| import org.apache.tools.ant.types.CommandlineJava; | import org.apache.tools.ant.types.CommandlineJava; | ||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.apache.tools.ant.util.FileUtils; | 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. | * The core JUnit task. | ||||
| @@ -82,6 +84,9 @@ import org.apache.tools.ant.util.FileUtils; | |||||
| */ | */ | ||||
| public class JUnitTask extends Task { | public class JUnitTask extends Task { | ||||
| private final static Resources RES = | |||||
| ResourceManager.getPackageResources( JUnitTask.class ); | |||||
| /** port to run the server on */ | /** port to run the server on */ | ||||
| private int port = -1; | private int port = -1; | ||||
| @@ -111,12 +116,13 @@ public class JUnitTask extends Task { | |||||
| execute.setCommandline(cmd.getCommandline()); | execute.setCommandline(cmd.getCommandline()); | ||||
| execute.setAntRun(project); | execute.setAntRun(project); | ||||
| log("Executing: " + cmd.toString(), Project.MSG_VERBOSE); | |||||
| log(RES.getString("task.process-cmdline.log", cmd.toString()), Project.MSG_VERBOSE); | |||||
| int retVal; | int retVal; | ||||
| try { | try { | ||||
| retVal = execute.execute(); | retVal = execute.execute(); | ||||
| } catch (IOException e) { | } 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 { | } finally { | ||||
| tmp.delete(); | tmp.delete(); | ||||
| } | } | ||||
| @@ -0,0 +1,3 @@ | |||||
| # task | |||||
| task.process-cmdline.log = Executing {0} | |||||
| task.process-failed.error = Process failed. | |||||
| @@ -55,6 +55,8 @@ package org.apache.tools.ant.taskdefs.optional.junit.formatter; | |||||
| import java.io.PrintWriter; | 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> | * Display additional messages from a <tt>SummaryFormatter</tt> | ||||
| @@ -64,19 +66,17 @@ import java.io.PrintWriter; | |||||
| */ | */ | ||||
| public class BriefFormatter extends SummaryFormatter { | public class BriefFormatter extends SummaryFormatter { | ||||
| private final static Resources RES = | |||||
| ResourceManager.getPackageResources( BriefFormatter.class ); | |||||
| public void onTestFailed(int status, String testname, String trace) { | 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) { | 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); | super.onTestFailed(status, testname, trace); | ||||
| } | } | ||||
| @@ -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 | |||||
| @@ -56,6 +56,9 @@ package org.apache.tools.ant.taskdefs.optional.junit.formatter; | |||||
| import java.io.PrintWriter; | import java.io.PrintWriter; | ||||
| import java.text.MessageFormat; | 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 | * Display a summary message at the end of a testsuite stating | ||||
| * runs, failures, errors, and elapsed time. | * runs, failures, errors, and elapsed time. | ||||
| @@ -64,25 +67,16 @@ import java.text.MessageFormat; | |||||
| */ | */ | ||||
| public class SummaryFormatter extends BaseFormatter { | 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) { | 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(); | close(); | ||||
| } | } | ||||
| @@ -62,6 +62,9 @@ import org.w3c.dom.Element; | |||||
| import org.w3c.dom.Text; | 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> | * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | ||||
| */ | */ | ||||