From b5e4dc4ecdfed82c134be877dfae324ef1b73e4b Mon Sep 17 00:00:00 2001 From: zhangzhuo Date: Sat, 23 Jan 2021 18:54:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=8F=92=E4=BB=B6=E5=9C=A8?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E7=8E=AF=E5=A2=83=E4=B8=8D=E8=83=BD=E8=A2=AB?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin1/config/UnRegistryValidatorImpl.java | 16 ++++++++++++++++ .../starblues/factory/PluginRegistryInfo.java | 2 ++ .../PluginPipeApplicationContextProcessor.java | 3 +-- .../operator/DefaultPluginOperator.java | 17 ++++++++++++++++- .../starblues/realize/UnRegistryValidator.java | 8 ++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 example/basic-example/plugins/basic-example-plugin1/src/main/java/com/basic/example/plugin1/config/UnRegistryValidatorImpl.java diff --git a/example/basic-example/plugins/basic-example-plugin1/src/main/java/com/basic/example/plugin1/config/UnRegistryValidatorImpl.java b/example/basic-example/plugins/basic-example-plugin1/src/main/java/com/basic/example/plugin1/config/UnRegistryValidatorImpl.java new file mode 100644 index 0000000..3a721af --- /dev/null +++ b/example/basic-example/plugins/basic-example-plugin1/src/main/java/com/basic/example/plugin1/config/UnRegistryValidatorImpl.java @@ -0,0 +1,16 @@ +package com.basic.example.plugin1.config; + +import com.gitee.starblues.realize.UnRegistryValidator; +import org.springframework.stereotype.Component; + +/** + * @author starBlues + * @version 1.0 + */ +@Component +public class UnRegistryValidatorImpl implements UnRegistryValidator { + @Override + public Result verify() throws Exception { + return new Result(false, "不可卸载"); + } +} 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 568c271..bab2049 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,7 @@ package com.gitee.starblues.factory; import com.gitee.starblues.factory.process.pipe.PluginInfoContainers; +import com.gitee.starblues.factory.process.pipe.PluginPipeApplicationContextProcessor; import com.gitee.starblues.factory.process.pipe.loader.ResourceWrapper; import com.gitee.starblues.realize.BasePlugin; import org.pf4j.*; @@ -375,6 +376,7 @@ public class PluginRegistryInfo { private void closePluginApplicationContext() { try { + PluginPipeApplicationContextProcessor.removeBeanExtend(this); pluginApplicationContext.close(); } catch (Exception e){ logger.error("Close plugin '{}' ApplicationContext failure", getPluginWrapper().getPluginId(), e); diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/PluginPipeApplicationContextProcessor.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/PluginPipeApplicationContextProcessor.java index ca2505c..a9b9a6f 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/PluginPipeApplicationContextProcessor.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/PluginPipeApplicationContextProcessor.java @@ -70,7 +70,6 @@ public class PluginPipeApplicationContextProcessor implements PluginPipeProcesso registrar.getClass().getName()); } } - removeBeanExtend(pluginRegistryInfo); } @@ -94,7 +93,7 @@ public class PluginPipeApplicationContextProcessor implements PluginPipeProcesso * 移除扩展绑定 * @param pluginRegistryInfo 插件注册信息 */ - private void removeBeanExtend(PluginRegistryInfo pluginRegistryInfo) { + public static void removeBeanExtend(PluginRegistryInfo pluginRegistryInfo) { String pluginUtilsName = pluginRegistryInfo.getExtension("PluginUtilsName"); if(StringUtils.isNullOrEmpty(pluginUtilsName)){ return; 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 9226793..2572158 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 @@ -215,6 +215,9 @@ public class DefaultPluginOperator implements PluginOperator { @Override public boolean uninstall(String pluginId, boolean isBackup) throws Exception { + if(isDev()){ + throw new RuntimeException("Plugin cannot be uninstalled in 'dev' environment"); + } if(StringUtils.isEmpty(pluginId)){ throw new IllegalArgumentException("Method:uninstall param 'pluginId' can not be empty"); } @@ -328,7 +331,7 @@ public class DefaultPluginOperator implements PluginOperator { @Override public boolean uploadPluginAndStart(MultipartFile pluginFile) throws Exception { if(isDev()){ - throw new RuntimeException("Plugin cannot be installed in the 'dev' environment"); + throw new RuntimeException("Plugin cannot uploadPluginAndStart in the 'dev' environment"); } if(pluginFile == null){ throw new IllegalArgumentException("Method:uploadPluginAndStart param 'pluginFile' can not be null"); @@ -344,6 +347,9 @@ public class DefaultPluginOperator implements PluginOperator { @Override public boolean installConfigFile(Path configFilePath) throws Exception { + if(isDev()){ + throw new RuntimeException("Plugin config file cannot be installed in the 'dev' environment"); + } if(!Files.exists(configFilePath)){ throw new FileNotFoundException("configFilePath '" + configFilePath + "' does not exist!"); } @@ -361,6 +367,9 @@ public class DefaultPluginOperator implements PluginOperator { @Override public boolean uploadConfigFile(MultipartFile configFile) throws Exception { + if(isDev()){ + throw new RuntimeException("Plugin config file cannot be uploaded in the 'dev' environment"); + } if(configFile == null){ throw new IllegalArgumentException("Method:uploadConfigFile param 'configFile' can not be null"); } @@ -379,6 +388,9 @@ public class DefaultPluginOperator implements PluginOperator { @Override public boolean backupPlugin(Path backDirPath, String sign) throws Exception { + if(isDev()){ + throw new RuntimeException("Plugin cannot backup in the 'dev' environment"); + } Objects.requireNonNull(backDirPath); return backup(backDirPath, sign, 2); } @@ -386,6 +398,9 @@ public class DefaultPluginOperator implements PluginOperator { @Override public boolean backupPlugin(String pluginId, String sign) throws Exception { + if(isDev()){ + throw new RuntimeException("Plugin cannot backup in the 'dev' environment"); + } PluginWrapper pluginManager = getPluginWrapper(pluginId, "BackupPlugin by pluginId"); return backupPlugin(pluginManager.getPluginPath(), sign); } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/realize/UnRegistryValidator.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/realize/UnRegistryValidator.java index a0061dd..af17b2c 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/realize/UnRegistryValidator.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/realize/UnRegistryValidator.java @@ -17,9 +17,17 @@ public interface UnRegistryValidator { class Result{ + /** + * 是否可卸载 + */ private boolean verify; + + /** + * 不可卸载时的提示内容 + */ private String message; + public Result(boolean verify) { this.verify = verify; } -- Gitee