From 2d20d14a04f81786939013502fdd76fd38c2d60e Mon Sep 17 00:00:00 2001 From: Harrison Date: Sun, 29 May 2022 15:45:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20REPORT-70565=20=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E7=8E=AF=E5=A2=83=E7=9B=91=E6=B5=8B=EF=BC=88jar?= =?UTF-8?q?=E5=8C=85=E5=BC=82=E5=B8=B8=E3=80=81finedb=E3=80=81=E6=9D=80?= =?UTF-8?q?=E6=AF=92=E8=BD=AF=E4=BB=B6=EF=BC=89=201-=E6=A2=B3=E7=90=86?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E8=BF=9B=E8=A1=8C=E6=A3=80=E6=B5=8B=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91=202-=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/exit/DesignerExiter.java | 46 ++++++++++ .../main/java/com/fr/start/BaseDesigner.java | 3 +- .../notification/NotificationDialogTest.java | 4 +- ...t.java => ClassConflictConvertorTest.java} | 6 +- .../detect/ui/DetectorErrorDialogTest.java | 8 ++ .../env/detect/ui/EnvDetectorDialogTest.java | 37 +++++++++ .../src/main/java/com/fr/start/Designer.java | 22 ++++- .../fr/start/LifecycleFatalErrorHandler.java | 83 +++++++++++++------ .../main/java/com/fr/start/MainDesigner.java | 2 + 9 files changed, 176 insertions(+), 35 deletions(-) rename designer-base/src/test/java/com/fr/env/detect/impl/converter/{ClassConfictConvertorTest.java => ClassConflictConvertorTest.java} (68%) create mode 100644 designer-base/src/test/java/com/fr/env/detect/ui/DetectorErrorDialogTest.java create mode 100644 designer-base/src/test/java/com/fr/env/detect/ui/EnvDetectorDialogTest.java diff --git a/designer-base/src/main/java/com/fr/exit/DesignerExiter.java b/designer-base/src/main/java/com/fr/exit/DesignerExiter.java index cda2e015b0..e1a93a46cf 100644 --- a/designer-base/src/main/java/com/fr/exit/DesignerExiter.java +++ b/designer-base/src/main/java/com/fr/exit/DesignerExiter.java @@ -1,10 +1,24 @@ package com.fr.exit; +import com.fr.common.util.Collections; +import com.fr.design.RestartHelper; +import com.fr.design.dialog.ErrorDialog; import com.fr.design.env.DesignerWorkspaceGenerator; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrame; +import com.fr.design.mainframe.messagecollect.StartErrorMessageCollector; +import com.fr.design.mainframe.messagecollect.entity.DesignerErrorMessage; import com.fr.design.monitor.DesignerLifecycleMonitorContext; +import com.fr.env.detect.EnvDetectorCenter; +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.ui.DetectorErrorDialog; +import com.fr.log.FineLoggerFactory; import com.fr.process.engine.core.FineProcessContext; import com.fr.process.engine.core.FineProcessEngineEvent; +import java.util.List; + /** * @author hades * @version 10.0 @@ -17,6 +31,38 @@ public class DesignerExiter { public static DesignerExiter getInstance() { return INSTANCE; } + + public void exit(Throwable throwable) { + + List results = EnvDetectorCenter.getInstance().terminate(throwable); + + if (Collections.isEmpty(results)) { + DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); + DetectorErrorDialog errorDialog = new DetectorErrorDialog(designerFrame, results); + errorDialog.setVisible(true); + } else { + FineLoggerFactory.getLogger().error(throwable.getMessage(), throwable); + StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.UNEXCEPTED_START_FAILED.getId(), + DesignerErrorMessage.UNEXCEPTED_START_FAILED.getMessage(), + throwable.getMessage()); + ErrorDialog dialog = new ErrorDialog(null, Toolkit.i18nText("Fine-Design_Error_Start_Apology_Message"), + Toolkit.i18nText("Fine-Design_Error_Start_Report"), + throwable.getMessage()) { + @Override + protected void okEvent() { + dispose(); + DesignerExiter.getInstance().execute(); + } + + @Override + protected void restartEvent() { + dispose(); + RestartHelper.restart(); + } + }; + dialog.setVisible(true); + } + } public void execute() { DesignerLifecycleMonitorContext.getMonitor().beforeStop(); diff --git a/designer-base/src/main/java/com/fr/start/BaseDesigner.java b/designer-base/src/main/java/com/fr/start/BaseDesigner.java index 360e9cdfa6..95f27442d4 100644 --- a/designer-base/src/main/java/com/fr/start/BaseDesigner.java +++ b/designer-base/src/main/java/com/fr/start/BaseDesigner.java @@ -32,7 +32,6 @@ import com.fr.process.ProcessEventPipe; import com.fr.process.engine.core.CarryMessageEvent; import com.fr.process.engine.core.FineProcessContext; import com.fr.stable.OperatingSystem; - import com.fr.start.event.LazyStartupEvent; import com.fr.workspace.base.WorkspaceStatus; @@ -138,7 +137,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock { if (!isException) { showDesignerFrame(true); } else { - DesignerExiter.getInstance().execute(); + DesignerExiter.getInstance().exit(e); } } } diff --git a/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java b/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java index fec7e8069b..1ba115c785 100644 --- a/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java +++ b/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java @@ -1,6 +1,6 @@ package com.fr.design.components.notification; -import com.fr.design.utils.DevUtil; +import com.fr.design.utils.DevUtils; import com.fr.third.guava.collect.Lists; import java.awt.Frame; @@ -15,7 +15,7 @@ public class NotificationDialogTest { public static void testShow() { - DevUtil.show(new Consumer() { + DevUtils.show(new Consumer() { @Override public void accept(Frame frame) { diff --git a/designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConfictConvertorTest.java b/designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConflictConvertorTest.java similarity index 68% rename from designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConfictConvertorTest.java rename to designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConflictConvertorTest.java index bf43c5560c..cdc789b015 100644 --- a/designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConfictConvertorTest.java +++ b/designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConflictConvertorTest.java @@ -2,13 +2,13 @@ package com.fr.env.detect.impl.converter; import org.junit.Test; -public class ClassConfictConvertorTest { +public class ClassConflictConvertorTest { @Test public void testInnerFinder() { ClassNotFoundException ex1 = new ClassNotFoundException("Class 111.222.333 not found"); - Iterable names = ClassConfictConvertor.Converter.CLASS.converter(ex1); + Iterable names = ClassConflictConvertor.Converter.CLASS.converter(ex1); System.out.println(); } @@ -17,7 +17,7 @@ public class ClassConfictConvertorTest { public void testConverter() { ClassNotFoundException ex1 = new ClassNotFoundException("com.zaxxer.hikari.HikariConfig"); - ClassConfictConvertor convertor = new ClassConfictConvertor(); + ClassConflictConvertor convertor = new ClassConflictConvertor(); convertor.convert(ex1); } } \ No newline at end of file diff --git a/designer-base/src/test/java/com/fr/env/detect/ui/DetectorErrorDialogTest.java b/designer-base/src/test/java/com/fr/env/detect/ui/DetectorErrorDialogTest.java new file mode 100644 index 0000000000..42d7923b8d --- /dev/null +++ b/designer-base/src/test/java/com/fr/env/detect/ui/DetectorErrorDialogTest.java @@ -0,0 +1,8 @@ +package com.fr.env.detect.ui; + +import static org.junit.Assert.*; + +public class DetectorErrorDialogTest { + + +} \ No newline at end of file diff --git a/designer-base/src/test/java/com/fr/env/detect/ui/EnvDetectorDialogTest.java b/designer-base/src/test/java/com/fr/env/detect/ui/EnvDetectorDialogTest.java new file mode 100644 index 0000000000..fd63b1714f --- /dev/null +++ b/designer-base/src/test/java/com/fr/env/detect/ui/EnvDetectorDialogTest.java @@ -0,0 +1,37 @@ +package com.fr.env.detect.ui; + +import com.fr.design.utils.DevUtils; +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorStatus; +import com.fr.env.detect.bean.DetectorType; + +import java.awt.Frame; +import java.util.function.Consumer; + +public class EnvDetectorDialogTest { + + public static void main(String[] args) { + + testShow(); + } + + private static void testShow() { + + DevUtils.show(new Consumer() { + @Override + public void accept(Frame frame) { + + EnvDetectorModel envDetectorModel = new EnvDetectorModel(); + envDetectorModel.update(DetectorType.JAR_CONFLICT, DetectorResult.builder() + .withTips("test") + .withSolution("test", "abc") + .withStatus(DetectorStatus.EXCEPTION) + .build()); + + EnvDetectorDialog envDetectorDialog = new EnvDetectorDialog(frame, envDetectorModel); + envDetectorDialog.setVisible(true); + } + }); + } + +} \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/start/Designer.java b/designer-realize/src/main/java/com/fr/start/Designer.java index 1f8d181ce3..c2ec299ea2 100644 --- a/designer-realize/src/main/java/com/fr/start/Designer.java +++ b/designer-realize/src/main/java/com/fr/start/Designer.java @@ -1,6 +1,7 @@ package com.fr.start; import com.fr.design.os.impl.SupportOSImpl; +import com.fr.exit.DesignerExiter; import com.fr.log.FineLoggerFactory; /** @@ -22,11 +23,26 @@ public class Designer { // 创建进程 DesignerLauncher.getInstance().start(args); } - } catch (Exception e) { - runNonGuardianDesigner(args); - FineLoggerFactory.getLogger().error(e.getMessage(), e); + } catch (Throwable ex1) { + try { + FineLoggerFactory.getLogger().error(ex1.getMessage(), ex1); + runNonGuardianDesigner(args); + } catch (Throwable ex2) { + // 异常退出 + exitExceptionally(ex2); + } } } + + /** + * 异常退出 + * + * @param throwable 异常 + */ + private static void exitExceptionally(Throwable throwable) { + + DesignerExiter.getInstance().exit(throwable); + } /** * 启动非守护设计器 diff --git a/designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java b/designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java index 446253e906..2a9103f4ad 100644 --- a/designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java +++ b/designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java @@ -2,11 +2,15 @@ package com.fr.start; import com.fr.common.report.ReportState; import com.fr.design.RestartHelper; -import com.fr.design.dialog.ErrorDialog; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.messagecollect.StartErrorMessageCollector; import com.fr.design.mainframe.messagecollect.entity.DesignerErrorMessage; +import com.fr.env.detect.EnvDetectorCenter; +import com.fr.env.detect.base.DetectorBridge; +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorStatus; +import com.fr.env.detect.bean.DetectorType; import com.fr.exit.DesignerExiter; import com.fr.general.IOUtils; import com.fr.io.utils.ResourceIOUtils; @@ -19,7 +23,7 @@ import com.fr.stable.lifecycle.ErrorTypeHelper; import com.fr.stable.lifecycle.FineLifecycleFatalError; import com.fr.stable.project.ProjectConstants; -import javax.swing.*; +import javax.swing.JOptionPane; import java.util.HashMap; import java.util.Map; @@ -60,16 +64,22 @@ public class LifecycleFatalErrorHandler { * finedb处理 */ enum FineDBHandler implements Handler { - + + /** + * 自检测 + */ SELF { @Override public void handle(FineLifecycleFatalError fatal) { + + String showText = generateShowText(fatal); + StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.FINEDB_PROBLEM.getId(), DesignerErrorMessage.FINEDB_PROBLEM.getMessage(), fatal.getMessage()); FineLoggerFactory.getLogger().error(DesignerErrorMessage.FINEDB_PROBLEM.getId() + ": " + DesignerErrorMessage.FINEDB_PROBLEM.getMessage()); int result = FineJOptionPane.showOptionDialog(null, - Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset"), + showText, Toolkit.i18nText("Fine-Design_Basic_Error_Tittle"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, @@ -95,8 +105,45 @@ public class LifecycleFatalErrorHandler { DesignerExiter.getInstance().execute(); } } - + + /** + * 生成展示信息 + * + * @param fatal 异常 + * @return 文本 + */ + private String generateShowText(FineLifecycleFatalError fatal) { + + // todo 其实这里的交互还是有问题, 为什么在锁住和没权限的场景下,要重置 FineDB 呢。 + DetectorResult detectorResult = DetectorBridge.getInstance().detect(DetectorType.FINE_DB_LOCKED, fatal); + if (detectorResult.getStatus() == DetectorStatus.NORMAL) { + detectorResult = DetectorBridge.getInstance().detect(DetectorType.FINE_DB_PERMISSION, fatal); + } + if (detectorResult.getStatus() == DetectorStatus.NORMAL) { + detectorResult = DetectorBridge.getInstance().detect(DetectorType.FINE_DB_DIRTY, fatal); + } + + String message; + + DetectorType type = detectorResult.getType(); + switch (type) { + case FINE_DB_LOCKED: + message = Toolkit.i18nText("Fine-Design_Error_Finedb_Locked_Backup_Reset"); + break; + case FINE_DB_PERMISSION: + message = Toolkit.i18nText("Fine-Design_Error_Finedb_Permission_Backup_Reset"); + break; + case FINE_DB_DIRTY: + message = Toolkit.i18nText("Fine-Design_Error_Finedb_Dirty_Backup_Reset"); + break; + default: + message = Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset"); + } + return message; + } + private void afterBackupFailed() { + FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset_Result", ResourceIOUtils.getRealPath(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME))), @@ -111,29 +158,15 @@ public class LifecycleFatalErrorHandler { * 默认处理 */ enum DefaultHandler implements Handler { + + /** + * 自处理 + */ SELF { @Override public void handle(FineLifecycleFatalError fatal) { - FineLoggerFactory.getLogger().error(fatal.getMessage(), fatal); - StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.UNEXCEPTED_START_FAILED.getId(), - DesignerErrorMessage.UNEXCEPTED_START_FAILED.getMessage(), - fatal.getMessage()); - ErrorDialog dialog = new ErrorDialog(null, Toolkit.i18nText("Fine-Design_Error_Start_Apology_Message"), - Toolkit.i18nText("Fine-Design_Error_Start_Report"), - fatal.getMessage()) { - @Override - protected void okEvent() { - dispose(); - DesignerExiter.getInstance().execute(); - } - - @Override - protected void restartEvent() { - dispose(); - RestartHelper.restart(); - } - }; - dialog.setVisible(true); + + EnvDetectorCenter.getInstance().terminate(fatal); } } } diff --git a/designer-realize/src/main/java/com/fr/start/MainDesigner.java b/designer-realize/src/main/java/com/fr/start/MainDesigner.java index f60003c9a1..09d7406834 100644 --- a/designer-realize/src/main/java/com/fr/start/MainDesigner.java +++ b/designer-realize/src/main/java/com/fr/start/MainDesigner.java @@ -46,6 +46,7 @@ import com.fr.design.share.SharableManager; import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.concurrent.ThreadFactoryBuilder; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.env.detect.EnvDetectorCenter; import com.fr.env.utils.DesignerInteractionHistory; import com.fr.event.Event; import com.fr.event.EventDispatcher; @@ -110,6 +111,7 @@ public class MainDesigner extends BaseDesigner { */ public static void main(String[] args) { + EnvDetectorCenter.getInstance().init(); showSplash(); DeepLinkManager.getInstance().start(args); StopWatch watch = new StopWatch();