sbailliez 02/01/13 15:40:12
Modified:
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit
ClasspathTestCollector.java ZipScanner.java
JUnitTask.java FilterElement.java JUnitHelper.java
KeepAliveOutputStream.java TestElement.java
WatchdogTest.java
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter
SummaryFormatter.java BriefFormatter.java
XMLFormatter.java Formatter.java BaseFormatter.java
FilterFormatter.java FilterStackFormatter.java
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote
MessageReader.java MessageWriter.java
TestRunner.java Server.java
Added:
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote
SocketUtil.java
Log:
- Clean up
- Refactored some code and moved protected fields to private
Revision Changes Path
1.2 +30 -32
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/ClasspathTestCollector.java
Index: ClasspathTestCollector.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/ClasspathTestCollector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClasspathTestCollector.java 11 Jan 2002 23:35:43 -0000 1.1
+++ ClasspathTestCollector.java 13 Jan 2002 23:40:11 -0000 1.2
@@ -53,20 +53,18 @@
*/
package org.apache.tools.ant.taskdefs.optional.junit;
+import java.io.File;
import java.util.Enumeration;
-import java.util.Vector;
import java.util.Hashtable;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipEntry;
-import java.io.File;
+import java.util.Vector;
import junit.runner.TestCollector;
-import org.apache.tools.ant.types.PatternSet;
-import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectComponent;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.PatternSet;
/**
* A rough implementation of a test collector that will collect tests
@@ -78,7 +76,7 @@
public class ClasspathTestCollector extends ProjectComponent
implements TestCollector {
- private final static int SUFFIX_LENGTH= ".class".length();
+ private final static int SUFFIX_LENGTH = ".class".length();
private PatternSet patterns = new PatternSet();
@@ -90,21 +88,21 @@
// override last one in case there are duplicates.
// ie mimic classpath behavior.
String[] paths = path.list();
- for (int i = paths.length; i >= 0; i--){
+ for (int i = paths.length; i >= 0; i--) {
File f = new File(paths[i]);
Vector included = null;
- if ( f.isDirectory() ){
+ if (f.isDirectory()) {
included = gatherFromDirectory(f);
- } else if ( f.getName().endsWith(".zip")
- || f.getName().endsWith(".jar") ) {
+ } else if (f.getName().endsWith(".zip")
+ || f.getName().endsWith(".jar")) {
included = gatherFromArchive(f);
} else {
continue;
}
// add tests to the already collected one
final int includedCount = included.size();
- for (int j = 0; j < includedCount; j++){
- String testname = (String)included.elementAt(i);
+ for (int j = 0; j < includedCount; j++) {
+ String testname = (String) included.elementAt(i);
collected.put(testname, "");
}
}
@@ -112,7 +110,7 @@
}
- protected Vector gatherFromDirectory(File dir){
+ protected Vector gatherFromDirectory(File dir) {
Project project = getProject();
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(dir);
@@ -123,7 +121,7 @@
return testClassNameFromFile(included);
}
- protected Vector gatherFromArchive(File zip){
+ protected Vector gatherFromArchive(File zip) {
ZipScanner zs = new ZipScanner();
zs.setBasedir(zip);
zs.setIncludes(patterns.getIncludePatterns(project));
@@ -133,11 +131,11 @@
return testClassNameFromFile(included);
}
- protected Vector testClassNameFromFile(String[] classFileNames){
+ protected Vector testClassNameFromFile(String[] classFileNames) {
Vector tests = new Vector(classFileNames.length);
- for (int i = 0; i < classFileNames.length; i++){
+ for (int i = 0; i < classFileNames.length; i++) {
String file = classFileNames[i];
- if ( isTestClass(file) ){
+ if (isTestClass(file)) {
String classname = classNameFromFile(file);
tests.addElement(classname);
}
@@ -146,30 +144,30 @@
}
protected boolean isTestClass(String classFileName) {
- return classFileName.endsWith(".class");
- }
+ return classFileName.endsWith(".class");
+ }
- protected String classNameFromFile(String classFileName) {
- // convert /a/b.class to a.b
- String s= classFileName.substring(0,
classFileName.length()-SUFFIX_LENGTH);
- String s2= s.replace(File.separatorChar, '.');
- if ( s2.startsWith(".") ){
- s2 = s2.substring(1);
+ protected String classNameFromFile(String classFileName) {
+ // convert /a/b.class to a.b
+ String s = classFileName.substring(0, classFileName.length() -
SUFFIX_LENGTH);
+ String s2 = s.replace(File.separatorChar, '.');
+ if (s2.startsWith(".")) {
+ s2 = s2.substring(1);
}
- return s2;
- }
+ return s2;
+ }
// Ant bean accessors
- public void setPath(Path path){
+ public void setPath(Path path) {
this.path = path;
}
- public PatternSet.NameEntry createInclude(){
+ public PatternSet.NameEntry createInclude() {
return patterns.createInclude();
}
- public PatternSet.NameEntry createExclude(){
+ public PatternSet.NameEntry createExclude() {
return patterns.createExclude();
}
1.2 +16 -18
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/ZipScanner.java
Index: ZipScanner.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/ZipScanner.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ZipScanner.java 11 Jan 2002 23:35:43 -0000 1.1
+++ ZipScanner.java 13 Jan 2002 23:40:11 -0000 1.2
@@ -55,14 +55,12 @@
import java.io.File;
import java.io.IOException;
-import java.util.Vector;
import java.util.Enumeration;
-import java.util.zip.ZipFile;
+import java.util.Vector;
import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.FileScanner;
-import org.apache.tools.ant.BuildException;
/**
* Provide a way to scan entries in a zip file. Note that it extends
@@ -93,10 +91,10 @@
* normalize a set of paths so that it uses / otherwise matching will
* fail beautifully since archives use / to denote a path.
*/
- protected void normalize(String[] files){
- if (files != null){
- for (int i = 0; i < files.length; i++){
- files[i] = files[i].replace('\\','/');
+ protected void normalize(String[] files) {
+ if (files != null) {
+ for (int i = 0; i < files.length; i++) {
+ files[i] = files[i].replace('\\', '/');
}
}
}
@@ -113,11 +111,11 @@
}
if (!basedir.exists()) {
throw new IllegalStateException("zipfile " + basedir
- + " does not exist");
+ + " does not exist");
}
if (basedir.isDirectory()) {
throw new IllegalStateException("zipfile " + basedir
- + " is not a file");
+ + " is not a file");
}
if (includes == null) {
@@ -129,12 +127,12 @@
excludes = new String[0];
}
- filesIncluded = new Vector();
+ filesIncluded = new Vector();
filesNotIncluded = new Vector();
- filesExcluded = new Vector();
- dirsIncluded = new Vector();
- dirsNotIncluded = new Vector();
- dirsExcluded = new Vector();
+ filesExcluded = new Vector();
+ dirsIncluded = new Vector();
+ dirsNotIncluded = new Vector();
+ dirsExcluded = new Vector();
if (isIncluded("")) {
if (!isExcluded("")) {
@@ -152,13 +150,13 @@
ZipFile zip = null;
try {
zip = new ZipFile(file);
- } catch (IOException e){
+ } catch (IOException e) {
throw new IllegalStateException(e.getMessage());
}
Enumeration entries = zip.entries();
- while ( entries.hasMoreElements() ) {
- ZipEntry entry = (ZipEntry)entries.nextElement();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = (ZipEntry) entries.nextElement();
String name = entry.getName();
// @fixme do we need to strip out entries that starts
// with . or ./ ?
1.5 +7 -7
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
Index: JUnitTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JUnitTask.java 11 Jan 2002 23:35:43 -0000 1.4
+++ JUnitTask.java 13 Jan 2002 23:40:11 -0000 1.5
@@ -58,18 +58,18 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;
-import java.util.Enumeration;
import junit.runner.TestCollector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
-import org.apache.tools.ant.taskdefs.optional.junit.formatter.Formatter;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.LogStreamHandler;
+import org.apache.tools.ant.taskdefs.optional.junit.formatter.Formatter;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Path;
@@ -136,8 +136,8 @@
// get all test classes to run...
StringBuffer buf = new StringBuffer(10240);
Enumeration classnames = collectTests();
- while ( classnames.hasMoreElements() ){
- String classname = (String)classnames.nextElement();
+ while (classnames.hasMoreElements()) {
+ String classname = (String) classnames.nextElement();
buf.append(classname).append(" ");
}
props.setProperty("classnames", buf.toString());
@@ -170,10 +170,10 @@
/**
* @return all collected tests specified with test elements.
*/
- protected Enumeration collectTests(){
+ protected Enumeration collectTests() {
Enumeration[] tests = new Enumeration[testCollectors.size()];
- for (int i = 0; i < testCollectors.size(); i++){
- TestCollector te = (TestCollector)testCollectors.elementAt(i);
+ for (int i = 0; i < testCollectors.size(); i++) {
+ TestCollector te = (TestCollector) testCollectors.elementAt(i);
tests[i] = te.collectTests();
}
return Enumerations.fromCompound(tests);
1.5 +1 -1
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/FilterElement.java
Index: FilterElement.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/FilterElement.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FilterElement.java 11 Jan 2002 21:46:53 -0000 1.4
+++ FilterElement.java 13 Jan 2002 23:40:11 -0000 1.5
@@ -105,7 +105,7 @@
try {
Class clazz = Class.forName(classname);
if (!FilterFormatter.class.isAssignableFrom(clazz)) {
- throw new BuildException( clazz + " must be a
FilterFormatter.");
+ throw new BuildException(clazz + " must be a
FilterFormatter.");
}
Constructor ctor = clazz.getConstructor(new
Class[]{Formatter.class});
return (Formatter) ctor.newInstance(new Object[]{f});
1.5 +9 -10
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitHelper.java
Index: JUnitHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitHelper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JUnitHelper.java 11 Jan 2002 20:56:28 -0000 1.4
+++ JUnitHelper.java 13 Jan 2002 23:40:11 -0000 1.5
@@ -53,14 +53,13 @@
*/
package org.apache.tools.ant.taskdefs.optional.junit;
-import java.lang.reflect.Method;
import java.io.File;
+import java.lang.reflect.Method;
import java.net.URL;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;
/**
@@ -78,12 +77,12 @@
* <tt>name(classname)</tt>
* @return an array with the elements in the order name, classname.
*/
- public static String[] parseTestString(String testname){
+ public static String[] parseTestString(String testname) {
int p1 = testname.indexOf('(');
int p2 = testname.indexOf(')', p1);
return new String[]{
testname.substring(0, p1),
- testname.substring(p1 + 1, p2) };
+ testname.substring(p1 + 1, p2)};
}
/**
@@ -110,10 +109,10 @@
public static Test getTest(Class clazz) {
try {
Object obj = clazz.newInstance();
- if (obj instanceof TestSuite){
- return (TestSuite) obj;
+ if (obj instanceof TestSuite) {
+ return (TestSuite) obj;
}
- } catch (Exception e){
+ } catch (Exception e) {
}
try {
// check if there is a suite method
@@ -125,7 +124,7 @@
// this will generate warnings if the class is no suitable Test
try {
return new TestSuite(clazz);
- } catch (Exception e){
+ } catch (Exception e) {
}
return null;
}
@@ -141,7 +140,7 @@
* @return the file or directory containing the resource or
* <tt>null</tt> if it does not know how to handle it.
*/
- public static File getResourceEntry(String resource){
+ public static File getResourceEntry(String resource) {
URL url = JUnitHelper.class.getResource(resource);
if (url != null) {
// can't find the resource...
@@ -169,7 +168,7 @@
* @param resource the resource to look for.
* @see #getResourceEntry(String)
*/
- public static void addClasspathEntry(Path path, String resource){
+ public static void addClasspathEntry(Path path, String resource) {
File f = getResourceEntry(resource);
if (f != null) {
path.createPathElement().setLocation(f);
1.2 +1 -1
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/KeepAliveOutputStream.java
Index: KeepAliveOutputStream.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/KeepAliveOutputStream.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- KeepAliveOutputStream.java 11 Jan 2002 20:56:28 -0000 1.1
+++ KeepAliveOutputStream.java 13 Jan 2002 23:40:11 -0000 1.2
@@ -54,8 +54,8 @@
package org.apache.tools.ant.taskdefs.optional.junit;
import java.io.FilterOutputStream;
-import java.io.OutputStream;
import java.io.IOException;
+import java.io.OutputStream;
/**
* Class that can be used to wrap <tt>System.out</tt> and <tt>System.err</tt>
1.3 +2 -2
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestElement.java
Index: TestElement.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestElement.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestElement.java 13 Jan 2002 13:55:13 -0000 1.2
+++ TestElement.java 13 Jan 2002 23:40:11 -0000 1.3
@@ -70,12 +70,12 @@
//@fixme, a path is needed for a test.
public Enumeration collectTests() {
- return Enumerations.fromArray( new String[]{ name } );
+ return Enumerations.fromArray(new String[]{name});
}
// Ant bean setters
- public String setName(String value){
+ public void setName(String value) {
this.name = value;
}
}
1.3 +1 -1
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/WatchdogTest.java
Index: WatchdogTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/WatchdogTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WatchdogTest.java 11 Jan 2002 20:56:28 -0000 1.2
+++ WatchdogTest.java 13 Jan 2002 23:40:11 -0000 1.3
@@ -69,7 +69,7 @@
public class WatchdogTest extends TestDecorator {
/** the time out delay in msecs */
- protected long timeOut;
+ private long timeOut;
/**
* Create a new watchdog.
1.4 +6 -5
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/SummaryFormatter.java
Index: SummaryFormatter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/SummaryFormatter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SummaryFormatter.java 11 Jan 2002 20:56:28 -0000 1.3
+++ SummaryFormatter.java 13 Jan 2002 23:40:11 -0000 1.4
@@ -53,8 +53,8 @@
*/
package org.apache.tools.ant.taskdefs.optional.junit.formatter;
+import java.io.PrintWriter;
import java.text.MessageFormat;
-import java.util.ResourceBundle;
/**
* Display a summary message at the end of a testsuite stating
@@ -64,19 +64,20 @@
*/
public class SummaryFormatter extends BaseFormatter {
- protected MessageFormat mf = new MessageFormat(
+ 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");
protected void finished(long elapsedtime) {
+ PrintWriter writer = getWriter();
writer.print("Testsuite: ");
writer.println();
String line = mf.format(new Object[]{
- new Integer(runCount),
- new Integer(failureCount),
- new Integer(errorCount),
+ new Integer(getRunCount()),
+ new Integer(getFailureCount()),
+ new Integer(getErrorCount()),
new Long(elapsedtime / 1000)
});
writer.print(line);
1.4 +3 -0
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BriefFormatter.java
Index: BriefFormatter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BriefFormatter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BriefFormatter.java 11 Jan 2002 20:56:28 -0000 1.3
+++ BriefFormatter.java 13 Jan 2002 23:40:11 -0000 1.4
@@ -53,6 +53,8 @@
*/
package org.apache.tools.ant.taskdefs.optional.junit.formatter;
+import java.io.PrintWriter;
+
/**
* Display additional messages from a <tt>SummaryFormatter</tt>
@@ -63,6 +65,7 @@
public class BriefFormatter extends SummaryFormatter {
public void onTestFailed(int status, String testname, String trace) {
+ PrintWriter writer = getWriter();
writer.print("TestCase: ");
writer.print(testname);
if (status == STATUS_ERROR) {
1.4 +9 -11
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/XMLFormatter.java
Index: XMLFormatter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/XMLFormatter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLFormatter.java 11 Jan 2002 20:56:28 -0000 1.3
+++ XMLFormatter.java 13 Jan 2002 23:40:11 -0000 1.4
@@ -61,8 +61,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Text;
-import org.apache.tools.ant.taskdefs.optional.junit.TestRunListener;
-
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a>
@@ -148,12 +146,12 @@
public void onTestEnded(String testname) {
Element currentTest = (Element) testElements.get(testname);
// with a TestSetup, startTest and endTest are not called.
- if (currentTest == null){
+ if (currentTest == null) {
onTestStarted(testname);
currentTest = (Element) testElements.get(testname);
}
Long l = (Long) testStarts.get(testname);
- float time = ((System.currentTimeMillis()-l.longValue()) / 1000.0f);
+ float time = ((System.currentTimeMillis() - l.longValue()) /
1000.0f);
currentTest.setAttribute(ATTR_TIME, Float.toString(time));
super.onTestEnded(testname);
// remove the test objects
@@ -201,23 +199,23 @@
private static DocumentBuilder getDocumentBuilder() {
try {
return DocumentBuilderFactory.newInstance().newDocumentBuilder();
- } catch(Exception exc) {
+ } catch (Exception exc) {
throw new ExceptionInInitializerError(exc);
}
}
- protected static String[] parseFirstLine(String trace){
+ protected static String[] parseFirstLine(String trace) {
int pos = trace.indexOf('\n');
- if (pos == -1){
- return new String[]{ trace, ""};
+ if (pos == -1) {
+ return new String[]{trace, ""};
}
String line = trace.substring(0, pos);
pos = line.indexOf(':');
- if (pos != -1){
+ if (pos != -1) {
String classname = line.substring(0, pos).trim();
String message = line.substring(pos + 1).trim();
- return new String[]{ classname, message };
+ return new String[]{classname, message};
}
- return new String[]{ trace, ""};
+ return new String[]{trace, ""};
}
}
1.3 +3 -3
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/Formatter.java
Index: Formatter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/Formatter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Formatter.java 11 Jan 2002 20:56:28 -0000 1.2
+++ Formatter.java 13 Jan 2002 23:40:11 -0000 1.3
@@ -65,16 +65,16 @@
/**
* Sets the stream the formatter is supposed to write its results to.
*/
- public void setOutput( OutputStream out );
+ public void setOutput(OutputStream out);
/**
* This is what the test has written to System.out
*/
- public void setSystemOutput( String out );
+ public void setSystemOutput(String out);
/**
* This is what the test has written to System.err
*/
- public void setSystemError( String err );
+ public void setSystemError(String err);
}
1.4 +36 -26
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BaseFormatter.java
Index: BaseFormatter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BaseFormatter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BaseFormatter.java 11 Jan 2002 20:56:28 -0000 1.3
+++ BaseFormatter.java 13 Jan 2002 23:40:11 -0000 1.4
@@ -67,23 +67,22 @@
*/
public abstract class BaseFormatter implements Formatter {
- protected OutputStream out;
+ /** writer to output the data to */
+ private PrintWriter writer;
- protected PrintWriter writer;
+ /** number of errors */
+ private int errorCount;
- protected int errorCount;
+ /** number of failures */
+ private int failureCount;
- protected int failureCount;
-
- protected int runCount;
-
- protected Properties props;
+ /** number of runs (success + failure + error) */
+ private int runCount;
public void setOutput(OutputStream value) {
- out = value;
try {
- writer = new PrintWriter(new BufferedWriter(new
OutputStreamWriter(out, "UTF8")), true);
- } catch (IOException e){
+ writer = new PrintWriter(new BufferedWriter(new
OutputStreamWriter(value, "UTF8")), true);
+ } catch (IOException e) {
// should not happen
throw new IllegalStateException(e.getMessage());
}
@@ -139,22 +138,33 @@
close();
}
- /** helper method to flush and close all streams */
+ /**
+ * @return the writer used to print data.
+ */
+ protected final PrintWriter getWriter() {
+ return writer;
+ }
+
+ /** @return the number of errors */
+ protected final int getErrorCount() {
+ return errorCount;
+ }
+
+ /** @return the number of failures */
+ protected final int getFailureCount() {
+ return failureCount;
+ }
+
+ /** @return the number of runs */
+ protected final int getRunCount() {
+ return runCount;
+ }
+
+ /** helper method to flush and close the stream */
protected void close() {
- try {
- if (writer != null) {
- writer.flush();
- writer = null;
- }
- } finally {
- // make sure we're not closing System.out or System.err...
- if (out != null && out != System.err && out != System.out) {
- try {
- out.close();
- out = null;
- } catch (IOException e) {
- }
- }
+ if (writer != null) {
+ writer.flush();
+ writer.close();
}
}
}
1.4 +1 -1
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/FilterFormatter.java
Index: FilterFormatter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/FilterFormatter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FilterFormatter.java 11 Jan 2002 20:56:28 -0000 1.3
+++ FilterFormatter.java 13 Jan 2002 23:40:11 -0000 1.4
@@ -65,7 +65,7 @@
protected Formatter formatter;
- protected FilterFormatter(Formatter value){
+ protected FilterFormatter(Formatter value) {
formatter = value;
}
1.4 +16 -20
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/FilterStackFormatter.java
Index: FilterStackFormatter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/FilterStackFormatter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FilterStackFormatter.java 11 Jan 2002 20:56:28 -0000 1.3
+++ FilterStackFormatter.java 13 Jan 2002 23:40:11 -0000 1.4
@@ -53,10 +53,6 @@
*/
package org.apache.tools.ant.taskdefs.optional.junit.formatter;
-import java.io.StringWriter;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.BufferedReader;
import java.util.StringTokenizer;
import org.apache.tools.ant.util.StringUtils;
@@ -83,32 +79,32 @@
public class FilterStackFormatter extends FilterFormatter {
/** the set of matches to look for in a stack trace */
- private final static String[] DEFAULT_TRACE_FILTERS = new String[] {
- "junit.framework.TestCase",
- "junit.framework.TestResult",
- "junit.framework.TestSuite",
- "junit.framework.Assert.", // don't filter AssertionFailure
- "junit.swingui.TestRunner",
- "junit.awtui.TestRunner",
- "junit.textui.TestRunner",
- "java.lang.reflect.Method.invoke(",
- "org.apache.tools.ant."
- };
+ private final static String[] DEFAULT_TRACE_FILTERS = new String[]{
+ "junit.framework.TestCase",
+ "junit.framework.TestResult",
+ "junit.framework.TestSuite",
+ "junit.framework.Assert.", // don't filter AssertionFailure
+ "junit.swingui.TestRunner",
+ "junit.awtui.TestRunner",
+ "junit.textui.TestRunner",
+ "java.lang.reflect.Method.invoke(",
+ "org.apache.tools.ant."
+ };
/**
* Creates a new <tt>FilterStackFormatter</tt>
* @param formatter the formatter to be filtered.
*/
- public FilterStackFormatter(Formatter formatter){
+ public FilterStackFormatter(Formatter formatter) {
super(formatter);
}
public void onTestFailed(int status, String testname, String trace) {
- StringTokenizer st = new StringTokenizer(trace,"\r\n");
+ StringTokenizer st = new StringTokenizer(trace, "\r\n");
StringBuffer buf = new StringBuffer(trace.length());
- while ( st.hasMoreTokens() ){
+ while (st.hasMoreTokens()) {
String line = st.nextToken();
- if ( accept(line) ){
+ if (accept(line)) {
buf.append(line).append(StringUtils.LINE_SEP);
}
}
@@ -120,7 +116,7 @@
* @param the line to be check for acceptance.
* @return <tt>true</tt> if the line is accepted, <tt>false</tt> if not.
*/
- protected boolean accept(String line){
+ protected boolean accept(String line) {
for (int i = 0; i < DEFAULT_TRACE_FILTERS.length; i++) {
if (line.indexOf(DEFAULT_TRACE_FILTERS[i]) > 0) {
return false;
1.5 +6 -9
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/MessageReader.java
Index: MessageReader.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/MessageReader.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MessageReader.java 13 Jan 2002 13:55:13 -0000 1.4
+++ MessageReader.java 13 Jan 2002 23:40:12 -0000 1.5
@@ -57,10 +57,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.ObjectInputStream;
-import java.io.ByteArrayInputStream;
-import java.util.Vector;
import java.util.Properties;
+import java.util.Vector;
import org.apache.tools.ant.taskdefs.optional.junit.TestRunListener;
@@ -128,7 +126,7 @@
* appropriate message to the listeners.
*/
protected void processMessage(String message) {
- if (message == null){
+ if (message == null) {
return;
}
@@ -173,17 +171,16 @@
notifyTestSuiteStopped(elapsedTime);
return;
}
- if (message.startsWith(MessageIds.PROPS_START)){
+ if (message.startsWith(MessageIds.PROPS_START)) {
try {
byte[] bytes = arg.substring(0,
arg.indexOf(MessageIds.PROPS_END)).getBytes();
bytes = Base64.decode(bytes);
- ObjectInputStream ois = new ObjectInputStream(new
ByteArrayInputStream(bytes));
- sysprops = (Properties)ois.readObject();
- } catch (Exception e){
+ sysprops = (Properties) SocketUtil.deserialize(bytes);
+ notifyTestSystemProperties(sysprops);
+ } catch (Exception e) {
// ignore now
e.printStackTrace();
}
- notifyTestSystemProperties(sysprops);
}
}
1.3 +9 -12
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/MessageWriter.java
Index: MessageWriter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/MessageWriter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MessageWriter.java 11 Jan 2002 20:56:28 -0000 1.2
+++ MessageWriter.java 13 Jan 2002 23:40:12 -0000 1.3
@@ -55,9 +55,6 @@
import java.io.OutputStream;
import java.io.PrintWriter;
-import java.io.ObjectOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import org.apache.tools.ant.taskdefs.optional.junit.TestRunListener;
@@ -80,12 +77,12 @@
this.pw = new PrintWriter(out, true);
}
- protected void finalize(){
+ protected void finalize() {
close();
}
public void close() {
- if (pw != null){
+ if (pw != null) {
pw.close();
pw = null;
}
@@ -140,13 +137,13 @@
public void notifySystemProperties() {
try {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(out);
- oos.writeObject(System.getProperties());
- oos.close();
- String msg = new String(Base64.encode(out.toByteArray()));
- sendMessage(MessageIds.PROPS_START + msg + MessageIds.PROPS_END);
- } catch (IOException e){
+ StringBuffer msg = new StringBuffer(512);
+ msg.append(MessageIds.PROPS_START);
+ byte[] data = SocketUtil.serialize(System.getProperties());
+ msg.append(Base64.encode(data));
+ msg.append(MessageIds.PROPS_END);
+ sendMessage(msg.toString());
+ } catch (Exception e) {
// ignore
e.printStackTrace();
}
1.4 +19 -18
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/TestRunner.java
Index: TestRunner.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/TestRunner.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestRunner.java 11 Jan 2002 20:56:28 -0000 1.3
+++ TestRunner.java 13 Jan 2002 23:40:12 -0000 1.4
@@ -54,13 +54,13 @@
package org.apache.tools.ant.taskdefs.optional.junit.remote;
import java.io.BufferedReader;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.io.FileInputStream;
import java.net.Socket;
-import java.util.Vector;
import java.util.Properties;
import java.util.StringTokenizer;
+import java.util.Vector;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
@@ -69,9 +69,9 @@
import junit.framework.TestResult;
import junit.framework.TestSuite;
-import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.ant.taskdefs.optional.junit.JUnitHelper;
import org.apache.tools.ant.taskdefs.optional.junit.TestRunListener;
+import org.apache.tools.ant.util.StringUtils;
/**
* TestRunner for running tests and send results to a remote server.
@@ -110,7 +110,7 @@
private BufferedReader reader;
/** bean constructor */
- public TestRunner(){
+ public TestRunner() {
}
/**
@@ -216,28 +216,29 @@
}
}
}
+
/**
* Initialize the TestRunner from properties.
* @param the properties containing configuration data.
* @see #init(String[])
*/
- protected void init(Properties props){
- if ( props.getProperty("debug") != null ){
+ protected void init(Properties props) {
+ if (props.getProperty("debug") != null) {
setDebug(true);
}
String port = props.getProperty("port");
- if (port != null){
+ if (port != null) {
setPort(Integer.parseInt(port));
}
String host = props.getProperty("host");
- if (host != null){
+ if (host != null) {
setHost(host);
}
String classnames = props.getProperty("classnames");
- if (classnames != null){
+ if (classnames != null) {
StringTokenizer st = new StringTokenizer(classnames);
- while (st.hasMoreTokens()){
- addTestClassName( st.nextToken() );
+ while (st.hasMoreTokens()) {
+ addTestClassName(st.nextToken());
}
}
}
@@ -272,10 +273,10 @@
String classname = (String) testClassNames.elementAt(i);
try {
Test test = JUnitHelper.getTest(null, classname);
- if (test != null){
+ if (test != null) {
suites.addElement(test);
}
- } catch (Exception e){
+ } catch (Exception e) {
// notify log error instead ?
log("Could not get Test instance from " + classname);
log(e);
@@ -304,7 +305,7 @@
long startTime = System.currentTimeMillis();
for (int i = 0; i < suites.length; i++) {
- if (suites[i] instanceof TestCase){
+ if (suites[i] instanceof TestCase) {
suites[i] = new TestSuite(suites[i].getClass().getName());
}
suites[i].run(testResult);
@@ -413,14 +414,14 @@
writer.notifyTestEnded(testName);
}
- public void log(String msg){
- if (debug){
+ public void log(String msg) {
+ if (debug) {
System.out.println(msg);
}
}
- public void log(Throwable t){
- if (debug){
+ public void log(Throwable t) {
+ if (debug) {
t.printStackTrace();
}
}
1.4 +4 -5
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/Server.java
Index: Server.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/Server.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Server.java 13 Jan 2002 13:55:13 -0000 1.3
+++ Server.java 13 Jan 2002 23:40:12 -0000 1.4
@@ -54,7 +54,6 @@
package org.apache.tools.ant.taskdefs.optional.junit.remote;
import java.io.IOException;
-import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
@@ -134,11 +133,11 @@
/** shutdown the server and any running client */
public void shutdown() {
- if (writer != null){
+ if (writer != null) {
writer.close();
writer = null;
}
- if (reader != null){
+ if (reader != null) {
//@fixme what about the stream ?
reader = null;
}
@@ -152,11 +151,11 @@
} catch (IOException e) {
}
try {
- if (server != null){
+ if (server != null) {
server.close();
server = null;
}
- } catch (IOException e){
+ } catch (IOException e) {
}
}
1.1
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/SocketUtil.java
Index: SocketUtil.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.taskdefs.optional.junit.remote;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* A set of helper methods related to sockets.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a>
*/
public class SocketUtil {
/**
* Helper method to deserialize an object
* @param bytes the binary data representing the serialized object.
* @return the deserialized object.
* @throws Exception a generic exception if an error occurs when
* deserializing the object.
*/
public static Object deserialize(byte[] bytes) throws Exception {
ObjectInputStream ois = new ObjectInputStream(new
ByteArrayInputStream(bytes));
return ois.readObject();
}
/**
* Helper method to serialize an object
* @param o the object to serialize.
* @return the binary data representing the serialized object.
* @throws Exception a generic exception if an error occurs when
* serializing the object.
*/
public static byte[] serialize(Object o) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(o);
oos.close();
return out.toByteArray();
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>