Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
adaptation-master
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
项目监控管理工具
adaptation-master
Commits
cd8ae5ed
提交
cd8ae5ed
authored
12月 23, 2019
作者:
wyl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adapt done
上级
ca8f77f7
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
266 行增加
和
53 行删除
+266
-53
pom.xml
pom.xml
+7
-1
WebSocketServer.java
.../adaptationmaster/adaptor/controller/WebSocketServer.java
+6
-6
Report.java
...java/com/zjty/adaptationmaster/adaptor/entity/Report.java
+1
-1
Rule.java
...n/java/com/zjty/adaptationmaster/adaptor/entity/Rule.java
+4
-3
AdaptationServiceImpl.java
...ionmaster/adaptor/service/Impl/AdaptationServiceImpl.java
+1
-1
Adaptor.java
...m/zjty/adaptationmaster/adaptor/service/Impl/Adaptor.java
+40
-19
InspectServiceImpl.java
...tationmaster/adaptor/service/Impl/InspectServiceImpl.java
+10
-1
FileUtil.java
src/main/java/com/zjty/adaptationmaster/utils/FileUtil.java
+0
-0
Inspector.java
src/main/java/com/zjty/adaptationmaster/utils/Inspector.java
+0
-0
MavenCompiler.java
...n/java/com/zjty/adaptationmaster/utils/MavenCompiler.java
+1
-1
ReadedFileTask.java
.../java/com/zjty/adaptationmaster/utils/ReadedFileTask.java
+75
-20
TestAdapt.java
src/test/java/com/zjty/adaptationmaster/TestAdapt.java
+96
-0
TestProcess.java
src/test/java/com/zjty/adaptationmaster/TestProcess.java
+25
-0
没有找到文件。
pom.xml
浏览文件 @
cd8ae5ed
...
@@ -139,7 +139,13 @@
...
@@ -139,7 +139,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>
...
...
src/main/java/com/zjty/adaptationmaster/adaptor/controller/WebSocketServer.java
浏览文件 @
cd8ae5ed
...
@@ -66,12 +66,12 @@ public class WebSocketServer {
...
@@ -66,12 +66,12 @@ public class WebSocketServer {
}
}
public
static
void
sendInfo
(
String
sessionId
,
String
msg
,
String
action
,
String
state
,
String
projectName
){
public
static
void
sendInfo
(
String
sessionId
,
String
msg
,
String
action
,
String
state
,
String
projectName
){
//System.out.println(LocalDateTime.now()+"\t"+projectName+"\t"+action+"\t"+state+"\t"+msg);
try
{
//
try {
map
.
get
(
sessionId
).
sendMessage
(
LocalDateTime
.
now
()+
"\t"
+
projectName
+
"\t"
+
action
+
"\t"
+
state
+
"\t"
+
msg
);
// //
map.get(sessionId).sendMessage(LocalDateTime.now()+"\t"+projectName+"\t"+action+"\t"+state+"\t"+msg);
}
catch
(
IOException
e
)
{
//
} catch (IOException e) {
e
.
printStackTrace
();
//
e.printStackTrace();
}
//
}
}
}
...
...
src/main/java/com/zjty/adaptationmaster/adaptor/entity/Report.java
浏览文件 @
cd8ae5ed
...
@@ -37,6 +37,6 @@ public class Report {
...
@@ -37,6 +37,6 @@ public class Report {
MYSQL
,
ORACLE
,
SQLSERVER
,
POSTGRE
MYSQL
,
ORACLE
,
SQLSERVER
,
POSTGRE
}
}
public
enum
Language
{
public
enum
Language
{
JAVA
,
PYTHON
,
CPP
JAVA
,
PYTHON
,
CPP
,
JSP
,
ONLYVIEW
}
}
}
}
src/main/java/com/zjty/adaptationmaster/adaptor/entity/Rule.java
浏览文件 @
cd8ae5ed
...
@@ -33,6 +33,7 @@ public class Rule {
...
@@ -33,6 +33,7 @@ public class Rule {
private
MatchType
pathMatchType
;
//文件匹配方式 路径/文件名/后缀
private
MatchType
pathMatchType
;
//文件匹配方式 路径/文件名/后缀
private
String
path
;
//文件路径匹配
private
String
path
;
//文件路径匹配
private
TextMatch
textMatching
;
//文本匹配方式 全文匹配/正则匹配
private
TextMatch
textMatching
;
//文本匹配方式 全文匹配/正则匹配
private
DealWay
dealWay
;
//替换,在匹配字之前插入,在匹配字之后插入
/**
/**
* AREA
* AREA
...
@@ -42,14 +43,14 @@ public class Rule {
...
@@ -42,14 +43,14 @@ public class Rule {
private
String
replacing
;
//更改方式 全文替换/正则替换
private
String
replacing
;
//更改方式 全文替换/正则替换
public
enum
MatchType
{
public
enum
MatchType
{
PATH
,
NAME
,
SUFFIX
PATH
,
NAME
,
SUFFIX
,
GLOB
}
}
public
enum
TextMatch
{
public
enum
TextMatch
{
AREA
AREA
,
CONTENT
}
}
public
enum
DealWay
{
public
enum
DealWay
{
REPLACE
,
INSERTAFTER
,
INSERTBEFORE
REPLACE
,
INSERTAFTER
,
INSERTBEFORE
,
InsertBetween
}
}
}
}
src/main/java/com/zjty/adaptationmaster/adaptor/service/Impl/AdaptationServiceImpl.java
浏览文件 @
cd8ae5ed
...
@@ -64,7 +64,7 @@ public class AdaptationServiceImpl implements AdaptationService {
...
@@ -64,7 +64,7 @@ public class AdaptationServiceImpl implements AdaptationService {
FileUtil
fileUtil
=
new
FileUtil
();
FileUtil
fileUtil
=
new
FileUtil
();
project
.
setCodeUrl
(
Const
.
UPLOAD_LOCATION
+
File
.
separator
+
project
.
getProjectName
());
project
.
setCodeUrl
(
Const
.
UPLOAD_LOCATION
+
File
.
separator
+
project
.
getProjectName
());
try
{
try
{
fileUtil
.
un
zip
(
path
,
project
.
getCodeUrl
());
fileUtil
.
un
Zip
(
new
File
(
path
)
,
project
.
getCodeUrl
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
src/main/java/com/zjty/adaptationmaster/adaptor/service/Impl/Adaptor.java
浏览文件 @
cd8ae5ed
...
@@ -7,6 +7,9 @@ import com.zjty.adaptationmaster.adaptor.entity.OriginalFile;
...
@@ -7,6 +7,9 @@ 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
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -59,7 +62,9 @@ public class Adaptor {
...
@@ -59,7 +62,9 @@ public class Adaptor {
public
void
doAdapt
(){
public
void
doAdapt
(){
//String regular = preprocesAdaptation();
//String regular = preprocesAdaptation();
//List<String> strings1 = preprocessRegular();
//List<String> strings1 = preprocessRegular();
Map
<
String
,
Rule
>
strings1
=
preprocessRegular
();
List
<
MatchAndRule
>
strings1
=
preprocessRegular
();
System
.
out
.
println
(
strings1
.
size
()+
"规则数量"
);
if
(
strings1
.
size
()<
1
){
if
(
strings1
.
size
()<
1
){
System
.
out
.
println
(
"检测到匹配规则为空"
);
System
.
out
.
println
(
"检测到匹配规则为空"
);
return
;
return
;
...
@@ -70,33 +75,36 @@ public class Adaptor {
...
@@ -70,33 +75,36 @@ public class Adaptor {
//记录实际具体适配内容
//记录实际具体适配内容
//List<AdaptationDetailsLogEntity> detailsLogEntities = new ArrayList<>();
//List<AdaptationDetailsLogEntity> detailsLogEntities = new ArrayList<>();
ReadedFileRepository
repository
=
new
ReadedFileRepository
();
ReadedFileRepository
repository
=
new
ReadedFileRepository
();
String
storePathParent
=
"originalFile/"
+
UUID
.
randomUUID
().
toString
();
try
{
try
{
Files
.
walkFileTree
(
Paths
.
get
(
project
.
getCodeUrl
()),
new
SimpleFileVisitor
<
Path
>()
{
Files
.
walkFileTree
(
Paths
.
get
(
project
.
getCodeUrl
()),
new
SimpleFileVisitor
<
Path
>()
{
@Override
@Override
public
FileVisitResult
visitFile
(
Path
file
,
BasicFileAttributes
attrs
)
throws
IOException
{
public
FileVisitResult
visitFile
(
Path
file
,
BasicFileAttributes
attrs
)
throws
IOException
{
// System.out.println(file);
// String pathString = file.toString();
// String pathString = file.toString();
// pathString.indexOf(System.getProperty("file.separator"),basePath.length());
// pathString.indexOf(System.getProperty("file.separator"),basePath.length());
boolean
match
=
false
;
boolean
match
=
false
;
List
<
Rule
>
thisFileMatched
=
null
;
List
<
Rule
>
thisFileMatched
=
null
;
//不符合规则的路径过滤掉
//不符合规则的路径过滤掉
for
(
String
regular:
strings1
.
keySet
())
{
for
(
MatchAndRule
regular:
strings1
)
{
if
(
FileSystems
.
getDefault
().
getPathMatcher
(
"glob:"
+
regular
).
matches
(
file
))
{
if
(
FileSystems
.
getDefault
().
getPathMatcher
(
"glob:"
+
regular
.
getMath
()).
matches
(
file
))
{
if
(
thisFileMatched
==
null
)
if
(
thisFileMatched
==
null
)
thisFileMatched
=
new
ArrayList
<>();
thisFileMatched
=
new
ArrayList
<>();
thisFileMatched
.
add
(
regular
.
getRule
());
thisFileMatched
.
add
(
strings1
.
get
(
regular
));
match
=
true
;
match
=
true
;
}
}
}
}
String
storePath
=
"originalFile/"
+
UUID
.
randomUUID
().
toString
()+
"/"
+
file
.
getFileName
();
//原先文件的新地址
Path
originalPath
=
Paths
.
get
(
basePath
+
storePath
);
File
parentFile
=
originalPath
.
toFile
().
getParentFile
();
if
(!
parentFile
.
exists
()||!
parentFile
.
isDirectory
())
parentFile
.
mkdirs
();
if
(
match
)
{
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
());
OriginalFile
originalFile
=
new
OriginalFile
(
file
.
toString
(),
originalPath
.
toString
(),
new
Date
());
originalFiles
.
add
(
originalFile
);
originalFiles
.
add
(
originalFile
);
//Files.copy(file,originalPath);
Files
.
move
(
file
,
originalPath
);
Files
.
move
(
file
,
originalPath
);
//splitedFile.setDeal(true);
//splitedFile.setDeal(true);
WebSocketServer
.
sendInfo
(
uuid
,
"过滤得到符合规则的文件"
+
file
,
"替换"
,
"过滤文件"
,
project
.
getProjectName
());
WebSocketServer
.
sendInfo
(
uuid
,
"过滤得到符合规则的文件"
+
file
,
"替换"
,
"过滤文件"
,
project
.
getProjectName
());
...
@@ -143,6 +151,7 @@ public class Adaptor {
...
@@ -143,6 +151,7 @@ public class Adaptor {
return
FileVisitResult
.
CONTINUE
;
return
FileVisitResult
.
CONTINUE
;
}
}
});
});
System
.
out
.
println
(
"遍历结束"
);
ReadedFileTask
apacheTask
=
new
ReadedFileTask
(
repository
.
getReadedFiles
(),
project
.
getProjectName
(),
uuid
);
ReadedFileTask
apacheTask
=
new
ReadedFileTask
(
repository
.
getReadedFiles
(),
project
.
getProjectName
(),
uuid
);
pool
.
submit
(
apacheTask
);
pool
.
submit
(
apacheTask
);
pool
.
shutdown
();
pool
.
shutdown
();
...
@@ -151,7 +160,7 @@ public class Adaptor {
...
@@ -151,7 +160,7 @@ public class Adaptor {
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
originalFileDao
.
saveAll
(
originalFiles
);
//
originalFileDao.saveAll(originalFiles);
//adaptationDetailLogEntityDao.saveAll(detailsLogEntities);
//adaptationDetailLogEntityDao.saveAll(detailsLogEntities);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -162,20 +171,26 @@ public class Adaptor {
...
@@ -162,20 +171,26 @@ public class Adaptor {
* 预处理适配规则,将规则实体类处理成glob表达式
* 预处理适配规则,将规则实体类处理成glob表达式
* @return
* @return
*/
*/
private
Map
<
String
,
Rule
>
preprocessRegular
()
{
private
List
<
MatchAnd
Rule
>
preprocessRegular
()
{
//List<String> result = new ArrayList<>();
//List<String> result = new ArrayList<>();
Map
<
String
,
Rule
>
result
=
new
HashMap
<>();
List
<
MatchAndRule
>
result
=
new
ArrayList
<>();
for
(
Rule
adaptorEntity
:
ruleList
)
{
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
())
{
switch
(
adaptorEntity
.
getPathMatchType
())
{
case
SUFFIX:
case
SUFFIX:
result
.
put
(
"**/**"
+
adaptorEntity
.
getPath
(),
adaptorEntity
);
result
.
add
(
new
MatchAndRule
(
"**/**"
+
adaptorEntity
.
getPath
(),
adaptorEntity
)
);
break
;
break
;
case
PATH:
case
PATH:
result
.
put
(
""
+
adaptorEntity
.
getPath
(),
adaptorEntity
);
result
.
add
(
new
MatchAndRule
(
""
+
adaptorEntity
.
getPath
(),
adaptorEntity
)
);
break
;
break
;
case
NAME:
case
NAME:
result
.
put
(
"**/"
+
adaptorEntity
.
getPath
(),
adaptorEntity
);
result
.
add
(
new
MatchAndRule
(
"**/"
+
adaptorEntity
.
getPath
(),
adaptorEntity
)
);
break
;
break
;
case
GLOB:
result
.
add
(
new
MatchAndRule
(
adaptorEntity
.
getPath
(),
adaptorEntity
));
}
}
}
}
return
result
;
return
result
;
...
@@ -267,5 +282,11 @@ public class Adaptor {
...
@@ -267,5 +282,11 @@ public class Adaptor {
}
}
}
}
@NoArgsConstructor
@AllArgsConstructor
@Data
private
class
MatchAndRule
{
private
String
math
;
private
Rule
rule
;
}
}
}
src/main/java/com/zjty/adaptationmaster/adaptor/service/Impl/InspectServiceImpl.java
浏览文件 @
cd8ae5ed
package
com
.
zjty
.
adaptationmaster
.
adaptor
.
service
.
Impl
;
package
com
.
zjty
.
adaptationmaster
.
adaptor
.
service
.
Impl
;
import
com.zjty.adaptationmaster.adaptor.entity.Project
;
import
com.zjty.adaptationmaster.adaptor.entity.Project
;
import
com.zjty.adaptationmaster.adaptor.entity.Report
;
import
com.zjty.adaptationmaster.adaptor.repository.ProjectDao
;
import
com.zjty.adaptationmaster.adaptor.repository.ProjectDao
;
import
com.zjty.adaptationmaster.adaptor.service.InspectService
;
import
com.zjty.adaptationmaster.adaptor.service.InspectService
;
import
com.zjty.adaptationmaster.base.response.ServerResponse
;
import
com.zjty.adaptationmaster.base.response.ServerResponse
;
...
@@ -11,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
...
@@ -11,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
@Service
@Service
public
class
InspectServiceImpl
implements
InspectService
{
public
class
InspectServiceImpl
implements
InspectService
{
...
@@ -21,6 +23,13 @@ public class InspectServiceImpl implements InspectService {
...
@@ -21,6 +23,13 @@ public class InspectServiceImpl implements InspectService {
@Override
@Override
public
ServerResponse
inspect
(
Project
project
)
{
public
ServerResponse
inspect
(
Project
project
)
{
//Project project = projectDao.getOne(projectId);
//Project project = projectDao.getOne(projectId);
return
ServerResponse
.
success
(
new
Inspector
(
project
,
new
HashMap
<>(),
new
HashMap
<>()
/*,new ArrayList<>()*/
).
inspect
());
Map
<
String
,
Report
.
Language
>
suffixLanguageMapping
=
new
HashMap
<>();
suffixLanguageMapping
.
put
(
"java"
,
Report
.
Language
.
JAVA
);
suffixLanguageMapping
.
put
(
"cpp"
,
Report
.
Language
.
CPP
);
suffixLanguageMapping
.
put
(
"py"
,
Report
.
Language
.
PYTHON
);
suffixLanguageMapping
.
put
(
"jsp"
,
Report
.
Language
.
JSP
);
//suffixLanguageMapping.put("html",Report.Language.ONLYVIEW);
return
ServerResponse
.
success
(
new
Inspector
(
project
,
suffixLanguageMapping
).
inspect
());
}
}
}
}
src/main/java/com/zjty/adaptationmaster/utils/FileUtil.java
浏览文件 @
cd8ae5ed
差异被折叠。
点击展开。
src/main/java/com/zjty/adaptationmaster/utils/Inspector.java
浏览文件 @
cd8ae5ed
差异被折叠。
点击展开。
src/main/java/com/zjty/adaptationmaster/utils/MavenCompiler.java
浏览文件 @
cd8ae5ed
...
@@ -25,7 +25,7 @@ public class MavenCompiler {
...
@@ -25,7 +25,7 @@ public class MavenCompiler {
public
void
compiler
(){
public
void
compiler
(){
InvocationRequest
request
=
new
DefaultInvocationRequest
();
InvocationRequest
request
=
new
DefaultInvocationRequest
();
request
.
setPomFile
(
new
File
(
project
.
getReport
().
getCompileFilePath
()));
request
.
setPomFile
(
new
File
(
project
.
getReport
().
getCompileFilePath
()));
request
.
setGoals
(
Collections
.
singletonList
(
"
compil
e"
));
request
.
setGoals
(
Collections
.
singletonList
(
"
packag
e"
));
Invoker
invoker
=
new
DefaultInvoker
();
Invoker
invoker
=
new
DefaultInvoker
();
invoker
.
setMavenHome
(
new
File
(
mavenHome
));
invoker
.
setMavenHome
(
new
File
(
mavenHome
));
...
...
src/main/java/com/zjty/adaptationmaster/utils/ReadedFileTask.java
浏览文件 @
cd8ae5ed
...
@@ -11,6 +11,7 @@ import java.io.*;
...
@@ -11,6 +11,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,7 +21,11 @@ public class ReadedFileTask implements Runnable {
...
@@ -20,7 +21,11 @@ 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
;
}
}
...
@@ -29,6 +34,7 @@ public class ReadedFileTask implements Runnable {
...
@@ -29,6 +34,7 @@ public class ReadedFileTask implements Runnable {
private
int
index
;
private
int
index
;
public
void
setBySort
(
Adaptor
.
WriterBySort
bySort
)
{
public
void
setBySort
(
Adaptor
.
WriterBySort
bySort
)
{
System
.
out
.
println
(
"线程遇到大文件"
);
this
.
bySort
=
bySort
;
this
.
bySort
=
bySort
;
}
}
...
@@ -38,42 +44,90 @@ public class ReadedFileTask implements Runnable {
...
@@ -38,42 +44,90 @@ public class ReadedFileTask implements Runnable {
@Override
@Override
public
void
run
()
{
public
void
run
()
{
for
(
ReadedFile
readedFile:
readedFiles
){
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
();
String
content
=
readedFile
.
getContent
();
System
.
out
.
println
(
"规则数量"
+
readedFile
.
getThisMatchedRule
().
size
());
System
.
out
.
println
(
"规则数量"
+
readedFile
.
getThisMatchedRule
().
size
());
for
(
Rule
entity:
readedFile
.
getThisMatchedRule
())
{
for
(
Rule
entity
:
readedFile
.
getThisMatchedRule
())
{
System
.
out
.
println
(
"文本匹配方式"
+
entity
.
getTextMatching
());
System
.
out
.
println
(
"文本匹配方式"
+
entity
.
getTextMatching
());
switch
(
entity
.
getTextMatching
()){
switch
(
entity
.
getTextMatching
())
{
case
AREA:
case
AREA:
System
.
out
.
println
(
"case"
);
String
[]
split
=
entity
.
getTarget
().
split
(
"\\|\\|"
);
String
[]
split
=
entity
.
getTarget
().
split
(
"\\|\\|"
);
String
begin
=
split
[
0
];
String
begin
=
split
[
0
];
String
matching
=
split
[
1
];
String
matching
=
split
[
1
];
String
end
=
split
[
2
];
String
end
=
split
[
2
];
System
.
out
.
println
(
begin
+
"||"
+
matching
+
"||"
+
end
);
System
.
out
.
println
(
begin
+
"||"
+
matching
+
"||"
+
end
);
int
i
=
content
.
indexOf
(
matching
);
int
i
=
content
.
indexOf
(
matching
);
if
(
i
>-
1
){
if
(
i
>
-
1
)
{
WebSocketServer
.
sendInfo
(
uuid
,
readedFile
.
getPath
().
getFileName
()+
":"
+
matching
+
" 替换为 "
+
entity
.
getReplacing
(),
"替换"
,
"正在替换"
,
projectName
);
System
.
out
.
println
(
"i"
+
i
);
WebSocketServer
.
sendInfo
(
uuid
,
readedFile
.
getPath
().
getFileName
()
+
":"
+
matching
+
" 替换为 "
+
entity
.
getReplacing
(),
"替换"
,
"正在替换"
,
projectName
);
int
beginIndex
=
content
.
lastIndexOf
(
begin
,
i
);
int
beginIndex
=
content
.
lastIndexOf
(
begin
,
i
);
int
endIndex
=
content
.
indexOf
(
end
,
i
+
1
);
int
endIndex
=
content
.
indexOf
(
end
,
i
+
1
);
if
(
beginIndex
>-
1
&&
endIndex
>-
1
)
{
if
(
beginIndex
>
-
1
&&
endIndex
>
-
1
)
{
content
=
content
.
substring
(
0
,
beginIndex
)+
entity
.
getReplacing
()+
content
.
substring
(
endIndex
+
end
.
length
());
content
=
content
.
substring
(
0
,
beginIndex
)
+
entity
.
getReplacing
()
+
content
.
substring
(
endIndex
+
end
.
length
());
}
}
}
}
else
{
}
//container.add(readedFile.getPath().getFileName()+"文本替换:"+entity.getTextMatching()+"|"+entity.getReplacing());
//template.convertAndSend("===="+readedFile.getPath().getFileName()+"////"+entity.getTextMatching()+"||||"+entity.getReplacing(),"1L");
System
.
out
.
println
(
"-i"
+
i
);
//responseWriter.write("===="+readedFile.getPath().getFileName()+"////"+entity.getTextMatching()+"||||"+entity.getReplacing());
}
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
{
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 +137,7 @@ public class ReadedFileTask implements Runnable {
...
@@ -83,6 +137,7 @@ public class ReadedFileTask implements Runnable {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
}
}
...
...
src/test/java/com/zjty/adaptationmaster/TestAdapt.java
0 → 100644
浏览文件 @
cd8ae5ed
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"
));
}
}
src/test/java/com/zjty/adaptationmaster/TestProcess.java
0 → 100644
浏览文件 @
cd8ae5ed
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论