Antoine Lévy-Lambert wrote:
I am +1 to get this into ant 1.6.1.
(in relation to static map of jarfile->manifest class path in AntClassLoader2).
Ok I will commit that.
Another optimization I tried was a quick hack to DefBase to have a static field containing the default classloader, so it
gets set once. This did speed up the typedef the second and subsequent times and reduced the
time for the test to 1.6 second (from 3 and thus below the 1.5.4 times (2 second) when using the crimson xml parser).
However it is a complete hack, and does not deal with non-default classpaths like:
<typedef classpath="${antlib.jar}" resource="net/sf/antcontrib/antcontrib.properties"/>
Note that the problem is not so bad for the antlib: xml ns shortcut.
<project xmlns:ac="antlib:net.sf.antcontrib">
<target name="compile-mains">
<ac:foreach list="a,b,c,d,e,f,g,h,i" param="program" target="compile"/>
</target>
<target name="compile">
..
</target>
</project>
This will in ant 1.6.1 cause only one typedef of the ant-contrib tasks. (There
is a bug in 1.6.0 which causes the tasks to be loaded for each ant-call, this
is fixed in cvs).
Peter
Index: src/main/org/apache/tools/ant/taskdefs/DefBase.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/DefBase.java,v retrieving revision 1.6 diff -u -r1.6 DefBase.java --- src/main/org/apache/tools/ant/taskdefs/DefBase.java 22 Sep 2003 08:58:58 -0000 1.6 +++ src/main/org/apache/tools/ant/taskdefs/DefBase.java 16 Jan 2004 15:06:36 -0000 @@ -83,7 +83,7 @@ * @ant.attribute ignore="true" */ public void setReverseLoader(boolean reverseLoader) { - this.cpDelegate.setReverseLoader(reverseLoader); + getDelegate().setReverseLoader(reverseLoader); log("The reverseloader attribute is DEPRECATED. It will be removed", Project.MSG_WARN); } @@ -92,14 +92,14 @@ * @return the classpath for this definition */ public Path getClasspath() { - return cpDelegate.getClasspath(); + return getDelegate().getClasspath(); } /** * @return the reverse loader attribute of the classpath delegate. */ public boolean isReverseLoader() { - return cpDelegate.isReverseLoader(); + return getDelegate().isReverseLoader(); } /** @@ -107,7 +107,7 @@ * @return the loader id */ public String getLoaderId() { - return cpDelegate.getClassLoadId(); + return getDelegate().getClassLoadId(); } /** @@ -115,7 +115,7 @@ * @return the class path id */ public String getClasspathId() { - return cpDelegate.getClassLoadId(); + return getDelegate().getClassLoadId(); } /** @@ -124,7 +124,7 @@ * @param classpath an Ant Path object containing the classpath. */ public void setClasspath(Path classpath) { - this.cpDelegate.setClasspath(classpath); + getDelegate().setClasspath(classpath); } /** @@ -133,7 +133,7 @@ * @return the classpath of the this definition */ public Path createClasspath() { - return this.cpDelegate.createClasspath(); + return getDelegate().createClasspath(); } /** @@ -142,7 +142,7 @@ * @param r the reference to the classpath */ public void setClasspathRef(Reference r) { - this.cpDelegate.setClasspathref(r); + getDelegate().setClasspathref(r); } /** @@ -158,9 +158,11 @@ * @since Ant 1.5 */ public void setLoaderRef(Reference r) { - this.cpDelegate.setLoaderRef(r); + getDelegate().setLoaderRef(r); } + private static ClassLoader defaultLoader; + /** * create a classloader for this definition * @return the classloader from the cpDelegate @@ -169,6 +171,13 @@ if (getAntlibClassLoader() != null) { return getAntlibClassLoader(); } + if (cpDelegate == null) { + if (defaultLoader == null) { + cpDelegate = ClasspathUtils.getDelegate(this); + defaultLoader = cpDelegate.getClassLoader(); + } + return defaultLoader; + } if (createdLoader == null) { createdLoader = this.cpDelegate.getClassLoader(); // need to load Task via system classloader or the new @@ -185,9 +194,13 @@ * @since Ant 1.6 */ public void init() throws BuildException { - this.cpDelegate = ClasspathUtils.getDelegate(this); super.init(); } - + private ClasspathUtils.Delegate getDelegate() { + if (cpDelegate == null) { + cpDelegate = ClasspathUtils.getDelegate(this); + } + return cpDelegate; + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]