提交 2f50f495 编写于 作者: K kohsuke

Merge commit 'huybrechts/lib-endorsed'

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@26998 71c3de6d-444a-0410-be80-ed276b4c234a
......@@ -53,6 +53,9 @@ import java.util.HashSet;
* @author Kohsuke Kawaguchi
*/
final class RemoteClassLoader extends URLClassLoader {
private static final boolean USE_SYSTEM_CLASSLOADER = Boolean.getBoolean(RemoteClassLoader.class.getName() + ".useSystemClassLoader");
/**
* Proxy to the code running on remote end.
*/
......@@ -363,6 +366,8 @@ final class RemoteClassLoader extends URLClassLoader {
final Channel channel;
public ClassLoaderProxy(ClassLoader cl, Channel channel) {
assert cl != null;
this.cl = cl;
this.channel = channel;
}
......@@ -372,6 +377,10 @@ final class RemoteClassLoader extends URLClassLoader {
}
public byte[] fetch(String className) throws ClassNotFoundException {
if (!USE_SYSTEM_CLASSLOADER && cl.equals(ClassLoader.getSystemClassLoader())) {
throw new ClassNotFoundException("Classloading from system classloader disabled");
}
InputStream in = cl.getResourceAsStream(className.replace('.', '/') + ".class");
if(in==null)
throw new ClassNotFoundException(className);
......@@ -385,7 +394,14 @@ final class RemoteClassLoader extends URLClassLoader {
public ClassFile fetch2(String className) throws ClassNotFoundException {
ClassLoader ecl = cl.loadClass(className).getClassLoader();
if (ecl == null) {
if (USE_SYSTEM_CLASSLOADER) {
ecl = ClassLoader.getSystemClassLoader();
} else {
throw new ClassNotFoundException("Classloading from system classloader disabled");
}
}
try {
return new ClassFile(
exportId(ecl,channel),
......@@ -396,18 +412,39 @@ final class RemoteClassLoader extends URLClassLoader {
}
public byte[] getResource(String name) throws IOException {
InputStream in = cl.getResourceAsStream(name);
if(in==null) return null;
return readFully(in);
URL resource = cl.getResource(name);
if (resource == null) {
return null;
}
if (!USE_SYSTEM_CLASSLOADER) {
URL systemResource = ClassLoader.getSystemResource(name);
if (resource.equals(systemResource)) {
return null;
}
}
return readFully(resource.openStream());
}
public byte[][] getResources(String name) throws IOException {
List<byte[]> images = new ArrayList<byte[]>();
Set<URL> systemResources = null;
if (!USE_SYSTEM_CLASSLOADER) {
systemResources = new HashSet<URL>();
Enumeration<URL> e = ClassLoader.getSystemResources(name);
while (e.hasMoreElements()) {
systemResources.add(e.nextElement());
}
}
Enumeration<URL> e = cl.getResources(name);
while(e.hasMoreElements()) {
images.add(readFully(e.nextElement().openStream()));
URL url = e.nextElement();
if (systemResources == null || !systemResources.contains(url)) {
images.add(readFully(url.openStream()));
}
}
return images.toArray(new byte[images.size()][]);
......
......@@ -70,10 +70,20 @@ final class UserRequest<RSP,EXC extends Throwable> extends Request<UserResponse<
}
/*package*/ static ClassLoader getClassLoader(Callable<?,?> c) {
if(c instanceof DelegatingCallable)
return ((DelegatingCallable)c).getClassLoader();
else
return c.getClass().getClassLoader();
ClassLoader result = null;
if(c instanceof DelegatingCallable) {
result =((DelegatingCallable)c).getClassLoader();
}
else {
result = c.getClass().getClassLoader();
}
if (result == null) {
result = ClassLoader.getSystemClassLoader();
}
return result;
}
protected UserResponse<RSP,EXC> perform(Channel channel) throws EXC {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册