conor 01/07/17 19:29:34
Modified: src/main/org/apache/tools/ant AntClassLoader.java
src/main/org/apache/tools/ant/taskdefs ExecuteJava.java
Log:
Improve the performance of the classloader - The classloader will, however,
now have the jars open.
Revision Changes Path
1.29 +26 -25
jakarta-ant/src/main/org/apache/tools/ant/AntClassLoader.java
Index: AntClassLoader.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/AntClassLoader.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- AntClassLoader.java 2001/07/17 14:32:04 1.28
+++ AntClassLoader.java 2001/07/18 02:29:34 1.29
@@ -163,7 +163,7 @@
/**
* The size of buffers to be used in this classloader.
*/
- static private final int BUFFER_SIZE = 1024;
+ static private final int BUFFER_SIZE = 8192;
/**
* The components of the classpath that the classloader searches for
classes
@@ -205,6 +205,11 @@
private ClassLoader parent = null;
/**
+ * A hashtable of zip files opened by the classloader
+ */
+ private Hashtable zipFiles = new Hashtable();
+
+ /**
* The context loader saved when setting the thread's current context
loader.
*/
private ClassLoader savedContextLoader = null;
@@ -579,28 +584,15 @@
}
}
else {
- ZipFile zipFile = null;
- try {
+ // is the zip file in the cache
+ ZipFile zipFile = (ZipFile)zipFiles.get(file);
+ if (zipFile == null) {
zipFile = new ZipFile(file);
-
- ZipEntry entry = zipFile.getEntry(resourceName);
- if (entry != null) {
- // we need to read the entry out of the zip file into
- // a baos and then
- ByteArrayOutputStream baos = new
ByteArrayOutputStream();
- byte[] buffer = new byte[BUFFER_SIZE];
- int bytesRead;
- InputStream stream = zipFile.getInputStream(entry);
- while ((bytesRead = stream.read(buffer, 0,
BUFFER_SIZE)) != -1) {
- baos.write(buffer, 0, bytesRead);
- }
- return new ByteArrayInputStream(baos.toByteArray());
- }
+ zipFiles.put(file, zipFile);
}
- finally {
- if (zipFile != null) {
- zipFile.close();
- }
+ ZipEntry entry = zipFile.getEntry(resourceName);
+ if (entry != null) {
+ return zipFile.getInputStream(entry);
}
}
}
@@ -788,7 +780,7 @@
if (theClass != null) {
return theClass;
}
-
+
if (isParentFirst(classname)) {
try {
theClass = findBaseClass(classname);
@@ -816,7 +808,7 @@
if (resolve) {
resolveClass(theClass);
}
-
+
return theClass;
}
@@ -847,9 +839,9 @@
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int bytesRead = -1;
- byte[] buffer = new byte[1024];
+ byte[] buffer = new byte[BUFFER_SIZE];
- while ((bytesRead = stream.read(buffer, 0, 1024)) != -1) {
+ while ((bytesRead = stream.read(buffer, 0, BUFFER_SIZE)) != -1) {
baos.write(buffer, 0, bytesRead);
}
@@ -951,6 +943,15 @@
public void buildFinished(BuildEvent event) {
pathComponents = null;
project = null;
+ for (Enumeration e = zipFiles.elements(); e.hasMoreElements(); ) {
+ ZipFile zipFile = (ZipFile)e.nextElement();
+ try {
+ zipFile.close();
+ }
+ catch (IOException ioe) {
+ // ignore
+ }
+ }
}
public void targetStarted(BuildEvent event) {
1.12 +0 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
Index: ExecuteJava.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ExecuteJava.java 2001/07/17 14:19:12 1.11
+++ ExecuteJava.java 2001/07/18 02:29:34 1.12
@@ -129,7 +129,6 @@
}
final Method main = target.getMethod("main", param);
main.invoke(null, argument);
-
} catch (NullPointerException e) {
throw new BuildException("Could not find main() method in " +
classname);
} catch (ClassNotFoundException e) {