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

mcj:新增文件名称匹配,修改kmp匹配bug

上级 321980d7
...@@ -15,6 +15,8 @@ import java.io.IOException; ...@@ -15,6 +15,8 @@ import java.io.IOException;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -193,10 +195,11 @@ public class Inspector { ...@@ -193,10 +195,11 @@ public class Inspector {
//新建一个pom对象 //新建一个pom对象
ProjectPom projectPom = new ProjectPom(); ProjectPom projectPom = new ProjectPom();
//截取jar名称 //截取jar名称
String[] split = file.getFileName().toString().split("\\.");
String patten = RegexUtil.patten(file.getFileName().toString());
//新建一个依赖对象 //新建一个依赖对象
PomDependency pomDependency = new PomDependency(); PomDependency pomDependency = new PomDependency();
pomDependency.setArtifactId(split[0]); pomDependency.setArtifactId(patten);
projectPom.getDependencies().add(pomDependency); projectPom.getDependencies().add(pomDependency);
// TODO: 2020-03-04 界定rule唯一,修改数据,一条数据绑定两种技术 // TODO: 2020-03-04 界定rule唯一,修改数据,一条数据绑定两种技术
//当参数为1时代表上传者管理员,代码可绝对信任,将jar名称当作可支持依赖添加进规则库中 //当参数为1时代表上传者管理员,代码可绝对信任,将jar名称当作可支持依赖添加进规则库中
...@@ -205,22 +208,22 @@ public class Inspector { ...@@ -205,22 +208,22 @@ public class Inspector {
Rule rule = new Rule(); Rule rule = new Rule();
//设置适配技术id //设置适配技术id
rule.setTechnologyId(techJavaSupport.getId()); rule.setTechnologyId(techJavaSupport.getId());
rule.setTarget(split[0]); rule.setTarget(patten);
//设置文件后缀 //设置文件后缀
rule.setSuffix("*"); rule.setSuffix("*");
rule.setId(UUIDUtil.getUUID()); rule.setId(UUIDUtil.getUUID());
rule.setTechnologyName(techJavaSupport.getTechnologyName()); rule.setTechnologyName(techJavaSupport.getTechnologyName());
//做规则查询,不用去数据库查询 //做规则查询,不用去数据库查询
if (!ruleMap.containsKey(split[0] + ":" + rule.getSuffix())) { if (!ruleMap.containsKey(patten + ":" + rule.getSuffix())) {
rules.add(rule); rules.add(rule);
ruleMap.put(split[0] + ":" + rule.getSuffix(), rule); ruleMap.put(patten + ":" + rule.getSuffix(), rule);
} }
//设置当前依赖为可支持 //设置当前依赖为可支持
pomDependency.setSupport(1); pomDependency.setSupport(1);
} else { } else {
//为普通用户上传,依赖需要检查是否支持。 //为普通用户上传,依赖需要检查是否支持。
int i = valiWarn(ruleList, file, split[0], 0); int i = valiWarn(ruleList, file,patten, 0);
//如果值为0则代表是有不支持技术到匹配 //如果值为0则代表是有不支持技术到匹配
pomDependency.setSupport(i); pomDependency.setSupport(i);
} }
...@@ -424,12 +427,12 @@ public class Inspector { ...@@ -424,12 +427,12 @@ public class Inspector {
private HashMap<String, List<Warn>> getWarnMap(HashMap<String, Technology> map) { private HashMap<String, List<Warn>> getWarnMap(HashMap<String, Technology> map) {
HashMap<String, List<Warn>> warnMap = new HashMap<>(); HashMap<String, List<Warn>> warnMap = new HashMap<>();
for (Warn warn : warns) { for (Warn warn : warns) {
if (!warnMap.containsKey(warn.getTechnologyId())) { if (!warnMap.containsKey(map.get(warn.getTechnologyId()).getTechnologyName())) {
ArrayList<Warn> warns1 = new ArrayList<>(); ArrayList<Warn> warns1 = new ArrayList<>();
warns1.add(warn); warns1.add(warn);
warnMap.put(warn.getTechnologyId(), warns1); warnMap.put(map.get(warn.getTechnologyId()).getTechnologyName(), warns1);
} else { } else {
warnMap.get(warn.getTechnologyId()).add(warn); warnMap.get(map.get(warn.getTechnologyId()).getTechnologyName()).add(warn);
} }
} }
return warnMap; return warnMap;
...@@ -511,6 +514,9 @@ public class Inspector { ...@@ -511,6 +514,9 @@ public class Inspector {
} else if (technologyHashMap.get(rule.getTechnologyId()).getSupport() == 3) { } else if (technologyHashMap.get(rule.getTechnologyId()).getSupport() == 3) {
warns.add(warn); warns.add(warn);
supportStatus = 3; supportStatus = 3;
}else if (technologyHashMap.get(rule.getTechnologyId()).getSupport() == 1) {
warns.add(warn);
supportStatus = 1;
} }
} }
} }
...@@ -528,9 +534,4 @@ public class Inspector { ...@@ -528,9 +534,4 @@ public class Inspector {
return i; return i;
} }
} }
public static void main(String[] args) {
int vue = KmpUtil.kmpMatch("vue.js", "vue");
System.out.println(vue);
}
} }
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论