aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2015-07-20 16:09:54 +0300
committerDecebal Suiu <decebal.suiu@gmail.com>2015-07-20 16:09:54 +0300
commit302ec57f15eac545eec6814dcd23cbe7d03361e7 (patch)
treea9aef0e04c0fed4e7ec2180c9397ffa3c898dc30
parent49d9974dd134e7cf2991cd9ccd28f06eaa47fd8d (diff)
downloadpf4j-302ec57f15eac545eec6814dcd23cbe7d03361e7.tar.gz
pf4j-302ec57f15eac545eec6814dcd23cbe7d03361e7.zip
fix for #53
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java78
1 files changed, 40 insertions, 38 deletions
diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java
index efa759c..9950914 100644
--- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java
+++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java
@@ -55,52 +55,54 @@ public class PluginClassLoader extends URLClassLoader {
*/
@Override
public Class<?> loadClass(String className) throws ClassNotFoundException {
- log.debug("Received request to load class '{}'", className);
- // if the class it's a part of the plugin engine use parent class loader
- if (className.startsWith(PLUGIN_PACKAGE_PREFIX)) {
- log.debug("Delegate the loading of class '{}' to parent", className);
+ synchronized (getClassLoadingLock(className)) {
+ log.debug("Received request to load class '{}'", className);
+ // if the class it's a part of the plugin engine use parent class loader
+ 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 {
- return getClass().getClassLoader().loadClass(className);
+ clazz = findClass(className);
+ log.debug("Found class '{}' in plugin classpath", className);
+ return clazz;
} 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;
- }
+ // look in dependencies
+ log.debug("Look in dependencies for class '{}'", 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
+ }
+ }
- // nope, try to load locally
- try {
- clazz = findClass(className);
- log.debug("Found class '{}' in plugin classpath", className);
- return clazz;
- } catch (ClassNotFoundException e) {
- // try next step
- }
+ log.debug("Couldn't find class '{}' in plugin classpath. Delegating to parent");
- // look in dependencies
- log.debug("Look in dependencies for class '{}'", 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
- }
+ // use the standard URLClassLoader (which follows normal parent delegation)
+ return super.loadClass(className);
}
-
- 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);
}
/**