diff --git a/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java b/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java index 5a524e5b5..98938a4f8 100644 --- a/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java +++ b/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java @@ -1,5 +1,6 @@ package com.fr.env.detect; +import com.fr.common.util.Collections; import com.fr.design.components.notification.NotificationDialog; import com.fr.design.components.notification.NotificationDialogProperties; import com.fr.design.components.notification.NotificationModel; @@ -28,6 +29,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; /** + * 环境检测中心 + * 如果环境检测 -> + * * created by Harrison on 2022/05/27 **/ public class EnvDetectorCenter { @@ -42,6 +46,9 @@ public class EnvDetectorCenter { private final AtomicReference PROCESS = new AtomicReference<>(); + /** + * 初始化 + */ public void init() { // 默认是启动 @@ -58,18 +65,11 @@ public class EnvDetectorCenter { } }); - // 切换工作目录 - EventDispatcher.listen(WorkspaceEvent.BeforeSwitch, new Listener() { - @Override - public void on(Event event, Workspace param) { - PROCESS.set(DetectorProcess.ENV_SWITCH); - start(); - } - }); + // 切换完成后的监听 EventDispatcher.listen(WorkspaceEvent.AfterSwitch, new Listener() { @Override public void on(Event event, Workspace param) { - if (isSameProcess(DetectorProcess.ENV_SWITCH)) { + if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) { stop(); } } @@ -108,33 +108,44 @@ public class EnvDetectorCenter { return PROCESS.compareAndSet(process, null); } + /** + * 启动 + */ public void start() { DetectorBridge.getInstance().start(); } + /** + * 关闭 + */ public void stop() { - Stream resultStream = DetectorBridge.getInstance().detect(); - - // 展示效果 - NotificationDialogProperties properties = new NotificationDialogProperties(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Detect_Notification_Title")); - List notificationModels = resultStream - .filter(Objects::nonNull) - .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) - .map(DetectorUtil::convert2Notification) - .collect(Collectors.toList()); - // 一分钟后执行 DelayHelper.delayCall(EnvDetectorCenter.class.getName(), () -> { + + Stream resultStream = DetectorBridge.getInstance().detect(); + + // 结束 + DetectorBridge.getInstance().stop(); + + // 展示效果 + NotificationDialogProperties properties = new NotificationDialogProperties(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Detect_Notification_Title")); + List notificationModels = resultStream + .filter(Objects::nonNull) + .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) + .map(DetectorUtil::convert2Notification) + .collect(Collectors.toList()); + if (Collections.isEmpty(notificationModels)) { + return; + } + UIUtil.invokeLaterIfNeeded(() -> { NotificationDialog dialog = new NotificationDialog(properties, notificationModels); dialog.open(); }); - }, 1, TimeUnit.MINUTES); + }, 30, TimeUnit.SECONDS); - // 结束 - DetectorBridge.getInstance().stop(); } /** @@ -146,10 +157,9 @@ public class EnvDetectorCenter { public List terminate(Throwable throwable) { Stream resultStream = DetectorBridge.getInstance().detect(throwable); - List results = resultStream + return resultStream .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) .collect(Collectors.toList()); - return results; } private enum DetectorProcess { diff --git a/designer-base/src/main/java/com/fr/env/detect/EnvPrepare.java b/designer-base/src/main/java/com/fr/env/detect/EnvPrepare.java new file mode 100644 index 000000000..eedc591db --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/EnvPrepare.java @@ -0,0 +1,21 @@ +package com.fr.env.detect; + +import com.fr.module.Activator; + +/** + * 设计器环境准备 + * + * created by Harrison on 2022/05/29 + **/ +public class EnvPrepare extends Activator { + + @Override + public void start() { + EnvDetectorCenter.getInstance().init(); + } + + @Override + public void stop() { + + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java b/designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java index 534fa7abf..0d5b60bc0 100644 --- a/designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java +++ b/designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java @@ -17,6 +17,9 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Stream; /** + * 检测器桥接逻辑 + * [detect-core] - bridge - ui + * * created by Harrison on 2022/05/13 **/ public class DetectorBridge { @@ -53,7 +56,7 @@ public class DetectorBridge { public void start() { - if (!hasStarted.get() && ExceptionDetectorConfig.getInstance().isOpen()) { + if (!hasStarted.get() && EnvDetectorConfig.getInstance().isEnabled()) { // 开始注册异常处理 ThrowableLogAppender.getInstance().enable(); hasStarted.set(true); @@ -91,11 +94,10 @@ public class DetectorBridge { @NotNull public DetectorResult detect(DetectorType type, Throwable throwable) { - // 先清理一下 - ThrowableStore.getInstance().reset(); - ThrowableStore.getInstance().add(throwable); + DetectorResult result = detect(type); + ThrowableStore.getInstance().reset(); return result; @@ -123,9 +125,6 @@ public class DetectorBridge { */ public Stream detect(Throwable throwable) { - // 先清理一下 - ThrowableStore.getInstance().reset(); - ThrowableStore.getInstance().add(throwable); Stream result = detect(); ThrowableStore.getInstance().reset(); diff --git a/designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java b/designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java index ced502129..bc65870da 100644 --- a/designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java +++ b/designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java @@ -7,9 +7,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; import java.util.stream.Stream; /** + * 检测器中心 + * * created by Harrison on 2022/05/24 **/ class DetectorManager { @@ -29,9 +32,10 @@ class DetectorManager { .map(ExceptionDetector::detect) .filter(Objects::nonNull); - // 记录一下日志 - results.forEach(DetectorResult::log); - return results; + List resultList = results.collect(Collectors.toList()); + resultList.forEach(DetectorResult::log); + + return resultList.stream(); } public DetectorResult detect(DetectorType type) { diff --git a/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java b/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java index 12c51d19b..fdfccf216 100644 --- a/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java +++ b/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java @@ -7,6 +7,7 @@ import com.fr.design.components.notification.NotificationModel; import com.fr.design.components.notification.NotificationType; import com.fr.design.dialog.link.MessageWithLink; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.utils.LinkStrUtils; import com.fr.env.detect.bean.DetectorResult; import com.fr.env.detect.bean.ExceptionSolution; import com.fr.env.detect.bean.ExceptionTips; @@ -29,11 +30,26 @@ import java.util.function.Function; **/ public class DetectorUtil { + /** + * 是否是设计器的 jar + * + * @param info 信息 + * @return 是/否 + */ public static boolean isDesignerJar(BuildInfo info) { - + + if (info == null) { + return false; + } return StringUtils.contains(info.getJar(), "fine-report-designer"); } + /** + * 将结果转化为提醒的数据 + * + * @param result 结果 + * @return 数据 + */ public static NotificationModel convert2Notification(DetectorResult result) { List messages = new ArrayList<>(); @@ -59,34 +75,46 @@ public class DetectorUtil { }; ExceptionTips tips = result.getTips(); - convert2NotificationMsg - .apply(tips.getMessage()) - .ifPresent(messages::add); + if (tips != null) { + convert2NotificationMsg + .apply(tips.getMessage()) + .ifPresent(messages::add); + } ExceptionSolution solution = result.getSolution(); - convert2NotificationMsg.apply(solution.getMessage()) - .ifPresent(messages::add); + if (solution != null) { + convert2NotificationMsg.apply(solution.getMessage()) + .ifPresent(messages::add); + } NotificationAction notificationAction = null; - SolutionAction solutionAction = solution.getAction(); - if (solutionAction != null) { - notificationAction = new NotificationAction() { - @Override - public String name() { - return solutionAction.name(); - } - - @Override - public void run(Object... args) { - solutionAction.run(); - } - }; + if (solution != null) { + SolutionAction solutionAction = solution.getAction(); + if (solutionAction != null) { + notificationAction = new NotificationAction() { + @Override + public String name() { + return solutionAction.name(); + } + + @Override + public void run(Object... args) { + solutionAction.run(); + } + }; + } } return new NotificationModel(NotificationType.WARNING, notificationAction, messages); } - public static JComponent convert2Component(@NotNull Message message) { + /** + * 将信息转化为展示的组件 + * + * @param message 信息 + * @return 组件 + */ + public static JComponent convert2TextComponent(@NotNull Message message) { if (message.getType() == Message.Type.LINK) { Message.Link linkMsg = (Message.Link) message; @@ -94,6 +122,6 @@ public class DetectorUtil { Desktop.getDesktop().browse(URI.create(linkMsg.getLink())); })); } - return new UILabel(message.get()); + return new UILabel(LinkStrUtils.generateHtmlTag(message.get())); } } diff --git a/designer-base/src/main/java/com/fr/env/detect/base/EnvDetectorConfig.java b/designer-base/src/main/java/com/fr/env/detect/base/EnvDetectorConfig.java new file mode 100644 index 000000000..caafdbe46 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/base/EnvDetectorConfig.java @@ -0,0 +1,59 @@ +package com.fr.env.detect.base; + +import com.fr.design.DesignerEnvManager; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLable; +import com.fr.stable.xml.XMLableReader; + +/** + * created by Harrison on 2022/05/13 + **/ +public class EnvDetectorConfig implements XMLable { + + public static final String XML_TAG = "EnvDetectorConfig"; + + private static final long serialVersionUID = -8170289826729582122L; + + private static final EnvDetectorConfig INSTANCE = new EnvDetectorConfig(); + + public static EnvDetectorConfig getInstance() { + + return INSTANCE; + } + + private boolean enabled = true; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + save(); + } + + private void save() { + + DesignerEnvManager.getEnvManager(false).saveXMLFile(); + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + @Override + public void readXML(XMLableReader reader) { + if (reader.isAttr()) { + this.setEnabled(reader.getAttrAsBoolean("isEnabled", true)); + } + } + + @Override + public void writeXML(XMLPrintWriter writer) { + writer.startTAG(XML_TAG); + writer.attr("isEnabled", this.isEnabled()); + writer.end(); + } + +} diff --git a/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java b/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java deleted file mode 100644 index 724e5e8d3..000000000 --- a/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.fr.env.detect.base; - -import com.fr.config.ConfigContext; -import com.fr.config.DefaultConfiguration; -import com.fr.config.holder.Conf; -import com.fr.config.holder.factory.Holders; - -/** - * created by Harrison on 2022/05/13 - **/ -public class ExceptionDetectorConfig extends DefaultConfiguration { - - private static volatile ExceptionDetectorConfig instance = null; - - public static ExceptionDetectorConfig getInstance() { - - if (instance == null) { - instance = ConfigContext.getConfigInstance(ExceptionDetectorConfig.class); - } - return instance; - } - - private final Conf open = Holders.simple(true); - - public void setOpen(boolean open) { - - this.open.set(open); - } - - public boolean isOpen() { - - return open.get(); - } -} diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java b/designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java index 6012be3d3..679671997 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java @@ -33,6 +33,8 @@ import java.util.stream.Collectors; **/ public class JarInconsistentDetector extends AbstractExceptionDetector { + public static final String SEPARATOR = ","; + public JarInconsistentDetector() { super(DetectorType.JAR_IN_CONSISTENCE); @@ -81,14 +83,14 @@ public class JarInconsistentDetector extends AbstractExceptionDetector { Set inConsistentJars = diffInCommon.keySet(); - String message = StringUtils.join(",", inConsistentJars); - Message.Simple tipsMessage = new Message.Simple(Toolkit.i18nText("Fine_Design_Basic_Detect_Server") + Toolkit.i18nText(type().getTipsLocale()) + "\n" + message); + String message = StringUtils.join(inConsistentJars, SEPARATOR); + Message.Simple tipsMessage = new Message.Simple(Toolkit.i18nText("Fine_Design_Basic_Detect_Server") + Toolkit.i18nText(type().getTipsLocale()) + message); return DetectorResult.exception(type(), new ExceptionTips(tipsMessage), new ExceptionSolution(new Message.Link(Toolkit.i18nText(type().getSolutionLocale(),DetectorConstants.JAR_HELP_LINK) , DetectorConstants.JAR_HELP_LINK), null), - ExceptionLog.create(type().getLogLocale() + message)); + ExceptionLog.create(Toolkit.i18nText(type().getLogLocale()) + message)); } @NotNull @@ -124,8 +126,8 @@ public class JarInconsistentDetector extends AbstractExceptionDetector { List inConsistentJars = inConsistentInfos.stream() .map(BuildInfo::getJar) .collect(Collectors.toList()); - String message = StringUtils.join(",", inConsistentJars); - String tipsMessage = Toolkit.i18nText("Fine_Design_Basic_Detect_Local") + Toolkit.i18nText(type().getTipsLocale()) + "\n" + message; + String message = StringUtils.join(inConsistentJars, SEPARATOR); + String tipsMessage = Toolkit.i18nText("Fine_Design_Basic_Detect_Local") + Toolkit.i18nText(type().getTipsLocale()) + message; return DetectorResult.exception(type(), new ExceptionTips(new Message.Simple(tipsMessage)), diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java b/designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java index 2175b8bb1..74c908000 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java @@ -1,7 +1,7 @@ package com.fr.env.detect.impl; import com.fr.common.util.Collections; -import com.fr.common.util.Strings; +import com.fr.design.i18n.Toolkit; import com.fr.env.detect.base.AbstractExceptionDetector; import com.fr.env.detect.base.DetectorConstants; import com.fr.env.detect.base.DetectorUtil; @@ -14,7 +14,6 @@ import com.fr.env.detect.bean.Message; import com.fr.general.build.BuildInfo; import com.fr.general.build.BuildInfoOperator; import com.fr.general.build.impl.BuildInfoOperatorImpl; -import com.fr.locale.InterProviderFactory; import com.fr.third.guava.collect.Lists; import com.fr.third.org.apache.commons.lang3.StringUtils; import com.fr.workspace.WorkContext; @@ -30,6 +29,11 @@ import java.util.stream.Collectors; **/ public class JarLackDetector extends AbstractExceptionDetector { + public static final String SEPARATOR = "、"; + public static final String BR_TAG = "
"; + public static final String WEB_LIB_PATH = "%FR_HOME%\\webapps\\webroot\\WEB-INF\\lib:"; + public static final String FR_HOME_LIB = "%FR_HOME%\\lib:"; + public JarLackDetector() { super(DetectorType.LACK_OF_JAR); @@ -57,9 +61,10 @@ public class JarLackDetector extends AbstractExceptionDetector { Message tipsMsg = tipsMessage(lackInfos); ExceptionLog exceptionLog = exceptionLog(lackInfos); - return DetectorResult.exception(type(), new ExceptionTips(tipsMsg), + return DetectorResult.exception(type(), + new ExceptionTips(tipsMsg), new ExceptionSolution( - new Message.Link(InterProviderFactory.getProvider().getLocText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), + new Message.Link(Toolkit.i18nText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), null), exceptionLog); } @@ -68,8 +73,8 @@ public class JarLackDetector extends AbstractExceptionDetector { List jarInfos = lackInfos.stream() .map(BuildInfo::getJar) .collect(Collectors.toList()); - String message = StringUtils.join(",", jarInfos); - return ExceptionLog.create(type().getLogLocale() + message); + String message = StringUtils.join(jarInfos, ","); + return ExceptionLog.create(Toolkit.i18nText(type().getLogLocale()) + message); } private boolean isLackInfo(BuildInfo e) { @@ -78,8 +83,8 @@ public class JarLackDetector extends AbstractExceptionDetector { private Message tipsMessage(List infos) { - String webLibPath = "%FR_HOME%\\webapps\\webroot\\WEB-INF\\lib:"; - String homeLibPath = "%FR_HOME%\\lib:"; + String webLibPath = WEB_LIB_PATH; + String homeLibPath = FR_HOME_LIB; Map> libMap = groupByPath(infos, homeLibPath, webLibPath); @@ -87,23 +92,24 @@ public class JarLackDetector extends AbstractExceptionDetector { List homeLibs = libMap.get(homeLibPath); if (!Collections.isEmpty(homeLibs)) { - sb.append(homeLibPath).append(":"); - sb.append(StringUtils.join("、", homeLibs)); + sb.append(homeLibPath); + sb.append(StringUtils.join(homeLibs, SEPARATOR)); } List webLibs = libMap.get(webLibPath); if (!Collections.isEmpty(webLibs)) { if (sb.length() != 0) { - sb.append("\n"); + sb.append(BR_TAG); } - sb.append(Strings.join("、", webLibs)); + sb.append(webLibPath); + sb.append(StringUtils.join(webLibs, SEPARATOR)); } String mainContent = sb.toString(); DetectorType type = this.type(); - String header = InterProviderFactory.getProvider().getLocText(type.getTipsLocale()); - return new Message.Simple(header + "\n" + mainContent); + String header = Toolkit.i18nText(type.getTipsLocale()); + return new Message.Simple(header + mainContent); } @NotNull diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java index 4fa33f301..3432d976d 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java @@ -1,6 +1,5 @@ package com.fr.env.detect.impl.converter; -import com.fr.common.util.Strings; import com.fr.design.i18n.Toolkit; import com.fr.env.detect.base.DetectorConstants; import com.fr.env.detect.bean.DetectorResult; @@ -10,6 +9,8 @@ import com.fr.env.detect.bean.ExceptionSolution; import com.fr.env.detect.bean.ExceptionTips; import com.fr.env.detect.thowable.ThrowableConverter; import com.fr.stable.resource.ResourceLoader; +import com.fr.third.org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import javax.el.MethodNotFoundException; import java.io.IOException; @@ -33,13 +34,15 @@ import java.util.regex.Pattern; **/ public class ClassConflictConvertor implements ThrowableConverter { - private Map, ClassNameConverter> throwableMap = new HashMap<>(); - + public static final String CLASSES = "classes"; + public static final String SEPARATOR = "、"; /** * 获取对应的 JAR 包名称 */ private static final Pattern JAR_NAME_PATTERN = Pattern.compile("([\\w+-\\.]*\\.jar)"); + private final Map, ClassNameConverter> throwableMap = new HashMap<>(); + public ClassConflictConvertor() { // 类异常 @@ -82,7 +85,7 @@ public class ClassConflictConvertor implements ThrowableConverter { Set allPath = new HashSet<>(); for (String className : classNames) { - String classFile = "/" + className.replaceAll("\\.", "/") + ".class"; + String classFile = convertClass2Path(className); try { Enumeration urls = ResourceLoader.getResources(classFile, this.getClass()); List urlList = new ArrayList<>(); @@ -97,9 +100,9 @@ public class ClassConflictConvertor implements ThrowableConverter { String jar = matcher.group(); allPath.add(jar); } else { - boolean containsClasses = file.contains("classes"); + boolean containsClasses = file.contains(CLASSES); if (containsClasses) { - allPath.add("classes"); + allPath.add(CLASSES); } } } @@ -107,15 +110,21 @@ public class ClassConflictConvertor implements ThrowableConverter { } } - String msg = Strings.join("、", allPath); + String msg = StringUtils.join(allPath, SEPARATOR); DetectorType type = DetectorType.JAR_CONFLICT; return DetectorResult.exception(type, - ExceptionTips.create(Toolkit.i18nText(type.getTipsLocale()) + msg), + ExceptionTips.create(Toolkit.i18nText(type.getTipsLocale(), msg)), ExceptionSolution.create(Toolkit.i18nText(type.getSolutionLocale()), DetectorConstants.JAR_HELP_LINK, null), ExceptionLog.create(Toolkit.i18nText(type.getLogLocale()), msg)); } + @NotNull + private String convertClass2Path(String className) { + + return "/" + className.replaceAll("\\.", "/") + ".class"; + } + private interface ClassNameConverter { /** diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java index fe114b253..4550cde4a 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java @@ -19,9 +19,7 @@ import com.fr.third.org.hibernate.exception.GenericJDBCException; import org.jetbrains.annotations.Nullable; import javax.swing.JOptionPane; -import java.util.HashMap; import java.util.Iterator; -import java.util.Map; /** * 脏数据检测 @@ -53,24 +51,22 @@ public class FineDbDirtyConverter implements ThrowableConverter { */ @Override public @Nullable DetectorResult convert(Throwable throwable) { - - // 检测 Config - Throwable sign = throwable; - while (sign.getClass() != GenericJDBCException.class) { - sign = sign.getCause(); - } - - Map configMap = getAllConfigurationClassName(); - StackTraceElement[] stackTrace = sign.getStackTrace(); - for (StackTraceElement stackTraceElement : stackTrace) { - String className = stackTraceElement.getClassName(); - if (configMap.containsKey(className)) { + Iterator tableNames = ConfigContext.getConfigNames(); + while (tableNames.hasNext()) { + String tableName = tableNames.next(); + Class configClass = ConfigContext.getConfigClass(tableName); + Configuration configuration = ConfigContext.getConfigInstance(configClass); + try { + + // 尝试获取每一个值 + configuration.mirror(); + } catch (Throwable e) { + DetectorType detectorType = DetectorType.FINE_DB_DIRTY; DetectorResult.DetectorResultBuilder builder = DetectorResult.builder() .withType(detectorType); - String tableName = configMap.get(className); String tipsLocale = Toolkit.i18nText(detectorType.getTipsLocale(), tableName); String solutionLocale = detectorType.getSolutionLocale(); @@ -79,7 +75,7 @@ public class FineDbDirtyConverter implements ThrowableConverter { public String name() { return Toolkit.i18nText("Fine-Design_Basic_Reset_Immediately"); } - + @Override public void run() { boolean success = false; @@ -90,6 +86,7 @@ public class FineDbDirtyConverter implements ThrowableConverter { } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } + // todo 最好的逻辑是,这里应该和 UI 隔离开的 if (!success) { FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset_Result", @@ -106,21 +103,8 @@ public class FineDbDirtyConverter implements ThrowableConverter { return builder.build(); } } - - return null; + + return DetectorResult.normal(DetectorType.FINE_DB_DIRTY); } - private Map getAllConfigurationClassName() { - - Map configMap = new HashMap<>(); - Iterator tableNames = ConfigContext.getConfigNames(); - while (tableNames.hasNext()) { - String tableName = tableNames.next(); - Class configClass = ConfigContext.getConfigClass(tableName); - String className = configClass.getName(); - configMap.put(className, tableName); - } - return configMap; - - } } diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java index 22f600104..8a5e74f0b 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java @@ -5,6 +5,7 @@ import com.fr.env.detect.base.DetectorConstants; import com.fr.env.detect.bean.DetectorResult; import com.fr.env.detect.bean.DetectorType; import com.fr.env.detect.thowable.ThrowableConverter; +import com.fr.third.org.apache.commons.lang3.StringUtils; import com.fr.third.org.hsqldb.HsqlException; /** @@ -12,6 +13,8 @@ import com.fr.third.org.hsqldb.HsqlException; **/ public class FineDbLockedConverter implements ThrowableConverter { + public static final String LOCK_FILE = "lockFile"; + @Override public boolean accept(Throwable throwable) { @@ -42,7 +45,7 @@ public class FineDbLockedConverter implements ThrowableConverter { DetectorType type = DetectorType.FINE_DB_LOCKED; String message = sign.getMessage(); - if (message.contains("lock")) { + if (StringUtils.containsIgnoreCase(message, LOCK_FILE)) { return DetectorResult.builder() .withType(type) diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java index 00775706d..dd350abdf 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java @@ -5,6 +5,7 @@ import com.fr.env.detect.base.DetectorConstants; import com.fr.env.detect.bean.DetectorResult; import com.fr.env.detect.bean.DetectorType; import com.fr.env.detect.thowable.ThrowableConverter; +import com.fr.third.org.apache.commons.lang3.StringUtils; import com.fr.third.org.hsqldb.HsqlException; /** @@ -14,6 +15,8 @@ import com.fr.third.org.hsqldb.HsqlException; **/ public class FineDbPermissionConverter implements ThrowableConverter { + public static final String PERMISSION = "permission"; + @Override public boolean accept(Throwable throwable) { @@ -37,7 +40,7 @@ public class FineDbPermissionConverter implements ThrowableConverter { DetectorType type = DetectorType.FINE_DB_PERMISSION; String message = sign.getMessage(); - if (message.contains("permission")) { + if (StringUtils.containsIgnoreCase(message, PERMISSION)) { return DetectorResult.builder() .withType(type) diff --git a/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java b/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java index 64cd3ce7b..14210b8fb 100644 --- a/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java +++ b/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java @@ -25,24 +25,33 @@ public class ThrowableLogAppender extends AbstractAppender { } private static class ExceptionLogAppenderHolder { - private static final ThrowableLogAppender INSTANCE = new ThrowableLogAppender("exception-detect", null, null, false, null); + private static final ThrowableLogAppender INSTANCE = new ThrowableLogAppender("exception-detect-appender", null, null, false, null); } - private LogHandler logHandler = toHandler(); + private final LogHandler logHandler = toHandler(); @Override public void append(LogEvent logEvent) { if (logEvent.getLevel() == Level.ERROR) { Throwable thrown = logEvent.getThrown(); - ThrowableStore.getInstance().add(thrown); + if (thrown != null) { + ThrowableStore.getInstance().add(thrown); + } } } private LogHandler toHandler() { final ThrowableLogAppender appender = this; - return () -> appender; + appender.start(); + LogHandler handler = new LogHandler() { + @Override + public ThrowableLogAppender getHandler() { + return appender; + } + }; + return handler; } diff --git a/designer-base/src/main/java/com/fr/env/detect/ui/DetectorErrorDialog.java b/designer-base/src/main/java/com/fr/env/detect/ui/DetectorErrorDialog.java index 96e8dfa3f..9b85c61af 100644 --- a/designer-base/src/main/java/com/fr/env/detect/ui/DetectorErrorDialog.java +++ b/designer-base/src/main/java/com/fr/env/detect/ui/DetectorErrorDialog.java @@ -5,7 +5,6 @@ import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.layout.VerticalFlowLayout; import com.fr.design.utils.ColorUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.env.detect.base.DetectorUtil; @@ -34,6 +33,7 @@ import java.util.List; /** * 未知错误框 * todo 其实这里可以将多个 error-dialog 抽象在一起的。 时间不够, 简单写写 + * 见 {@link com.fr.design.dialog.ErrorDialog} * * created by Harrison on 2022/05/29 **/ @@ -63,19 +63,19 @@ public class DetectorErrorDialog extends JDialog implements ActionListener { UILabel detailDesc = new UILabel(Toolkit.i18nText("Fine-Design_Problem_Detail_Message")); centerPane.add(detailDesc, BorderLayout.NORTH); - JPanel detailPanel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, VerticalFlowLayout.TOP, 0, 10); + JPanel detailPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); detailPanel.setBorder(BorderFactory.createEmptyBorder(0, 20, 10, 10)); for (DetectorResult result : results) { ExceptionTips tips = result.getTips(); if (tips != null) { Message tipsMsg = tips.getMessage(); - detailPanel.add(DetectorUtil.convert2Component(tipsMsg)); + detailPanel.add(DetectorUtil.convert2TextComponent(tipsMsg), BorderLayout.NORTH); } ExceptionSolution solution = result.getSolution(); if (solution != null) { Message solutionMsg = solution.getMessage(); - detailPanel.add(DetectorUtil.convert2Component(solutionMsg)); + detailPanel.add(DetectorUtil.convert2TextComponent(solutionMsg), BorderLayout.CENTER); } } diff --git a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorAction.java b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorAction.java new file mode 100644 index 000000000..7992648f0 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorAction.java @@ -0,0 +1,28 @@ +package com.fr.env.detect.ui; + +import com.fr.design.actions.UpdateAction; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; + +import java.awt.event.ActionEvent; + +/** + * 工具栏里面的行为 + * + * created by Harrison on 2022/05/29 + **/ +public class EnvDetectorAction extends UpdateAction { + + public EnvDetectorAction() { + + this.setName(Toolkit.i18nText("Fine-Design_Basic_Detect_Toolbar_Title")); + this.setSmallIcon("com/fr/env/detect/detect_normal.svg"); + } + + @Override + public void actionPerformed(ActionEvent e) { + + EnvDetectorDialog dialog = new EnvDetectorDialog(DesignerContext.getDesignerFrame()); + dialog.setVisible(true); + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorDialog.java b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorDialog.java index a5cea1323..64d6f4168 100644 --- a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorDialog.java +++ b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorDialog.java @@ -17,7 +17,7 @@ import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUIPaintUtils; import com.fr.env.detect.base.DetectorBridge; import com.fr.env.detect.base.DetectorUtil; -import com.fr.env.detect.base.ExceptionDetectorConfig; +import com.fr.env.detect.base.EnvDetectorConfig; import com.fr.env.detect.bean.DetectorResult; import com.fr.env.detect.bean.DetectorStatus; import com.fr.env.detect.bean.DetectorType; @@ -79,7 +79,7 @@ public class EnvDetectorDialog extends JDialog { /* config model */ - private boolean detectOpen = ExceptionDetectorConfig.getInstance().isOpen(); + private boolean detectOpen = EnvDetectorConfig.getInstance().isEnabled(); public EnvDetectorDialog(Frame owner) { this(owner, null); @@ -213,7 +213,7 @@ public class EnvDetectorDialog extends JDialog { if (buttonStatus.isExecuting()) { // 执行结束 - buttonStatus = buttonStatus.next(); + buttonStatus = EnvDetectorButtonStatus.A_NEW; UIUtil.invokeLaterIfNeeded(() -> detectButton.setText(buttonStatus.getDesc())); } } @@ -366,7 +366,7 @@ public class EnvDetectorDialog extends JDialog { setVisible(false); dispose(); // 配置处理 - ExceptionDetectorConfig.getInstance().setOpen(this.detectOpen); + EnvDetectorConfig.getInstance().setEnabled(this.detectOpen); }); actionsPanel.add(confirmButton, BorderLayout.WEST); diff --git a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorItem.java b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorItem.java index 6b5b1159c..0f9075313 100644 --- a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorItem.java +++ b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorItem.java @@ -4,6 +4,8 @@ import com.fr.env.detect.bean.DetectorResult; import com.fr.env.detect.bean.DetectorType; /** + * 环境检测条目 + * * created by Harrison on 2022/05/27 **/ public class EnvDetectorItem { diff --git a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorModel.java b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorModel.java index 8a698f3c3..457734d0b 100644 --- a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorModel.java +++ b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorModel.java @@ -12,17 +12,28 @@ import java.util.stream.Collectors; import java.util.stream.Stream; /** + * 环境检测数据格式 + * * created by Harrison on 2022/05/27 **/ public class EnvDetectorModel { - private Map> itemMap = new LinkedHashMap<>(); + /** + * 类型 -> list [{type-result}] + */ + private final Map> itemMap = new LinkedHashMap<>(); public EnvDetectorModel() { - itemMap.put(DetectorType.Kind.JAR, Lists.newArrayList(new EnvDetectorItem(DetectorType.LACK_OF_JAR), new EnvDetectorItem(DetectorType.JAR_IN_CONSISTENCE), new EnvDetectorItem(DetectorType.JAR_CONFLICT))); + itemMap.put(DetectorType.Kind.JAR, Lists.newArrayList( + new EnvDetectorItem(DetectorType.LACK_OF_JAR), + new EnvDetectorItem(DetectorType.JAR_IN_CONSISTENCE), + new EnvDetectorItem(DetectorType.JAR_CONFLICT))); - itemMap.put(DetectorType.Kind.FINE_DB, Lists.newArrayList(new EnvDetectorItem(DetectorType.FINE_DB_LOCKED), new EnvDetectorItem(DetectorType.FINE_DB_PERMISSION), new EnvDetectorItem(DetectorType.FINE_DB_DIRTY))); + itemMap.put(DetectorType.Kind.FINE_DB, Lists.newArrayList( + new EnvDetectorItem(DetectorType.FINE_DB_LOCKED), + new EnvDetectorItem(DetectorType.FINE_DB_PERMISSION), + new EnvDetectorItem(DetectorType.FINE_DB_DIRTY))); } public void update(DetectorType type, DetectorResult result) { diff --git a/designer-base/src/main/resources/com/fr/env/detect/detect.svg b/designer-base/src/main/resources/com/fr/env/detect/detect.svg new file mode 100644 index 000000000..b279a649f --- /dev/null +++ b/designer-base/src/main/resources/com/fr/env/detect/detect.svg @@ -0,0 +1,3 @@ + + + diff --git a/designer-base/src/main/resources/com/fr/env/detect/detect_normal.svg b/designer-base/src/main/resources/com/fr/env/detect/detect_normal.svg new file mode 100644 index 000000000..b279a649f --- /dev/null +++ b/designer-base/src/main/resources/com/fr/env/detect/detect_normal.svg @@ -0,0 +1,3 @@ + + +