|
|
@@ -44,7 +44,7 @@ import org.apache.tools.ant.util.LoaderUtils; |
|
|
|
* class will then use this loader rather than the system class loader. |
|
|
|
* |
|
|
|
*/ |
|
|
|
public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
public class AntClassLoader extends ClassLoader implements SubBuildListener { |
|
|
|
|
|
|
|
private static final FileUtils fileUtils = FileUtils.newFileUtils(); |
|
|
|
|
|
|
@@ -118,7 +118,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
private void findNextResource() { |
|
|
|
URL url = null; |
|
|
|
while ((pathElementsIndex < pathComponents.size()) |
|
|
|
&& (url == null)) { |
|
|
|
&& (url == null)) { |
|
|
|
try { |
|
|
|
File pathComponent |
|
|
|
= (File) pathComponents.elementAt(pathElementsIndex); |
|
|
@@ -222,7 +222,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
Class protectionDomain |
|
|
|
= Class.forName("java.security.ProtectionDomain"); |
|
|
|
Class[] args = new Class[] {String.class, byte[].class, |
|
|
|
Integer.TYPE, Integer.TYPE, protectionDomain}; |
|
|
|
Integer.TYPE, Integer.TYPE, protectionDomain}; |
|
|
|
defineClassProtectionDomain |
|
|
|
= ClassLoader.class.getDeclaredMethod("defineClass", args); |
|
|
|
} catch (Exception e) { |
|
|
@@ -392,9 +392,9 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
if (project != null) { |
|
|
|
project.log(message, priority); |
|
|
|
} |
|
|
|
// else { |
|
|
|
// System.out.println(message); |
|
|
|
// } |
|
|
|
// else { |
|
|
|
// System.out.println(message); |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -442,7 +442,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
public void addPathElement(String pathElement) throws BuildException { |
|
|
|
File pathComponent |
|
|
|
= project != null ? project.resolveFile(pathElement) |
|
|
|
: new File(pathElement); |
|
|
|
: new File(pathElement); |
|
|
|
try { |
|
|
|
addPathFile(pathComponent); |
|
|
|
} catch (IOException e) { |
|
|
@@ -582,7 +582,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
* on this loader's classpath. |
|
|
|
*/ |
|
|
|
public Class forceLoadClass(String classname) |
|
|
|
throws ClassNotFoundException { |
|
|
|
throws ClassNotFoundException { |
|
|
|
log("force loading " + classname, Project.MSG_DEBUG); |
|
|
|
|
|
|
|
Class theClass = findLoadedClass(classname); |
|
|
@@ -611,7 +611,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
* on this loader's classpath. |
|
|
|
*/ |
|
|
|
public Class forceLoadSystemClass(String classname) |
|
|
|
throws ClassNotFoundException { |
|
|
|
throws ClassNotFoundException { |
|
|
|
log("force system loading " + classname, Project.MSG_DEBUG); |
|
|
|
|
|
|
|
Class theClass = findLoadedClass(classname); |
|
|
@@ -815,7 +815,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
URL url = null; |
|
|
|
if (isParentFirst(name)) { |
|
|
|
url = (parent == null) ? super.getResource(name) |
|
|
|
: parent.getResource(name); |
|
|
|
: parent.getResource(name); |
|
|
|
} |
|
|
|
|
|
|
|
if (url != null) { |
|
|
@@ -907,7 +907,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
if (entry != null) { |
|
|
|
try { |
|
|
|
return new URL("jar:" + fileUtils.getFileURL(file) |
|
|
|
+ "!/" + entry); |
|
|
|
+ "!/" + entry); |
|
|
|
} catch (MalformedURLException ex) { |
|
|
|
return null; |
|
|
|
} |
|
|
@@ -941,7 +941,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
* classpath. |
|
|
|
*/ |
|
|
|
protected synchronized Class loadClass(String classname, boolean resolve) |
|
|
|
throws ClassNotFoundException { |
|
|
|
throws ClassNotFoundException { |
|
|
|
// 'sync' is needed - otherwise 2 threads can load the same class |
|
|
|
// twice, resulting in LinkageError: duplicated class definition. |
|
|
|
// findLoadedClass avoids that, but without sync it won't work. |
|
|
@@ -1059,8 +1059,8 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
* reading the class from the stream. |
|
|
|
*/ |
|
|
|
private Class getClassFromStream(InputStream stream, String classname, |
|
|
|
File container) |
|
|
|
throws IOException, SecurityException { |
|
|
|
File container) |
|
|
|
throws IOException, SecurityException { |
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
|
|
int bytesRead = -1; |
|
|
|
byte[] buffer = new byte[BUFFER_SIZE]; |
|
|
@@ -1120,7 +1120,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
* on this loader's classpath. |
|
|
|
*/ |
|
|
|
private Class findClassInComponents(String name) |
|
|
|
throws ClassNotFoundException { |
|
|
|
throws ClassNotFoundException { |
|
|
|
// we need to search the components of the path to see if |
|
|
|
// we can find the class we want. |
|
|
|
InputStream stream = null; |
|
|
@@ -1219,6 +1219,31 @@ public class AntClassLoader extends ClassLoader implements BuildListener { |
|
|
|
cleanup(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Cleans up any resources held by this classloader at the end of |
|
|
|
* a subbuild if it has been created for the subbuild's project |
|
|
|
* instance. |
|
|
|
* |
|
|
|
* @param event the buildFinished event |
|
|
|
* |
|
|
|
* @since Ant 1.6.2 |
|
|
|
*/ |
|
|
|
public void subBuildFinished(BuildEvent event) { |
|
|
|
if (event.getProject() == project) { |
|
|
|
cleanup(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Empty implementation to satisfy the BuildListener interface. |
|
|
|
* |
|
|
|
* @param event the buildStarted event |
|
|
|
* |
|
|
|
* @since Ant 1.6.2 |
|
|
|
*/ |
|
|
|
public void subBuildStarted(BuildEvent event) { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Empty implementation to satisfy the BuildListener interface. |
|
|
|
* |
|
|
|