Revert "Shift plugin initialization; Addresses BUKKIT-1788"

This reverts commit 27cb5e7c9c6b2cfc5419262df75d89bc6bfe7879. Issues
were discovered with shared class loaders.

By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
Bukkit/Spigot 2012-06-16 00:48:47 -05:00
parent 5d9e74a637
commit 8b6f1612a1
3 changed files with 4 additions and 37 deletions

View File

@ -49,12 +49,7 @@ public abstract class JavaPlugin extends PluginBase {
private File configFile = null;
private PluginLogger logger = null;
public JavaPlugin() {
ClassLoader classLoader = this.getClass().getClassLoader();
if (classLoader instanceof PluginClassLoader) {
((PluginClassLoader) classLoader).initialize(this);
}
}
public JavaPlugin() {}
/**
* Returns the folder that the plugin data's files are located in. The

View File

@ -134,7 +134,7 @@ public class JavaPluginLoader implements PluginLoader {
loader = loaders.get(description.getClassLoaderOf());
loader.addURL(urls[0]);
} else {
loader = new PluginClassLoader(this, urls, getClass().getClassLoader(), server, description, dataFolder, file);
loader = new PluginClassLoader(this, urls, getClass().getClassLoader());
}
Class<?> jarClass = Class.forName(description.getMain(), true, loader);
@ -143,6 +143,8 @@ public class JavaPluginLoader implements PluginLoader {
Constructor<? extends JavaPlugin> constructor = plugin.getConstructor();
result = constructor.newInstance();
result.initialize(this, server, description, dataFolder, file, loader);
} catch (InvocationTargetException ex) {
throw new InvalidPluginException(ex.getCause());
} catch (Throwable ex) {

View File

@ -1,43 +1,22 @@
package org.bukkit.plugin.java;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.Validate;
import org.bukkit.Server;
import org.bukkit.plugin.PluginDescriptionFile;
/**
* A ClassLoader for plugins, to allow shared classes across multiple plugins
*/
public class PluginClassLoader extends URLClassLoader {
private final JavaPluginLoader loader;
private final Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
private final PluginDescriptionFile description;
private final Server server;
private final File dataFolder;
private final File file;
/**
* Changed in favor of class loader that initializes plugins
*/
@Deprecated
public PluginClassLoader(final JavaPluginLoader loader, final URL[] urls, final ClassLoader parent) {
this(loader, urls, parent, null, null, null, null);
}
public PluginClassLoader(final JavaPluginLoader loader, final URL[] urls, final ClassLoader parent, final Server server, final PluginDescriptionFile description, final File dataFolder, final File file) {
super(urls, parent);
this.loader = loader;
this.server = server;
this.description = description;
this.dataFolder = dataFolder;
this.file = file;
}
@Override
@ -75,13 +54,4 @@ public class PluginClassLoader extends URLClassLoader {
public Set<String> getClasses() {
return classes.keySet();
}
void initialize(JavaPlugin javaPlugin) {
Validate.notNull(javaPlugin, "Initializing plugin cannot be null");
Validate.isTrue(javaPlugin.getClass().getClassLoader() == this, "Cannot initialize plugin outside of this class loader");
if (server != null && description != null && dataFolder != null && file != null) {
javaPlugin.initialize(loader, server, description, dataFolder, file, this);
}
}
}