Return-Path: Delivered-To: apmail-ant-user-archive@www.apache.org Received: (qmail 38077 invoked from network); 10 May 2007 04:13:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 May 2007 04:13:03 -0000 Received: (qmail 43795 invoked by uid 500); 10 May 2007 04:13:08 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 42912 invoked by uid 500); 10 May 2007 04:13:05 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 50045 invoked by uid 99); 9 May 2007 15:21:23 -0000 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of anfernee.xu@gmail.com designates 66.249.90.178 as permitted sender) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; b=QxcmqIzRLoXH/G89fqT1CjT3k3Jngs7nteFtrfg14MVV6rEsvE9OYiBq2XCGYKrAZkW6dZl0TDbEsUnREGWOPaXLh5kHRAyAeWxumx5/Hnnob8/ZqEf9g1nQ3OMpz/hwHDpgruBT2jQ/avOq/3nWHVBMLxVROFsr3WmrWq0lDdA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=PV/NOcsmtJWWpiD73QLs1of1c8J+jO/fvndYp2W7PO1ddcDA1BCfuCtdkF+AideMPg67KRhvDwvQETQeoIvsert+W01qAhKkpy5qmhFZ+eeRIu9H8HBixCP4hVuyukGzmErk8qU/+7VyuqVSvQ/UCsmOyVJr5X/N1ffCALngYmU= Message-ID: <71e105540705090820g7a87fdfdnc685843277cdc2e2@mail.gmail.com> Date: Wed, 9 May 2007 23:20:54 +0800 From: "Xu Xin" To: user@ant.apache.org Subject: The AntClassLoader created in one JUnitTask can not be used in another. MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_22626_32527530.1178724054763" X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_22626_32527530.1178724054763 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello everyone, I had a problem with JUnitTask, I have a couple of xml files where I also have a lot of targets which contain tasks, originally I used the Apache Ant's JUnitTask, but unfortunately the test run had performance issue, that was caused by each has its own classloader, as a result some static memory was created multiple times. So I customized the JUnitTask by making the classloader created for each test cacheable, the task has the same customer classpath elements share the same classloader, so I can save the memory as I can, but the strange thing is junit testcase was not recognized, it seemed a classloading issue, but after I ran the tests in DEBUG mode, I can find the classloader hierarchy is correct, I do not know what's going wrong. The snippet code is below: private void createClassLoader() { Path userClasspath = getCommandline().getClasspath(); if (userClasspath != null) { //get cached classloader from the pool if it exists classLoader = getCachedClassLoader(userClasspath); Path classpath = (Path) userClasspath.clone(); if (includeAntRuntime) { log("Implicitly adding " + antRuntimeClasses + " to CLASSPATH", Project.MSG_VERBOSE); classpath.append(antRuntimeClasses); } if (reloading || classLoader == null) { //create a new one if no cached classLoader = getProject().createClassLoader(classpath); if (getClass().getClassLoader() != null && getClass().getClassLoader() != Project.class.getClassLoader()) { classLoader.setParent(getClass().getClassLoader()); } classLoader.setParentFirst(false); classLoader.addJavaLibraries(); // make sure the test will be accepted as a TestCase classLoader.addSystemPackageRoot("junit"); // will cause trouble in JDK 1.1 if omitted classLoader.addSystemPackageRoot("org.apache.tools.ant"); // testlogic: this fixes 'not a JUnitResultFormatter' issue classLoader.addSystemPackageRoot("org.testlogic.testrunner.ant.junit "); cacheClassLoader(userClasspath, classLoader); } else { //this is the cached one if (classLoader != null) { classLoader.setProject(this.getProject()); classLoader.setClassPath(classpath); if (getClass().getClassLoader() != null && getClass().getClassLoader() != Project.class.getClassLoader()) { classLoader.setParent(getClass().getClassLoader()); } } } } } and next pass the classLoader to JUnitTestRunner as usual, the test class can be loaded, as well as JUnit class: TestSuite and Test, but when constructing TestCase, TestSuite complains the test class is not implementation of Test, but I can see the test class was loaded by cached AntClassLoader, and TestSuite and Test were loaded by its parent classloader. So could you guys please tell me what's wrong? Thanks -- anfernee ------=_Part_22626_32527530.1178724054763--