提交 45501895 authored 作者: wyl's avatar wyl

Merge branch 'master' of 192.168.1.249:ty_wyl/adaptation-master1 into wyl

# Conflicts: # src/main/java/com/zjty/adaptationmaster/utils/AnalysisPom.java
package com.zjty.adaptationmaster; package com.zjty.adaptationmaster;
import com.zjty.adaptationmaster.base.enums.Const;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
......
package com.zjty.adaptationmaster.adaptor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
/**
* @author Mcj
* @date 2020-01-15 13:18
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VueBrowserslist {
List<String> production = new ArrayList<>();
List<String> development = new ArrayList<>();
}
...@@ -22,8 +22,10 @@ public class Report { ...@@ -22,8 +22,10 @@ public class Report {
private DatabaseType databaseType;//数据库类型 private DatabaseType databaseType;//数据库类型
private int fileNum; private int fileNum;
private long lineNum; private long lineNum;
//取名,后端依赖
private List<PomDependency> dependencies; private List<PomDependency> dependencies;
//取名。前端依赖
private List<PomDependency> dependencies1;
@Transient @Transient
private ProjectPom projectPom; private ProjectPom projectPom;
......
package com.zjty.adaptationmaster.adaptor.entity;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.zjty.adaptationmaster.adaptor.VueBrowserslist;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Mcj
* @date 2020-01-15 11:18
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VueDep {
String name;
String version;
@JsonSetter("private")
String vuePrivate;
Map<String,String> dependencies = new HashMap<>();
Map<String,String> scripts = new HashMap<>();
Map<String,String> eslintConfig = new HashMap<>();
VueBrowserslist browserslist;
}
...@@ -21,6 +21,12 @@ public class PomDependency { ...@@ -21,6 +21,12 @@ public class PomDependency {
private String version; private String version;
private Integer reportId; private Integer reportId;
/**
* 1:前端依赖
* 2:后端依赖
*/
// TODO: 2020-01-15 取名
private Integer q;
/*依赖类型,默认类型是jar。它通常表示依赖的文件的扩展名,但也有例外。一个类型可以被映射成另外一个扩展 /*依赖类型,默认类型是jar。它通常表示依赖的文件的扩展名,但也有例外。一个类型可以被映射成另外一个扩展
名或分类器。类型经常和使用的打包方式对应,尽管这也有例外。一些类型的例子:jar,war,ejb-client和test-jar。 名或分类器。类型经常和使用的打包方式对应,尽管这也有例外。一些类型的例子:jar,war,ejb-client和test-jar。
如果设置extensions为 true,就可以在plugin里定义新的类型。所以前面的类型的例子不完整 如果设置extensions为 true,就可以在plugin里定义新的类型。所以前面的类型的例子不完整
......
...@@ -48,11 +48,16 @@ public class AdaptationServiceImpl implements AdaptationService { ...@@ -48,11 +48,16 @@ public class AdaptationServiceImpl implements AdaptationService {
// project.setDependenceManagement(Report.DependenceManagement.MAVEN); // project.setDependenceManagement(Report.DependenceManagement.MAVEN);
//Project project = projectDao.getOne(projectId); //Project project = projectDao.getOne(projectId);
try { try {
if(project.getReport()==null)return ServerResponse.error("请进行项目体检或完善项目信息"); if(project.getReport()==null) {
return ServerResponse.error("请进行项目体检或完善项目信息");
}
switch (project.getReport().getDependenceManagement()) { switch (project.getReport().getDependenceManagement()) {
case MAVEN: case MAVEN:
new MavenCompiler(project, Const.MAVENHOME, uuid).compiler(); new MavenCompiler(project, Const.MAVENHOME, uuid).compiler();
break;
default:
} }
Project one = projectDao.getOne(project.getId()); Project one = projectDao.getOne(project.getId());
one.setStage(2); one.setStage(2);
......
...@@ -45,7 +45,7 @@ public class AssemblyServiceImpl implements AssemblyService{ ...@@ -45,7 +45,7 @@ public class AssemblyServiceImpl implements AssemblyService{
} }
@Override @Override
@Transactional @Transactional(rollbackFor = Exception.class)
public ServerResponse deleteAssembly(Integer id) { public ServerResponse deleteAssembly(Integer id) {
Assembly assembly = assemblyDao.getOne(id); Assembly assembly = assemblyDao.getOne(id);
assembly.setStatus(0); assembly.setStatus(0);
......
...@@ -76,7 +76,7 @@ public class DBMigrateServiceImpl implements DBMigrateService { ...@@ -76,7 +76,7 @@ public class DBMigrateServiceImpl implements DBMigrateService {
//根据传入的生成数据库类型,查找未被删除的配置文件 //根据传入的生成数据库类型,查找未被删除的配置文件
DBManage databaseManagement = dbManageDao.findDBManageByIdAndStatus(databaseResponse.getId(),1); DBManage databaseManagement = dbManageDao.findDBManageByIdAndStatus(databaseResponse.getId(),1);
//源数据库:mysql数据库 目标数据库:highgo //源数据库:mysql数据库 目标数据库:highgo
if(databaseResponse.getCreateType().equals(DBName.highgoName) && databaseResponse.getSourceType().equals("mysql")){ if(databaseResponse.getCreateType().equals(DBName.highgoName) && "mysql".equals(databaseResponse.getSourceType())){
//生成数据库的名称 //生成数据库的名称
//连接系统数据库,建立新数据库 //连接系统数据库,建立新数据库
databaseManagement.setDatabaseName(highgoDBName); databaseManagement.setDatabaseName(highgoDBName);
......
...@@ -34,7 +34,7 @@ public class InspectServiceImpl implements InspectService { ...@@ -34,7 +34,7 @@ public class InspectServiceImpl implements InspectService {
@Transactional @Transactional
@Override @Override
public ServerResponse inspect(Project project,String uuid) { public ServerResponse inspect(Project project,String uuid) {
if(project.getCodeUrl() != null && !project.getCodeUrl().equals("")){ if(project.getCodeUrl() != null && !"".equals(project.getCodeUrl())){
//Project project = projectDao.getOne(projectId); //Project project = projectDao.getOne(projectId);
// 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);
...@@ -97,9 +97,11 @@ public class InspectServiceImpl implements InspectService { ...@@ -97,9 +97,11 @@ public class InspectServiceImpl implements InspectService {
reportEntity.setIsSeparate(report.getIsSeparate()); reportEntity.setIsSeparate(report.getIsSeparate());
reportEntity.setLanguage(report.getLanguage()); reportEntity.setLanguage(report.getLanguage());
reportEntity.setLineNum(report.getLineNum()); reportEntity.setLineNum(report.getLineNum());
reportEntity.setCreateTime(new Date().getTime()); reportEntity.setCreateTime(System.currentTimeMillis());
reportEntity.setPackagePath(report.getPackagePath()); reportEntity.setPackagePath(report.getPackagePath());
List<Inspector.Warn> warnList = report.getWarnList(); List<Inspector.Warn> warnList = report.getWarnList();
String s1 = JSON.toJSONString(warnList); String s1 = JSON.toJSONString(warnList);
reportEntity.setWarnList(s1); reportEntity.setWarnList(s1);
...@@ -110,13 +112,20 @@ public class InspectServiceImpl implements InspectService { ...@@ -110,13 +112,20 @@ public class InspectServiceImpl implements InspectService {
reportEntity.setPackagePath(project.getCodeUrl()); reportEntity.setPackagePath(project.getCodeUrl());
} }
//入库
ReportEntity reportEntitySave = reportDao.save(reportEntity); ReportEntity reportEntitySave = reportDao.save(reportEntity);
Project one = projectDao.getOne(project.getId()); Project one = projectDao.getOne(project.getId());
List<PomDependency> dependencies = report.getDependencies(); List<PomDependency> dependencies = report.getDependencies();
for (PomDependency dependency : dependencies) { for (PomDependency dependency : dependencies) {
dependency.setReportId(reportEntitySave.getId()); dependency.setReportId(reportEntitySave.getId());
} }
//TODO
List<PomDependency> dependencies1 = report.getDependencies1();
for (PomDependency dependency : dependencies1) {
dependency.setReportId(reportEntitySave.getId());
}
pomDependencyDao.saveAll(dependencies); pomDependencyDao.saveAll(dependencies);
pomDependencyDao.saveAll(dependencies1);
one.setReport(reportEntitySave); one.setReport(reportEntitySave);
return ServerResponse.success(reportEntitySave); return ServerResponse.success(reportEntitySave);
}else{ }else{
...@@ -128,10 +137,22 @@ public class InspectServiceImpl implements InspectService { ...@@ -128,10 +137,22 @@ public class InspectServiceImpl implements InspectService {
public ServerResponse 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();
// TODO: 2020-01-15 取名
ArrayList<PomDependency> pomDependencies = new ArrayList<>();
ArrayList<PomDependency> pomDependencies1 = new ArrayList<>();
List<PomDependency> allByReportIdEquals = pomDependencyDao.findAllByReportIdEquals(id); List<PomDependency> allByReportIdEquals = pomDependencyDao.findAllByReportIdEquals(id);
for (PomDependency allByReportIdEqual : allByReportIdEquals) {
if(allByReportIdEqual.getQ()==1){
pomDependencies.add(allByReportIdEqual);
}else{
pomDependencies1.add(allByReportIdEqual);
}
}
report.setId(one.getId()); report.setId(one.getId());
report.setDependencies(allByReportIdEquals); report.setDependencies(pomDependencies1);
report.setDependencies1(pomDependencies);
report.setDatabaseType(one.getDatabaseType()); report.setDatabaseType(one.getDatabaseType());
report.setLanguage(one.getLanguage()); report.setLanguage(one.getLanguage());
report.setPackagePath(one.getPackagePath()); report.setPackagePath(one.getPackagePath());
......
...@@ -50,8 +50,9 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -50,8 +50,9 @@ public class ProjectServiceImpl implements ProjectService {
project.setUpdateTime(new Date()); project.setUpdateTime(new Date());
} }
List<Rule> rules = project.getRules(); List<Rule> rules = project.getRules();
if(rules != null) if(rules != null) {
rules.forEach(rule -> rule.setProject(project)); rules.forEach(rule -> rule.setProject(project));
}
Project save = projectDao.save(project); Project save = projectDao.save(project);
return ServerResponse.success("项目创建成功",filter(save)); return ServerResponse.success("项目创建成功",filter(save));
} }
......
...@@ -44,8 +44,9 @@ public class RuleServiceImpl implements RuleService{ ...@@ -44,8 +44,9 @@ public class RuleServiceImpl implements RuleService{
@Override @Override
public ServerResponse addRuleSet(RuleSet ruleSet) { public ServerResponse addRuleSet(RuleSet ruleSet) {
List<Rule> ruleList = ruleSet.getRuleList(); List<Rule> ruleList = ruleSet.getRuleList();
if (ruleList != null) if (ruleList != null) {
ruleList.forEach(rule -> rule.setRuleSet(ruleSet)); ruleList.forEach(rule -> rule.setRuleSet(ruleSet));
}
RuleSet save = ruleSetDao.save(ruleSet); RuleSet save = ruleSetDao.save(ruleSet);
return ServerResponse.success(filter(save)); return ServerResponse.success(filter(save));
} }
......
...@@ -121,7 +121,9 @@ public class ServerResponse<T> { ...@@ -121,7 +121,9 @@ public class ServerResponse<T> {
public static ServerResponse uploadAndGet( public static ServerResponse uploadAndGet(
@RequestParam("file") Optional<MultipartFile> file, String dirName) { @RequestParam("file") Optional<MultipartFile> file, String dirName) {
// 空指针判断 // 空指针判断
if (!file.isPresent()) return error(NOT_NULL_PARAMETER); if (!file.isPresent()) {
return error(NOT_NULL_PARAMETER);
}
// 上传文件并且获得相应结果 // 上传文件并且获得相应结果
MultipartFile uploadFile = file.get(); MultipartFile uploadFile = file.get();
FileServerResponse fsp = FileServerResponse fsp =
...@@ -148,7 +150,9 @@ public class ServerResponse<T> { ...@@ -148,7 +150,9 @@ public class ServerResponse<T> {
public static ServerResponse deleteAndGet( public static ServerResponse deleteAndGet(
@RequestParam(value = "fileName") Optional<String> fileName, String dirName) { @RequestParam(value = "fileName") Optional<String> fileName, String dirName) {
// 空指针判断 // 空指针判断
if (!fileName.isPresent()) return error(NOT_NULL_PARAMETER); if (!fileName.isPresent()) {
return error(NOT_NULL_PARAMETER);
}
// 发送删除文件的请求,附带文件所在的目录和在服务器中的文件名 // 发送删除文件的请求,附带文件所在的目录和在服务器中的文件名
FileServerResponse fsp = HttpClientUtil.daleteFileToServer(dirName, fileName.get()); FileServerResponse fsp = HttpClientUtil.daleteFileToServer(dirName, fileName.get());
// 根据返回结果的状态码确定相应的返回信息(200返回成功,否则error) // 根据返回结果的状态码确定相应的返回信息(200返回成功,否则error)
......
...@@ -4,7 +4,7 @@ import com.zjty.adaptationmaster.base.enums.Const; ...@@ -4,7 +4,7 @@ import com.zjty.adaptationmaster.base.enums.Const;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import java.io.File; import java.io.File;
...@@ -15,7 +15,7 @@ import java.io.File; ...@@ -15,7 +15,7 @@ import java.io.File;
* @Date : 2018/4/19 13:29 * @Date : 2018/4/19 13:29
*/ */
@Configuration @Configuration
public class MyWebConfig extends WebMvcConfigurerAdapter { public class MyWebConfig extends WebMvcConfigurationSupport/*WebMvcConfigurerAdapter*/ {
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
File file1 =new File(Const.UPLOAD_LOCATION); File file1 =new File(Const.UPLOAD_LOCATION);
......
...@@ -76,7 +76,7 @@ public class Adaptor { ...@@ -76,7 +76,7 @@ public class Adaptor {
System.out.println("检测到匹配规则为空"); System.out.println("检测到匹配规则为空");
return ServerResponse.error("检测到匹配规则为空"); return ServerResponse.error("检测到匹配规则为空");
} }
if(project.getCodeUrl() == null || project.getCodeUrl().equals("")){ if(project.getCodeUrl() == null || "".equals(project.getCodeUrl())){
System.out.println("未上传源代码"); System.out.println("未上传源代码");
return ServerResponse.error("未上传源代码"); return ServerResponse.error("未上传源代码");
} }
...@@ -103,7 +103,9 @@ public class Adaptor { ...@@ -103,7 +103,9 @@ public class Adaptor {
//直接用java正则 //直接用java正则
String s = regular.getMath().replaceAll("\\?", ".").replaceAll("\\*", ".+"); String s = regular.getMath().replaceAll("\\?", ".").replaceAll("\\*", ".+");
if (Pattern.matches(s,file.getFileName().toString())) { if (Pattern.matches(s,file.getFileName().toString())) {
if(thisFileMatched==null)thisFileMatched = new ArrayList<>(); if(thisFileMatched==null) {
thisFileMatched = new ArrayList<>();
}
thisFileMatched.add(regular.getRule()); thisFileMatched.add(regular.getRule());
match = true; match = true;
} }
...@@ -118,7 +120,9 @@ public class Adaptor { ...@@ -118,7 +120,9 @@ public class Adaptor {
//原先文件的新地址 //原先文件的新地址
Path originalPath = Paths.get(basePath +storePath); Path originalPath = Paths.get(basePath +storePath);
File parentFile = originalPath.toFile().getParentFile(); File parentFile = originalPath.toFile().getParentFile();
if(!parentFile.exists()||!parentFile.isDirectory())parentFile.mkdirs(); if(!parentFile.exists()||!parentFile.isDirectory()) {
parentFile.mkdirs();
}
OriginalFile originalFile = new OriginalFile(file.toString(),originalPath.toString(),new Date()); OriginalFile originalFile = new OriginalFile(file.toString(),originalPath.toString(),new Date());
originalFiles.add(originalFile); originalFiles.add(originalFile);
//Files.copy(file,originalPath); //Files.copy(file,originalPath);
...@@ -238,7 +242,9 @@ public class Adaptor { ...@@ -238,7 +242,9 @@ public class Adaptor {
} }
public boolean put(String readedFile){ public boolean put(String readedFile){
if(readedFiles==null)readedFiles = new ArrayList<>(); if(readedFiles==null) {
readedFiles = new ArrayList<>();
}
readedFiles.add(new StringBuilder(readedFile)); readedFiles.add(new StringBuilder(readedFile));
count+=readedFile.length(); count+=readedFile.length();
return count > LIMIT; return count > LIMIT;
...@@ -257,7 +263,9 @@ public class Adaptor { ...@@ -257,7 +263,9 @@ public class Adaptor {
} }
public boolean put(ReadedFileTask.ReadedFile readedFile){ public boolean put(ReadedFileTask.ReadedFile readedFile){
if(readedFiles==null)readedFiles = new ArrayList<>(); if(readedFiles==null) {
readedFiles = new ArrayList<>();
}
readedFiles.add(readedFile); readedFiles.add(readedFile);
count+=readedFile.getAttributes().size(); count+=readedFile.getAttributes().size();
return count > LIMIT; return count > LIMIT;
......
package com.zjty.adaptationmaster.utils; package com.zjty.adaptationmaster.utils;
import java.io.File; import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.FileOutputStream; import com.zjty.adaptationmaster.adaptor.entity.VueDep;
import java.io.IOException;
import java.io.InputStream; import java.io.*;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
...@@ -12,10 +12,12 @@ import java.util.zip.ZipFile; ...@@ -12,10 +12,12 @@ import java.util.zip.ZipFile;
public class FileUtil { public class FileUtil {
static int BUFFER_SIZE = 1024; static int BUFFER_SIZE = 1024;
/** /**
* zip解压 * zip解压
* @param srcFile zip源文件 *
* @param destDirPath 解压后的目标文件夹 * @param srcFile zip源文件
* @param destDirPath 解压后的目标文件夹
* @throws RuntimeException 解压失败会抛出运行时异常 * @throws RuntimeException 解压失败会抛出运行时异常
*/ */
public static void unZip(File srcFile, String destDirPath) throws RuntimeException { public static void unZip(File srcFile, String destDirPath) throws RuntimeException {
...@@ -41,7 +43,7 @@ public class FileUtil { ...@@ -41,7 +43,7 @@ public class FileUtil {
// 如果是文件,就先创建一个文件,然后用io流把内容copy过去 // 如果是文件,就先创建一个文件,然后用io流把内容copy过去
File targetFile = new File(destDirPath + "/" + entry.getName()); File targetFile = new File(destDirPath + "/" + entry.getName());
// 保证这个文件的父文件夹必须要存在 // 保证这个文件的父文件夹必须要存在
if(!targetFile.getParentFile().exists()){ if (!targetFile.getParentFile().exists()) {
targetFile.getParentFile().mkdirs(); targetFile.getParentFile().mkdirs();
} }
targetFile.createNewFile(); targetFile.createNewFile();
...@@ -59,11 +61,11 @@ public class FileUtil { ...@@ -59,11 +61,11 @@ public class FileUtil {
} }
} }
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
System.out.println("解压完成,耗时:" + (end - start) +" ms"); System.out.println("解压完成,耗时:" + (end - start) + " ms");
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("unzip error from ZipUtils", e); throw new RuntimeException("unzip error from ZipUtils", e);
} finally { } finally {
if(zipFile != null){ if (zipFile != null) {
try { try {
zipFile.close(); zipFile.close();
} catch (IOException e) { } catch (IOException e) {
...@@ -72,24 +74,25 @@ public class FileUtil { ...@@ -72,24 +74,25 @@ public class FileUtil {
} }
} }
} }
private static void recursiveFiles(String path){
private static void recursiveFiles(String path) {
// 创建 File对象 // 创建 File对象
File file = new File(path); File file = new File(path);
// 取 文件/文件夹 // 取 文件/文件夹
File files[] = file.listFiles(); File files[] = file.listFiles();
// 对象为空 直接返回 // 对象为空 直接返回
if(files == null){ if (files == null) {
return; return;
} }
// 存在文件 遍历 判断 // 存在文件 遍历 判断
for (File f : files) { for (File f : files) {
// 判断是否为 文件夹 // 判断是否为 文件夹
if(f.isDirectory()){ if (f.isDirectory()) {
// 为 文件夹继续遍历 // 为 文件夹继续遍历
recursiveFiles(f.getAbsolutePath()); recursiveFiles(f.getAbsolutePath());
// 判断是否为 文件 // 判断是否为 文件
} else if(f.isFile()){ } else if (f.isFile()) {
if("pom.xml".equals(f.getName())){ if ("pom.xml".equals(f.getName())) {
System.out.println("解析pom"); System.out.println("解析pom");
} }
System.out.println(f.getName()); System.out.println(f.getName());
...@@ -99,14 +102,26 @@ public class FileUtil { ...@@ -99,14 +102,26 @@ public class FileUtil {
} }
} }
} }
public static void main(String[] args) {
String filePath = "C:\\Users\\wyl\\Desktop\\alllib.zip"; static VueDep parseJsonFile(String path) {
String path = "C:\\Users\\wyl\\Desktop\\unZip";
try { try {
unZip(new File(filePath),path); File file = new File(path);
VueDep vueDep;
vueDep = new ObjectMapper().readValue(file,VueDep.class);
return vueDep;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); return null;
} }
} }
public static void main(String[] args) throws IOException {
File file = new File("/Users/mcj/Downloads/package.json");
VueDep vueDep = new ObjectMapper().readValue(file, VueDep.class);
System.out.println(vueDep);
}
} }
...@@ -4,6 +4,7 @@ import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer; ...@@ -4,6 +4,7 @@ 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.VueDep;
import com.zjty.adaptationmaster.adaptor.entity.pomEntity.ProjectPom; import com.zjty.adaptationmaster.adaptor.entity.pomEntity.ProjectPom;
import com.zjty.adaptationmaster.adaptor.entity.pomEntity.SecondFloor.PomDependency; import com.zjty.adaptationmaster.adaptor.entity.pomEntity.SecondFloor.PomDependency;
import com.zjty.adaptationmaster.base.enums.Const; import com.zjty.adaptationmaster.base.enums.Const;
...@@ -123,6 +124,15 @@ public class Inspector { ...@@ -123,6 +124,15 @@ public class Inspector {
writer.write("文件数量:"+report.getFileNum()+"\t"); writer.write("文件数量:"+report.getFileNum()+"\t");
writer.write("代码行数:"+report.getLineNum()+"\n\n"); writer.write("代码行数:"+report.getLineNum()+"\n\n");
writer.write("后端依赖列表:\n");
for(PomDependency dependency:report.getDependencies()){
writer.write(""+dependency.getGroupId()+"\t"+dependency.getArtifactId()+"\t"+dependency.getVersion()+"\n");
}
writer.write("\n前端依赖列表:\n");
for(PomDependency dependency:report.getDependencies1()){
writer.write(""+dependency.getGroupId()+"\t"+dependency.getArtifactId()+"\t"+dependency.getVersion()+"\n");
}
int j = 1; int j = 1;
for(Warn warn:report.getWarnList()){ for(Warn warn:report.getWarnList()){
writer.write(j+++"、所在文件:"+warn.getPath()+" 行数:"+warn.getLine()+"行 关键字:"+warn.getKeyWord()+"\n" writer.write(j+++"、所在文件:"+warn.getPath()+" 行数:"+warn.getLine()+"行 关键字:"+warn.getKeyWord()+"\n"
...@@ -147,6 +157,9 @@ public class Inspector { ...@@ -147,6 +157,9 @@ public class Inspector {
private Map<String,List<Path>> configFileTypePathsMapping; private Map<String,List<Path>> configFileTypePathsMapping;
private List<Warn> warnList; private List<Warn> warnList;
private List<PomDependency> jarFiles;
private List<PomDependency> jsFiles;
public Inspector(Project project,Map<String,Report.Language> suffixLanguageMapping,List<Rule> ruleList,String uuid){ public Inspector(Project project,Map<String,Report.Language> suffixLanguageMapping,List<Rule> ruleList,String uuid){
this.uuid = uuid; this.uuid = uuid;
this.project = project; this.project = project;
...@@ -168,6 +181,8 @@ public class Inspector { ...@@ -168,6 +181,8 @@ public class Inspector {
configFileTypePathsMapping.put("xml",new ArrayList<>()); configFileTypePathsMapping.put("xml",new ArrayList<>());
configFileTypePathsMapping.put("properties",new ArrayList<>()); configFileTypePathsMapping.put("properties",new ArrayList<>());
configFileTypePathsMapping.put("yml",new ArrayList<>()); configFileTypePathsMapping.put("yml",new ArrayList<>());
this.jarFiles = new ArrayList<>();
this.jsFiles = new ArrayList<>();
this.report = new Report(); this.report = new Report();
this.warnList = new ArrayList<>(); this.warnList = new ArrayList<>();
} }
...@@ -224,6 +239,32 @@ public class Inspector { ...@@ -224,6 +239,32 @@ public class Inspector {
configFileTypePathsMapping.get(entry.getValue()).add(file); configFileTypePathsMapping.get(entry.getValue()).add(file);
} }
} }
if(file.toString().endsWith(".jar")){
PomDependency pomDependency = new PomDependency();
String fileName = file.getFileName().toString();
String substring = fileName.substring(0, fileName.indexOf("."));
int i = substring.lastIndexOf("-");
if(i>-1){
pomDependency.setArtifactId(substring.substring(0,i));
pomDependency.setVersion(substring.substring(i));
}else {
pomDependency.setArtifactId(substring);
}
jarFiles.add(pomDependency);
}
if(file.toString().endsWith(".js")){
PomDependency pomDependency = new PomDependency();
String fileName = file.getFileName().toString();
int i = fileName.lastIndexOf(".");
int i1 = fileName.indexOf("-");
if(i1>-1){
pomDependency.setArtifactId(fileName.substring(0,i1));
pomDependency.setVersion(fileName.substring(i1+1,i));
}else {
pomDependency.setArtifactId(fileName.substring(0,fileName.indexOf(".")));
}
jsFiles.add(pomDependency);
}
List<String> allLines; List<String> allLines;
try { try {
...@@ -286,12 +327,20 @@ public class Inspector { ...@@ -286,12 +327,20 @@ public class Inspector {
// } // }
} }
report.setLanguage(most==null? Report.Language.UNKNOW:most); report.setLanguage(most==null? Report.Language.UNKNOW:most);
report.setDependencies(jarFiles);
report.setDependencies1(jsFiles);
/** /**
* 对于具体的配置文件对应的处理方法 * 对于具体的配置文件对应的处理方法
* 增加要处理的文件类型需要在这里增加相应的处理方法 * 增加要处理的文件类型需要在这里增加相应的处理方法
*/ */
//后端依赖
ArrayList<PomDependency> dependencies1 = new ArrayList<>(); ArrayList<PomDependency> dependencies1 = new ArrayList<>();
//前端依赖
ArrayList<PomDependency> dependencies2 = new ArrayList<>();
boolean havepkgjs = false;
boolean havepmxml = false;
for(Map.Entry<String,List<Path>> entry:configFileTypePathsMapping.entrySet()){ for(Map.Entry<String,List<Path>> entry:configFileTypePathsMapping.entrySet()){
//System.out.println(entry.getKey()); //System.out.println(entry.getKey());
switch (entry.getKey()){ switch (entry.getKey()){
...@@ -306,6 +355,7 @@ public class Inspector { ...@@ -306,6 +355,7 @@ public class Inspector {
* 编译方式打包方式和打好的包的路径 * 编译方式打包方式和打好的包的路径
*/ */
if(path.getFileName().endsWith("pom.xml")){ if(path.getFileName().endsWith("pom.xml")){
havepmxml = true;
report.setDependenceManagement(Report.DependenceManagement.MAVEN); report.setDependenceManagement(Report.DependenceManagement.MAVEN);
report.setCompileFilePath(path.toString()); report.setCompileFilePath(path.toString());
//解析pom文件 //解析pom文件
...@@ -411,8 +461,28 @@ public class Inspector { ...@@ -411,8 +461,28 @@ public class Inspector {
}); });
} }
break; break;
case "json":
for(Path path:entry.getValue()) {
if("package.json".equals(path.getFileName())){
havepkgjs = true;
VueDep json = FileUtil.parseJsonFile(path.toString());
Map<String, String> dependencies = json.getDependencies();
for (String s : dependencies.keySet()) {
PomDependency pomDependency = new PomDependency();
pomDependency.setQ(1);
pomDependency.setArtifactId(s);
pomDependency.setVersion(dependencies.get(s));
pomDependency.setReportId(report.getId());
dependencies2.add(pomDependency);
}
}
}
break;
} }
} }
// for(Path path:propertiesConfigPaths){ // for(Path path:propertiesConfigPaths){
// try { // try {
// for(String s:Files.readAllLines(path)){ // for(String s:Files.readAllLines(path)){
...@@ -463,7 +533,16 @@ public class Inspector { ...@@ -463,7 +533,16 @@ public class Inspector {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
report.setDependencies(dependencies1); if(havepmxml) {
report.setDependencies(dependencies1);
}
if(havepkgjs) {
report.setDependencies1(dependencies2);
}
if(report.getLanguage()== Report.Language.JAVA){
String tips = "该项目采用java语言开发,使用了主流框架,未见生僻插件,适配无明显难点。预计适配工作量较小,适配成功率高";
}
report.setWarnList(warnList); report.setWarnList(warnList);
return report; return report;
} }
......
...@@ -180,7 +180,7 @@ public class Regular { ...@@ -180,7 +180,7 @@ public class Regular {
if(createTableSql.contains(",") && createTableSql.contains(");")){ if(createTableSql.contains(",") && createTableSql.contains(");")){
removeCommas = createTableSql.substring(createTableSql.lastIndexOf(",") + 1,createTableSql.lastIndexOf(");")); removeCommas = createTableSql.substring(createTableSql.lastIndexOf(",") + 1,createTableSql.lastIndexOf(");"));
} }
if(removeCommas.equals("\r\n")){ if("\r\n".equals(removeCommas)){
String startChar = createTableSql.substring(0,createTableSql.lastIndexOf(",")); String startChar = createTableSql.substring(0,createTableSql.lastIndexOf(","));
String endChar = createTableSql.substring(createTableSql.lastIndexOf(",") + 1); String endChar = createTableSql.substring(createTableSql.lastIndexOf(",") + 1);
createTableSql = startChar + endChar; createTableSql = startChar + endChar;
......
...@@ -69,8 +69,9 @@ public class StringCompareUtil { ...@@ -69,8 +69,9 @@ public class StringCompareUtil {
for(int i=j;i>=2;i--){ for(int i=j;i>=2;i--){
N[i-1]=getK(i,pat); N[i-1]=getK(i,pat);
} }
for(int a:N) for(int a:N) {
p(a); p(a);
}
return N; return N;
} }
private static int getK(int j, char[] pat) { private static int getK(int j, char[] pat) {
......
package com.zjty.adaptationmaster;
public class InspectFramework {
public void inspect(){
}
}
package com.zjty.adaptationmaster; package com.zjty.adaptationmaster;
import org.junit.Test;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class YmlConfig { public class YmlConfig {
public static void main(String[] args) { public static void main(String[] args) {
String string = ""; String string = "";
} }
@Test
public void test(){
Yaml yaml = new Yaml();
File file = new File("D:\\project\\adaptation-master\\.gitlab-ci.yml");
try {
Iterable<Object> objects = yaml.loadAll(new FileInputStream(file));
for (Object object:objects){
System.out.println(object.getClass());
System.out.println(object);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public void sout(Object object){
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论