提交 4015b3c8 authored 作者: 孙洁清's avatar 孙洁清

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

......@@ -16,6 +16,15 @@ public interface TechnologyDao extends JpaRepository<Technology,String> {
Technology findAllByTechnologyNameEquals(String name);
List<Technology> findAllByTechnologyNameLike(String name);
/**
* 根据id查询
* @param ids ids
* @return
*/
List<Technology> findAllByIdIn(List<String> ids);
@Query("select technologyName from Technology ")
List<String> getTechnologyNames();
}
......@@ -25,6 +25,7 @@ public class PomDependency implements Serializable {
/**
* 1:支持
* 2:不支持
* 3:未知
*/
private Integer support;
}
......@@ -43,7 +43,7 @@ public class ReportVo {
* 2:重构
*/
@Column(length = 5)
private Integer recastMethod;
private String recastMethod;
/**
* 源代码地址
......
......@@ -41,8 +41,9 @@ public class Technology {
/**
* 1:支持
* 2:不支持
* 3:未知
*/
private Integer support = 1;
private Integer support;
/**
* 技术类型
......
......@@ -134,8 +134,6 @@ public class task implements CommandLineRunner {
coefficientMode7.setMediumCoefficient(0D);
coefficientMode7.setTopCoefficient(0D);
coefficientModels.add(coefficientMode6);
coefficientModels.add(coefficientMode5);
coefficientModels.add(coefficientMode4);
......@@ -156,10 +154,18 @@ public class task implements CommandLineRunner {
Technology technology1 = new Technology();
technology1.setTechnologyName("非国产化依赖");
technology1.setSupport(2);
technology1.setAdvice("国产化不支持的依赖");
technology1.setFund(5);
technology1.setId(UUIDUtil.getUUID());
Technology technology2 = new Technology();
technology2.setTechnologyName("未知依赖");
technology2.setSupport(3);
technology2.setAdvice("未知的依赖");
technology2.setFund(5);
technology2.setId(UUIDUtil.getUUID());
Rule rule = new Rule();
rule.setId(UUIDUtil.getUUID());
rule.setSuffix("*");
......@@ -172,9 +178,18 @@ public class task implements CommandLineRunner {
rule1.setTarget("mysql-connect");
rule1.setTechnologyId(technology1.getId());
Rule rule2 = new Rule();
rule2.setId(UUIDUtil.getUUID());
rule2.setSuffix("*");
rule2.setTarget("mysql-connect");
rule2.setTechnologyId(technology2.getId());
technologyDao.save(technology);
technologyDao.save(technology1);
technologyDao.save(technology2);
ruleDao.save(rule);
ruleDao.save(rule1);
ruleDao.save(rule2);
}
}
......@@ -62,6 +62,11 @@ public class Inspector {
* 不支持的国产化技术
*/
Technology techNotCnSupport;
/**
* 未知依赖
*/
Technology techUnKnowSupport;
/**
* 计算预算的参数对象
*/
......@@ -95,11 +100,14 @@ public class Inspector {
* 配置文件后缀
* xml:list【路径】
*/
private Map<String, List<Path>> configFileTypePathsMapping = new HashMap<>();
private Map<String, List<Path>> ruleSuffixMap = new HashMap<>();
private Map<String, List<Rule>> ruleSuffixList = new HashMap<>();
private Map<String, Technology> technologyHashMap = new HashMap<>();
/**
* 统计各后缀文件路径与出现次数,顺便解析jar与js文件
* FileVisitResult.CONTINUE 继续遍历
......@@ -113,6 +121,7 @@ public class Inspector {
//查询技术,构造支持与非支持技术对象
techJavaSupport = technologyDao.findAllByTechnologyNameEquals("Java依赖");
techNotCnSupport = technologyDao.findAllByTechnologyNameEquals("非国产化依赖");
techUnKnowSupport = technologyDao.findAllByTechnologyNameEquals("未知依赖");
//统计项目组成文件构成
for (String languageName : suffixLanguageMapping.keySet()) {
//配置如:java,0
......@@ -128,13 +137,16 @@ public class Inspector {
//查询所有规则
this.ruleList = ruleDao.findAll();
Set<String> id = ruleList.stream().map(Rule::getTechnologyId).collect(Collectors.toSet());
List<Technology> technologies = technologyDao.findAllByIdIn(new ArrayList<>(id));
for (Technology technology : technologies) {
technologyHashMap.put(technology.getId(), technology);
}
for (Rule rule : ruleList) {
if (!ruleSuffixMap.containsKey(rule.getSuffix())) {
//用于存储各种后缀的文件集合
ruleSuffixMap.put(rule.getSuffix(), new ArrayList<>());
//将每个后缀的规则分类
//key:规则后缀
//value:规则集合
......@@ -227,9 +239,7 @@ public class Inspector {
//为普通用户上传,依赖需要检查是否支持。
int i = valiWarn(ruleList, file, split[0], 0);
//如果值为0则代表是有不支持技术到匹配
if (i == 0) {
pomDependency.setSupport(2);
}
pomDependency.setSupport(i);
}
dependencyVo.add(projectPom);
}
......@@ -275,9 +285,9 @@ public class Inspector {
report.setFramework(languageMatchMap.get("jsp").i > 0 ? "混合型架构" : "分离型架构");
//设置是否需要重构
if (languageMatchMap.get("jsp").i == 0 & languageMatchMap.get("java").i == 0) {
report.setRecastMethod(2);
report.setRecastMethod("建议重构");
} else {
report.setRecastMethod(1);
report.setRecastMethod("建议适配");
}
//解析配置文件集合
for (Map.Entry<String, List<Path>> entry : configFileTypePathsMapping.entrySet()) {
......@@ -331,13 +341,16 @@ public class Inspector {
if (path1.toAbsolutePath().toString().endsWith("jar") || path1.toAbsolutePath().toString().endsWith("class")) {
continue;
}
if (path1.toAbsolutePath().toString().endsWith("xml")) {
System.out.println("d");
}
//将文件的每一行都与规则匹配
List<String> strings = Files.readAllLines(path1);
for (int i = 0; i < strings.size(); i++) {
valiWarn(rules, path1, strings.get(i), i + 1);
}
} catch (IOException e) {
log.error("解析{}出错,异常信息为{}",path1.toAbsolutePath().toString(),e.getMessage());
log.error("解析{}出错,异常信息为{}", path1.toAbsolutePath().toString(), e.getMessage());
}
}
}
......@@ -416,9 +429,7 @@ public class Inspector {
dependency.setSupport(1);
} else {
int i = valiWarn(ruleList, path, stringBuilder.toString(), 0);
if (i == 0) {
dependency.setSupport(2);
}
dependency.setSupport(i);
}
stringBuilder.delete(0, stringBuilder.length());
}
......@@ -434,11 +445,11 @@ public class Inspector {
* @return 1:正常、2:不支持依赖
*/
public int valiWarn(List<Rule> rules, Path path, String data, int num) {
//a为1代表当前依赖没有问题
int a = 1;
//默认未知依赖
int a = 3;
for (Rule rule : rules) {
//规则目标字符串为null 或者 空时
if (rule.getTarget()==null || rule.getTarget().isEmpty()) {
if (rule.getTarget() == null || rule.getTarget().isEmpty()) {
continue;
}
//匹配字符串
......@@ -446,17 +457,20 @@ public class Inspector {
//当index>0时代表data中有当前规则
if (index > 0) {
//判断当前规则是否是不支持规则
if (rule.getTechnologyId().equals(techNotCnSupport.getId())) {
//如果是不支持规则则需要保存匹配信息
Warn warn = new Warn();
warn.setFilePath(path.toAbsolutePath().toString());
warn.setLineNum(num);
warn.setTechnologyId(rule.getTechnologyId());
warn.setRuleId(rule.getId());
warn.setRule(rule.getTarget());
Warn warn = new Warn();
//如果是不支持规则则需要保存匹配信息
warn.setFilePath(path.toAbsolutePath().toString());
warn.setLineNum(num);
warn.setRuleId(rule.getId());
warn.setRule(rule.getTarget());
warn.setTechnologyId(rule.getTechnologyId());
if (technologyHashMap.get(rule.getTechnologyId()).getSupport() == 2) {
warns.add(warn);
//设置a=0代表当前依赖有问题
a = 0;
a = 2;
} else if (technologyHashMap.get(rule.getTechnologyId()).getSupport() == 3) {
warns.add(warn);
a = 3;
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论