On Fri, 15 Feb 2008, Petar Tahchiev <[EMAIL PROTECTED]> wrote:
> in the execute(JUnitTest arg) method, too. Well, as Stefan
> suggested, we can put the
> if (delegate == null) {
> setupJUnitDelegate();
> }
>
> in executeInVM() method, that we call when we don't fork the JUnit
> execution. Well, as you see a little bit
> down in the code there is a piece that states:
> if (splitJunit) {
> classLoader = (AntClassLoader) delegate.getClass
> ().getClassLoader();
> } else {
> createClassLoader();
> }
>
> since I have no control over splitJUnit it is false, and then we
> invoke the createClassLoader(); method, which, invokes
> deleteClassLoader() and it, again, nullify-s the delegate object.
Ouch, my fault.
Actually I added the "delegate = null" statement to
deleteClassLoader after running my tests and didn't rerun the
tests after the change. I know I shouldn't do that, even if a
change looks simple.
Appended is a revised patch that doesn't exhibit the same
problem.
Stefan
Index: src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
===================================================================
--- src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
(revision 628687)
+++ src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
(working copy)
@@ -162,6 +162,7 @@
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 @@
}
/**
- * 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,7 +763,17 @@
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();
boolean forkPerTest = forkMode.getValue().equals(ForkMode.PER_TEST);
@@ -793,11 +800,7 @@
}
}
} finally {
- deleteClassLoader();
- if (mirrorLoader instanceof SplitLoader) {
- ((SplitLoader) mirrorLoader).cleanup();
- }
- delegate = null;
+ cleanup();
}
}
@@ -1262,6 +1265,10 @@
* @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 @@
*/
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);
@@ -1592,6 +1603,14 @@
}
/**
+ * Removes resources.
+ */
+ protected void cleanup() {
+ deleteClassLoader();
+ delegate = null;
+ }
+
+ /**
* Removes a classloader if needed.
* @since Ant 1.7
*/
@@ -1600,6 +1619,10 @@
classLoader.cleanup();
classLoader = null;
}
+ if (mirrorLoader instanceof SplitLoader) {
+ ((SplitLoader) mirrorLoader).cleanup();
+ }
+ mirrorLoader = null;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]