ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Reilly" <peter.kitt.rei...@gmail.com>
Subject Re: classloader for 1.7
Date Wed, 30 Aug 2006 15:49:31 GMT
On 8/30/06, Jesse Glick <jesse.glick@sun.com> 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 ---;)

Ok,
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 Project.java
   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"
    xmlns:ac="antlib:net.sf.antcontrib">
    <target name="depend">

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

        <jdepend>
            <classespath path="build/classes"/>
        </jdepend>

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

        <ac:for param="param" list="a,b,c">
            <sequential>
              <echo>@{param}</echo>
            </sequential>
        </ac:for>

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

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

A couple of notes:
   1) mixing using the append component loader with the .ant/lib ant
$ANT_HOME/lib
       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
because
       a) I could not get it to work
       b) a public method is provided to set the coreloader.

Peter

Mime
View raw message