-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIXED JENKINS-44898] Add findResource to PluginFirstClassLoader #2916
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,13 +27,16 @@ | |
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.lang.reflect.Field; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Enumeration; | ||
import java.util.List; | ||
import java.util.Vector; | ||
|
||
import org.apache.tools.ant.AntClassLoader; | ||
import org.apache.tools.ant.Project; | ||
|
||
/** | ||
* classLoader which use first /WEB-INF/lib/*.jar and /WEB-INF/classes before core classLoader | ||
|
@@ -45,7 +48,21 @@ public class PluginFirstClassLoader | |
extends AntClassLoader | ||
implements Closeable | ||
{ | ||
|
||
|
||
private final Vector pathComponents; | ||
|
||
public PluginFirstClassLoader() { | ||
super(); | ||
|
||
try { | ||
Field $pathComponents = AntClassLoader.class.getDeclaredField("pathComponents"); | ||
$pathComponents.setAccessible(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like you need to introduce a common ancestor with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Or we should just stop using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm generally mystified but wanted to go with the least-disruptive-change-possible in case there was some legitimate reason somewhere for it. I'll add a common ancestor. |
||
pathComponents = (Vector)$pathComponents.get(this); | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
throw new Error(e); | ||
} | ||
} | ||
|
||
private List<URL> urls = new ArrayList<URL>(); | ||
|
||
public void addPathFiles( Collection<File> paths ) | ||
|
@@ -100,6 +117,27 @@ public InputStream getResourceAsStream( String name ) | |
{ | ||
InputStream is = super.getResourceAsStream( name ); | ||
return is; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* As of 1.8.0, {@link AntClassLoader} doesn't implement {@link #findResource(String)} | ||
* in any meaningful way, which breaks fast lookup. Implement it properly. | ||
*/ | ||
@Override | ||
protected URL findResource(String name) { | ||
URL url = null; | ||
|
||
// try and load from this loader if the parent either didn't find | ||
// it or wasn't consulted. | ||
Enumeration e = pathComponents.elements(); | ||
while (e.hasMoreElements() && url == null) { | ||
File pathComponent = (File) e.nextElement(); | ||
url = getResourceURL(pathComponent, name); | ||
if (url != null) { | ||
log("Resource " + name + " loaded from ant loader", Project.MSG_DEBUG); | ||
} | ||
} | ||
|
||
return url; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implements Closeable
redundant