From c96607630031c702830d0bd2c9ff385673632847 Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 27 May 2022 15:21:31 +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=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=A0=B8=E5=BF=83=E9=80=BB=E8=BE=91=E3=80=82=20=E9=81=87?= =?UTF-8?q?=E5=88=B0=E4=B8=8D=E6=98=8E=E7=A1=AE=E7=9A=84=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=EF=BC=8C=20=E5=88=99=E5=B0=86=E5=BC=82=E5=B8=B8=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=BF=9B=E6=9D=A5=E5=90=8E=EF=BC=8C=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E6=A3=80=E6=B5=8B=20=E9=81=87=E5=88=B0?= =?UTF-8?q?=E6=98=8E=E7=A1=AE=E7=9A=84=E5=BC=82=E5=B8=B8=EF=BC=8C=E9=80=9A?= =?UTF-8?q?=E8=BF=87=20DetectorType=20=E8=BF=9B=E8=A1=8C=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=A4=84=E7=90=86=20=E7=BB=9F=E4=B8=80=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E7=9B=B4=E6=8E=A5=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detect/base/CatchExceptionDetector.java | 17 +- .../fr/env/detect/base/DetectorBridge.java | 48 +- .../fr/env/detect/base/DetectorManager.java | 15 +- .../fr/env/detect/base/ExceptionDetector.java | 2 - .../fr/env/detect/bean/DetectorResult.java | 81 ++- .../fr/env/detect/bean/DetectorStatus.java | 17 + .../com/fr/env/detect/bean/DetectorType.java | 36 +- .../com/fr/env/detect/bean/ExceptionLog.java | 30 +- .../java/com/fr/env/detect/bean/Message.java | 15 +- ...Detector.java => FineDbDirtyDetector.java} | 6 +- .../env/detect/impl/FineDbLockedDetector.java | 16 + .../detect/impl/FineDbPermissionDetector.java | 15 + .../env/detect/impl/JarConflictDetector.java | 15 + .../detect/impl/JarInconsistentDetector.java | 51 +- .../fr/env/detect/impl/JarLackDetector.java | 27 +- .../impl/converter/ClassConfictConvertor.java | 1 + .../impl/converter/FineDbDirtyConverter.java | 16 +- .../impl/converter/FineDbLockedConverter.java | 13 +- .../converter/FineDbPermissionConverter.java | 8 +- .../fr/env/detect/ui/EnvDetectorDialog.java | 595 ++++++++++++++++++ 20 files changed, 916 insertions(+), 108 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/env/detect/bean/DetectorStatus.java rename designer-base/src/main/java/com/fr/env/detect/impl/{HsqlDirtyDetector.java => FineDbDirtyDetector.java} (73%) create mode 100644 designer-base/src/main/java/com/fr/env/detect/impl/FineDbLockedDetector.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/impl/FineDbPermissionDetector.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/impl/JarConflictDetector.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorDialog.java 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 index b2e60d42c7..3eeac6e461 100644 --- 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 @@ -16,8 +16,14 @@ public abstract class CatchExceptionDetector extends AbstractExceptionDetector { private ThrowableConverter throwableConverter; - public CatchExceptionDetector(DetectorType key, ThrowableStore throwableStore, ThrowableConverter throwableConverter) { - super(key); + public CatchExceptionDetector(DetectorType type, ThrowableConverter throwableConverter) { + super(type); + this.throwableStore = ThrowableStore.getInstance(); + this.throwableConverter = throwableConverter; + } + + public CatchExceptionDetector(DetectorType type, ThrowableStore throwableStore, ThrowableConverter throwableConverter) { + super(type); this.throwableStore = throwableStore; this.throwableConverter = throwableConverter; } @@ -36,7 +42,12 @@ public abstract class CatchExceptionDetector extends AbstractExceptionDetector { List throwableList = throwableStore.getAll(); for (Throwable throwable : throwableList) { if (throwableConverter.accept(throwable)) { - return throwableConverter.convert(throwable); + + DetectorResult result = throwableConverter.convert(throwable); + if (result == null) { + result = DetectorResult.normal(type()); + } + return result; } } 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 index 8cbef25abb..031df59a2c 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 @@ -2,14 +2,14 @@ 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.impl.HsqlDirtyDetector; +import com.fr.env.detect.impl.FineDbDirtyDetector; +import com.fr.env.detect.impl.FineDbLockedDetector; +import com.fr.env.detect.impl.FineDbPermissionDetector; +import com.fr.env.detect.impl.JarConflictDetector; import com.fr.env.detect.impl.JarInconsistentDetector; import com.fr.env.detect.impl.JarLackDetector; -import com.fr.env.detect.impl.converter.ClassConfictConvertor; -import com.fr.env.detect.impl.converter.FineDbDirtyConverter; -import com.fr.env.detect.impl.converter.FineDbLockedConverter; -import com.fr.env.detect.impl.converter.FineDbPermissionConverter; import com.fr.env.detect.thowable.ThrowableLogAppender; +import com.fr.env.detect.thowable.ThrowableStore; import com.fr.value.NotNullLazyValue; import org.jetbrains.annotations.NotNull; @@ -32,28 +32,20 @@ public class DetectorBridge { private static final DetectorBridge INSTANCE = new DetectorBridge(); } - private final NotNullLazyValue throwableBridge = new NotNullLazyValue() { - @Override - protected @NotNull ThrowableBridge compute() { - - ThrowableBridge bridge = new ThrowableBridge(); - bridge.register(new ClassConfictConvertor()); - bridge.register(new FineDbDirtyConverter()); - bridge.register(new FineDbLockedConverter()); - bridge.register(new FineDbPermissionConverter()); - return bridge; - } - }; - private final NotNullLazyValue detectorManager = new NotNullLazyValue() { @Override protected @NotNull DetectorManager compute() { DetectorManager manager = new DetectorManager(); - manager.register(new HsqlDirtyDetector()); + + manager.register(new FineDbDirtyDetector()); + manager.register(new FineDbPermissionDetector()); + manager.register(new FineDbLockedDetector()); + manager.register(new JarInconsistentDetector()); manager.register(new JarLackDetector()); + manager.register(new JarConflictDetector()); return manager; } }; @@ -90,7 +82,8 @@ public class DetectorBridge { } /** - * 执行-检测异常 + * 异常检测 + * 对异常统一检测 * * @return 能够检测出的异常情况 */ @@ -100,13 +93,22 @@ public class DetectorBridge { } /** - * 执行-捕获异常 + * 异常检测 + * 当遇到异常时,且异常难以处理,直接导致服务器启动失败时,调用 + * 将异常添加进来,统一检测 * * @param throwable 异常 * @return 检测结果 */ - public Optional convert(Throwable throwable) { + public Stream detect(Throwable throwable) { + + // 先清理一下 + ThrowableStore.getInstance().reset(); - return throwableBridge.getValue().convert(throwable); + ThrowableStore.getInstance().add(throwable); + Stream result = detect(); + ThrowableStore.getInstance().reset(); + + return result; } } 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 9d3ae2daa9..76c2d2dd18 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 @@ -1,7 +1,7 @@ package com.fr.env.detect.base; -import com.fr.env.detect.bean.DetectorType; import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorType; import java.util.ArrayList; import java.util.List; @@ -25,16 +25,25 @@ class DetectorManager { public Stream detect() { - return detectors.stream() + Stream results = detectors.stream() .map(ExceptionDetector::detect) .filter(Objects::nonNull); + + // 记录一下日志 + results.forEach(DetectorResult::log); + return results; } public Optional detect(DetectorType type) { - return detectors.stream() + Optional result = detectors.stream() .filter((detector -> type == detector.type())) .findFirst() .map(ExceptionDetector::detect); + + // 记录日志 + result.ifPresent(DetectorResult::log); + + return result; } } 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 index c874b19791..7713ef739e 100644 --- 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 @@ -2,7 +2,6 @@ package com.fr.env.detect.base; import com.fr.env.detect.bean.DetectorResult; import com.fr.env.detect.bean.DetectorType; -import org.jetbrains.annotations.Nullable; /** * created by Harrison on 2022/05/13 @@ -21,7 +20,6 @@ public interface ExceptionDetector { * * @return 结果 */ - @Nullable DetectorResult detect(); } 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 86d6c0e0ce..aadccd0911 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 @@ -1,7 +1,5 @@ package com.fr.env.detect.bean; -import org.jetbrains.annotations.Nullable; - /** * 检测结果 * @@ -11,42 +9,76 @@ public class DetectorResult { private DetectorType type; + private DetectorStatus status; + private ExceptionTips tips; private ExceptionSolution solution; - public DetectorResult(DetectorType type, ExceptionTips tips, ExceptionSolution solution) { + private ExceptionLog log; + + private DetectorResult(DetectorType type) { + this.type = type; + } + + private DetectorResult(DetectorType type, ExceptionTips tips, ExceptionSolution solution, ExceptionLog log) { + this.type = type; this.tips = tips; this.solution = solution; + this.log = log; + } + + public static DetectorResult normal(DetectorType type) { + + DetectorResult result = new DetectorResult(type); + result.status = DetectorStatus.NORMAL; + return result; + } + + public static DetectorResult exception(DetectorType type, ExceptionTips tips, ExceptionSolution solution, ExceptionLog log) { + + DetectorResult result = new DetectorResult(type, tips, solution, log); + result.status = DetectorStatus.EXCEPTION; + return result; + } + + public DetectorStatus getStatus() { + return status; } public DetectorType getType() { return type; } - @Nullable public ExceptionTips getTips() { return tips; } - @Nullable public ExceptionSolution getSolution() { return solution; } - public static DetectorResultBuilder builder() { + public void log() { - return new DetectorResultBuilder(); + if (log != null) { + log.log(); + } } + public static DetectorResultBuilder builder() { + + return new DetectorResultBuilder() + .withStatus(DetectorStatus.EXCEPTION); + } public static final class DetectorResultBuilder { private DetectorType type; - + private DetectorStatus status; private ExceptionTips tips; private ExceptionSolution solution; + private ExceptionLog log; private DetectorResultBuilder() { } @@ -56,6 +88,16 @@ public class DetectorResult { return this; } + public DetectorResultBuilder withStatus(DetectorStatus status) { + this.status = status; + return this; + } + + public DetectorResultBuilder withTips(ExceptionTips tips) { + this.tips = tips; + return this; + } + public DetectorResultBuilder withTips(String message) { Message.Simple simple = new Message.Simple(message); @@ -63,26 +105,33 @@ public class DetectorResult { return this; } - public DetectorResultBuilder withTips(ExceptionTips tips) { - this.tips = tips; + public DetectorResultBuilder withSolution(ExceptionSolution solution) { + this.solution = solution; return this; } - - public DetectorResultBuilder withSolution(String content, String link) { + public DetectorResultBuilder withSolution(String content, String link) { + Message.Link message = new Message.Link(content, link); this.solution = new ExceptionSolution(message, null); return this; } - public DetectorResultBuilder withSolution(ExceptionSolution solution) { - this.solution = solution; + public DetectorResultBuilder withLog(String log, Object... args) { + + this.log = ExceptionLog.create(log, args); + return this; + } + + public DetectorResultBuilder withLog(ExceptionLog log) { + this.log = log; return this; } public DetectorResult build() { - - return new DetectorResult(type, tips, solution); + DetectorResult detectorResult = new DetectorResult(type, tips, solution, log); + 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..6a12015e91 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorStatus.java @@ -0,0 +1,17 @@ +package com.fr.env.detect.bean; + +/** + * created by Harrison on 2022/05/27 + **/ +public enum DetectorStatus { + + /** + * 正常 + */ + NORMAL, + + /** + * 异常 + */ + EXCEPTION, +} 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 index 979b355018..1dc8e4d62a 100644 --- 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 @@ -1,5 +1,7 @@ package com.fr.env.detect.bean; +import com.fr.design.i18n.Toolkit; + /** * 检测的原生数据 * 其实这里可以继续拆分到不同的逻辑下面的, 比如实际生成 DetectorResult 的地方 {@link com.fr.env.detect.base.ExceptionDetector}。 @@ -13,6 +15,7 @@ public enum DetectorType { * 缺少 JAR */ LACK_OF_JAR(Kind.JAR, WorkType.LOCAL, + "Fine_Design_Basic_Jar_Lacked_Desc", "Fine_Design_Basic_Jar_Lack", "Fine_Design_Basic_Jar_Solution", "Fine_Design_Basic_Log_Jar_Lack"), @@ -22,6 +25,7 @@ public enum DetectorType { * JAR 包版本不一致 */ JAR_IN_CONSISTENCE(Kind.JAR, WorkType.SIMPLE, + "Fine_Design_Basic_Jar_InConsistent_Desc", "Fine_Design_Basic_Jar_InConsistent", "Fine_Design_Basic_Jar_Solution", "Fine_Design_Basic_Log_Jar_InConsistent"), @@ -30,6 +34,7 @@ public enum DetectorType { * JAR 包冲突 */ JAR_CONFLICT(Kind.JAR, WorkType.REMOTE, + "Fine_Design_Basic_Jar_Problem_Desc", "Fine_Design_Basic_Jar_Problem", "Fine_Design_Basic_Jar_Solution", "Fine_Design_Basic_Log_Jar_Problem"), @@ -38,6 +43,7 @@ public enum DetectorType { * FineDB 权限问题 */ FINE_DB_PERMISSION(Kind.FINE_DB, WorkType.LOCAL, + "Fine_Design_Basic_FineDB_Permission_Occupied_Desc", "Fine_Design_Basic_FineDB_Permission_Occupied", "Fine_Design_Basic_FineDB_Solution", "Fine_Design_Basic_Log_FineDB_Permission_Occupied"), @@ -46,6 +52,7 @@ public enum DetectorType { * FineDB 锁 */ FINE_DB_LOCKED(Kind.FINE_DB, WorkType.LOCAL, + "Fine_Design_Basic_FineDB_Locked_Desc", "Fine_Design_Basic_FineDB_Locked", "Fine_Design_Basic_FineDB_Solution", "Fine_Design_Basic_Log_FineDB_Locked"), @@ -54,6 +61,7 @@ public enum DetectorType { * FineDB 脏数据 */ FINE_DB_DIRTY(Kind.FINE_DB, WorkType.SIMPLE, + "Fine_Design_Basic_FineDB_Dirty_Data_Desc", "Fine_Design_Basic_FineDB_Dirty_Data", "Fine_Design_Basic_FineDB_Dirty_Solution", "Fine_Design_Basic_Log_FineDB_Dirty_Data") @@ -63,21 +71,32 @@ public enum DetectorType { private final WorkType workType; + private final String descLocale; + private final String tipsLocale; private final String solutionLocale; private final String logLocale; - DetectorType(Kind kind, WorkType workType, String tipsLocale, String solutionLocale, String logLocale) { + DetectorType(Kind kind, WorkType workType, String descLocale, String tipsLocale, String solutionLocale, String logLocale) { this.kind = kind; this.workType = workType; + this.descLocale = descLocale; this.tipsLocale = tipsLocale; this.solutionLocale = solutionLocale; this.logLocale = logLocale; } + public String getDescription() { + return Toolkit.i18nText(descLocale); + } + + public String getDescLocale() { + return descLocale; + } + public Kind getKind() { return kind; } @@ -103,11 +122,22 @@ public enum DetectorType { /** * JAR 类型 */ - JAR, + JAR("Fine_Design_Basic_Jar_Kind_Desc"), + /** * FineDB 类型 */ - FINE_DB + FINE_DB("Fine_Design_Basic_FineDB_Kind_Desc"); + + private final String locale; + + Kind(String locale) { + this.locale = locale; + } + + public String getDescription() { + return Toolkit.i18nText(this.locale); + } } public enum WorkType { 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 index 90cdb58fdb..521e903452 100644 --- 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 @@ -1,24 +1,36 @@ package com.fr.env.detect.bean; +import com.fr.log.FineLoggerFactory; + /** * created by Harrison on 2022/05/13 **/ public class ExceptionLog { - private final String errorCode; + private final String template; + + private final Object[] args; + + private ExceptionLog(String template, Object... args) { + this.template = template; + this.args = args; + } + + public static ExceptionLog create(String template, Object... args) { + + return new ExceptionLog(template, args); + } - private final String locale; + public void log() { - public ExceptionLog(String errorCode, String locale) { - this.errorCode = errorCode; - this.locale = locale; + FineLoggerFactory.getLogger().error(template, args); } - public String getErrorCode() { - return errorCode; + public String getTemplate() { + return template; } - public String getLocale() { - return locale; + public Object[] getArgs() { + return args; } } 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 index e1d6dcd62c..2acdec8b84 100644 --- 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 @@ -12,6 +12,13 @@ public interface Message { */ Type getType(); + /** + * 返回内容 + * + * @return 内容 + */ + String get(); + enum Type { /** @@ -33,7 +40,8 @@ public interface Message { this.message = message; } - public String getMessage() { + @Override + public String get() { return message; } @@ -54,6 +62,11 @@ public interface Message { this.link = link; } + @Override + public String get() { + return getText(); + } + public String getText() { return text; } 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/FineDbDirtyDetector.java similarity index 73% rename from designer-base/src/main/java/com/fr/env/detect/impl/HsqlDirtyDetector.java rename to designer-base/src/main/java/com/fr/env/detect/impl/FineDbDirtyDetector.java index 4d3645858c..1b34597866 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/HsqlDirtyDetector.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/FineDbDirtyDetector.java @@ -8,13 +8,13 @@ import com.fr.env.detect.thowable.ThrowableStore; /** * created by Harrison on 2022/05/25 **/ -public class HsqlDirtyDetector extends CatchExceptionDetector { +public class FineDbDirtyDetector extends CatchExceptionDetector { - public HsqlDirtyDetector() { + public FineDbDirtyDetector() { this(ThrowableStore.getInstance()); } - public HsqlDirtyDetector(ThrowableStore throwableStore) { + public FineDbDirtyDetector(ThrowableStore throwableStore) { super(DetectorType.FINE_DB_DIRTY, throwableStore, new FineDbDirtyConverter()); } diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/FineDbLockedDetector.java b/designer-base/src/main/java/com/fr/env/detect/impl/FineDbLockedDetector.java new file mode 100644 index 0000000000..c312ce3288 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/impl/FineDbLockedDetector.java @@ -0,0 +1,16 @@ +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.impl.converter.FineDbLockedConverter; + +/** + * created by Harrison on 2022/05/26 + **/ +public class FineDbLockedDetector extends CatchExceptionDetector { + + public FineDbLockedDetector() { + super(DetectorType.FINE_DB_LOCKED, new FineDbLockedConverter()); + } + +} diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/FineDbPermissionDetector.java b/designer-base/src/main/java/com/fr/env/detect/impl/FineDbPermissionDetector.java new file mode 100644 index 0000000000..4e3a18cedd --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/impl/FineDbPermissionDetector.java @@ -0,0 +1,15 @@ +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.impl.converter.FineDbPermissionConverter; + +/** + * created by Harrison on 2022/05/26 + **/ +public class FineDbPermissionDetector extends CatchExceptionDetector { + + public FineDbPermissionDetector() { + super(DetectorType.FINE_DB_PERMISSION, new FineDbPermissionConverter()); + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/JarConflictDetector.java b/designer-base/src/main/java/com/fr/env/detect/impl/JarConflictDetector.java new file mode 100644 index 0000000000..39a3bc4e0b --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/impl/JarConflictDetector.java @@ -0,0 +1,15 @@ +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.impl.converter.ClassConfictConvertor; + +/** + * created by Harrison on 2022/05/26 + **/ +public class JarConflictDetector extends CatchExceptionDetector { + + public JarConflictDetector() { + super(DetectorType.JAR_CONFLICT, new ClassConfictConvertor()); + } +} 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 4a3e4aafa8..dfb880a9e1 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 @@ -7,15 +7,14 @@ import com.fr.env.detect.base.DetectorConstants; import com.fr.env.detect.base.DetectorUtil; import com.fr.env.detect.bean.DetectorResult; import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.bean.ExceptionLog; import com.fr.env.detect.bean.ExceptionSolution; import com.fr.env.detect.bean.ExceptionTips; import com.fr.env.detect.bean.Message; -import com.fr.env.detect.exception.DetectorException; import com.fr.general.build.BuildInfo; import com.fr.general.build.BuildInfoManager; import com.fr.general.build.BuildInfoOperator; import com.fr.general.build.impl.BuildInfoOperatorImpl; -import com.fr.log.FineLoggerFactory; import com.fr.third.guava.collect.MapDifference; import com.fr.third.guava.collect.Maps; import com.fr.third.org.apache.commons.lang3.StringUtils; @@ -24,6 +23,7 @@ import com.fr.workspace.WorkContext; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -37,42 +37,57 @@ public class JarInconsistentDetector extends AbstractExceptionDetector { super(DetectorType.JAR_IN_CONSISTENCE); } + /** + * 本地 + * 先获取 Designer, 然后对其他的 JAR 信息匹配 + *

+ * 远程 + * 两边一一对应匹配 + * + * @return 结果 + */ @Override public DetectorResult detect() { - DetectorResult.DetectorResultBuilder builder = DetectorResult.builder(); - if (WorkContext.getCurrent().isLocal()) { // 本地的获取方式 BuildInfoOperator operator = new BuildInfoOperatorImpl(); List buildInfos = operator.getBuildInfos(); - String designerBuild = buildInfos.stream() + // 获取设计器的 build + Optional designerBuild = buildInfos.stream() .filter(DetectorUtil::isDesignerJar) .map(BuildInfo::getGroupBuild) .filter(StringUtils::isNotEmpty) - .findFirst() - .orElseThrow(DetectorException::new); + .findFirst(); + + // 如果 build + if (!designerBuild.isPresent()) { + return DetectorResult.normal(type()); + } + // 获取所有的不一致的 build List inConsistentInfos = buildInfos.stream() - .filter((e) -> !StringUtils.equals(designerBuild, e.getGroupBuild())) + .filter((e) -> !StringUtils.equals(designerBuild.get(), e.getGroupBuild())) .collect(Collectors.toList()); + // 没有直接返回 if (Collections.isEmpty(inConsistentInfos)) { - return null; + return DetectorResult.normal(type()); } + // 有的话 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; - builder.withTips(new ExceptionTips(new Message.Simple(tipsMessage))) - .withSolution(new ExceptionSolution(new Message.Link(Toolkit.i18nText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), null)); - FineLoggerFactory.getLogger().error(type().getLogLocale() + message); + return DetectorResult.exception(type(), + new ExceptionTips(new Message.Simple(tipsMessage)), + new ExceptionSolution(new Message.Link(Toolkit.i18nText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), null), + ExceptionLog.create(type().getLogLocale() + message)); } else { @@ -91,20 +106,20 @@ public class JarInconsistentDetector extends AbstractExceptionDetector { Map diffInCommon = difference.entriesInCommon(); if (diffInCommon.isEmpty()) { - return null; + return DetectorResult.normal(type()); } 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); - builder.withTips(new ExceptionTips(tipsMessage)) - .withSolution(new ExceptionSolution(new Message.Link(Toolkit.i18nText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), null)); + return DetectorResult.exception(type(), + new ExceptionTips(tipsMessage), + new ExceptionSolution(new Message.Link(Toolkit.i18nText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), null), + ExceptionLog.create(type().getLogLocale() + message)); } - return builder.build(); } private Map groupBy(List localInfos) { 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 ecad03e121..654029da7c 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 @@ -7,6 +7,7 @@ import com.fr.env.detect.base.DetectorConstants; import com.fr.env.detect.base.DetectorUtil; import com.fr.env.detect.bean.DetectorResult; import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.bean.ExceptionLog; import com.fr.env.detect.bean.ExceptionSolution; import com.fr.env.detect.bean.ExceptionTips; import com.fr.env.detect.bean.Message; @@ -14,7 +15,6 @@ 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.log.FineLoggerFactory; import com.fr.stable.CommonUtils; import com.fr.stable.StableUtils; import com.fr.third.guava.collect.Lists; @@ -43,11 +43,9 @@ public class JarLackDetector extends AbstractExceptionDetector { // 不支持远程 if (!WorkContext.getCurrent().isLocal()) { - return null; + return DetectorResult.normal(type()); } - DetectorResult.DetectorResultBuilder builder = DetectorResult.builder(); - // 检测有哪些 JAR 包, 当前是否缺少对应的 JAR 包 BuildInfoOperator buildInfoOperator = new BuildInfoOperatorImpl(); List buildInfos = buildInfoOperator.getBuildInfos(); @@ -56,28 +54,25 @@ public class JarLackDetector extends AbstractExceptionDetector { .collect(Collectors.toList()); if (Collections.isEmpty(lackInfos)) { - return null; + return DetectorResult.normal(type()); } - Message message = tipsMessage(lackInfos); - builder.withTips(new ExceptionTips(message)) - .withSolution( - new ExceptionSolution( - new Message.Link(InterProviderFactory.getProvider().getLocText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), - null)); - - logException(lackInfos); + Message tipsMsg = tipsMessage(lackInfos); + ExceptionLog exceptionLog = exceptionLog(lackInfos); - return builder.build(); + return DetectorResult.exception(type(), new ExceptionTips(tipsMsg), + new ExceptionSolution( + new Message.Link(InterProviderFactory.getProvider().getLocText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), + null), exceptionLog); } - private void logException(List lackInfos) { + private ExceptionLog exceptionLog(List lackInfos) { List jarInfos = lackInfos.stream() .map(BuildInfo::getJar) .collect(Collectors.toList()); String message = StringUtils.join(",", jarInfos); - FineLoggerFactory.getLogger().error(type().getLogLocale() + message); + return ExceptionLog.create(type().getLogLocale() + message); } private boolean isLackInfo(BuildInfo e) { diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConfictConvertor.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConfictConvertor.java index dd26dc50fb..f2c8c5b758 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConfictConvertor.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConfictConvertor.java @@ -93,6 +93,7 @@ public class ClassConfictConvertor implements ThrowableConverter { } } } + } catch (IOException ignore) { } } 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 962768eb4a..f61d16913c 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 @@ -10,7 +10,6 @@ import com.fr.env.detect.bean.ExceptionSolution; import com.fr.env.detect.bean.Message; import com.fr.env.detect.bean.SolutionAction; import com.fr.env.detect.thowable.ThrowableConverter; -import com.fr.log.FineLoggerFactory; import com.fr.third.org.hibernate.exception.GenericJDBCException; import org.jetbrains.annotations.Nullable; @@ -19,6 +18,8 @@ import java.util.Iterator; import java.util.Map; /** + * 脏数据检测 + * * created by Harrison on 2022/05/25 **/ public class FineDbDirtyConverter implements ThrowableConverter { @@ -36,6 +37,14 @@ public class FineDbDirtyConverter implements ThrowableConverter { return false; } + /** + * 根据堆栈,确认是否是从配置中发出来的异常 + * 如果是,则找到对应的配置的表, + * 输出信息 + * + * @param throwable 异常 + * @return 检测结果 + */ @Override public @Nullable DetectorResult convert(Throwable throwable) { @@ -72,10 +81,9 @@ public class FineDbDirtyConverter implements ThrowableConverter { } }); builder.withTips(tipsLocale) - .withSolution(exceptionSolution); + .withSolution(exceptionSolution) + .withLog(Toolkit.i18nText(detectorType.getLogLocale(), tableName)); - String errorMsg = Toolkit.i18nText(detectorType.getLogLocale(), tableName); - FineLoggerFactory.getLogger().error(errorMsg); return builder.build(); } } 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 509cb30f3a..09cc9b62f8 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 @@ -25,6 +25,12 @@ public class FineDbLockedConverter implements ThrowableConverter { return false; } + /** + * 检测 FineDB 是否锁住 + * + * @param throwable 异常 + * @return 结果 + */ @Override public DetectorResult convert(Throwable throwable) { @@ -33,15 +39,16 @@ public class FineDbLockedConverter implements ThrowableConverter { sign = sign.getCause(); } + DetectorType type = DetectorType.FINE_DB_LOCKED; + String message = sign.getMessage(); if (message.contains("lock")) { - DetectorType type = DetectorType.FINE_DB_LOCKED; - String tipsLocale = type.getTipsLocale(); return DetectorResult.builder() .withType(type) - .withTips(Toolkit.i18nText(tipsLocale)) + .withTips(Toolkit.i18nText(type.getTipsLocale())) .withSolution(Toolkit.i18nText(type.getSolutionLocale()), DetectorConstants.FINE_DB_HELP_LINK) + .withLog(Toolkit.i18nText(type.getLogLocale())) .build(); } 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 index 7a7407ea99..8052f81648 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 @@ -35,15 +35,15 @@ public class FineDbPermissionConverter implements ThrowableConverter { sign = sign.getCause(); } + DetectorType type = DetectorType.FINE_DB_PERMISSION; String message = sign.getMessage(); if (message.contains("permission")) { - DetectorType type = DetectorType.FINE_DB_PERMISSION; - String tipsLocale = type.getTipsLocale(); - + return DetectorResult.builder() .withType(type) - .withTips(Toolkit.i18nText(tipsLocale)) + .withTips(Toolkit.i18nText(type.getTipsLocale())) .withSolution(Toolkit.i18nText(type.getSolutionLocale()), DetectorConstants.FINE_DB_HELP_LINK) + .withLog(type.getLogLocale()) .build(); } return null; 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 new file mode 100644 index 0000000000..d5a0c45eac --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorDialog.java @@ -0,0 +1,595 @@ +package com.fr.env.detect.ui; + +import com.fr.base.svg.IconUtils; +import com.fr.design.components.notification.NotificationAction; +import com.fr.design.components.notification.NotificationDialog; +import com.fr.design.components.notification.NotificationDialogProperties; +import com.fr.design.components.notification.NotificationMessage; +import com.fr.design.components.notification.NotificationModel; +import com.fr.design.components.notification.NotificationType; +import com.fr.design.components.table.TablePanel; +import com.fr.design.constants.DesignerColor; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ibutton.UIButtonUI; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.ui.util.UIUtil; +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.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorStatus; +import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.bean.ExceptionSolution; +import com.fr.env.detect.bean.ExceptionTips; +import com.fr.env.detect.bean.Message; +import com.fr.env.detect.bean.SolutionAction; +import com.fr.third.guava.collect.Lists; +import org.jetbrains.annotations.NotNull; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.SwingWorker; +import javax.swing.plaf.ButtonUI; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * created by Harrison on 2022/05/26 + **/ +public class EnvDetectorDialog extends JDialog { + + private static final ImageIcon LOADING_ICON = getLoadingIcon(); + + private JPanel body; + + private final JPanel headerPanel; + + private final TablePanel tablePanel; + + private final JPanel tailPanel; + + /* 数据 model */ + + private EnvDetectorModel model = new EnvDetectorModel(); + + /* 流程 model */ + + /** + * 默认是第一个要检测 + */ + private int currentDetectIndex = 0; + + private EnvDetectorButtonStatus buttonStatus = EnvDetectorButtonStatus.START; + + private SwingWorker detectWorker = null; + + public EnvDetectorDialog(Frame owner) { + super(owner); + + configProperties(); + + this.body = FRGUIPaneFactory.createBorderLayout_L_Pane(); + Color backgroundColor = new Color(240, 240, 243, 1); + this.body.setBackground( backgroundColor); + + this.headerPanel = createHeaderPanel(); + body.add(headerPanel, BorderLayout.NORTH); + + this.tablePanel = createTablePanel(); + body.add(tablePanel, BorderLayout.CENTER); + + /* tailPanel*/ + this.tailPanel = createTailPanel(); + body.add(tailPanel, BorderLayout.SOUTH); + + add(body); + + Dimension preferredSize = body.getPreferredSize(); + setSize(preferredSize); + + repaint(); + pack(); + + GUICoreUtils.centerWindow(this); + } + + @NotNull + private JPanel createHeaderPanel() { + + JPanel headerPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + headerPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 12, 0)); + UIButton detectButton = new UIButton(buttonStatus.getDesc()) { + @Override + public ButtonUI getUI() { + + return new UIButtonUI() { + @Override + protected void doExtraPainting(UIButton b, Graphics2D g2d, int w, int h, String selectedRoles) { + if (isPressed(b) && b.isPressedPainted()) { + GUIPaintUtils.fillPressed(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), + DesignerColor.Button.Primary.PRESSED); + } else if (isRollOver(b)) { + GUIPaintUtils.fillRollOver(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), b.isPressedPainted(), + DesignerColor.Button.Primary.HOVER); + } else if (b.isNormalPainted()) { + GUIPaintUtils.fillNormal(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), b.isPressedPainted(), + DesignerColor.Button.Primary.NORMAL); + } + } + }; + } + }; + detectButton.setForeground(Color.WHITE); + detectButton.addActionListener(event -> { + if (buttonStatus.isNotExecuting()) { + startDetecting(detectButton); + } else { + stopDetecting(detectButton); + } + }); + detectButton.setPreferredSize(new Dimension(68, 20)); + detectButton.setBorderPainted(false); + detectButton.setContentAreaFilled(false); + headerPanel.add(detectButton, BorderLayout.WEST); + + return headerPanel; + } + + private void startDetecting(UIButton detectButton) { + + // 执行前 + buttonStatus = buttonStatus.next(); + UIUtil.invokeLaterIfNeeded(() -> detectButton.setText(buttonStatus.getDesc())); + detectWorker = new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + List items = model.getItems(); + // 执行刷新 + for (int i = currentDetectIndex; i < items.size(); i++) { + + // 看一下是否关闭了, 有可能已经关闭了。 + if (buttonStatus.isNotExecuting()) { + return null; + } + + // 刷新一下面板-开始执行啦 + UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refresh); + + EnvDetectorItem item = items.get(i); + DetectorType type = item.getType(); + + // 执行检测, UI-当前在检测中 + Optional detect = UIUtil.waitUntil( + () -> DetectorBridge.getInstance().detect(type), + 1000, TimeUnit.MILLISECONDS); + // 获取结果,更新UI + detect.ifPresent(item::setResult); + + // 只有还在运行中,才会真正的刷新面板 + if (buttonStatus.isExecuting()) { + // 在刷新一下面板 + UIUtil.invokeLaterIfNeeded(EnvDetectorDialog.this::refresh); + currentDetectIndex++; + } + + } + return null; + } + + @Override + protected void done() { + + if (buttonStatus.isExecuting()) { + // 执行结束 + buttonStatus = buttonStatus.next(); + UIUtil.invokeLaterIfNeeded(() -> detectButton.setText(buttonStatus.getDesc())); + } + } + }; + // 开始执行 + detectWorker.execute(); + } + + private void stopDetecting(UIButton detectButton) { + + buttonStatus = buttonStatus.next(); + + // 先停止 + detectWorker.cancel(false); + // 更改-UI + // 执行中 + UIUtil.invokeLaterIfNeeded(() -> { + // 刷新按钮 + detectButton.setText(buttonStatus.getDesc()); + // 刷新面板 + refresh(); + }); + } + + + @NotNull + private TablePanel createTablePanel() { + + TablePanel tablePanel = new TablePanel(18, 3); + tablePanel.updateHeaders(new String[] { + Toolkit.i18nText("Fine-Design_Basic_Detect_Kind"), + Toolkit.i18nText("Fine-Design_Basic_Detect_Item"), + Toolkit.i18nText("Fine-Design_Basic_Detect_Result")}); + + updateTable(tablePanel); + + return tablePanel; + } + + private void updateTable(TablePanel tablePanel) { + + Map> itemMap = model.getItemMap(); + + // 行号, 这边更新是通过 行/列 。 不是索引 + int row = 1; + for (Map.Entry> entry : itemMap.entrySet()) { + + DetectorType.Kind kind = entry.getKey(); + List items = entry.getValue(); + for (int i = 0; i < items.size(); i++) { + if (i == 0) { + tablePanel.updateCell(row, 1, kind.getDescription()); + } + EnvDetectorItem item = items.get(i); + tablePanel.updateCell(row, 2, new UILabel(item.getDescription())); + DetectorResult result = item.getResult(); + + int detectRow = currentDetectIndex + 1; + + if (result == null) { + // 处于非正在检测状态 或者 索引不等于当前行号的时候 + UILabel label; + if (buttonStatus.isExecuting() && detectRow == row) { + // 正在检测索引 + label = new UILabel(LOADING_ICON, UILabel.LEADING); + } else { + label = new UILabel("-"); + } + tablePanel.updateCell(row, 3, label); + } else { + Component resultComponent = createResultComponent(result); + tablePanel.updateCell(row, 3, resultComponent); + } + row++; + } + } + } + + private static ImageIcon getLoadingIcon() { + + URL resource = EnvDetectorDialog.class.getResource("/com/fr/design/standard/loading/loading-120.gif"); + if (resource == null) { + return null; + } + ImageIcon loadingIcon = new ImageIcon(resource); + int width = 16; + int height = 16; + loadingIcon.setImage(loadingIcon.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT)); + return loadingIcon; + } + + private Component createResultComponent(DetectorResult result) { + + JPanel statusPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + if (result.getStatus() == DetectorStatus.NORMAL) { + statusPanel.add(new UILabel(IconUtils.readIcon("/com/fr/design/standard/reminder/reminder_success.svg")), BorderLayout.WEST); + statusPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Normal")), BorderLayout.CENTER); + } else { + statusPanel.add(new UILabel(IconUtils.readIcon("/com/fr/design/standard/reminder/reminder_error.svg")), BorderLayout.WEST); + statusPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Exception")), BorderLayout.CENTER); + 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(EnvDetectorDialog.this::convertDetectorResult) + .collect(Collectors.toList()); + + NotificationDialog dialog = new NotificationDialog(properties, notificationModels); + dialog.open(); + } + }); + statusPanel.add(detailLabel); + } + return statusPanel; + } + + private NotificationModel convertDetectorResult(DetectorResult result) { + + List messages = new ArrayList<>(); + + Function> convert2NotificationMsg = message -> { + + NotificationMessage notificationMessage = null; + if (message != null) { + Message.Type type = message.getType(); + switch (type) { + case SIMPLE: + notificationMessage = (new NotificationMessage.SimpleMessage(message.get())); + break; + case LINK: + Message.Link linkMsg = (Message.Link) message; + notificationMessage = new NotificationMessage.LinkMessage(linkMsg.getText(), linkMsg.getLink()); + break; + default: + break; + } + } + return Optional.ofNullable(notificationMessage); + }; + + ExceptionTips tips = result.getTips(); + convert2NotificationMsg + .apply(tips.getMessage()) + .ifPresent(messages::add); + + ExceptionSolution solution = result.getSolution(); + 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(); + } + }; + } + + return new NotificationModel(NotificationType.WARNING, notificationAction, messages); + } + + private void refresh() { + + updateTable(this.tablePanel); + pack(); + repaint(); + } + + @NotNull + private JPanel createTailPanel() { + + JPanel tailPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + tailPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0)); + + JPanel configPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + { + UICheckBox checkBox = new UICheckBox(); + configPanel.add(checkBox, BorderLayout.WEST); + UILabel description = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Detect_Switch")); + configPanel.add(description, BorderLayout.EAST); + } + tailPanel.add(configPanel, BorderLayout.WEST); + + JPanel actionsPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + actionsPanel.setLayout(FRGUIPaneFactory.createM_BorderLayout()); + { + UIButton confirmButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Confirm")); + confirmButton.addActionListener((e) -> { + setVisible(false); + dispose(); + // 配置处理 + // todo + }); + actionsPanel.add(confirmButton, BorderLayout.WEST); + + UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel")); + cancelButton.addActionListener((e) -> { + setVisible(false); + dispose(); + }); + actionsPanel.add(cancelButton, BorderLayout.EAST); + } + tailPanel.add(actionsPanel, BorderLayout.EAST); + return tailPanel; + } + + private void configProperties() { + + setTitle(Toolkit.i18nText("Fine-Design_Basic_Detect_Title")); + setModal(false); + setFocusable(false); + setAutoRequestFocus(false); + setResizable(false); + } + + /** + * 数据 model + * + * kind-list_item + */ + private class EnvDetectorModel { + + private 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.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) { + + List items = itemMap.get(type.getKind()); + items.stream() + .filter((e) -> e.getType() == type) + .findFirst() + .ifPresent((e) -> {e.setResult(result);}); + } + + public Stream getResults() { + + return getItems().stream() + .map(EnvDetectorItem::getResult); + } + + public List getItems() { + + return itemMap.values().stream() + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + + public Map> getItemMap() { + + return this.itemMap; + } + + } + + private class EnvDetectorItem { + + private DetectorType type; + + private DetectorResult result; + + public EnvDetectorItem(DetectorType detectorType) { + this.type = detectorType; + } + + public DetectorType getType() { + return type; + } + + public String getKind() { + return this.type.getKind().getDescription(); + } + + public String getDescription() { + return this.type.getDescription(); + } + + public DetectorResult getResult() { + return result; + } + + public void setResult(DetectorResult result) { + this.result = result; + } + } + + /** + * 按钮的当前状态 + */ + private enum EnvDetectorButtonStatus { + + /** + * 开始 -> 停止 + */ + START("Fine-Design_Basic_Detect_Start") { + @Override + public EnvDetectorButtonStatus next() { + return STOP; + } + }, + + /** + * 停止 -> 继续 + */ + STOP("Fine-Design_Basic_Detect_Stop") { + @Override + public EnvDetectorButtonStatus next() { + return CONTINUE; + } + }, + + /** + * 继续 -> 停止 + */ + CONTINUE("Fine-Design_Basic_Detect_Continue") { + @Override + public EnvDetectorButtonStatus next() { + return STOP; + } + }, + + /** + * 重新 -> 停止 + */ + A_NEW("Fine-Design_Basic_Detect_A_New") { + @Override + public EnvDetectorButtonStatus next() { + return STOP; + } + } + + ; + + private String descLocale; + + EnvDetectorButtonStatus(String descLocale) { + + this.descLocale = descLocale; + } + + public String getDesc() { + + return Toolkit.i18nText(descLocale); + } + + /** + * 在执行中 + * + * @return 是/否 + */ + public boolean isExecuting() { + + return this == EnvDetectorButtonStatus.STOP; + }; + + /** + * 不在执行中 + * + * @return 是/否 + */ + public boolean isNotExecuting() { + + return !isExecuting(); + } + + public abstract EnvDetectorButtonStatus next(); + } +}