Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
adaptation-master
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
项目监控管理工具
adaptation-master
Commits
3eb2bfcf
提交
3eb2bfcf
authored
12月 23, 2019
作者:
wyl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
极简版规则
上级
ddccadf2
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
94 行增加
和
45 行删除
+94
-45
WebSocketServer.java
.../adaptationmaster/adaptor/controller/WebSocketServer.java
+6
-6
Adaptor.java
src/main/java/com/zjty/adaptationmaster/utils/Adaptor.java
+8
-5
ReadedFileTask.java
.../java/com/zjty/adaptationmaster/utils/ReadedFileTask.java
+18
-33
Test1.java
src/test/java/com/zjty/adaptationmaster/Test1.java
+25
-1
TestAdapterSimplest.java
...t/java/com/zjty/adaptationmaster/TestAdapterSimplest.java
+37
-0
没有找到文件。
src/main/java/com/zjty/adaptationmaster/adaptor/controller/WebSocketServer.java
浏览文件 @
3eb2bfcf
...
...
@@ -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
);
...
...
src/main/java/com/zjty/adaptationmaster/utils/Adaptor.java
浏览文件 @
3eb2bfcf
...
...
@@ -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
()
{
...
...
src/main/java/com/zjty/adaptationmaster/utils/ReadedFileTask.java
浏览文件 @
3eb2bfcf
...
...
@@ -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
();
...
...
src/test/java/com/zjty/adaptationmaster/Test1.java
浏览文件 @
3eb2bfcf
...
...
@@ -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
);
}
}
src/test/java/com/zjty/adaptationmaster/TestAdapterSimplest.java
0 → 100644
浏览文件 @
3eb2bfcf
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论