From f88195d402c2ce068d6d8a0ae7c2e59ab599244a Mon Sep 17 00:00:00 2001 From: Harrison Date: Wed, 25 May 2022 15:46:50 +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=20=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=A3=80=E6=B5=8B=E7=9A=84=E6=A0=B8=E5=BF=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=92=8C=E9=83=A8=E5=88=86=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E3=80=82=20=E6=97=A0=20UI=20=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/AbstractExceptionDetector.java | 19 ++++ .../detect/base/CatchExceptionDetector.java | 44 ++++++++ .../fr/env/detect/base/DetectorBridge.java | 95 ++++++++++++++++ .../fr/env/detect/base/DetectorManager.java | 40 +++++++ .../fr/env/detect/base/ExceptionDetector.java | 25 +++++ .../detect/base/ExceptionDetectorConfig.java | 21 ++++ .../fr/env/detect/base/ThrowableBridge.java | 40 +++++++ .../com/fr/env/detect/base/package-info.java | 4 + .../fr/env/detect/bean/DetectorResult.java | 102 ++++++++++++++++++ .../fr/env/detect/bean/DetectorStatus.java | 22 ++++ .../com/fr/env/detect/bean/DetectorType.java | 88 +++++++++++++++ .../com/fr/env/detect/bean/ExceptionLog.java | 24 +++++ .../fr/env/detect/bean/ExceptionSolution.java | 24 +++++ .../com/fr/env/detect/bean/ExceptionTips.java | 19 ++++ .../java/com/fr/env/detect/bean/Message.java | 70 ++++++++++++ .../fr/env/detect/bean/SolutionAction.java | 11 ++ .../detect/exception/DetectorException.java | 26 +++++ .../fr/env/detect/impl/HsqlDirtyDetector.java | 18 ++++ .../detect/impl/JarInconsistentDetector.java | 85 +++++++++++++++ .../fr/env/detect/impl/JarLackDetector.java | 43 ++++++++ .../converter/ClassThrowableConvertor.java | 53 +++++++++ .../impl/converter/FineDbDirtyConverter.java | 33 ++++++ .../impl/converter/FineDbLockedConverter.java | 31 ++++++ .../converter/FineDbPermissionConverter.java | 33 ++++++ .../detect/thowable/ThrowableConverter.java | 28 +++++ .../detect/thowable/ThrowableLogAppender.java | 58 ++++++++++ .../env/detect/thowable/ThrowableStore.java | 36 +++++++ 27 files changed, 1092 insertions(+) create mode 100644 designer-base/src/main/java/com/fr/env/detect/base/AbstractExceptionDetector.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/base/CatchExceptionDetector.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetector.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/base/ThrowableBridge.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/base/package-info.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/bean/DetectorStatus.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/bean/DetectorType.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/bean/ExceptionLog.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/bean/ExceptionSolution.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/bean/ExceptionTips.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/bean/Message.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/bean/SolutionAction.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/exception/DetectorException.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/impl/HsqlDirtyDetector.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassThrowableConvertor.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableConverter.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableStore.java diff --git a/designer-base/src/main/java/com/fr/env/detect/base/AbstractExceptionDetector.java b/designer-base/src/main/java/com/fr/env/detect/base/AbstractExceptionDetector.java new file mode 100644 index 0000000000..32d54a1d75 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/base/AbstractExceptionDetector.java @@ -0,0 +1,19 @@ +package com.fr.env.detect.base; + +import com.fr.env.detect.bean.DetectorType; + +/** + * created by Harrison on 2022/05/13 + **/ +public abstract class AbstractExceptionDetector implements ExceptionDetector { + + private DetectorType key; + + public AbstractExceptionDetector(DetectorType key) { + this.key = key; + } + + public DetectorType type() { + return key; + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/base/CatchExceptionDetector.java b/designer-base/src/main/java/com/fr/env/detect/base/CatchExceptionDetector.java new file mode 100644 index 0000000000..b2e60d42c7 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/base/CatchExceptionDetector.java @@ -0,0 +1,44 @@ +package com.fr.env.detect.base; + +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.thowable.ThrowableConverter; +import com.fr.env.detect.thowable.ThrowableStore; + +import java.util.List; + +/** + * created by Harrison on 2022/05/13 + **/ +public abstract class CatchExceptionDetector extends AbstractExceptionDetector { + + private ThrowableStore throwableStore; + + private ThrowableConverter throwableConverter; + + public CatchExceptionDetector(DetectorType key, ThrowableStore throwableStore, ThrowableConverter throwableConverter) { + super(key); + this.throwableStore = throwableStore; + this.throwableConverter = throwableConverter; + } + + public ThrowableStore getThrowableStore() { + return throwableStore; + } + + public ThrowableConverter getThrowableConverter() { + return throwableConverter; + } + + @Override + public DetectorResult detect() { + + List throwableList = throwableStore.getAll(); + for (Throwable throwable : throwableList) { + if (throwableConverter.accept(throwable)) { + return throwableConverter.convert(throwable); + } + } + return null; + } +} 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 new file mode 100644 index 0000000000..78b5017844 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java @@ -0,0 +1,95 @@ +package com.fr.env.detect.base; + +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.thowable.ThrowableLogAppender; +import com.fr.value.NotNullLazyValue; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Stream; + +/** + * created by Harrison on 2022/05/13 + **/ +public class DetectorBridge { + + public static DetectorBridge getInstance() { + + return DetectorBridgeHolder.INSTANCE; + } + + private static class DetectorBridgeHolder { + + private static final DetectorBridge INSTANCE = new DetectorBridge(); + } + + private final NotNullLazyValue throwableBridge = new NotNullLazyValue() { + @Override + protected @NotNull ThrowableBridge compute() { + + return new ThrowableBridge(); + } + }; + + private final NotNullLazyValue detectorManager = new NotNullLazyValue() { + + @Override + protected @NotNull DetectorManager compute() { + + return new DetectorManager(); + } + }; + + private final AtomicBoolean hasStarted = new AtomicBoolean(false); + + public void start() { + + if (ExceptionDetectorConfig.getInstance().isOpen()) { + // 开始注册异常处理 + ThrowableLogAppender.getInstance().enable(); + hasStarted.set(true); + } + } + + public void stop() { + + if (hasStarted.compareAndSet(true, false)) { + // 关闭异常处理 + ThrowableLogAppender.getInstance().disable(); + } + } + + /** + * 执行-检测异常 + * + * @return 能够检测出的异常情况 + */ + public Stream detect() { + + return detectorManager.getValue().detect(); + } + + /** + * 针对某一项进行检测 + * + * @param type 检测类型 + * @return 检测结果 + */ + public Optional detect(DetectorType type) { + + return detectorManager.getValue().detect(type); + } + + /** + * 执行-捕获异常 + * + * @param throwable 异常 + * @return 检测结果 + */ + public Optional convert(Throwable throwable) { + + return throwableBridge.getValue().convert(throwable); + } +} 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 new file mode 100644 index 0000000000..9d3ae2daa9 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java @@ -0,0 +1,40 @@ +package com.fr.env.detect.base; + +import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.bean.DetectorResult; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; + +/** + * created by Harrison on 2022/05/24 + **/ +class DetectorManager { + + private List detectors = new ArrayList<>(); + + public void register(ExceptionDetector detector) { + + if (detector != null) { + detectors.add(detector); + } + } + + public Stream detect() { + + return detectors.stream() + .map(ExceptionDetector::detect) + .filter(Objects::nonNull); + } + + public Optional detect(DetectorType type) { + + return detectors.stream() + .filter((detector -> type == detector.type())) + .findFirst() + .map(ExceptionDetector::detect); + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetector.java b/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetector.java new file mode 100644 index 0000000000..3d6d8bc4eb --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetector.java @@ -0,0 +1,25 @@ +package com.fr.env.detect.base; + +import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.bean.DetectorResult; + +/** + * created by Harrison on 2022/05/13 + **/ +public interface ExceptionDetector { + + /** + * 检测类型 + * + * @return TYPE + */ + DetectorType type(); + + /** + * 检测结果 + * + * @return 结果 + */ + DetectorResult detect(); + +} 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 new file mode 100644 index 0000000000..489d5e3113 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java @@ -0,0 +1,21 @@ +package com.fr.env.detect.base; + +/** + * created by Harrison on 2022/05/13 + **/ +public class ExceptionDetectorConfig { + + + public static ExceptionDetectorConfig getInstance() { + return ExceptionDetectorConfigHolder.INSTANCE; + } + + private static class ExceptionDetectorConfigHolder { + private static final ExceptionDetectorConfig INSTANCE = new ExceptionDetectorConfig(); + } + + public boolean isOpen() { + + return true; + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/base/ThrowableBridge.java b/designer-base/src/main/java/com/fr/env/detect/base/ThrowableBridge.java new file mode 100644 index 0000000000..c8ef7a02c8 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/base/ThrowableBridge.java @@ -0,0 +1,40 @@ +package com.fr.env.detect.base; + +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.thowable.ThrowableConverter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +/** + * created by Harrison on 2022/05/13 + **/ +class ThrowableBridge { + + private List throwableConverters = new ArrayList<>(); + + public void register(ThrowableConverter throwableConverter) { + + if (throwableConverter != null) { + throwableConverters.add(throwableConverter); + } + } + + /** + * 将 throwable 转化成检测的结果 + * + * @param throwable 异常 + * @return 结果 + */ + public Optional convert(Throwable throwable) { + + return throwableConverters + .stream() + .filter((e) -> e.accept(throwable)) + .map((e) -> e.convert(throwable)) + .filter(Objects::nonNull) + .findFirst(); + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/base/package-info.java b/designer-base/src/main/java/com/fr/env/detect/base/package-info.java new file mode 100644 index 0000000000..12fef30e19 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/base/package-info.java @@ -0,0 +1,4 @@ +/** + * 设计器环境检测 见 {@see https://kms.fineres.com/pages/viewpage.action?pageId=388333688} + */ +package com.fr.env.detect.base; 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 new file mode 100644 index 0000000000..09850055d4 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java @@ -0,0 +1,102 @@ +package com.fr.env.detect.bean; + +import org.jetbrains.annotations.Nullable; + +/** + * 检测结果 + * + * created by Harrison on 2022/05/13 + **/ +public class DetectorResult { + + private DetectorType type; + + private DetectorStatus status; + + private ExceptionTips tips; + + private ExceptionSolution solution; + + private ExceptionLog exceptionLog; + + public DetectorResult(DetectorType type, ExceptionTips tips, ExceptionSolution solution, ExceptionLog exceptionLog) { + this.type = type; + this.tips = tips; + this.solution = solution; + this.exceptionLog = exceptionLog; + } + + public DetectorType getType() { + return type; + } + + public DetectorStatus getStatus() { + return status; + } + + @Nullable + public ExceptionTips getTips() { + return tips; + } + + @Nullable + public ExceptionSolution getSolution() { + return solution; + } + + @Nullable + public ExceptionLog getExceptionLog() { + return exceptionLog; + } + + public static DetectorResultBuilder builder() { + + return new DetectorResultBuilder(); + } + + + public static final class DetectorResultBuilder { + + private DetectorType type; + private DetectorStatus status; + + private ExceptionTips tips; + private ExceptionSolution solution; + private ExceptionLog exceptionLog; + + private DetectorResultBuilder() { + } + + public DetectorResultBuilder withType(DetectorType type) { + this.type = type; + return this; + } + + public DetectorResultBuilder withStatus(DetectorStatus status) { + this.status = status; + return this; + } + + public DetectorResultBuilder withTips(ExceptionTips tips) { + this.tips = tips; + return this; + } + + public DetectorResultBuilder withSolution(ExceptionSolution solution) { + this.solution = solution; + return this; + } + + public DetectorResultBuilder withExceptionLog(ExceptionLog exceptionLog) { + this.exceptionLog = exceptionLog; + return this; + } + + public DetectorResult build() { + + DetectorResult detectorResult = new DetectorResult(type, tips, solution, exceptionLog); + detectorResult.status = this.status; + return detectorResult; + } + } +} 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 new file mode 100644 index 0000000000..d75a82e56e --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorStatus.java @@ -0,0 +1,22 @@ +package com.fr.env.detect.bean; + +/** + * created by Harrison on 2022/05/25 + **/ +public enum DetectorStatus { + + /** + * 成功 + */ + SUCCESS, + + /** + * 失败 + */ + FAILED, + + /** + * 异常 + */ + UNKNOWN +} diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/DetectorType.java b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorType.java new file mode 100644 index 0000000000..2bc71e58a5 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorType.java @@ -0,0 +1,88 @@ +package com.fr.env.detect.bean; + +/** + * 检测的原生数据 + * + * created by Harrison on 2022/05/13 + **/ +public enum DetectorType { + + /** + * 缺少 JAR + */ + LACK_OF_JAR(Kind.JAR, WorkType.LOCAL), + + /** + * JAR 包版本不一致 + */ + JAR_IN_CONSISTENCE(Kind.JAR, WorkType.SIMPLE), + + /** + * JAR 包冲突 + */ + JAR_CONFLICT(Kind.JAR, WorkType.REMOTE), + + + /** + * FineDB 权限问题 + */ + FINE_DB_PERMISSION(Kind.FINE_DB, WorkType.LOCAL), + + /** + * FineDB 锁 + */ + FINE_DB_LOCKED(Kind.FINE_DB, WorkType.LOCAL), + + /** + * FineDB 脏数据 + */ + FINE_DB_DIRTY(Kind.FINE_DB, WorkType.SIMPLE) + ; + + private final Kind kind; + + private final WorkType workType; + + DetectorType(Kind kind, WorkType workType) { + + this.kind = kind; + this.workType = workType; + } + + public Kind getKind() { + return kind; + } + + public WorkType getWorkType() { + return workType; + } + + public enum Kind { + + /** + * JAR 类型 + */ + JAR, + /** + * FineDB 类型 + */ + FINE_DB + } + + public enum WorkType { + + /** + * 本地 + */ + LOCAL, + /** + * 远程 + */ + REMOTE, + /** + * 全部 + */ + SIMPLE + } + +} diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionLog.java b/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionLog.java new file mode 100644 index 0000000000..90cdb58fdb --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionLog.java @@ -0,0 +1,24 @@ +package com.fr.env.detect.bean; + +/** + * created by Harrison on 2022/05/13 + **/ +public class ExceptionLog { + + private final String errorCode; + + private final String locale; + + public ExceptionLog(String errorCode, String locale) { + this.errorCode = errorCode; + this.locale = locale; + } + + public String getErrorCode() { + return errorCode; + } + + public String getLocale() { + return locale; + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionSolution.java b/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionSolution.java new file mode 100644 index 0000000000..a6748e26cb --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionSolution.java @@ -0,0 +1,24 @@ +package com.fr.env.detect.bean; + +/** + * created by Harrison on 2022/05/13 + **/ +public class ExceptionSolution { + + private Message message; + + private SolutionAction action; + + public ExceptionSolution(Message message, SolutionAction action) { + this.message = message; + this.action = action; + } + + public Message getMessage() { + return message; + } + + public SolutionAction getAction() { + return action; + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionTips.java b/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionTips.java new file mode 100644 index 0000000000..970bca989d --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionTips.java @@ -0,0 +1,19 @@ +package com.fr.env.detect.bean; + +/** + * 异常提示 + * + * created by Harrison on 2022/05/13 + **/ +public class ExceptionTips { + + private Message message; + + public ExceptionTips(Message message) { + this.message = message; + } + + public Message getMessage() { + return message; + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/Message.java b/designer-base/src/main/java/com/fr/env/detect/bean/Message.java new file mode 100644 index 0000000000..e1d6dcd62c --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/bean/Message.java @@ -0,0 +1,70 @@ +package com.fr.env.detect.bean; + +/** + * created by Harrison on 2022/05/24 + **/ +public interface Message { + + /** + * 消息类型 + * + * @return 类型 + */ + Type getType(); + + enum Type { + + /** + * 简单 + */ + SIMPLE, + + /** + * 链接 + */ + LINK + } + + class Simple implements Message { + + private String message; + + public Simple(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + @Override + public Type getType() { + return Type.SIMPLE; + } + } + + class Link implements Message { + + private String text; + + private String link; + + public Link(String text, String link) { + this.text = text; + this.link = link; + } + + public String getText() { + return text; + } + + public String getLink() { + return link; + } + + @Override + public Type getType() { + return Type.LINK; + } + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/SolutionAction.java b/designer-base/src/main/java/com/fr/env/detect/bean/SolutionAction.java new file mode 100644 index 0000000000..4b959053bd --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/bean/SolutionAction.java @@ -0,0 +1,11 @@ +package com.fr.env.detect.bean; + +/** + * created by Harrison on 2022/05/24 + **/ +public interface SolutionAction { + + String name(); + + void run(); +} diff --git a/designer-base/src/main/java/com/fr/env/detect/exception/DetectorException.java b/designer-base/src/main/java/com/fr/env/detect/exception/DetectorException.java new file mode 100644 index 0000000000..14adcab292 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/exception/DetectorException.java @@ -0,0 +1,26 @@ +package com.fr.env.detect.exception; + +/** + * created by Harrison on 2022/05/25 + **/ +public class DetectorException extends RuntimeException { + + public DetectorException() { + } + + public DetectorException(String message) { + super(message); + } + + public DetectorException(String message, Throwable cause) { + super(message, cause); + } + + public DetectorException(Throwable cause) { + super(cause); + } + + public DetectorException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/HsqlDirtyDetector.java b/designer-base/src/main/java/com/fr/env/detect/impl/HsqlDirtyDetector.java new file mode 100644 index 0000000000..6afc41a669 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/impl/HsqlDirtyDetector.java @@ -0,0 +1,18 @@ +package com.fr.env.detect.impl; + +import com.fr.env.detect.base.CatchExceptionDetector; +import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.thowable.ThrowableStore; +import com.fr.env.detect.impl.converter.FineDbDirtyConverter; + +/** + * created by Harrison on 2022/05/25 + **/ +public class HsqlDirtyDetector extends CatchExceptionDetector { + + public HsqlDirtyDetector(ThrowableStore throwableStore) { + + super(DetectorType.FINE_DB_DIRTY, throwableStore, new FineDbDirtyConverter()); + } + +} 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 new file mode 100644 index 0000000000..0967697f67 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java @@ -0,0 +1,85 @@ +package com.fr.env.detect.impl; + +import com.fr.env.detect.base.AbstractExceptionDetector; +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.exception.DetectorException; +import com.fr.general.build.BuildInfo; +import com.fr.general.build.BuildInfoOperator; +import com.fr.general.build.BuildInfoManager; +import com.fr.stable.StringUtils; +import com.fr.third.guava.collect.MapDifference; +import com.fr.third.guava.collect.Maps; +import com.fr.workspace.WorkContext; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * created by Harrison on 2022/05/25 + **/ +public class JarInconsistentDetector extends AbstractExceptionDetector { + + public JarInconsistentDetector() { + + super(DetectorType.JAR_IN_CONSISTENCE); + } + + @Override + public DetectorResult detect() { + + DetectorResult.DetectorResultBuilder builder = DetectorResult.builder(); + // 检测有哪些 JAR 包, 当前是否缺少对应的 JAR 包 + BuildInfoOperator buildInfoOperator = WorkContext.getCurrent().get(BuildInfoOperator.class); + List buildInfos = buildInfoOperator.getBuildInfos(); + + if (WorkContext.getCurrent().isLocal()) { + + String designerBuild = buildInfos.stream() + .filter(this::isDesignerJar) + .map(BuildInfo::getGroupBuild) + .filter(StringUtils::isNotEmpty) + .findFirst() + .orElseThrow(DetectorException::new); + + List inConsistentInfos = buildInfos.stream() + .filter((e) -> !StringUtils.equals(designerBuild, e.getGroupBuild())) + .collect(Collectors.toList()); + + } else { + + // 远程情况 + List localInfos = BuildInfoManager.getInstance().getInfos(); + Map localMap = groupBy(localInfos); + + List remoteInfos = buildInfos; + Map remoteMap = groupBy(remoteInfos); + + MapDifference difference = Maps.difference(localMap, remoteMap); + // 两边都有的 JAR 的不同之处 + Map diffInCommon = difference.entriesInCommon(); + + } + + return builder.build(); + } + + private boolean isDesignerJar(BuildInfo info) { + + return StringUtils.contains(info.getJar(), "fine-report-designer"); + } + + private Map groupBy(List localInfos) { + + Map localMap = new HashMap<>(); + for (BuildInfo localInfo : localInfos) { + String jar = localInfo.getJar(); + String groupContent = localInfo.getGroupBuild(); + localMap.put(jar, groupContent); + } + return localMap; + } + +} 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 new file mode 100644 index 0000000000..86f589f303 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java @@ -0,0 +1,43 @@ +package com.fr.env.detect.impl; + +import com.fr.env.detect.base.AbstractExceptionDetector; +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorType; +import com.fr.general.build.BuildInfo; +import com.fr.general.build.BuildInfoOperator; +import com.fr.stable.StringUtils; +import com.fr.workspace.WorkContext; + +import java.util.List; + +/** + * created by Harrison on 2022/05/24 + **/ +public class JarLackDetector extends AbstractExceptionDetector { + + public JarLackDetector() { + super(DetectorType.LACK_OF_JAR); + } + + @Override + public DetectorResult detect() { + + DetectorResult.DetectorResultBuilder builder = DetectorResult.builder(); + + // 检测有哪些 JAR 包, 当前是否缺少对应的 JAR 包 + BuildInfoOperator buildInfoOperator = WorkContext.getCurrent().get(BuildInfoOperator.class); + List buildInfos = buildInfoOperator.getBuildInfos(); + for (BuildInfo buildInfo : buildInfos) { + String jar = buildInfo.getJar(); + String buildContent = buildInfo.getGroupBuild(); + boolean isLack = StringUtils.isEmpty(buildContent); + if (isLack) { + // 处理信息 + + } + } + + return builder.build(); + + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassThrowableConvertor.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassThrowableConvertor.java new file mode 100644 index 0000000000..7fdd8bbe33 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassThrowableConvertor.java @@ -0,0 +1,53 @@ +package com.fr.env.detect.impl.converter; + +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.thowable.ThrowableConverter; + +import javax.el.MethodNotFoundException; +import java.util.HashSet; +import java.util.Set; + +/** + * 类抛出异常的转换 + * created by Harrison on 2022/05/24 + **/ +public class ClassThrowableConvertor implements ThrowableConverter { + + private Set> throwableClassSet = new HashSet<>(); + + private Set> throwableMethodSet = new HashSet<>(); + + public ClassThrowableConvertor() { + + // 类异常 + this.throwableClassSet.add(ClassNotFoundException.class); + this.throwableClassSet.add(NoClassDefFoundError.class); + this.throwableClassSet.add(ClassCastException.class); + this.throwableClassSet.add(IncompatibleClassChangeError.class); + + // 方法异常 + this.throwableMethodSet.add(MethodNotFoundException.class); + this.throwableMethodSet.add(NoSuchMethodException.class); + this.throwableMethodSet.add(NoSuchMethodError.class); + } + + @Override + public boolean accept(Throwable throwable) { + + Throwable sign = throwable; + while (sign != null) { + if (throwableClassSet.contains(sign.getClass()) || throwableMethodSet.contains(sign.getClass())) { + return true; + } + sign = sign.getCause(); + } + return false; + } + + @Override + public DetectorResult convert(Throwable throwable) { + + // todo + return null; + } +} 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 new file mode 100644 index 0000000000..d23aa9915c --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java @@ -0,0 +1,33 @@ +package com.fr.env.detect.impl.converter; + +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.thowable.ThrowableConverter; +import com.fr.third.org.hibernate.exception.GenericJDBCException; +import org.jetbrains.annotations.Nullable; + +/** + * created by Harrison on 2022/05/25 + **/ +public class FineDbDirtyConverter implements ThrowableConverter { + + @Override + public boolean accept(Throwable throwable) { + + Throwable sign = throwable; + while (sign != null) { + if (sign instanceof GenericJDBCException) { + return true; + } + sign = sign.getCause(); + } + return false; + } + + @Override + public @Nullable DetectorResult convert(Throwable throwable) { + + // 检测 Config + // todo + return null; + } +} 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 new file mode 100644 index 0000000000..8924d688a2 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java @@ -0,0 +1,31 @@ +package com.fr.env.detect.impl.converter; + +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.thowable.ThrowableConverter; +import com.fr.third.org.hsqldb.HsqlException; + +/** + * created by Harrison on 2022/05/24 + **/ +public class FineDbLockedConverter implements ThrowableConverter { + + @Override + public boolean accept(Throwable throwable) { + + Throwable sign = throwable; + while (sign != null) { + if (sign instanceof HsqlException) { + return true; + } + sign = sign.getCause(); + } + return false; + } + + @Override + public DetectorResult convert(Throwable throwable) { + + // todo + return null; + } +} 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 new file mode 100644 index 0000000000..21722ebb4e --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java @@ -0,0 +1,33 @@ +package com.fr.env.detect.impl.converter; + +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.thowable.ThrowableConverter; +import com.fr.third.org.hsqldb.HsqlException; + +/** + * HSQL 下的权限检测 + * + * created by Harrison on 2022/05/24 + **/ +public class FineDbPermissionConverter implements ThrowableConverter { + + @Override + public boolean accept(Throwable throwable) { + + Throwable sign = throwable; + while (sign != null) { + if (sign instanceof HsqlException) { + return true; + } + sign = sign.getCause(); + } + return false; + } + + @Override + public DetectorResult convert(Throwable throwable) { + + // todo + return null; + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableConverter.java b/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableConverter.java new file mode 100644 index 0000000000..6843cb2a80 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableConverter.java @@ -0,0 +1,28 @@ +package com.fr.env.detect.thowable; + +import com.fr.env.detect.bean.DetectorResult; +import org.jetbrains.annotations.Nullable; + +/** + * created by Harrison on 2022/05/13 + **/ +public interface ThrowableConverter { + + /** + * 是否支持该异常 + * + * @param throwable 异常 + * @return 是/否 + */ + boolean accept(Throwable throwable); + + /** + * 将异常转化为结果 + * + * @param throwable 异常 + * @return 转化结果 + */ + @Nullable + DetectorResult convert(Throwable throwable); + +} 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 new file mode 100644 index 0000000000..64cd3ce7b7 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java @@ -0,0 +1,58 @@ +package com.fr.env.detect.thowable; + +import com.fr.log.FineLoggerFactory; +import com.fr.log.LogHandler; +import com.fr.third.apache.logging.log4j.Level; +import com.fr.third.apache.logging.log4j.core.Filter; +import com.fr.third.apache.logging.log4j.core.Layout; +import com.fr.third.apache.logging.log4j.core.LogEvent; +import com.fr.third.apache.logging.log4j.core.appender.AbstractAppender; +import com.fr.third.apache.logging.log4j.core.config.Property; + +import java.io.Serializable; + +/** + * created by Harrison on 2022/05/13 + **/ +public class ThrowableLogAppender extends AbstractAppender { + + public ThrowableLogAppender(String name, Filter filter, Layout layout, boolean ignoreExceptions, Property[] properties) { + super(name, filter, layout, ignoreExceptions, properties); + } + + public static ThrowableLogAppender getInstance() { + return ExceptionLogAppenderHolder.INSTANCE; + } + + private static class ExceptionLogAppenderHolder { + private static final ThrowableLogAppender INSTANCE = new ThrowableLogAppender("exception-detect", null, null, false, null); + } + + private LogHandler logHandler = toHandler(); + + @Override + public void append(LogEvent logEvent) { + + if (logEvent.getLevel() == Level.ERROR) { + Throwable thrown = logEvent.getThrown(); + ThrowableStore.getInstance().add(thrown); + } + } + + private LogHandler toHandler() { + + final ThrowableLogAppender appender = this; + return () -> appender; + } + + + public void enable() { + + FineLoggerFactory.getLogger().addLogAppender(logHandler); + } + + public void disable() { + + FineLoggerFactory.getLogger().removeLogAppender(logHandler); + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableStore.java b/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableStore.java new file mode 100644 index 0000000000..346e218991 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableStore.java @@ -0,0 +1,36 @@ +package com.fr.env.detect.thowable; + +import java.util.ArrayList; +import java.util.List; + +/** + * 异常存储中心 + * + * created by Harrison on 2022/05/13 + **/ +public class ThrowableStore { + + public static ThrowableStore getInstance() { + return ThrowableStoreHolder.INSTANCE; + } + + private static class ThrowableStoreHolder { + private static final ThrowableStore INSTANCE = new ThrowableStore(); + } + + private List exceptions = new ArrayList<>(); + + public void add(Throwable throwable) { + if (throwable != null) { + exceptions.add(throwable); + } + } + + public List getAll() { + return exceptions; + } + + public void reset() { + exceptions.clear(); + } +}