Browse Source

feat: REPORT-70565 设计器环境监测(jar包异常、finedb、杀毒软件)

1-梳理需要进行检测的逻辑
2-添加单元测试
feature/x
Harrison 3 years ago
parent
commit
2d20d14a04
  1. 46
      designer-base/src/main/java/com/fr/exit/DesignerExiter.java
  2. 3
      designer-base/src/main/java/com/fr/start/BaseDesigner.java
  3. 4
      designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java
  4. 6
      designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConflictConvertorTest.java
  5. 8
      designer-base/src/test/java/com/fr/env/detect/ui/DetectorErrorDialogTest.java
  6. 37
      designer-base/src/test/java/com/fr/env/detect/ui/EnvDetectorDialogTest.java
  7. 22
      designer-realize/src/main/java/com/fr/start/Designer.java
  8. 83
      designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java
  9. 2
      designer-realize/src/main/java/com/fr/start/MainDesigner.java

46
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<DetectorResult> 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();

3
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);
}
}
}

4
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<Frame>() {
DevUtils.show(new Consumer<Frame>() {
@Override
public void accept(Frame frame) {

6
designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConfictConvertorTest.java → designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConflictConvertorTest.java vendored

@ -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<String> names = ClassConfictConvertor.Converter.CLASS.converter(ex1);
Iterable<String> 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);
}
}

8
designer-base/src/test/java/com/fr/env/detect/ui/DetectorErrorDialogTest.java vendored

@ -0,0 +1,8 @@
package com.fr.env.detect.ui;
import static org.junit.Assert.*;
public class DetectorErrorDialogTest {
}

37
designer-base/src/test/java/com/fr/env/detect/ui/EnvDetectorDialogTest.java vendored

@ -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<Frame>() {
@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);
}
});
}
}

22
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);
}
/**
* 启动非守护设计器

83
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);
}
}
}

2
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();

Loading…
Cancel
Save