diff --git a/src/main/java/cn/wizzer/common/core/Setup.java b/src/main/java/cn/wizzer/common/core/Setup.java index 9cb5f6fa6..f1ddbe8e8 100644 --- a/src/main/java/cn/wizzer/common/core/Setup.java +++ b/src/main/java/cn/wizzer/common/core/Setup.java @@ -89,12 +89,12 @@ private void initSysPlugin(NutConfig config, Dao dao) { for (Sys_plugin sysPlugin : list) { String name = sysPlugin.getPath().substring(sysPlugin.getPath().indexOf(".")).toLowerCase(); File file = new File(Globals.AppRoot + sysPlugin.getPath()); - byte[] buf = Files.readBytes(file); String[] p = new String[]{}; IPlugin plugin; if (".jar".equals(name)) { - plugin = pluginMaster.buildFromJar(file, sysPlugin.getClassName(), buf); + plugin = pluginMaster.buildFromJar(file, sysPlugin.getClassName()); } else { + byte[] buf = Files.readBytes(file); plugin = pluginMaster.build(sysPlugin.getClassName(), buf); } if (!Strings.isBlank(sysPlugin.getArgs())) { diff --git a/src/main/java/cn/wizzer/common/plugin/PluginMaster.java b/src/main/java/cn/wizzer/common/plugin/PluginMaster.java index aaf155475..da660a9b1 100644 --- a/src/main/java/cn/wizzer/common/plugin/PluginMaster.java +++ b/src/main/java/cn/wizzer/common/plugin/PluginMaster.java @@ -72,7 +72,7 @@ public IPlugin build(final String className, byte[] buf) { } @SuppressWarnings("resource") - public IPlugin buildFromJar(final File file, final String className, byte[] buf) { + public IPlugin buildFromJar(final File file, final String className) { try { log.debug(file.getAbsolutePath()); return (IPlugin) new URLClassLoader(new URL[]{file.toURI().toURL()}, getClass().getClassLoader(), null).loadClass(className).newInstance(); diff --git a/src/main/java/cn/wizzer/modules/controllers/platform/sys/SysPluginController.java b/src/main/java/cn/wizzer/modules/controllers/platform/sys/SysPluginController.java index 2979063ad..3c0a21781 100644 --- a/src/main/java/cn/wizzer/modules/controllers/platform/sys/SysPluginController.java +++ b/src/main/java/cn/wizzer/modules/controllers/platform/sys/SysPluginController.java @@ -60,15 +60,15 @@ public Object addDo(@Param("code") String code, try { String name = tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf(".")).toLowerCase(); String p = Globals.AppRoot; - String f = Globals.AppUploadPath + "/plugin/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + name; + String f = Globals.AppUploadPath + "/plugin/" + R.UU32() + name; File file = new File(p + f); Files.createFileIfNoExists(file); - Files.write(f, tf.getInputStream()); - byte[] buf = Files.readBytes(file); + Files.write(file, tf.getInputStream()); IPlugin plugin; if (".jar".equals(name)) { - plugin = pluginMaster.buildFromJar(file, className, buf); + plugin = pluginMaster.buildFromJar(file, className); } else { + byte[] buf = Files.readBytes(file); plugin = pluginMaster.build(className, buf); } pluginMaster.register(code, plugin, args); @@ -92,7 +92,7 @@ public Object delete(String id) { try { Sys_plugin sysPlugin = sysPluginService.fetch(id); pluginMaster.remove(sysPlugin.getCode()); - Files.deleteFile(new File(Globals.AppRoot + sysPlugin.getPath())); + //被占用删不掉文件啊 Files.deleteFile(new File(Globals.AppRoot + sysPlugin.getPath())); sysPluginService.delete(id); return Result.success("system.success"); } catch (Exception e) { @@ -108,12 +108,12 @@ public Object enable(String id) { Sys_plugin sysPlugin = sysPluginService.fetch(id); String name = sysPlugin.getPath().substring(sysPlugin.getPath().indexOf(".")).toLowerCase(); File file = new File(Globals.AppRoot + sysPlugin.getPath()); - byte[] buf = Files.readBytes(file); String[] p = new String[]{}; IPlugin plugin; if (".jar".equals(name)) { - plugin = pluginMaster.buildFromJar(file, sysPlugin.getClassName(), buf); + plugin = pluginMaster.buildFromJar(file, sysPlugin.getClassName()); } else { + byte[] buf = Files.readBytes(file); plugin = pluginMaster.build(sysPlugin.getClassName(), buf); } if (!Strings.isBlank(sysPlugin.getArgs())) {