Browse Source

Load formatter from user specified classpath - even in the timeout case.

PR: 19953
Submitted by:	Mariano Benitez <mariano at fuegolabs dot com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274608 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
bd578f489a
3 changed files with 60 additions and 24 deletions
  1. +4
    -0
      WHATSNEW
  2. +20
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
  3. +36
    -22
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java

+ 4
- 0
WHATSNEW View File

@@ -132,6 +132,10 @@ Fixed bugs:
* file names that include spaces need to be quoted inside the @argfile * file names that include spaces need to be quoted inside the @argfile
argument using <javadoc> and JDK 1.4. Bugzilla Report 16871. argument using <javadoc> and JDK 1.4. Bugzilla Report 16871.


* <junit> didn't work with custom formatters that were only available
on the user specified classpath when a timeout occured. Bugzilla
Report 19953.

Other changes: Other changes:
-------------- --------------
* Six new Clearcase tasks added. * Six new Clearcase tasks added.


+ 20
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -57,6 +57,7 @@ package org.apache.tools.ant.taskdefs.optional.junit;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.EnumeratedAttribute;


@@ -172,14 +173,31 @@ public class FormatterElement {
return useFile; return useFile;
} }


/**
* @since Ant 1.2
*/
JUnitResultFormatter createFormatter() throws BuildException { JUnitResultFormatter createFormatter() throws BuildException {
return createFormatter(null);
}

/**
* @since Ant 1.6
*/
JUnitResultFormatter createFormatter(ClassLoader loader)
throws BuildException {

if (classname == null) { if (classname == null) {
throw new BuildException("you must specify type or classname"); throw new BuildException("you must specify type or classname");
} }
Class f = null; Class f = null;
try { try {
f = Class.forName(classname);
if (loader == null) {
f = Class.forName(classname);
} else {
f = loader.loadClass(classname);
AntClassLoader.initializeClass(f);
}
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new BuildException(e); throw new BuildException(e);
} }


+ 36
- 22
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -835,26 +835,8 @@ public class JUnitTask extends Task {
log("Using System properties " + System.getProperties(), log("Using System properties " + System.getProperties(),
Project.MSG_VERBOSE); Project.MSG_VERBOSE);
Path userClasspath = commandline.getClasspath(); Path userClasspath = commandline.getClasspath();
Path classpath = userClasspath == null
? null
: (Path) userClasspath.clone();
if (classpath != null) {
if (includeAntRuntime) {
log("Implicitly adding " + antRuntimeClasses
+ " to CLASSPATH", Project.MSG_VERBOSE);
classpath.append(antRuntimeClasses);
}

cl = getProject().createClassLoader(classpath);
cl.setParentFirst(false);
cl.addJavaLibraries();
log("Using CLASSPATH " + cl.getClasspath(),
Project.MSG_VERBOSE);

// make sure the test will be accepted as a TestCase
cl.addSystemPackageRoot("junit");
// will cause trouble in JDK 1.1 if omitted
cl.addSystemPackageRoot("org.apache.tools.ant");
if (userClasspath != null) {
cl = createClassLoader();
cl.setThreadContextLoader(); cl.setThreadContextLoader();
} }
runner = new JUnitTestRunner(test, test.getHaltonerror(), runner = new JUnitTestRunner(test, test.getHaltonerror(),
@@ -880,7 +862,7 @@ public class JUnitTask extends Task {
} else { } else {
fe.setOutput(getDefaultOutput()); fe.setOutput(getDefaultOutput());
} }
runner.addFormatter(fe.createFormatter());
runner.addFormatter(fe.createFormatter(cl));
} }


runner.run(); runner.run();
@@ -1013,10 +995,11 @@ public class JUnitTask extends Task {
*/ */


private void logTimeout(FormatterElement[] feArray, JUnitTest test) { private void logTimeout(FormatterElement[] feArray, JUnitTest test) {
AntClassLoader cl = createClassLoader();
for (int i = 0; i < feArray.length; i++) { for (int i = 0; i < feArray.length; i++) {
FormatterElement fe = feArray[i]; FormatterElement fe = feArray[i];
File outFile = getOutput(fe, test); File outFile = getOutput(fe, test);
JUnitResultFormatter formatter = fe.createFormatter();
JUnitResultFormatter formatter = fe.createFormatter(cl);
if (outFile != null && formatter != null) { if (outFile != null && formatter != null) {
try { try {
OutputStream out = new FileOutputStream(outFile); OutputStream out = new FileOutputStream(outFile);
@@ -1040,4 +1023,35 @@ public class JUnitTask extends Task {
} }
} }


/**
* Creates and configures an AntClassLoader instance from the
* nested classpath element.
*
* @return null if there is no user-specified classpath.
*
* @since Ant 1.6
*/
private AntClassLoader createClassLoader() {
AntClassLoader cl = null;
Path userClasspath = commandline.getClasspath();
if (userClasspath != null) {
Path classpath = (Path) userClasspath.clone();
if (includeAntRuntime) {
log("Implicitly adding " + antRuntimeClasses
+ " to CLASSPATH", Project.MSG_VERBOSE);
classpath.append(antRuntimeClasses);
}

cl = getProject().createClassLoader(classpath);
cl.setParentFirst(false);
cl.addJavaLibraries();
log("Using CLASSPATH " + cl.getClasspath(), Project.MSG_VERBOSE);

// make sure the test will be accepted as a TestCase
cl.addSystemPackageRoot("junit");
// will cause trouble in JDK 1.1 if omitted
cl.addSystemPackageRoot("org.apache.tools.ant");
}
return cl;
}
} }

Loading…
Cancel
Save