|
|
@ -55,52 +55,54 @@ public class PluginClassLoader extends URLClassLoader { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Class<?> loadClass(String className) throws ClassNotFoundException { |
|
|
|
public Class<?> loadClass(String className) throws ClassNotFoundException { |
|
|
|
log.debug("Received request to load class '{}'", className); |
|
|
|
synchronized (getClassLoadingLock(className)) { |
|
|
|
// if the class it's a part of the plugin engine use parent class loader
|
|
|
|
log.debug("Received request to load class '{}'", className); |
|
|
|
if (className.startsWith(PLUGIN_PACKAGE_PREFIX)) { |
|
|
|
// if the class it's a part of the plugin engine use parent class loader
|
|
|
|
log.debug("Delegate the loading of class '{}' to parent", className); |
|
|
|
if (className.startsWith(PLUGIN_PACKAGE_PREFIX)) { |
|
|
|
|
|
|
|
log.debug("Delegate the loading of class '{}' to parent", className); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
return getClass().getClassLoader().loadClass(className); |
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
|
|
|
|
// try next step
|
|
|
|
|
|
|
|
// TODO if I uncomment below lines (the correct approach) I received ClassNotFoundException for demo (ro.fortsoft.pf4j.demo)
|
|
|
|
|
|
|
|
// log.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
// throw e;
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// second check whether it's already been loaded
|
|
|
|
|
|
|
|
Class<?> clazz = findLoadedClass(className); |
|
|
|
|
|
|
|
if (clazz != null) { |
|
|
|
|
|
|
|
log.debug("Found loaded class '{}'", className); |
|
|
|
|
|
|
|
return clazz; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// nope, try to load locally
|
|
|
|
try { |
|
|
|
try { |
|
|
|
return getClass().getClassLoader().loadClass(className); |
|
|
|
clazz = findClass(className); |
|
|
|
|
|
|
|
log.debug("Found class '{}' in plugin classpath", className); |
|
|
|
|
|
|
|
return clazz; |
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
// try next step
|
|
|
|
// try next step
|
|
|
|
// TODO if I uncomment below lines (the correct approach) I received ClassNotFoundException for demo (ro.fortsoft.pf4j.demo)
|
|
|
|
|
|
|
|
// log.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
// throw e;
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// second check whether it's already been loaded
|
|
|
|
// look in dependencies
|
|
|
|
Class<?> clazz = findLoadedClass(className); |
|
|
|
log.debug("Look in dependencies for class '{}'", className); |
|
|
|
if (clazz != null) { |
|
|
|
List<PluginDependency> dependencies = pluginDescriptor.getDependencies(); |
|
|
|
log.debug("Found loaded class '{}'", className); |
|
|
|
for (PluginDependency dependency : dependencies) { |
|
|
|
return clazz; |
|
|
|
PluginClassLoader classLoader = pluginManager.getPluginClassLoader(dependency.getPluginId()); |
|
|
|
} |
|
|
|
try { |
|
|
|
|
|
|
|
return classLoader.loadClass(className); |
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
|
|
|
|
// try next dependency
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// nope, try to load locally
|
|
|
|
log.debug("Couldn't find class '{}' in plugin classpath. Delegating to parent"); |
|
|
|
try { |
|
|
|
|
|
|
|
clazz = findClass(className); |
|
|
|
|
|
|
|
log.debug("Found class '{}' in plugin classpath", className); |
|
|
|
|
|
|
|
return clazz; |
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
|
|
|
|
// try next step
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// look in dependencies
|
|
|
|
// use the standard URLClassLoader (which follows normal parent delegation)
|
|
|
|
log.debug("Look in dependencies for class '{}'", className); |
|
|
|
return super.loadClass(className); |
|
|
|
List<PluginDependency> dependencies = pluginDescriptor.getDependencies(); |
|
|
|
|
|
|
|
for (PluginDependency dependency : dependencies) { |
|
|
|
|
|
|
|
PluginClassLoader classLoader = pluginManager.getPluginClassLoader(dependency.getPluginId()); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
return classLoader.loadClass(className); |
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
|
|
|
|
// try next dependency
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.debug("Couldn't find class '{}' in plugin classpath. Delegating to parent"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// use the standard URLClassLoader (which follows normal parent delegation)
|
|
|
|
|
|
|
|
return super.loadClass(className); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|