Browse Source

fix part of Cactus problems with the refactored JUnit task of 1.7.0: create the "delegate" as needed instead of in execute()

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@628990 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
86b59ef90a
1 changed files with 34 additions and 11 deletions
  1. +34
    -11
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java

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

@@ -162,6 +162,7 @@ public class JUnitTask extends Task {

private boolean splitJunit = false;
private JUnitTaskMirror delegate;
private ClassLoader mirrorLoader;

/** A boolean on whether to get the forked path for ant classes */
private boolean forkedPathChecked = false;
@@ -746,14 +747,10 @@ public class JUnitTask extends Task {
}

/**
* Runs the testcase.
*
* @throws BuildException in case of test failures or errors
* @since Ant 1.2
* Sets up the delegate that will actually run the tests.
*/
public void execute() throws BuildException {
protected void setupJUnitDelegate() {
ClassLoader myLoader = JUnitTask.class.getClassLoader();
ClassLoader mirrorLoader;
if (splitJunit) {
Path path = new Path(getProject());
path.add(antRuntimeClasses);
@@ -766,6 +763,16 @@ public class JUnitTask extends Task {
mirrorLoader = myLoader;
}
delegate = createMirror(this, mirrorLoader);
}

/**
* Runs the testcase.
*
* @throws BuildException in case of test failures or errors
* @since Ant 1.2
*/
public void execute() throws BuildException {
setupJUnitDelegate();

List testLists = new ArrayList();

@@ -793,11 +800,7 @@ public class JUnitTask extends Task {
}
}
} finally {
deleteClassLoader();
if (mirrorLoader instanceof SplitLoader) {
((SplitLoader) mirrorLoader).cleanup();
}
delegate = null;
cleanup();
}
}

@@ -1262,6 +1265,10 @@ public class JUnitTask extends Task {
* @return the results
*/
private TestResultHolder executeInVM(JUnitTest arg) throws BuildException {
if (delegate == null) {
setupJUnitDelegate();
}

JUnitTest test = (JUnitTest) arg.clone();
test.setProperties(getProject().getProperties());
if (dir != null) {
@@ -1514,6 +1521,10 @@ public class JUnitTask extends Task {
*/
private void logVmExit(FormatterElement[] feArray, JUnitTest test,
String message, String testCase) {
if (delegate == null) {
setupJUnitDelegate();
}

try {
log("Using System properties " + System.getProperties(),
Project.MSG_VERBOSE);
@@ -1591,6 +1602,14 @@ public class JUnitTask extends Task {
}
}

/**
* Removes resources.
*/
protected void cleanup() {
deleteClassLoader();
delegate = null;
}

/**
* Removes a classloader if needed.
* @since Ant 1.7
@@ -1600,6 +1619,10 @@ public class JUnitTask extends Task {
classLoader.cleanup();
classLoader = null;
}
if (mirrorLoader instanceof SplitLoader) {
((SplitLoader) mirrorLoader).cleanup();
}
mirrorLoader = null;
}

/**


Loading…
Cancel
Save