CommandlineJava.SysProperties sysProperties =
commandline.getSystemProperties();
if (sysProperties != null) {
sysProperties.setSystem();
}
AntClassLoader cl = null;
try {
log("Using System properties " + System.getProperties(),
Project.MSG_VERBOSE);
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 = new AntClassLoader(null, project, classpath, false);
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");
cl.setThreadContextLoader();
}
runner = new JUnitTestRunner(test, test.getHaltonerror(),
test.getFiltertrace(),
test.getHaltonfailure(), cl);
if (summary) {
log("Running " + test.getName(), Project.MSG_INFO);
SummaryJUnitResultFormatter f =
new SummaryJUnitResultFormatter();
f.setWithOutAndErr("withoutanderr"
.equalsIgnoreCase(summaryValue));
f.setOutput(getDefaultOutput());
runner.addFormatter(f);
}
final FormatterElement[] feArray = mergeFormatters(test);
for (int i = 0; i < feArray.length; i++) {
FormatterElement fe = feArray[i];
File outFile = getOutput(fe, test);
if (outFile != null) {
fe.setOutfile(outFile);
} else {
fe.setOutput(getDefaultOutput());
}
runner.addFormatter(fe.createFormatter());
}
runner.run();
return runner.getRetCode();
} finally{
if (sysProperties != null) {
sysProperties.restoreSystem();
}
if (cl != null) {
cl.resetThreadContextLoader();
}
}
}