Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 41228 invoked from network); 16 Oct 2008 14:51:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Oct 2008 14:51:54 -0000 Received: (qmail 77103 invoked by uid 500); 16 Oct 2008 14:51:54 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 77049 invoked by uid 500); 16 Oct 2008 14:51:54 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 77038 invoked by uid 99); 16 Oct 2008 14:51:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Oct 2008 07:51:54 -0700 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [64.233.182.187] (HELO nf-out-0910.google.com) (64.233.182.187) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Oct 2008 14:50:46 +0000 Received: by nf-out-0910.google.com with SMTP id g13so16502nfb.10 for ; Thu, 16 Oct 2008 07:51:12 -0700 (PDT) Received: by 10.210.78.16 with SMTP id a16mr2966165ebb.166.1224168672452; Thu, 16 Oct 2008 07:51:12 -0700 (PDT) Received: from ?192.168.2.23? ([78.149.159.19]) by mx.google.com with ESMTPS id g9sm3899348gvc.0.2008.10.16.07.51.10 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 16 Oct 2008 07:51:11 -0700 (PDT) Message-ID: <48F754DC.10901@paremus.com> Date: Thu, 16 Oct 2008 15:51:08 +0100 From: Derek Baum User-Agent: Thunderbird 2.0.0.17 (Macintosh/20080914) MIME-Version: 1.0 To: Ant Developers List Subject: ivy settings classpath always creates new classloader when used with subant References: <896359.41999.qm@web30806.mail.mud.yahoo.com> <635a05060810160329je2b82d2x8b43dae1528403c3@mail.gmail.com> In-Reply-To: <635a05060810160329je2b82d2x8b43dae1528403c3@mail.gmail.com> Content-Type: multipart/mixed; boundary="------------020100020609020908000209" X-Virus-Checked: Checked by ClamAV on apache.org --------------020100020609020908000209 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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. ... 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 --------------020100020609020908000209 Content-Type: text/plain; name="classpath-cache-patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="classpath-cache-patch.txt" 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; --------------020100020609020908000209 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org --------------020100020609020908000209--