Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
I
inspect
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
项目监控管理工具
inspect
Commits
960ffcd9
提交
960ffcd9
authored
4月 08, 2020
作者:
马晨俊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mcj:aop记录方法时间
上级
d4904820
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
91 行增加
和
81 行删除
+91
-81
AopIntercept.java
src/main/java/com/zjty/inspect/aop/AopIntercept.java
+7
-16
LoginInterceptor.java
src/main/java/com/zjty/inspect/config/LoginInterceptor.java
+3
-3
Inspector.java
src/main/java/com/zjty/inspect/inspect/Inspector.java
+81
-62
没有找到文件。
src/main/java/com/zjty/inspect/aop/A
uth
Intercept.java
→
src/main/java/com/zjty/inspect/aop/A
op
Intercept.java
浏览文件 @
960ffcd9
...
...
@@ -24,7 +24,7 @@ import java.util.List;
@Aspect
@Slf4j
@Component
public
class
A
uth
Intercept
{
public
class
A
op
Intercept
{
private
User
user
;
...
...
@@ -32,27 +32,18 @@ public class AuthIntercept {
this
.
user
=
user
;
}
@Pointcut
(
"
@annotation(com.zjty.inspect.aop.AuthAnnotation
)"
)
@Pointcut
(
"
execution(* com.zjty.inspect.inspect.Inspector.inspect(..)
)"
)
public
void
doPointCut
()
{
}
@Around
(
"doPointCut()"
)
public
Object
aroundMethod
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
AuthAnnotation
annotation
=
((
MethodSignature
)
joinPoint
.
getSignature
()).
getMethod
().
getAnnotation
(
AuthAnnotation
.
class
);
//注解配置权限code
String
[]
methodAuthCodes
=
annotation
.
code
();
//用户拥有权限code
List
<
String
>
authorityCode
=
user
.
getAuthorityCode
();
int
i
=
0
;
for
(
String
methodAuthCode
:
methodAuthCodes
)
{
if
(
authorityCode
.
contains
(
methodAuthCode
)){
i
++;
}
}
if
(
i
==
0
){
return
ResponseEntity
.
status
(
403
).
build
();
}
long
startMillis
=
System
.
currentTimeMillis
();
Object
proceed
=
joinPoint
.
proceed
();
long
endMillis
=
System
.
currentTimeMillis
();
long
time
=
(
endMillis
-
startMillis
);
log
.
info
(
"评估总耗时{}毫秒"
,
time
);
log
.
info
(
"PersonAspect2 ==> before method : {}"
,
joinPoint
.
getSignature
().
getName
());
log
.
info
(
"注解的类型名称为{}"
,
joinPoint
.
getSignature
().
getDeclaringTypeName
());
log
.
info
(
"方法修饰符个数为{}"
,
joinPoint
.
getSignature
().
getModifiers
());
...
...
src/main/java/com/zjty/inspect/config/LoginInterceptor.java
浏览文件 @
960ffcd9
package
com
.
zjty
.
inspect
.
config
;
import
com.zjty.inspect.aop.A
uth
Intercept
;
import
com.zjty.inspect.aop.A
op
Intercept
;
import
com.zjty.inspect.entity.ServerResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -22,7 +22,7 @@ public class LoginInterceptor implements HandlerInterceptor {
private
RestTemplate
restTemplate
;
@Autowired
private
A
uthIntercept
auth
Intercept
;
private
A
opIntercept
aop
Intercept
;
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
o
)
{
String
sessionId
=
request
.
getHeader
(
"sessionId"
);
...
...
@@ -34,7 +34,7 @@ public class LoginInterceptor implements HandlerInterceptor {
response
.
setStatus
(
403
);
return
false
;
}
a
uth
Intercept
.
setUser
(
user
.
getData
());
a
op
Intercept
.
setUser
(
user
.
getData
());
return
true
;
}
...
...
src/main/java/com/zjty/inspect/inspect/Inspector.java
浏览文件 @
960ffcd9
package
com
.
zjty
.
inspect
.
inspect
;
import
com.alibaba.fastjson.JSON
;
import
com.zjty.inspect.dao.*
;
import
com.zjty.inspect.entity.*
;
import
com.zjty.inspect.enums.DependenceManagement
;
...
...
@@ -22,31 +21,32 @@ import java.nio.charset.MalformedInputException;
import
java.nio.file.*
;
import
java.nio.file.attribute.BasicFileAttributes
;
import
java.util.*
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.stream.Collectors
;
import
static
java
.
util
.
concurrent
.
CompletableFuture
.
allOf
;
import
static
java
.
util
.
concurrent
.
CompletableFuture
.
runAsync
;
/**
* 项目体检,根据既定特征值,
* 扫描、统计、分析项目特征,
* 生成报告VO
*
* @author mcj
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Service
@Slf4j
@Transactional
()
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
class
Inspector
{
@Autowired
private
AnalysisFile
analysisFile
;
@Autowired
private
BudgetUitl
budgetUitl
;
@Autowired
private
RuleService
ruleService
;
@Autowired
private
TechnologyDao
technologyDao
;
@Autowired
private
ParameterDao
parameterDao
;
private
DependencyVo
dependencyVo
=
new
DependencyVo
();
...
...
@@ -125,7 +125,6 @@ public class Inspector {
*/
private
Map
<
String
,
List
<
Path
>>
configFileTypePathsMapping
=
new
HashMap
<>(
512
);
private
Map
<
String
,
List
<
Path
>>
ruleSuffixFilePathMap
;
private
Map
<
String
,
List
<
Rule
>>
ruleSuffixMap
;
...
...
@@ -136,50 +135,97 @@ public class Inspector {
*/
private
Map
<
String
,
Technology
>
technologyHashMap
=
new
HashMap
<>(
64
);
@Autowired
public
Inspector
(
BudgetUitl
budgetUitl
,
RuleService
ruleService
,
TechnologyDao
technologyDao
,
ParameterDao
parameterDao
,
AnalysisFile
analysisFile
)
{
this
.
budgetUitl
=
budgetUitl
;
this
.
ruleService
=
ruleService
;
this
.
technologyDao
=
technologyDao
;
this
.
parameterDao
=
parameterDao
;
this
.
analysisFile
=
analysisFile
;
}
/**
* 评估
*
* @return 报告
*/
public
ReportVo
inspect
()
throws
IOException
{
//初始化
值
//初始化
成员变量
initData
();
//扫描文件
//扫描文件
,进行文件分类
scanFiles
();
//配置
//配置
参数
inspectParameter
.
setCodeSize
((
int
)
codeSize
);
report
.
setFileNum
(
fileNum
);
report
.
setFileLine
(
fileLine
);
log
.
info
(
"inspect:源代码扫描完成,统计各个文件后缀完成"
);
//统计项目语言
setReportLanguageAndFrame
(
);
CompletableFuture
<
Void
>
future
=
runAsync
(
this
::
setReportLanguageAndFrame
);
//根据扫描结果以及用户配置得出需要使用的规则及技术
ruleTransform
(
inspectParameter
.
getRecastMethod
());
CompletableFuture
<
Void
>
future1
=
runAsync
(()
->
ruleTransform
(
inspectParameter
.
getRecastMethod
()));
allOf
(
future
,
future1
);
//扫描配置文件
forEachFilesMap
();
//将得到的告警信息根据技术id进行转换
Set
<
String
>
idSet
=
warns
.
stream
().
map
(
Warn:
:
getTechnologyId
).
collect
(
Collectors
.
toSet
());
List
<
Technology
>
technologies
=
technologyDao
.
findAllById
(
idSet
);
//计算技术金额
Integer
technologyFund
=
0
;
for
(
Technology
tech
:
technologies
)
{
technologyFund
+=
tech
.
getFund
();
}
//计算预算
if
(
inspectParameter
.
getValid
()
!=
null
)
{
BudgetVo
budget
=
budgetUitl
.
getBudget
(
technologyFund
,
report
,
inspectParameter
);
report
.
setBudgets
(
budget
);
}
parameterDao
.
save
(
inspectParameter
);
//填充地址(如果有)
report
.
setGitAddress
(
inspectParameter
.
getGitAddress
());
//填充适配技术
report
.
setTechnologies
(
technologies
);
//填充依赖
report
.
setDependencyVo
(
dependencyVo
);
//数据转换
HashMap
<
String
,
List
<
Warn
>>
warnMap
=
getWarnMap
();
ruleService
.
addRule
(
rules
);
report
.
setWarnDetails
(
warnMap
);
log
.
info
(
"评估报告关键技术,{}"
,
warnMap
);
return
report
;
}
/**
* 遍历操作扫描文件后得出的文件
*/
private
void
forEachFilesMap
()
{
//解析配置文件集合
for
(
Map
.
Entry
<
String
,
List
<
Path
>>
entry
:
configFileTypePathsMapping
.
entrySet
())
{
switch
(
entry
.
getKey
())
{
/**
* 配置文件的一个类型,xml文件
*/
case
"xml"
:
if
(
"xml"
.
equals
(
entry
.
getKey
()))
{
for
(
Path
path
:
entry
.
getValue
())
{
if
(
path
.
getFileName
().
endsWith
(
"pom.xml"
))
{
try
{
// TODO: 2020-02-28 解析maven树文件,设置依赖保存到redis
report
.
setManager
(
DependenceManagement
.
MAVEN
.
getStatus
());
ProjectPom
projectPom
=
analysisFile
.
analysisPom
(
path
);
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
PomDependency
dependency
:
projectPom
.
getDependencies
())
{
setRule
(
path
,
stringBuilder
,
dependency
);
setRule
(
stringBuilder
,
dependency
);
}
List
<
String
>
lines
=
Files
.
readAllLines
(
path
);
List
<
String
>
lines
;
lines
=
Files
.
readAllLines
(
path
);
for
(
int
i
=
0
;
i
<
lines
.
size
();
i
++)
{
valiWarn
(
rules
,
path
,
lines
.
get
(
i
),
i
+
1
);
}
dependencyVo
.
add
(
projectPom
);
}
catch
(
IOException
e
)
{
log
.
error
(
"路径文件读取错误{}"
,
path
.
toString
());
}
}
}
break
;
default
:
}
}
//指定后缀到文件匹配关键字
...
...
@@ -205,33 +251,6 @@ public class Inspector {
}
}
}
//将得到的告警信息根据技术id进行转换
Set
<
String
>
idSet
=
warns
.
stream
().
map
(
Warn:
:
getTechnologyId
).
collect
(
Collectors
.
toSet
());
List
<
Technology
>
technologies
=
technologyDao
.
findAllById
(
idSet
);
//计算技术金额
Integer
technologyFund
=
0
;
for
(
Technology
tech
:
technologies
)
{
technologyFund
+=
tech
.
getFund
();
}
//计算预算
if
(
inspectParameter
.
getValid
()
!=
null
)
{
BudgetVo
budget
=
budgetUitl
.
getBudget
(
technologyFund
,
report
,
inspectParameter
);
report
.
setBudgets
(
budget
);
}
parameterDao
.
save
(
inspectParameter
);
//填充地址(如果有)
report
.
setGitAddress
(
inspectParameter
.
getGitAddress
());
//填充适配技术
report
.
setTechnologies
(
technologies
);
//填充依赖
report
.
setDependencyVo
(
dependencyVo
);
//数据转换
HashMap
<
String
,
List
<
Warn
>>
warnMap
=
getWarnMap
();
ruleService
.
addRule
(
rules
);
report
.
setWarnDetails
(
warnMap
);
log
.
info
(
"评估报告关键技术,{}"
,
warnMap
);
return
report
;
}
...
...
@@ -267,6 +286,7 @@ public class Inspector {
/**
* rule所需要数据装配
*
* @param status 状态
* 1:改造
* 2:适配
...
...
@@ -309,6 +329,11 @@ public class Inspector {
}
private
void
initData
()
{
//查询技术,构造支持与非支持技术对象,3个对象
CompletableFuture
<
Void
>
future
=
runAsync
(
this
::
findExistTechnology
);
//配置语言 map结构
CompletableFuture
<
Void
>
future1
=
runAsync
(
this
::
statisticsLanguage
);
CompletableFuture
<
Void
>
future2
=
runAsync
(
this
::
initRule
);
codeSize
=
0
;
fileLine
=
0
;
fileNum
=
0
;
...
...
@@ -319,14 +344,10 @@ public class Inspector {
supportWarns
=
new
ArrayList
<>();
warns
.
clear
();
rules
.
clear
();
//查询技术,构造支持与非支持技术对象,3个对象
findExistTechnology
();
//配置语言 map结构
statisticsLanguage
();
//配置 config文件 结构
statisticsConfigFile
();
initRule
();
initTechnology
();
CompletableFuture
.
allOf
(
future
,
future1
,
future2
);
}
private
void
statisticsConfigFile
()
{
...
...
@@ -413,16 +434,14 @@ public class Inspector {
warnMap
.
put
(
technology
.
getTechnologyName
(),
warns1
);
}
}
return
warnMap
;
}
/**
* @param path 文件路径
* @param stringBuilder string缓冲区
* @param dependency 依赖
*/
private
void
setRule
(
Path
path
,
StringBuilder
stringBuilder
,
PomDependency
dependency
)
{
private
void
setRule
(
StringBuilder
stringBuilder
,
PomDependency
dependency
)
{
stringBuilder
.
append
(
dependency
.
getGroupId
()).
append
(
":"
).
append
(
dependency
.
getArtifactId
());
Rule
rule
=
new
Rule
();
...
...
@@ -508,9 +527,10 @@ public class Inspector {
/**
* 扫描源文件
*
* @throws IOException
*/
public
void
scanFiles
()
throws
IOException
{
public
void
scanFiles
()
{
//以下为计算文件名称匹配正则表达式
FileSystem
aDefault
=
FileSystems
.
getDefault
();
Map
<
String
,
PathMatcher
>
languageSuffixMatcherMapping
=
new
HashMap
<>(
16
);
...
...
@@ -531,6 +551,7 @@ public class Inspector {
//文件读取
if
(
inspectParameter
.
getSourceAddress
()
!=
null
)
{
try
{
Files
.
walkFileTree
(
Paths
.
get
(
inspectParameter
.
getSourceAddress
()),
new
FileVisitor
<
Path
>()
{
@Override
public
FileVisitResult
preVisitDirectory
(
Path
dir
,
BasicFileAttributes
attrs
)
throws
IOException
{
...
...
@@ -539,7 +560,7 @@ public class Inspector {
}
@Override
public
FileVisitResult
visitFile
(
Path
file
,
BasicFileAttributes
attrs
)
{
public
FileVisitResult
visitFile
(
Path
file
,
BasicFileAttributes
attrs
)
throws
IOException
{
//扫描jar文件时
if
(
file
.
getFileName
().
toString
().
endsWith
(
".jar"
))
{
//新建一个pom对象
...
...
@@ -578,14 +599,9 @@ public class Inspector {
dependencyVo
.
add
(
projectPom
);
}
fileNum
+=
1
;
try
{
List
<
String
>
allLines
=
Files
.
readAllLines
(
file
);
fileLine
+=
allLines
.
size
();
}
catch
(
MalformedInputException
e
)
{
return
FileVisitResult
.
CONTINUE
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
for
(
Map
.
Entry
<
String
,
PathMatcher
>
entry
:
languageSuffixMatcherMapping
.
entrySet
())
{
//通过正则表达式匹配.java类型后缀文件,并+1
if
(
entry
.
getValue
().
matches
(
file
))
{
...
...
@@ -619,6 +635,9 @@ public class Inspector {
return
FileVisitResult
.
CONTINUE
;
}
});
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论