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 0000000000000000000000000000000000000000..3a721af9123ed609052a5e60e5294b1b9221ffcd --- /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 568c271cec028cc2937cecc5df5d0f970f52015b..bab2049fa3e37545e8f525a2ac33da754a58fa77 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 ca2505cbec27dc36cd4cc295a679e4eeb9ad80e6..a9b9a6fe68f19a931cdcaf1e683cd37989ab228b 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 922679313372f039fb3773630597195a7ce804fb..25721583e8ec4f1235e436ef2a82e94a51fdf5df 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 a0061dd1de199bfe42cdaed44baeba43b623563c..af17b2c2bcd67c1c96cf58f16671016a0c503ac6 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; }