Commit 7a7db14a authored by Dave Cridland's avatar Dave Cridland

Merge pull request #342 from wmz7year/PluginClassLoader

Fix PluginClassLoader load resource path issue  
parents 32b85e8e ee30e18c
...@@ -510,25 +510,25 @@ public class PluginClassLoader extends URLClassLoader { ...@@ -510,25 +510,25 @@ public class PluginClassLoader extends URLClassLoader {
// Add classes directory to classpath. // Add classes directory to classpath.
File classesDir = new File(directory, "classes"); File classesDir = new File(directory, "classes");
if (classesDir.exists()) { if (classesDir.exists()) {
addResource(classesDir.toURI().toURL()); addResource(classesDir.toURI().toURL(), "/");
} }
// Add i18n directory to classpath. // Add i18n directory to classpath.
File databaseDir = new File(directory, "database"); File databaseDir = new File(directory, "database");
if (databaseDir.exists()) { if (databaseDir.exists()) {
addResource(databaseDir.toURI().toURL()); addResource(databaseDir.toURI().toURL(), "/");
} }
// Add i18n directory to classpath. // Add i18n directory to classpath.
File i18nDir = new File(directory, "i18n"); File i18nDir = new File(directory, "i18n");
if (i18nDir.exists()) { if (i18nDir.exists()) {
addResource(i18nDir.toURI().toURL()); addResource(i18nDir.toURI().toURL(), "/");
} }
// Add web directory to classpath. // Add web directory to classpath.
File webDir = new File(directory, "web"); File webDir = new File(directory, "web");
if (webDir.exists()) { if (webDir.exists()) {
addResource(webDir.toURI().toURL()); addResource(webDir.toURI().toURL(), "/");
} }
// Add lib directory to classpath. // Add lib directory to classpath.
...@@ -545,10 +545,10 @@ public class PluginClassLoader extends URLClassLoader { ...@@ -545,10 +545,10 @@ public class PluginClassLoader extends URLClassLoader {
if (developmentMode) { if (developmentMode) {
// Do not add plugin-pluginName.jar to classpath. // Do not add plugin-pluginName.jar to classpath.
if (!jars[i].getName().equals("plugin-" + directory.getName() + ".jar")) { if (!jars[i].getName().equals("plugin-" + directory.getName() + ".jar")) {
addResource(new URL("jar", "", -1, jarFileUri)); addResource(new URL("jar", "", -1, jarFileUri), "/");
} }
} else { } else {
addResource(new URL("jar", "", -1, jarFileUri)); addResource(new URL("jar", "", -1, jarFileUri), "/");
} }
} }
} }
...@@ -596,7 +596,7 @@ public class PluginClassLoader extends URLClassLoader { ...@@ -596,7 +596,7 @@ public class PluginClassLoader extends URLClassLoader {
* URL for the JAR file or directory to append to classpath * URL for the JAR file or directory to append to classpath
*/ */
public void addURLFile(URL file) { public void addURLFile(URL file) {
addResource(file); addResource(file, "/");
} }
/** /**
...@@ -606,14 +606,17 @@ public class PluginClassLoader extends URLClassLoader { ...@@ -606,14 +606,17 @@ public class PluginClassLoader extends URLClassLoader {
resourceEntries.clear(); resourceEntries.clear();
} }
private void addResource(URL url) { private void addResource(URL url, String parent) {
// check file is directory and list files // check file is directory and list files
try { try {
File file = new File(url.toURI()); File file = new File(url.toURI());
if (file.isDirectory()) { if (file.isDirectory()) {
File[] files = file.listFiles(); File[] files = file.listFiles();
for (File temp : files) { for (File temp : files) {
addResource(temp.toURI().toURL()); if(temp.isDirectory()){
parent = String.format("%s%s/", parent, temp.getName());
}
addResource(temp.toURI().toURL(), parent);
} }
return; return;
} }
...@@ -638,8 +641,9 @@ public class PluginClassLoader extends URLClassLoader { ...@@ -638,8 +641,9 @@ public class PluginClassLoader extends URLClassLoader {
entry.codeBase = url; entry.codeBase = url;
entry.lastModified = file.lastModified(); entry.lastModified = file.lastModified();
entry.binaryContent = readBytes(new FileInputStream(file)); entry.binaryContent = readBytes(new FileInputStream(file));
if (Log.isDebugEnabled())
resourceEntries.put("/" + file.getName(), entry); Log.debug("add resource path:" + parent + file.getName());
resourceEntries.put(parent + file.getName(), entry);
} }
} catch (Exception e) { } catch (Exception e) {
Log.warn("Failed to load plugin resource: " + url.toExternalForm()); Log.warn("Failed to load plugin resource: " + url.toExternalForm());
...@@ -662,6 +666,8 @@ public class PluginClassLoader extends URLClassLoader { ...@@ -662,6 +666,8 @@ public class PluginClassLoader extends URLClassLoader {
entry.lastModified = jarEntry.getTime(); entry.lastModified = jarEntry.getTime();
entry.binaryContent = readBytes(jarFile.getInputStream(jarEntry)); entry.binaryContent = readBytes(jarFile.getInputStream(jarEntry));
entry.codeBase = codebase; entry.codeBase = codebase;
if (Log.isDebugEnabled())
Log.debug("add resource path:/" + jarEntry.getName());
resourceEntries.put("/" + jarEntry.getName(), entry); resourceEntries.put("/" + jarEntry.getName(), entry);
} }
} catch (IOException e) { } catch (IOException e) {
......
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