diff --git a/example/basic-example/basic-example-main/pom.xml b/example/basic-example/basic-example-main/pom.xml index 0d15f5c30157cbcdbe593e7a8f4a0d4fb999a7b8..af9add2398431ae9583be18e6a69e32b486b0f33 100644 --- a/example/basic-example/basic-example-main/pom.xml +++ b/example/basic-example/basic-example-main/pom.xml @@ -13,19 +13,20 @@ com.gitee.starblues basic-example-main - 2.1.3-RELEASE + 2.1.4-RELEASE jar 2.7.0 1.6 + 2.1.4-RELEASE com.gitee.starblues springboot-plugin-framework - ${project.version} + ${springboot-plugin-framework.version} diff --git a/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/rest/PluginResource.java b/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/rest/PluginResource.java index e26cf8714afac90743ce904c5d0b5378ca8f004b..bb54179c557fd847defaa937ae019c42c46fe01b 100644 --- a/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/rest/PluginResource.java +++ b/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/rest/PluginResource.java @@ -61,10 +61,10 @@ public class PluginResource { public String stop(@PathVariable("id") String id){ try { pluginOperator.stop(id); - return "plugin<" + id +"> stop success"; + return "plugin '" + id +"' stop success"; } catch (Exception e) { e.printStackTrace(); - return "plugin<" + id +"> stop failure : " + e.getMessage(); + return "plugin '" + id +"' stop failure. " + e.getMessage(); } } @@ -77,10 +77,10 @@ public class PluginResource { public String start(@PathVariable("id") String id){ try { pluginOperator.start(id); - return "plugin<" + id +"> start success"; + return "plugin '" + id +"' start success"; } catch (Exception e) { e.printStackTrace(); - return "plugin<" + id +"> start failure : " + e.getMessage(); + return "plugin '" + id +"' start failure. " + e.getMessage(); } } @@ -94,10 +94,10 @@ public class PluginResource { public String uninstall(@PathVariable("id") String id){ try { pluginOperator.uninstall(id); - return "plugin<" + id +"> uninstall success"; + return "plugin '" + id +"' uninstall success"; } catch (Exception e) { e.printStackTrace(); - return "plugin<" + id +"> uninstall failure : " + e.getMessage(); + return "plugin '" + id +"' uninstall failure. " + e.getMessage(); } } @@ -136,68 +136,53 @@ public class PluginResource { } - /** - * 上传插件的配置文件。注意: 该操作只适用于生产环境 - * @param multipartFile 上传文件 multipartFile - * @return 操作结果 - */ - @PostMapping("/uploadPluginConfigFile") - public String uploadConfig(@RequestParam("configFile") MultipartFile multipartFile){ - try { - pluginOperator.uploadConfigFile(multipartFile); - return "uploadConfig success"; - } catch (Exception e) { - e.printStackTrace(); - return "uploadConfig failure : " + e.getMessage(); - } - } - /** - * 通过插件id删除插件。注意: 该操作只适用于生产环境 + * 备份插件。注意: 该操作只适用于生产环境 * @param pluginId 插件id * @return 操作结果 */ - @DeleteMapping("/pluginId/{pluginId}") - public String deleteById(@PathVariable("pluginId") String pluginId){ + @PostMapping("/back/{pluginId}") + public String backupPlugin(@PathVariable("pluginId") String pluginId){ try { - pluginOperator.delete(pluginId); - return "deleteById success"; + pluginOperator.backupPlugin(pluginId, "testBack"); + return "backupPlugin success"; } catch (Exception e) { e.printStackTrace(); - return "deleteById failure : " + e.getMessage(); + return "backupPlugin failure : " + e.getMessage(); } } + /** - * 通过路径删除插件。注意: 该操作只适用于生产环境 - * @param pluginJarPath 插件jar路径 + * 上传插件的配置文件。注意: 该操作只适用于生产环境 + * @param multipartFile 上传文件 multipartFile * @return 操作结果 */ - @PostMapping("/path") - public String deleteByPath(@RequestParam("pluginJarPath") String pluginJarPath){ + @PostMapping("/uploadPluginConfigFile") + public String uploadConfig(@RequestParam("configFile") MultipartFile multipartFile){ try { - pluginOperator.delete(Paths.get(pluginJarPath)); - return "deleteByPath success"; + pluginOperator.uploadConfigFile(multipartFile); + return "uploadPluginConfigFile success"; } catch (Exception e) { e.printStackTrace(); - return "deleteByPath failure : " + e.getMessage(); + return "uploadPluginConfigFile failure : " + e.getMessage(); } } /** - * 备份插件。注意: 该操作只适用于生产环境 - * @param pluginId 插件id + * 通过路径安装配置文件。注意: 该操作只适用于生产环境 + * @param path 配置文件路径 * @return 操作结果 */ - @PostMapping("/back/{pluginId}") - public String backupPlugin(@PathVariable("pluginId") String pluginId){ + @PostMapping("/installPluginConfig") + public String installPluginConfig(@RequestParam("path") String path){ try { - pluginOperator.backupPlugin(pluginId, "testBack"); - return "backupPlugin success"; + pluginOperator.installConfigFile(Paths.get(path)); + return "installPluginConfig success"; } catch (Exception e) { e.printStackTrace(); - return "backupPlugin failure : " + e.getMessage(); + return "installPluginConfig failure : " + e.getMessage(); } } diff --git a/example/basic-example/basic-example-runner/pom.xml b/example/basic-example/basic-example-runner/pom.xml index 334b1e71f2cae83cf0caf45864b2c7890c5c79ef..51509a9c065d60e4566eea1796ee587dd94b8100 100644 --- a/example/basic-example/basic-example-runner/pom.xml +++ b/example/basic-example/basic-example-runner/pom.xml @@ -14,7 +14,7 @@ com.gitee.starblues basic-example-runner - 2.1.3-RELEASE + 2.1.4-RELEASE pom diff --git a/example/basic-example/plugins/basic-example-plugin1/plugin.properties b/example/basic-example/plugins/basic-example-plugin1/plugin.properties index d88dc4c8909a5aa090f80222cd64c5215fc03e64..d9ff7d8fa856bb0b5cc2377cf967358be8428155 100644 --- a/example/basic-example/plugins/basic-example-plugin1/plugin.properties +++ b/example/basic-example/plugins/basic-example-plugin1/plugin.properties @@ -1,4 +1,4 @@ plugin.id=basic-example-plugin1 plugin.class=com.basic.example.plugin1.DefinePlugin -plugin.version=2.1.3-RELEASE +plugin.version=2.1.4-RELEASE plugin.provider=StarBlues \ No newline at end of file diff --git a/example/basic-example/plugins/basic-example-plugin1/pom.xml b/example/basic-example/plugins/basic-example-plugin1/pom.xml index 69428eb293a9ce63bcc4dbee376d3e6454990dc3..6343f5a9941aacd21ee2629715ec8b5efaea7fbb 100644 --- a/example/basic-example/plugins/basic-example-plugin1/pom.xml +++ b/example/basic-example/plugins/basic-example-plugin1/pom.xml @@ -8,12 +8,12 @@ com.gitee.starblues basic-example-plugin-parent - 2.1.3-RELEASE + 2.1.4-RELEASE ../pom.xml basic-example-plugin1 - 2.1.3-RELEASE + 2.1.4-RELEASE jar diff --git a/example/basic-example/plugins/basic-example-plugin2/plugin.properties b/example/basic-example/plugins/basic-example-plugin2/plugin.properties index 66410a19c9ec9f37a00b146a763892eba4ecf5b8..96f2d22216fc662224d04cc36143b9a887c4e16e 100644 --- a/example/basic-example/plugins/basic-example-plugin2/plugin.properties +++ b/example/basic-example/plugins/basic-example-plugin2/plugin.properties @@ -1,4 +1,4 @@ plugin.id=basic-example-plugin2 plugin.class=com.basic.example.plugin2.DefinePlugin -plugin.version=2.1.3-RELEASE +plugin.version=2.1.4-RELEASE plugin.provider=StarBlues \ No newline at end of file diff --git a/example/basic-example/plugins/basic-example-plugin2/pom.xml b/example/basic-example/plugins/basic-example-plugin2/pom.xml index 83d634965ce8a4bde2da0063320db7cd22f15dac..a109b8ee7bcffde8b5c6e22d8658f37a96b79edf 100644 --- a/example/basic-example/plugins/basic-example-plugin2/pom.xml +++ b/example/basic-example/plugins/basic-example-plugin2/pom.xml @@ -8,12 +8,12 @@ com.gitee.starblues basic-example-plugin-parent - 2.1.3-RELEASE + 2.1.4-RELEASE ../pom.xml basic-example-plugin2 - 2.1.3-RELEASE + 2.1.4-RELEASE jar diff --git a/example/basic-example/plugins/pom.xml b/example/basic-example/plugins/pom.xml index aaf8c435f4b8b089cbdaf7511b444cc3c87d547a..8b8e99ac414a29c4ebabaa236cd4c3e16383e198 100644 --- a/example/basic-example/plugins/pom.xml +++ b/example/basic-example/plugins/pom.xml @@ -7,7 +7,7 @@ com.gitee.starblues basic-example-plugin-parent - 2.1.3-RELEASE + 2.1.4-RELEASE pom diff --git a/example/basic-example/pom.xml b/example/basic-example/pom.xml index 4aa3fd5693a81b20bc2a6030ef523970ebb059e8..07a3308b50ed65b8f073a50ede5eb1ed5133102a 100644 --- a/example/basic-example/pom.xml +++ b/example/basic-example/pom.xml @@ -6,7 +6,7 @@ com.gitee.starblues basic-example - 2.1.3-RELEASE + 2.1.4-RELEASE pom 基本案例 diff --git a/example/integration-mybatis/integration-mybatis-main/pom.xml b/example/integration-mybatis/integration-mybatis-main/pom.xml index 901a70423c2da0acdc692b6fed76e40db7398e4e..695dae300d91cd7fe5744f80a1f4405e01e03285 100644 --- a/example/integration-mybatis/integration-mybatis-main/pom.xml +++ b/example/integration-mybatis/integration-mybatis-main/pom.xml @@ -14,13 +14,14 @@ com.gitee.starblues integration-mybatis-main - 2.1.3-RELEASE + 2.1.4-RELEASE jar 主程序模块 + 2.1.4-RELEASE + 2.1.4-RELEASE 2.0.1 - 2.1.3-RELEASE 2.7.0 1.6 @@ -31,7 +32,7 @@ com.gitee.starblues springboot-plugin-framework - ${project.version} + ${springboot-plugin-framework.version} diff --git a/example/integration-mybatis/integration-mybatis-main/src/main/java/com/mybatis/main/rest/PluginResource.java b/example/integration-mybatis/integration-mybatis-main/src/main/java/com/mybatis/main/rest/PluginResource.java index cdaa874431e7044f7513fe6c14f99bbdeb1b8cc3..917e33b7e1602db878046c457495fa781a745882 100644 --- a/example/integration-mybatis/integration-mybatis-main/src/main/java/com/mybatis/main/rest/PluginResource.java +++ b/example/integration-mybatis/integration-mybatis-main/src/main/java/com/mybatis/main/rest/PluginResource.java @@ -62,10 +62,10 @@ public class PluginResource { public String stop(@PathVariable("id") String id){ try { pluginOperator.stop(id); - return "plugin<" + id +"> stop success"; + return "plugin '" + id +"' stop success"; } catch (Exception e) { e.printStackTrace(); - return "plugin<" + id +"> stop failure : " + e.getMessage(); + return "plugin '" + id +"' stop failure. " + e.getMessage(); } } @@ -78,10 +78,10 @@ public class PluginResource { public String start(@PathVariable("id") String id){ try { pluginOperator.start(id); - return "plugin<" + id +"> start success"; + return "plugin '" + id +"' start success"; } catch (Exception e) { e.printStackTrace(); - return "plugin<" + id +"> start failure : " + e.getMessage(); + return "plugin '" + id +"' start failure. " + e.getMessage(); } } @@ -95,10 +95,10 @@ public class PluginResource { public String uninstall(@PathVariable("id") String id){ try { pluginOperator.uninstall(id); - return "plugin<" + id +"> uninstall success"; + return "plugin '" + id +"' uninstall success"; } catch (Exception e) { e.printStackTrace(); - return "plugin<" + id +"> uninstall failure : " + e.getMessage(); + return "plugin '" + id +"' uninstall failure. " + e.getMessage(); } } @@ -154,38 +154,6 @@ public class PluginResource { } - /** - * 通过插件id删除插件。注意: 该操作只适用于生产环境 - * @param pluginId 插件id - * @return 操作结果 - */ - @DeleteMapping("/pluginId/{pluginId}") - public String deleteById(@PathVariable("pluginId") String pluginId){ - try { - pluginOperator.delete(pluginId); - return "deleteById success"; - } catch (Exception e) { - e.printStackTrace(); - return "deleteById failure : " + e.getMessage(); - } - } - - /** - * 通过路径删除插件。注意: 该操作只适用于生产环境 - * @param pluginJarPath 插件jar路径 - * @return 操作结果 - */ - @PostMapping("/path") - public String deleteByPath(@RequestParam("pluginJarPath") String pluginJarPath){ - try { - pluginOperator.delete(Paths.get(pluginJarPath)); - return "deleteByPath success"; - } catch (Exception e) { - e.printStackTrace(); - return "deleteByPath failure : " + e.getMessage(); - } - } - /** * 备份插件。注意: 该操作只适用于生产环境 * @param pluginId 插件id diff --git a/example/integration-mybatis/integration-mybatis-plugin-parent/pom.xml b/example/integration-mybatis/integration-mybatis-plugin-parent/pom.xml index c0c4addc9275b4f3909e7ca8a9dc50fb63904e1d..d15419e9c2cd802816f3e0f7d191d34cfb439675 100644 --- a/example/integration-mybatis/integration-mybatis-plugin-parent/pom.xml +++ b/example/integration-mybatis/integration-mybatis-plugin-parent/pom.xml @@ -7,7 +7,7 @@ com.gitee.starblues integration-mybatis-plugin-parent - 2.1.3-RELEASE + 2.1.4-RELEASE pom diff --git a/example/integration-mybatis/integration-mybatis-runner/pom.xml b/example/integration-mybatis/integration-mybatis-runner/pom.xml index 6fb9f0ce10b1be901b258d16ce0eba008059e712..2f6131ab96d24e658f34ce11c1a5a70d7e3d9a07 100644 --- a/example/integration-mybatis/integration-mybatis-runner/pom.xml +++ b/example/integration-mybatis/integration-mybatis-runner/pom.xml @@ -14,7 +14,7 @@ com.gitee.starblues integration-mybatis-runner - 2.1.3-RELEASE + 2.1.4-RELEASE jar 启动程序模块。将启动类配置到该模块下 diff --git a/example/integration-mybatis/plugins/integration-mybatis-plugin1/plugin.properties b/example/integration-mybatis/plugins/integration-mybatis-plugin1/plugin.properties index 5c4ed48bd6893d7c1d3cab6fe46c2b9d950c7005..99109b79d17592d0a4a7138021079b3db59519a7 100644 --- a/example/integration-mybatis/plugins/integration-mybatis-plugin1/plugin.properties +++ b/example/integration-mybatis/plugins/integration-mybatis-plugin1/plugin.properties @@ -1,4 +1,4 @@ plugin.id=integration-mybatis-plugin1 plugin.class=com.mybatis.plugin1.ExamplePlugin1 -plugin.version=2.1.3-RELEASE +plugin.version=2.1.4-RELEASE plugin.provider=StarBlues \ No newline at end of file diff --git a/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml b/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml index d98b889e68f9d40d07fe6381b2e262a9bc820d60..af20f000186bd564d03b7d76e3f8c0b10c3036ac 100644 --- a/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml +++ b/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml @@ -8,12 +8,12 @@ com.gitee.starblues integration-mybatis-plugin-parent - 2.1.3-RELEASE + 2.1.4-RELEASE ../../integration-mybatis-plugin-parent integration-mybatis-plugin1 - 2.1.3-RELEASE + 2.1.4-RELEASE jar @@ -21,10 +21,6 @@ com.mybatis.plugin1.ExamplePlugin1 ${project.version} StarBlues - - 2.8.2 - 2.0.1 - 2.1.3-RELEASE diff --git a/example/integration-mybatis/plugins/integration-mybatis-plugin2/plugin.properties b/example/integration-mybatis/plugins/integration-mybatis-plugin2/plugin.properties index edb904a959890a47155953afcecfd6a66fc9bef4..f65a59d2c73bb5546e20c25df84c3ca212ef8d36 100644 --- a/example/integration-mybatis/plugins/integration-mybatis-plugin2/plugin.properties +++ b/example/integration-mybatis/plugins/integration-mybatis-plugin2/plugin.properties @@ -1,4 +1,4 @@ plugin.id=integration-mybatis-plugin2 plugin.class=com.mybatis.plugin2.ExamplePlugin2 -plugin.version=2.1.3-RELEASE +plugin.version=2.1.4-RELEASE plugin.provider=StarBlues \ No newline at end of file diff --git a/example/integration-mybatis/plugins/integration-mybatis-plugin2/pom.xml b/example/integration-mybatis/plugins/integration-mybatis-plugin2/pom.xml index f3f645b39fdf6dd2a6e819c673d5ce1efda302c0..dd08cc324cf4192fe417a424b730e90728727ba0 100644 --- a/example/integration-mybatis/plugins/integration-mybatis-plugin2/pom.xml +++ b/example/integration-mybatis/plugins/integration-mybatis-plugin2/pom.xml @@ -8,12 +8,12 @@ com.gitee.starblues integration-mybatis-plugin-parent - 2.1.3-RELEASE + 2.1.4-RELEASE ../../integration-mybatis-plugin-parent integration-mybatis-plugin2 - 2.1.3-RELEASE + 2.1.4-RELEASE jar @@ -21,10 +21,6 @@ com.mybatis.plugin2.ExamplePlugin2 ${project.version} StarBlues - - 2.8.2 - 2.0.1 - 2.1.3-RELEASE diff --git a/example/integration-mybatis/pom.xml b/example/integration-mybatis/pom.xml index 58ef949440a16cae79387d65c8e7ae68d4b49db4..606631d8c4c84eee52af66ef88b98f1394bdd216 100644 --- a/example/integration-mybatis/pom.xml +++ b/example/integration-mybatis/pom.xml @@ -7,7 +7,7 @@ com.gitee.starblues integration-mybatis - 2.1.3-RELEASE + 2.1.4-RELEASE pom 集成mybatis案例 diff --git a/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml b/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml index a9059791cb9b3286907a188527e1acdff10328da..ab420400b00088a2d7648e5d81c1625bfe959668 100644 --- a/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml +++ b/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml @@ -13,7 +13,7 @@ com.gitee.starblues - 2.1.3-RELEASE + 2.1.4-RELEASE integration-mybatisplus-main jar 集成mybatis-plus 案例--主程序 @@ -26,7 +26,9 @@ 2.0.1 3.2.0 - 2.1.3-RELEASE + + 2.1.4-RELEASE + 2.1.4-RELEASE 2.7.0 1.6 @@ -35,7 +37,7 @@ com.gitee.starblues springboot-plugin-framework - ${project.version} + ${springboot-plugin-framework.version} diff --git a/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/plugin.properties b/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/plugin.properties index e4ccdd01f332cc18e215de8de6c0d2e7df14e5da..61c686280b883184ac6b9c8b224b40a3f2dca7f5 100644 --- a/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/plugin.properties +++ b/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/plugin.properties @@ -1,4 +1,4 @@ plugin.id=integration-mybatisplus-plugin plugin.class=com.mybatisplus.plugin.MybatisPlusPlugin -plugin.version=2.1.3-RELEASE +plugin.version=2.1.4-RELEASE plugin.provider=StarBlues \ No newline at end of file diff --git a/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/pom.xml b/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/pom.xml index a8ec8a6284f69caebf8707e78054062098536dd4..ff0e50c1c9d349e8868ca500d735be02fb47b336 100644 --- a/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/pom.xml +++ b/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/pom.xml @@ -6,7 +6,7 @@ com.gitee.starblues integration-mybatisplus-plugin - 2.1.3-RELEASE + 2.1.4-RELEASE jar diff --git a/example/integration-mybatisplus/pom.xml b/example/integration-mybatisplus/pom.xml index f89d04bd654d883371cc3cd3cc736e21ae1c2298..7f7bcc30b16a2cfde478e1d71ec9eed460c7abe1 100644 --- a/example/integration-mybatisplus/pom.xml +++ b/example/integration-mybatisplus/pom.xml @@ -6,7 +6,7 @@ com.gitee.starblues integration-mybatisplus - 2.1.3-RELEASE + 2.1.4-RELEASE pom 集成mybatis-plus案例 diff --git a/example/pom.xml b/example/pom.xml index ca8e07e261fc19ff5b489405b52d50c4d699e2d8..42b8d7ed03fd036d3d5065255a9035b64e793905 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -6,7 +6,7 @@ com.gitee.starblues springboot-plugin-framework-example - 2.1.3-RELEASE + 2.1.4-RELEASE pom diff --git a/pom.xml b/pom.xml index c8bfe7050b583c6dc4fdc5501cfc11df146be23c..1770ff02d98acc99bfc5adeb0b702031f74147d8 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.gitee.starblues springboot-plugin-framework-parent pom - 2.1.3-RELEASE + 2.1.4-RELEASE spring boot 插件开发集成包 diff --git a/springboot-plugin-framework-extension/pom.xml b/springboot-plugin-framework-extension/pom.xml index 8b8aaea4b70d287c7e0786c742e9cb524183f523..07c05d40be6b934bbb16f9df525354b7af137db2 100644 --- a/springboot-plugin-framework-extension/pom.xml +++ b/springboot-plugin-framework-extension/pom.xml @@ -9,7 +9,7 @@ com.gitee.starblues springboot-plugin-framework-extension pom - 2.1.3-RELEASE + 2.1.4-RELEASE spring boot 插件式开发集成包--扩展模块 diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml index de6089f17a06bb6659f187793687a141bb005654..0536374e5aa5444f1e92cfa027971e8c0121b5a0 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml @@ -13,7 +13,7 @@ com.gitee.starblues springboot-plugin-framework-extension-mybatis - 2.1.3-RELEASE + 2.1.4-RELEASE jar 插件扩展-spring boot mybatis 集成扩展 @@ -64,7 +64,7 @@ 3.1.0 1.6 - 2.1.3-RELEASE + 2.1.4-RELEASE 2.0.1 3.2.0 diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/PluginMybatisXmlLoader.java b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/PluginMybatisXmlLoader.java index 01fd4d4b2e3b155ef5456ff29d2d7dad7680c800..53978edef0c5aeea9e76b1a0b678c8fe30189aab 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/PluginMybatisXmlLoader.java +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/PluginMybatisXmlLoader.java @@ -44,9 +44,8 @@ public class PluginMybatisXmlLoader implements PluginResourceLoader { @Override public List load(BasePlugin basePlugin) throws Exception { if(!(basePlugin instanceof SpringBootMybatisConfig)){ - String error = "Plugin<" + basePlugin.getClass().getName() + - "> not implements SpringBootMybatisConfig, Please implements SpringBootMybatisConfig interface"; - LOG.error(error); + LOG.warn("Plugin <{}> not implements SpringBootMybatisConfig, If you need to use mybatis in the plugin," + + "Please implements SpringBootMybatisConfig interface", basePlugin.getClass().getName()); return null; } SpringBootMybatisConfig springBootMybatisConfig = (SpringBootMybatisConfig) basePlugin; diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/PluginMybatisXmlProcessor.java b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/PluginMybatisXmlProcessor.java index 7c0c9886c34cba7ca692bbe5f549991946fd9edb..0bd61100fca77bd8db9b120ca17842a9b50d8383 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/PluginMybatisXmlProcessor.java +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/PluginMybatisXmlProcessor.java @@ -1,6 +1,5 @@ package com.gitee.starblues.extension.mybatis; -import com.gitee.starblues.exception.PluginFactoryException; import com.gitee.starblues.extension.mybatis.utils.MybatisXmlProcess; import com.gitee.starblues.realize.BasePlugin; import com.gitee.starblues.factory.PluginRegistryInfo; @@ -54,14 +53,9 @@ public class PluginMybatisXmlProcessor implements PluginPipeProcessorExtend { if(pluginResources == null || pluginResources.isEmpty()){ return; } - try { - boolean change = mybatisXmlProcess.isChange(pluginResources); - if(change){ - mybatisXmlProcess.loadXmlResource(pluginResources, pluginWrapper.getPluginClassLoader()); - } - } catch (Exception e){ - e.printStackTrace(); - throw new PluginFactoryException("load mybatis xml error : " + e.getMessage()); + boolean change = mybatisXmlProcess.isChange(pluginResources); + if(change){ + mybatisXmlProcess.loadXmlResource(pluginResources, pluginWrapper.getPluginClassLoader()); } } diff --git a/springboot-plugin-framework/pom.xml b/springboot-plugin-framework/pom.xml index 1ed1d4d71185b060966b8a8c844930db83cdb922..1de711cdad556e9b5cd80e8cf536f61cb721427e 100644 --- a/springboot-plugin-framework/pom.xml +++ b/springboot-plugin-framework/pom.xml @@ -13,7 +13,7 @@ com.gitee.starblues springboot-plugin-framework jar - 2.1.3-RELEASE + 2.1.4-RELEASE spring boot 插件式开发集成包 diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/ConfigurationParseException.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/ConfigurationParseException.java deleted file mode 100644 index 4462b0c66def97cd965729e9a924ab3edac81cf1..0000000000000000000000000000000000000000 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/ConfigurationParseException.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.gitee.starblues.exception; - -/** - * 配置文件解析异常 - * @author zhangzhuo - * @version 1.0 - */ -public class ConfigurationParseException extends Exception{ - - public ConfigurationParseException() { - super(); - } - - public ConfigurationParseException(String message) { - super(message); - } - - public ConfigurationParseException(String message, Throwable cause) { - super(message, cause); - } - - public ConfigurationParseException(Throwable cause) { - super(cause); - } - - protected ConfigurationParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/PipProcessorException.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/PipProcessorException.java deleted file mode 100644 index bc2160d7e951e50b1217ab9da170be0df02344fe..0000000000000000000000000000000000000000 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/PipProcessorException.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.gitee.starblues.exception; - -/** - * 插件pip处理异常 - * - * @author zhangzhuo - * @version 1.0 - */ -public class PipProcessorException extends PluginFactoryException{ - - public PipProcessorException() { - super(); - } - - public PipProcessorException(String message) { - super(message); - } - - public PipProcessorException(String message, Throwable cause) { - super(message, cause); - } - - public PipProcessorException(Throwable cause) { - super(cause); - } - - protected PipProcessorException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/PluginBeanFactoryException.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/PluginBeanFactoryException.java deleted file mode 100644 index 91a414a7da03d0fe7cf3ea5101d85df3c7eb2a95..0000000000000000000000000000000000000000 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/PluginBeanFactoryException.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.gitee.starblues.exception; - -/** - * 插件bean注册异常 - * @author zhangzhuo - * @version 1.0 - */ -public class PluginBeanFactoryException extends PluginFactoryException{ - - public PluginBeanFactoryException() { - super(); - } - - public PluginBeanFactoryException(String message) { - super(message); - } - - public PluginBeanFactoryException(String message, Throwable cause) { - super(message, cause); - } - - public PluginBeanFactoryException(Throwable cause) { - super(cause); - } - - protected PluginBeanFactoryException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/PluginFactoryException.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/PluginFactoryException.java deleted file mode 100644 index f26decfa70c625b65c4d7c55873dbac8572b2a75..0000000000000000000000000000000000000000 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/exception/PluginFactoryException.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.gitee.starblues.exception; - -/** - * 插件工厂异常 - * - * @author zhangzhuo - * @version 1.0 - */ -public class PluginFactoryException extends Exception{ - - public PluginFactoryException() { - super(); - } - - public PluginFactoryException(String message) { - super(message); - } - - public PluginFactoryException(String message, Throwable cause) { - super(message, cause); - } - - public PluginFactoryException(Throwable cause) { - super(cause); - } - - public PluginFactoryException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/DefaultPluginFactory.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/DefaultPluginFactory.java index 1aa92b295293a5f65cba72097fe23046733023a5..7dc8313b621c95f3818c1591241dca0daddc765c 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/DefaultPluginFactory.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/DefaultPluginFactory.java @@ -8,8 +8,6 @@ import com.gitee.starblues.integration.listener.PluginListener; import com.gitee.starblues.integration.listener.PluginListenerFactory; import com.gitee.starblues.utils.AopUtils; import org.pf4j.PluginWrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.GenericApplicationContext; @@ -26,7 +24,6 @@ import java.util.Map; */ public class DefaultPluginFactory implements PluginFactory { - private static final Logger log = LoggerFactory.getLogger(DefaultPluginFactory.class); /** * 注册的插件集合 @@ -95,20 +92,20 @@ public class DefaultPluginFactory implements PluginFactory { public synchronized PluginFactory unRegistry(String pluginId) throws Exception { PluginRegistryInfo registerPluginInfo = registerPluginInfoMap.get(pluginId); if(registerPluginInfo == null){ - throw new IllegalArgumentException("Not found plugin " + pluginId + " registered"); + throw new Exception("Not found plugin " + pluginId + " registered"); } if(!buildContainer.isEmpty() && buildType == 1){ - throw new IllegalAccessException("Unable to UnRegistry operate. Because there's no build"); + throw new Exception("Unable to UnRegistry operate. Because there's no build"); } try { pluginProcessor.unRegistry(registerPluginInfo); - registerPluginInfoMap.remove(pluginId); buildContainer.add(registerPluginInfo); return this; } catch (Exception e) { pluginListenerFactory.failure(pluginId, e); throw e; } finally { + registerPluginInfoMap.remove(pluginId); buildType = 2; } } @@ -116,7 +113,7 @@ public class DefaultPluginFactory implements PluginFactory { @Override public synchronized void build() throws Exception { if(buildContainer.isEmpty()){ - throw new IllegalAccessException("No Found registered or unRegistry plugin. Unable to build"); + throw new Exception("No Found registered or unRegistry plugin. Unable to build"); } // 构建注册的Class插件监听者 pluginListenerFactory.buildListenerClass(applicationContext); diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/PluginRegistryInfo.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/PluginRegistryInfo.java index 9d74d0b6dcb03cbb11d27db2ed4b3bf0eef81d34..9e150d4d9a4b0091998837c581042f560688f68e 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/PluginRegistryInfo.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/PluginRegistryInfo.java @@ -1,6 +1,8 @@ package com.gitee.starblues.factory; import com.gitee.starblues.realize.BasePlugin; +import org.pf4j.Plugin; +import org.pf4j.PluginState; import org.pf4j.PluginWrapper; import java.util.*; @@ -14,10 +16,7 @@ import java.util.concurrent.ConcurrentHashMap; */ public class PluginRegistryInfo { - /** - * 全局扩展信息 - */ - private static Map globalExtensionMap = new ConcurrentHashMap<>(); + /** * 扩展存储项 @@ -135,28 +134,5 @@ public class PluginRegistryInfo { - /** - * 添加全局扩展数据 - * @param key 扩展的key - * @param value 扩展值 - */ - public static synchronized void addGlobalExtension(String key, Object value){ - globalExtensionMap.put(key, value); - } - - /** - * 获取全局扩展值 - * @param key 全局扩展的key - * @param 返回值泛型 - * @return 扩展值 - */ - public static synchronized T getGlobalExtension(String key){ - Object o = globalExtensionMap.get(key); - if(o == null){ - return null; - } else { - return (T) o; - } - } } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/BasicBeanProcessor.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/BasicBeanProcessor.java index 1ed1e8d71b309d5e7a7b0ea6546f30c40393d269..5def94a8b8aba9139feea7cbccb6261adc40c89d 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/BasicBeanProcessor.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/BasicBeanProcessor.java @@ -6,12 +6,13 @@ import com.gitee.starblues.factory.process.pipe.PluginPipeProcessor; import com.gitee.starblues.factory.process.pipe.classs.group.ComponentGroup; import com.gitee.starblues.factory.process.pipe.classs.group.ConfigurationGroup; import com.gitee.starblues.factory.process.pipe.classs.group.RepositoryGroup; +import com.gitee.starblues.utils.GlobalRegistryInfo; +import com.gitee.starblues.utils.PluginOperatorInfo; import org.springframework.aop.Advisor; import org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ApplicationContext; -import org.springframework.core.annotation.AnnotationUtils; import java.util.HashSet; import java.util.List; @@ -85,7 +86,7 @@ public class BasicBeanProcessor implements PluginPipeProcessor { if(aClass == null){ continue; } - String namePrefix = resolveAopClass(aClass); + String namePrefix = resolveAopClass(pluginId, aClass); String beanName = springBeanRegister.register(pluginId, namePrefix, aClass); beanNames.add(beanName); } @@ -103,23 +104,34 @@ public class BasicBeanProcessor implements PluginPipeProcessor { * @param aClass 当前要处理的类 * @return 返回代理类的bean名称前缀 */ - private String resolveAopClass(Class aClass){ + private String resolveAopClass(String pluginId, Class aClass){ + PluginOperatorInfo operatorPluginInfo = GlobalRegistryInfo.getPluginInstallNum(pluginId); + if(operatorPluginInfo == null){ + // 操作插件信息为空, 直接返回空 + return null; + } List advisorBeans = helper.findAdvisorBeans(); List advisorsThatCanApply = AopUtils.findAdvisorsThatCanApply(advisorBeans, aClass); if(advisorsThatCanApply.isEmpty()){ // 如果不是代理类, 则返回 null return null; + } + // 是代理类 + Object o = GlobalRegistryInfo.getExtension(AOP_BEAN_NAME_INC_NUM); + AtomicInteger atomicInteger = null; + if(o instanceof AtomicInteger){ + atomicInteger = (AtomicInteger) o; } else { - Object o = PluginRegistryInfo.getGlobalExtension(AOP_BEAN_NAME_INC_NUM); - AtomicInteger atomicInteger = null; - if(o instanceof AtomicInteger){ - atomicInteger = (AtomicInteger) o; - } else { - atomicInteger = new AtomicInteger(0); - PluginRegistryInfo.addGlobalExtension(AOP_BEAN_NAME_INC_NUM, atomicInteger); - } - // 是代理类 - return String.valueOf(atomicInteger.getAndIncrement()); + atomicInteger = new AtomicInteger(-1); + GlobalRegistryInfo.addExtension(AOP_BEAN_NAME_INC_NUM, atomicInteger); + } + PluginOperatorInfo.OperatorType operatorType = operatorPluginInfo.getOperatorType(); + if(operatorType == PluginOperatorInfo.OperatorType.INSTALL){ + // 现在的操作为安装操作, 则重新给代理类设置递增的 bean 名称编号 + return String.valueOf(atomicInteger.incrementAndGet()); + } else { + // 现在时启动操作, 则复用上次的编号 + return String.valueOf(atomicInteger.get()); } } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/ConfigBeanProcessor.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/ConfigBeanProcessor.java index 72be7322f42a27236e0170d94f65f993f5242b21..cf904bf479a213d281942b6ad96b85d9af7d33a2 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/ConfigBeanProcessor.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/ConfigBeanProcessor.java @@ -1,9 +1,6 @@ package com.gitee.starblues.factory.process.pipe.bean; import com.gitee.starblues.annotation.ConfigDefinition; -import com.gitee.starblues.exception.ConfigurationParseException; -import com.gitee.starblues.exception.PluginBeanFactoryException; -import com.gitee.starblues.integration.IntegrationConfiguration; import com.gitee.starblues.factory.PluginInfoContainer; import com.gitee.starblues.factory.PluginRegistryInfo; import com.gitee.starblues.factory.process.pipe.PluginPipeProcessor; @@ -11,13 +8,12 @@ import com.gitee.starblues.factory.process.pipe.bean.configuration.Configuration import com.gitee.starblues.factory.process.pipe.bean.configuration.PluginConfigDefinition; import com.gitee.starblues.factory.process.pipe.bean.configuration.YamlConfigurationParser; import com.gitee.starblues.factory.process.pipe.classs.group.ConfigDefinitionGroup; +import com.gitee.starblues.integration.IntegrationConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.RestController; import java.util.HashSet; import java.util.List; @@ -32,7 +28,6 @@ public class ConfigBeanProcessor implements PluginPipeProcessor { private static final String KEY = "ConfigBeanProcessor"; - private final Logger LOG = LoggerFactory.getLogger(this.getClass()); private final ConfigurationParser configurationParser; private final DefaultListableBeanFactory defaultListableBeanFactory; @@ -93,25 +88,19 @@ public class ConfigBeanProcessor implements PluginPipeProcessor { } String fileName = configDefinition.value(); if(StringUtils.isEmpty(fileName)){ - throw new Exception(aClass.getName() + " configDefinition value is null"); + throw new IllegalArgumentException(aClass.getName() + " configDefinition value is null"); } - try { - PluginConfigDefinition pluginConfigDefinition = - new PluginConfigDefinition(fileName, aClass); - Object parseObject = configurationParser.parse(pluginRegistryInfo.getBasePlugin(), pluginConfigDefinition); - String name = configDefinition.name(); - if(StringUtils.isEmpty(name)){ - name = aClass.getName(); - } - if(!defaultListableBeanFactory.containsSingleton(name)){ - defaultListableBeanFactory.registerSingleton(name, parseObject); - } - return name; - } catch (ConfigurationParseException e) { - e.printStackTrace(); - String errorMsg = "parse config <" + aClass.getName() + "> error,errorMsg : " + e.getMessage(); - throw new Exception(errorMsg, e); + PluginConfigDefinition pluginConfigDefinition = + new PluginConfigDefinition(fileName, aClass); + Object parseObject = configurationParser.parse(pluginRegistryInfo.getBasePlugin(), pluginConfigDefinition); + String name = configDefinition.name(); + if(StringUtils.isEmpty(name)){ + name = aClass.getName(); + } + if(!defaultListableBeanFactory.containsSingleton(name)){ + defaultListableBeanFactory.registerSingleton(name, parseObject); } + return name; } } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/PluginBeanRegister.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/PluginBeanRegister.java index e766f4a6b10d9faa63bfae8ddd46f63cc8de3abb..d13094b7980c10c170ac37dca80273e7fdb5d519 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/PluginBeanRegister.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/PluginBeanRegister.java @@ -1,6 +1,5 @@ package com.gitee.starblues.factory.process.pipe.bean; -import com.gitee.starblues.exception.PluginBeanFactoryException; import com.gitee.starblues.factory.PluginRegistryInfo; /** @@ -22,17 +21,17 @@ public interface PluginBeanRegister { * 注册插件中的bane * @param registerPluginInfo 插件信息 * @return 返回注册的bean的标识。卸载时,会将该参数传入 - * @throws PluginBeanFactoryException 插件bean工厂异常 + * @throws Exception 插件bean工厂异常 */ - T registry(PluginRegistryInfo registerPluginInfo) throws PluginBeanFactoryException; + T registry(PluginRegistryInfo registerPluginInfo) throws Exception; /** * 卸载插件中的bean * @param registerPluginInfo 插件信息 * @param t 注册时返回的参数 - * @throws PluginBeanFactoryException 插件bean工厂异常 + * @throws Exception 插件bean工厂异常 */ - void unRegistry(PluginRegistryInfo registerPluginInfo, T t) throws PluginBeanFactoryException; + void unRegistry(PluginRegistryInfo registerPluginInfo, T t) throws Exception; } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/AbstractConfigurationParser.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/AbstractConfigurationParser.java index 044faf2e1ea89910457ba1311928ad019a045c3a..3634ebb2b08c42290733a52a9be601f4e8c81adf 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/AbstractConfigurationParser.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/AbstractConfigurationParser.java @@ -1,6 +1,5 @@ package com.gitee.starblues.factory.process.pipe.bean.configuration; -import com.gitee.starblues.exception.ConfigurationParseException; import com.gitee.starblues.integration.IntegrationConfiguration; import com.gitee.starblues.loader.PluginResourceLoader; import com.gitee.starblues.loader.load.PluginConfigFileLoader; @@ -25,36 +24,32 @@ public abstract class AbstractConfigurationParser implements ConfigurationParser } @Override - public Object parse(BasePlugin basePlugin, PluginConfigDefinition pluginConfigDefinition) throws ConfigurationParseException { + public Object parse(BasePlugin basePlugin, PluginConfigDefinition pluginConfigDefinition) throws Exception { Class configClass = pluginConfigDefinition.getConfigClass(); if(pluginConfigDefinition.getConfigClass() == null){ - throw new ConfigurationParseException("pluginConfigDefinition : " + pluginConfigDefinition + " " + + throw new IllegalArgumentException("pluginConfigDefinition : " + pluginConfigDefinition + " " + "configClass can not be null"); } String fileName = pluginConfigDefinition.getFileName(); if(pluginConfigDefinition.getFileName() == null || "".equals(pluginConfigDefinition.getFileName())){ - throw new ConfigurationParseException("pluginConfigDefinition : " + pluginConfigDefinition + " " + + throw new IllegalArgumentException("pluginConfigDefinition : " + pluginConfigDefinition + " " + "fileName can not be empty"); } - try { - PluginResourceLoader pluginResourceLoader = new PluginConfigFileLoader( - configuration.pluginConfigFilePath(), - fileName, - configuration.environment() - ); - List resources = pluginResourceLoader.load(basePlugin); - if(resources.isEmpty() || resources.size() != 1){ - return null; - } - Object o = parse(resources.get(0), configClass); - if(o == null){ - return configClass.newInstance(); - } - return o; - } catch (Exception e) { - throw new ConfigurationParseException("Parse Plugin Config Failure" + e.getMessage(),e); + PluginResourceLoader pluginResourceLoader = new PluginConfigFileLoader( + configuration.pluginConfigFilePath(), + fileName, + configuration.environment() + ); + List resources = pluginResourceLoader.load(basePlugin); + if(resources.isEmpty() || resources.size() != 1){ + return null; } + Object o = parse(resources.get(0), configClass); + if(o == null){ + return configClass.newInstance(); + } + return o; } @@ -63,10 +58,10 @@ public abstract class AbstractConfigurationParser implements ConfigurationParser * @param resource 配置文件的资源信息 * @param pluginConfigClass 配置文件class * @return 返回映射后的存在值得对象 - * @throws ConfigurationParseException 配置文件解析异常 + * @throws Exception 配置文件解析异常 */ protected abstract Object parse(Resource resource, - Class pluginConfigClass) throws ConfigurationParseException; + Class pluginConfigClass) throws Exception; } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/ConfigurationParser.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/ConfigurationParser.java index 79ac4b31a626fa098b458a33036ba1a34cc1d431..fa6c1fd32231315a048328381d8e280f010dc6f2 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/ConfigurationParser.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/ConfigurationParser.java @@ -1,6 +1,5 @@ package com.gitee.starblues.factory.process.pipe.bean.configuration; -import com.gitee.starblues.exception.ConfigurationParseException; import com.gitee.starblues.realize.BasePlugin; /** @@ -15,8 +14,8 @@ public interface ConfigurationParser { * @param basePlugin 插件信息 * @param pluginConfigDefinition 插件配置定义 * @return 解析后映射值的对象 - * @throws ConfigurationParseException 抛出配置解析异常 + * @throws Exception 抛出配置解析异常 */ - Object parse(BasePlugin basePlugin, PluginConfigDefinition pluginConfigDefinition) throws ConfigurationParseException; + Object parse(BasePlugin basePlugin, PluginConfigDefinition pluginConfigDefinition) throws Exception; } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/YamlConfigurationParser.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/YamlConfigurationParser.java index 8cdbb87a01585a0597ba22be65504187a336755d..ad9fe65977bd31fdf02b01f4a2c975d65e6ad692 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/YamlConfigurationParser.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/configuration/YamlConfigurationParser.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.TreeTraversingParser; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLParser; -import com.gitee.starblues.exception.ConfigurationParseException; import com.gitee.starblues.integration.IntegrationConfiguration; import org.springframework.core.io.Resource; @@ -33,19 +32,14 @@ public class YamlConfigurationParser extends AbstractConfigurationParser { @Override protected Object parse(Resource resource, Class pluginConfigClass) - throws ConfigurationParseException{ - try { - InputStream input = new FileInputStream(resource.getFile()); - YAMLParser yamlParser = yamlFactory.createParser(input); - final JsonNode node = objectMapper.readTree(yamlParser); - if(node == null){ - return pluginConfigClass.newInstance(); - } - TreeTraversingParser treeTraversingParser = new TreeTraversingParser(node); - final Object o = objectMapper.readValue(treeTraversingParser, pluginConfigClass); - return o; - } catch (Exception e){ - throw new ConfigurationParseException("Yaml Parse Failure : " + e.getMessage(), e); + throws Exception{ + InputStream input = new FileInputStream(resource.getFile()); + YAMLParser yamlParser = yamlFactory.createParser(input); + final JsonNode node = objectMapper.readTree(yamlParser); + if(node == null){ + return pluginConfigClass.newInstance(); } + TreeTraversingParser treeTraversingParser = new TreeTraversingParser(node); + return objectMapper.readValue(treeTraversingParser, pluginConfigClass); } } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginControllerPostProcessor.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginControllerPostProcessor.java index b5543f96010c22ee748f03bc43db7360e2e3a6be..1dd7d5b2e793e2f66d6e6f8b6fcc6f88a297a509 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginControllerPostProcessor.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginControllerPostProcessor.java @@ -1,16 +1,14 @@ package com.gitee.starblues.factory.process.post.bean; -import com.gitee.starblues.exception.PluginBeanFactoryException; import com.gitee.starblues.extension.PluginControllerProcessor; -import com.gitee.starblues.integration.IntegrationConfiguration; import com.gitee.starblues.factory.PluginRegistryInfo; import com.gitee.starblues.factory.SpringBeanRegister; import com.gitee.starblues.factory.process.pipe.classs.group.ControllerGroup; import com.gitee.starblues.factory.process.post.PluginPostProcessor; +import com.gitee.starblues.integration.IntegrationConfiguration; import com.gitee.starblues.utils.AopUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.context.ApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.annotation.AnnotationUtils; @@ -20,7 +18,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.mvc.method.RequestMappingInfo; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; -import java.lang.reflect.*; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.util.*; /** @@ -111,12 +112,12 @@ public class PluginControllerPostProcessor implements PluginPostProcessor { String pluginId = pluginRegistryInfo.getPluginWrapper().getPluginId(); String beanName = springBeanRegister.register(pluginId, aClass); if(beanName == null || "".equals(beanName)){ - throw new PluginBeanFactoryException("registry "+ aClass.getName() + "failure!"); + throw new IllegalArgumentException("registry "+ aClass.getName() + "failure!"); } try { Object object = applicationContext.getBean(beanName); if(object == null){ - throw new PluginBeanFactoryException("registry "+ aClass.getName() + "failure! " + + throw new Exception("registry "+ aClass.getName() + "failure! " + "Not found The instance of" + aClass.getName()); } ControllerBeanWrapper controllerBeanWrapper = new ControllerBeanWrapper(); diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/DefaultPluginOperator.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/DefaultPluginOperator.java index abcee549e99a5f685c604cc85259f55aa6279d1d..872c1c485d79b5f36fc71a333a4b5ba959a7cb98 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/DefaultPluginOperator.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/DefaultPluginOperator.java @@ -9,6 +9,8 @@ import com.gitee.starblues.integration.operator.verify.PluginLegalVerify; import com.gitee.starblues.integration.operator.verify.PluginUploadVerify; import com.gitee.starblues.factory.DefaultPluginFactory; import com.gitee.starblues.factory.PluginFactory; +import com.gitee.starblues.utils.GlobalRegistryInfo; +import com.gitee.starblues.utils.PluginOperatorInfo; import com.gitee.starblues.utils.PluginFileUtils; import org.apache.commons.io.FileUtils; import org.pf4j.*; @@ -24,7 +26,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; @@ -75,7 +76,7 @@ public class DefaultPluginOperator implements PluginOperator { } try { pluginInitializerListenerFactory.addPluginInitializerListeners(pluginInitializerListener); - log.info("Start initialize plugins"); + log.info("Start initialize plugins of root path '{}'", pluginManager.getPluginsRoot().toString()); pluginInitializerListenerFactory.before(); // 启动前, 清除空文件 PluginFileUtils.cleanEmptyFile(pluginManager.getPluginsRoot()); @@ -87,6 +88,8 @@ public class DefaultPluginOperator implements PluginOperator { return false; } for (PluginWrapper pluginWrapper : pluginWrappers) { + GlobalRegistryInfo.addOperatorPluginInfo(pluginWrapper.getPluginId(), + PluginOperatorInfo.OperatorType.INSTALL, false); pluginFactory.registry(pluginWrapper); } pluginFactory.build(); @@ -100,24 +103,41 @@ public class DefaultPluginOperator implements PluginOperator { } } - @Override - public String loadPlugin(Path path) throws Exception { - return pluginManager.loadPlugin(path); - } @Override public boolean install(Path path) throws Exception { if(path == null){ - throw new IllegalArgumentException("Method:install param [pluginId] can not be empty"); + throw new IllegalArgumentException("Method:install param 'pluginId' can not be empty"); } String pluginId = null; try { pluginId = pluginManager.loadPlugin(path); - return start(pluginId); + if(StringUtils.isEmpty(pluginId)){ + log.error("Install plugin '{}' failure, this plugin id is empty.", pluginId); + return false; + } + GlobalRegistryInfo.addOperatorPluginInfo(pluginId, PluginOperatorInfo.OperatorType.INSTALL, true); + if(start(pluginId)){ + log.info("Install plugin '{}' success. {}", pluginId); + return true; + } else { + log.error("Install plugin '{}' failure", pluginId); + return false; + } } catch (Exception e){ // 说明load成功, 但是没有启动成功, 则卸载该插件 - uninstall(pluginId); + log.error("Install plugin '{}' failure. {}", pluginId, e.getMessage()); + log.info("Start uninstall plugin '{}' failure", pluginId); + try { + uninstall(pluginId); + } catch (Exception uninstallException){ + log.error("Uninstall plugin '{}' failure. {}", pluginId, e.getMessage()); + } throw e; + } finally { + if(pluginId != null){ + GlobalRegistryInfo.setOperatorPluginInfo(pluginId, false); + } } } @@ -125,167 +145,131 @@ public class DefaultPluginOperator implements PluginOperator { public boolean uninstall(String pluginId) throws Exception { PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId); if(pluginWrapper == null){ - log.error("Uninstall Plugin failure, Not found plugin {}", pluginId); + log.error("Uninstall plugin failure, Not found plugin '{}'", pluginId); return false; } + Exception exception = null; try { pluginFactory.unRegistry(pluginId); pluginFactory.build(); - return true; } catch (Exception e){ - throw new Exception("Stop plugin [" + pluginId + "] failure. " + e.getMessage() ,e); - } finally { + log.error("Uninstall plugin '{}' failure, {}", pluginId, e.getMessage()); + exception = e; + } + try { if (pluginManager.unloadPlugin(pluginId)) { // 卸载完后,将插件文件移到备份文件中 backup(pluginWrapper.getPluginPath(), "uninstallPlugin", 1); - log.info("Unload Plugin [{}] success", pluginId); - log.info("Uninstall Plugin [{}] success", pluginId); + log.info("Uninstall plugin '{}' success", pluginId); + return true; } else { - log.info("Unload Plugin [{}] failure", pluginId); - log.info("Uninstall Plugin [{}] failure", pluginId); - } - } - } - - @Override - public boolean delete(String pluginId) throws Exception { - PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId); - if(pluginWrapper == null){ - log.error("Delete -> Not Found plugin [{}]", pluginId); - return false; - } - if(pluginWrapper.getPluginState() == PluginState.STARTED){ - uninstall(pluginId); - } - backup(pluginWrapper.getPluginPath(), "deleteByPluginId", 1); - log.info("Delete plugin [{}] Success", pluginId); - return true; - } - - @Override - public boolean delete(Path path) throws Exception { - try { - if(!Files.exists(path)){ - throw new FileNotFoundException(path.toString() + " does not exist!"); - } - PluginDescriptor pluginDescriptor = pluginDescriptorFinder.find(path); - PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginDescriptor.getPluginId()); - if(pluginWrapper != null){ - return delete(pluginWrapper.getPluginId()); - } else { - log.error("Not found Plugin [{}] of path {}", pluginDescriptor.getPluginId(), path.toString()); + log.error("Uninstall plugin '{}' failure", pluginId); return false; } - } finally { - backup(path, "deleteByPath", 2); + } catch (Exception e){ + if(exception != null){ + exception.printStackTrace(); + } + log.error("Uninstall plugin '{}' failure. {}", pluginId, e.getMessage()); + throw e; } } + @Override public boolean start(String pluginId) throws Exception { if(StringUtils.isEmpty(pluginId)){ - throw new IllegalArgumentException("Method:start param [pluginId] can not be empty"); + throw new IllegalArgumentException("Method:start param 'pluginId' can not be empty"); } PluginWrapper pluginWrapper = getPluginWrapper(pluginId, "Start"); if(pluginWrapper.getPluginState() == PluginState.STARTED){ - throw new Exception("This plugin [" + pluginId + "] have already started"); + throw new Exception("This plugin '" + pluginId + "' have already started"); } - PluginState pluginState = pluginManager.startPlugin(pluginId); - if(pluginState == PluginState.STARTED){ - pluginFactory.registry(pluginWrapper); - pluginFactory.build(); - log.info("Start Plugin [{}] success", pluginId); - return true; + try { + PluginState pluginState = pluginManager.startPlugin(pluginId); + if(pluginState == PluginState.STARTED){ + GlobalRegistryInfo.addOperatorPluginInfo(pluginId, PluginOperatorInfo.OperatorType.START, false); + pluginFactory.registry(pluginWrapper); + pluginFactory.build(); + log.info("Start plugin '{}' success", pluginId); + return true; + } + log.error("Start plugin '{}' failure, plugin state is not start. Current plugin state is '{}'", + pluginId, pluginState.toString()); + } catch (Exception e){ + log.error("Start plugin '{}' failure. {}", pluginId, e.getMessage()); + log.info("Start stop plugin {}", pluginId); + try { + stop(pluginId); + } catch (Exception stopException){ + log.error("Stop plugin '{}' failure. {}", pluginId, e.getMessage()); + } + throw e; } - log.error("Start Plugin [{}] failure, plugin state is not start. State[{}]", pluginId, pluginState.toString()); + return false; } @Override public boolean stop(String pluginId) throws Exception { if(StringUtils.isEmpty(pluginId)){ - throw new IllegalArgumentException("Method:stop param [pluginId] can not be empty"); + throw new IllegalArgumentException("Method:stop param 'pluginId' can not be empty"); } PluginWrapper pluginWrapper = getPluginWrapper(pluginId, "Stop"); if(pluginWrapper.getPluginState() != PluginState.STARTED){ - throw new Exception("This plugin [" + pluginId + "] is not started"); + throw new Exception("This plugin '" + pluginId + "' is not started"); } try { pluginFactory.unRegistry(pluginId); pluginFactory.build(); - return true; } catch (Exception e){ - throw new Exception("Stop plugin [" + pluginId + "] failure. " + e.getMessage() ,e); - } finally { + log.error("Stop plugin '{}' failure. {}", pluginId, e.getMessage()); + e.printStackTrace(); + } + try { pluginManager.stopPlugin(pluginId); + log.info("Stop plugin '{}' success", pluginId); + return true; + } catch (Exception e){ + log.error("Stop plugin '{}' failure. {}", pluginId, e.getMessage()); + throw e; } } - - @Override - public Path uploadPlugin(MultipartFile pluginFile) throws Exception { + public boolean uploadPluginAndStart(MultipartFile pluginFile) throws Exception { if(pluginFile == null){ - throw new IllegalArgumentException("Method:uploadPlugin param [pluginFile] can not be null"); + throw new IllegalArgumentException("Method:uploadPluginAndStart param 'pluginFile' can not be null"); } - // 获取文件的后缀名 - String fileName = pluginFile.getOriginalFilename(); - String suffixName = fileName.substring(fileName.lastIndexOf(".") + 1); - //检查文件格式是否合法 - if(StringUtils.isEmpty(suffixName)){ - throw new IllegalArgumentException("Invalid file type, please select .jar or .zip file"); - } - if(!"jar".equalsIgnoreCase(suffixName) && !"zip".equalsIgnoreCase(suffixName)){ - throw new IllegalArgumentException("Invalid file type, please select .jar or .zip file"); - } - String tempPath = integrationConfiguration.uploadTempPath() + File.separator + fileName; - Path srcPath = PluginFileUtils.getExistPath(Paths.get(tempPath)); - Path tempPluginFile = Files.write(srcPath, pluginFile.getBytes()); - - try { - Path verifyPath = uploadPluginVerify.verify(tempPluginFile); - if(verifyPath != null){ - String pluginFilePathString = pluginManager.getPluginsRoot().toString() + - File.separator + fileName; - Path pluginFilePath = Paths.get(pluginFilePathString); - File target = pluginFilePath.toFile(); - if(target.exists()){ - // 存在则拷贝一份 - backup(pluginFilePath, "uploadPlugin", 2); - } - FileUtils.writeByteArrayToFile(target, FileUtils.readFileToByteArray(verifyPath.toFile())); - return pluginFilePath; - } else { - Exception exception = - new Exception(fileName + " verify failure, verifyPath is null"); - verifyFailureDelete(tempPluginFile, exception); - throw exception; - } - } catch (Exception e){ - // 出现异常, 删除刚才上传的临时文件 - verifyFailureDelete(tempPluginFile, e); - throw new Exception("Verify failure : " + e.getMessage(), e); + Path path = uploadPlugin(pluginFile); + if(this.install(path)){ + log.info("Upload And Start plugin Success"); + return true; + } else { + log.error("Upload And Start plugin failure"); + return false; } } - @Override - public boolean uploadPluginAndStart(MultipartFile pluginFile) throws Exception { - if(pluginFile == null){ - throw new Exception("Method:uploadPluginAndStart param [pluginFile] can not be null"); + public boolean installConfigFile(Path path) throws Exception { + if(!Files.exists(path)){ + throw new FileNotFoundException("path ' " + path + "' does not exist!"); } - Path path = uploadPlugin(pluginFile); - this.install(path); - log.info("Upload And Start Plugin Success. [{}]", path.toString()); + File sourceFile = path.toFile(); + String configPath = integrationConfiguration.pluginConfigFilePath() + + File.separator + sourceFile.getName(); + Path targetPath = PluginFileUtils.getExistPath(Paths.get(configPath)); + FileUtils.copyFile(sourceFile, targetPath.toFile()); return true; } @Override public boolean uploadConfigFile(MultipartFile configFile) throws Exception { if(configFile == null){ - throw new IllegalArgumentException("Method:uploadConfigFile param [configFile] can not be null"); + throw new IllegalArgumentException("Method:uploadConfigFile param 'configFile' can not be null"); } String fileName = configFile.getOriginalFilename(); String configPath = integrationConfiguration.pluginConfigFilePath() + @@ -327,21 +311,17 @@ public class DefaultPluginOperator implements PluginOperator { @Override public Set getPluginFilePaths() throws Exception { - try { - RuntimeMode environment = integrationConfiguration.environment(); - Set paths = new HashSet<>(); - if(environment == RuntimeMode.DEVELOPMENT){ - paths.add(integrationConfiguration.pluginPath()); - return paths; - } - List files = org.pf4j.util.FileUtils.getJars(Paths.get(integrationConfiguration.pluginPath())); - return files.stream() - .filter(file -> file != null) - .map(file -> file.getAbsolutePath()) - .collect(Collectors.toSet()); - } catch (Exception e){ - throw new Exception(e); + RuntimeMode environment = integrationConfiguration.environment(); + Set paths = new HashSet<>(); + if(environment == RuntimeMode.DEVELOPMENT){ + paths.add(integrationConfiguration.pluginPath()); + return paths; } + List files = org.pf4j.util.FileUtils.getJars(Paths.get(integrationConfiguration.pluginPath())); + return files.stream() + .filter(file -> file != null) + .map(file -> file.getAbsolutePath()) + .collect(Collectors.toSet()); } @Override @@ -349,6 +329,58 @@ public class DefaultPluginOperator implements PluginOperator { return pluginManager.getPlugins(); } + /** + * 上传插件 + * @param pluginFile 插件文件 + * @return 返回上传的插件路径 + * @throws Exception 异常信息 + */ + private Path uploadPlugin(MultipartFile pluginFile) throws Exception { + if(pluginFile == null){ + throw new IllegalArgumentException("Method:uploadPlugin param 'pluginFile' can not be null"); + } + // 获取文件的后缀名 + String fileName = pluginFile.getOriginalFilename(); + String suffixName = fileName.substring(fileName.lastIndexOf(".") + 1); + //检查文件格式是否合法 + if(StringUtils.isEmpty(suffixName)){ + throw new IllegalArgumentException("Invalid file type, please select .jar or .zip file"); + } + if(!"jar".equalsIgnoreCase(suffixName) && !"zip".equalsIgnoreCase(suffixName)){ + throw new IllegalArgumentException("Invalid file type, please select .jar or .zip file"); + } + String tempPathString = integrationConfiguration.uploadTempPath() + File.separator + fileName; + Path tempPath = PluginFileUtils.getExistPath(Paths.get(tempPathString)); + File tempFile = tempPath.toFile(); + FileUtils.writeByteArrayToFile(tempFile, pluginFile.getBytes()); + try { + Path verifyPath = uploadPluginVerify.verify(tempPath); + if(verifyPath != null){ + String pluginFilePathString = pluginManager.getPluginsRoot().toString() + + File.separator + fileName; + Path pluginFilePath = Paths.get(pluginFilePathString); + File target = pluginFilePath.toFile(); + if(target.exists()){ + // 存在则拷贝一份 + backup(pluginFilePath, "uploadPlugin", 2); + } + FileUtils.copyFile(verifyPath.toFile(), target); + // 删除临时文件 + tempFile.deleteOnExit(); + return pluginFilePath; + } else { + Exception exception = + new Exception(fileName + " verify failure, verifyPath is null"); + verifyFailureDelete(tempPath, exception); + throw exception; + } + } catch (Exception e){ + // 出现异常, 删除刚才上传的临时文件 + verifyFailureDelete(tempPath, e); + throw e; + } + } + /** * 得到插件包装类 @@ -389,8 +421,12 @@ public class DefaultPluginOperator implements PluginOperator { * @throws Exception Exception */ private boolean backup(Path sourcePath, String appendName, int type) throws Exception { + if(isDev()){ + // 如果是开发环境, 则不进行备份 + return true; + } if(!Files.exists(sourcePath)){ - throw new FileNotFoundException(sourcePath.toString() + " does not exist!"); + throw new FileNotFoundException("path ' " + sourcePath.toString() + "' does not exist!"); } try { String fileName = sourcePath.getFileName().toString(); @@ -404,13 +440,17 @@ public class DefaultPluginOperator implements PluginOperator { } File targetFile = target.toFile(); File sourceFile = sourcePath.toFile(); + if(sourceFile.length() == 0){ + // 源文件字节为0, 说明为删除的插件。不需要备份 + return true; + } FileUtils.writeByteArrayToFile(targetFile, FileUtils.readFileToByteArray(sourceFile)); if(type == 1){ FileUtils.writeByteArrayToFile(sourceFile, "".getBytes()); } return true; } catch (IOException e) { - throw new Exception("BackupPlugin " + sourcePath.toString() + " failure : " + e.getMessage(), e); + throw new Exception("Backup plugin jar '" + sourcePath.toString() + "' failure : " + e.getMessage(), e); } } @@ -423,6 +463,12 @@ public class DefaultPluginOperator implements PluginOperator { return dateTimeFormatter.format(localDateTime); } - + /** + * 是否是开发环境 + * @return bolean + */ + private boolean isDev(){ + return integrationConfiguration.environment() == RuntimeMode.DEVELOPMENT; + } } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/PluginOperator.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/PluginOperator.java index e4a80fadb0fdce029a481706427dc96fee4372fb..091b5fafbee7e23459f2ad8b6efd7beac32f72fd 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/PluginOperator.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/PluginOperator.java @@ -21,129 +21,105 @@ public interface PluginOperator { * 初始化插件。该方法只能执行一次。 * @param pluginInitializerListener 插件初始化监听者 * @return 成功返回true.不成功抛出异常或者返回false - * @throws Exception 插件插头异常 + * @throws Exception 异常信息 */ boolean initPlugins(PluginInitializerListener pluginInitializerListener) throws Exception; + /** - * 通过路径加载插件(不会启用) - * @param path 插件路径 - * @return 成功返回插件id - * @throws Exception 插件插头异常 - */ - String loadPlugin(Path path) throws Exception; - - /** - * 通过路径安装插件(会启用) + * 通过路径安装插件(会启用), 该插件文件必须存在于服务器 [适用于生产环境] * @param path 插件路径 * @return 成功返回true.不成功抛出异常或者返回false - * @throws Exception 插件插头异常 + * @throws Exception 异常信息 */ boolean install(Path path) throws Exception; /** - * 卸载插件 + * 卸载插件 [适用于生产环境] * @param pluginId 插件id * @return 成功返回true.不成功抛出异常或者返回false - * @throws Exception 插件插头异常 + * @throws Exception 异常信息 */ boolean uninstall(String pluginId) throws Exception; - - /** - * 通过插件id删除插件。只适用于生产环境 - * @param pluginId 插件id - * @return 成功返回true.不成功抛出异常或者返回false - * @throws Exception 插件插头异常 - */ - boolean delete(String pluginId) throws Exception; - - - /** - * 通过路径删除插件。只适用于生产环境 - * @param path 插件路径 - * @return 成功返回true.不成功抛出异常或者返回false - * @throws Exception 插件插头异常 - */ - boolean delete(Path path) throws Exception; - + /** - * 启用插件 + * 启用插件 [适用于生产环境、开发环境] * @param pluginId 插件id * @return 成功返回true.不成功抛出异常或者返回false - * @throws Exception 插件插头异常 + * @throws Exception 异常信息 */ boolean start(String pluginId) throws Exception; /** - * 停止插件 + * 停止插件 [适用于生产环境、开发环境] * @param pluginId 插件id * @return 成功返回true.不成功抛出异常或者返回false - * @throws Exception 插件插头异常 + * @throws Exception 异常信息 */ boolean stop(String pluginId) throws Exception; - - - /** - * 上传插件。只适用于生产环境 - * @param pluginFile 插件文件 - * @return 成功返回插件路径.不成功返回null, 或者抛出异常 - * @throws Exception 插件插头异常 - */ - Path uploadPlugin(MultipartFile pluginFile) throws Exception; - + /** - * 上传插件并启用插件。只适用于生产环境 + * 上传插件并启用插件。[适用于生产环境] * @param pluginFile 配置文件 * @return 成功返回true.不成功返回false, 或者抛出异常 - * @throws Exception 插件插头异常 + * @throws Exception 异常信息 */ boolean uploadPluginAndStart(MultipartFile pluginFile) throws Exception; /** - * 上传配置文件(如果存在, 则覆盖)。只适用于生产环境 + * 通过路径安装插件的配置文件。该文件必须存在于服务器。[适用于生产环境] + * @param path 配置文件路径。 + * @return 成功返回true.不成功返回false, 或者抛出异常 + * @throws Exception + */ + boolean installConfigFile(Path path) throws Exception; + + + /** + * 上传配置文件(如果存在, 则覆盖)。[适用于生产环境] * @param configFile 配置文件 * @return 成功返回true.不成功返回false, 或者抛出异常 - * @throws Exception 插件插头异常 + * @throws Exception 异常信息 */ boolean uploadConfigFile(MultipartFile configFile) throws Exception; /** - * 通过路径备份插件文件。只适用于生产环境 + * 通过路径备份文件。可备份插件和插件的配置文件。[适用于生产环境] * @param path 路径 * @param appendName 追加的名称 * @return 成功返回true.不成功返回false, 或者抛出异常 - * @throws Exception 插件插头异常 + * @throws Exception 异常信息 */ boolean backupPlugin(Path path, String appendName) throws Exception; /** - * 通过插件id备份插件。只适用于生产环境 + * 通过插件id备份插件。[适用于生产环境] * @param pluginId 插件id * @param appendName 追加的名称 * @return 成功返回true.不成功返回false, 或者抛出异常 - * @throws Exception 插件插头异常 + * @throws Exception 异常信息 */ boolean backupPlugin(String pluginId, String appendName) throws Exception; /** - * 获取插件信息 + * 获取插件信息 [适用于生产环境、开发环境] * @return 返回插件信息列表 */ List getPluginInfo(); /** - * 得到插件文件的路径。只适用于生产环境 + * 得到插件文件的路径 [适用于生产环境] * @return 返回插件路径列表 - * @throws Exception 插件插头异常 + * @throws Exception 异常信息 */ Set getPluginFilePaths() throws Exception; /** - * 得到插件的包装类 + * 得到插件的包装类 [适用于生产环境、开发环境] * @return 返回插件包装类集合 */ List getPluginWrapper(); diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/GlobalRegistryInfo.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/GlobalRegistryInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..d31114ad3a5c6e891e72f7be3c2b4bfa1604be53 --- /dev/null +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/GlobalRegistryInfo.java @@ -0,0 +1,102 @@ +package com.gitee.starblues.utils; + + +import java.util.HashMap; +import java.util.Map; + +/** + * 全局注册信息 + * + * @author zhangzhuo + * @version 1.0 + */ +public final class GlobalRegistryInfo { + + private GlobalRegistryInfo(){} + + + + /** + * 全局插件安装次数 + */ + private static Map operatorPluginInfos = new HashMap<>(); + + /** + * 全局扩展信息 + */ + private static Map extensionMap = new HashMap<>(); + + + + /** + * 添加操作插件信息 + * @param pluginId 插件id + */ + public static synchronized void addOperatorPluginInfo(String pluginId, + PluginOperatorInfo.OperatorType operatorType, + boolean isLock){ + PluginOperatorInfo operatorPluginInfo = operatorPluginInfos.get(pluginId); + if(operatorPluginInfo == null){ + operatorPluginInfo = new PluginOperatorInfo(); + operatorPluginInfos.put(pluginId, operatorPluginInfo); + } + operatorPluginInfo.setOperatorType(operatorType); + operatorPluginInfo.setLock(isLock); + } + + + public static synchronized void setOperatorPluginInfo(String pluginId, boolean isLock){ + PluginOperatorInfo operatorPluginInfo = operatorPluginInfos.get(pluginId); + if(operatorPluginInfo != null){ + operatorPluginInfo.setLock(isLock); + } + } + + + + /** + * 获取插件安装次数 + * @param pluginId 插件id + * @return 操作插件类型 + */ + public static synchronized PluginOperatorInfo getPluginInstallNum(String pluginId){ + return operatorPluginInfos.get(pluginId); + } + + + /** + * 添加全局扩展数据 + * @param key 扩展的key + * @param value 扩展值 + */ + public static synchronized void addExtension(String key, Object value){ + extensionMap.put(key, value); + } + + /** + * 删除全局扩展数据 + * @param key 扩展的key + */ + public static synchronized void removeExtension(String key){ + extensionMap.remove(key); + } + + /** + * 获取全局扩展值 + * @param key 全局扩展的key + * @param 返回值泛型 + * @return 扩展值 + */ + public static synchronized T getExtension(String key){ + Object o = extensionMap.get(key); + if(o == null){ + return null; + } else { + return (T) o; + } + } + + + + +} diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/PluginOperatorInfo.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/PluginOperatorInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..9f7d07eb17245b1855f85f83c09650d83e22c4ec --- /dev/null +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/PluginOperatorInfo.java @@ -0,0 +1,65 @@ +package com.gitee.starblues.utils; + +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * 操作插件信息。为了解决连续上传安装后, 停止后, 无法启动的问题。 + * + * @author zhangzhuo + * @version 1.0 + */ +public class PluginOperatorInfo { + + + /** + * 当前操作类型 + */ + private OperatorType operatorType; + + /** + * 是否锁定。如果锁定, 则不允许更新操作类型。 + * 该参数主要解决在安装插件时 setOperatorType 一次操作类型,但是它又调用了启动插件,而启动插件也要 setOperatorType 一次操作类型 + * 所以, 使用该参数, 用于在安装插件时, 锁定 setOperatorType, 在启动时就无法再 setOperatorType 了, 就不会覆盖该值 + */ + private AtomicBoolean isLock = new AtomicBoolean(false); + + /** + * 设置操作类型 + * @param operatorType 操作类型 + */ + public void setOperatorType(OperatorType operatorType) { + if(operatorType != null && !isLock.get()){ + // 如果锁定了, 则不能更新操作类型 + this.operatorType = operatorType; + } + } + + /** + * 主要用于锁定或者解锁。 + * @param isLock 是否锁定。true 锁定, false 解锁 + */ + public void setLock(boolean isLock){ + this.isLock.set(isLock); + } + + public OperatorType getOperatorType() { + return operatorType; + } + + /** + * 操作类型 + */ + public enum OperatorType{ + /** + * 启动插件 + */ + START, + + /** + * 安装插件 + */ + INSTALL, + } + + +}