Commit 0879759f authored by Matt Tucker's avatar Matt Tucker Committed by matt

Added support for child plugins (JM-336).


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1713 b35dd754-fafc-0310-a699-88a17e54d16e
parent 832a1048
......@@ -91,6 +91,10 @@ file might look like the following:
<li>minServerVersion -- the minimum version of Jive Messenger required
to run the plugin (supported by Jive Messenger 2.1.2 and later). If the
server version is less than the required value, the plugin will not be started.</li>
<li>parentPlugin -- the name of the parent plugin (given as "foo" for the "foo.jar" plugin).
When a plugin has a parent plugin, the parent plugin's classloader will be used instead
of creating a new classloader. This lets plugins work together more closely. A
child plugin will not function without its parent present.</li>
</ul></p>
Several additional files can be present in the plugin to provide additional information to
......
......@@ -11,6 +11,8 @@
package org.jivesoftware.messenger.container;
import org.jivesoftware.util.Log;
import java.io.File;
import java.io.FilenameFilter;
import java.net.MalformedURLException;
......@@ -34,7 +36,7 @@ import java.util.List;
class PluginClassLoader {
private URLClassLoader classLoader;
private final List list = new ArrayList();
private final List<URL> list = new ArrayList<URL>();
/**
......@@ -43,15 +45,24 @@ class PluginClassLoader {
* @param pluginDir the plugin directory.
* @throws java.lang.SecurityException if the created class loader violates
* existing security constraints.
* @throws java.net.MalformedURLException if a located resource name cannot be
* properly converted to a URL.
*/
public PluginClassLoader(File pluginDir) throws MalformedURLException, SecurityException {
File classesDir = new File(pluginDir, "classes");
public PluginClassLoader(File pluginDir) throws SecurityException {
addDirectory(pluginDir);
}
/**
* Adds a directory to the class loader. The {@link #initialize()} method should be called
* after adding the directory to make the change take effect.
*
* @param directory the directory.
*/
public void addDirectory(File directory) {
try {
File classesDir = new File(directory, "classes");
if (classesDir.exists()) {
list.add(classesDir.toURL());
}
File libDir = new File(pluginDir, "lib");
File libDir = new File(directory, "lib");
File[] jars = libDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar") || name.endsWith(".zip");
......@@ -65,11 +76,25 @@ class PluginClassLoader {
}
}
}
catch (MalformedURLException mue) {
Log.error(mue);
}
}
/**
* Adds a URL to the class loader. The {@link #initialize()} method should be called
* after adding the URL to make the change take effect.
*
* @param url the url.
*/
public void addURL(URL url) {
list.add(url);
}
/**
* Initializes the class loader with all configured classpath URLs. This method
* can be called multiple times if the list of URLs changes.
*/
public void initialize(){
Iterator urls = list.iterator();
URL[] urlArray = new URL[list.size()];
......
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