提交 c3605dd2 authored 作者: 马晨俊's avatar 马晨俊

mcj:修改返回依赖bug,新增统计字段

上级 590f9989
......@@ -59,8 +59,8 @@ public class ReportVo {
/**
* 适配方式
* 1:适配重构
* 2:代码修改
* 1:修改
* 2:适配
*/
private Integer recastMethod;
......@@ -109,6 +109,8 @@ public class ReportVo {
*/
private Integer fileLine;
private Integer supportSize = 0;
/**
* 评估时间
*/
......
......@@ -53,6 +53,7 @@ public class Inspector {
private DependencyVo dependencyVo = new DependencyVo();
private ArrayList<Rule> rules = new ArrayList<>(512);
private ArrayList<Warn> warns = new ArrayList<>(64);
private ArrayList<Warn> supportWarns = new ArrayList<>(64);
/**
* 添加规则时去重使用
......@@ -146,29 +147,31 @@ public class Inspector {
* 1.解析文件
* 2/记录文件地址
* 3/统计各个规则文件后缀
*
* @return
*/
public ReportVo inspect() {
codeSize=0;
ruleSuffixFilePathMap = new HashMap<>();
ruleSuffixMap = new HashMap<>();
technologyHashMap = new HashMap<>();
warns.clear();
rules.clear();
//查询技术,构造支持与非支持技术对象
//初始化值
initData();
//查询技术,构造支持与非支持技术对象,3个对象
findExistTechnology();
//配置语言 map结构
statisticsLanguage();
//配置 config文件 结构
statisticsConfigFile();
//查询所有规则,第一遍扫描文件需要
this.ruleList = ruleDao.findAll();
//根据后缀名,收集文件进行操作
for (Rule rule : ruleList) {
if (!ruleSuffixFilePathMap.containsKey(rule.getSuffix())) {
ruleSuffixFilePathMap.put(rule.getSuffix(), new ArrayList<>());
}
if(!ruleMap.containsKey(rule.getTarget()+":"+rule.getSuffix())){
ruleMap.put(rule.getTarget()+":"+rule.getSuffix(),rule);
if (!ruleMap.containsKey(rule.getTarget() + ":" + rule.getSuffix())) {
ruleMap.put(rule.getTarget() + ":" + rule.getSuffix(), rule);
}
}
//查询所有技术,第一遍扫描文件需要
List<Technology> technologies = technologyDao.findAll();
for (Technology technology : technologies) {
technologyHashMap.put(technology.getId(), technology);
......@@ -204,6 +207,7 @@ public class Inspector {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
//扫描jar文件时
if (file.getFileName().toString().endsWith(".jar")) {
//新建一个pom对象
ProjectPom projectPom = new ProjectPom();
......@@ -241,11 +245,11 @@ public class Inspector {
}
dependencyVo.add(projectPom);
}
fileNum+=1;
fileNum += 1;
try {
List<String> allLines = Files.readAllLines(file);
fileLine+=allLines.size();
}catch (MalformedInputException e){
fileLine += allLines.size();
} catch (MalformedInputException e) {
return FileVisitResult.CONTINUE;
} catch (IOException e) {
e.printStackTrace();
......@@ -294,6 +298,15 @@ public class Inspector {
return analysis();
}
private void initData() {
codeSize = 0;
ruleSuffixFilePathMap = new HashMap<>();
ruleSuffixMap = new HashMap<>();
technologyHashMap = new HashMap<>();
warns.clear();
rules.clear();
}
/**
* 解析数据
*
......@@ -357,11 +370,14 @@ public class Inspector {
if (path1.toAbsolutePath().toString().endsWith("jar") || path1.toAbsolutePath().toString().endsWith("class")) {
continue;
}
if(path1.getFileName().toString().equals("js")){
System.out.println("d");
}
valiWarn(rules, path1, path1.getFileName().toString(), 0);
//将文件的每一行都与规则匹配
List<String> strings = Files.readAllLines(path1);
for (int i = 0; i < strings.size(); i++) {
valiWarn(rules, path1, strings.get(i), i + 1);
int i1 = valiWarn(rules, path1, strings.get(i), i + 1);
}
} catch (IOException e) {
log.error("解析{}出错,异常信息为{}", path1.toAbsolutePath().toString(), e.getMessage());
......@@ -387,18 +403,23 @@ public class Inspector {
report.setGitAddress(inspectParameter.getGitAddress());
//填充适配技术
report.setTechnologies(allById);
//填充依赖
report.setDependencyVo(dependencyVo);
//数据转换
HashMap<String, List<Warn>> warnMap = getWarnMap();
ruleDao.saveAll(rules);
report.setWarnDetails(warnMap);
fileLine=0;
fileNum=0;
log.info("评估报告关键技术,{}", warnMap);
fileLine = 0;
fileNum = 0;
return report;
}
/**
* 比对源文件数量
*/
private void setReportLanguageAndFrame() {
String most = null;
int mostStatus = 0;
......@@ -459,7 +480,7 @@ public class Inspector {
}
ArrayList<String> keys = new ArrayList<>();
for (String s : ruleSuffixFilePathMap.keySet()) {
if(!ruleSuffixMap.containsKey(s)){
if (!ruleSuffixMap.containsKey(s)) {
keys.add(s);
}
}
......@@ -484,34 +505,43 @@ public class Inspector {
}
}
/**
* 查询三个默认依赖
*/
private void findExistTechnology() {
techJavaSupport = technologyDao.findAllByTechnologyNameEquals("国产化依赖(支持)");
techNotCnSupport = technologyDao.findAllByTechnologyNameEquals("非国产化依赖(不支持)");
techUnKnowSupport = technologyDao.findAllByTechnologyNameEquals("未知依赖(未知)");
}
/**
* 数据转换
*
* @return map key=技术名称 value=匹配点
*/
private HashMap<String, List<Warn>> getWarnMap() {
List<Technology> technologies = technologyDao.findAll();
HashMap<String, Technology> techMap = new HashMap<>();
for (Technology technology : technologies) {
if(!techMap.containsKey(technology.getId())){
techMap.put(technology.getId(),technology);
if (!techMap.containsKey(technology.getId())) {
techMap.put(technology.getId(), technology);
}
}
HashMap<String, List<Warn>> warnMap = new HashMap<>();
warns.addAll(supportWarns);
for (Warn warn : warns) {
if(!warnMap.containsKey(warn.getTechnologyName())){
if (!warnMap.containsKey(warn.getTechnologyName())) {
ArrayList<Warn> warns1 = new ArrayList<>();
warns1.add(warn);
warnMap.put(techMap.get(warn.getTechnologyId()).getTechnologyName(), warns1);
}else{
} else {
warnMap.get(warn.getTechnologyName()).add(warn);
}
}
for (Technology technology : technologies) {
if(!warnMap.containsKey(technology.getTechnologyName())){
if (!warnMap.containsKey(technology.getTechnologyName())) {
ArrayList<Warn> warns1 = new ArrayList<>();
warnMap.put(technology.getTechnologyName(), warns1);
}
......@@ -590,21 +620,24 @@ public class Inspector {
Technology technology = technologyHashMap.get(rule.getTechnologyId());
warn.setTechnologyName(technology.getTechnologyName());
warn.setCategoryId(technology.getCategory_id());
if (technologyHashMap.get(rule.getTechnologyId()).getSupport() == 2) {
if (technologyHashMap.get(rule.getTechnologyId()).getSupport() != 1) {
warns.add(warn);
//设置a=0代表当前依赖有问题
supportStatus = 2;
} 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 = technology.getSupport();
} else{
if(supportWarns.size()!=10){
supportWarns.add(warn);
}
Integer size = report.getSupportSize();
Integer integer = size+1;
report.setSupportSize(integer);
supportStatus = 1;
}
}
}
return supportStatus;
}
public class Counter {
private int i = 0;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论