From 758a6bcb93484d657bdd50c688c023a59d153476 Mon Sep 17 00:00:00 2001 From: Jacobus Martinus Kruithof Date: Sun, 29 Apr 2007 13:00:17 +0000 Subject: [PATCH] Pr: 42259 inspired on optimization suggested by Tom Brus git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@533498 13f79535-47bb-0310-9956-ffa450edef68 --- CONTRIBUTORS | 1 + WHATSNEW | 3 + .../org/apache/tools/ant/AntClassLoader.java | 58 +++++++++---------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 07c1e6c0f..b52a8dcbb 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -262,6 +262,7 @@ Tim Fennell Timothy Gerard Endres Tim Stephenson Tom Ball +Tom Brus Tom Cunningham Tom Dimock Tom Eugelink diff --git a/WHATSNEW b/WHATSNEW index 36bbaa9d1..a65a90a59 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -11,6 +11,9 @@ Changes that could break older environments: Fixed bugs: ----------- +* Improvements in AntClassLoader Speed. + Bugzilla report 42259 + * Error in handling of some permissions, most notably the AllPermission on jdk 1.5 Bugzilla report 41776 diff --git a/src/main/org/apache/tools/ant/AntClassLoader.java b/src/main/org/apache/tools/ant/AntClassLoader.java index 90462240a..71f60a6b3 100644 --- a/src/main/org/apache/tools/ant/AntClassLoader.java +++ b/src/main/org/apache/tools/ant/AntClassLoader.java @@ -812,22 +812,22 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { */ private InputStream getResourceStream(File file, String resourceName) { try { - if (!file.exists()) { - return null; - } - - if (file.isDirectory()) { + ZipFile zipFile = (ZipFile) zipFiles.get(file); + if (zipFile == null && file.isDirectory()) { File resource = new File(file, resourceName); if (resource.exists()) { return new FileInputStream(resource); } } else { - // is the zip file in the cache - ZipFile zipFile = (ZipFile) zipFiles.get(file); if (zipFile == null) { - zipFile = new ZipFile(file); - zipFiles.put(file, zipFile); + if (file.exists()) { + + zipFile = new ZipFile(file); + zipFiles.put(file, zipFile); + } else { + return null; + } //to eliminate a race condition, retrieve the entry //that is in the hash table under that filename zipFile = (ZipFile) zipFiles.get(file); @@ -838,23 +838,24 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { } } } catch (Exception e) { - log("Ignoring Exception " + e.getClass().getName() - + ": " + e.getMessage() + " reading resource " + resourceName - + " from " + file, Project.MSG_VERBOSE); + log("Ignoring Exception " + e.getClass().getName() + ": " + + e.getMessage() + " reading resource " + resourceName + + " from " + file, Project.MSG_VERBOSE); } return null; } /** - * Tests whether or not the parent classloader should be checked for - * a resource before this one. If the resource matches both the - * "use parent classloader first" and the "use this classloader first" - * lists, the latter takes priority. - * - * @param resourceName The name of the resource to check. - * Must not be null. - * + * Tests whether or not the parent classloader should be checked for a + * resource before this one. If the resource matches both the "use parent + * classloader first" and the "use this classloader first" lists, the latter + * takes priority. + * + * @param resourceName + * The name of the resource to check. Must not be + * null. + * * @return whether or not the parent classloader should be checked for a * resource before this one is. */ @@ -1010,11 +1011,8 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { */ protected URL getResourceURL(File file, String resourceName) { try { - if (!file.exists()) { - return null; - } - - if (file.isDirectory()) { + ZipFile zipFile = (ZipFile) zipFiles.get(file); + if (zipFile == null && file.isDirectory()) { File resource = new File(file, resourceName); if (resource.exists()) { @@ -1025,12 +1023,14 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { } } } else { - ZipFile zipFile = (ZipFile) zipFiles.get(file); if (zipFile == null) { - zipFile = new ZipFile(file); - zipFiles.put(file, zipFile); + if (file.exists()) { + zipFile = new ZipFile(file); + zipFiles.put(file, zipFile); + } else { + return null; + } } - ZipEntry entry = zipFile.getEntry(resourceName); if (entry != null) { try {