提交 08df1731 authored 作者: 孙洁清's avatar 孙洁清

Merge branch 'master' of git.yfzx.zjtys.com.cn:912-system/monitor/inspect

......@@ -15,6 +15,8 @@ import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
......@@ -193,10 +195,11 @@ public class Inspector {
//新建一个pom对象
ProjectPom projectPom = new ProjectPom();
//截取jar名称
String[] split = file.getFileName().toString().split("\\.");
String patten = RegexUtil.patten(file.getFileName().toString());
//新建一个依赖对象
PomDependency pomDependency = new PomDependency();
pomDependency.setArtifactId(split[0]);
pomDependency.setArtifactId(patten);
projectPom.getDependencies().add(pomDependency);
// TODO: 2020-03-04 界定rule唯一,修改数据,一条数据绑定两种技术
//当参数为1时代表上传者管理员,代码可绝对信任,将jar名称当作可支持依赖添加进规则库中
......@@ -205,22 +208,22 @@ public class Inspector {
Rule rule = new Rule();
//设置适配技术id
rule.setTechnologyId(techJavaSupport.getId());
rule.setTarget(split[0]);
rule.setTarget(patten);
//设置文件后缀
rule.setSuffix("*");
rule.setId(UUIDUtil.getUUID());
rule.setTechnologyName(techJavaSupport.getTechnologyName());
//做规则查询,不用去数据库查询
if (!ruleMap.containsKey(split[0] + ":" + rule.getSuffix())) {
if (!ruleMap.containsKey(patten + ":" + rule.getSuffix())) {
rules.add(rule);
ruleMap.put(split[0] + ":" + rule.getSuffix(), rule);
ruleMap.put(patten + ":" + rule.getSuffix(), rule);
}
//设置当前依赖为可支持
pomDependency.setSupport(1);
} else {
//为普通用户上传,依赖需要检查是否支持。
int i = valiWarn(ruleList, file, split[0], 0);
int i = valiWarn(ruleList, file,patten, 0);
//如果值为0则代表是有不支持技术到匹配
pomDependency.setSupport(i);
}
......@@ -306,6 +309,7 @@ public class Inspector {
if (path1.toAbsolutePath().toString().endsWith("jar") || path1.toAbsolutePath().toString().endsWith("class")) {
continue;
}
valiWarn(rules, path1, path1.getFileName().toString(), 0);
//将文件的每一行都与规则匹配
List<String> strings = Files.readAllLines(path1);
for (int i = 0; i < strings.size(); i++) {
......@@ -423,12 +427,12 @@ public class Inspector {
private HashMap<String, List<Warn>> getWarnMap(HashMap<String, Technology> map) {
HashMap<String, List<Warn>> warnMap = new HashMap<>();
for (Warn warn : warns) {
if (!warnMap.containsKey(warn.getTechnologyId())) {
if (!warnMap.containsKey(map.get(warn.getTechnologyId()).getTechnologyName())) {
ArrayList<Warn> warns1 = new ArrayList<>();
warns1.add(warn);
warnMap.put(warn.getTechnologyId(), warns1);
warnMap.put(map.get(warn.getTechnologyId()).getTechnologyName(), warns1);
} else {
warnMap.get(warn.getTechnologyId()).add(warn);
warnMap.get(map.get(warn.getTechnologyId()).getTechnologyName()).add(warn);
}
}
return warnMap;
......@@ -446,15 +450,13 @@ public class Inspector {
rule.setTechnologyId(techJavaSupport.getId());
rule.setTarget(dependency.getGroupId());
rule.setTechnologyName(techJavaSupport.getTechnologyName());
//?
rule.setSuffix("*");
rule.setId(UUIDUtil.getUUID());
Rule rule1 = new Rule();
rule1.setTechnologyId(techJavaSupport.getId());
rule1.setTarget(dependency.getArtifactId());
rule.setTechnologyName(techJavaSupport.getTechnologyName());
//?
rule1.setTechnologyName(techJavaSupport.getTechnologyName());
rule1.setSuffix("*");
rule1.setId(UUIDUtil.getUUID());
......@@ -495,7 +497,7 @@ public class Inspector {
//匹配字符串
int index = KmpUtil.kmpMatch(data, rule.getTarget());
//当index>0时代表data中有当前规则
if (index > 0) {
if (index > -1) {
//判断当前规则是否是不支持规则
Warn warn = new Warn();
//如果是不支持规则则需要保存匹配信息
......@@ -512,6 +514,9 @@ public class Inspector {
} else if (technologyHashMap.get(rule.getTechnologyId()).getSupport() == 3) {
warns.add(warn);
supportStatus = 3;
}else if (technologyHashMap.get(rule.getTechnologyId()).getSupport() == 1) {
warns.add(warn);
supportStatus = 1;
}
}
}
......
package com.zjty.inspect.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Mcj
* @date 2020-03-04 23:39
*/
public class RegexUtil {
private static Pattern pattern = Pattern.compile("-[0-9]");
public static String patten(String string){
Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
int i = string.indexOf(matcher.group());
String substring = string.substring(0, i);
return substring;
}
return "";
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论