Commit fe5a56b0 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Child plugins were not using the same plugin classloader, but were only...

Child plugins were not using the same plugin classloader, but were only initializing the classpath from the parent plugin, but not in the same instance.

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/branches/jive_messenger_2_2_branch@2871 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9a37d08b
...@@ -43,8 +43,8 @@ class PluginClassLoader { ...@@ -43,8 +43,8 @@ class PluginClassLoader {
* Constructs a plugin loader for the given plugin directory. * Constructs a plugin loader for the given plugin directory.
* *
* @param pluginDir the plugin directory. * @param pluginDir the plugin directory.
* @throws java.lang.SecurityException if the created class loader violates * @throws SecurityException if the created class loader violates
* existing security constraints. * existing security constraints.
*/ */
public PluginClassLoader(File pluginDir) throws SecurityException { public PluginClassLoader(File pluginDir) throws SecurityException {
addDirectory(pluginDir); addDirectory(pluginDir);
...@@ -58,24 +58,24 @@ class PluginClassLoader { ...@@ -58,24 +58,24 @@ class PluginClassLoader {
*/ */
public void addDirectory(File directory) { public void addDirectory(File directory) {
try { try {
File classesDir = new File(directory, "classes"); File classesDir = new File(directory, "classes");
if (classesDir.exists()) { if (classesDir.exists()) {
list.add(classesDir.toURL()); list.add(classesDir.toURL());
}
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");
} }
}); File libDir = new File(directory, "lib");
if (jars != null) { File[] jars = libDir.listFiles(new FilenameFilter() {
for (int i = 0; i < jars.length; i++) { public boolean accept(File dir, String name) {
if (jars[i] != null && jars[i].isFile()) { return name.endsWith(".jar") || name.endsWith(".zip");
list.add(jars[i].toURL()); }
});
if (jars != null) {
for (int i = 0; i < jars.length; i++) {
if (jars[i] != null && jars[i].isFile()) {
list.add(jars[i].toURL());
}
} }
} }
} }
}
catch (MalformedURLException mue) { catch (MalformedURLException mue) {
Log.error(mue); Log.error(mue);
} }
...@@ -95,13 +95,21 @@ class PluginClassLoader { ...@@ -95,13 +95,21 @@ class PluginClassLoader {
* Initializes the class loader with all configured classpath URLs. This method * Initializes the class loader with all configured classpath URLs. This method
* can be called multiple times if the list of URLs changes. * can be called multiple times if the list of URLs changes.
*/ */
public void initialize(){ public void initialize() {
Iterator urls = list.iterator(); Iterator urls = list.iterator();
URL[] urlArray = new URL[list.size()]; URL[] urlArray = new URL[list.size()];
for (int i = 0; urls.hasNext(); i++) { for (int i = 0; urls.hasNext(); i++) {
urlArray[i] = (URL)urls.next(); urlArray[i] = (URL)urls.next();
} }
classLoader = new URLClassLoader(urlArray, findParentClassLoader());
// If the classloader is to be used by a child plugin, we should
// never use the ContextClassLoader, but only reuse the plugin classloader itself.
if (classLoader != null) {
classLoader = new URLClassLoader(urlArray, classLoader);
}
else {
classLoader = new URLClassLoader(urlArray, findParentClassLoader());
}
} }
/** /**
...@@ -115,7 +123,7 @@ class PluginClassLoader { ...@@ -115,7 +123,7 @@ class PluginClassLoader {
* @throws SecurityException if the custom class loader not allowed. * @throws SecurityException if the custom class loader not allowed.
*/ */
public Class loadClass(String name) throws ClassNotFoundException, IllegalAccessException, public Class loadClass(String name) throws ClassNotFoundException, IllegalAccessException,
InstantiationException, SecurityException { InstantiationException, SecurityException {
return classLoader.loadClass(name); return classLoader.loadClass(name);
} }
......
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