From f5695dbbb565e1c780c8cc6d89f2340283033b85 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Mon, 11 Nov 2024 17:12:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adaptation/ReportAdaptationComponent.java | 2 +- .../boot/env/DesignCorePluginComponent.java | 42 --------- .../boot/env/DesignPluginComponent.java | 86 ++++++++++++++++++- .../env/function/DesignUpdateComponent.java | 2 +- .../boot/init/DesignPreLoadComponent.java | 3 +- 5 files changed, 86 insertions(+), 49 deletions(-) delete mode 100644 designer-realize/src/main/java/com/fanruan/boot/env/DesignCorePluginComponent.java diff --git a/designer-realize/src/main/java/com/fanruan/boot/adaptation/ReportAdaptationComponent.java b/designer-realize/src/main/java/com/fanruan/boot/adaptation/ReportAdaptationComponent.java index 7a1a90af3d..f3de414e70 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/adaptation/ReportAdaptationComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/adaptation/ReportAdaptationComponent.java @@ -12,9 +12,9 @@ import com.fr.decision.ExtraDecisionClassManager; import com.fr.decision.base.VirtualFilterChain; import com.fr.decision.fun.EmbedRequestFilterProvider; import com.fr.decision.fun.GlobalRequestFilterProvider; +import com.fr.decision.fun.PluginPortalModuleDevice; import com.fr.decision.fun.SystemOptionProvider; import com.fr.decision.plugin.PluginControllerManager; -import com.fr.decision.portal.PluginPortalModuleDevice; import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.event.Listener; diff --git a/designer-realize/src/main/java/com/fanruan/boot/env/DesignCorePluginComponent.java b/designer-realize/src/main/java/com/fanruan/boot/env/DesignCorePluginComponent.java deleted file mode 100644 index 57dbb323cf..0000000000 --- a/designer-realize/src/main/java/com/fanruan/boot/env/DesignCorePluginComponent.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.fanruan.boot.env; - -import com.fanruan.boot.CorePluginComponent; -import com.fanruan.carina.Carina; -import com.fanruan.carina.annotions.DependsOn; -import com.fanruan.carina.annotions.FineComponent; -import com.fanruan.carina.annotions.Start; -import com.fanruan.carina.annotions.Supplemental; -import com.fanruan.plugin.autonomy.AutonomyClassManagerGroup; -import com.fanruan.plugin.autonomy.AutonomyClassManagerProvider; -import com.fr.plugin.ExtraClassManager; - -/** - * DesignCorePluginComponent - * - * @author Destiny.Lin - * @since 11.0 - * Created on 2024/8/9 - */ -@FineComponent(name = "design_plugin_core") -@DependsOn(dependencies = {"design_plugin"}) -public class DesignCorePluginComponent extends CorePluginComponent { - - /** - * prepare - */ - @Supplemental - public void supportFunctionDef() { - super.supportFunctionDef(); - } - - /** - * start - */ - @Start - public void start() { - /// 插件下沉不能直接调用fbp的逻辑,此时内置服务器未启动,一部分逻辑要拆到内置服务器启动的时候再做 -// super.start(); - } - - -} diff --git a/designer-realize/src/main/java/com/fanruan/boot/env/DesignPluginComponent.java b/designer-realize/src/main/java/com/fanruan/boot/env/DesignPluginComponent.java index a36066386a..3e232bfaab 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/env/DesignPluginComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/env/DesignPluginComponent.java @@ -7,15 +7,34 @@ import com.fanruan.carina.annotions.FineComponent; import com.fanruan.carina.annotions.Start; import com.fanruan.carina.annotions.Stop; import com.fanruan.carina.annotions.Supplemental; +import com.fanruan.plugin.autonomy.AutonomyClassManagerFactory; import com.fanruan.plugin.autonomy.AutonomyClassManagerGroup; import com.fanruan.plugin.autonomy.AutonomyClassManagerProvider; +import com.fr.config.ConfigContext; +import com.fr.invoke.ClassFactory; import com.fr.json.JSONObject; -import com.fr.plugin.ExtraClassManager; +import com.fr.plugin.beforeload.embed.PluginEmbedInfo; +import com.fr.plugin.config.PluginConfigContext; +import com.fr.plugin.injectable.PluginInjectionFilter; import com.fr.plugin.manage.PluginManager; import com.fr.plugin.manage.PluginSyncModuleType; +import com.fr.plugin.observer.PluginEvent; +import com.fr.plugin.observer.PluginEventListener; +import com.fr.plugin.observer.PluginListenerRegistration; +import com.fr.plugin.validate.PluginValidator; +import com.fr.stable.CommonUtils; +import com.fr.stable.project.ProjectConstants; +import com.fr.stable.resource.ResourceLoader; +import com.fr.startup.web.annotation.MappingJackson2HttpMessageConverter; +import com.fr.workspace.WorkContext; import com.fr.workspace.server.repository.plugin.PluginRepository; import javax.servlet.ServletContext; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; import java.util.List; import java.util.function.Supplier; @@ -43,13 +62,35 @@ public class DesignPluginComponent extends PluginComponent { */ @Start public void start() { - ExtraClassManager.getInstance().registerAutonomyClassManager(Carina.getApplicationContext().group(AutonomyClassManagerGroup.class).getAll().toArray(new AutonomyClassManagerProvider[0])); + //收集插件对象的过滤器 + Collection filters = Carina.getApplicationContext().group(PluginInjectionFilter.GroupKey.class).getAll(); + for (PluginInjectionFilter filter: filters) { + PluginManager.addInjectionFilter(filter); + } + + //装备外部的验证器 + assembleValidator(); + // 注册内置插件信息 + registerEmbedPluginInfo(); + // 注册插件配置类Provider + registerPluginConfigProvider(); + + + AutonomyClassManagerFactory.getInstance().registerAutonomyClassManager(Carina.getApplicationContext().group(AutonomyClassManagerGroup.class).getAll().toArray(new AutonomyClassManagerProvider[0])); Supplier> supplier = () -> PluginRepository.getInstance().getPluginStatus(); PluginManager.registerRemotePluginSupplier(supplier); PluginManager.setSyncModuleType(PluginSyncModuleType.DESIGN); + //PluginManager要在环境切换和模块启动之前初始化 + PluginManager.startEngine(); - super.start(); + PluginListenerRegistration.getInstance().listenRunningChanged(new PluginEventListener() { + @Override + public void on(PluginEvent event) { + MappingJackson2HttpMessageConverter.KEY.refreshObjectMapper(); + } + }); + registerPluginClassFinder(); } @Override @@ -57,6 +98,45 @@ public class DesignPluginComponent extends PluginComponent { // do nothing } + private void registerEmbedPluginInfo() { + Collection pluginEmbedInfos = Carina.getApplicationContext().group(PluginEmbedInfo.class).getAll(); + + PluginManager.getPluginEmbedManager().addPluginEmbedInfos(pluginEmbedInfos); + } + + private void registerPluginConfigProvider() { + ConfigContext.setPluginConfigContextProvider(new PluginConfigContext()); + } + + private void assembleValidator() { + PluginManager.getValidatorManager().register(Carina.getApplicationContext().group(PluginValidator.GroupKey.class).getAll()); + } + + + private void registerPluginClassFinder() { + ClassFactory.getInstance().addFinder(className -> { + //再找. + // alex:currentEnv可能是null + String envPath = WorkContext.getCurrent().getPath(); + if (envPath == null) { + throw new ClassNotFoundException(className); + } + File clssesFile = new File(CommonUtils.pathJoin(envPath, ProjectConstants.CLASSES_NAME)); + ClassLoader urlClassLoader; + try { + urlClassLoader = new URLClassLoader(new URL[]{clssesFile.toURI().toURL()}, CommonUtils.class.getClassLoader()); + } catch (MalformedURLException malformedURLException) { + urlClassLoader = ClassLoader.getSystemClassLoader(); + } + return Class.forName(className, true, urlClassLoader); + }); + + //从插件中拿 + ClassFactory.getInstance().addFinder(ResourceLoader::classForName); + //从插件引擎中拿 + ClassFactory.getInstance().addFinder(className -> Class.forName(className, true, PluginManager.getController().getClass().getClassLoader())); + } + /** * stop */ diff --git a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignUpdateComponent.java b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignUpdateComponent.java index 8f5d592bb0..3404618217 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignUpdateComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignUpdateComponent.java @@ -38,7 +38,7 @@ import java.util.List; * Created on 2024/7/2 */ @FineComponent(name = "design_function_update") -@DependsOn(dependencies = "design_plugin_core") +@DependsOn(dependencies = "design_plugin") public class DesignUpdateComponent { /** diff --git a/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java b/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java index a107548fbf..2c72fa4a8c 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java @@ -1,6 +1,5 @@ package com.fanruan.boot.init; -import com.fanruan.boot.ClassFindComponent; import com.fanruan.boot.ExtraLocaleClassManager; import com.fanruan.boot.key.StartupArgsShell; import com.fanruan.carina.Carina; @@ -205,7 +204,7 @@ public class DesignPreLoadComponent { ProjectConstants.CLASSES_NAME)); ClassLoader urlClassLoader; try { - urlClassLoader = new URLClassLoader(new URL[]{clssesFile.toURI().toURL()}, ClassFindComponent.class.getClassLoader()); + urlClassLoader = new URLClassLoader(new URL[]{clssesFile.toURI().toURL()}, DesignPreLoadComponent.class.getClassLoader()); } catch (MalformedURLException malformedURLException) { urlClassLoader = ClassLoader.getSystemClassLoader(); }