Commit a7bd18d0 authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Removing Guice, alas we barely knew you

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8649 b35dd754-fafc-0310-a699-88a17e54d16e
parent a940eeff
......@@ -18,10 +18,6 @@ import org.dom4j.io.SAXReader;
import org.jivesoftware.admin.AdminConsole;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.plugin.AbstractPlugin;
import org.jivesoftware.openfire.container.plugin.PluginName;
import org.jivesoftware.openfire.container.plugin.PluginDescription;
import org.jivesoftware.openfire.container.plugin.PluginDir;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.Version;
......@@ -35,11 +31,6 @@ import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
import java.util.zip.ZipFile;
import com.google.inject.Guice;
import com.google.inject.AbstractModule;
import com.google.inject.Provider;
import com.google.inject.Scopes;
/**
* Loads and manages plugins. The <tt>plugins</tt> directory is monitored for any
* new plugins, and they are dynamically loaded.<p/>
......@@ -381,35 +372,7 @@ public class PluginManager {
}
String className = pluginXML.selectSingleNode("/plugin/class").getText();
Class pluginClazz = pluginLoader.loadClass(className);
if(AbstractPlugin.class.isAssignableFrom(pluginClazz)) {
String moduleClassName;
try {
moduleClassName = pluginXML.selectSingleNode("/plugin/module/class")
.getText();
}
catch (NullPointerException npe) {
moduleClassName = null;
}
Class moduleClazz;
try {
if (moduleClassName != null) {
moduleClazz = pluginLoader.loadClass(moduleClassName);
}
else {
moduleClazz = null;
}
}
catch (ClassNotFoundException cnfe) {
moduleClazz = null;
}
//noinspection unchecked
plugin = instantiateAbstractPlugin(pluginDir, pluginLoader, pluginClazz,
moduleClazz);
}
else {
plugin = (Plugin) pluginClazz.newInstance();
}
plugin = (Plugin)pluginLoader.loadClass(className).newInstance();
if (parentPluginNode != null) {
String parentPlugin = parentPluginNode.getTextTrim();
// See if the parent is already loaded.
......@@ -533,58 +496,6 @@ public class PluginManager {
}
}
private Plugin instantiateAbstractPlugin(final File pluginDir, PluginClassLoader pluginLoader,
final Class<? extends AbstractPlugin> pluginClazz,
Class<? extends com.google.inject.Module> moduleClazz)
throws IllegalAccessException, InstantiationException
{
// Init the plugin.
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(pluginLoader);
final PluginModule module = new PluginModule();
com.google.inject.Module tempModule;
if(moduleClazz == null) {
tempModule = null;
}
else {
tempModule = moduleClazz.newInstance();
}
final com.google.inject.Module pluginModule = tempModule;
AbstractPlugin plugin = Guice.createInjector(new AbstractModule() {
protected void configure() {
install(module);
if (pluginModule != null) {
install(pluginModule);
}
bind(String.class).annotatedWith(PluginName.class).toProvider(
new Provider<String>() {
public String get() {
return getName(pluginDir);
}
}
);
bind(String.class).annotatedWith(PluginDescription.class).toProvider(
new Provider<String>() {
public String get() {
return getDescription(pluginDir);
}
}
);
bind(File.class).annotatedWith(PluginDir.class).toProvider(
new Provider<File>() {
public File get() {
return pluginDir;
}
}
);
bind(pluginClazz).in(Scopes.SINGLETON);
}
}).getInstance(pluginClazz);
Thread.currentThread().setContextClassLoader(oldLoader);
return plugin;
}
private void firePluginCreatedEvent(String name, Plugin plugin) {
for(PluginListener listener : pluginListeners) {
listener.pluginCreated(name, plugin);
......@@ -708,12 +619,8 @@ public class PluginManager {
* @return the plugin's name.
*/
public String getName(Plugin plugin) {
return getName(pluginDirs.get(plugin));
}
private String getName(File pluginDir) {
String name = getElementValue(pluginDir, "/plugin/name");
String pluginName = pluginDir.getName();
String name = getElementValue(plugin, "/plugin/name");
String pluginName = pluginDirs.get(plugin).getName();
if (name != null) {
return AdminConsole.getAdminText(name, pluginName);
}
......@@ -730,13 +637,8 @@ public class PluginManager {
* @return the plugin's description.
*/
public String getDescription(Plugin plugin) {
return getDescription(pluginDirs.get(plugin));
}
private String getDescription(File pluginDir) {
String pluginName = pluginDir.getName();
return AdminConsole.getAdminText(getElementValue(pluginDirs.get(pluginDir),
"/plugin/description"), pluginName);
String pluginName = pluginDirs.get(plugin).getName();
return AdminConsole.getAdminText(getElementValue(plugin, "/plugin/description"), pluginName);
}
/**
......@@ -747,7 +649,7 @@ public class PluginManager {
* @return the plugin's author.
*/
public String getAuthor(Plugin plugin) {
return getElementValue(pluginDirs.get(plugin), "/plugin/author");
return getElementValue(plugin, "/plugin/author");
}
/**
......@@ -758,7 +660,7 @@ public class PluginManager {
* @return the plugin's version.
*/
public String getVersion(Plugin plugin) {
return getElementValue(pluginDirs.get(plugin), "/plugin/version");
return getElementValue(plugin, "/plugin/version");
}
/**
......@@ -769,7 +671,7 @@ public class PluginManager {
* @return the plugin's version.
*/
public String getMinServerVersion(Plugin plugin) {
return getElementValue(pluginDirs.get(plugin), "/plugin/minServerVersion");
return getElementValue(plugin, "/plugin/minServerVersion");
}
/**
......@@ -781,7 +683,7 @@ public class PluginManager {
* @return the plugin's database schema key or <tt>null</tt> if it doesn't exist.
*/
public String getDatabaseKey(Plugin plugin) {
return getElementValue(pluginDirs.get(plugin), "/plugin/databaseKey");
return getElementValue(plugin, "/plugin/databaseKey");
}
/**
......@@ -793,7 +695,7 @@ public class PluginManager {
* @return the plugin's database schema version or <tt>-1</tt> if it doesn't exist.
*/
public int getDatabaseVersion(Plugin plugin) {
String versionString = getElementValue(pluginDirs.get(plugin), "/plugin/databaseVersion");
String versionString = getElementValue(plugin, "/plugin/databaseVersion");
if (versionString != null) {
try {
return Integer.parseInt(versionString.trim());
......@@ -814,7 +716,7 @@ public class PluginManager {
* @return the plugin's license agreement.
*/
public License getLicense(Plugin plugin) {
String licenseString = getElementValue(pluginDirs.get(plugin), "/plugin/licenseType");
String licenseString = getElementValue(plugin, "/plugin/licenseType");
if (licenseString != null) {
try {
// Attempt to load the get the license type. We lower-case and
......@@ -844,11 +746,12 @@ public class PluginManager {
* Returns the value of an element selected via an xpath expression from
* a Plugin's plugin.xml file.
*
* @param pluginDir the plugin directory.
* @param plugin the plugin.
* @param xpath the xpath expression.
* @return the value of the element selected by the xpath expression.
*/
private String getElementValue(File pluginDir, String xpath) {
private String getElementValue(Plugin plugin, String xpath) {
File pluginDir = pluginDirs.get(plugin);
if (pluginDir == null) {
return null;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment