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

合并分支 'wyl' 到 'master'

rule少一个字段“备注”,补全 查看合并请求 ty_wyl/adaptation-master1!47
......@@ -131,11 +131,11 @@
<artifactId>snakeyaml</artifactId>
<version>1.25</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.3.4</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.zookeeper</groupId>-->
<!-- <artifactId>zookeeper</artifactId>-->
<!-- <version>3.3.4</version>-->
<!-- </dependency>-->
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
......
......@@ -69,13 +69,13 @@ public class WebSocketServer {
this.session.getBasicRemote().sendText(message);
}
public static void sendIn(String sessionId,String message) throws IOException {
System.out.println(message);
// try {
// map.get(sessionId).sendMessage(message);
// }catch (Exception e){
// log.info("向前台发送日志出错");
// //e.printStackTrace();
// }
//System.out.println(message);
try {
map.get(sessionId).sendMessage(message);
}catch (Exception e){
log.info("向前台发送日志出错");
//e.printStackTrace();
}
}
}
......@@ -84,7 +84,7 @@ public class AdaptationServiceImpl implements AdaptationService {
} catch (Exception e) {
e.printStackTrace();
}
return ServerResponse.success(project);
return ServerResponse.success(project1);
}
@Override
......
//package com.zjty.adaptationmaster.adaptor.service.Impl;
//
//import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer;
//import com.zjty.adaptationmaster.adaptor.entity.Project;
//import com.zjty.adaptationmaster.adaptor.repository.ProjectDao;
//import com.zjty.adaptationmaster.base.response.ServerResponse;
//import com.zjty.adaptationmaster.utils.ReadedFileTask;
//import com.zjty.adaptationmaster.adaptor.entity.OriginalFile;
//import com.zjty.adaptationmaster.adaptor.entity.Rule;
//import com.zjty.adaptationmaster.base.enums.Const;
//import com.zjty.adaptationmaster.adaptor.repository.OriginalFileDao;
//import com.zjty.adaptationmaster.utils.WriterBySort;
//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;
//
////适应四种规则的适配器,改成只适配java正则的,再util下面
////@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正则
// if (FileSystems.getDefault().getPathMatcher(regular.getMath()).matches(file)) {
// 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());
//// 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));
// }
// }
// 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;
// }
//}
......@@ -40,7 +40,7 @@ public class Const {
public static Map<String,Long> transferCountMap = new ConcurrentHashMap<>();
public static final String MAVENHOME = "D:\\Program Files\\apache-maven-3.5.4-bin\\apache-maven-3.5.4";
public static final String CTLPATH = "/home/user/AAS-V9.0/bin/appctl.cmd";
public static final String MAVENHOME = "/opt/apache-maven-3.5.4";
public static final String CTLPATH = "/home/taiyuan/桌面/AAS-V9.0/bin/appctl";
public static final String CTLPWD = "Qwert123!@#";
}
......@@ -11,6 +11,8 @@ import com.zjty.adaptationmaster.base.response.ServerResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -27,11 +29,12 @@ import java.util.regex.Pattern;
@Component
public class Adaptor {
Logger logger = LoggerFactory.getLogger(getClass());
//@Autowired
//private AdaptationDetailLogEntityDao adaptationDetailLogEntityDao;
@Autowired
private OriginalFileDao originalFileDao;
@Autowired
private ProjectDao projectDao;
private String uuid;
......@@ -107,8 +110,10 @@ public class Adaptor {
}
if(match) {
System.out.println("match");
System.out.println(file);
// logger.info();
// System.out.println("match");
// System.out.println(file);
//logger.info("找到文件"+file.getFileName());
String storePath = storePathParent+"/"+UUID.randomUUID().toString()+"/"+file.getFileName();
//原先文件的新地址
Path originalPath = Paths.get(basePath +storePath);
......@@ -119,7 +124,7 @@ public class Adaptor {
//Files.copy(file,originalPath);
Files.move(file, originalPath);
//splitedFile.setDeal(true);
WebSocketServer.sendIn(uuid,TimeUtil.getNowDate()+"内容替换:过滤文件"+project.getProjectName()+file.getFileName());
//WebSocketServer.sendIn(uuid,TimeUtil.getNowDate()+"内容替换:过滤文件"+project.getProjectName()+file.getFileName());
//System.out.println();
if (attrs.size() > LIMIT) {
System.out.println("找到大文件" + file);
......
......@@ -37,7 +37,7 @@ public class ApusicDeployer {
outputStream.write(password.getBytes());
outputStream.flush();
outputStream.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream(),"GBK"));
BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream(),"UTF-8"));
boolean titleEnd = false;
String line = null;
while ((line = reader.readLine()) != null) {
......@@ -80,7 +80,7 @@ public class ApusicDeployer {
outputStream.write(password.getBytes());
outputStream.flush();
outputStream.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream(),"GBK"));
BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream(),"UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
WebSocketServer.sendIn(webSocketName, TimeUtil.getNowDate()+"自动部署:"+ projectName+line);
......
......@@ -24,6 +24,10 @@ public class MavenCompiler {
public void compiler(){
System.out.print("wwwwwww");
InvocationRequest request1 = new DefaultInvocationRequest();
request1.setPomFile(new File(project.getReport().getCompileFilePath()));
request1.setGoals(Collections.singletonList("clean"));
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File(project.getReport().getCompileFilePath()));
request.setGoals(Collections.singletonList("package"));
......@@ -39,6 +43,7 @@ public class MavenCompiler {
}
});
try {
invoker.execute(request1);
InvocationResult execute = invoker.execute(request);
CommandLineException executionException = execute.getExecutionException();
if(executionException==null){
......
......@@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.tomcat.websocket.server.WsServerContainer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.nio.file.Path;
......@@ -16,6 +18,7 @@ import java.util.Properties;
public class ReadedFileTask implements Runnable {
Logger logger = LoggerFactory.getLogger(getClass());
private String projectName;
private String uuid;
......@@ -42,10 +45,11 @@ public class ReadedFileTask implements Runnable {
@Override
public void run() {
System.out.println("进来线程");
//System.out.println("进来线程");
for(ReadedFile readedFile:readedFiles) {
boolean match = false;
String content = readedFile.getContent();
System.out.println("规则数量" + readedFile.getThisMatchedRule().size());
//System.out.println("规则数量" + readedFile.getThisMatchedRule().size());
for (Rule entity : readedFile.getThisMatchedRule()) {
//在改动的地方加日志
// int i = content.indexOf(entity.getTarget());
......@@ -54,6 +58,7 @@ public class ReadedFileTask implements Runnable {
String replace = entity.getReplacing();
String[] split;
if(replace.contains("*")) {
logger.info("目标文本包含*,要记录*中的内容");
split = entity.getTarget().split("\\*");
int i = content.indexOf(split[0]);
int i1 = content.indexOf(split[1], i + split[0].length());
......@@ -62,17 +67,34 @@ public class ReadedFileTask implements Runnable {
replace = split1[0]+temp+split1[1];
content = content.substring(0,i)+replace+content.substring(i1);
}else {
if(content.contains(entity.getTarget())){
try {
WebSocketServer.sendIn(uuid,TimeUtil.getNowDate() + " 代码替换:在文件" + readedFile.getPath().getFileName() + "中,找到关键字:\""+entity.getTarget()+"\",替换为"+replace);//"替换文件,找到文件"+ readedFile.getPath().getFileName());
} catch (IOException e) {
e.printStackTrace();
}
match = true;
logger.info("找到目标"+readedFile.getPath().getFileName()+"目标:"+entity.getTarget());
}
content = content.replaceAll(entity.getTarget(), replace);
// if(match){
// logger.info(content);
// }
}
System.out.println("处理完成");
//System.out.println("处理完成");
}
try {
if (bySort != null) {
System.out.println("bysort");
//System.out.println("bysort");
bySort.insert(index, content);
} else {
System.out.println("notbysort");
WebSocketServer.sendIn(uuid, TimeUtil.getNowDate()+"内容替换:文件写出"+readedFile.getPath().getFileName());
//System.out.println("notbysort");
//logger.info(TimeUtil.getNowDate()+"内容替换:文件写出"+readedFile.getPath().getFileName());
if(match) {
//System.out.println(TimeUtil.getNowDate() + "内容替换:文件正在写出" + readedFile.getPath().getFileName());
//WebSocketServer.sendIn(uuid, TimeUtil.getNowDate() + "内容替换:文件写出" + readedFile.getPath().getFileName());
}
File file = readedFile.getPath().toFile();
file.createNewFile();
OutputStreamWriter contentWriter = new OutputStreamWriter(new FileOutputStream(file));
......@@ -82,7 +104,6 @@ public class ReadedFileTask implements Runnable {
} catch (IOException e) {
e.printStackTrace();
}
}
}
......
# mysql数据库配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/adaptation?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5866/adaptation?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
spring.datasource.username=sysdba
spring.datasource.password=highgo@123
......@@ -9,18 +9,15 @@ import java.util.List;
public class TestDemo {
public static void main(String[] args) {
Rule rule = new Rule();
rule.setPath("*.*");
rule.setTarget("OpenDoc\\(\\);");
rule.setReplacing("OpenOfd\\(\\);");
rule.setTarget("OpenDoc");
rule.setReplacing("OpenOfd");
List ruleList = new ArrayList();
ruleList.add(rule);
Project project = new Project();
project.setCodeUrl("C:\\Users\\wyl\\Desktop\\demo");
project.setCodeUrl("D:\\project\\page1");
project.setProjectName("aaa");
Adaptor adaptor = new Adaptor();
adaptor.setRuleList(ruleList);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论