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; ...@@ -18,10 +18,6 @@ import org.dom4j.io.SAXReader;
import org.jivesoftware.admin.AdminConsole; import org.jivesoftware.admin.AdminConsole;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.XMPPServer; 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.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.Version; import org.jivesoftware.util.Version;
...@@ -35,11 +31,6 @@ import java.util.jar.JarOutputStream; ...@@ -35,11 +31,6 @@ import java.util.jar.JarOutputStream;
import java.util.jar.Pack200; import java.util.jar.Pack200;
import java.util.zip.ZipFile; 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 * Loads and manages plugins. The <tt>plugins</tt> directory is monitored for any
* new plugins, and they are dynamically loaded.<p/> * new plugins, and they are dynamically loaded.<p/>
...@@ -381,35 +372,7 @@ public class PluginManager { ...@@ -381,35 +372,7 @@ public class PluginManager {
} }
String className = pluginXML.selectSingleNode("/plugin/class").getText(); String className = pluginXML.selectSingleNode("/plugin/class").getText();
Class pluginClazz = pluginLoader.loadClass(className); plugin = (Plugin)pluginLoader.loadClass(className).newInstance();
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();
}
if (parentPluginNode != null) { if (parentPluginNode != null) {
String parentPlugin = parentPluginNode.getTextTrim(); String parentPlugin = parentPluginNode.getTextTrim();
// See if the parent is already loaded. // See if the parent is already loaded.
...@@ -533,58 +496,6 @@ public class PluginManager { ...@@ -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) { private void firePluginCreatedEvent(String name, Plugin plugin) {
for(PluginListener listener : pluginListeners) { for(PluginListener listener : pluginListeners) {
listener.pluginCreated(name, plugin); listener.pluginCreated(name, plugin);
...@@ -708,12 +619,8 @@ public class PluginManager { ...@@ -708,12 +619,8 @@ public class PluginManager {
* @return the plugin's name. * @return the plugin's name.
*/ */
public String getName(Plugin plugin) { public String getName(Plugin plugin) {
return getName(pluginDirs.get(plugin)); String name = getElementValue(plugin, "/plugin/name");
} String pluginName = pluginDirs.get(plugin).getName();
private String getName(File pluginDir) {
String name = getElementValue(pluginDir, "/plugin/name");
String pluginName = pluginDir.getName();
if (name != null) { if (name != null) {
return AdminConsole.getAdminText(name, pluginName); return AdminConsole.getAdminText(name, pluginName);
} }
...@@ -730,13 +637,8 @@ public class PluginManager { ...@@ -730,13 +637,8 @@ public class PluginManager {
* @return the plugin's description. * @return the plugin's description.
*/ */
public String getDescription(Plugin plugin) { public String getDescription(Plugin plugin) {
return getDescription(pluginDirs.get(plugin)); String pluginName = pluginDirs.get(plugin).getName();
} return AdminConsole.getAdminText(getElementValue(plugin, "/plugin/description"), pluginName);
private String getDescription(File pluginDir) {
String pluginName = pluginDir.getName();
return AdminConsole.getAdminText(getElementValue(pluginDirs.get(pluginDir),
"/plugin/description"), pluginName);
} }
/** /**
...@@ -747,7 +649,7 @@ public class PluginManager { ...@@ -747,7 +649,7 @@ public class PluginManager {
* @return the plugin's author. * @return the plugin's author.
*/ */
public String getAuthor(Plugin plugin) { public String getAuthor(Plugin plugin) {
return getElementValue(pluginDirs.get(plugin), "/plugin/author"); return getElementValue(plugin, "/plugin/author");
} }
/** /**
...@@ -758,7 +660,7 @@ public class PluginManager { ...@@ -758,7 +660,7 @@ public class PluginManager {
* @return the plugin's version. * @return the plugin's version.
*/ */
public String getVersion(Plugin plugin) { public String getVersion(Plugin plugin) {
return getElementValue(pluginDirs.get(plugin), "/plugin/version"); return getElementValue(plugin, "/plugin/version");
} }
/** /**
...@@ -769,7 +671,7 @@ public class PluginManager { ...@@ -769,7 +671,7 @@ public class PluginManager {
* @return the plugin's version. * @return the plugin's version.
*/ */
public String getMinServerVersion(Plugin plugin) { public String getMinServerVersion(Plugin plugin) {
return getElementValue(pluginDirs.get(plugin), "/plugin/minServerVersion"); return getElementValue(plugin, "/plugin/minServerVersion");
} }
/** /**
...@@ -781,7 +683,7 @@ public class PluginManager { ...@@ -781,7 +683,7 @@ public class PluginManager {
* @return the plugin's database schema key or <tt>null</tt> if it doesn't exist. * @return the plugin's database schema key or <tt>null</tt> if it doesn't exist.
*/ */
public String getDatabaseKey(Plugin plugin) { public String getDatabaseKey(Plugin plugin) {
return getElementValue(pluginDirs.get(plugin), "/plugin/databaseKey"); return getElementValue(plugin, "/plugin/databaseKey");
} }
/** /**
...@@ -793,7 +695,7 @@ public class PluginManager { ...@@ -793,7 +695,7 @@ public class PluginManager {
* @return the plugin's database schema version or <tt>-1</tt> if it doesn't exist. * @return the plugin's database schema version or <tt>-1</tt> if it doesn't exist.
*/ */
public int getDatabaseVersion(Plugin plugin) { public int getDatabaseVersion(Plugin plugin) {
String versionString = getElementValue(pluginDirs.get(plugin), "/plugin/databaseVersion"); String versionString = getElementValue(plugin, "/plugin/databaseVersion");
if (versionString != null) { if (versionString != null) {
try { try {
return Integer.parseInt(versionString.trim()); return Integer.parseInt(versionString.trim());
...@@ -814,7 +716,7 @@ public class PluginManager { ...@@ -814,7 +716,7 @@ public class PluginManager {
* @return the plugin's license agreement. * @return the plugin's license agreement.
*/ */
public License getLicense(Plugin plugin) { public License getLicense(Plugin plugin) {
String licenseString = getElementValue(pluginDirs.get(plugin), "/plugin/licenseType"); String licenseString = getElementValue(plugin, "/plugin/licenseType");
if (licenseString != null) { if (licenseString != null) {
try { try {
// Attempt to load the get the license type. We lower-case and // Attempt to load the get the license type. We lower-case and
...@@ -844,11 +746,12 @@ public class PluginManager { ...@@ -844,11 +746,12 @@ public class PluginManager {
* Returns the value of an element selected via an xpath expression from * Returns the value of an element selected via an xpath expression from
* a Plugin's plugin.xml file. * a Plugin's plugin.xml file.
* *
* @param pluginDir the plugin directory. * @param plugin the plugin.
* @param xpath the xpath expression. * @param xpath the xpath expression.
* @return the value of the element selected by 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) { if (pluginDir == null) {
return 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