Browse Source

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
master
Jacobus Martinus Kruithof 18 years ago
parent
commit
758a6bcb93
3 changed files with 33 additions and 29 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +3
    -0
      WHATSNEW
  3. +29
    -29
      src/main/org/apache/tools/ant/AntClassLoader.java

+ 1
- 0
CONTRIBUTORS View File

@@ -262,6 +262,7 @@ Tim Fennell
Timothy Gerard Endres Timothy Gerard Endres
Tim Stephenson Tim Stephenson
Tom Ball Tom Ball
Tom Brus
Tom Cunningham Tom Cunningham
Tom Dimock Tom Dimock
Tom Eugelink Tom Eugelink


+ 3
- 0
WHATSNEW View File

@@ -11,6 +11,9 @@ Changes that could break older environments:


Fixed bugs: Fixed bugs:
----------- -----------
* Improvements in AntClassLoader Speed.
Bugzilla report 42259

* Error in handling of some permissions, most notably the AllPermission on * Error in handling of some permissions, most notably the AllPermission on
jdk 1.5 jdk 1.5
Bugzilla report 41776 Bugzilla report 41776


+ 29
- 29
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -812,22 +812,22 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*/ */
private InputStream getResourceStream(File file, String resourceName) { private InputStream getResourceStream(File file, String resourceName) {
try { 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); File resource = new File(file, resourceName);


if (resource.exists()) { if (resource.exists()) {
return new FileInputStream(resource); return new FileInputStream(resource);
} }
} else { } else {
// is the zip file in the cache
ZipFile zipFile = (ZipFile) zipFiles.get(file);
if (zipFile == null) { 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 //to eliminate a race condition, retrieve the entry
//that is in the hash table under that filename //that is in the hash table under that filename
zipFile = (ZipFile) zipFiles.get(file); zipFile = (ZipFile) zipFiles.get(file);
@@ -838,23 +838,24 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
} }
} }
} catch (Exception e) { } 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; 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 <code>null</code>.
*
* 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
* <code>null</code>.
*
* @return whether or not the parent classloader should be checked for a * @return whether or not the parent classloader should be checked for a
* resource before this one is. * resource before this one is.
*/ */
@@ -1010,11 +1011,8 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*/ */
protected URL getResourceURL(File file, String resourceName) { protected URL getResourceURL(File file, String resourceName) {
try { 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); File resource = new File(file, resourceName);


if (resource.exists()) { if (resource.exists()) {
@@ -1025,12 +1023,14 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
} }
} }
} else { } else {
ZipFile zipFile = (ZipFile) zipFiles.get(file);
if (zipFile == null) { 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); ZipEntry entry = zipFile.getEntry(resourceName);
if (entry != null) { if (entry != null) {
try { try {


Loading…
Cancel
Save