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

合并分支 'wyl' 到 'master'

Wyl 查看合并请求 ty_wyl/adaptation-master1!41
...@@ -144,7 +144,13 @@ ...@@ -144,7 +144,13 @@
<dependency> <dependency>
<groupId>org.apache.ant</groupId> <groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId> <artifactId>ant</artifactId>
<version>1.10.2</version> <version>1.9.7</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -26,6 +26,7 @@ public class Report { ...@@ -26,6 +26,7 @@ public class Report {
@ElementCollection @ElementCollection
public List<String> jarPath;//依赖文件的地址列表,用于编译,如果不是用版本管理工具 public List<String> jarPath;//依赖文件的地址列表,用于编译,如果不是用版本管理工具
private String packagePath; private String packagePath;
private int fileNum;
public enum DependenceManagement{ public enum DependenceManagement{
MAVEN,GRADLE,ANT MAVEN,GRADLE,ANT
......
...@@ -30,9 +30,10 @@ public class Rule { ...@@ -30,9 +30,10 @@ public class Rule {
private Integer status = 1;//状态(0:删除 1:未删除) private Integer status = 1;//状态(0:删除 1:未删除)
private MatchType pathMatchType;//文件匹配方式 路径/文件名/后缀 //private MatchType pathMatchType;//文件匹配方式 路径/文件名/后缀
private String path;//文件路径匹配 private String path;//文件路径匹配
private TextMatch textMatching;//文本匹配方式 全文匹配/正则匹配 //private TextMatch textMatching;//文本匹配方式 全文匹配/正则匹配
//private DealWay dealWay;//替换,在匹配字之前插入,在匹配字之后插入
/** /**
* AREA * AREA
...@@ -41,15 +42,15 @@ public class Rule { ...@@ -41,15 +42,15 @@ public class Rule {
private String target;//文本匹配目标 private String target;//文本匹配目标
private String replacing;//更改方式 全文替换/正则替换 private String replacing;//更改方式 全文替换/正则替换
public enum MatchType{ // public enum MatchType{
PATH,NAME,SUFFIX,GLOB // PATH,NAME,SUFFIX,GLOB
} // }
//
public enum TextMatch{ // public enum TextMatch{
AREA,CONTENT // AREA,CONTENT
} // }
//
public enum DealWay{ // public enum DealWay{
REPLACE,INSERTAFTER,INSERTBEFORE // REPLACE,INSERTAFTER,INSERTBEFORE,InsertBetween
} // }
} }
...@@ -7,10 +7,7 @@ import com.zjty.adaptationmaster.adaptor.repository.ProjectDao; ...@@ -7,10 +7,7 @@ import com.zjty.adaptationmaster.adaptor.repository.ProjectDao;
import com.zjty.adaptationmaster.base.enums.Const; import com.zjty.adaptationmaster.base.enums.Const;
import com.zjty.adaptationmaster.base.response.ServerResponse; import com.zjty.adaptationmaster.base.response.ServerResponse;
import com.zjty.adaptationmaster.adaptor.service.AdaptationService; import com.zjty.adaptationmaster.adaptor.service.AdaptationService;
import com.zjty.adaptationmaster.utils.ApusicDeployer; import com.zjty.adaptationmaster.utils.*;
import com.zjty.adaptationmaster.utils.FileUtil;
import com.zjty.adaptationmaster.utils.FileZip;
import com.zjty.adaptationmaster.utils.MavenCompiler;
import org.springframework.beans.factory.annotation.Autowired; 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;
...@@ -87,7 +84,7 @@ public class AdaptationServiceImpl implements AdaptationService { ...@@ -87,7 +84,7 @@ public class AdaptationServiceImpl implements AdaptationService {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return ServerResponse.success(filter(project1)); return ServerResponse.success(project);
} }
@Override @Override
......
package com.zjty.adaptationmaster.adaptor.service.Impl; //package com.zjty.adaptationmaster.adaptor.service.Impl;
//
import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer; //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.repository.ProjectDao; //import com.zjty.adaptationmaster.adaptor.repository.ProjectDao;
import com.zjty.adaptationmaster.base.response.ServerResponse; //import com.zjty.adaptationmaster.base.response.ServerResponse;
import com.zjty.adaptationmaster.utils.ReadedFileTask; //import com.zjty.adaptationmaster.utils.ReadedFileTask;
import com.zjty.adaptationmaster.adaptor.entity.OriginalFile; //import com.zjty.adaptationmaster.adaptor.entity.OriginalFile;
import com.zjty.adaptationmaster.adaptor.entity.Rule; //import com.zjty.adaptationmaster.adaptor.entity.Rule;
import com.zjty.adaptationmaster.base.enums.Const; //import com.zjty.adaptationmaster.base.enums.Const;
import com.zjty.adaptationmaster.adaptor.repository.OriginalFileDao; //import com.zjty.adaptationmaster.adaptor.repository.OriginalFileDao;
import org.springframework.beans.factory.annotation.Autowired; //import com.zjty.adaptationmaster.utils.WriterBySort;
import org.springframework.stereotype.Component; //import lombok.AllArgsConstructor;
//import lombok.Data;
import java.io.*; //import lombok.NoArgsConstructor;
import java.nio.charset.Charset; //import org.springframework.beans.factory.annotation.Autowired;
import java.nio.charset.StandardCharsets; //import org.springframework.stereotype.Component;
import java.nio.file.*; //
import java.nio.file.attribute.BasicFileAttributes; //import java.io.*;
import java.util.*; //import java.nio.charset.Charset;
import java.util.concurrent.ArrayBlockingQueue; //import java.nio.charset.StandardCharsets;
import java.util.concurrent.ThreadPoolExecutor; //import java.nio.file.*;
import java.util.concurrent.TimeUnit; //import java.nio.file.attribute.BasicFileAttributes;
//import java.util.*;
@Component //import java.util.concurrent.ArrayBlockingQueue;
public class Adaptor { //import java.util.concurrent.ThreadPoolExecutor;
//@Autowired //import java.util.concurrent.TimeUnit;
//private AdaptationDetailLogEntityDao adaptationDetailLogEntityDao; //
@Autowired ////适应四种规则的适配器,改成只适配java正则的,再util下面
private OriginalFileDao originalFileDao; ////@Component
//public class Adaptor {
private ProjectDao projectDao; // //@Autowired
// //private AdaptationDetailLogEntityDao adaptationDetailLogEntityDao;
private String uuid; // @Autowired
//@Value("${base.path}") // private OriginalFileDao originalFileDao;
private String basePath = Const.CONSOLE; //
//线程池数量,合适的线程数量能让程序更快 // private ProjectDao projectDao;
private static final int poolSize = 20; //
//为避免内存溢出,对于超大文件,切分成部分分别读入处理,最后拼接写出 // private String uuid;
private static final long LIMIT = 200*1024*1024; // //@Value("${base.path}")
List<Rule> ruleList; // private String basePath = Const.CONSOLE;
Project project; // //线程池数量,合适的线程数量能让程序更快
//String projectPath; // private static final int poolSize = 20;
//private List<Rule> adaptorEntities = new ArrayList<>(); // //为避免内存溢出,对于超大文件,切分成部分分别读入处理,最后拼接写出
// private static final long LIMIT = 200*1024*1024;
//public void setProjectPath(String projectPath) { // List<Rule> ruleList;
// this.projectPath = projectPath; // Project project;
//} // //String projectPath;
// //private List<Rule> adaptorEntities = new ArrayList<>();
//
public void setProject(Project project) { // //public void setProjectPath(String projectPath) {
this.project = project; // // this.projectPath = projectPath;
} // //}
//
public void setRuleList(List<Rule> ruleList) { //
this.ruleList = ruleList; // public void setProject(Project project) {
} // this.project = project;
// }
public void setUuid(String uuid) { //
this.uuid = uuid; // public void setRuleList(List<Rule> ruleList) {
} // this.ruleList = ruleList;
// }
public ServerResponse doAdapt(){ //
//String regular = preprocesAdaptation(); // public void setUuid(String uuid) {
//List<String> strings1 = preprocessRegular(); // this.uuid = uuid;
Map<String, Rule> strings1 = preprocessRegular(); // }
if(strings1.size()<1){ //
System.out.println("检测到匹配规则为空"); // public ServerResponse doAdapt(){
return ServerResponse.error("检测到匹配规则为空"); // //String regular = preprocesAdaptation();
} // //List<String> strings1 = preprocessRegular();
if(project.getCodeUrl() == null || project.getCodeUrl().equals("")){ // List<MatchAndRule> strings1 = preprocessRegular();
System.out.println("未上传源代码"); // System.out.println(strings1.size()+"规则数量");
return ServerResponse.error("未上传源代码"); //
} // if(strings1.size()<1){
ThreadPoolExecutor pool = new ThreadPoolExecutor(poolSize,poolSize,10, TimeUnit.SECONDS,new ArrayBlockingQueue<>(poolSize*2)); // System.out.println("检测到匹配规则为空");
pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // return ServerResponse.error("检测到匹配规则为空");
List<OriginalFile> originalFiles = new ArrayList<>(); // }
//记录实际具体适配内容 // if(project.getCodeUrl() == null || project.getCodeUrl().equals("")){
//List<AdaptationDetailsLogEntity> detailsLogEntities = new ArrayList<>(); // System.out.println("未上传源代码");
ReadedFileRepository repository = new ReadedFileRepository(); // return ServerResponse.error("未上传源代码");
try { // }
Files.walkFileTree(Paths.get(project.getCodeUrl()),new SimpleFileVisitor<Path>() { // ThreadPoolExecutor pool = new ThreadPoolExecutor(poolSize,poolSize,10, TimeUnit.SECONDS,new ArrayBlockingQueue<>(poolSize*2));
@Override // pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { // List<OriginalFile> originalFiles = new ArrayList<>();
// //记录实际具体适配内容
// String pathString = file.toString(); // //List<AdaptationDetailsLogEntity> detailsLogEntities = new ArrayList<>();
// pathString.indexOf(System.getProperty("file.separator"),basePath.length()); // ReadedFileRepository repository = new ReadedFileRepository();
// String storePathParent ="originalFile/"+ UUID.randomUUID().toString();
boolean match = false; // try {
List<Rule> thisFileMatched = null; // Files.walkFileTree(Paths.get(project.getCodeUrl()),new SimpleFileVisitor<Path>() {
//不符合规则的路径过滤掉 // @Override
for(String regular:strings1.keySet()) { // public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (FileSystems.getDefault().getPathMatcher("glob:"+regular).matches(file)) { //// System.out.println(file);
if(thisFileMatched==null) //// String pathString = file.toString();
thisFileMatched = new ArrayList<>(); //// pathString.indexOf(System.getProperty("file.separator"),basePath.length());
thisFileMatched.add(strings1.get(regular)); //
match = true; // boolean match = false;
} // List<Rule> thisFileMatched = null;
} // //不符合规则的路径过滤掉
String storePath ="originalFile/"+ UUID.randomUUID().toString()+"/"+file.getFileName(); // for(MatchAndRule regular:strings1) {
//原先文件的新地址 // //if (FileSystems.getDefault().getPathMatcher("glob:"+regular.getMath()).matches(file)) {
Path originalPath = Paths.get(basePath +storePath); // //直接用java正则
File parentFile = originalPath.toFile().getParentFile(); // if (FileSystems.getDefault().getPathMatcher(regular.getMath()).matches(file)) {
if(!parentFile.exists()||!parentFile.isDirectory())parentFile.mkdirs(); // if(thisFileMatched==null)thisFileMatched = new ArrayList<>();
if(match) { // thisFileMatched.add(regular.getRule());
OriginalFile originalFile = new OriginalFile(file.toString(),originalPath.toString(),new Date()); // match = true;
originalFiles.add(originalFile); // }
Files.move(file, originalPath); // }
//splitedFile.setDeal(true); //
WebSocketServer.sendInfo(uuid,"过滤得到符合规则的文件" + file,"替换","过滤文件",project.getProjectName()); // if(match) {
//System.out.println(); // //System.out.println("match");
if (attrs.size() > LIMIT) { // String storePath = storePathParent+"/"+UUID.randomUUID().toString()+"/"+file.getFileName();
System.out.println("找到大文件" + file); // //原先文件的新地址
ReadedLinesRepository linesRepository = new ReadedLinesRepository(); // Path originalPath = Paths.get(basePath +storePath);
int i = 0; // File parentFile = originalPath.toFile().getParentFile();
WriterBySort bySort = new WriterBySort(); // if(!parentFile.exists()||!parentFile.isDirectory())parentFile.mkdirs();
File newFile = file.toFile(); // OriginalFile originalFile = new OriginalFile(file.toString(),originalPath.toString(),new Date());
newFile.createNewFile(); // originalFiles.add(originalFile);
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(newFile), StandardCharsets.UTF_8); // //Files.copy(file,originalPath);
bySort.setWriter(writer); // Files.move(file, originalPath);
for (String s : Files.readAllLines(originalPath, Charset.forName("utf-8"))) { // //splitedFile.setDeal(true);
if (linesRepository.put(s)) { // WebSocketServer.sendInfo(uuid,"过滤得到符合规则的文件" + file,"替换","过滤文件",project.getProjectName());
List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>(); // //System.out.println();
readedFiles.add(new ReadedFileTask.ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched)); // if (attrs.size() > LIMIT) {
ReadedFileTask apacheTask = new ReadedFileTask(readedFiles,project.getProjectName(),uuid); // System.out.println("找到大文件" + file);
apacheTask.setBySort(bySort); // ReadedLinesRepository linesRepository = new ReadedLinesRepository();
apacheTask.setIndex(i); // int i = 0;
pool.submit(apacheTask); // WriterBySort bySort = new WriterBySort();
i++; // File newFile = file.toFile();
} // newFile.createNewFile();
} // OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(newFile), StandardCharsets.UTF_8);
List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>(); // bySort.setWriter(writer);
readedFiles.add(new ReadedFileTask.ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched)); // for (String s : Files.readAllLines(originalPath, Charset.forName("utf-8"))) {
ReadedFileTask apacheTask = new ReadedFileTask(readedFiles,project.getProjectName(),uuid); // if (linesRepository.put(s)) {
apacheTask.setBySort(bySort); // List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>();
apacheTask.setIndex(i); // readedFiles.add(new ReadedFileTask.ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched));
pool.submit(apacheTask); // ReadedFileTask apacheTask = new ReadedFileTask(readedFiles,project.getProjectName(),uuid);
i++; // apacheTask.setBySort(bySort);
bySort.setSize(i); // apacheTask.setIndex(i);
}else { // pool.submit(apacheTask);
String s = new String(Files.readAllBytes(originalPath)); // i++;
ReadedFileTask.ReadedFile readedFile = new ReadedFileTask.ReadedFile(s, attrs, file,thisFileMatched); // }
if (repository.put(readedFile)) { // }
ReadedFileTask apacheTask = new ReadedFileTask(repository.getReadedFiles(),project.getProjectName(),uuid); // List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>();
pool.submit(apacheTask); // readedFiles.add(new ReadedFileTask.ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched));
} // ReadedFileTask apacheTask = new ReadedFileTask(readedFiles,project.getProjectName(),uuid);
} // apacheTask.setBySort(bySort);
}/*else { // apacheTask.setIndex(i);
Files.copy(file, Paths.get(newPath)); // pool.submit(apacheTask);
}*/ // i++;
return FileVisitResult.CONTINUE; // bySort.setSize(i);
} // }else {
}); // String s = new String(Files.readAllBytes(originalPath));
ReadedFileTask apacheTask = new ReadedFileTask(repository.getReadedFiles(),project.getProjectName(),uuid); // ReadedFileTask.ReadedFile readedFile = new ReadedFileTask.ReadedFile(s, attrs, file,thisFileMatched);
pool.submit(apacheTask); // if (repository.put(readedFile)) {
pool.shutdown(); // ReadedFileTask apacheTask = new ReadedFileTask(repository.getReadedFiles(),project.getProjectName(),uuid);
try { // pool.submit(apacheTask);
pool.awaitTermination(1,TimeUnit.HOURS); // }
} catch (InterruptedException e) { // }
e.printStackTrace(); // }/*else {
} // Files.copy(file, Paths.get(newPath));
originalFileDao.saveAll(originalFiles); // }*/
//adaptationDetailLogEntityDao.saveAll(detailsLogEntities); // return FileVisitResult.CONTINUE;
Project one = projectDao.getOne(project.getId()); // }
one.setStage(1); // });
return ServerResponse.success("替换成功",one); // System.out.println("遍历结束");
} catch (IOException e) { // ReadedFileTask apacheTask = new ReadedFileTask(repository.getReadedFiles(),project.getProjectName(),uuid);
e.printStackTrace(); // pool.submit(apacheTask);
return ServerResponse.error("替换失败"); // pool.shutdown();
} // try {
} // pool.awaitTermination(1,TimeUnit.HOURS);
// } catch (InterruptedException e) {
/** // e.printStackTrace();
* 预处理适配规则,将规则实体类处理成glob表达式 // }
* @return // //originalFileDao.saveAll(originalFiles);
*/ // //adaptationDetailLogEntityDao.saveAll(detailsLogEntities);
private Map<String,Rule> preprocessRegular() { // Project one = projectDao.getOne(project.getId());
//List<String> result = new ArrayList<>(); // one.setStage(1);
Map<String,Rule> result = new HashMap<>(); // return ServerResponse.success("替换成功",one);
for (Rule adaptorEntity : ruleList) { // } catch (IOException e) {
switch (adaptorEntity.getPathMatchType()) { // e.printStackTrace();
case SUFFIX: // return ServerResponse.error("替换失败");
result.put("**/**" + adaptorEntity.getPath(),adaptorEntity); // }
break; // }
case PATH: //
result.put("" + adaptorEntity.getPath(),adaptorEntity); // /**
break; // * 预处理适配规则,将规则实体类处理成glob表达式
case NAME: // * @return
result.put("**/" + adaptorEntity.getPath(),adaptorEntity); // */
break; // private List<MatchAndRule> preprocessRegular() {
} // //List<String> result = new ArrayList<>();
} // List<MatchAndRule> result = new ArrayList<>();
return result; // for (Rule adaptorEntity : ruleList) {
} // System.out.println(adaptorEntity.getPath());
//// System.out.println(adaptorEntity.getTarget()+"11");
/** //// System.out.println(adaptorEntity.getPathMatchType());
* 对于大文件,按行读取,积攒到一定大小去处理 //// System.out.println(adaptorEntity);
* 这里put进来每行 // switch (adaptorEntity.getPathMatchType()) {
* 大小不够时返回false // case SUFFIX:
* 大小够时返回true // result.add(new MatchAndRule("**/**" + adaptorEntity.getPath(),adaptorEntity));
*/ // break;
private class ReadedLinesRepository{ // case PATH:
private static final long LIMIT = 200*1024*1024;//字节*k*m // result.add(new MatchAndRule("" + adaptorEntity.getPath(),adaptorEntity));
// break;
private List<StringBuilder> readedFiles; // case NAME:
private long count; // result.add(new MatchAndRule("**/" + adaptorEntity.getPath(),adaptorEntity));
// break;
public String getReadedFiles() { // case GLOB:
return readedFiles.toString(); // result.add(new MatchAndRule(adaptorEntity.getPath(),adaptorEntity));
} // }
// }
public boolean put(String readedFile){ // return result;
if(readedFiles==null)readedFiles = new ArrayList<>(); // }
readedFiles.add(new StringBuilder(readedFile)); //
count+=readedFile.length(); // /**
return count > LIMIT; // * 对于大文件,按行读取,积攒到一定大小去处理
} // * 这里put进来每行
} // * 大小不够时返回false
// * 大小够时返回true
/** // */
* 读取到的大量小文件,积累到一定的大小,才交给一个线程去处理 // private class ReadedLinesRepository{
*/ // private static final long LIMIT = 200*1024*1024;//字节*k*m
private class ReadedFileRepository{ //
private List<ReadedFileTask.ReadedFile> readedFiles; // private List<StringBuilder> readedFiles;
private long count; // private long count;
//
public List<ReadedFileTask.ReadedFile> getReadedFiles() { // public String getReadedFiles() {
return readedFiles; // return readedFiles.toString();
} // }
//
public boolean put(ReadedFileTask.ReadedFile readedFile){ // public boolean put(String readedFile){
if(readedFiles==null)readedFiles = new ArrayList<>(); // if(readedFiles==null)readedFiles = new ArrayList<>();
readedFiles.add(readedFile); // readedFiles.add(new StringBuilder(readedFile));
count+=readedFile.getAttributes().size(); // count+=readedFile.length();
return count > LIMIT; // return count > LIMIT;
} // }
} // }
//
/** // /**
* 过大的文件,切割成几块,每块编号,分给每个线程处理,处理结束后,按编号顺序写出 // * 读取到的大量小文件,积累到一定的大小,才交给一个线程去处理
* 这里按编号控制写出顺序 // */
*/ // private class ReadedFileRepository{
public class WriterBySort{ // private List<ReadedFileTask.ReadedFile> readedFiles;
private int currentIndex = -1; // private long count;
private Map<Integer,String> map = new TreeMap<>(); //
private Writer contentWriter; // public List<ReadedFileTask.ReadedFile> getReadedFiles() {
private int size; // return readedFiles;
// }
public void setWriter(Writer writer) { //
this.contentWriter = writer; // public boolean put(ReadedFileTask.ReadedFile readedFile){
} // if(readedFiles==null)readedFiles = new ArrayList<>();
public void setSize(int size) { // readedFiles.add(readedFile);
this.size = size; // count+=readedFile.getAttributes().size();
if(currentIndex==size){ // return count > LIMIT;
try { // }
contentWriter.close(); // }
} catch (IOException e) { //
e.printStackTrace(); // /**
} // * 过大的文件,切割成几块,每块编号,分给每个线程处理,处理结束后,按编号顺序写出
} // * 这里按编号控制写出顺序
} // */
public void insert(Integer key, String value){ //// public class WriterBySort{
map.put(key,value); //// private int currentIndex = -1;
while (map.get(currentIndex+1)!=null){ //// private Map<Integer,String> map = new TreeMap<>();
try { //// private Writer contentWriter;
contentWriter.write(map.remove(currentIndex+1)); //// private int size;
} catch (IOException e) { ////
e.printStackTrace(); //// public void setWriter(Writer writer) {
} //// this.contentWriter = writer;
currentIndex++; //// }
if(currentIndex == size){ //// public void setSize(int size) {
try { //// this.size = size;
contentWriter.close(); //// if(currentIndex==size){
} catch (IOException e) { //// try {
e.printStackTrace(); //// contentWriter.close();
} //// } catch (IOException e) {
} //// e.printStackTrace();
} //// }
} //// }
} //// }
//// public void insert(Integer key, String value){
//// map.put(key,value);
} //// while (map.get(currentIndex+1)!=null){
//// try {
//// contentWriter.write(map.remove(currentIndex+1));
//// } catch (IOException e) {
//// e.printStackTrace();
//// }
//// currentIndex++;
//// if(currentIndex == size){
//// try {
//// contentWriter.close();
//// } catch (IOException e) {
//// e.printStackTrace();
//// }
//// }
//// }
//// }
//// }
//
// @NoArgsConstructor
// @AllArgsConstructor
// @Data
// private class MatchAndRule{
// private String math;
// private Rule rule;
// }
//}
package com.zjty.adaptationmaster.utils;
import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer;
import com.zjty.adaptationmaster.adaptor.entity.OriginalFile;
import com.zjty.adaptationmaster.adaptor.entity.Project;
import com.zjty.adaptationmaster.adaptor.entity.Rule;
import com.zjty.adaptationmaster.adaptor.repository.OriginalFileDao;
import com.zjty.adaptationmaster.adaptor.repository.ProjectDao;
import com.zjty.adaptationmaster.base.enums.Const;
import com.zjty.adaptationmaster.base.response.ServerResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
@Component
public class Adaptor {
//@Autowired
//private AdaptationDetailLogEntityDao adaptationDetailLogEntityDao;
@Autowired
private OriginalFileDao originalFileDao;
private ProjectDao projectDao;
private String uuid;
//@Value("${base.path}")
private String basePath = Const.CONSOLE;
//线程池数量,合适的线程数量能让程序更快
private static final int poolSize = 20;
//为避免内存溢出,对于超大文件,切分成部分分别读入处理,最后拼接写出
private static final long LIMIT = 200*1024*1024;
List<Rule> ruleList;
Project project;
//String projectPath;
//private List<Rule> adaptorEntities = new ArrayList<>();
//public void setProjectPath(String projectPath) {
// this.projectPath = projectPath;
//}
public void setProject(Project project) {
this.project = project;
}
public void setRuleList(List<Rule> ruleList) {
this.ruleList = ruleList;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public ServerResponse doAdapt(){
//String regular = preprocesAdaptation();
//List<String> strings1 = preprocessRegular();
List<MatchAndRule> strings1 = preprocessRegular();
System.out.println(strings1.size()+"规则数量");
if(strings1.size()<1){
System.out.println("检测到匹配规则为空");
return ServerResponse.error("检测到匹配规则为空");
}
if(project.getCodeUrl() == null || project.getCodeUrl().equals("")){
System.out.println("未上传源代码");
return ServerResponse.error("未上传源代码");
}
ThreadPoolExecutor pool = new ThreadPoolExecutor(poolSize,poolSize,10, TimeUnit.SECONDS,new ArrayBlockingQueue<>(poolSize*2));
pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
List<OriginalFile> originalFiles = new ArrayList<>();
//记录实际具体适配内容
//List<AdaptationDetailsLogEntity> detailsLogEntities = new ArrayList<>();
ReadedFileRepository repository = new ReadedFileRepository();
String storePathParent ="originalFile/"+ UUID.randomUUID().toString();
try {
Files.walkFileTree(Paths.get(project.getCodeUrl()),new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
// System.out.println(file);
// String pathString = file.toString();
// pathString.indexOf(System.getProperty("file.separator"),basePath.length());
boolean match = false;
List<Rule> thisFileMatched = null;
//不符合规则的路径过滤掉
for(MatchAndRule regular:strings1) {
//if (FileSystems.getDefault().getPathMatcher("glob:"+regular.getMath()).matches(file)) {
//直接用java正则
String s = regular.getMath().replaceAll("\\?", ".").replaceAll("\\*", ".+");
if (Pattern.matches(s,file.getFileName().toString())) {
if(thisFileMatched==null)thisFileMatched = new ArrayList<>();
thisFileMatched.add(regular.getRule());
match = true;
}
}
if(match) {
//System.out.println("match");
String storePath = storePathParent+"/"+UUID.randomUUID().toString()+"/"+file.getFileName();
//原先文件的新地址
Path originalPath = Paths.get(basePath +storePath);
File parentFile = originalPath.toFile().getParentFile();
if(!parentFile.exists()||!parentFile.isDirectory())parentFile.mkdirs();
OriginalFile originalFile = new OriginalFile(file.toString(),originalPath.toString(),new Date());
originalFiles.add(originalFile);
//Files.copy(file,originalPath);
Files.move(file, originalPath);
//splitedFile.setDeal(true);
WebSocketServer.sendInfo(uuid,"过滤得到符合规则的文件" + file,"替换","过滤文件",project.getProjectName());
//System.out.println();
if (attrs.size() > LIMIT) {
System.out.println("找到大文件" + file);
ReadedLinesRepository linesRepository = new ReadedLinesRepository();
int i = 0;
WriterBySort bySort = new WriterBySort();
File newFile = file.toFile();
newFile.createNewFile();
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(newFile), StandardCharsets.UTF_8);
bySort.setWriter(writer);
for (String s : Files.readAllLines(originalPath, Charset.forName("utf-8"))) {
if (linesRepository.put(s)) {
List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>();
readedFiles.add(new ReadedFileTask.ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched));
ReadedFileTask apacheTask = new ReadedFileTask(readedFiles,project.getProjectName(),uuid);
apacheTask.setBySort(bySort);
apacheTask.setIndex(i);
pool.submit(apacheTask);
i++;
}
}
List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>();
readedFiles.add(new ReadedFileTask.ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched));
ReadedFileTask apacheTask = new ReadedFileTask(readedFiles,project.getProjectName(),uuid);
apacheTask.setBySort(bySort);
apacheTask.setIndex(i);
pool.submit(apacheTask);
i++;
bySort.setSize(i);
}else {
String s = new String(Files.readAllBytes(originalPath));
ReadedFileTask.ReadedFile readedFile = new ReadedFileTask.ReadedFile(s, attrs, file,thisFileMatched);
if (repository.put(readedFile)) {
ReadedFileTask apacheTask = new ReadedFileTask(repository.getReadedFiles(),project.getProjectName(),uuid);
pool.submit(apacheTask);
}
}
}/*else {
Files.copy(file, Paths.get(newPath));
}*/
return FileVisitResult.CONTINUE;
}
});
System.out.println("遍历结束");
ReadedFileTask apacheTask = new ReadedFileTask(repository.getReadedFiles(),project.getProjectName(),uuid);
pool.submit(apacheTask);
pool.shutdown();
try {
pool.awaitTermination(1,TimeUnit.HOURS);
} catch (InterruptedException e) {
e.printStackTrace();
}
//originalFileDao.saveAll(originalFiles);
//adaptationDetailLogEntityDao.saveAll(detailsLogEntities);
Project one = projectDao.getOne(project.getId());
one.setStage(1);
return ServerResponse.success("替换成功",one);
} catch (IOException e) {
e.printStackTrace();
return ServerResponse.error("替换失败");
}
}
/**
* 预处理适配规则,将规则实体类处理成glob表达式
* @return
*/
private List<MatchAndRule> preprocessRegular() {
//List<String> result = new ArrayList<>();
List<MatchAndRule> result = new ArrayList<>();
for (Rule adaptorEntity : ruleList) {
System.out.println(adaptorEntity.getPath());
adaptorEntity.setPath(adaptorEntity.getPath().replaceAll("\\?",".").replaceAll("\\*",".+"));
// System.out.println(adaptorEntity.getTarget()+"11");
// System.out.println(adaptorEntity.getPathMatchType());
// System.out.println(adaptorEntity);
// switch (adaptorEntity.getPathMatchType()) {
// case SUFFIX:
// result.add(new MatchAndRule("**/**" + adaptorEntity.getPath(),adaptorEntity));
// break;
// case PATH:
// result.add(new MatchAndRule("" + adaptorEntity.getPath(),adaptorEntity));
// break;
// case NAME:
// result.add(new MatchAndRule("**/" + adaptorEntity.getPath(),adaptorEntity));
// break;
// case GLOB:
// result.add(new MatchAndRule(adaptorEntity.getPath(),adaptorEntity));
// }
result.add(new MatchAndRule(adaptorEntity.getPath(),adaptorEntity));
}
return result;
}
/**
* 对于大文件,按行读取,积攒到一定大小去处理
* 这里put进来每行
* 大小不够时返回false
* 大小够时返回true
*/
private class ReadedLinesRepository{
private static final long LIMIT = 200*1024*1024;//字节*k*m
private List<StringBuilder> readedFiles;
private long count;
public String getReadedFiles() {
return readedFiles.toString();
}
public boolean put(String readedFile){
if(readedFiles==null)readedFiles = new ArrayList<>();
readedFiles.add(new StringBuilder(readedFile));
count+=readedFile.length();
return count > LIMIT;
}
}
/**
* 读取到的大量小文件,积累到一定的大小,才交给一个线程去处理
*/
private class ReadedFileRepository{
private List<ReadedFileTask.ReadedFile> readedFiles;
private long count;
public List<ReadedFileTask.ReadedFile> getReadedFiles() {
return readedFiles;
}
public boolean put(ReadedFileTask.ReadedFile readedFile){
if(readedFiles==null)readedFiles = new ArrayList<>();
readedFiles.add(readedFile);
count+=readedFile.getAttributes().size();
return count > LIMIT;
}
}
/**
* 过大的文件,切割成几块,每块编号,分给每个线程处理,处理结束后,按编号顺序写出
* 这里按编号控制写出顺序
*/
// public class WriterBySort{
// private int currentIndex = -1;
// private Map<Integer,String> map = new TreeMap<>();
// private Writer contentWriter;
// private int size;
//
// public void setWriter(Writer writer) {
// this.contentWriter = writer;
// }
// public void setSize(int size) {
// this.size = size;
// if(currentIndex==size){
// try {
// contentWriter.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }
// public void insert(Integer key, String value){
// map.put(key,value);
// while (map.get(currentIndex+1)!=null){
// try {
// contentWriter.write(map.remove(currentIndex+1));
// } catch (IOException e) {
// e.printStackTrace();
// }
// currentIndex++;
// if(currentIndex == size){
// try {
// contentWriter.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }
// }
// }
@NoArgsConstructor
@AllArgsConstructor
@Data
private class MatchAndRule{
private String math;
private Rule rule;
}
}
...@@ -63,6 +63,7 @@ public class Inspector { ...@@ -63,6 +63,7 @@ public class Inspector {
this.report = new Report(); this.report = new Report();
} }
int fileNum = 0;
/** /**
* FileVisitResult.CONTINUE 继续遍历 * FileVisitResult.CONTINUE 继续遍历
* FileVisitResult.TERMINATE 中止访问 * FileVisitResult.TERMINATE 中止访问
...@@ -100,6 +101,7 @@ public class Inspector { ...@@ -100,6 +101,7 @@ public class Inspector {
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
fileNum++;
for(Map.Entry<String,PathMatcher> entry:languageSuffixMatcherMapping.entrySet()){ for(Map.Entry<String,PathMatcher> entry:languageSuffixMatcherMapping.entrySet()){
if(entry.getValue().matches(file)){ if(entry.getValue().matches(file)){
languageMatchMap.get(entry.getKey()).plus(); languageMatchMap.get(entry.getKey()).plus();
...@@ -131,6 +133,7 @@ public class Inspector { ...@@ -131,6 +133,7 @@ public class Inspector {
} }
public Report analysis(){ public Report analysis(){
report.setFileNum(fileNum);
report.setLanguage(Report.Language.ONLYVIEW); report.setLanguage(Report.Language.ONLYVIEW);
for(Map.Entry<String,Counter> entry:languageMatchMap.entrySet()){ for(Map.Entry<String,Counter> entry:languageMatchMap.entrySet()){
if(entry.getValue().getNumber()>0){ if(entry.getValue().getNumber()>0){
......
...@@ -2,7 +2,6 @@ package com.zjty.adaptationmaster.utils; ...@@ -2,7 +2,6 @@ package com.zjty.adaptationmaster.utils;
import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer; import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer;
import com.zjty.adaptationmaster.adaptor.entity.Rule; import com.zjty.adaptationmaster.adaptor.entity.Rule;
import com.zjty.adaptationmaster.adaptor.service.Impl.Adaptor;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -11,6 +10,7 @@ import java.io.*; ...@@ -11,6 +10,7 @@ import java.io.*;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.List; import java.util.List;
import java.util.Properties;
public class ReadedFileTask implements Runnable { public class ReadedFileTask implements Runnable {
...@@ -20,15 +20,20 @@ public class ReadedFileTask implements Runnable { ...@@ -20,15 +20,20 @@ public class ReadedFileTask implements Runnable {
private List<ReadedFile> readedFiles; private List<ReadedFile> readedFiles;
//private Writer responseWriter; //private Writer responseWriter;
public ReadedFileTask(List<ReadedFile> readedFiles,String projectName,String uuid) { public ReadedFileTask(List<ReadedFile> readedFiles,String projectName,String uuid) {
//System.out.println("一个线程");
this.readedFiles = readedFiles; this.readedFiles = readedFiles;
for(ReadedFile file:readedFiles){
System.out.println(file.path);
}
this.projectName = projectName; this.projectName = projectName;
this.uuid = uuid; this.uuid = uuid;
} }
private Adaptor.WriterBySort bySort; private WriterBySort bySort;
private int index; private int index;
public void setBySort(Adaptor.WriterBySort bySort) { public void setBySort(WriterBySort bySort) {
System.out.println("线程遇到大文件");
this.bySort = bySort; this.bySort = bySort;
} }
...@@ -38,42 +43,51 @@ public class ReadedFileTask implements Runnable { ...@@ -38,42 +43,51 @@ public class ReadedFileTask implements Runnable {
@Override @Override
public void run() { public void run() {
for(ReadedFile readedFile:readedFiles){ System.out.println("进来线程");
String content = readedFile.getContent(); for(ReadedFile readedFile:readedFiles) {
System.out.println("规则数量"+readedFile.getThisMatchedRule().size()); if(readedFile.path.toString().endsWith(".properties")){
for(Rule entity:readedFile.getThisMatchedRule()){ Properties properties = new Properties();
System.out.println("文本匹配方式"+entity.getTextMatching()); OutputStream stream =null;
switch (entity.getTextMatching()){ try {
case AREA: properties.load(new ByteArrayInputStream(readedFile.content.getBytes()));
String[] split = entity.getTarget().split("\\|\\|"); for (Rule entity : readedFile.getThisMatchedRule()) {
String begin = split[0];
String matching = split[1];
String end = split[2];
System.out.println(begin+"||"+matching+"||"+end);
int i = content.indexOf(matching); //if(properties.getProperty(entity.getTarget())!=null) {
if(i>-1){ properties.setProperty(entity.getTarget(), entity.getReplacing());
WebSocketServer.sendInfo(uuid,readedFile.getPath().getFileName()+":"+matching+" 替换为 "+entity.getReplacing(),"替换","正在替换",projectName); //}
int beginIndex = content.lastIndexOf(begin, i); System.out.println("属性修改后"+properties.getProperty(entity.getTarget()));
int endIndex = content.indexOf(end, i + 1); }
if(beginIndex>-1&&endIndex>-1){ readedFile.getPath().toFile().createNewFile();
content = content.substring(0,beginIndex)+entity.getReplacing()+content.substring(endIndex+end.length()); stream = new FileOutputStream(readedFile.getPath().toFile());
} System.out.println(properties);
} properties.store(stream,"111");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
//container.add(readedFile.getPath().getFileName()+"文本替换:"+entity.getTextMatching()+"|"+entity.getReplacing()); continue;
}
//template.convertAndSend("===="+readedFile.getPath().getFileName()+"////"+entity.getTextMatching()+"||||"+entity.getReplacing(),"1L"); String content = readedFile.getContent();
//responseWriter.write("===="+readedFile.getPath().getFileName()+"////"+entity.getTextMatching()+"||||"+entity.getReplacing()); System.out.println("规则数量" + readedFile.getThisMatchedRule().size());
for (Rule entity : readedFile.getThisMatchedRule()) {
//在改动的地方加日志
// int i = content.indexOf(entity.getTarget());
// int i1 = content.lastIndexOf("\\r\\n", i);
//
content = content.replaceAll(entity.getTarget(),entity.getReplacing());
} }
try { try {
if(bySort!=null){ if (bySort != null) {
System.out.println("toBySort"); bySort.insert(index, content);
bySort.insert(index,content);
} else { } else {
System.out.println("writerFile"); WebSocketServer.sendInfo(uuid, readedFile.getPath().getFileName() + "", "替换", "正在写出", projectName);
WebSocketServer.sendInfo(uuid,readedFile.getPath().getFileName()+"","替换","正在写出",projectName);
File file = readedFile.getPath().toFile(); File file = readedFile.getPath().toFile();
file.createNewFile(); file.createNewFile();
OutputStreamWriter contentWriter = new OutputStreamWriter(new FileOutputStream(file)); OutputStreamWriter contentWriter = new OutputStreamWriter(new FileOutputStream(file));
...@@ -83,6 +97,7 @@ public class ReadedFileTask implements Runnable { ...@@ -83,6 +97,7 @@ public class ReadedFileTask implements Runnable {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
......
//package com.zjty.adaptationmaster.utils;
//
//import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer;
//import com.zjty.adaptationmaster.adaptor.entity.Rule;
//import lombok.AllArgsConstructor;
//import lombok.Data;
//import lombok.NoArgsConstructor;
//
//import java.io.*;
//import java.nio.file.Path;
//import java.nio.file.attribute.BasicFileAttributes;
//import java.util.List;
//import java.util.Properties;
//
//
//public class ReadedFileTask implements Runnable {
//
// private String projectName;
// private String uuid;
// private List<ReadedFile> readedFiles;
// //private Writer responseWriter;
// public ReadedFileTask(List<ReadedFile> readedFiles,String projectName,String uuid) {
// //System.out.println("一个线程");
// this.readedFiles = readedFiles;
// for(ReadedFile file:readedFiles){
// System.out.println(file.path);
// }
// this.projectName = projectName;
// this.uuid = uuid;
// }
//
// private WriterBySort bySort;
// private int index;
//
// public void setBySort(WriterBySort bySort) {
// System.out.println("线程遇到大文件");
// this.bySort = bySort;
// }
//
// public void setIndex(int index) {
// this.index = index;
// }
//
// @Override
// public void run() {
// System.out.println("进来线程");
// for(ReadedFile readedFile:readedFiles) {
// if(readedFile.path.toString().endsWith(".properties")){
// Properties properties = new Properties();
// OutputStream stream =null;
// try {
// properties.load(new ByteArrayInputStream(readedFile.content.getBytes()));
// for (Rule entity : readedFile.getThisMatchedRule()) {
//
// //if(properties.getProperty(entity.getTarget())!=null) {
// properties.setProperty(entity.getTarget(), entity.getReplacing());
// //}
// System.out.println("属性修改后"+properties.getProperty(entity.getTarget()));
// }
// readedFile.getPath().toFile().createNewFile();
// stream = new FileOutputStream(readedFile.getPath().toFile());
// System.out.println(properties);
// properties.store(stream,"111");
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }finally {
// try {
// stream.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// continue;
// }
// String content = readedFile.getContent();
// System.out.println("规则数量" + readedFile.getThisMatchedRule().size());
// for (Rule entity : readedFile.getThisMatchedRule()) {
// System.out.println("文本匹配方式" + entity.getTextMatching());
// switch (entity.getTextMatching()) {
// case AREA:
// System.out.println("case");
// String[] split = entity.getTarget().split("\\|\\|");
// String begin = split[0];
// String matching = split[1];
// String end = split[2];
// System.out.println(begin + "||" + matching + "||" + end);
//
// int i = content.indexOf(matching);
// if (i > -1) {
// System.out.println("i" + i);
// WebSocketServer.sendInfo(uuid, readedFile.getPath().getFileName() + ":" + matching + " 替换为 " + entity.getReplacing(), "替换", "正在替换", projectName);
// int beginIndex = content.lastIndexOf(begin, i);
// int endIndex = content.indexOf(end, i + 1);
// if (beginIndex > -1 && endIndex > -1) {
// content = content.substring(0, beginIndex) + entity.getReplacing() + content.substring(endIndex + end.length());
// }
// } else {
//
// System.out.println("-i" + i);
// }
// break;
// case CONTENT:
// switch (entity.getDealWay()) {
// case REPLACE:
// content = content.replaceAll(entity.getTarget(), entity.getReplacing());
// break;
// case INSERTAFTER:
// //判断是不是本来就有,如果已有,就不用新增了
// //if(content.indexOf(entity.getReplacing(),content.indexOf(entity.getTarget()))==-1) {
// int insertPlace = content.indexOf(entity.getTarget()) + entity.getTarget().length();
// content = content.substring(0, insertPlace) + entity.getReplacing() + content.substring(insertPlace);
// //}
// break;
// case INSERTBEFORE:
// break;
// case InsertBetween:
// break;
// }
//
// break;
// }
// }
// try {
// if (bySort != null) {
// bySort.insert(index, content);
// } else {
// WebSocketServer.sendInfo(uuid, readedFile.getPath().getFileName() + "", "替换", "正在写出", projectName);
// File file = readedFile.getPath().toFile();
// file.createNewFile();
// OutputStreamWriter contentWriter = new OutputStreamWriter(new FileOutputStream(file));
// contentWriter.write(content);
// contentWriter.close();
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
// }
//
// @Data
// @NoArgsConstructor
// @AllArgsConstructor
// public static class ReadedFile {
// private String content;
// private BasicFileAttributes attributes;
// private Path path;
// private List<Rule> thisMatchedRule;
// }
//}
package com.zjty.adaptationmaster.utils;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import java.util.TreeMap;
public class WriterBySort {
private int currentIndex = -1;
private Map<Integer,String> map = new TreeMap<>();
private Writer contentWriter;
private int size;
public void setWriter(Writer writer) {
this.contentWriter = writer;
}
public void setSize(int size) {
this.size = size;
if(currentIndex==size){
try {
contentWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void insert(Integer key, String value){
map.put(key,value);
while (map.get(currentIndex+1)!=null){
try {
contentWriter.write(map.remove(currentIndex+1));
} catch (IOException e) {
e.printStackTrace();
}
currentIndex++;
if(currentIndex == size){
try {
contentWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
...@@ -9,6 +9,7 @@ import java.nio.file.PathMatcher; ...@@ -9,6 +9,7 @@ import java.nio.file.PathMatcher;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
public class Test1 { public class Test1 {
@Test @Test
...@@ -684,4 +685,9 @@ public class Test1 { ...@@ -684,4 +685,9 @@ public class Test1 {
System.out.println(sb.toString()); System.out.println(sb.toString());
} }
@Test
public void test5(){
System.out.println(Pattern.matches(".+22.+","2223"));
}
} }
//package com.zjty.adaptationmaster;
//
//import com.zjty.adaptationmaster.adaptor.entity.Project;
//import com.zjty.adaptationmaster.adaptor.entity.Rule;
//import com.zjty.adaptationmaster.adaptor.service.Impl.Adaptor;
//import org.junit.Test;
//
//import java.nio.file.FileSystems;
//import java.nio.file.Path;
//import java.nio.file.Paths;
//import java.util.ArrayList;
//import java.util.List;
//
//public class TestAdapt {
//
// public static void main(String[] args) {
// List ruleList = new ArrayList();
// Rule rule = new Rule();
// rule.setPathMatchType(Rule.MatchType.NAME);
// rule.setPath("pom.xml");
// rule.setTextMatching(Rule.TextMatch.CONTENT);
// rule.setDealWay(Rule.DealWay.REPLACE);
// rule.setTarget("<packaging>jar</packaging>");
// rule.setReplacing("<packaging>war</packaging>");
// ruleList.add(rule);
//
// Rule rule11 = new Rule();
// rule11.setPathMatchType(Rule.MatchType.NAME);
// rule11.setPath("pom.xml");
// rule11.setTextMatching(Rule.TextMatch.CONTENT);
// rule11.setDealWay(Rule.DealWay.INSERTAFTER);
// rule11.setTarget("<dependencies>");
// rule11.setReplacing("<dependency>\n" +
// " <groupId>org.postgresql</groupId>\n" +
// " <artifactId>postgresql</artifactId>\n" +
// " <scope>runtime</scope>\n" +
// " </dependency>");
// ruleList.add(rule11);
//
// Rule rule1 = new Rule();
// rule1.setPathMatchType(Rule.MatchType.GLOB);
// rule1.setPath("**/application**.properties");
// rule1.setTextMatching(Rule.TextMatch.CONTENT);
// rule1.setDealWay(Rule.DealWay.REPLACE);
// rule1.setTarget("spring.datasource.driver-class-name");
// rule1.setReplacing("org.postgresql.Driver");
// ruleList.add(rule1);
//
// Rule rule2 = new Rule();
// rule2.setPathMatchType(Rule.MatchType.GLOB);
// rule2.setPath("**/application**.properties");
// rule2.setTextMatching(Rule.TextMatch.CONTENT);
// rule2.setDealWay(Rule.DealWay.REPLACE);
// rule2.setTarget("spring.datasource.url");
// rule2.setReplacing("jdbc:postgresql://localhost:5866/hrm");
// ruleList.add(rule2);
// Rule rule3 = new Rule();
// rule3.setPathMatchType(Rule.MatchType.GLOB);
// rule3.setPath("**/application**.properties");
// rule3.setTextMatching(Rule.TextMatch.CONTENT);
// rule3.setDealWay(Rule.DealWay.REPLACE);
// rule3.setTarget("spring.datasource.username");
// rule3.setReplacing("sysdba");
// ruleList.add(rule3);
// Rule rule4 = new Rule();
// rule4.setPathMatchType(Rule.MatchType.GLOB);
// rule4.setPath("**/application**.properties");
// rule4.setTextMatching(Rule.TextMatch.CONTENT);
// rule4.setDealWay(Rule.DealWay.REPLACE);
// rule4.setTarget("spring.datasource.password");
// rule4.setReplacing("highgo@123");
// ruleList.add(rule4);
// Rule rule5 = new Rule();
// rule5.setPathMatchType(Rule.MatchType.GLOB);
// rule5.setPath("**/application**.properties");
// rule5.setTextMatching(Rule.TextMatch.CONTENT);
// rule5.setDealWay(Rule.DealWay.REPLACE);
// rule5.setTarget("spring.jpa.database-platform");
// rule5.setReplacing("org.hibernate.dialect.PostgreSQLDialect");
// ruleList.add(rule5);
//
// Adaptor adaptor = new Adaptor();
// adaptor.setRuleList(ruleList);
// adaptor.setUuid("111");
// Project project = new Project();
// project.setCodeUrl("C:\\home\\project\\rsc\\hrmbclient");
// project.setProjectName("hrm");
// adaptor.setProject(project);
// adaptor.doAdapt();
// }
// @Test
// public void test(){
// Path path = Paths.get("D:/aaa.properties");
// System.out.println(path.toString().endsWith(".properties"));
// }
//}
package com.zjty.adaptationmaster;
import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer;
import java.io.*;
public class TestProcess {
public static void main(String[] args) {
try {
Process exec = Runtime.getRuntime().exec("C:/Users/wyl/Desktop/national/AAS-V9.0/bin/appctl.cmd install -p Qwer123!@# hrm C://home/project/rsc/hrmbclient/target/hrmanager-0.0.1-SNAPSHOT.war");
BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(exec.getOutputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
writer.write("@Qwer123!@#");
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论