Browse Source

Merge pull request #9299 in DESIGN/design from bugfix/11.0 to feature/x

* commit 'cc17fbce9fc0d83c20d24a73313cc98028a7ff5a':
  KERNEL-11501 去除classhelper
feature/x
superman 2 years ago
parent
commit
ae41d48898
  1. 37
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java
  2. 91
      designer-base/src/main/java/com/fr/design/mod/ContentObjectManager.java
  3. 3
      designer-base/src/main/java/com/fr/design/mod/ContentReplacerCenter.java
  4. 26
      designer-base/src/main/java/com/fr/design/record/analyzer/DesignerAnalyzerActivator.java
  5. 28
      designer-base/src/main/java/com/fr/design/record/analyzer/Interceptor/CollectInterceptor.java
  6. 26
      designer-base/src/main/java/com/fr/design/record/analyzer/advice/CollectAdvice.java
  7. 2
      designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java

37
designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java

@ -1,12 +1,10 @@
package com.fr.design.file;
import com.fr.base.chart.chartdata.CallbackEvent;
import com.fr.base.io.BaseBook;
import com.fr.design.DesignerEnvManager;
import com.fr.design.base.mode.DesignModeContext;
import com.fr.design.base.mode.DesignerMode;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.file.filter.ClassFilter;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrameFileDealerPane;
@ -16,10 +14,8 @@ import com.fr.design.ui.util.UIUtil;
import com.fr.file.FILE;
import com.fr.file.FileNodeFILE;
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;
import com.fr.stable.CoreConstants;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.commons.io.FilenameUtils;
@ -429,13 +425,10 @@ public class HistoryTemplateListCache implements CallbackEvent {
for (int i = 0; i < size; i++) {
JTemplate<?, ?> template = historyList.get(i);
FILE file = template.getEditingFILE();
boolean needReload = context == null || needReloadTemplate(context, template);
if (needReload) {
FILE stashFile = template.templateToStashFile();
if (stashFile != null) {
FineLoggerFactory.getLogger().info("{} is being reloaded", file.getName());
template.refreshResource(stashFile);
}
FILE stashFile = template.templateToStashFile();
if (stashFile != null) {
FineLoggerFactory.getLogger().info("{} is being reloaded", file.getName());
template.refreshResource(stashFile);
}
}
FineLoggerFactory.getLogger().info("Plugin env change reload all template ended");
@ -457,28 +450,6 @@ public class HistoryTemplateListCache implements CallbackEvent {
_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<ClassLoader> set = ClassHelper.getClassLoadersByFilter(baseBook, ClassFilter.getInstance());
FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start));
if (set != null) {
for (ClassLoader classLoader : set) {
if (ComparatorUtils.equals(pluginId, PluginManager.detectLeakingPlugin(classLoader))) {
return true;
}
}
} else {
// set为null说明 检测classloader 这里返回true直接刷新 兜底行为
return true;
}
}
return false;
}
public void replaceCurrentEditingTemplate(JTemplate<?, ?> jt) {
int index = contains(this.editingTemplate);
this.editingTemplate = jt;

91
designer-base/src/main/java/com/fr/design/mod/ContentObjectManager.java

@ -1,32 +1,15 @@
package com.fr.design.mod;
import com.fr.base.Formula;
import com.fr.base.headerfooter.FormulaHFElement;
import com.fr.base.present.FormulaPresent;
import com.fr.chart.web.ChartHyperRelateCellLink;
import com.fr.chart.web.ChartHyperRelateFloatLink;
import com.fr.data.SimpleDSColumn;
import com.fr.data.condition.FormulaCondition;
import com.fr.data.impl.FormulaDictionary;
import com.fr.data.impl.NameTableData;
import com.fr.design.mod.impl.repalce.JavaScriptContentReplacer;
import com.fr.design.mod.impl.repalce.VanChartHtmlLabelContentReplacer;
import com.fr.form.main.FormHyperlink;
import com.fr.form.ui.CardSwitchButton;
import com.fr.form.ui.WidgetTitle;
import com.fr.invoke.ClassHelper;
import com.fr.form.ui.Widget;
import com.fr.js.JavaScriptImpl;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.chart.base.VanChartHtmlLabel;
import com.fr.report.cell.cellattr.CellExpandAttr;
import com.fr.report.cell.cellattr.CellGUIAttr;
import com.fr.report.cell.cellattr.core.RichChar;
import com.fr.report.cell.cellattr.core.group.DSColumn;
import com.fr.report.cell.cellattr.core.group.FunctionGrouper;
import com.fr.report.cell.cellattr.core.group.SelectCount;
import com.fr.stable.Filter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
@ -49,53 +32,36 @@ public class ContentObjectManager {
/**
* 放置所有需要替换内容的对象
*/
private Map<String, Collection<Object>> objectMap;
private final Set<String> set = new HashSet<>();
private Map<String, Collection<Object>> objectMap = new HashMap<>();
private final Map<String, ContentReplacer> map = new HashMap<>();
private boolean needCollect = false;
private ContentObjectManager() {
set.add(Formula.class.getName());
set.add(JavaScriptImpl.class.getName());
set.add(ChartHyperRelateCellLink.class.getName());
set.add(ChartHyperRelateFloatLink.class.getName());
set.add(VanChartHtmlLabel.class.getName());
set.add(NameTableData.class.getName());
set.add(SimpleDSColumn.class.getName());
set.add(DSColumn.class.getName());
set.add(FormHyperlink.class.getName());
set.add(CellExpandAttr.class.getName());
set.add(FormulaCondition.class.getName());
set.add(FormulaDictionary.class.getName());
set.add(FormulaHFElement.class.getName());
set.add(FormulaPresent.class.getName());
set.add(RichChar.class.getName());
set.add(CardSwitchButton.class.getName());
set.add(CellGUIAttr.class.getName());
set.add(SelectCount.class.getName());
set.add(WidgetTitle.class.getName());
set.add(FunctionGrouper.class.getName());
map.put(JavaScriptImpl.class.getName(), new JavaScriptContentReplacer());
map.put(VanChartHtmlLabel.class.getName(), new VanChartHtmlLabelContentReplacer());
}
public void searchObject(Object ob) {
objectMap = ClassHelper.searchObject(ob, set, ModClassFilter.getInstance());
}
public void searchObject(Object ob, Filter<String> filter) {
objectMap = ClassHelper.searchObject(ob, set, filter);
@Nullable
public Widget searchObject(Widget widget) {
try {
needCollect = true;
objectMap.clear();
Widget clonedWidget = (Widget) widget.clone();
needCollect = false;
return clonedWidget;
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
// 防止抛出异常未重置
needCollect = false;
}
return null;
}
public void searchObject(Object ob, Set<String> set, Filter<String> filter) {
objectMap = ClassHelper.searchObject(ob, set, filter);
}
public void clearObject() {
if (objectMap != null) {
objectMap.clear();
}
objectMap = null;
objectMap.clear();
}
@Nullable
@ -103,8 +69,15 @@ public class ContentObjectManager {
return objectMap;
}
public boolean needContentTip(Object ob, Set<String> nameSet) {
objectMap = ClassHelper.searchObject(ob, set, ModClassFilter.getInstance());
public void collect(Object ob) {
if (needCollect) {
Collection<Object> collection = objectMap.computeIfAbsent(ob.getClass().getName(), k -> new ArrayList<>());
collection.add(ob);
}
}
public boolean needContentTip(Widget ob, Set<String> nameSet) {
collect(ob);
for (Map.Entry<String, Collection<Object>> entry : objectMap.entrySet()) {
for (Object o : entry.getValue()) {
for (String name : nameSet) {

3
designer-base/src/main/java/com/fr/design/mod/ContentReplacerCenter.java

@ -70,9 +70,6 @@ public class ContentReplacerCenter {
@Override
public void on(Event event, ContentChangeItem param) {
itemsMap.put(param.getChangeItem(), param);
long start = System.currentTimeMillis();
ContentObjectManager.getInstance().searchObject(param.getObject());
FineLoggerFactory.getLogger().debug("search object spend {} ms", (System.currentTimeMillis() - start));
FineLoggerFactory.getLogger().debug("search result: {}", ContentObjectManager.getInstance().getObjectMap() == null
? null : ContentObjectManager.getInstance().getObjectMap().keySet());
List<ContentChangeItem> itemsCopy = new ArrayList<>(itemsMap.values());

26
designer-base/src/main/java/com/fr/design/record/analyzer/DesignerAnalyzerActivator.java

@ -1,8 +1,11 @@
package com.fr.design.record.analyzer;
import com.fr.base.OptimizeUtil;
import com.fr.collect.Collect;
import com.fr.design.record.analyzer.Interceptor.CollectInterceptor;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.constants.DesignerLaunchStatus;
import com.fr.design.record.analyzer.advice.CollectAdvice;
import com.fr.design.record.analyzer.advice.DBMonitorAdvice;
import com.fr.design.record.analyzer.advice.FaultToleranceAdvice;
import com.fr.design.record.analyzer.advice.FocusAdvice;
@ -19,6 +22,7 @@ import com.fr.module.Activator;
import com.fr.module.extension.Prepare;
import com.fr.record.analyzer.AnalyzerConfiguration;
import com.fr.record.analyzer.AnalyzerKey;
import com.fr.record.analyzer.Assistant;
import com.fr.record.analyzer.DBMetrics;
import com.fr.record.analyzer.FineAnalyzer;
import com.fr.record.analyzer.advice.AnalyzerAdviceKey;
@ -26,7 +30,11 @@ import com.fr.record.analyzer.advice.FineAdviceAssistant;
import com.fr.record.analyzer.configuration.AnalyzerAssemblyFactory;
import com.fr.record.analyzer.configuration.FineAnalyzerAssemblyFactory;
import com.fr.stable.collections.CollectionUtils;
import com.fr.third.net.bytebuddy.description.type.TypeDescription;
import com.fr.third.net.bytebuddy.dynamic.DynamicType;
import com.fr.third.net.bytebuddy.implementation.MethodDelegation;
import com.fr.third.net.bytebuddy.matcher.ElementMatchers;
import com.fr.third.net.bytebuddy.utility.JavaModule;
import com.fr.tolerance.FaultTolerance;
import org.jetbrains.annotations.NotNull;
@ -117,6 +125,24 @@ public class DesignerAnalyzerActivator extends Activator implements Prepare {
ElementMatchers.isAnnotatedWith(FaultTolerance.class),
FaultToleranceAdvice.class
));
// 保持M1 可用
addMutable(AnalyzerKey.KEY, AnalyzerConfiguration.create(new Assistant() {
@Override
public DynamicType.Builder<?> supply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) {
return builder
.method(ElementMatchers.isAnnotatedWith(Collect.class))
.intercept(MethodDelegation.to(CollectInterceptor.class));
}
}));
addMutable(AnalyzerAdviceKey.KEY, FineAdviceAssistant.create(
ElementMatchers.isAnnotatedWith(Collect.class),
CollectAdvice.class
));
}

28
designer-base/src/main/java/com/fr/design/record/analyzer/Interceptor/CollectInterceptor.java

@ -0,0 +1,28 @@
package com.fr.design.record.analyzer.Interceptor;
import com.fr.design.mod.ContentObjectManager;
import com.fr.third.net.bytebuddy.implementation.bind.annotation.AllArguments;
import com.fr.third.net.bytebuddy.implementation.bind.annotation.Origin;
import com.fr.third.net.bytebuddy.implementation.bind.annotation.RuntimeType;
import com.fr.third.net.bytebuddy.implementation.bind.annotation.SuperCall;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;
/**
* 收集
*
* @author hades
* @version 11.0
* Created by hades on 2022/6/17
*/
public class CollectInterceptor {
@RuntimeType
public static Object intercept(@Origin Method method,
@SuperCall Callable<?> callable,
@AllArguments Object[] args) throws Exception {
Object result = callable.call();
ContentObjectManager.getInstance().collect(result);
return result;
}
}

26
designer-base/src/main/java/com/fr/design/record/analyzer/advice/CollectAdvice.java

@ -0,0 +1,26 @@
package com.fr.design.record.analyzer.advice;
import com.fr.design.mod.ContentObjectManager;
import com.fr.design.record.analyzer.DesignerAnalyzerAdvice;
import com.fr.third.net.bytebuddy.asm.Advice;
import com.fr.third.net.bytebuddy.implementation.bytecode.assign.Assigner;
import java.lang.reflect.Method;
/**
* @author hades
* @version 11.0
* Created by hades on 2022/6/17
*/
public class CollectAdvice implements DesignerAnalyzerAdvice {
@Advice.OnMethodExit(onThrowable = Exception.class)
public static void onMethodExit(@Advice.This(optional = true, typing = Assigner.Typing.DYNAMIC) Object self,
@Advice.Origin Method method,
@Advice.AllArguments(typing = Assigner.Typing.DYNAMIC) Object[] args,
@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object result) throws Exception {
ContentObjectManager.getInstance().collect(result);
}
}

2
designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java

@ -15,6 +15,7 @@ import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.FormSelection;
import com.fr.design.mainframe.JForm;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mod.ContentObjectManager;
import com.fr.form.share.SharableWidgetProvider;
import com.fr.form.share.bean.ShareLayoutWidget;
import com.fr.form.share.constants.ComponentPath;
@ -42,6 +43,7 @@ public class ShareComponentUtils {
public static XCreator createXCreator(Widget creatorSource, String shareId, SharableWidgetProvider provider) {
XCreator xCreator;
creatorSource = ContentObjectManager.getInstance().searchObject(creatorSource);
if (creatorSource instanceof WCardMainBorderLayout) {
xCreator = XCreatorUtils.createXCreator(creatorSource, new Dimension(500, 300));
} else if (creatorSource instanceof ShareLayoutWidget) {

Loading…
Cancel
Save