Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
I
inspect
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
项目监控管理工具
inspect
Commits
031e5f4c
提交
031e5f4c
authored
3月 16, 2020
作者:
马晨俊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mcj:新增如果不上传源代码的逻辑
上级
f4b91a89
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
134 行增加
和
130 行删除
+134
-130
InspectController.java
...n/java/com/zjty/inspect/controller/InspectController.java
+52
-52
Inspector.java
src/main/java/com/zjty/inspect/inspect/Inspector.java
+82
-78
没有找到文件。
src/main/java/com/zjty/inspect/controller/InspectController.java
浏览文件 @
031e5f4c
...
@@ -51,11 +51,12 @@ public class InspectController {
...
@@ -51,11 +51,12 @@ public class InspectController {
@Autowired
@Autowired
private
ConfigParamDao
configParamDao
;
private
ConfigParamDao
configParamDao
;
//应用类型转换:小型0
//应用类型转换:小型0
Integer
[]
small
=
{
3
,
4
};
Integer
[]
small
=
{
3
,
4
};
//应用类型转换:中型2
//应用类型转换:中型2
private
Integer
[]
middle
=
{
1
,
2
,
6
,
7
,
8
,
10
};
private
Integer
[]
middle
=
{
1
,
2
,
6
,
7
,
8
,
10
};
//应用类型转换:大型4
//应用类型转换:大型4
private
Integer
[]
big
=
{
5
,
9
};
private
Integer
[]
big
=
{
5
,
9
};
/**
/**
* 上传代码进行评估
* 上传代码进行评估
*
*
...
@@ -76,12 +77,17 @@ public class InspectController {
...
@@ -76,12 +77,17 @@ public class InspectController {
@ApiOperation
(
"上传代码进行评估"
)
@ApiOperation
(
"上传代码进行评估"
)
public
ResponseEntity
inspect
(
Integer
years
,
Integer
systemFund
,
Integer
modules
public
ResponseEntity
inspect
(
Integer
years
,
Integer
systemFund
,
Integer
modules
,
String
valid
,
Integer
framework
,
Integer
safety
,
Integer
disaster
,
Integer
data
,
String
valid
,
Integer
framework
,
Integer
safety
,
Integer
disaster
,
Integer
data
,
Integer
admin
,
String
projectName
,
Integer
tables
,
String
databaseType
,
Integer
content
,
Integer
method
,
String
username
,
MultipartFile
multfile
)
throws
IOException
{
,
Integer
admin
,
String
projectName
,
Integer
tables
,
String
databaseType
,
Integer
content
,
Integer
method
,
String
username
,
MultipartFile
multfile
)
throws
IOException
{
File
file
=
FileUtil
.
saveToLocal
(
multfile
);
log
.
info
(
"inspect:代码解压完成,地址为{}"
,
file
.
getCanonicalPath
());
InspectParameter
inspectParameter
=
new
InspectParameter
();
InspectParameter
inspectParameter
=
new
InspectParameter
();
ReportVo
reportVo
=
new
ReportVo
();
if
(
multfile
!=
null
)
{
File
file
=
FileUtil
.
saveToLocal
(
multfile
);
log
.
info
(
"inspect:代码解压完成,地址为{}"
,
file
.
getCanonicalPath
());
inspectParameter
.
setSourceAddress
(
file
.
getCanonicalPath
());
reportVo
.
setFileName
(
file
.
getName
());
reportVo
.
setSourceAddress
(
file
.
getCanonicalPath
());
}
inspectParameter
.
setUsername
(
username
);
inspectParameter
.
setUsername
(
username
);
inspectParameter
.
setSystemFund
(
systemFund
);
inspectParameter
.
setSystemFund
(
systemFund
);
inspectParameter
.
setModules
(
modules
);
inspectParameter
.
setModules
(
modules
);
...
@@ -97,14 +103,9 @@ public class InspectController {
...
@@ -97,14 +103,9 @@ public class InspectController {
inspectParameter
.
setAdmin
(
admin
);
inspectParameter
.
setAdmin
(
admin
);
inspectParameter
.
setSystemFund
(
systemFund
);
inspectParameter
.
setSystemFund
(
systemFund
);
inspectParameter
.
setRecastMethod
(
method
);
inspectParameter
.
setRecastMethod
(
method
);
inspectParameter
.
setSourceAddress
(
file
.
getCanonicalPath
());
ReportVo
reportVo
=
new
ReportVo
();
reportVo
.
setId
(
RandomUtil
.
getRandom
());
reportVo
.
setId
(
RandomUtil
.
getRandom
());
reportVo
.
setUploadType
(
"文件上传"
);
reportVo
.
setUploadType
(
"文件上传"
);
reportVo
.
setFileName
(
file
.
getName
());
reportVo
.
setProjectName
(
projectName
);
reportVo
.
setProjectName
(
projectName
);
reportVo
.
setSourceAddress
(
file
.
getCanonicalPath
());
reportVo
.
setDatabaseType
(
databaseType
);
reportVo
.
setDatabaseType
(
databaseType
);
ReportVo
inspect
=
inspectService
.
inspect
(
reportVo
,
inspectParameter
);
ReportVo
inspect
=
inspectService
.
inspect
(
reportVo
,
inspectParameter
);
...
@@ -113,11 +114,9 @@ public class InspectController {
...
@@ -113,11 +114,9 @@ public class InspectController {
int
support
=
technologyService
.
findAllTechnologyNotSupport
();
int
support
=
technologyService
.
findAllTechnologyNotSupport
();
reportVo
.
setTechnologiesRepair
(
support
);
reportVo
.
setTechnologiesRepair
(
support
);
log
.
info
(
"inspect:代码评估完成"
);
log
.
info
(
"inspect:代码评估完成"
);
// String filePath = inspectService.freemakerData(inspect,count,support);
reportVo
.
setHtmlAddress
(
null
);
reportVo
.
setHtmlAddress
(
null
);
Report
report
=
new
Report
();
Report
report
=
new
Report
();
String
random
=
RandomUtil
.
getRandom
();
report
.
setId
(
RandomUtil
.
getRandom
());
report
.
setId
(
RandomUtil
.
getRandom
());
report
.
setHtmlAddress
(
reportVo
.
getHtmlAddress
());
report
.
setHtmlAddress
(
reportVo
.
getHtmlAddress
());
reportService
.
saveReport
(
report
);
reportService
.
saveReport
(
report
);
...
@@ -135,10 +134,10 @@ public class InspectController {
...
@@ -135,10 +134,10 @@ public class InspectController {
public
ResponseEntity
rapidAssessment
(
@RequestBody
Reform
reform
)
throws
IOException
{
public
ResponseEntity
rapidAssessment
(
@RequestBody
Reform
reform
)
throws
IOException
{
//输入参数
//输入参数
String
in
=
JSON
.
toJSONString
(
reform
);
String
in
=
JSON
.
toJSONString
(
reform
);
Evaluation
evaluation
=
new
Evaluation
();
Evaluation
evaluation
=
new
Evaluation
();
evaluation
.
setInEva
(
in
);
evaluation
.
setInEva
(
in
);
//判断评估类型
//判断评估类型
if
(
reform
.
getAssessmentType
()!=
null
&&
reform
.
getAssessmentType
()
==
1
)
{
if
(
reform
.
getAssessmentType
()
!=
null
&&
reform
.
getAssessmentType
()
==
1
)
{
//快速评估
//快速评估
reform
.
setSystemStructure
(
new
SystemStructure
());
reform
.
setSystemStructure
(
new
SystemStructure
());
reform
.
setBrowser
(
new
Browser
());
reform
.
setBrowser
(
new
Browser
());
...
@@ -150,36 +149,36 @@ public class InspectController {
...
@@ -150,36 +149,36 @@ public class InspectController {
//获取admin
//获取admin
Config
adminConfig
=
configParamDao
.
findByName
(
"admin"
);
Config
adminConfig
=
configParamDao
.
findByName
(
"admin"
);
Integer
admin
;
Integer
admin
;
if
(
adminConfig
!=
null
)
{
if
(
adminConfig
!=
null
)
{
admin
=
Integer
.
valueOf
(
adminConfig
.
getValue
());
admin
=
Integer
.
valueOf
(
adminConfig
.
getValue
());
}
else
{
}
else
{
admin
=
2
;
admin
=
2
;
}
}
System
.
out
.
println
(
"admin:"
+
admin
);
System
.
out
.
println
(
"admin:"
+
admin
);
System
.
out
.
println
(
JSON
.
toJSONString
(
reform
));
System
.
out
.
println
(
JSON
.
toJSONString
(
reform
));
//架构类型
//架构类型
Integer
framework
=
reform
.
getFramework
();
Integer
framework
=
reform
.
getFramework
();
if
(
framework
!=
null
&&
framework
==
1
)
{
if
(
framework
!=
null
&&
framework
==
1
)
{
framework
=
2
;
framework
=
2
;
}
}
//应用类型
//应用类型
Integer
content
=
0
;
Integer
content
=
0
;
List
<
Integer
>
applicationType
=
reform
.
getApplicationType
();
List
<
Integer
>
applicationType
=
reform
.
getApplicationType
();
if
(
applicationType
==
null
||
applicationType
.
size
()==
0
)
{
if
(
applicationType
==
null
||
applicationType
.
size
()
==
0
)
{
content
=
-
1
;
content
=
-
1
;
}
else
{
}
else
{
for
(
Integer
type
:
applicationType
)
{
for
(
Integer
type
:
applicationType
)
{
if
(
Arrays
.
asList
(
middle
).
contains
(
type
))
{
if
(
Arrays
.
asList
(
middle
).
contains
(
type
))
{
if
(
content
<
2
)
{
if
(
content
<
2
)
{
content
=
2
;
content
=
2
;
}
}
}
else
if
(
Arrays
.
asList
(
big
).
contains
(
type
))
{
}
else
if
(
Arrays
.
asList
(
big
).
contains
(
type
))
{
content
=
4
;
content
=
4
;
break
;
break
;
}
}
}
}
}
}
System
.
out
.
println
(
"content:"
+
content
);
System
.
out
.
println
(
"content:"
+
content
);
InspectParameter
inspectParameter
=
new
InspectParameter
();
InspectParameter
inspectParameter
=
new
InspectParameter
();
inspectParameter
.
setContent
(
content
);
inspectParameter
.
setContent
(
content
);
...
@@ -204,16 +203,16 @@ public class InspectController {
...
@@ -204,16 +203,16 @@ public class InspectController {
int
support
=
technologyService
.
findAllTechnologyNotSupport
();
int
support
=
technologyService
.
findAllTechnologyNotSupport
();
reportVo
.
setTechnologiesRepair
(
support
);
reportVo
.
setTechnologiesRepair
(
support
);
reportVo
.
setId
(
RandomUtil
.
getRandom
());
reportVo
.
setId
(
RandomUtil
.
getRandom
());
if
(
reform
.
getGitUrl
()==
null
)
{
if
(
reform
.
getGitUrl
()
==
null
)
{
reportVo
.
setUploadType
(
"文件上传"
);
reportVo
.
setUploadType
(
"文件上传"
);
}
else
{
}
else
{
reportVo
.
setUploadType
(
"git下载"
);
reportVo
.
setUploadType
(
"git下载"
);
}
}
reportVo
.
setFileName
(
reform
.
getCodeName
());
reportVo
.
setFileName
(
reform
.
getCodeName
());
reportVo
.
setProjectName
(
reform
.
getProjectName
());
reportVo
.
setProjectName
(
reform
.
getProjectName
());
reportVo
.
setSourceAddress
(
reform
.
getCodeUrl
());
reportVo
.
setSourceAddress
(
reform
.
getCodeUrl
());
reportVo
.
setDatabaseType
(
null
);
reportVo
.
setDatabaseType
(
null
);
ReportVo
inspect
=
inspectService
.
inspect
(
reportVo
,
inspectParameter
);
ReportVo
inspect
=
inspectService
.
inspect
(
reportVo
,
inspectParameter
);
log
.
info
(
"inspect:代码评估完成"
);
log
.
info
(
"inspect:代码评估完成"
);
Report
report
=
new
Report
();
Report
report
=
new
Report
();
String
random
=
RandomUtil
.
getRandom
();
String
random
=
RandomUtil
.
getRandom
();
...
@@ -236,9 +235,9 @@ public class InspectController {
...
@@ -236,9 +235,9 @@ public class InspectController {
将马晨俊的数据放入输出的表单
将马晨俊的数据放入输出的表单
*/
*/
AssessmentReport
assessmentReport
=
new
AssessmentReport
();
AssessmentReport
assessmentReport
=
new
AssessmentReport
();
if
(
reform
.
getMode
()==
1
&&
inspect
.
getLanguage
()!=
1
)
{
if
(
reform
.
getMode
()
==
1
&&
inspect
.
getLanguage
()
!=
1
)
{
assessmentReport
.
setCode
(
500
);
assessmentReport
.
setCode
(
500
);
}
else
{
}
else
{
assessmentReport
.
setCode
(
200
);
assessmentReport
.
setCode
(
200
);
}
}
//架构
//架构
...
@@ -284,33 +283,33 @@ public class InspectController {
...
@@ -284,33 +283,33 @@ public class InspectController {
HashMap
<
String
,
List
<
Warn
>>
warnDetails
=
inspect
.
getWarnDetails
();
HashMap
<
String
,
List
<
Warn
>>
warnDetails
=
inspect
.
getWarnDetails
();
Set
<
String
>
keySet
=
warnDetails
.
keySet
();
Set
<
String
>
keySet
=
warnDetails
.
keySet
();
List
<
TechnologyReport
>
technologyReports
=
new
ArrayList
<>();
List
<
TechnologyReport
>
technologyReports
=
new
ArrayList
<>();
for
(
String
key
:
keySet
)
{
for
(
String
key
:
keySet
)
{
List
<
Warn
>
warns
=
warnDetails
.
get
(
key
);
List
<
Warn
>
warns
=
warnDetails
.
get
(
key
);
if
(
warns
.
size
()>
0
)
{
if
(
warns
.
size
()
>
0
)
{
TechnologyReport
technologyReport
=
new
TechnologyReport
();
TechnologyReport
technologyReport
=
new
TechnologyReport
();
technologyReport
.
setTechnology
(
key
);
technologyReport
.
setTechnology
(
key
);
//少一个策略
//少一个策略
List
<
TechnologyContent
>
technologyContents
=
new
ArrayList
<>();
List
<
TechnologyContent
>
technologyContents
=
new
ArrayList
<>();
for
(
Warn
warn
:
warns
)
{
for
(
Warn
warn
:
warns
)
{
TechnologyContent
technologyContent
=
new
TechnologyContent
();
TechnologyContent
technologyContent
=
new
TechnologyContent
();
//technologyContent.setLocal(warn.get);
//technologyContent.setLocal(warn.get);
technologyContent
.
setFile
(
warn
.
getFilePath
());
technologyContent
.
setFile
(
warn
.
getFilePath
());
technologyContent
.
setKeyWord
(
warn
.
getRule
());
technologyContent
.
setKeyWord
(
warn
.
getRule
());
technologyContent
.
setPosition
(
warn
.
getLineNum
().
toString
());
technologyContent
.
setPosition
(
warn
.
getLineNum
().
toString
());
String
categoryId
=
warn
.
getCategoryId
();
String
categoryId
=
warn
.
getCategoryId
();
if
(!
Objects
.
equals
(
categoryId
,
"0"
)
&&
categoryId
!=
null
&&
Objects
.
equals
(
categoryId
,
"1"
)
if
(!
Objects
.
equals
(
categoryId
,
"0"
)
&&
categoryId
!=
null
&&
Objects
.
equals
(
categoryId
,
"1"
)
&&
(
key
.
contains
(
"不支持"
)
||
key
.
contains
(
"未知"
))){
&&
(
key
.
contains
(
"不支持"
)
||
key
.
contains
(
"未知"
)))
{
number
+=
1
;
number
+=
1
;
}
}
technologyContents
.
add
(
technologyContent
);
technologyContents
.
add
(
technologyContent
);
}
}
if
(
Objects
.
equals
(
key
,
"Microsoft CSS extensions(不支持)"
))
{
if
(
Objects
.
equals
(
key
,
"Microsoft CSS extensions(不支持)"
))
{
css
=
technologyContents
.
size
();
css
=
technologyContents
.
size
();
}
else
if
(
Objects
.
equals
(
key
,
"Microsoft API extensions(不支持)"
))
{
}
else
if
(
Objects
.
equals
(
key
,
"Microsoft API extensions(不支持)"
))
{
api
=
technologyContents
.
size
();
api
=
technologyContents
.
size
();
}
else
if
(
Objects
.
equals
(
key
,
"Microsoft JavaScript extensions(不支持)"
))
{
}
else
if
(
Objects
.
equals
(
key
,
"Microsoft JavaScript extensions(不支持)"
))
{
plugIn
=
technologyContents
.
size
();
plugIn
=
technologyContents
.
size
();
}
else
if
(
Objects
.
equals
(
key
,
"JNI(不支持)"
))
{
}
else
if
(
Objects
.
equals
(
key
,
"JNI(不支持)"
))
{
jni
=
technologyContents
.
size
();
jni
=
technologyContents
.
size
();
}
}
technologyReport
.
setTechnologyContents
(
technologyContents
);
technologyReport
.
setTechnologyContents
(
technologyContents
);
...
@@ -349,7 +348,7 @@ public class InspectController {
...
@@ -349,7 +348,7 @@ public class InspectController {
browserDifficulty
.
setDocument
(
browser
.
getDocument
());
browserDifficulty
.
setDocument
(
browser
.
getDocument
());
browserDifficulty
.
setMedia
(
browser
.
getMedia
());
browserDifficulty
.
setMedia
(
browser
.
getMedia
());
browserDifficulty
.
setFlash
(
browser
.
getFlash
());
browserDifficulty
.
setFlash
(
browser
.
getFlash
());
System
.
out
.
println
(
"BrowserDifficulty:"
+
JSON
.
toJSONString
(
browserDifficulty
));
System
.
out
.
println
(
"BrowserDifficulty:"
+
JSON
.
toJSONString
(
browserDifficulty
));
difficultyAssessment
.
setBrowserDifficulty
(
browserDifficulty
);
difficultyAssessment
.
setBrowserDifficulty
(
browserDifficulty
);
//中间件难度
//中间件难度
MiddlewareDifficulty
middlewareDifficulty
=
new
MiddlewareDifficulty
();
MiddlewareDifficulty
middlewareDifficulty
=
new
MiddlewareDifficulty
();
...
@@ -387,7 +386,7 @@ public class InspectController {
...
@@ -387,7 +386,7 @@ public class InspectController {
middlewareDifficulty
.
setJms
(
middleware
.
getJms
());
middlewareDifficulty
.
setJms
(
middleware
.
getJms
());
middlewareDifficulty
.
setJndi
(
middleware
.
getJndi
());
middlewareDifficulty
.
setJndi
(
middleware
.
getJndi
());
middlewareDifficulty
.
setRoute
(
middleware
.
getRoute
());
middlewareDifficulty
.
setRoute
(
middleware
.
getRoute
());
System
.
out
.
println
(
"middlewareDifficulty"
+
JSON
.
toJSONString
(
middlewareDifficulty
));
System
.
out
.
println
(
"middlewareDifficulty"
+
JSON
.
toJSONString
(
middlewareDifficulty
));
difficultyAssessment
.
setMiddlewareDifficulty
(
middlewareDifficulty
);
difficultyAssessment
.
setMiddlewareDifficulty
(
middlewareDifficulty
);
//数据库难度
//数据库难度
DatabaseDifficulty
databaseDifficulty
=
new
DatabaseDifficulty
();
DatabaseDifficulty
databaseDifficulty
=
new
DatabaseDifficulty
();
...
@@ -401,11 +400,11 @@ public class InspectController {
...
@@ -401,11 +400,11 @@ public class InspectController {
//本地程序难度
//本地程序难度
ProgramDifficulty
programDifficulty
=
new
ProgramDifficulty
();
ProgramDifficulty
programDifficulty
=
new
ProgramDifficulty
();
List
<
DependOnNum
>
dependOns
=
new
ArrayList
<>();
List
<
DependOnNum
>
dependOns
=
new
ArrayList
<>();
DependOnNum
dependOnNum2
=
new
DependOnNum
(
"jni"
,
jni
);
DependOnNum
dependOnNum2
=
new
DependOnNum
(
"jni"
,
jni
);
dependOns
.
add
(
dependOnNum2
);
dependOns
.
add
(
dependOnNum2
);
programDifficulty
.
setDependOnNum
(
dependOns
);
programDifficulty
.
setDependOnNum
(
dependOns
);
difficultyAssessment
.
setProgramDifficulty
(
programDifficulty
);
difficultyAssessment
.
setProgramDifficulty
(
programDifficulty
);
System
.
out
.
println
(
"programDifficulty+:"
+
JSON
.
toJSONString
(
programDifficulty
));
System
.
out
.
println
(
"programDifficulty+:"
+
JSON
.
toJSONString
(
programDifficulty
));
assessmentReport
.
setDifficultyAssessment
(
difficultyAssessment
);
assessmentReport
.
setDifficultyAssessment
(
difficultyAssessment
);
WorkLoadUtil
workLoadUtil
=
new
WorkLoadUtil
();
WorkLoadUtil
workLoadUtil
=
new
WorkLoadUtil
();
//r:人工费
//r:人工费
...
@@ -413,8 +412,8 @@ public class InspectController {
...
@@ -413,8 +412,8 @@ public class InspectController {
//restTemplate.exchange("localhost:8079/config", HttpMethod.GET,new HttpEntity<>())
//restTemplate.exchange("localhost:8079/config", HttpMethod.GET,new HttpEntity<>())
//计算f
//计算f
Budget
budget
=
inspect
.
getBudgets
().
getBudget
().
get
(
0
);
Budget
budget
=
inspect
.
getBudgets
().
getBudget
().
get
(
0
);
double
f
=
budget
.
getProportion
()
*
budget
.
getSysFund
()*
budget
.
getMoneyRate
()*
budget
.
getCoefficient
();
double
f
=
budget
.
getProportion
()
*
budget
.
getSysFund
()
*
budget
.
getMoneyRate
()
*
budget
.
getCoefficient
();
System
.
out
.
println
(
"F:"
+
f
);
System
.
out
.
println
(
"F:"
+
f
);
workLoadUtil
.
result
(
reform
,
assessmentReport
,
f
,
1.5
);
workLoadUtil
.
result
(
reform
,
assessmentReport
,
f
,
1.5
);
...
@@ -431,23 +430,24 @@ public class InspectController {
...
@@ -431,23 +430,24 @@ public class InspectController {
}
}
@PostMapping
(
"/uploads"
)
@PostMapping
(
"/uploads"
)
private
ResponseEntity
uploads
(
@RequestParam
(
value
=
"file"
)
MultipartFile
multfile
,
String
s
)
{
private
ResponseEntity
uploads
(
@RequestParam
(
value
=
"file"
)
MultipartFile
multfile
,
String
s
)
{
try
{
try
{
File
file
=
FileUtil
.
saveToLocal
(
multfile
);
File
file
=
FileUtil
.
saveToLocal
(
multfile
);
String
name
=
file
.
getName
();
String
name
=
file
.
getName
();
String
path
=
file
.
getCanonicalPath
();
String
path
=
file
.
getCanonicalPath
();
return
ResponseEntity
.
ok
(
new
com
.
zjty
.
inspect
.
entity
.
File
(
name
,
path
));
return
ResponseEntity
.
ok
(
new
com
.
zjty
.
inspect
.
entity
.
File
(
name
,
path
));
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
return
ResponseEntity
.
ok
(
"上传失败"
);
return
ResponseEntity
.
ok
(
"上传失败"
);
}
}
}
}
@PostMapping
(
"/gitdownload"
)
@PostMapping
(
"/gitdownload"
)
private
ResponseEntity
gitDownloads
(
String
gitAddress
,
String
username
,
String
password
)
{
private
ResponseEntity
gitDownloads
(
String
gitAddress
,
String
username
,
String
password
)
{
try
{
try
{
String
gitPath
=
GitLabUtil
.
downLoadProject
(
gitAddress
,
username
,
password
);
String
gitPath
=
GitLabUtil
.
downLoadProject
(
gitAddress
,
username
,
password
);
return
ResponseEntity
.
ok
(
gitPath
);
return
ResponseEntity
.
ok
(
gitPath
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
status
(
400
).
build
();
return
ResponseEntity
.
status
(
400
).
build
();
}
}
}
}
...
...
src/main/java/com/zjty/inspect/inspect/Inspector.java
浏览文件 @
031e5f4c
...
@@ -144,11 +144,13 @@ public class Inspector {
...
@@ -144,11 +144,13 @@ public class Inspector {
public
ReportVo
inspect
()
throws
IOException
{
public
ReportVo
inspect
()
throws
IOException
{
//初始化值
//初始化值
initData
();
initData
();
//扫描文件
scanFiles
();
scanFiles
();
inspectParameter
.
setCodeSize
((
int
)
codeSize
);
inspectParameter
.
setCodeSize
((
int
)
codeSize
);
report
.
setFileNum
(
fileNum
);
report
.
setFileNum
(
fileNum
);
report
.
setFileLine
(
fileLine
);
report
.
setFileLine
(
fileLine
);
log
.
info
(
"inspect:源代码扫描完成,统计各个文件后缀完成"
);
log
.
info
(
"inspect:源代码扫描完成,统计各个文件后缀完成"
);
//统计项目语言
setReportLanguageAndFrame
();
setReportLanguageAndFrame
();
//根据扫描结果以及用户配置得出需要使用的规则及技术
//根据扫描结果以及用户配置得出需要使用的规则及技术
ruleTransform
(
report
.
getRecastMethod
());
ruleTransform
(
report
.
getRecastMethod
());
...
@@ -537,94 +539,96 @@ public class Inspector {
...
@@ -537,94 +539,96 @@ public class Inspector {
}
}
//文件读取
//文件读取
Files
.
walkFileTree
(
Paths
.
get
(
inspectParameter
.
getSourceAddress
()),
new
FileVisitor
<
Path
>()
{
if
(
inspectParameter
.
getSourceAddress
()!=
null
){
@Override
Files
.
walkFileTree
(
Paths
.
get
(
inspectParameter
.
getSourceAddress
()),
new
FileVisitor
<
Path
>()
{
public
FileVisitResult
preVisitDirectory
(
Path
dir
,
BasicFileAttributes
attrs
)
throws
IOException
{
@Override
public
FileVisitResult
preVisitDirectory
(
Path
dir
,
BasicFileAttributes
attrs
)
throws
IOException
{
return
FileVisitResult
.
CONTINUE
;
return
FileVisitResult
.
CONTINUE
;
}
}
@Override
@Override
public
FileVisitResult
visitFile
(
Path
file
,
BasicFileAttributes
attrs
)
{
public
FileVisitResult
visitFile
(
Path
file
,
BasicFileAttributes
attrs
)
{
//扫描jar文件时
//扫描jar文件时
if
(
file
.
getFileName
().
toString
().
endsWith
(
".jar"
))
{
if
(
file
.
getFileName
().
toString
().
endsWith
(
".jar"
))
{
//新建一个pom对象
//新建一个pom对象
ProjectPom
projectPom
=
new
ProjectPom
();
ProjectPom
projectPom
=
new
ProjectPom
();
//截取jar名称
//截取jar名称
String
patten
=
RegexUtil
.
patten
(
file
.
getFileName
().
toString
());
String
patten
=
RegexUtil
.
patten
(
file
.
getFileName
().
toString
());
//新建一个依赖对象
//新建一个依赖对象
PomDependency
pomDependency
=
new
PomDependency
();
PomDependency
pomDependency
=
new
PomDependency
();
pomDependency
.
setArtifactId
(
patten
);
pomDependency
.
setArtifactId
(
patten
);
projectPom
.
getDependencies
().
add
(
pomDependency
);
projectPom
.
getDependencies
().
add
(
pomDependency
);
//当参数为1时代表上传者管理员,代码可绝对信任,将jar名称当作可支持依赖添加进规则库中
//当参数为1时代表上传者管理员,代码可绝对信任,将jar名称当作可支持依赖添加进规则库中
if
(
inspectParameter
.
getAdmin
()
==
1
)
{
if
(
inspectParameter
.
getAdmin
()
==
1
)
{
//新建规则对象
//新建规则对象
Rule
rule
=
new
Rule
();
Rule
rule
=
new
Rule
();
//设置适配技术id
//设置适配技术id
rule
.
setTechnologyId
(
techJavaSupport
.
getId
());
rule
.
setTechnologyId
(
techJavaSupport
.
getId
());
rule
.
setTarget
(
patten
);
rule
.
setTarget
(
patten
);
//设置文件后缀
//设置文件后缀
rule
.
setSuffix
(
"*"
);
rule
.
setSuffix
(
"*"
);
rule
.
setId
(
UUIDUtil
.
getUUID
());
rule
.
setId
(
UUIDUtil
.
getUUID
());
rule
.
setTechnologyName
(
techJavaSupport
.
getTechnologyName
());
rule
.
setTechnologyName
(
techJavaSupport
.
getTechnologyName
());
//做规则查询,不用去数据库查询
//做规则查询,不用去数据库查询
if
(!
ruleMap
.
containsKey
(
patten
+
":"
+
rule
.
getSuffix
()))
{
if
(!
ruleMap
.
containsKey
(
patten
+
":"
+
rule
.
getSuffix
()))
{
rules
.
add
(
rule
);
rules
.
add
(
rule
);
ruleMap
.
put
(
patten
+
":"
+
rule
.
getSuffix
(),
rule
);
ruleMap
.
put
(
patten
+
":"
+
rule
.
getSuffix
(),
rule
);
}
//设置当前依赖为可支持
pomDependency
.
setSupport
(
1
);
}
else
{
//为普通用户上传,依赖需要检查是否支持。
int
i
=
valiWarn
(
ruleList
,
file
,
patten
,
0
);
//如果值为0则代表是有不支持技术到匹配
pomDependency
.
setSupport
(
i
);
}
}
//设置当前依赖为可支持
dependencyVo
.
add
(
projectPom
);
pomDependency
.
setSupport
(
1
);
}
else
{
//为普通用户上传,依赖需要检查是否支持。
int
i
=
valiWarn
(
ruleList
,
file
,
patten
,
0
);
//如果值为0则代表是有不支持技术到匹配
pomDependency
.
setSupport
(
i
);
}
}
dependencyVo
.
add
(
projectPom
);
fileNum
+=
1
;
}
try
{
fileNum
+=
1
;
List
<
String
>
allLines
=
Files
.
readAllLines
(
file
);
try
{
fileLine
+=
allLines
.
size
();
List
<
String
>
allLines
=
Files
.
readAllLines
(
file
);
}
catch
(
MalformedInputException
e
)
{
fileLine
+=
allLines
.
size
();
return
FileVisitResult
.
CONTINUE
;
}
catch
(
MalformedInputException
e
)
{
}
catch
(
IOException
e
)
{
return
FileVisitResult
.
CONTINUE
;
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
for
(
Map
.
Entry
<
String
,
PathMatcher
>
entry
:
languageSuffixMatcherMapping
.
entrySet
())
{
//通过正则表达式匹配.java类型后缀文件,并+1
if
(
entry
.
getValue
().
matches
(
file
))
{
long
length
=
file
.
toFile
().
length
();
codeSize
+=
length
/
1024
;
languageMatchMap
.
get
(
entry
.
getKey
()).
plus
();
}
}
}
for
(
Map
.
Entry
<
String
,
PathMatcher
>
entry
:
languageSuffixMatcherMapping
.
entrySet
())
{
for
(
Map
.
Entry
<
PathMatcher
,
String
>
entry
:
configFileMatcherSuffixMapping
.
entrySet
())
{
//通过正则表达式匹配.java类型后缀文件,并+1
//通过配置文件正则表达式匹配.xml文件,记录文件地址
if
(
entry
.
getValue
().
matches
(
file
))
{
if
(
entry
.
getKey
().
matches
(
file
))
{
long
length
=
file
.
toFile
().
length
();
configFileTypePathsMapping
.
get
(
entry
.
getValue
()).
add
(
file
);
codeSize
+=
length
/
1024
;
languageMatchMap
.
get
(
entry
.
getKey
()).
plus
();
}
}
}
}
for
(
Map
.
Entry
<
PathMatcher
,
String
>
entry
:
configFileMatcherSuffixMapping
.
entrySet
())
{
for
(
Map
.
Entry
<
PathMatcher
,
String
>
entry
:
ruleSuffixMap
.
entrySet
())
{
//通过配置文件正则表达式匹配.xml文件,记录文件地址
//通过规则匹配后缀正则表达式匹配,记录匹配上的文件地址
if
(
entry
.
getKey
().
matches
(
file
))
{
if
(
entry
.
getKey
().
matches
(
file
))
{
configFileTypePathsMapping
.
get
(
entry
.
getValue
()).
add
(
file
);
ruleSuffixFilePathMap
.
get
(
entry
.
getValue
()).
add
(
file
);
}
}
for
(
Map
.
Entry
<
PathMatcher
,
String
>
entry
:
ruleSuffixMap
.
entrySet
())
{
//通过规则匹配后缀正则表达式匹配,记录匹配上的文件地址
if
(
entry
.
getKey
().
matches
(
file
))
{
ruleSuffixFilePathMap
.
get
(
entry
.
getValue
()).
add
(
file
);
}
}
}
return
FileVisitResult
.
CONTINUE
;
}
}
return
FileVisitResult
.
CONTINUE
;
}
@Override
@Override
public
FileVisitResult
visitFileFailed
(
Path
file
,
IOException
exc
)
{
public
FileVisitResult
visitFileFailed
(
Path
file
,
IOException
exc
)
{
return
FileVisitResult
.
CONTINUE
;
return
FileVisitResult
.
CONTINUE
;
}
}
@Override
@Override
public
FileVisitResult
postVisitDirectory
(
Path
dir
,
IOException
exc
)
{
public
FileVisitResult
postVisitDirectory
(
Path
dir
,
IOException
exc
)
{
return
FileVisitResult
.
CONTINUE
;
return
FileVisitResult
.
CONTINUE
;
}
}
});
});
}
}
}
public
class
Counter
{
public
class
Counter
{
private
int
i
=
0
;
private
int
i
=
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论