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/BuildFileTest.java
===================================================================
--- src/tests/junit/org/apache/tools/ant/BuildFileTest.java     (revision 
687833)
+++ src/tests/junit/org/apache/tools/ant/BuildFileTest.java     (working copy)
@@ -282,6 +282,7 @@
         logBuffer = new StringBuffer();
         fullLogBuffer = new StringBuffer();
         project = new Project();
+        project.setCoreLoader(this.getClass().getClassLoader());
         project.init();
         File antFile = new File(System.getProperty("root"), filename);
         project.setUserProperty("ant.file" , antFile.getAbsolutePath());
Index: src/main/org/apache/tools/ant/ComponentHelper.java
===================================================================
--- src/main/org/apache/tools/ant/ComponentHelper.java  (revision 687833)
+++ src/main/org/apache/tools/ant/ComponentHelper.java  (working copy)
@@ -831,6 +831,9 @@
         definer.setProject(project);
         definer.init();
         definer.setURI(uri);
+        //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"
         definer.setTaskName(uri);
         //if this is left out, bad things happen. like all build files break
Index: src/main/org/apache/tools/ant/Project.java
===================================================================
--- src/main/org/apache/tools/ant/Project.java  (revision 687833)
+++ src/main/org/apache/tools/ant/Project.java  (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 <[EMAIL PROTECTED]>:
> On 2008-11-15, Gilles Scokart <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
Gilles Scokart

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

Reply via email to