Our project currently requires that JUnit tests share a database connection. A separate issue requires us to migrate to Ant 1.5.3. The attached patch adds a boolean parameter called 'reloading' to JUnitTask. The default value of 'reloading' is 'true' so that it has backward compatible behavior.

We are trying to migrate away from this requirement, but it will take quite a bit of time. I am providing this patch in the hopes that we can avoid having a customized version of Ant in our development environment.

Michael
Index: JUnitTask.java
===================================================================
RCS file: 
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
retrieving revision 1.44.2.7
diff -u -b -w -r1.44.2.7 JUnitTask.java
--- JUnitTask.java      10 Feb 2003 14:25:13 -0000      1.44.2.7
+++ JUnitTask.java      6 Jun 2003 21:37:27 -0000
@@ -168,6 +168,7 @@
 
     private Integer timeout = null;
     private boolean summary = false;
+    private boolean reloading = true;
     private String summaryValue = "";
     private JUnitTestRunner runner = null;
 
@@ -178,6 +179,16 @@
     private Path antRuntimeClasses = null;
 
     private boolean showOutput = false;
+    private AntClassLoader classLoader = null;
+
+    /**
+     * If true, force ant to re-classload all classes for each JUnit TestCase
+     *
+     * @param value force class reloading for each test case
+     */
+    public void setReloading(boolean value) {
+        reloading = value;
+    }
 
     /**
      * If true, smartly filter the stack frames of
@@ -794,7 +805,7 @@
         if (sysProperties != null) {
             sysProperties.setSystem();
         }
-        AntClassLoader cl = null;
+
         try {
             log("Using System properties " + System.getProperties(), 
                 Project.MSG_VERBOSE);
@@ -809,19 +820,21 @@
                     classpath.append(antRuntimeClasses);
                 }
 
-                cl = new AntClassLoader(null, getProject(), classpath, false);
-                log("Using CLASSPATH " + cl.getClasspath(),
+                if (reloading || classLoader == null) {
+                    classLoader = new AntClassLoader(null, getProject(), 
classpath, false);
+                    log("Using CLASSPATH " + classLoader.getClasspath(),
                     Project.MSG_VERBOSE);
 
                 // make sure the test will be accepted as a TestCase
-                cl.addSystemPackageRoot("junit");
+                    classLoader.addSystemPackageRoot("junit");
                 // will cause trouble in JDK 1.1 if omitted
-                cl.addSystemPackageRoot("org.apache.tools.ant");
-                cl.setThreadContextLoader();
+                    classLoader.addSystemPackageRoot("org.apache.tools.ant");
+                    classLoader.setThreadContextLoader();
+                }
             }
             runner = new JUnitTestRunner(test, test.getHaltonerror(), 
                                          test.getFiltertrace(), 
-                                         test.getHaltonfailure(), cl);
+                                         test.getHaltonfailure(), classLoader);
             if (summary) {
                 log("Running " + test.getName(), Project.MSG_INFO);
 
@@ -851,8 +864,8 @@
             if (sysProperties != null) {
                 sysProperties.restoreSystem();
             }
-            if (cl != null) {
-                cl.resetThreadContextLoader();
+            if (classLoader != null) {
+                classLoader.resetThreadContextLoader();
             }
         }
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to