Skip to content

Commit 91b11c3

Browse files
[MSHARED-1359] Use child first classloader in BeanShellScriptInterpreter
1 parent 9dfe91d commit 91b11c3

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/main/java/org/apache/maven/shared/scriptinterpreter/BeanShellScriptInterpreter.java

+35-3
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,50 @@
4040
*/
4141
class BeanShellScriptInterpreter implements ScriptInterpreter {
4242

43-
private static class AppendableURLClassLoader extends URLClassLoader {
44-
AppendableURLClassLoader() {
43+
private static class ChildFirstURLClassLoader extends URLClassLoader {
44+
ChildFirstURLClassLoader() {
4545
super(new URL[] {}, Thread.currentThread().getContextClassLoader());
4646
}
4747

4848
@Override
4949
public void addURL(URL url) {
5050
super.addURL(url);
5151
}
52+
53+
@Override
54+
protected synchronized Class<?> loadClass(final String name, final boolean resolve)
55+
throws ClassNotFoundException {
56+
57+
Class<?> c = findLoadedClass(name);
58+
if (c != null) {
59+
return c;
60+
}
61+
62+
try {
63+
c = super.findClass(name);
64+
} catch (ClassNotFoundException e) {
65+
// ignore
66+
}
67+
68+
if (c == null) {
69+
c = super.loadClass(name, resolve);
70+
}
71+
72+
if (resolve) {
73+
resolveClass(c);
74+
}
75+
76+
return c;
77+
}
78+
79+
@Override
80+
public URL getResource(final String name) {
81+
URL url = findResource(name);
82+
return url != null ? url : super.getResource(name);
83+
}
5284
}
5385

54-
private final AppendableURLClassLoader classLoader = new AppendableURLClassLoader();
86+
private final ChildFirstURLClassLoader classLoader = new ChildFirstURLClassLoader();
5587

5688
@Override
5789
public void setClassPath(List<String> classPath) {

0 commit comments

Comments
 (0)