From 945994e032ef138fd802e0f3b2a6ef917a097b8d Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 10 Jun 2022 16:31:28 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-73403=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=91jar?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=BC=B9=E7=AA=97=EF=BC=8C%FR=5FHOME%\lib?= =?UTF-8?q?=E5=92=8C\WEB-INF\lib=E4=B8=8B=E7=9A=84jar=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E6=98=BE=E7=A4=BA=20=E9=80=82=E9=85=8D?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E7=9A=84=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/env/detect/base/DetectorConstants.java | 7 ++++ .../com/fr/env/detect/base/DetectorUtil.java | 42 ++++++++++++++++++- .../fr/env/detect/impl/JarLackDetector.java | 35 +++------------- .../converter/ClassConflictConvertor.java | 20 +++++---- 4 files changed, 67 insertions(+), 37 deletions(-) diff --git a/designer-base/src/main/java/com/fr/env/detect/base/DetectorConstants.java b/designer-base/src/main/java/com/fr/env/detect/base/DetectorConstants.java index be1036f0d..4e4592dcd 100644 --- a/designer-base/src/main/java/com/fr/env/detect/base/DetectorConstants.java +++ b/designer-base/src/main/java/com/fr/env/detect/base/DetectorConstants.java @@ -8,4 +8,11 @@ public class DetectorConstants { public static final String JAR_HELP_LINK = "https://help.fanruan.com/finereport/doc-view-4700.html?source=3"; public static final String FINE_DB_HELP_LINK = "https://help.fanruan.com/finereport/doc-view-4701.html?source=3"; + + public static final String SEPARATOR = "、"; + public static final String BR_TAG = "
"; + + public static final String WEB_LIB_PATH = "%FR_HOME%\\webapps\\webroot\\WEB-INF\\lib:"; + + public static final String FR_HOME_LIB = "%FR_HOME%\\lib:"; } diff --git a/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java b/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java index fdfccf216..fd6c33607 100644 --- a/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java +++ b/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java @@ -1,6 +1,7 @@ package com.fr.env.detect.base; import com.fr.base.function.ThrowableRunnable; +import com.fr.common.util.Collections; import com.fr.design.components.notification.NotificationAction; import com.fr.design.components.notification.NotificationMessage; import com.fr.design.components.notification.NotificationModel; @@ -14,7 +15,7 @@ import com.fr.env.detect.bean.ExceptionTips; import com.fr.env.detect.bean.Message; import com.fr.env.detect.bean.SolutionAction; import com.fr.general.build.BuildInfo; -import com.fr.stable.StringUtils; +import com.fr.third.org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import javax.swing.JComponent; @@ -22,9 +23,15 @@ import java.awt.Desktop; import java.net.URI; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.function.Function; +import static com.fr.env.detect.base.DetectorConstants.BR_TAG; +import static com.fr.env.detect.base.DetectorConstants.FR_HOME_LIB; +import static com.fr.env.detect.base.DetectorConstants.SEPARATOR; +import static com.fr.env.detect.base.DetectorConstants.WEB_LIB_PATH; + /** * created by Harrison on 2022/05/25 **/ @@ -124,4 +131,37 @@ public class DetectorUtil { } return new UILabel(LinkStrUtils.generateHtmlTag(message.get())); } + + /** + * 将 lib 转化成合适的格式 + * %FR_HOME%/lib + * %FR_HOME%/webapps/webroot/WEB-INF/lib + * + * @param libMap jar 路径, key为前缀 + * @return 信息 + */ + public static String concatLibFormatMsg(Map> libMap) { + + String webLibPath = WEB_LIB_PATH; + String homeLibPath = FR_HOME_LIB; + + StringBuilder sb = new StringBuilder(); + + List homeLibs = libMap.get(homeLibPath); + if (!Collections.isEmpty(homeLibs)) { + sb.append(homeLibPath); + sb.append(StringUtils.join(homeLibs, SEPARATOR)); + } + + List webLibs = libMap.get(webLibPath); + if (!Collections.isEmpty(webLibs)) { + if (sb.length() != 0) { + sb.append(BR_TAG); + } + sb.append(webLibPath); + sb.append(StringUtils.join(webLibs, SEPARATOR)); + } + return sb.toString(); + } + } 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 82b906270..322c15d50 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 @@ -27,16 +27,14 @@ import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; +import static com.fr.env.detect.base.DetectorConstants.FR_HOME_LIB; +import static com.fr.env.detect.base.DetectorConstants.WEB_LIB_PATH; + /** * created by Harrison on 2022/05/24 **/ public class JarLackDetector extends AbstractExceptionDetector { - public static final String SEPARATOR = "、"; - public static final String BR_TAG = "
"; - public static final String WEB_LIB_PATH = "%FR_HOME%\\webapps\\webroot\\WEB-INF\\lib:"; - public static final String FR_HOME_LIB = "%FR_HOME%\\lib:"; - public JarLackDetector() { super(DetectorType.LACK_OF_JAR); @@ -115,33 +113,12 @@ public class JarLackDetector extends AbstractExceptionDetector { private Message tipsMessage(List infos) { - String webLibPath = WEB_LIB_PATH; - String homeLibPath = FR_HOME_LIB; - - Map> libMap = groupByPath(infos, homeLibPath, webLibPath); - - StringBuilder sb = new StringBuilder(); - - List homeLibs = libMap.get(homeLibPath); - if (!Collections.isEmpty(homeLibs)) { - sb.append(homeLibPath); - sb.append(StringUtils.join(homeLibs, SEPARATOR)); - } - - List webLibs = libMap.get(webLibPath); - if (!Collections.isEmpty(webLibs)) { - if (sb.length() != 0) { - sb.append(BR_TAG); - } - sb.append(webLibPath); - sb.append(StringUtils.join(webLibs, SEPARATOR)); - } - - String mainContent = sb.toString(); + Map> libMap = groupByPath(infos, FR_HOME_LIB, WEB_LIB_PATH); + String content = DetectorUtil.concatLibFormatMsg(libMap); DetectorType type = this.type(); String header = Toolkit.i18nText(type.getTipsLocale()); - return new Message.Simple(header + mainContent); + return new Message.Simple(header + content); } @NotNull diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java index ab2b16ed9..ef5be1339 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java @@ -2,6 +2,7 @@ package com.fr.env.detect.impl.converter; import com.fr.design.i18n.Toolkit; 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; @@ -9,7 +10,6 @@ import com.fr.env.detect.bean.ExceptionSolution; import com.fr.env.detect.bean.ExceptionTips; import com.fr.env.detect.thowable.ThrowableConverter; import com.fr.stable.resource.ResourceLoader; -import com.fr.third.org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import javax.el.MethodNotFoundException; @@ -83,6 +83,10 @@ public class ClassConflictConvertor implements ThrowableConverter { sign = sign.getCause(); } + Map> libMap = new HashMap<>(); + libMap.put(DetectorConstants.FR_HOME_LIB, new ArrayList<>()); + libMap.put(DetectorConstants.WEB_LIB_PATH, new ArrayList<>()); + Set allPath = new HashSet<>(); for (String className : classNames) { String classFile = convertClass2Path(className); @@ -98,12 +102,14 @@ public class ClassConflictConvertor implements ThrowableConverter { Matcher matcher = JAR_NAME_PATTERN.matcher(url.getFile()); if (matcher.find()) { String jar = matcher.group(); - allPath.add(jar); - } else { - boolean containsClasses = file.contains(CLASSES); - if (containsClasses) { - allPath.add(CLASSES); + List libPath = null; + if (file.contains("WEB-INF")) { + libPath = libMap.get(DetectorConstants.WEB_LIB_PATH); + } else { + libPath = libMap.get(DetectorConstants.FR_HOME_LIB); } + libPath.add(jar); + allPath.add(jar); } } } catch (IOException ignore) { @@ -115,7 +121,7 @@ public class ClassConflictConvertor implements ThrowableConverter { return null; } - String msg = StringUtils.join(allPath, SEPARATOR); + String msg = DetectorUtil.concatLibFormatMsg(libMap); DetectorType type = DetectorType.JAR_CONFLICT; return DetectorResult.exception(type,