提交 0db389c2 authored 作者: wyl's avatar wyl

accessDone

上级 54dcdde4
package com.zjty.adaptationmaster.adaptor.controller; package com.zjty.adaptationmaster.adaptor.controller;
import com.zjty.adaptationmaster.adaptor.entity.AdaptRequest;
import com.zjty.adaptationmaster.adaptor.entity.Project; import com.zjty.adaptationmaster.adaptor.entity.Project;
import com.zjty.adaptationmaster.adaptor.entity.Report;
import com.zjty.adaptationmaster.adaptor.service.InspectService; import com.zjty.adaptationmaster.adaptor.service.InspectService;
import com.zjty.adaptationmaster.base.response.ServerResponse; import com.zjty.adaptationmaster.base.response.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -14,8 +16,8 @@ public class InspectController { ...@@ -14,8 +16,8 @@ public class InspectController {
private InspectService inspectService; private InspectService inspectService;
@PutMapping("/inspect") @PutMapping("/inspect")
public ServerResponse inspect(@RequestBody Project projectId){ public ServerResponse inspect(@RequestBody AdaptRequest adaptRequest){
return inspectService.inspect(projectId); return inspectService.inspect(adaptRequest.getProject(),adaptRequest.getUuid());
} }
@GetMapping("/{id}") @GetMapping("/{id}")
......
...@@ -10,6 +10,7 @@ import lombok.NoArgsConstructor; ...@@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
import javax.persistence.*; import javax.persistence.*;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@Data @Data
...@@ -36,6 +37,7 @@ public class Report { ...@@ -36,6 +37,7 @@ public class Report {
@ElementCollection @ElementCollection
public List<String> jarPath;//依赖文件的地址列表,用于编译,如果不是用版本管理工具 public List<String> jarPath;//依赖文件的地址列表,用于编译,如果不是用版本管理工具
private String packagePath; private String packagePath;
private long createTime;
public enum DependenceManagement{ public enum DependenceManagement{
MAVEN,GRADLE,ANT MAVEN,GRADLE,ANT
......
...@@ -32,7 +32,9 @@ public class ReportEntity { ...@@ -32,7 +32,9 @@ public class ReportEntity {
public Report.DependenceManagement dependenceManagement;//版本管理方式 public Report.DependenceManagement dependenceManagement;//版本管理方式
private String packagePath; private String packagePath;
public String jarPath;//依赖文件的地址列表,用于编译,如果不是用版本管理工具 public String jarPath;//依赖文件的地址列表,用于编译,如果不是用版本管理工具
@Column(columnDefinition = "text")
private String warnList; private String warnList;
private long createTime;
public enum DependenceManagement{ public enum DependenceManagement{
MAVEN,GRADLE,ANT MAVEN,GRADLE,ANT
} }
......
...@@ -4,6 +4,7 @@ import lombok.Data; ...@@ -4,6 +4,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import java.util.List; import java.util.List;
...@@ -13,6 +14,7 @@ import java.util.List; ...@@ -13,6 +14,7 @@ import java.util.List;
public class Dependency { public class Dependency {
@Id @Id
@GeneratedValue
private int id; private int id;
private String groupId; private String groupId;
private String artifactId; private String artifactId;
......
...@@ -17,10 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,10 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service @Service
public class InspectServiceImpl implements InspectService { public class InspectServiceImpl implements InspectService {
...@@ -33,7 +30,7 @@ public class InspectServiceImpl implements InspectService { ...@@ -33,7 +30,7 @@ public class InspectServiceImpl implements InspectService {
@Transactional @Transactional
@Override @Override
public ServerResponse inspect(Project project) { public ServerResponse inspect(Project project,String uuid) {
if(project.getCodeUrl() != null && !project.getCodeUrl().equals("")){ if(project.getCodeUrl() != null && !project.getCodeUrl().equals("")){
//Project project = projectDao.getOne(projectId); //Project project = projectDao.getOne(projectId);
// Map<String, Report.Language> suffixLanguageMapping = new HashMap<>(); // Map<String, Report.Language> suffixLanguageMapping = new HashMap<>();
...@@ -79,11 +76,14 @@ public class InspectServiceImpl implements InspectService { ...@@ -79,11 +76,14 @@ public class InspectServiceImpl implements InspectService {
ruleList.add(new Rule("public native","这里用到了JNI")); ruleList.add(new Rule("public native","这里用到了JNI"));
ruleList.add(new Rule("<packaging>jar</packaging>","建议修改打包方式为war包并排除掉springboot内置的tomcat,以部署到国产化中间件上")); ruleList.add(new Rule("<packaging>jar</packaging>","建议修改打包方式为war包并排除掉springboot内置的tomcat,以部署到国产化中间件上"));
ruleList.add(new Rule("WebOffice","这里用到了weboffice文档展示编辑插件")); ruleList.add(new Rule("WebOffice","这里用到了weboffice文档展示编辑插件"));
ruleList.add(new Rule("webOffice","这里用到了weboffice文档展示编辑插件"));
ruleList.add(new Rule("weboffice","这里用到了weboffice文档展示编辑插件"));
ruleList.add(new Rule("Weboffice","这里用到了weboffice文档展示编辑插件"));
ruleList.add(new Rule("pdfobject.min.js","这里用到了pdf文档展示插件")); ruleList.add(new Rule("pdfobject.min.js","这里用到了pdf文档展示插件"));
ruleList.add(new Rule("pdfobject.js","这里用到了pdf文档展示插件")); ruleList.add(new Rule("pdfobject.js","这里用到了pdf文档展示插件"));
ruleList.add(new Rule(".swf","这里用到了flash流媒体播放插件")); ruleList.add(new Rule(".swf","这里用到了flash流媒体播放插件"));
Report report = new Inspector(project, suffixLanguageMapping, ruleList).inspect(); Report report = new Inspector(project, suffixLanguageMapping, ruleList,uuid).inspect();
ReportEntity reportEntity = new ReportEntity(); ReportEntity reportEntity = new ReportEntity();
reportEntity.setCompileFilePath(report.getCompileFilePath()); reportEntity.setCompileFilePath(report.getCompileFilePath());
...@@ -93,7 +93,8 @@ public class InspectServiceImpl implements InspectService { ...@@ -93,7 +93,8 @@ public class InspectServiceImpl implements InspectService {
reportEntity.setFramework(report.getFramework()); reportEntity.setFramework(report.getFramework());
reportEntity.setIsSeparate(report.getIsSeparate()); reportEntity.setIsSeparate(report.getIsSeparate());
reportEntity.setLanguage(report.getLanguage()); reportEntity.setLanguage(report.getLanguage());
reportEntity.setLineNum(report.getLineNum());
reportEntity.setCreateTime(new Date().getTime());
List<Inspector.Warn> warnList = report.getWarnList(); List<Inspector.Warn> warnList = report.getWarnList();
String s1 = JSON.toJSONString(warnList); String s1 = JSON.toJSONString(warnList);
...@@ -120,7 +121,7 @@ public class InspectServiceImpl implements InspectService { ...@@ -120,7 +121,7 @@ public class InspectServiceImpl implements InspectService {
} }
@Override @Override
public Report getReportById(Integer id) { public ServerResponse getReportById(Integer id) {
ReportEntity one = reportDao.getOne(id); ReportEntity one = reportDao.getOne(id);
Report report = new Report(); Report report = new Report();
...@@ -136,12 +137,13 @@ public class InspectServiceImpl implements InspectService { ...@@ -136,12 +137,13 @@ public class InspectServiceImpl implements InspectService {
report.setLineNum(one.getLineNum()); report.setLineNum(one.getLineNum());
report.setFramework(one.getFramework()); report.setFramework(one.getFramework());
report.setIsSeparate(one.getIsSeparate()); report.setIsSeparate(one.getIsSeparate());
report.setCreateTime(one.getCreateTime());
List<Inspector.Warn> warns = JSON.parseArray(one.getWarnList(), Inspector.Warn.class); List<Inspector.Warn> warns = JSON.parseArray(one.getWarnList(), Inspector.Warn.class);
report.setWarnList(warns); report.setWarnList(warns);
List<String> path = JSON.parseArray(one.getJarPath(), String.class); List<String> path = JSON.parseArray(one.getJarPath(), String.class);
report.setJarPath(path); report.setJarPath(path);
return report; return ServerResponse.success(report);
} }
} }
...@@ -6,7 +6,7 @@ import com.zjty.adaptationmaster.adaptor.entity.ReportEntity; ...@@ -6,7 +6,7 @@ import com.zjty.adaptationmaster.adaptor.entity.ReportEntity;
import com.zjty.adaptationmaster.base.response.ServerResponse; import com.zjty.adaptationmaster.base.response.ServerResponse;
public interface InspectService { public interface InspectService {
ServerResponse inspect(Project projectId); ServerResponse inspect(Project projectId,String uuid);
Report getReportById(Integer id); ServerResponse getReportById(Integer id);
} }
package com.zjty.adaptationmaster.utils; package com.zjty.adaptationmaster.utils;
import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer;
import com.zjty.adaptationmaster.adaptor.entity.Project; import com.zjty.adaptationmaster.adaptor.entity.Project;
import com.zjty.adaptationmaster.adaptor.entity.Report; import com.zjty.adaptationmaster.adaptor.entity.Report;
import com.zjty.adaptationmaster.adaptor.entity.Rule; import com.zjty.adaptationmaster.adaptor.entity.Rule;
import com.zjty.adaptationmaster.adaptor.entity.pomEntity.ProjectPom; import com.zjty.adaptationmaster.adaptor.entity.pomEntity.ProjectPom;
import com.zjty.adaptationmaster.adaptor.entity.pomEntity.SecondFloor.Dependency; import com.zjty.adaptationmaster.adaptor.entity.pomEntity.SecondFloor.Dependency;
import com.zjty.adaptationmaster.base.enums.Const;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -30,6 +32,9 @@ import java.util.*; ...@@ -30,6 +32,9 @@ import java.util.*;
* 生成报告VO * 生成报告VO
* *
*/ */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Inspector { public class Inspector {
public static void main(String[] args) { public static void main(String[] args) {
...@@ -98,6 +103,7 @@ public class Inspector { ...@@ -98,6 +103,7 @@ public class Inspector {
// System.out.println(LocalDateTime.now()); // System.out.println(LocalDateTime.now());
} }
private String uuid;
private Project project; private Project project;
private Report report; private Report report;
private Map<String, Counter> languageMatchMap; private Map<String, Counter> languageMatchMap;
...@@ -108,7 +114,8 @@ public class Inspector { ...@@ -108,7 +114,8 @@ public class Inspector {
private Map<String,List<Path>> configFileTypePathsMapping; private Map<String,List<Path>> configFileTypePathsMapping;
private List<Warn> warnList; private List<Warn> warnList;
public Inspector(Project project,Map<String,Report.Language> suffixLanguageMapping,List<Rule> ruleList){ public Inspector(Project project,Map<String,Report.Language> suffixLanguageMapping,List<Rule> ruleList,String uuid){
this.uuid = uuid;
this.project = project; this.project = project;
this.suffixLanguageMapping = suffixLanguageMapping; this.suffixLanguageMapping = suffixLanguageMapping;
this.ruleList = ruleList; this.ruleList = ruleList;
...@@ -151,7 +158,7 @@ public class Inspector { ...@@ -151,7 +158,7 @@ public class Inspector {
for(String s:configFileTypePathsMapping.keySet()){ for(String s:configFileTypePathsMapping.keySet()){
configFileMatcherSuffixMapping.put(aDefault.getPathMatcher("glob:**/*."+s),s); configFileMatcherSuffixMapping.put(aDefault.getPathMatcher("glob:**/*."+s),s);
} }
WebSocketServer.sendIn(uuid,TimeUtil.getNowDate() + " 项目评估:" + "开始读取项目文件");
Files.walkFileTree(Paths.get(project.getCodeUrl()), new FileVisitor<Path>() { Files.walkFileTree(Paths.get(project.getCodeUrl()), new FileVisitor<Path>() {
/** /**
* 统计某个后缀出现的次数 * 统计某个后缀出现的次数
...@@ -166,6 +173,7 @@ public class Inspector { ...@@ -166,6 +173,7 @@ public class Inspector {
* 这里是对于路径(文件夹)的过滤,在这里读不到文件 * 这里是对于路径(文件夹)的过滤,在这里读不到文件
* 如果能判断,可以返回FileVisitResult.SKIP_SUBTREE 不访问子目录 * 如果能判断,可以返回FileVisitResult.SKIP_SUBTREE 不访问子目录
*/ */
//if(dir.getFileName().startsWith("."))return FileVisitResult.SKIP_SUBTREE;
//if (dir.endsWith(".git"))return FileVisitResult.SKIP_SUBTREE; //if (dir.endsWith(".git"))return FileVisitResult.SKIP_SUBTREE;
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
...@@ -195,7 +203,8 @@ public class Inspector { ...@@ -195,7 +203,8 @@ public class Inspector {
String s = allLines.get(i); String s = allLines.get(i);
for(Rule rule:ruleList){ for(Rule rule:ruleList){
if (s.indexOf(rule.getTarget())>-1){ if (s.indexOf(rule.getTarget())>-1){
warnList.add(new Warn(file,i+1,rule.getTarget(),rule.getReplacing()));
warnList.add(new Warn(file.toString().substring(Const.UPLOAD_LOCATION.length()),i+1,rule.getTarget(),rule.getReplacing()));
} }
} }
} }
...@@ -213,6 +222,7 @@ public class Inspector { ...@@ -213,6 +222,7 @@ public class Inspector {
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
}); });
WebSocketServer.sendIn(uuid,TimeUtil.getNowDate() + " 项目评估:" + "读取项目文件结束");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -220,6 +230,11 @@ public class Inspector { ...@@ -220,6 +230,11 @@ public class Inspector {
} }
public Report analysis(){ public Report analysis(){
try {
WebSocketServer.sendIn(uuid,TimeUtil.getNowDate() + " 项目评估:" + "开始分析项目文件");
} catch (IOException e) {
e.printStackTrace();
}
report.setFileNum(fileNum); report.setFileNum(fileNum);
report.setLineNum(lineNum); report.setLineNum(lineNum);
//report.setLanguage(Report.Language.ONLYVIEW); //report.setLanguage(Report.Language.ONLYVIEW);
...@@ -406,6 +421,13 @@ public class Inspector { ...@@ -406,6 +421,13 @@ public class Inspector {
// e.printStackTrace(); // e.printStackTrace();
// } // }
// } // }
try {
WebSocketServer.sendIn(uuid,TimeUtil.getNowDate() + " 项目评估:" + "分析项目文件完成");
WebSocketServer.sendIn(uuid,TimeUtil.getNowDate() + " 项目评估:" + "正在生成报告");
WebSocketServer.sendIn(uuid,TimeUtil.getNowDate() + " 项目评估:" + "即将下载报告");
} catch (IOException e) {
e.printStackTrace();
}
report.setDependencies(dependencies1); report.setDependencies(dependencies1);
report.setWarnList(warnList); report.setWarnList(warnList);
return report; return report;
...@@ -432,8 +454,8 @@ public class Inspector { ...@@ -432,8 +454,8 @@ public class Inspector {
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class Warn{ public static class Warn{
private Path path; private String path;
private int line; private int line;
private String keyWord; private String keyWord;
private String suggest; private String suggest;
......
...@@ -2,6 +2,7 @@ package com.zjty.adaptationmaster; ...@@ -2,6 +2,7 @@ package com.zjty.adaptationmaster;
import com.zjty.adaptationmaster.adaptor.entity.db.DBManage; import com.zjty.adaptationmaster.adaptor.entity.db.DBManage;
import com.zjty.adaptationmaster.utils.Regular; import com.zjty.adaptationmaster.utils.Regular;
import org.junit.Test;
import org.postgresql.copy.CopyManager; import org.postgresql.copy.CopyManager;
import org.postgresql.core.BaseConnection; import org.postgresql.core.BaseConnection;
...@@ -9,6 +10,8 @@ import java.io.File; ...@@ -9,6 +10,8 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -17,4 +20,13 @@ public class Test4 { ...@@ -17,4 +20,13 @@ public class Test4 {
String s = "\"record_alarm\" bit(1) DEFAULT NULL,"; String s = "\"record_alarm\" bit(1) DEFAULT NULL,";
System.out.println(s.replaceAll("bit(1)","boolean")); System.out.println(s.replaceAll("bit(1)","boolean"));
} }
@Test
public void testSubPath(){
Path path = Paths.get("D:\\project\\adaptation\\apusicLibTest\\src");
System.out.println(path.subpath(0,1));
for(int i = 0;i<10;i++) {
System.out.println(path.subpath(i, 10));
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论