ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles Scokart" <>
Subject CoreLoader not used for antlib & typedef [Re: Launching unit test of antunit]
Date Wed, 19 Nov 2008 21:08:41 GMT
It took me quiet a lot of time to find the way to build antunit, so I
wanted to understand the root cause of the problem (and lost a few
hours more ;-) )

The problem actually comes from the fact the the antunit unit test
creates projects and execute build using BuildFileTest.
However, the created project are not aware of the classpath used by
the unit test.
I was thus thinking to provide this classpath using the
project.setCoreLoader.  But that didn't worked.
Indeed, the coreLoader is not used when declaring antlib.

The antunit unit tests use 2 aproach to define type : the antlib uri,
and a typedef.

Making use of the coreLoader when using the antlib seems to have minor
impact, but for the typedef declaration, I feel I should update
Project.createClassLoader, which might have a wide impact.

Here is the patch I end up :

Index: src/tests/junit/org/apache/tools/ant/
--- src/tests/junit/org/apache/tools/ant/	(revision 687833)
+++ src/tests/junit/org/apache/tools/ant/	(working copy)
@@ -282,6 +282,7 @@
         logBuffer = new StringBuffer();
         fullLogBuffer = new StringBuffer();
         project = new Project();
+        project.setCoreLoader(this.getClass().getClassLoader());
         File antFile = new File(System.getProperty("root"), filename);
         project.setUserProperty("ant.file" , antFile.getAbsolutePath());
Index: src/main/org/apache/tools/ant/
--- src/main/org/apache/tools/ant/	(revision 687833)
+++ src/main/org/apache/tools/ant/	(working copy)
@@ -831,6 +831,9 @@
+        //anlib declared by their namespace only should be searched
in the coreLoader
+        //when specified
+        definer.setAntlibClassLoader(project.getCoreLoader());
         //there to stop error messages being "null"
         //if this is left out, bad things happen. like all build files break
Index: src/main/org/apache/tools/ant/
--- src/main/org/apache/tools/ant/	(revision 687833)
+++ src/main/org/apache/tools/ant/	(working copy)
@@ -335,8 +335,11 @@
      * @return an appropriate classloader.
     public AntClassLoader createClassLoader(Path path) {
-        return new AntClassLoader(
-            getClass().getClassLoader(), this, path);
+        ClassLoader cl = getCoreLoader();
+        if (cl==null) {
+            cl = getClass().getClassLoader();
+        }
+        return new AntClassLoader(cl, this, path);

With that, antunit unit test could be executed with : ant test
I still have to run the test suite in ant itself (and seeing the time
I took to run the test in antunit I have some fears;-)
In parallel I wanted to ask feedback for such sensible change for
which I can't really mesure all the impact.

2008/11/17 Stefan Bodewig <>:
> On 2008-11-15, Gilles Scokart <> wrote:
>> The only workaround.I found is :
>> ant -lib build/classes\;build/test-classes test
> I use two -libs, but otherwise I do exactly the same.
> Stefan
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Gilles Scokart

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message