|
|
|
@ -12,6 +12,7 @@ import com.fr.env.detect.bean.ExceptionSolution;
|
|
|
|
|
import com.fr.env.detect.bean.ExceptionTips; |
|
|
|
|
import com.fr.env.detect.bean.Message; |
|
|
|
|
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.third.guava.collect.Lists; |
|
|
|
@ -22,18 +23,18 @@ import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
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 = "<br/>"; |
|
|
|
|
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); |
|
|
|
@ -42,17 +43,40 @@ public class JarLackDetector extends AbstractExceptionDetector {
|
|
|
|
|
@Override |
|
|
|
|
public DetectorResult detect() { |
|
|
|
|
|
|
|
|
|
// 不支持远程
|
|
|
|
|
List<BuildInfo> lackInfos; |
|
|
|
|
|
|
|
|
|
// 远程
|
|
|
|
|
if (!WorkContext.getCurrent().isLocal()) { |
|
|
|
|
return DetectorResult.normal(type()); |
|
|
|
|
// 检测有哪些 JAR 包, 当前是否缺少对应的 JAR 包
|
|
|
|
|
BuildInfoOperator buildInfoOperator = WorkContext.getCurrent().get(BuildInfoOperator.class); |
|
|
|
|
// 远程情况
|
|
|
|
|
List<BuildInfo> remoteInfos = buildInfoOperator.getBuildInfos(); |
|
|
|
|
// 本地情况
|
|
|
|
|
List<BuildInfo> localInfos = BuildInfoManager.getInstance().getInfos(); |
|
|
|
|
|
|
|
|
|
Set<String> remoteSet = remoteInfos.stream() |
|
|
|
|
.filter(this::isExistInfo) |
|
|
|
|
.map(BuildInfo::getJar) |
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
|
|
Predicate<BuildInfo> remoteNotContains = (e) -> !remoteSet.contains(e.getJar()); |
|
|
|
|
|
|
|
|
|
lackInfos = localInfos.stream() |
|
|
|
|
.filter(this::isExistInfo) |
|
|
|
|
// 不是设计器的 JAR
|
|
|
|
|
.filter((e) -> !DetectorUtil.isDesignerJar(e)) |
|
|
|
|
.filter(remoteNotContains) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// 本地
|
|
|
|
|
// 检测有哪些 JAR 包, 当前是否缺少对应的 JAR 包
|
|
|
|
|
BuildInfoOperator buildInfoOperator = new BuildInfoOperatorImpl(); |
|
|
|
|
List<BuildInfo> buildInfos = buildInfoOperator.getBuildInfos(); |
|
|
|
|
lackInfos = buildInfos.stream() |
|
|
|
|
.filter(this::isLackInfo) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 检测有哪些 JAR 包, 当前是否缺少对应的 JAR 包
|
|
|
|
|
BuildInfoOperator buildInfoOperator = new BuildInfoOperatorImpl(); |
|
|
|
|
List<BuildInfo> buildInfos = buildInfoOperator.getBuildInfos(); |
|
|
|
|
List<BuildInfo> lackInfos = buildInfos.stream() |
|
|
|
|
.filter(this::isLackInfo) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
if (Collections.isEmpty(lackInfos)) { |
|
|
|
|
return DetectorResult.normal(type()); |
|
|
|
@ -77,6 +101,11 @@ public class JarLackDetector extends AbstractExceptionDetector {
|
|
|
|
|
return ExceptionLog.create(Toolkit.i18nText(type().getLogLocale()) + message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isExistInfo(BuildInfo e) { |
|
|
|
|
|
|
|
|
|
return !isLackInfo(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isLackInfo(BuildInfo e) { |
|
|
|
|
|
|
|
|
|
return StringUtils.isEmpty(e.getGroupBuild()); |
|
|
|
@ -84,33 +113,12 @@ public class JarLackDetector extends AbstractExceptionDetector {
|
|
|
|
|
|
|
|
|
|
private Message tipsMessage(List<BuildInfo> infos) { |
|
|
|
|
|
|
|
|
|
String webLibPath = WEB_LIB_PATH; |
|
|
|
|
String homeLibPath = FR_HOME_LIB; |
|
|
|
|
|
|
|
|
|
Map<String, List<String>> libMap = groupByPath(infos, homeLibPath, webLibPath); |
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
List<String> homeLibs = libMap.get(homeLibPath); |
|
|
|
|
if (!Collections.isEmpty(homeLibs)) { |
|
|
|
|
sb.append(homeLibPath); |
|
|
|
|
sb.append(StringUtils.join(homeLibs, SEPARATOR)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<String> 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<String, List<String>> 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 |
|
|
|
|