Hi,
I have a custom Ivy resolver that keeps a static cache because it is
time-consuming to initialise.
However, this cache doesn't work in a multi-project build, because the
ivysettings/classpath command is creating a new URLClassLoader for each
subant iteration, so all static class fields are reset.
<ivysettings>
<classpath file="${ivy.settings.dir}/sigil-ivy-plugin.jar" />
<typedef name="sigil" classname="org.cauldron.bld.ivy.SigilResolver" />
...
</ivysettings>
I'm building multiple projects, using ivy:buildlist and subant, as in
the Ivy multi-project example.
Each iteration of subant, causes IvySettings to reload.
IvySettings.classloader is thus null and so a new URLClassLoader is created.
I temporarily worked around this by loading my plugin at the same time
as Ivy (i.e. not using settings/classpath), but I'd really like the
setting/classpath method to work too.
One possible solution would be to add a "loaderRef" attribute to
settings/classpath, similar to the Ant taskdef/typedef tasks, to make it
use the same ClassLoader.
Alternatively, IvySettings could simply be changed to only create a new
URLClassLoader if the list of URLs has changed. I attach a simple patch
to IvySettings.java that does this and seems to work OK.
If this is valid and useful, let me know and I'll raise it in Jira.
Thanks,
Derek
Index: src/java/org/apache/ivy/core/settings/IvySettings.java
===================================================================
--- src/java/org/apache/ivy/core/settings/IvySettings.java (revision
705243)
+++ src/java/org/apache/ivy/core/settings/IvySettings.java (working copy)
@@ -644,13 +644,19 @@
}
}
+ private static Map loaderCache = new HashMap();
+
private ClassLoader getClassLoader() {
if (classloader == null) {
if (classpathURLs.isEmpty()) {
classloader = Ivy.class.getClassLoader();
} else {
- classloader = new URLClassLoader((URL[]) classpathURLs
+ classloader = (ClassLoader) loaderCache.get(classpathURLs);
+ if (classloader == null) {
+ classloader = new URLClassLoader((URL[]) classpathURLs
.toArray(new URL[classpathURLs.size()]),
Ivy.class.getClassLoader());
+ loaderCache.put(classpathURLs, classloader);
+ }
}
}
return classloader;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]