ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Reilly" <>
Subject Re: classloader for 1.7
Date Wed, 30 Aug 2006 15:49:31 GMT
On 8/30/06, Jesse Glick <> wrote:
> Peter Reilly wrote:
> > So what would be the hier for the secondary class loader?
> > if it is bootstrap->ext->system->project->secondary,
> Yes.
> > it would meant that the classes in project would not be able to see the
> > secondary classes.
> Correct. Why is this a problem? Ant core classes should not be referring
> to tasks and such stuff.

It is not much of a problem ---;)

I have done a prototype and the results look good:

1) a new ComponentClassLoader which is a AntClassLoader, except that
   a) it loads up with the classpath from Project.class.getClassLoader() and
uses the paths
       from there to as its paths.
   b) it intercepts classes with "optional" or "ScriptRunner" in the name
and loads these from
       itself rather than from the parent classloader.
  both of these changes are to allow ant's optional classes to be loaded for
the component
  class loader rather than from Project.class.getClassLoader()
  c) set the parent classloader to Project.class.getClassLoader()

2) modify
   a) create a component classloader if is not created as a sub-project
   b) use this as a parent when Project.createClassLoader () is called
   c) set the component classloader of sub-projects
   d) provide a public accessor for the component classloader

3) modify ComponentHelper
   a) use componentClassLoader when loading in tasks and types.

4) provide a task to add paths to the componentClassLoader

The end result looks like this:
<project name="depend" default="depend"
    <target name="depend">

        <!-- test for ant optional task - jdepend -->
            <fileset dir="c:/apps/jdepend-2.9.1/lib"/>

            <classespath path="build/classes"/>

        <!-- test for ant lib -->
            <fileset dir="${user.home}/p" includes="ant-con*.jar"/>

        <ac:for param="param" list="a,b,c">

        <!-- test for script -->
            <fileset dir="${user.home}/lang/bsf" includes="*.jar"/>
            <fileset dir="${user.home}/lang/beanshell" includes="*.jar"/>

        <script language="beanshell">
            System.out.println("Hello world");

A couple of notes:
   1) mixing using the append component loader with the .ant/lib ant
       extensions may cause projects if the classes in .ant/lib load classes
in the append component
       - so in the above example bsf.jar needs to be loaded with the
beanshell.jar file, otherwise
       it will not see the beanshell classes. This can be avoided by:
         a) adding more strings to intercept (fragile)
         b) getting AntLauncher to set the component class loader (ant.jar +
xml jars in project loader and the
            other jars in the component loader) : This would not be
supported by the IDEs.
         c) using revert lookup for classes, except Project, Task etc..
(very fragile)

  2) the code is a bit like the coreloader code, but I do not use that
       a) I could not get it to work
       b) a public method is provided to set the coreloader.


View raw message