Community
Participate
Working Groups
Ant supports ProjectHelpers which can be plugged in by the user to set up projects from the source xml files. Normally Ant's default ProjectHelper will be used. If the user wants to use a custom ProjectHelper he has either to set the system property org.apache.tools.ant.ProjectHelper where the value is the fully qualified class name of the custom ProjectHelper or include a resource org.apache.tools.ant.ProjectHelper in the /META-INF/services directory of the jar containing the custom ProjectHelper (see also class sun.misc.Service). All this works perfectly with Ant's command line frontend, but can't be configured with the Ant plugin in Eclipse. (To set the system property for Ant's command line frontend the ANT_OPTS environment variable can be set.) Neither seems to be a way to specify a system property when launching the Ant runner nor seems the resource in /META-INF/services to be honoured. I guess the latter is related to class loading somehow. To my surprise it didn't even work when I set the system property by starting Eclipse with the option "-vmargs -Dorg.apache.tools.ant.ProjectHelper=...".
email to platform-ant-dev from Knut Wannheden: Browsing the Ant user manual I noticed that this feature isn't documented anywhere but in the source code ;-) The same goes for the ant.home property which is set by Ant's command line frontend and is used by the core <exec> task. This makes it a little bit unclear whether this is really a bug in the Ant plugin or not. But if any exposed behaviour differing from Ant's command line frontend is regarded as a bug, then this clearly is one. So for documentation I have to point you to the source files, where the classes org.apache.tools.ant.ProjectHelper and org.apache.tools.ant.helper.ProjectHelperImpl should capture everything about the feature.
Recently I've seen discussions on the list about using a separate thread to run the Ant builds. There is even a feature request (see bug 25062) which is targeted for the 2.1 M3 release. And as I understand it there is also a custom ClassLoader for the AntRunner to use. If this ClassLoader were set as the ContextClassLoader of the thread then I think this problem with the ProjectHelper would be fixed. Because Ant uses the ContextClassLoader of the running thread to locate the META- INF/services/org.apache.tools.ant.ProjectHelper resource, which in turn specifies the ProjectHelper. What is your opinion on this?
Note bug 25062 is currently slated for 2.1 not necessary 2.1 M3. The Eclipse ant support does have its own class loader. Thanks for the suggestion and I will definately look into it.
Moving to M5
AntRunner now sets and restores the Thread context classloader for all builds. Please verify.
Verified code.