From 2d322f3ad24d3f1bc7bb04685232f0a15af0684e Mon Sep 17 00:00:00 2001 From: Harrison Date: Tue, 14 Jun 2022 16:58:40 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-73586=E3=80=90=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E7=8E=AF=E5=A2=83=E7=9B=91=E6=B5=8B=E3=80=91=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E8=BF=9E=E6=8E=A5=E5=A4=B1=E8=B4=A5=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=89=8B=E5=8A=A8=E6=A3=80=E6=B5=8B=EF=BC=8C?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=A4=B1=E8=B4=A5=20=E5=92=8C=E4=BA=A7?= =?UTF-8?q?=E5=93=81=E6=B2=9F=E9=80=9A=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E5=AD=98=E5=9C=A8=E6=A3=80=E6=B5=8B=E8=BF=87=E7=A8=8B?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/env/detect/base/DetectorBridge.java | 9 +- .../fr/env/detect/bean/DetectorResult.java | 6 ++ .../fr/env/detect/bean/DetectorStatus.java | 5 ++ .../detect/thowable/ThrowableLogAppender.java | 2 + .../fr/env/detect/ui/EnvDetectorDialog.java | 82 +++++++++++-------- 5 files changed, 67 insertions(+), 37 deletions(-) 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 50bca7fd1c..765ad1edac 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 @@ -10,6 +10,7 @@ import com.fr.env.detect.impl.JarInconsistentDetector; import com.fr.env.detect.impl.JarLackDetector; import com.fr.env.detect.thowable.ThrowableLogAppender; import com.fr.env.detect.thowable.ThrowableStore; +import com.fr.log.FineLoggerFactory; import com.fr.value.NotNullLazyValue; import org.jetbrains.annotations.NotNull; @@ -86,7 +87,13 @@ public class DetectorBridge { @NotNull public DetectorResult detect(DetectorType type) { - return detectorManager.getValue().detect(type); + try { + return detectorManager.getValue().detect(type); + } catch (Exception e) { + FineLoggerFactory.getLogger().error("detect failed", e); + // 返回成功的信息, 别影响前端的展示。 + return DetectorResult.unknown(type); + } } /** diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java index 2b45ecbc1e..aa9a007bbb 100644 --- a/designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java +++ b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java @@ -31,6 +31,12 @@ public class DetectorResult { this.log = log; } + public static DetectorResult unknown(DetectorType type) { + DetectorResult result = new DetectorResult(type); + result.status = DetectorStatus.UNKNOWN; + return result; + } + public static DetectorResult normal(DetectorType type) { DetectorResult result = new DetectorResult(type); diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/DetectorStatus.java b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorStatus.java index 6a12015e91..b7e5df818c 100644 --- a/designer-base/src/main/java/com/fr/env/detect/bean/DetectorStatus.java +++ b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorStatus.java @@ -14,4 +14,9 @@ public enum DetectorStatus { * 异常 */ EXCEPTION, + + /** + * 未知 + */ + UNKNOWN, } 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 bcb4736e1d..3348052f4d 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 @@ -60,6 +60,8 @@ public class ThrowableLogAppender extends AbstractAppender { public void enable() { + // 初始化一下,别出问题 + logHandler.getHandler().start(); FRLogger.getLogger().addExtendLogAppender(logHandler); } 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 25689ad202..ed03d78cc1 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 @@ -21,6 +21,7 @@ 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; +import com.fr.log.FineLoggerFactory; import org.jetbrains.annotations.NotNull; import javax.swing.BorderFactory; @@ -55,6 +56,7 @@ public class EnvDetectorDialog extends JDialog { private static final int TIMEOUT = 1000; private static final Color SUCCESS_COLOR = new Color(22, 193, 83); + private static final Color DETAIL_FONT_COLOR = new Color(65, 155, 249); private final JPanel body; @@ -177,7 +179,7 @@ public class EnvDetectorDialog extends JDialog { } // 执行前 buttonStatus = buttonStatus.next(); - UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refreshHeaderPanel); + UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refreshHeader); detectWorker = new SwingWorker() { @Override @@ -192,7 +194,7 @@ public class EnvDetectorDialog extends JDialog { } // 刷新一下面板-开始执行啦 - UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refresh); + UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refreshBody); EnvDetectorItem item = items.get(i); DetectorType type = item.getType(); @@ -208,7 +210,7 @@ public class EnvDetectorDialog extends JDialog { // 只有还在运行中,才会真正的刷新面板 if (buttonStatus.isExecuting()) { // 在刷新一下面板 - UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refresh); + UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refreshBody); currentDetectIndex++; } @@ -218,11 +220,16 @@ public class EnvDetectorDialog extends JDialog { @Override protected void done() { - - if (buttonStatus.isExecuting()) { - // 执行结束 - buttonStatus = EnvDetectorButtonStatus.A_NEW; - UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refreshHeaderPanel); + + try { + this.get(); + if (buttonStatus.isExecuting()) { + // 执行结束 + buttonStatus = EnvDetectorButtonStatus.A_NEW; + UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refreshHeader); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error("detect failed", e); } } }; @@ -236,7 +243,7 @@ public class EnvDetectorDialog extends JDialog { e.setResult(null); } // 刷新一下面板-开始执行啦 - UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refresh); + UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refreshBody); } private void stopDetecting(UIButton detectButton) { @@ -251,7 +258,7 @@ public class EnvDetectorDialog extends JDialog { // 刷新按钮 detectButton.setText(buttonStatus.getDesc()); // 刷新面板 - refresh(); + refreshBody(); }); } @@ -265,7 +272,7 @@ public class EnvDetectorDialog extends JDialog { this.resultSummaryPane.setLayout(new BorderLayout(5, 0)); Boolean success = model.getResults() .map((e) -> { - if (e.getStatus() == DetectorStatus.NORMAL) { + if (e != null && e.getStatus() == DetectorStatus.NORMAL) { return Boolean.TRUE; } return Boolean.FALSE; @@ -360,31 +367,34 @@ public class EnvDetectorDialog extends JDialog { infoPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Exception")), BorderLayout.CENTER); } statusPanel.add(infoPanel, BorderLayout.WEST); - - JPanel detailPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - { - detailPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); - UILabel detailLabel = new UILabel(Toolkit.i18nText("Fine_Designer_Look_Detail")); - detailLabel.setForeground(new Color(65, 155, 249)); - detailLabel.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent mouseEvent) { - NotificationDialogProperties properties = new NotificationDialogProperties((Frame) EnvDetectorDialog.this.getOwner(), Toolkit.i18nText("Fine-Design_Basic_Detect_Notification_Title")); - Stream results = model.getResults(); - List notificationModels = results - .filter(Objects::nonNull) - .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) - .map(DetectorUtil::convert2Notification) - .collect(Collectors.toList()); - - NotificationDialog dialog = new NotificationDialog(properties, notificationModels); - dialog.open(); - } - }); - detailPanel.add(detailLabel, BorderLayout.CENTER); + + // 如果结果是检测出的异常,则出现详细信息。 + if (result.getStatus() == DetectorStatus.EXCEPTION) { + JPanel detailPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + { + detailPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); + UILabel detailLabel = new UILabel(Toolkit.i18nText("Fine_Designer_Look_Detail")); + detailLabel.setForeground(DETAIL_FONT_COLOR); + detailLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent mouseEvent) { + NotificationDialogProperties properties = new NotificationDialogProperties((Frame) EnvDetectorDialog.this.getOwner(), Toolkit.i18nText("Fine-Design_Basic_Detect_Notification_Title")); + Stream results = model.getResults(); + List notificationModels = results + .filter(Objects::nonNull) + .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) + .map(DetectorUtil::convert2Notification) + .collect(Collectors.toList()); + + NotificationDialog dialog = new NotificationDialog(properties, notificationModels); + dialog.open(); + } + }); + detailPanel.add(detailLabel, BorderLayout.CENTER); + } + statusPanel.add(detailPanel, BorderLayout.CENTER); } - statusPanel.add(detailPanel, BorderLayout.CENTER); } return statusPanel; } @@ -434,14 +444,14 @@ public class EnvDetectorDialog extends JDialog { return tailPanel; } - private void refreshHeaderPanel() { + private void refreshHeader() { updateHeaderPanel(); pack(); repaint(); } - private void refresh() { + private void refreshBody() { updateTable(this.tablePanel); pack();