You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Gilles Scokart <gs...@gmail.com> on 2008/11/19 22:08:41 UTC
CoreLoader not used for antlib & typedef [Re: Launching unit test of antunit]
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 <bo...@apache.org>:
> On 2008-11-15, Gilles Scokart <gs...@gmail.com> 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: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
--
Gilles Scokart
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: CoreLoader not used for antlib & typedef [Re: Launching unit test of antunit]
Posted by Gilles Scokart <gs...@gmail.com>.
2008/11/26 Stefan Bodewig <bo...@apache.org>:
> On 2008-11-26, Gilles Scokart <gs...@gmail.com> wrote:
>
>> I still have move-test.xml failing. I tried on windows XP and on
>> cygwin, with a JDK 1.6 and with 1.5. The antunit test is always
>> failing.
>
>> Did others have the problem?
>
> Never, neither on Windows/Cygwin nor on Linux.
>
> BTW, I thought you were talking about AntUnit's own test suite. To
> run Ant's AntUnit tests I simply invoke
I initially was. But I fall on the problem with this unit test while
testing the patch for the coreLoader usage.
>
> ./build.sh test
I found it,thanks. (it was easier to find ;-) )
>
> and that's it. No fiddling with -lib or anything like that.
>
>> I already had some file-system issues on my machines when deleting
>> files, (the delete of freshly created files were sometime failing,
>> being ignored or being delayed). Maybe I have the same problem
>> again...
>
> Virus-Scanner?
I already tried, I disbled all process and services I could... But the
problem was still there. This is specialy visible in ivy unit tests
that creates and deletes a lot of files. :-(
One day, I will reinstall everything...
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
--
Gilles Scokart
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: CoreLoader not used for antlib & typedef [Re: Launching unit test of antunit]
Posted by Stefan Bodewig <bo...@apache.org>.
On 2008-11-26, Gilles Scokart <gs...@gmail.com> wrote:
> I still have move-test.xml failing. I tried on windows XP and on
> cygwin, with a JDK 1.6 and with 1.5. The antunit test is always
> failing.
> Did others have the problem?
Never, neither on Windows/Cygwin nor on Linux.
BTW, I thought you were talking about AntUnit's own test suite. To
run Ant's AntUnit tests I simply invoke
./build.sh test
and that's it. No fiddling with -lib or anything like that.
> I already had some file-system issues on my machines when deleting
> files, (the delete of freshly created files were sometime failing,
> being ignored or being delayed). Maybe I have the same problem
> again...
Virus-Scanner?
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: CoreLoader not used for antlib & typedef [Re: Launching unit test of antunit]
Posted by Gilles Scokart <gs...@gmail.com>.
I still have move-test.xml failing. I tried on windows XP and on
cygwin, with a JDK 1.6 and with 1.5. The antunit test is always
failing.
Did others have the problem?
I already had some file-system issues on my machines when deleting
files, (the delete of freshly created files were sometime failing,
being ignored or being delayed). Maybe I have the same problem
again...
Gilles
2008/11/20 Gilles Scokart <gs...@gmail.com>:
> 2008/11/20 Stefan Bodewig <bo...@apache.org>:
>> On 2008-11-19, Gilles Scokart <gs...@gmail.com> wrote:
>>
>>> 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.
>>
>> Is coreLoader used at all? Anywhere?
>
>
> Yes, in a very few tasks : Which ressources and ExecuteJava (but only
> when no classpath is given)
> It is also used for the core ant tasks & types.
>
>
>>
>> There are bugzilla issues talking about making it functional.
>>
>> I don't recall the details but think the core loader is the result of
>> an unfinished experiment.
>
>
> It was what I was suspecting. There is indeed a lot of tasks that use
> Project.createClassLoader that was not considering the coreLoader.
>
>
>>
>>> In parallel I wanted to ask feedback for such sensible change for
>>> which I can't really mesure all the impact.
>>
>> Classloader changes are dangerous, in particular since our unit tests
>> don't cover many scenarios (and it would be difficult to do, you'd
>> need lots of forked junits) and Gump uses a very specific construct so
>> won't catch problems here.
>
> Oups, I was hoping Gump could help... Specialy for the different
> antlibs test suites.
>
>
>>
>> For your concrete patches I'll need more time to review before I
>> comment.
>>
>
> I can understand. Take your time.
>
>
> On my side, I managed to launch the unit test. I works at the
> exception of the antunit move-test.xml. But I guess it is related to
> cygwin (or java 1.6?). I will have a look to be sure.
>
> I have also rethink about the change. I feel that the change in
> BuildFileTest in maybe too intrusive and there is a risk of
> incompatibility, specialy if some test are testing things linked to
> classLoader. Maybe transfering the unit test classLoader into the
> project coreLoader should be optional, to reduce this risk.
>
> Also, in the componentHelper, the call
> definer.setAntlibClassLoader(project.getCoreLoader()); is useless with
> the change done in Project. I did it this change first to allow the
> automated antlib to be found, but then I realized that it still didn't
> worked for the declared typedef and I made the more impacting change
> in Project.
>
>
>
>
>
> --
> Gilles Scokart
>
--
Gilles Scokart
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: CoreLoader not used for antlib & typedef [Re: Launching unit test of antunit]
Posted by Gilles Scokart <gs...@gmail.com>.
2008/11/20 Stefan Bodewig <bo...@apache.org>:
> On 2008-11-19, Gilles Scokart <gs...@gmail.com> wrote:
>
>> 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.
>
> Is coreLoader used at all? Anywhere?
Yes, in a very few tasks : Which ressources and ExecuteJava (but only
when no classpath is given)
It is also used for the core ant tasks & types.
>
> There are bugzilla issues talking about making it functional.
>
> I don't recall the details but think the core loader is the result of
> an unfinished experiment.
It was what I was suspecting. There is indeed a lot of tasks that use
Project.createClassLoader that was not considering the coreLoader.
>
>> In parallel I wanted to ask feedback for such sensible change for
>> which I can't really mesure all the impact.
>
> Classloader changes are dangerous, in particular since our unit tests
> don't cover many scenarios (and it would be difficult to do, you'd
> need lots of forked junits) and Gump uses a very specific construct so
> won't catch problems here.
Oups, I was hoping Gump could help... Specialy for the different
antlibs test suites.
>
> For your concrete patches I'll need more time to review before I
> comment.
>
I can understand. Take your time.
On my side, I managed to launch the unit test. I works at the
exception of the antunit move-test.xml. But I guess it is related to
cygwin (or java 1.6?). I will have a look to be sure.
I have also rethink about the change. I feel that the change in
BuildFileTest in maybe too intrusive and there is a risk of
incompatibility, specialy if some test are testing things linked to
classLoader. Maybe transfering the unit test classLoader into the
project coreLoader should be optional, to reduce this risk.
Also, in the componentHelper, the call
definer.setAntlibClassLoader(project.getCoreLoader()); is useless with
the change done in Project. I did it this change first to allow the
automated antlib to be found, but then I realized that it still didn't
worked for the declared typedef and I made the more impacting change
in Project.
--
Gilles Scokart
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: CoreLoader not used for antlib & typedef [Re: Launching unit test of antunit]
Posted by Stefan Bodewig <bo...@apache.org>.
On 2008-11-19, Gilles Scokart <gs...@gmail.com> wrote:
> 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.
Is coreLoader used at all? Anywhere?
There are bugzilla issues talking about making it functional.
I don't recall the details but think the core loader is the result of
an unfinished experiment.
> In parallel I wanted to ask feedback for such sensible change for
> which I can't really mesure all the impact.
Classloader changes are dangerous, in particular since our unit tests
don't cover many scenarios (and it would be difficult to do, you'd
need lots of forked junits) and Gump uses a very specific construct so
won't catch problems here.
For your concrete patches I'll need more time to review before I
comment.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org