List Info

Thread: classloader for 1.7




classloader for 1.7
user name
2006-08-30 15:49:31



On 8/30/06, Jesse Glick <sun.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">jesse.glicksun.com &gt; wrote:
Peter Reilly wrote:
>; So what would be the hier for the secondary class loader?
&gt; if it is bootstrap->ext->;system->;project-&gt;secondary,

Yes.

&gt; 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
&nbsp; &nbsp; &nbsp;  from there to as its paths.
&nbsp;  b) it intercepts classes with "optional" or "ScriptRunner&quot; in the name and loads these from
 &nbsp; &nbsp;   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
 &nbsp; a) create a component classloader if is not created as a sub-project
 &nbsp; b) use this as a parent when Project.createClassLoader () is called
&nbsp;  c) set the component classloader of sub-projects
 &nbsp; 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&quot; default=&quot;depend&quot;
 ; &nbsp; xmlns:ac=&quot;antlib:net.sf.antcontrib&quot;>
&nbsp; &nbsp; <target name=";depend&quot;>
&nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp;  <!-- test for ant optional task - jdepend -->
&nbsp; &nbsp; &nbsp;   <appendcomponentpath>
&nbsp; &nbsp; &nbsp; &nbsp;   ;  <fileset dir="c:/apps/jdepend-2.9.1/lib"/&gt;
   ; &nbsp; &nbsp; </appendcomponentpath>
&nbsp; &nbsp; &nbsp;  
 &nbsp; &nbsp; &nbsp;  <jdepend>
 ; &nbsp; &nbsp; &nbsp; &nbsp;   <classespath path=";build/classes"/&gt;
 &nbsp;   ; &nbsp; </jdepend>
&nbsp; &nbsp; &nbsp; &nbsp;   
 &nbsp; &nbsp; &nbsp;  <!-- test for ant lib -->
&nbsp; &nbsp;   ;  <appendcomponentpath>
&nbsp; &nbsp; &nbsp; &nbsp;   ;  <fileset dir="${user.home}/p" includes=&quot;ant-con*.jar";/>
&nbsp; &nbsp; &nbsp; &nbsp; </appendcomponentpath>

&nbsp; &nbsp;   ;  <ac:for param=&quot;param&quot; list=";a,b,c";>
&nbsp; &nbsp; &nbsp; &nbsp;   ;  <sequential>
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;  <echo&gt;<;/echo>
  ; &nbsp; &nbsp; &nbsp; &nbsp;  </sequential>
&nbsp;   ; &nbsp;  </ac:for>
 ; &nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp;  <!-- test for script -->
&nbsp; &nbsp; &nbsp;   <appendcomponentpath>
&nbsp; &nbsp; &nbsp;   ; &nbsp;  <fileset dir="${user.home}/lang/bsf&quot; includes=&quot;*.jar&quot;/>
  ; &nbsp; &nbsp; &nbsp; &nbsp;  <fileset dir="${user.home}/lang/beanshell" includes=&quot;*.jar&quot;/>
  ; &nbsp; &nbsp;  </appendcomponentpath>

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

A couple of notes:
&nbsp;  1) mixing using the append component loader with the .ant/lib ant $ANT_HOME/lib
 &nbsp;   ;  extensions may cause projects if the classes in .ant/lib load classes in the append component
  ; &nbsp; &nbsp; - so in the above example bsf.jar needs to be loaded with the beanshell.jar file, otherwise
  ; &nbsp; &nbsp; it will not see the beanshell classes. This can be avoided by:
   ; &nbsp; &nbsp;  a) adding more strings to intercept (fragile)
  ; &nbsp; &nbsp; &nbsp; b) getting AntLauncher to set the component class loader ( ant.jar + xml jars in project loader and the
   ; &nbsp; &nbsp; &nbsp; &nbsp; other jars in the component loader) : This would not be supported by the IDEs.
&nbsp; &nbsp; &nbsp; &nbsp;  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
&nbsp; &nbsp;   ; a) I could not get it to work
 ; &nbsp; &nbsp;  b) a public method is provided to set the coreloader.

Peter



classloader for 1.7
user name
2006-08-31 19:15:59
Peter Reilly wrote:
> I have done a prototype and the results look good:

Does indeed look safer to me.

> b) it intercepts classes with "optional" or
"ScriptRunner" in the 
> name and loads these from itself rather than from the
parent
> classloader.

Note that you could exclude all of .taskdefs.** if we just
cleaned up 
Ant a bit so that core classes do not refer to any taskdefs.
Such a 
cleanup could also be enforced using Lattix or a similar
tool, or by 
rearranging Ant sources a bit so that class loader
separation is 
mirrored in the physical structure of the project. Of course
this kind 
of cleanup could be done at any time.

>         <appendcomponentpath>

Workable if a bit verbose. Not sure "component"
is very intuitive. Want 
to emphasize analogy to -lib cmdline option.

>         <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>

Cool.

>          a) adding more strings to intercept (fragile)

Alternately, use a positive rather than a negative pattern.
More 
specifically: enumerate all packages/classes which should be
loaded by 
the core loader, e.g. the transitive closure of Project plus
perhaps a 
few things. For all other classes, the component loader
should use the 
same classpath entries as the core loader but not delegate.
That would 
mean that the component loader would be used for

- all standard tasks
- all types (incl. filters, conditions, etc.)
- all standard optional tasks and types
- anything else given in -lib or ${ant.home}/lib etc.
- anything else specified in <appendcomponentpath>

This would prevent the problem you mention with -lib bsf.jar
+ 
<acp>beanshell.jar</acp>, since bsf.jar,
beanshell.jar, and 
ant-apache-bsf.jar would all be loaded in the component
loader.

Such a separation could also be done on a JAR basis, i.e.
check the code 
source (ProtectionDomain/CodeSource) of each class and only
use the core 
loader for ant.jar, ant-launcher.jar, and (perhaps) the
bundled XML 
JARs. Optionally, also split ant.jar into ant-core.jar + 
ant-standard-tasks.jar.

-J.

-- 
jesse.glicksun.com  x22801  netbeans.org  ant.apache.org
       http://
google.com/search?q=e%5E%28pi*i%29%2B1


------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeant.apache.org
For additional commands, e-mail: dev-helpant.apache.org

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )