ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles Scokart" <gscok...@gmail.com>
Subject Re: ivy settings classpath always creates new classloader when used with subant
Date Fri, 17 Oct 2008 07:03:17 GMT
There will be a prerequisite for that to work : You must be sure that
that ivy itself is not loaded in two ClassLoader.  For that, your
taskdef for ivy should itself use a loaderRef, and the subant must
have the right options that make the id shared accross the projects.

And if that prerequisite is valid, in most case you can arrange your
buildscript in order to have the ivysettings defined only once.



2008/10/16 Derek Baum <derek.baum@paremus.com>:
> 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: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>



-- 
Gilles Scokart

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message