From f12138626871ed9f050a8015806fda664b01960e Mon Sep 17 00:00:00 2001 From: hades Date: Fri, 25 Dec 2020 09:21:53 +0800 Subject: [PATCH 01/12] =?UTF-8?q?KERNEL-6380=20=E5=9C=A8=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=88=87=E6=8D=A2=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=EF=BC=8C=E9=9C=80=E8=A6=81=E6=9C=89=E4=B8=80=E4=B8=AA=E9=9B=86?= =?UTF-8?q?=E4=B8=AD=E5=88=B7=E6=96=B0=E7=BC=93=E5=AD=98=E7=9A=84=E5=9C=B0?= =?UTF-8?q?=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/PluginRefreshManager.java | 73 +++++++++++++++++++ .../data/datapane/TableDataTreePane.java | 34 --------- .../design/file/HistoryTemplateListCache.java | 27 +++++++ .../design/gui/frpane/HyperlinkGroupPane.java | 1 - .../com/fr/design/mainframe/JTemplate.java | 18 +++-- .../start/module/DesignerInitActivator.java | 2 + .../module/DesignerWorkspaceActivator.java | 4 +- 7 files changed, 118 insertions(+), 41 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/PluginRefreshManager.java diff --git a/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java b/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java new file mode 100644 index 000000000..67442bb06 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java @@ -0,0 +1,73 @@ +package com.fr.design; + +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.fun.HyperlinkProvider; +import com.fr.design.fun.TableDataDefineProvider; +import com.fr.plugin.manage.PluginFilter; +import com.fr.plugin.observer.PluginEvent; +import com.fr.plugin.observer.PluginEventListener; +import com.fr.plugin.observer.PluginEventType; +import com.fr.plugin.observer.PluginListenerRegistration; +import com.fr.stable.fun.IOFileAttrMark; +import java.util.HashSet; +import java.util.Set; + +/** + * + * @author hades + * @version 10.0 + * Created by hades on 2020/12/17 + */ +public class PluginRefreshManager { + + + private static final PluginRefreshManager INSTANCE = new PluginRefreshManager(); + + private final Set context = new HashSet<>(); + + private final PluginEventListener pluginAfterRunEventListener = new PluginEventListener() { + @Override + public void on(PluginEvent event) { + // 重新载入模板xml内容 到 Workbook/Form对象中 + HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(); + } + }; + + private final PluginFilter pluginFilter = pluginContext -> { + for (String xmlTag : context) { + if (pluginContext.contain(xmlTag)) { + return true; + } + } + return false; + }; + + + public static PluginRefreshManager getInstance() { + return INSTANCE; + } + + public void load() { + context.add(IOFileAttrMark.MARK_STRING); + context.add(TableDataDefineProvider.XML_TAG); + context.add(HyperlinkProvider.XML_TAG); + } + + private PluginRefreshManager() { + PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, this.pluginAfterRunEventListener, this.pluginFilter); + } + + public void registerItem(String xmlTag) { + context.add(xmlTag); + } + + public void removePluginListener() { + PluginListenerRegistration.getInstance().stopListen(this.pluginAfterRunEventListener); + + } + + public void addPluginListener() { + PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, this.pluginAfterRunEventListener, this.pluginFilter); + } + +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java index a2cc5b7d2..f1a3cf336 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java @@ -18,8 +18,6 @@ import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.FineJOptionPane; -import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.fun.TableDataDefineProvider; import com.fr.design.fun.TableDataPaneProcessor; import com.fr.design.gui.ibutton.UIHeadGroup; import com.fr.design.gui.icontainer.UIScrollPane; @@ -28,7 +26,6 @@ import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.icon.IconPathConstants; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.JTemplate; import com.fr.design.menu.MenuDef; import com.fr.design.menu.SeparatorDef; import com.fr.design.menu.ToolBarDef; @@ -98,9 +95,6 @@ public class TableDataTreePane extends BasicTableDataTreePane { createAddMenuDef(); - // 创建插件监听 - createPluginListener(); - editAction = new EditAction(); removeAction = new RemoveAction(); previewTableDataAction = new PreviewTableDataAction(dataTree); @@ -160,34 +154,6 @@ public class TableDataTreePane extends BasicTableDataTreePane { return context.contain(PluginModule.ExtraDesign); } }); - - //监听数据集插件 - GeneralContext.listenPluginRunningChanged(new PluginEventListener() { - @Override - public void on(PluginEvent event) { - //REPORT-25577 - //如果数据集插件禁用或启用。需要清空当前模板中的缓存 - reloadCurrTemplate(); - } - - private void reloadCurrTemplate() { - JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - if (accept(jt)) { - jt.refreshResource(); - } - } - - private boolean accept(JTemplate jt) { - - return jt != null && jt.getEditingFILE() != null && jt.getEditingFILE().exists(); - } - }, new PluginFilter() { - @Override - public boolean accept(PluginContext pluginContext) { - - return pluginContext.contain(TableDataDefineProvider.XML_TAG); - } - }); } diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 7b13c94a0..05b2a24f6 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -420,6 +420,7 @@ public class HistoryTemplateListCache implements CallbackEvent { /** * 重新载入当前模板,刷新数据/对象 */ + @Deprecated public void reloadCurrentTemplate() { JTemplate jt = getCurrentEditingTemplate(); boolean access = jt != null && jt.getEditingFILE() != null && jt.getEditingFILE().exists(); @@ -440,4 +441,30 @@ public class HistoryTemplateListCache implements CallbackEvent { }); } + /** + * 插件安装后/启用 重新加载模板资源 + */ + public void reloadAllEditingTemplate() { + FineLoggerFactory.getLogger().info("Plugin env Change reload all template started"); + int size = historyList.size(); + for (int i = 0; i < size; i++) { + JTemplate template = historyList.get(i); + FILE file = template.getEditingFILE(); + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + BaseBook target = template.getTarget(); + if (target != null) { + FineLoggerFactory.getLogger().info("{} is being reloaded", template.getName()); + target.export(outputStream); + FILE stashedFile = new StashedFILE(file, outputStream.toByteArray()); + template.refreshResource(stashedFile); + } + // 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理 + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + FineLoggerFactory.getLogger().info("Plugin env Change reload all template ended"); + } + } diff --git a/designer-base/src/main/java/com/fr/design/gui/frpane/HyperlinkGroupPane.java b/designer-base/src/main/java/com/fr/design/gui/frpane/HyperlinkGroupPane.java index 8405ce09e..0a8e4769a 100644 --- a/designer-base/src/main/java/com/fr/design/gui/frpane/HyperlinkGroupPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/frpane/HyperlinkGroupPane.java @@ -46,7 +46,6 @@ public abstract class HyperlinkGroupPane extends UIListControlPane { @Override public void on(PluginEvent event) { refreshNameableCreator(createNameableCreators()); - HistoryTemplateListCache.getInstance().reloadCurrentTemplate(); } }, new PluginFilter() { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 5cfd7a13d..87bcd23f5 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -47,6 +47,7 @@ import com.fr.design.menu.MenuDef; import com.fr.design.menu.NameSeparator; import com.fr.design.menu.ShortCut; import com.fr.design.preview.PagePreview; +import com.fr.design.ui.util.UIUtil; import com.fr.design.write.submit.DBManipulationInWidgetEventPane; import com.fr.design.write.submit.DBManipulationPane; import com.fr.event.EventDispatcher; @@ -332,16 +333,23 @@ public abstract class JTemplate> * CenterPane 负责监听改动。 * 所以需要同步处理 */ + @Deprecated public void refreshResource() { + refreshResource(this.editingFILE); + } + + public void refreshResource(FILE file) { try { - this.template = JTemplateFactory.asIOFile(this.editingFILE); + this.template = JTemplateFactory.asIOFile(file); setTarget(this.template); - // 先移除旧的。 - removeCenterPane(); - // 加入新的 - addCenterPane(); + UIUtil.invokeLaterIfNeeded(() -> { + // 先移除旧的。 + removeCenterPane(); + // 加入新的 + addCenterPane(); + }); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java index 1eeb5a6a3..5ca7efdd6 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java @@ -1,5 +1,6 @@ package com.fr.start.module; +import com.fr.design.PluginRefreshManager; import com.fr.module.Activator; import com.fr.start.DesignerInitial; @@ -15,6 +16,7 @@ public class DesignerInitActivator extends Activator { @Override public void start() { + PluginRefreshManager.getInstance().load(); DesignerInitial.init(findSingleton(StartupArgs.class).get()); } diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java index f5231eafe..1842ea762 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java @@ -1,6 +1,7 @@ package com.fr.start.module; import com.fr.concurrent.NamedThreadFactory; +import com.fr.design.PluginRefreshManager; import com.fr.design.file.HistoryTemplateListCache; import com.fr.event.Event; import com.fr.event.Listener; @@ -50,7 +51,7 @@ public class DesignerWorkspaceActivator extends Activator { @Override public void on(Event event, Workspace workspace) { - + PluginRefreshManager.getInstance().removePluginListener(); HistoryTemplateListCache.getInstance().stash(); } }); @@ -62,6 +63,7 @@ public class DesignerWorkspaceActivator extends Activator { public void on(Event event, Workspace workspace) { HistoryTemplateListCache.getInstance().load(); + PluginRefreshManager.getInstance().addPluginListener(); } }); } From 1bfb44b088ef206f140a2cfcc053cceabc156dad Mon Sep 17 00:00:00 2001 From: hades Date: Tue, 29 Dec 2020 09:25:37 +0800 Subject: [PATCH 02/12] =?UTF-8?q?KERNEL-6380=20=E5=9C=A8=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=88=87=E6=8D=A2=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=EF=BC=8C=E9=9C=80=E8=A6=81=E6=9C=89=E4=B8=80=E4=B8=AA=E9=9B=86?= =?UTF-8?q?=E4=B8=AD=E5=88=B7=E6=96=B0=E7=BC=93=E5=AD=98=E7=9A=84=E5=9C=B0?= =?UTF-8?q?=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/base/ClassHelper.java | 174 ++++++++++++++++++ .../com/fr/design/PluginRefreshManager.java | 51 +++-- .../data/datapane/TableDataTreePane.java | 2 + .../design/file/HistoryTemplateListCache.java | 97 +++++----- .../com/fr/design/mainframe/JTemplate.java | 2 - .../java/com/fr/base/ClassHelperTest.java | 28 +++ 6 files changed, 300 insertions(+), 54 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/base/ClassHelper.java create mode 100644 designer-base/src/test/java/com/fr/base/ClassHelperTest.java diff --git a/designer-base/src/main/java/com/fr/base/ClassHelper.java b/designer-base/src/main/java/com/fr/base/ClassHelper.java new file mode 100644 index 000000000..00ff7f9eb --- /dev/null +++ b/designer-base/src/main/java/com/fr/base/ClassHelper.java @@ -0,0 +1,174 @@ +package com.fr.base; + +import com.fr.general.ComparatorUtils; +import com.fr.log.FineLoggerFactory; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.jetbrains.annotations.Nullable; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/12/28 + */ +public class ClassHelper { + + private static final Set primClasses = new HashSet<>(); + + private static final Set classLoaders = new HashSet<>(); + + private static final Map map = new HashMap<>(); + + private static final Set data = new HashSet<>(); + + private static final String PLUGIN_CLASS_CLASSLOADER= "com.fr.plugin.engine.core.PluginClassLoader"; + + static { + primClasses.add("boolean"); + primClasses.add("byte"); + primClasses.add("char"); + primClasses.add("short"); + primClasses.add("int"); + primClasses.add("long"); + primClasses.add("float"); + primClasses.add("double"); + primClasses.add("void"); + primClasses.add("java.lang.Boolean"); + primClasses.add("java.lang.Byte"); + primClasses.add("java.lang.Character"); + primClasses.add("java.lang.Short"); + primClasses.add("java.lang.Integer"); + primClasses.add("java.lang.Long"); + primClasses.add("java.lang.FLOAT"); + primClasses.add("java.lang.DOUBLE"); + primClasses.add("java.lang.Void"); + primClasses.add("java.lang.String"); + primClasses.add("java.awt.image.BufferedImage"); + } + + + /** + * 获取当前对象字段中由插件加载出类的classloader + * + * @param o + * @return + */ + @Nullable + public static Set getPluginClassLoaders(Object o) { + try { + collectClassloader(o); + Set result = new HashSet<>(classLoaders); + data.clear(); + classLoaders.clear(); + map.clear(); + return result; + } catch (Throwable e) { + FineLoggerFactory.getLogger().warn(e.getMessage(), e); + data.clear(); + classLoaders.clear(); + map.clear(); + return null; + } + } + + private static void collectClassloader(Object o) { + if (o == null) { + return; + } + Field[] fields; + Class aclass = o.getClass(); + + String className = aclass.getName(); + + if (map.containsKey(className)) { + fields = map.get(className); + } else { + fields = fields(aclass, o); + map.put(className, fields); + } + + if (aclass.isArray()) { + for (int i = 0, len = Array.getLength(o); i < len; i++) { + Object arrayOb = Array.get(o, i); + if (arrayOb != null) { + Class arrayObClass = arrayOb.getClass(); + String name = arrayObClass.getName(); + if (primClasses.contains(name)) { + return; + } + data.add(arrayOb); + ClassLoader loader = arrayObClass.getClassLoader(); + if (loader != null && ComparatorUtils.equals(loader.getClass().getName(), PLUGIN_CLASS_CLASSLOADER)) { + classLoaders.add(loader); + } + } else { + continue; + } + collectClassloader(arrayOb); + } + } + + if (fields.length == 0) { + return; + } + + for (Field field : fields) { + if (!field.isAccessible()) { + field.setAccessible(true); + } + Object ob = null; + try { + ob = field.get(o); + + if (ob == null) { + continue; + } + Class clazz = ob.getClass(); + String name = clazz.getName(); + + if (primClasses.contains(name)) { + continue; + } + + if (!data.contains(ob)) { + data.add(ob); + ClassLoader loader = clazz.getClassLoader(); + if (loader != null && ComparatorUtils.equals(loader.getClass().getName(), PLUGIN_CLASS_CLASSLOADER)) { + classLoaders.add(loader); + } + collectClassloader(ob); + } + + } catch (Throwable e) { + FineLoggerFactory.getLogger().warn(e.getMessage(), e); + } + } + } + + + + private static Field[] fields(Class clazz, Object o) { + + Class t = clazz; + Set result = new HashSet<>(); + + do { + for (Field field : t.getDeclaredFields()) { + if (clazz != o ^ Modifier.isStatic(field.getModifiers())) { + result.add(field); + } + } + + t = t.getSuperclass(); + } + while (t != null); + + return result.toArray(new Field[0]); + } + +} diff --git a/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java b/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java index 67442bb06..6ccf1f190 100644 --- a/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java +++ b/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java @@ -1,14 +1,13 @@ package com.fr.design; +import com.fr.design.constants.DesignerLaunchStatus; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.fun.HyperlinkProvider; import com.fr.design.fun.TableDataDefineProvider; -import com.fr.plugin.manage.PluginFilter; import com.fr.plugin.observer.PluginEvent; import com.fr.plugin.observer.PluginEventListener; import com.fr.plugin.observer.PluginEventType; import com.fr.plugin.observer.PluginListenerRegistration; -import com.fr.stable.fun.IOFileAttrMark; import java.util.HashSet; import java.util.Set; @@ -28,18 +27,33 @@ public class PluginRefreshManager { private final PluginEventListener pluginAfterRunEventListener = new PluginEventListener() { @Override public void on(PluginEvent event) { + boolean mustReload = false; + // 兼容之前版本特性 + for (String tag : context) { + if (event.getContext().contain(tag)) { + mustReload = true; + break; + } + } // 重新载入模板xml内容 到 Workbook/Form对象中 - HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(); + HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(mustReload); } }; - private final PluginFilter pluginFilter = pluginContext -> { - for (String xmlTag : context) { - if (pluginContext.contain(xmlTag)) { - return true; + private final PluginEventListener pluginBeforeStopEventListener = new PluginEventListener() { + @Override + public void on(PluginEvent event) { + boolean canCal = true; + for (String tag : context) { + if (event.getContext().contain(tag)) { + canCal = false; + break; + } + } + if (canCal) { + HistoryTemplateListCache.getInstance().calNeedReloadTemplate(event.getContext()); } } - return false; }; @@ -48,13 +62,26 @@ public class PluginRefreshManager { } public void load() { - context.add(IOFileAttrMark.MARK_STRING); context.add(TableDataDefineProvider.XML_TAG); context.add(HyperlinkProvider.XML_TAG); } private PluginRefreshManager() { - PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, this.pluginAfterRunEventListener, this.pluginFilter); + PluginListenerRegistration.getInstance().listen(PluginEventType.BeforeAllActive, new PluginEventListener() { + @Override + public void on(PluginEvent event) { + removePluginListener(); + } + }); + PluginListenerRegistration.getInstance().listen(PluginEventType.AfterAllActive, new PluginEventListener() { + @Override + public void on(PluginEvent event) { + addPluginListener(); + if (DesignerLaunchStatus.getStatus() != DesignerLaunchStatus.WORKSPACE_INIT_COMPLETE) { + HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(true); + } + } + }); } public void registerItem(String xmlTag) { @@ -63,11 +90,13 @@ public class PluginRefreshManager { public void removePluginListener() { PluginListenerRegistration.getInstance().stopListen(this.pluginAfterRunEventListener); + PluginListenerRegistration.getInstance().stopListen(this.pluginBeforeStopEventListener); } public void addPluginListener() { - PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, this.pluginAfterRunEventListener, this.pluginFilter); + PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, this.pluginAfterRunEventListener); + PluginListenerRegistration.getInstance().listen(PluginEventType.BeforeStop, this.pluginBeforeStopEventListener); } } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java index f1a3cf336..ca587c3da 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java @@ -94,6 +94,8 @@ public class TableDataTreePane extends BasicTableDataTreePane { addMenuDef.setIconPath(IconPathConstants.ADD_POPMENU_ICON_PATH); createAddMenuDef(); + // 创建插件监听 + createPluginListener(); editAction = new EditAction(); removeAction = new RemoveAction(); diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 05b2a24f6..242d1d5c1 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -1,5 +1,6 @@ package com.fr.design.file; +import com.fr.base.ClassHelper; import com.fr.base.chart.chartdata.CallbackEvent; import com.fr.base.io.BaseBook; import com.fr.design.DesignerEnvManager; @@ -18,6 +19,8 @@ import com.fr.file.FileNodeFILE; import com.fr.file.StashedFILE; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.manage.PluginManager; import com.fr.stable.CoreConstants; import com.fr.stable.StringUtils; import com.fr.third.org.apache.commons.io.FilenameUtils; @@ -29,6 +32,7 @@ import java.util.HashMap; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Set; /** * 历史模板缓存 @@ -42,6 +46,8 @@ public class HistoryTemplateListCache implements CallbackEvent { private List> historyList; private JTemplate editingTemplate; + private Map templateNeedReloadMap = new HashMap<>(); + public static HistoryTemplateListCache getInstance() { return Holder.INSTANCE; } @@ -72,6 +78,9 @@ public class HistoryTemplateListCache implements CallbackEvent { selected.fireJTemplateClosed(); selected.stopEditing(); try { + if (!templateNeedReloadMap.isEmpty()) { + templateNeedReloadMap.remove(selected.getEditingFILE().getName()); + } historyList.remove(contains(selected)); selected.getEditingFILE().closeTemplate(); FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Closed_Warn_Text", selected.getEditingFILE().getName())); @@ -370,7 +379,6 @@ public class HistoryTemplateListCache implements CallbackEvent { */ public void load() { FineLoggerFactory.getLogger().info("Env Change Template Loading..."); - JTemplate currentTemplate = null; if (stashFILEMap != null && stashFILEMap.size() != 0) { int size = historyList.size(); for (int i = 0; i < size; i++) { @@ -381,32 +389,14 @@ public class HistoryTemplateListCache implements CallbackEvent { if (stashedFile == null) { continue; } - JTemplate template = JTemplateFactory.createJTemplate(stashedFile); - if (template != null) { - historyList.set(i, template); - // 替换当前正在编辑的模板,使用添加并激活的方式,以便使用统一的入口来处理监听事件 - if (isCurrentEditingFile(template.getPath())) { - currentTemplate = template; - } - } else { - // 当模板为空时 说明是一个新建的未保存模板 但是内存中保存了该模板 可以从中获取 - JTemplate jt = historyList.get(i); - // 另外如果该模板是正在编辑的模板,需要要激活 - if (jt != null && isCurrentEditingFile(jt.getPath())) { - currentTemplate = jt; - } - } + FineLoggerFactory.getLogger().info("{} is being reloaded", stashedFile.getName()); + JTemplate template = historyList.get(i); + template.refreshResource(stashedFile); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } } - // 最后加载当前正在编辑的模板 以保证数据集刷新正常 - if (currentTemplate != null) { - loadCurrentTemplate(currentTemplate); - } stashFILEMap.clear(); - MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList); - MutilTempalteTabPane.getInstance().repaint(); } FineLoggerFactory.getLogger().info("Env Change Template Loaded."); } @@ -422,11 +412,7 @@ public class HistoryTemplateListCache implements CallbackEvent { */ @Deprecated public void reloadCurrentTemplate() { - JTemplate jt = getCurrentEditingTemplate(); - boolean access = jt != null && jt.getEditingFILE() != null && jt.getEditingFILE().exists(); - if (access) { - jt.refreshResource(); - } + reloadAllEditingTemplate(true); } /** @@ -444,27 +430,56 @@ public class HistoryTemplateListCache implements CallbackEvent { /** * 插件安装后/启用 重新加载模板资源 */ - public void reloadAllEditingTemplate() { - FineLoggerFactory.getLogger().info("Plugin env Change reload all template started"); + public void reloadAllEditingTemplate(boolean mustReload) { + FineLoggerFactory.getLogger().info("Plugin env change reload all template started"); + long start = System.currentTimeMillis(); int size = historyList.size(); for (int i = 0; i < size; i++) { JTemplate template = historyList.get(i); FILE file = template.getEditingFILE(); - try { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - BaseBook target = template.getTarget(); - if (target != null) { - FineLoggerFactory.getLogger().info("{} is being reloaded", template.getName()); - target.export(outputStream); - FILE stashedFile = new StashedFILE(file, outputStream.toByteArray()); - template.refreshResource(stashedFile); + Boolean value = templateNeedReloadMap.get(file.getName()); + boolean needReload = mustReload || (value != null && value); + if (needReload) { + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + BaseBook target = template.getTarget(); + if (target != null) { + FineLoggerFactory.getLogger().info("{} is being reloaded", file.getName()); + target.export(outputStream); + FILE stashedFile = new StashedFILE(file, outputStream.toByteArray()); + template.refreshResource(stashedFile); + } + // 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理 + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); } - // 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理 - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); } } - FineLoggerFactory.getLogger().info("Plugin env Change reload all template ended"); + templateNeedReloadMap.clear(); + FineLoggerFactory.getLogger().info("Plugin env change reload all template ended"); + FineLoggerFactory.getLogger().debug("Reload all template spend: {} ms", (System.currentTimeMillis() - start)); + } + + public void calNeedReloadTemplate(PluginContext context) { + for (JTemplate template : historyList) { + BaseBook baseBook = template.getTarget(); + if (baseBook != null) { + String name = template.getEditingFILE().getName(); + long start = System.currentTimeMillis(); + Set set = ClassHelper.getPluginClassLoaders(baseBook); + FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start)); + if (set != null) { + for (ClassLoader classLoader : set) { + PluginContext pluginContext = PluginManager.getContext(classLoader); + if (pluginContext != null && ComparatorUtils.equals(context.getName(), pluginContext.getName())) { + templateNeedReloadMap.put(name, true); + } + } + } else { + templateNeedReloadMap.put(name, true); + } + } + } } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 87bcd23f5..d80d9f07a 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -344,12 +344,10 @@ public abstract class JTemplate> this.template = JTemplateFactory.asIOFile(file); setTarget(this.template); - UIUtil.invokeLaterIfNeeded(() -> { // 先移除旧的。 removeCenterPane(); // 加入新的 addCenterPane(); - }); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } diff --git a/designer-base/src/test/java/com/fr/base/ClassHelperTest.java b/designer-base/src/test/java/com/fr/base/ClassHelperTest.java new file mode 100644 index 000000000..ae0facfcf --- /dev/null +++ b/designer-base/src/test/java/com/fr/base/ClassHelperTest.java @@ -0,0 +1,28 @@ +package com.fr.base; + +import com.fr.form.main.Form; +import com.fr.main.impl.WorkBook; +import java.util.Set; +import junit.framework.TestCase; +import org.junit.Assert; + + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/12/28 + */ +public class ClassHelperTest extends TestCase { + + + public void testGetPluginClassLoaders() { + WorkBook workBook = new WorkBook(); + Set set = ClassHelper.getPluginClassLoaders(workBook); + Assert.assertEquals(0, set.size()); + Form form = new Form(); + Set set1 = ClassHelper.getPluginClassLoaders(form); + Assert.assertEquals(0, set1.size()); + + } + +} \ No newline at end of file From 6871224633f0ae45ea61d3878969e08fb38beade Mon Sep 17 00:00:00 2001 From: hades Date: Tue, 29 Dec 2020 09:29:50 +0800 Subject: [PATCH 03/12] =?UTF-8?q?KERNEL-6380=20=E6=A0=BC=E5=BC=8F=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/mainframe/JTemplate.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index d80d9f07a..f540cdbc6 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -344,10 +344,10 @@ public abstract class JTemplate> this.template = JTemplateFactory.asIOFile(file); setTarget(this.template); - // 先移除旧的。 - removeCenterPane(); - // 加入新的 - addCenterPane(); + // 先移除旧的。 + removeCenterPane(); + // 加入新的 + addCenterPane(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } From 9a157b8281b115fffb87cc41a067a8b54382ee8a Mon Sep 17 00:00:00 2001 From: hades Date: Tue, 29 Dec 2020 13:04:45 +0800 Subject: [PATCH 04/12] =?UTF-8?q?KERNEL-6380=20=E5=9C=A8=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=88=87=E6=8D=A2=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=EF=BC=8C=E9=9C=80=E8=A6=81=E6=9C=89=E4=B8=80=E4=B8=AA=E9=9B=86?= =?UTF-8?q?=E4=B8=AD=E5=88=B7=E6=96=B0=E7=BC=93=E5=AD=98=E7=9A=84=E5=9C=B0?= =?UTF-8?q?=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/base/ClassHelper.java | 174 ------------------ .../design/file/HistoryTemplateListCache.java | 6 +- .../java/com/fr/base/ClassHelperTest.java | 11 +- 3 files changed, 9 insertions(+), 182 deletions(-) delete mode 100644 designer-base/src/main/java/com/fr/base/ClassHelper.java diff --git a/designer-base/src/main/java/com/fr/base/ClassHelper.java b/designer-base/src/main/java/com/fr/base/ClassHelper.java deleted file mode 100644 index 00ff7f9eb..000000000 --- a/designer-base/src/main/java/com/fr/base/ClassHelper.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.fr.base; - -import com.fr.general.ComparatorUtils; -import com.fr.log.FineLoggerFactory; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import org.jetbrains.annotations.Nullable; - -/** - * @author hades - * @version 10.0 - * Created by hades on 2020/12/28 - */ -public class ClassHelper { - - private static final Set primClasses = new HashSet<>(); - - private static final Set classLoaders = new HashSet<>(); - - private static final Map map = new HashMap<>(); - - private static final Set data = new HashSet<>(); - - private static final String PLUGIN_CLASS_CLASSLOADER= "com.fr.plugin.engine.core.PluginClassLoader"; - - static { - primClasses.add("boolean"); - primClasses.add("byte"); - primClasses.add("char"); - primClasses.add("short"); - primClasses.add("int"); - primClasses.add("long"); - primClasses.add("float"); - primClasses.add("double"); - primClasses.add("void"); - primClasses.add("java.lang.Boolean"); - primClasses.add("java.lang.Byte"); - primClasses.add("java.lang.Character"); - primClasses.add("java.lang.Short"); - primClasses.add("java.lang.Integer"); - primClasses.add("java.lang.Long"); - primClasses.add("java.lang.FLOAT"); - primClasses.add("java.lang.DOUBLE"); - primClasses.add("java.lang.Void"); - primClasses.add("java.lang.String"); - primClasses.add("java.awt.image.BufferedImage"); - } - - - /** - * 获取当前对象字段中由插件加载出类的classloader - * - * @param o - * @return - */ - @Nullable - public static Set getPluginClassLoaders(Object o) { - try { - collectClassloader(o); - Set result = new HashSet<>(classLoaders); - data.clear(); - classLoaders.clear(); - map.clear(); - return result; - } catch (Throwable e) { - FineLoggerFactory.getLogger().warn(e.getMessage(), e); - data.clear(); - classLoaders.clear(); - map.clear(); - return null; - } - } - - private static void collectClassloader(Object o) { - if (o == null) { - return; - } - Field[] fields; - Class aclass = o.getClass(); - - String className = aclass.getName(); - - if (map.containsKey(className)) { - fields = map.get(className); - } else { - fields = fields(aclass, o); - map.put(className, fields); - } - - if (aclass.isArray()) { - for (int i = 0, len = Array.getLength(o); i < len; i++) { - Object arrayOb = Array.get(o, i); - if (arrayOb != null) { - Class arrayObClass = arrayOb.getClass(); - String name = arrayObClass.getName(); - if (primClasses.contains(name)) { - return; - } - data.add(arrayOb); - ClassLoader loader = arrayObClass.getClassLoader(); - if (loader != null && ComparatorUtils.equals(loader.getClass().getName(), PLUGIN_CLASS_CLASSLOADER)) { - classLoaders.add(loader); - } - } else { - continue; - } - collectClassloader(arrayOb); - } - } - - if (fields.length == 0) { - return; - } - - for (Field field : fields) { - if (!field.isAccessible()) { - field.setAccessible(true); - } - Object ob = null; - try { - ob = field.get(o); - - if (ob == null) { - continue; - } - Class clazz = ob.getClass(); - String name = clazz.getName(); - - if (primClasses.contains(name)) { - continue; - } - - if (!data.contains(ob)) { - data.add(ob); - ClassLoader loader = clazz.getClassLoader(); - if (loader != null && ComparatorUtils.equals(loader.getClass().getName(), PLUGIN_CLASS_CLASSLOADER)) { - classLoaders.add(loader); - } - collectClassloader(ob); - } - - } catch (Throwable e) { - FineLoggerFactory.getLogger().warn(e.getMessage(), e); - } - } - } - - - - private static Field[] fields(Class clazz, Object o) { - - Class t = clazz; - Set result = new HashSet<>(); - - do { - for (Field field : t.getDeclaredFields()) { - if (clazz != o ^ Modifier.isStatic(field.getModifiers())) { - result.add(field); - } - } - - t = t.getSuperclass(); - } - while (t != null); - - return result.toArray(new Field[0]); - } - -} diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 242d1d5c1..88f64a4d5 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -1,6 +1,5 @@ package com.fr.design.file; -import com.fr.base.ClassHelper; import com.fr.base.chart.chartdata.CallbackEvent; import com.fr.base.io.BaseBook; import com.fr.design.DesignerEnvManager; @@ -18,6 +17,7 @@ import com.fr.file.FILE; import com.fr.file.FileNodeFILE; import com.fr.file.StashedFILE; import com.fr.general.ComparatorUtils; +import com.fr.invoke.ClassHelper; import com.fr.log.FineLoggerFactory; import com.fr.plugin.context.PluginContext; import com.fr.plugin.manage.PluginManager; @@ -457,7 +457,7 @@ public class HistoryTemplateListCache implements CallbackEvent { } templateNeedReloadMap.clear(); FineLoggerFactory.getLogger().info("Plugin env change reload all template ended"); - FineLoggerFactory.getLogger().debug("Reload all template spend: {} ms", (System.currentTimeMillis() - start)); + FineLoggerFactory.getLogger().info("Reload all template spend: {} ms", (System.currentTimeMillis() - start)); } public void calNeedReloadTemplate(PluginContext context) { @@ -466,7 +466,7 @@ public class HistoryTemplateListCache implements CallbackEvent { if (baseBook != null) { String name = template.getEditingFILE().getName(); long start = System.currentTimeMillis(); - Set set = ClassHelper.getPluginClassLoaders(baseBook); + Set set = ClassHelper.getClassLoaders(baseBook); FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start)); if (set != null) { for (ClassLoader classLoader : set) { diff --git a/designer-base/src/test/java/com/fr/base/ClassHelperTest.java b/designer-base/src/test/java/com/fr/base/ClassHelperTest.java index ae0facfcf..c77bb7b67 100644 --- a/designer-base/src/test/java/com/fr/base/ClassHelperTest.java +++ b/designer-base/src/test/java/com/fr/base/ClassHelperTest.java @@ -1,6 +1,7 @@ package com.fr.base; import com.fr.form.main.Form; +import com.fr.invoke.ClassHelper; import com.fr.main.impl.WorkBook; import java.util.Set; import junit.framework.TestCase; @@ -15,13 +16,13 @@ import org.junit.Assert; public class ClassHelperTest extends TestCase { - public void testGetPluginClassLoaders() { + public void testGetClassLoaders() { WorkBook workBook = new WorkBook(); - Set set = ClassHelper.getPluginClassLoaders(workBook); - Assert.assertEquals(0, set.size()); + Set set = ClassHelper.getClassLoaders(workBook); + Assert.assertFalse(set.isEmpty()); Form form = new Form(); - Set set1 = ClassHelper.getPluginClassLoaders(form); - Assert.assertEquals(0, set1.size()); + Set set1 = ClassHelper.getClassLoaders(form); + Assert.assertFalse(set1.isEmpty()); } From 7d64006f2db9e1416848f524b7d5233e0ca947e5 Mon Sep 17 00:00:00 2001 From: Lanlan Date: Fri, 4 Dec 2020 12:11:46 +0800 Subject: [PATCH 05/12] =?UTF-8?q?KERNEL-6154=20GeneralXMLTools=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/start/module/DesignerActivator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java index 3f1aa2663..495252e38 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java @@ -99,6 +99,7 @@ import com.fr.report.cell.cellattr.core.group.DSColumn; import com.fr.report.cell.painter.BiasTextPainter; import com.fr.report.cell.painter.CellImagePainter; import com.fr.stable.ArrayUtils; +import com.fr.stable.EssentialUtils; import com.fr.stable.ParameterProvider; import com.fr.stable.bridge.StableFactory; import com.fr.stable.os.support.OSBasedAction; @@ -191,8 +192,8 @@ public class DesignerActivator extends Activator { justStartModules4Designer(); CalculatorProviderContext.setValueConverter(valueConverter()); - GeneralXMLTools.Object_Tokenizer = startXMLReadObjectTokenizer(); - GeneralXMLTools.Object_XML_Writer_Finder = startObjectXMLWriterFinder(); + EssentialUtils.Object_Tokenizer = startXMLReadObjectTokenizer(); + EssentialUtils.Object_XML_Writer_Finder = startObjectXMLWriterFinder(); addAdapterForPlate(); designerRegister(); From 6442a43639cadc24dde7d7d1828fdf8472dae83e Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 30 Dec 2020 15:44:29 +0800 Subject: [PATCH 06/12] =?UTF-8?q?KERNEL-6380=20=E8=A7=A3=E8=80=A6=20?= =?UTF-8?q?=E4=BB=85=E5=A4=84=E7=90=86=E6=8F=92=E4=BB=B6afterRun=E7=94=9F?= =?UTF-8?q?=E5=91=BD=E5=91=A8=E6=9C=9F=20+=20=E9=87=8D=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...er.java => PluginClassRefreshManager.java} | 38 +++---------- .../design/file/HistoryTemplateListCache.java | 57 ++++++++++--------- .../start/module/DesignerInitActivator.java | 4 +- 3 files changed, 38 insertions(+), 61 deletions(-) rename designer-base/src/main/java/com/fr/design/{PluginRefreshManager.java => PluginClassRefreshManager.java} (65%) diff --git a/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java b/designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java similarity index 65% rename from designer-base/src/main/java/com/fr/design/PluginRefreshManager.java rename to designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java index 6ccf1f190..22f791f4f 100644 --- a/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java +++ b/designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java @@ -17,47 +17,30 @@ import java.util.Set; * @version 10.0 * Created by hades on 2020/12/17 */ -public class PluginRefreshManager { +public class PluginClassRefreshManager { - private static final PluginRefreshManager INSTANCE = new PluginRefreshManager(); + private static final PluginClassRefreshManager INSTANCE = new PluginClassRefreshManager(); private final Set context = new HashSet<>(); private final PluginEventListener pluginAfterRunEventListener = new PluginEventListener() { @Override public void on(PluginEvent event) { - boolean mustReload = false; // 兼容之前版本特性 for (String tag : context) { if (event.getContext().contain(tag)) { - mustReload = true; + HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(); break; } } // 重新载入模板xml内容 到 Workbook/Form对象中 - HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(mustReload); - } - }; - - private final PluginEventListener pluginBeforeStopEventListener = new PluginEventListener() { - @Override - public void on(PluginEvent event) { - boolean canCal = true; - for (String tag : context) { - if (event.getContext().contain(tag)) { - canCal = false; - break; - } - } - if (canCal) { - HistoryTemplateListCache.getInstance().calNeedReloadTemplate(event.getContext()); - } + HistoryTemplateListCache.getInstance().reloadAllEditingTemplateByPlugin(event.getContext()); } }; - public static PluginRefreshManager getInstance() { + public static PluginClassRefreshManager getInstance() { return INSTANCE; } @@ -66,7 +49,7 @@ public class PluginRefreshManager { context.add(HyperlinkProvider.XML_TAG); } - private PluginRefreshManager() { + private PluginClassRefreshManager() { PluginListenerRegistration.getInstance().listen(PluginEventType.BeforeAllActive, new PluginEventListener() { @Override public void on(PluginEvent event) { @@ -78,25 +61,18 @@ public class PluginRefreshManager { public void on(PluginEvent event) { addPluginListener(); if (DesignerLaunchStatus.getStatus() != DesignerLaunchStatus.WORKSPACE_INIT_COMPLETE) { - HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(true); + HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(); } } }); } - public void registerItem(String xmlTag) { - context.add(xmlTag); - } - public void removePluginListener() { PluginListenerRegistration.getInstance().stopListen(this.pluginAfterRunEventListener); - PluginListenerRegistration.getInstance().stopListen(this.pluginBeforeStopEventListener); - } public void addPluginListener() { PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, this.pluginAfterRunEventListener); - PluginListenerRegistration.getInstance().listen(PluginEventType.BeforeStop, this.pluginBeforeStopEventListener); } } diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 88f64a4d5..5184c7d0d 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -46,8 +46,6 @@ public class HistoryTemplateListCache implements CallbackEvent { private List> historyList; private JTemplate editingTemplate; - private Map templateNeedReloadMap = new HashMap<>(); - public static HistoryTemplateListCache getInstance() { return Holder.INSTANCE; } @@ -78,9 +76,6 @@ public class HistoryTemplateListCache implements CallbackEvent { selected.fireJTemplateClosed(); selected.stopEditing(); try { - if (!templateNeedReloadMap.isEmpty()) { - templateNeedReloadMap.remove(selected.getEditingFILE().getName()); - } historyList.remove(contains(selected)); selected.getEditingFILE().closeTemplate(); FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Closed_Warn_Text", selected.getEditingFILE().getName())); @@ -412,7 +407,7 @@ public class HistoryTemplateListCache implements CallbackEvent { */ @Deprecated public void reloadCurrentTemplate() { - reloadAllEditingTemplate(true); + reloadAllEditingTemplate(); } /** @@ -430,15 +425,14 @@ public class HistoryTemplateListCache implements CallbackEvent { /** * 插件安装后/启用 重新加载模板资源 */ - public void reloadAllEditingTemplate(boolean mustReload) { + private void _reloadAllEditingTemplate(PluginContext context) { FineLoggerFactory.getLogger().info("Plugin env change reload all template started"); long start = System.currentTimeMillis(); int size = historyList.size(); for (int i = 0; i < size; i++) { JTemplate template = historyList.get(i); FILE file = template.getEditingFILE(); - Boolean value = templateNeedReloadMap.get(file.getName()); - boolean needReload = mustReload || (value != null && value); + boolean needReload = context == null || needReloadTemplate(context, template); if (needReload) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @@ -455,31 +449,38 @@ public class HistoryTemplateListCache implements CallbackEvent { } } } - templateNeedReloadMap.clear(); FineLoggerFactory.getLogger().info("Plugin env change reload all template ended"); FineLoggerFactory.getLogger().info("Reload all template spend: {} ms", (System.currentTimeMillis() - start)); } - public void calNeedReloadTemplate(PluginContext context) { - for (JTemplate template : historyList) { - BaseBook baseBook = template.getTarget(); - if (baseBook != null) { - String name = template.getEditingFILE().getName(); - long start = System.currentTimeMillis(); - Set set = ClassHelper.getClassLoaders(baseBook); - FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start)); - if (set != null) { - for (ClassLoader classLoader : set) { - PluginContext pluginContext = PluginManager.getContext(classLoader); - if (pluginContext != null && ComparatorUtils.equals(context.getName(), pluginContext.getName())) { - templateNeedReloadMap.put(name, true); - } - } - } else { - templateNeedReloadMap.put(name, true); - } + + public void reloadAllEditingTemplateByPlugin(PluginContext context) { + _reloadAllEditingTemplate(context); + } + + public void reloadAllEditingTemplate() { + _reloadAllEditingTemplate(null); + } + + private boolean needReloadTemplate(PluginContext context, JTemplate template) { + BaseBook baseBook = template.getTarget(); + if (baseBook != null) { + String name = template.getEditingFILE().getName(); + String pluginId = context.getID(); + long start = System.currentTimeMillis(); + Set set = ClassHelper.getClassLoaders(baseBook); + FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start)); + if (set != null) { + for (ClassLoader classLoader : set) { + if (PluginManager.isBeforeLoadBy(classLoader, pluginId)) { + return true; + } + } + } else { + return true; } } + return false; } } diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java index 5ca7efdd6..ebea410bb 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java @@ -1,6 +1,6 @@ package com.fr.start.module; -import com.fr.design.PluginRefreshManager; +import com.fr.design.PluginClassRefreshManager; import com.fr.module.Activator; import com.fr.start.DesignerInitial; @@ -16,7 +16,7 @@ public class DesignerInitActivator extends Activator { @Override public void start() { - PluginRefreshManager.getInstance().load(); + PluginClassRefreshManager.getInstance().load(); DesignerInitial.init(findSingleton(StartupArgs.class).get()); } From 11046865fc26ec0b7c0ed3b490dc3965e997fb88 Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 30 Dec 2020 16:15:03 +0800 Subject: [PATCH 07/12] =?UTF-8?q?KERNEL-6380=20=E8=B0=83=E6=95=B4=E4=B8=8B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/file/HistoryTemplateListCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 5184c7d0d..afb056ba1 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -472,7 +472,7 @@ public class HistoryTemplateListCache implements CallbackEvent { FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start)); if (set != null) { for (ClassLoader classLoader : set) { - if (PluginManager.isBeforeLoadBy(classLoader, pluginId)) { + if (ComparatorUtils.equals(pluginId, PluginManager.findPluginId(classLoader))) { return true; } } From 26e54fb4bf79070c457c28c81ba072bfa785e548 Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 30 Dec 2020 16:42:15 +0800 Subject: [PATCH 08/12] =?UTF-8?q?KERNEL-6380=20=E4=BF=AE=E6=94=B9=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/file/HistoryTemplateListCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index afb056ba1..1a1414417 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -472,7 +472,7 @@ public class HistoryTemplateListCache implements CallbackEvent { FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start)); if (set != null) { for (ClassLoader classLoader : set) { - if (ComparatorUtils.equals(pluginId, PluginManager.findPluginId(classLoader))) { + if (ComparatorUtils.equals(pluginId, PluginManager.detectLeakingPlugin(classLoader))) { return true; } } From c634b2fe1d1234ed3f778127f8571994e6c0c2ff Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 30 Dec 2020 17:00:16 +0800 Subject: [PATCH 09/12] =?UTF-8?q?KERNEL-6380=20=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/file/HistoryTemplateListCache.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 1a1414417..06bfd3cf7 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -453,11 +453,17 @@ public class HistoryTemplateListCache implements CallbackEvent { FineLoggerFactory.getLogger().info("Reload all template spend: {} ms", (System.currentTimeMillis() - start)); } - + /** + * 根据具体插件来刷新模板 + * @param context + */ public void reloadAllEditingTemplateByPlugin(PluginContext context) { _reloadAllEditingTemplate(context); } + /** + * 直接刷新所以模板 + */ public void reloadAllEditingTemplate() { _reloadAllEditingTemplate(null); } @@ -477,6 +483,7 @@ public class HistoryTemplateListCache implements CallbackEvent { } } } else { + // set为null说明 检测classloader 这里返回true直接刷新 兜底行为 return true; } } From ea708f0f74e6d127379b405ebc4abaa3ce8057a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Wed, 30 Dec 2020 18:00:54 +0800 Subject: [PATCH 10/12] =?UTF-8?q?CHART-17633=20=E5=9C=B0=E5=9B=BEgis?= =?UTF-8?q?=E5=9F=8B=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/van/chart/map/designer/type/VanChartMapPlotPane.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/designer-chart/src/main/java/com/fr/van/chart/map/designer/type/VanChartMapPlotPane.java b/designer-chart/src/main/java/com/fr/van/chart/map/designer/type/VanChartMapPlotPane.java index a5e26427b..9b5636e40 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/map/designer/type/VanChartMapPlotPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/map/designer/type/VanChartMapPlotPane.java @@ -2,9 +2,11 @@ package com.fr.van.chart.map.designer.type; import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.Plot; +import com.fr.chartx.config.info.constant.ConfigType; import com.fr.chartx.data.ChartDataDefinitionProvider; import com.fr.chartx.data.MapChartDataDefinition; import com.fr.design.mainframe.chart.gui.type.ChartImagePane; +import com.fr.design.mainframe.chart.info.ChartInfoCollector; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.log.FineLoggerFactory; import com.fr.plugin.chart.attr.plot.VanChartPlot; @@ -100,6 +102,7 @@ public class VanChartMapPlotPane extends AbstractVanChartTypePane { if (!isSamePlot() || (typeChanged && isSamePlot())) { resetAttr(plot); } + ChartInfoCollector.getInstance().updateChartConfig(chart, ConfigType.MAP, chart.getBuryingPointMapConfig()); } } /** From 8e34fc7c12c1d4220e89794d62d6047913339281 Mon Sep 17 00:00:00 2001 From: hades Date: Thu, 31 Dec 2020 09:34:10 +0800 Subject: [PATCH 11/12] =?UTF-8?q?KERNEL-6380=20=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=B8=8B=E8=BF=94=E5=9B=9E=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/PluginClassRefreshManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java b/designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java index 22f791f4f..711dd2975 100644 --- a/designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java +++ b/designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java @@ -31,7 +31,7 @@ public class PluginClassRefreshManager { for (String tag : context) { if (event.getContext().contain(tag)) { HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(); - break; + return; } } // 重新载入模板xml内容 到 Workbook/Form对象中 From 01f5e64443a53f50465830abda0233b1438ef341 Mon Sep 17 00:00:00 2001 From: hades Date: Mon, 4 Jan 2021 10:36:30 +0800 Subject: [PATCH 12/12] =?UTF-8?q?KERNEL-6380=20=E6=BC=8F=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/start/module/DesignerWorkspaceActivator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java index 1842ea762..7154de982 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java @@ -1,7 +1,7 @@ package com.fr.start.module; import com.fr.concurrent.NamedThreadFactory; -import com.fr.design.PluginRefreshManager; +import com.fr.design.PluginClassRefreshManager; import com.fr.design.file.HistoryTemplateListCache; import com.fr.event.Event; import com.fr.event.Listener; @@ -51,7 +51,7 @@ public class DesignerWorkspaceActivator extends Activator { @Override public void on(Event event, Workspace workspace) { - PluginRefreshManager.getInstance().removePluginListener(); + PluginClassRefreshManager.getInstance().removePluginListener(); HistoryTemplateListCache.getInstance().stash(); } }); @@ -63,7 +63,7 @@ public class DesignerWorkspaceActivator extends Activator { public void on(Event event, Workspace workspace) { HistoryTemplateListCache.getInstance().load(); - PluginRefreshManager.getInstance().addPluginListener(); + PluginClassRefreshManager.getInstance().addPluginListener(); } }); }