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

mcj:update

上级 2c8edc5c
...@@ -30,33 +30,37 @@ public class InspectController { ...@@ -30,33 +30,37 @@ public class InspectController {
*/ */
@PostMapping("/path") @PostMapping("/path")
public ResponseEntity inspect(@RequestBody InspectParameter inspectParameter, MultipartFile file) throws IOException { public ResponseEntity inspect(@RequestBody InspectParameter inspectParameter, MultipartFile file) throws IOException {
// File file1 = file.getResource().getFile(); File file1 = file.getResource().getFile();
// if(file1.getName().endsWith("zip")){ if(file1.getName().endsWith("zip")){
// FileUtil.unPackZip(file1,"", "./"); FileUtil.unPackZip(file1,"", "./");
// }else{ }else{
// FileUtil.unPackRar(file1, "./"); FileUtil.unPackRar(file1, "./");
// } }
// String[] split = file1.getName().split("\\."); String[] split = file1.getName().split("\\.");
// File file2 = new File("./"+split[0]); File file2 = new File("./"+split[0]);
// String path1 = file2.getPath(); String path1 = file2.getPath();
File file1 = new File("/Users/mcj/IdeaProjects/inspect"); // File file1 = new File("/Users/mcj/IdeaProjects/inspect");
String path1 = file1.getPath(); // String path1 = file1.getPath();
inspectService.inspect(inspectParameter,path1); inspectParameter.setPath(path1);
inspectService.inspect(inspectParameter);
return ResponseEntity.ok(200); return ResponseEntity.ok(200);
} }
/** /**
* git下载代码进行评估 * git下载代码进行评估
* @param path * @param inspectParameter 封装
* @return * @return
*/ */
@PostMapping("/git") @PostMapping("/git")
public ResponseEntity inspect1(@RequestBody InspectParameter inspectParameter,String path){ public ResponseEntity inspect1(@RequestBody InspectParameter inspectParameter){
inspectService.inspect(inspectParameter);
//inspectService.inspect(inspectParameter,path);
System.out.println(path);
return ResponseEntity.ok(200); return ResponseEntity.ok(200);
} }
@PostMapping("/frontend")
public ResponseEntity inspect(MultipartFile file) throws IOException {
return ResponseEntity.ok(200);
}
} }
...@@ -4,7 +4,7 @@ import com.zjty.inspect.entity.InspectParameter; ...@@ -4,7 +4,7 @@ import com.zjty.inspect.entity.InspectParameter;
import com.zjty.inspect.entity.Report; import com.zjty.inspect.entity.Report;
public interface InspectService { public interface InspectService {
Report inspect(InspectParameter inspectParameter,String path); Report inspect(InspectParameter inspectParameter);
void setTechId(String id); void setTechId(String id);
} }
...@@ -39,7 +39,7 @@ public class InspectServiceImpl implements InspectService { ...@@ -39,7 +39,7 @@ public class InspectServiceImpl implements InspectService {
@Transactional @Transactional
@Override @Override
public Report inspect(InspectParameter inspectParameter,String path) { public Report inspect(InspectParameter inspectParameter) {
Map<String, Report.Language> suffixLanguageMapping = new HashMap<>(); Map<String, Report.Language> suffixLanguageMapping = new HashMap<>();
suffixLanguageMapping.put("java", Report.Language.JAVA); suffixLanguageMapping.put("java", Report.Language.JAVA);
suffixLanguageMapping.put("vue", Report.Language.VUE); suffixLanguageMapping.put("vue", Report.Language.VUE);
...@@ -49,18 +49,16 @@ public class InspectServiceImpl implements InspectService { ...@@ -49,18 +49,16 @@ public class InspectServiceImpl implements InspectService {
suffixLanguageMapping.put("html", Report.Language.ONLYVIEW); suffixLanguageMapping.put("html", Report.Language.ONLYVIEW);
suffixLanguageMapping.put("js", Report.Language.JAVASCRIPT); suffixLanguageMapping.put("js", Report.Language.JAVASCRIPT);
suffixLanguageMapping.put("go", Report.Language.GO); suffixLanguageMapping.put("go", Report.Language.GO);
Path path1 = Paths.get(path);
File file = path1.toFile();
Report report1 = new Report(); Report report1 = new Report();
report1.setGitAddress(path); report1.setGitAddress(inspectParameter.getPath());
inspector.setTechId(techId); inspector.setTechId(techId);
inspector.setInspectParameter(inspectParameter); inspector.setInspectParameter(inspectParameter);
inspector.setReport(report1); inspector.setReport(report1);
inspector.setSuffixLanguageMapping(suffixLanguageMapping); inspector.setSuffixLanguageMapping(suffixLanguageMapping);
inspector.setPath(path); inspector.setPath(inspectParameter.getPath());
Report report = inspector.inspect(); Report report = inspector.inspect();
reportDao.save(report); reportDao.save(report);
return null; return report;
} }
@Override @Override
......
package com.zjty.inspect.utils; package com.zjty.inspect.utils;
import com.alibaba.fastjson.JSONObject;
import com.zjty.inspect.dao.RuleDao; import com.zjty.inspect.dao.RuleDao;
import com.zjty.inspect.dao.TechnologyAndReportDao; import com.zjty.inspect.dao.TechnologyAndReportDao;
import com.zjty.inspect.entity.*; import com.zjty.inspect.entity.*;
import com.zjty.inspect.entity.Properties;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -16,7 +10,10 @@ import java.io.IOException; ...@@ -16,7 +10,10 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
@Component @Component
public class AnalysisFile { public class AnalysisFile {
...@@ -63,12 +60,31 @@ public class AnalysisFile { ...@@ -63,12 +60,31 @@ public class AnalysisFile {
try { try {
List<String> strings = Files.readAllLines(path); List<String> strings = Files.readAllLines(path);
String s1 = strings.get(0); String s1 = strings.get(0);
depTree.setDepName(s1);
map.put(0,depTree); map.put(0,depTree);
int now = 0; int now = 0;
depTree.setDepName(s1);
for (int i = 1; i <= strings.size()-1; i++) { for (int i = 1; i <= strings.size()-1; i++) {
DepTree depTree1 = new DepTree(); DepTree depTree1 = new DepTree();
String s = strings.get(i); String s = strings.get(i);
int i1 = s.indexOf("-");
String s2 = s.substring(i1 + 1).replaceAll("\\|", "").replaceAll("\\+", "")
.replaceAll(" ", "")
.replaceAll("\\\\", "");
if(i1==one){
depTree1.setDepName(s2);
depTree.getDepTreeList().add(depTree1);
}else{
if(i1>now){
depTree1.setDepName(s2);
map.get(i1).getDepTreeList().add(depTree1);
}else{
depTree1.setDepName(s2);
map.get(i1).getDepTreeList().add(depTree1);
}
}
for (Rule rule : ruleList) { for (Rule rule : ruleList) {
if(KmpUtil.kmpMatch(s,rule.getTarget())>0){ if(KmpUtil.kmpMatch(s,rule.getTarget())>0){
depTree1.setViolation(1); depTree1.setViolation(1);
...@@ -84,25 +100,10 @@ public class AnalysisFile { ...@@ -84,25 +100,10 @@ public class AnalysisFile {
technologyAndReports.add(technologyAndReport); technologyAndReports.add(technologyAndReport);
} }
} }
int i1 = s.indexOf("-");
if(i1==one){
depTree1.setDepName(s);
depTree.getDepTreeList().add(depTree1);
}else{
if(i1>now){
depTree1.setDepName(s);
map.get(i1).getDepTreeList().add(depTree1);
}else{
depTree1.setDepName(s);
map.get(i1).getDepTreeList().add(depTree1);
}
}
map.put(i1+3,depTree1); map.put(i1+3,depTree1);
now = i1; now = i1;
//将依赖全部放进规则库中 //将依赖全部放进规则库中
String[] split = s.substring(i1+1).replaceAll("\\|","").replaceAll("\\+","") String[] split = s2
.replaceAll(" ","")
.replaceAll("\\\\","")
.split(":"); .split(":");
StringBuilder stringBuffer = new StringBuilder(); StringBuilder stringBuffer = new StringBuilder();
for (int i2 = 0; i2 < 2; i2++) { for (int i2 = 0; i2 < 2; i2++) {
...@@ -146,14 +147,4 @@ public class AnalysisFile { ...@@ -146,14 +147,4 @@ public class AnalysisFile {
public void setMap(HashMap<String,Rule> map){ public void setMap(HashMap<String,Rule> map){
this.ruleMap=map; this.ruleMap=map;
} }
public static void main(String[] args) {
String s = "\\gfdgdfgdfgd";
System.out.println(s.replaceAll(
"\\\\",""));
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(1).append(2).append("fdf");
stringBuilder.delete(0,stringBuilder.length());
System.out.println(stringBuilder.toString());
}
} }
...@@ -2,13 +2,10 @@ package com.zjty.inspect.utils; ...@@ -2,13 +2,10 @@ package com.zjty.inspect.utils;
import com.zjty.inspect.dao.*; import com.zjty.inspect.dao.*;
import com.zjty.inspect.entity.*; import com.zjty.inspect.entity.*;
import io.lettuce.core.dynamic.annotation.Param;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -273,7 +270,7 @@ public class Inspector { ...@@ -273,7 +270,7 @@ public class Inspector {
case "json": case "json":
//前端依赖解析 //前端依赖解析
for (Path path : entry.getValue()) { for (Path path : entry.getValue()) {
if (path.getFileName().endsWith("build.gradle")) { if (path.getFileName().endsWith("package.json")) {
VueDep json = FileUtil.parseJsonFile(path.toString()); VueDep json = FileUtil.parseJsonFile(path.toString());
Map<String, String> dependencies = json.getDependencies(); Map<String, String> dependencies = json.getDependencies();
for (String s : dependencies.keySet()) { for (String s : dependencies.keySet()) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论