提交 3eb2bfcf authored 作者: wyl's avatar wyl

极简版规则

上级 ddccadf2
......@@ -69,12 +69,12 @@ public class WebSocketServer {
public static void sendInfo(String sessionId,String msg,String action,String state,String projectName){
try {
//System.out.println(sessionId);
map.get(sessionId).sendMessage(LocalDateTime.now()+"\t"+projectName+"\t"+action+"\t"+state+"\t"+msg);
} catch (IOException e) {
e.printStackTrace();
}
// try {
// //System.out.println(sessionId);
// //map.get(sessionId).sendMessage(LocalDateTime.now()+"\t"+projectName+"\t"+action+"\t"+state+"\t"+msg);
// } catch (IOException e) {
// e.printStackTrace();
// }
}
public static void sendIn(String sessionId,String message) throws IOException {
map.get(sessionId).sendMessage(message);
......
......@@ -107,7 +107,8 @@ public class Adaptor {
}
if(match) {
//System.out.println("match");
System.out.println("match");
System.out.println(file);
String storePath = storePathParent+"/"+UUID.randomUUID().toString()+"/"+file.getFileName();
//原先文件的新地址
Path originalPath = Paths.get(basePath +storePath);
......@@ -173,8 +174,9 @@ public class Adaptor {
}
//originalFileDao.saveAll(originalFiles);
//adaptationDetailLogEntityDao.saveAll(detailsLogEntities);
Project one = projectDao.getOne(project.getId());
one.setStage(1);
// Project one = projectDao.getOne(project.getId());
// one.setStage(1);
Project one = new Project();
return ServerResponse.success("替换成功",one);
} catch (IOException e) {
e.printStackTrace();
......@@ -190,7 +192,8 @@ public class Adaptor {
//List<String> result = new ArrayList<>();
List<MatchAndRule> result = new ArrayList<>();
for (Rule adaptorEntity : ruleList) {
System.out.println(adaptorEntity.getPath());
//System.out.println("preprocess"+adaptorEntity);
//System.out.println(adaptorEntity.getPath());
adaptorEntity.setPath(adaptorEntity.getPath().replaceAll("\\?",".").replaceAll("\\*",".+"));
// System.out.println(adaptorEntity.getTarget()+"11");
// System.out.println(adaptorEntity.getPathMatchType());
......@@ -241,7 +244,7 @@ public class Adaptor {
* 读取到的大量小文件,积累到一定的大小,才交给一个线程去处理
*/
private class ReadedFileRepository{
private List<ReadedFileTask.ReadedFile> readedFiles;
private List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>();
private long count;
public List<ReadedFileTask.ReadedFile> getReadedFiles() {
......
......@@ -5,10 +5,12 @@ import com.zjty.adaptationmaster.adaptor.entity.Rule;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.tomcat.websocket.server.WsServerContainer;
import java.io.*;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
......@@ -22,9 +24,6 @@ public class ReadedFileTask implements Runnable {
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;
}
......@@ -45,35 +44,6 @@ public class ReadedFileTask implements Runnable {
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()) {
......@@ -81,12 +51,27 @@ public class ReadedFileTask implements Runnable {
// int i = content.indexOf(entity.getTarget());
// int i1 = content.lastIndexOf("\\r\\n", i);
//
content = content.replaceAll(entity.getTarget(),entity.getReplacing());
String replace = entity.getReplacing();
String[] split;
if(replace.contains("*")) {
split = entity.getTarget().split("\\*");
int i = content.indexOf(split[0]);
int i1 = content.indexOf(split[1], i + split[0].length());
String temp = content.substring(i+split[0].length(),i1);
String[] split1 = replace.split("\\*");
replace = split1[0]+temp+split1[1];
content = content.substring(0,i)+replace+content.substring(i1);
}else {
content = content.replaceAll(entity.getTarget(), replace);
}
System.out.println("处理完成");
}
try {
if (bySort != null) {
System.out.println("bysort");
bySort.insert(index, content);
} else {
System.out.println("notbysort");
WebSocketServer.sendInfo(uuid, readedFile.getPath().getFileName() + "", "替换", "正在写出", projectName);
File file = readedFile.getPath().toFile();
file.createNewFile();
......
......@@ -687,7 +687,31 @@ public class Test1 {
@Test
public void test5(){
System.out.println(Pattern.matches(".+22.+","2223"));
System.out.println(Pattern.matches(".+22.+","2223678"));
System.out.println(Pattern.matches("2223","2223"));
System.out.println(Pattern.matches("22.3","2223"));
}
@Test
public void test6(){
String content = "aaaaaaaobject=888;ssssss";
String target = "object=*;";
String replace = "subject(*)";
String[] split;
if(replace.contains("*")) {
split = target.split("\\*");
int i = content.indexOf(split[0]);
int i1 = content.indexOf(split[1], i + split[0].length());
String temp = content.substring(i+split[0].length(),i1);
String[] split1 = replace.split("\\*");
replace = split1[0]+temp+split1[1];
content = content.substring(0,i)+replace+content.substring(i1);
}
content = content.replaceAll(target,replace);
System.out.println(content);
}
}
package com.zjty.adaptationmaster;
import com.zjty.adaptationmaster.adaptor.entity.Project;
import com.zjty.adaptationmaster.adaptor.entity.Rule;
import com.zjty.adaptationmaster.utils.Adaptor;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class TestAdapterSimplest {
public static void main(String[] args) {
// System.out.println(Pattern.matches("application.+.properties","application-dev.properties"));
// }{
List<Rule> ruleList = new ArrayList<>();
Rule rule = new Rule();
rule.setPath("application*.properties");
rule.setTarget("spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver");
rule.setReplacing("spring.datasource.driver-class-name=org.postgresql.Drrrrr");
ruleList.add(rule);
Rule rule1 = new Rule();
rule1.setPath("*.abc");
rule1.setTarget("object=*;");
rule1.setReplacing("subject(*)");
ruleList.add(rule1);
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();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论