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")); | |||
| 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)); | |||
| createClassHeader(); | |||
| @@ -334,13 +336,13 @@ public class FailureRecorder extends ProjectComponent implements JUnitResultForm | |||
| /** | |||
| * 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. */ | |||
| private String className; | |||
| private final String className; | |||
| /** The method name of the testcase. */ | |||
| private String methodName; | |||
| private final String methodName; | |||
| /** | |||
| * 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) { | |||
| 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; | |||
| } | |||
| } | |||
| public boolean equals(Object obj) { | |||
| return obj instanceof TestInfos && toString().equals(obj.toString()); | |||
| } | |||
| public int hashCode() { | |||
| return toString().hashCode(); | |||
| } | |||
| } | |||
| // ===== BuildListener ===== | |||
| @@ -23,6 +23,7 @@ import java.io.FileOutputStream; | |||
| import java.io.OutputStream; | |||
| import java.io.BufferedOutputStream; | |||
| import java.lang.reflect.Field; | |||
| import java.lang.reflect.InvocationTargetException; | |||
| import java.lang.reflect.Method; | |||
| import org.apache.tools.ant.BuildException; | |||
| @@ -326,8 +327,10 @@ public class FormatterElement { | |||
| // there is already a project reference so dont overwrite this | |||
| needToSetProjectReference = false; | |||
| } | |||
| } catch (Exception e) { | |||
| } catch (NoSuchFieldException e) { | |||
| // no field present, so no previous reference exists | |||
| } catch (IllegalAccessException e) { | |||
| throw new BuildException(e); | |||
| } | |||
| if (needToSetProjectReference) { | |||
| @@ -335,8 +338,12 @@ public class FormatterElement { | |||
| try { | |||
| setter = r.getClass().getMethod("setProject", new Class[] {Project.class}); | |||
| setter.invoke(r, new Object[] {project}); | |||
| } catch (Exception e) { | |||
| } catch (NoSuchMethodException e) { | |||
| // 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.methodNames = methodNames; | |||
| this.methodNames = (String[]) methodNames.clone(); | |||
| this.cache = Cache.instance; | |||
| // Warning: If 'testClass' is an old-style (pre-JUnit-4) class, | |||
| @@ -194,6 +194,8 @@ public class JUnit4TestMethodAdapter implements Test { | |||
| * of type {@code JUnit4TestAdapter}. | |||
| */ | |||
| private static final class Cache extends JUnit4TestAdapterCache { | |||
| private static final long serialVersionUID = 8454901854293461610L; | |||
| private static final Cache instance = new Cache(); | |||
| @@ -29,6 +29,8 @@ import java.io.OutputStream; | |||
| import java.io.PrintStream; | |||
| import java.lang.reflect.Constructor; | |||
| import java.net.URL; | |||
| import java.security.AccessController; | |||
| import java.security.PrivilegedAction; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.Enumeration; | |||
| @@ -652,8 +654,6 @@ public class JUnitTask extends Task { | |||
| * @since Ant 1.2 | |||
| */ | |||
| 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 | |||
| */ | |||
| protected void setupJUnitDelegate() { | |||
| ClassLoader myLoader = JUnitTask.class.getClassLoader(); | |||
| final ClassLoader myLoader = JUnitTask.class.getClassLoader(); | |||
| if (splitJunit) { | |||
| Path path = new Path(getProject()); | |||
| final Path path = new Path(getProject()); | |||
| path.add(antRuntimeClasses); | |||
| Path extra = getCommandline().getClasspath(); | |||
| if (extra != null) { | |||
| 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[] { | |||
| "BriefJUnitResultFormatter", | |||
| "JUnit4TestMethodAdapter", | |||
| @@ -739,6 +740,8 @@ public class JUnitTask extends Task { | |||
| "TearDownOnVmCrash", | |||
| "XMLJUnitResultFormatter", | |||
| }); | |||
| } | |||
| }); | |||
| } else { | |||
| mirrorLoader = myLoader; | |||
| } | |||
| @@ -884,7 +887,7 @@ public class JUnitTask extends Task { | |||
| log(e.toString(), Project.MSG_ERR); | |||
| throw new BuildException(e); | |||
| } finally { | |||
| FILE_UTILS.close(writer); | |||
| FileUtils.close(writer); | |||
| try { | |||
| FILE_UTILS.tryHardToDelete(casesFile); | |||
| @@ -925,7 +928,6 @@ public class JUnitTask extends Task { | |||
| } catch (CloneNotSupportedException e) { | |||
| throw new BuildException("This shouldn't happen", e, getLocation()); | |||
| } | |||
| cmd.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner"); | |||
| if (casesFile == null) { | |||
| cmd.createArgument().setValue(test.getName()); | |||
| if (test.getMethods() != null) { | |||
| @@ -1177,13 +1179,13 @@ public class JUnitTask extends Task { | |||
| return new File(FILE_UTILS.fromURI(url1)) | |||
| .equals(new File(FILE_UTILS.fromURI(url2))); | |||
| } | |||
| return u1.equals(u2); | |||
| return url1.equals(url2); | |||
| } | |||
| private static String maybeStripJarAndClass(URL u) { | |||
| String s = u.toString(); | |||
| if (s.startsWith("jar:")) { | |||
| int pling = s.indexOf("!"); | |||
| int pling = s.indexOf('!'); | |||
| s = s.substring(4, pling == -1 ? s.length() : pling); | |||
| } | |||
| return s; | |||
| @@ -1723,6 +1725,7 @@ public class JUnitTask extends Task { | |||
| protected CommandlineJava getCommandline() { | |||
| if (commandline == null) { | |||
| commandline = new CommandlineJava(); | |||
| commandline.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner"); | |||
| } | |||
| return commandline; | |||
| } | |||
| @@ -1940,7 +1943,7 @@ public class JUnitTask extends Task { | |||
| /** | |||
| * A value class that contains the result of a test. | |||
| */ | |||
| protected class TestResultHolder { | |||
| protected static class TestResultHolder { | |||
| // CheckStyle:VisibilityModifier OFF - bc | |||
| /** the exit code of the test. */ | |||
| public int exitCode = JUnitTaskMirror.JUnitTestRunnerMirror.ERRORS; | |||
| @@ -2019,7 +2022,7 @@ public class JUnitTask extends Task { | |||
| */ | |||
| private static JUnitTest createDummyTestForBatchTest(JUnitTest test) { | |||
| 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 | |||
| // the last test of the batch | |||
| 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 haltOnFailure if true halt the tests if there is a failure. | |||
| * @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 | |||
| */ | |||
| public JUnitTest(String name, boolean haltOnError, boolean haltOnFailure, | |||
| @@ -107,8 +106,8 @@ public class JUnitTest extends BaseTest implements Cloneable { | |||
| this.haltOnError = haltOnError; | |||
| this.haltOnFail = haltOnFailure; | |||
| 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; | |||
| case stateInsideWord: | |||
| if (c == ',') { | |||
| result[wordIndex++] = new String(methodNames.substring(wordStartIndex, i)); | |||
| result[wordIndex++] = methodNames.substring(wordStartIndex, i); | |||
| state = stateBeforeWord; | |||
| } else if (c == ' ') { | |||
| result[wordIndex++] = new String(methodNames.substring(wordStartIndex, i)); | |||
| result[wordIndex++] = methodNames.substring(wordStartIndex, i); | |||
| state = stateAfterWord; | |||
| } else if (Character.isJavaIdentifierPart(c)) { | |||
| // remain in the same state | |||
| @@ -327,7 +326,7 @@ public class JUnitTest extends BaseTest implements Cloneable { | |||
| case stateAfterWord: | |||
| break; | |||
| case stateInsideWord: | |||
| result[wordIndex++] = new String(methodNames.substring(wordStartIndex, chars.length)); | |||
| result[wordIndex++] = methodNames.substring(wordStartIndex, chars.length); | |||
| break; | |||
| default: | |||
| // this should never happen | |||
| @@ -289,13 +289,13 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||
| boolean filtertrace, boolean haltOnFailure, | |||
| boolean showOutput, boolean logTestListenerEvents, | |||
| ClassLoader loader) { | |||
| JUnitTestRunner.filtertrace = filtertrace; | |||
| JUnitTestRunner.filtertrace = filtertrace; // XXX clumsy, should use instance field somehow | |||
| this.junitTest = test; | |||
| this.haltOnError = haltOnError; | |||
| this.haltOnFailure = haltOnFailure; | |||
| this.showOutput = showOutput; | |||
| this.logTestListenerEvents = logTestListenerEvents; | |||
| this.methods = methods; | |||
| this.methods = methods != null ? (String[]) methods.clone() : null; | |||
| this.loader = loader; | |||
| } | |||