提交 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
......
...@@ -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();
} }
} }
continue;
} }
//container.add(readedFile.getPath().getFileName()+"文本替换:"+entity.getTextMatching()+"|"+entity.getReplacing()); String content = readedFile.getContent();
System.out.println("规则数量" + readedFile.getThisMatchedRule().size());
//template.convertAndSend("===="+readedFile.getPath().getFileName()+"////"+entity.getTextMatching()+"||||"+entity.getReplacing(),"1L"); for (Rule entity : readedFile.getThisMatchedRule()) {
//responseWriter.write("===="+readedFile.getPath().getFileName()+"////"+entity.getTextMatching()+"||||"+entity.getReplacing()); //在改动的地方加日志
// 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论