diff options
author | Raphfrk <raphfrk@gmail.com> | 2011-03-09 22:14:13 +0000 |
---|---|---|
committer | Erik Broes <erikbroes@grum.nl> | 2011-03-25 20:36:59 +0100 |
commit | 2275372cb1c4b43fde51ad64491d5f7d8000898b (patch) | |
tree | 2b221b65badabcef179950bfe44e15fd145fde20 /src/main/java | |
parent | adfeb9c819cfc05514e57af2fa3e655507aa0c01 (diff) | |
download | bukkit-2275372cb1c4b43fde51ad64491d5f7d8000898b.tar bukkit-2275372cb1c4b43fde51ad64491d5f7d8000898b.tar.gz bukkit-2275372cb1c4b43fde51ad64491d5f7d8000898b.tar.lz bukkit-2275372cb1c4b43fde51ad64491d5f7d8000898b.tar.xz bukkit-2275372cb1c4b43fde51ad64491d5f7d8000898b.zip |
Fixed basic dependency functionality - If class can't be found, all other .jar files are scanned
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java | 44 | ||||
-rw-r--r-- | src/main/java/org/bukkit/plugin/java/PluginClassLoader.java | 8 |
2 files changed, 36 insertions, 16 deletions
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index ee0a1a01..e69a4c47 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -39,7 +39,7 @@ public final class JavaPluginLoader implements PluginLoader { Pattern.compile("\\.jar$"), }; private final Map<String, Class<?>> classes = new HashMap<String, Class<?>>(); - private final Map<String, File> files = new HashMap<String, File>(); + private final Map<String, PluginClassLoader> loaders = new HashMap<String, PluginClassLoader>(); public JavaPluginLoader(Server instance) { server = instance; @@ -81,27 +81,21 @@ public final class JavaPluginLoader implements PluginLoader { throw new InvalidPluginException(ex); } - ArrayList<File> dependFiles = new ArrayList<File>(); - for(String pluginName : depend) { - if(files == null) { + if(loaders == null) { throw new UnknownDependencyException(pluginName); } - File current = files.get(pluginName); + PluginClassLoader current = loaders.get(pluginName); if(current == null) { throw new UnknownDependencyException(pluginName); } - dependFiles.add(current); } + PluginClassLoader loader = null; try { - URL[] urls = new URL[dependFiles.size() + 1]; + URL[] urls = new URL[1]; urls[0] = file.toURI().toURL(); - int cnt = 1; - for(File f : dependFiles) { - urls[cnt++] = f.toURI().toURL(); - } - ClassLoader loader = new PluginClassLoader(this, urls, getClass().getClassLoader()); + loader = new PluginClassLoader(this, urls, getClass().getClassLoader()); Class<?> jarClass = Class.forName(description.getMain(), true, loader); Class<? extends JavaPlugin> plugin = jarClass.asSubclass(JavaPlugin.class); @@ -113,7 +107,7 @@ public final class JavaPluginLoader implements PluginLoader { throw new InvalidPluginException(ex); } - files.put(description.getName(), file); + loaders.put(description.getName(), (PluginClassLoader)loader); return (Plugin)result; } @@ -143,7 +137,22 @@ public final class JavaPluginLoader implements PluginLoader { } public Class<?> getClassByName(final String name) { - return classes.get(name); + Class<?> cachedClass = classes.get(name); + if(cachedClass != null) { + return cachedClass; + } else { + for(String current : loaders.keySet()) { + PluginClassLoader loader = loaders.get(current); + try { + cachedClass = loader.findClass(name, false); + } catch (ClassNotFoundException cnfe) { + } + if(cachedClass != null) { + return cachedClass; + } + } + } + return null; } public void setClass(final String name, final Class<?> clazz) { @@ -450,6 +459,11 @@ public final class JavaPluginLoader implements PluginLoader { if (!plugin.isEnabled()) { JavaPlugin jPlugin = (JavaPlugin)plugin; + String pluginName = jPlugin.getDescription().getName(); + if(!loaders.containsKey(pluginName)) { + loaders.put(pluginName, (PluginClassLoader)jPlugin.getClassLoader()); + } + jPlugin.setEnabled(true); server.getPluginManager().callEvent(new PluginEvent(Event.Type.PLUGIN_ENABLE, plugin)); } @@ -468,7 +482,7 @@ public final class JavaPluginLoader implements PluginLoader { server.getPluginManager().callEvent(new PluginEvent(Event.Type.PLUGIN_DISABLE, plugin)); - files.remove(jPlugin.getDescription().getName()); + loaders.remove(jPlugin.getDescription().getName()); if (cloader instanceof PluginClassLoader) { PluginClassLoader loader = (PluginClassLoader)cloader; diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java index d17e0f4f..91d4d6d3 100644 --- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java +++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java @@ -21,10 +21,16 @@ public class PluginClassLoader extends URLClassLoader { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { + return findClass(name, true); + } + + protected Class<?> findClass(String name, boolean checkGlobal) throws ClassNotFoundException { Class<?> result = classes.get(name); if (result == null) { - result = loader.getClassByName(name); + if(checkGlobal) { + result = loader.getClassByName(name); + } if (result == null) { result = super.findClass(name); |