git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@960931 13f79535-47bb-0310-9956-ffa450edef68master
@@ -249,7 +249,9 @@ public class FailureRecorder extends ProjectComponent implements JUnitResultForm | |||||
File sourceFile = new File((getLocationName() + ".java")); | File sourceFile = new File((getLocationName() + ".java")); | ||||
verbose("Write collector class to '" + sourceFile.getAbsolutePath() + "'"); | verbose("Write collector class to '" + sourceFile.getAbsolutePath() + "'"); | ||||
sourceFile.delete(); | |||||
if (!sourceFile.delete()) { | |||||
throw new IOException("could not delete " + sourceFile); | |||||
} | |||||
writer = new BufferedWriter(new FileWriter(sourceFile)); | writer = new BufferedWriter(new FileWriter(sourceFile)); | ||||
createClassHeader(); | createClassHeader(); | ||||
@@ -334,13 +336,13 @@ public class FailureRecorder extends ProjectComponent implements JUnitResultForm | |||||
/** | /** | ||||
* TestInfos holds information about a given test for later use. | * TestInfos holds information about a given test for later use. | ||||
*/ | */ | ||||
public class TestInfos implements Comparable { | |||||
public static class TestInfos implements Comparable { | |||||
/** The class name of the test. */ | /** The class name of the test. */ | ||||
private String className; | |||||
private final String className; | |||||
/** The method name of the testcase. */ | /** The method name of the testcase. */ | ||||
private String methodName; | |||||
private final String methodName; | |||||
/** | /** | ||||
* This constructor extracts the needed information from the given test. | * This constructor extracts the needed information from the given test. | ||||
@@ -348,8 +350,8 @@ public class FailureRecorder extends ProjectComponent implements JUnitResultForm | |||||
*/ | */ | ||||
public TestInfos(Test test) { | public TestInfos(Test test) { | ||||
className = test.getClass().getName(); | className = test.getClass().getName(); | ||||
methodName = test.toString(); | |||||
methodName = methodName.substring(0, methodName.indexOf('(')); | |||||
String _methodName = test.toString(); | |||||
methodName = _methodName.substring(0, _methodName.indexOf('(')); | |||||
} | } | ||||
/** | /** | ||||
@@ -378,6 +380,12 @@ public class FailureRecorder extends ProjectComponent implements JUnitResultForm | |||||
return -1; | return -1; | ||||
} | } | ||||
} | } | ||||
public boolean equals(Object obj) { | |||||
return obj instanceof TestInfos && toString().equals(obj.toString()); | |||||
} | |||||
public int hashCode() { | |||||
return toString().hashCode(); | |||||
} | |||||
} | } | ||||
// ===== BuildListener ===== | // ===== BuildListener ===== | ||||
@@ -23,6 +23,7 @@ import java.io.FileOutputStream; | |||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
import java.io.BufferedOutputStream; | import java.io.BufferedOutputStream; | ||||
import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||
import java.lang.reflect.InvocationTargetException; | |||||
import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
@@ -326,8 +327,10 @@ public class FormatterElement { | |||||
// there is already a project reference so dont overwrite this | // there is already a project reference so dont overwrite this | ||||
needToSetProjectReference = false; | needToSetProjectReference = false; | ||||
} | } | ||||
} catch (Exception e) { | |||||
} catch (NoSuchFieldException e) { | |||||
// no field present, so no previous reference exists | // no field present, so no previous reference exists | ||||
} catch (IllegalAccessException e) { | |||||
throw new BuildException(e); | |||||
} | } | ||||
if (needToSetProjectReference) { | if (needToSetProjectReference) { | ||||
@@ -335,8 +338,12 @@ public class FormatterElement { | |||||
try { | try { | ||||
setter = r.getClass().getMethod("setProject", new Class[] {Project.class}); | setter = r.getClass().getMethod("setProject", new Class[] {Project.class}); | ||||
setter.invoke(r, new Object[] {project}); | setter.invoke(r, new Object[] {project}); | ||||
} catch (Exception e) { | |||||
} catch (NoSuchMethodException e) { | |||||
// no setProject to invoke; just ignore | // no setProject to invoke; just ignore | ||||
} catch (IllegalAccessException e) { | |||||
throw new BuildException(e); | |||||
} catch (InvocationTargetException e) { | |||||
throw new BuildException(e); | |||||
} | } | ||||
} | } | ||||
@@ -74,7 +74,7 @@ public class JUnit4TestMethodAdapter implements Test { | |||||
} | } | ||||
} | } | ||||
this.testClass = testClass; | this.testClass = testClass; | ||||
this.methodNames = methodNames; | |||||
this.methodNames = (String[]) methodNames.clone(); | |||||
this.cache = Cache.instance; | this.cache = Cache.instance; | ||||
// Warning: If 'testClass' is an old-style (pre-JUnit-4) class, | // Warning: If 'testClass' is an old-style (pre-JUnit-4) class, | ||||
@@ -194,6 +194,8 @@ public class JUnit4TestMethodAdapter implements Test { | |||||
* of type {@code JUnit4TestAdapter}. | * of type {@code JUnit4TestAdapter}. | ||||
*/ | */ | ||||
private static final class Cache extends JUnit4TestAdapterCache { | private static final class Cache extends JUnit4TestAdapterCache { | ||||
private static final long serialVersionUID = 8454901854293461610L; | |||||
private static final Cache instance = new Cache(); | private static final Cache instance = new Cache(); | ||||
@@ -29,6 +29,8 @@ import java.io.OutputStream; | |||||
import java.io.PrintStream; | import java.io.PrintStream; | ||||
import java.lang.reflect.Constructor; | import java.lang.reflect.Constructor; | ||||
import java.net.URL; | import java.net.URL; | ||||
import java.security.AccessController; | |||||
import java.security.PrivilegedAction; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
import java.util.Enumeration; | import java.util.Enumeration; | ||||
@@ -652,8 +654,6 @@ public class JUnitTask extends Task { | |||||
* @since Ant 1.2 | * @since Ant 1.2 | ||||
*/ | */ | ||||
public JUnitTask() throws Exception { | public JUnitTask() throws Exception { | ||||
getCommandline() | |||||
.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner"); | |||||
} | } | ||||
/** | /** | ||||
@@ -716,16 +716,17 @@ public class JUnitTask extends Task { | |||||
* @since Ant 1.7.1 | * @since Ant 1.7.1 | ||||
*/ | */ | ||||
protected void setupJUnitDelegate() { | protected void setupJUnitDelegate() { | ||||
ClassLoader myLoader = JUnitTask.class.getClassLoader(); | |||||
final ClassLoader myLoader = JUnitTask.class.getClassLoader(); | |||||
if (splitJunit) { | if (splitJunit) { | ||||
Path path = new Path(getProject()); | |||||
final Path path = new Path(getProject()); | |||||
path.add(antRuntimeClasses); | path.add(antRuntimeClasses); | ||||
Path extra = getCommandline().getClasspath(); | Path extra = getCommandline().getClasspath(); | ||||
if (extra != null) { | if (extra != null) { | ||||
path.add(extra); | path.add(extra); | ||||
} | } | ||||
mirrorLoader = | |||||
new SplitClassLoader(myLoader, path, getProject(), | |||||
mirrorLoader = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { | |||||
public Object run() { | |||||
return new SplitClassLoader(myLoader, path, getProject(), | |||||
new String[] { | new String[] { | ||||
"BriefJUnitResultFormatter", | "BriefJUnitResultFormatter", | ||||
"JUnit4TestMethodAdapter", | "JUnit4TestMethodAdapter", | ||||
@@ -739,6 +740,8 @@ public class JUnitTask extends Task { | |||||
"TearDownOnVmCrash", | "TearDownOnVmCrash", | ||||
"XMLJUnitResultFormatter", | "XMLJUnitResultFormatter", | ||||
}); | }); | ||||
} | |||||
}); | |||||
} else { | } else { | ||||
mirrorLoader = myLoader; | mirrorLoader = myLoader; | ||||
} | } | ||||
@@ -884,7 +887,7 @@ public class JUnitTask extends Task { | |||||
log(e.toString(), Project.MSG_ERR); | log(e.toString(), Project.MSG_ERR); | ||||
throw new BuildException(e); | throw new BuildException(e); | ||||
} finally { | } finally { | ||||
FILE_UTILS.close(writer); | |||||
FileUtils.close(writer); | |||||
try { | try { | ||||
FILE_UTILS.tryHardToDelete(casesFile); | FILE_UTILS.tryHardToDelete(casesFile); | ||||
@@ -925,7 +928,6 @@ public class JUnitTask extends Task { | |||||
} catch (CloneNotSupportedException e) { | } catch (CloneNotSupportedException e) { | ||||
throw new BuildException("This shouldn't happen", e, getLocation()); | throw new BuildException("This shouldn't happen", e, getLocation()); | ||||
} | } | ||||
cmd.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner"); | |||||
if (casesFile == null) { | if (casesFile == null) { | ||||
cmd.createArgument().setValue(test.getName()); | cmd.createArgument().setValue(test.getName()); | ||||
if (test.getMethods() != null) { | if (test.getMethods() != null) { | ||||
@@ -1177,13 +1179,13 @@ public class JUnitTask extends Task { | |||||
return new File(FILE_UTILS.fromURI(url1)) | return new File(FILE_UTILS.fromURI(url1)) | ||||
.equals(new File(FILE_UTILS.fromURI(url2))); | .equals(new File(FILE_UTILS.fromURI(url2))); | ||||
} | } | ||||
return u1.equals(u2); | |||||
return url1.equals(url2); | |||||
} | } | ||||
private static String maybeStripJarAndClass(URL u) { | private static String maybeStripJarAndClass(URL u) { | ||||
String s = u.toString(); | String s = u.toString(); | ||||
if (s.startsWith("jar:")) { | if (s.startsWith("jar:")) { | ||||
int pling = s.indexOf("!"); | |||||
int pling = s.indexOf('!'); | |||||
s = s.substring(4, pling == -1 ? s.length() : pling); | s = s.substring(4, pling == -1 ? s.length() : pling); | ||||
} | } | ||||
return s; | return s; | ||||
@@ -1723,6 +1725,7 @@ public class JUnitTask extends Task { | |||||
protected CommandlineJava getCommandline() { | protected CommandlineJava getCommandline() { | ||||
if (commandline == null) { | if (commandline == null) { | ||||
commandline = new CommandlineJava(); | commandline = new CommandlineJava(); | ||||
commandline.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner"); | |||||
} | } | ||||
return commandline; | return commandline; | ||||
} | } | ||||
@@ -1940,7 +1943,7 @@ public class JUnitTask extends Task { | |||||
/** | /** | ||||
* A value class that contains the result of a test. | * A value class that contains the result of a test. | ||||
*/ | */ | ||||
protected class TestResultHolder { | |||||
protected static class TestResultHolder { | |||||
// CheckStyle:VisibilityModifier OFF - bc | // CheckStyle:VisibilityModifier OFF - bc | ||||
/** the exit code of the test. */ | /** the exit code of the test. */ | ||||
public int exitCode = JUnitTaskMirror.JUnitTestRunnerMirror.ERRORS; | public int exitCode = JUnitTaskMirror.JUnitTestRunnerMirror.ERRORS; | ||||
@@ -2019,7 +2022,7 @@ public class JUnitTask extends Task { | |||||
*/ | */ | ||||
private static JUnitTest createDummyTestForBatchTest(JUnitTest test) { | private static JUnitTest createDummyTestForBatchTest(JUnitTest test) { | ||||
JUnitTest t = (JUnitTest) test.clone(); | JUnitTest t = (JUnitTest) test.clone(); | ||||
int index = test.getName().indexOf("."); | |||||
int index = test.getName().indexOf('.'); | |||||
// make sure test looks as if it was in the same "package" as | // make sure test looks as if it was in the same "package" as | ||||
// the last test of the batch | // the last test of the batch | ||||
String pack = index > 0 ? test.getName().substring(0, index + 1) : ""; | String pack = index > 0 ? test.getName().substring(0, index + 1) : ""; | ||||
@@ -97,8 +97,7 @@ public class JUnitTest extends BaseTest implements Cloneable { | |||||
* @param haltOnError if true halt the tests if there is an error. | * @param haltOnError if true halt the tests if there is an error. | ||||
* @param haltOnFailure if true halt the tests if there is a failure. | * @param haltOnFailure if true halt the tests if there is a failure. | ||||
* @param filtertrace if true filter stack traces. | * @param filtertrace if true filter stack traces. | ||||
* @param methods if true run only test methods that failed during the | |||||
* previous run of the test suite | |||||
* @param methods if non-null run only these test methods | |||||
* @since 1.8.2 | * @since 1.8.2 | ||||
*/ | */ | ||||
public JUnitTest(String name, boolean haltOnError, boolean haltOnFailure, | public JUnitTest(String name, boolean haltOnError, boolean haltOnFailure, | ||||
@@ -107,8 +106,8 @@ public class JUnitTest extends BaseTest implements Cloneable { | |||||
this.haltOnError = haltOnError; | this.haltOnError = haltOnError; | ||||
this.haltOnFail = haltOnFailure; | this.haltOnFail = haltOnFailure; | ||||
this.filtertrace = filtertrace; | this.filtertrace = filtertrace; | ||||
this.methods = methods; | |||||
this.methodsSpecified = (methods != null); | |||||
this.methodsSpecified = methods != null; | |||||
this.methods = methodsSpecified ? (String[]) methods.clone() : null; | |||||
} | } | ||||
/** | /** | ||||
@@ -298,10 +297,10 @@ public class JUnitTest extends BaseTest implements Cloneable { | |||||
break; | break; | ||||
case stateInsideWord: | case stateInsideWord: | ||||
if (c == ',') { | if (c == ',') { | ||||
result[wordIndex++] = new String(methodNames.substring(wordStartIndex, i)); | |||||
result[wordIndex++] = methodNames.substring(wordStartIndex, i); | |||||
state = stateBeforeWord; | state = stateBeforeWord; | ||||
} else if (c == ' ') { | } else if (c == ' ') { | ||||
result[wordIndex++] = new String(methodNames.substring(wordStartIndex, i)); | |||||
result[wordIndex++] = methodNames.substring(wordStartIndex, i); | |||||
state = stateAfterWord; | state = stateAfterWord; | ||||
} else if (Character.isJavaIdentifierPart(c)) { | } else if (Character.isJavaIdentifierPart(c)) { | ||||
// remain in the same state | // remain in the same state | ||||
@@ -327,7 +326,7 @@ public class JUnitTest extends BaseTest implements Cloneable { | |||||
case stateAfterWord: | case stateAfterWord: | ||||
break; | break; | ||||
case stateInsideWord: | case stateInsideWord: | ||||
result[wordIndex++] = new String(methodNames.substring(wordStartIndex, chars.length)); | |||||
result[wordIndex++] = methodNames.substring(wordStartIndex, chars.length); | |||||
break; | break; | ||||
default: | default: | ||||
// this should never happen | // this should never happen | ||||
@@ -289,13 +289,13 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
boolean filtertrace, boolean haltOnFailure, | boolean filtertrace, boolean haltOnFailure, | ||||
boolean showOutput, boolean logTestListenerEvents, | boolean showOutput, boolean logTestListenerEvents, | ||||
ClassLoader loader) { | ClassLoader loader) { | ||||
JUnitTestRunner.filtertrace = filtertrace; | |||||
JUnitTestRunner.filtertrace = filtertrace; // XXX clumsy, should use instance field somehow | |||||
this.junitTest = test; | this.junitTest = test; | ||||
this.haltOnError = haltOnError; | this.haltOnError = haltOnError; | ||||
this.haltOnFailure = haltOnFailure; | this.haltOnFailure = haltOnFailure; | ||||
this.showOutput = showOutput; | this.showOutput = showOutput; | ||||
this.logTestListenerEvents = logTestListenerEvents; | this.logTestListenerEvents = logTestListenerEvents; | ||||
this.methods = methods; | |||||
this.methods = methods != null ? (String[]) methods.clone() : null; | |||||
this.loader = loader; | this.loader = loader; | ||||
} | } | ||||