Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
I
inspect
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
项目监控管理工具
inspect
Commits
81715037
提交
81715037
authored
3月 02, 2020
作者:
马晨俊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mcj:新增文件解析
上级
1c36b7b8
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
164 行增加
和
129 行删除
+164
-129
pom.xml
pom.xml
+14
-0
FpCorsFilter.java
src/main/java/com/zjty/inspect/config/FpCorsFilter.java
+45
-0
RedisConfig.java
src/main/java/com/zjty/inspect/config/RedisConfig.java
+28
-28
InspectController.java
...n/java/com/zjty/inspect/controller/InspectController.java
+10
-4
FileUtil.java
src/main/java/com/zjty/inspect/utils/FileUtil.java
+64
-94
Inspector.java
src/main/java/com/zjty/inspect/utils/Inspector.java
+3
-3
没有找到文件。
pom.xml
浏览文件 @
81715037
...
...
@@ -85,6 +85,20 @@
<artifactId>
snakeyaml
</artifactId>
<version>
1.25
</version>
</dependency>
<dependency>
<groupId>
net.lingala.zip4j
</groupId>
<artifactId>
zip4j
</artifactId>
<version>
1.3.2
</version>
</dependency>
<!--解压rar压缩-->
<dependency>
<groupId>
com.github.junrar
</groupId>
<artifactId>
junrar
</artifactId>
<version>
0.7
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/zjty/inspect/config/FpCorsFilter.java
0 → 100644
浏览文件 @
81715037
package
com
.
zjty
.
inspect
.
config
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.*
;
import
javax.servlet.annotation.WebFilter
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
/**
* <p>Description : fp-api
* <p>Date : 2018/11/8 10:53
* <p>@author : Mcj
*/
@Component
@WebFilter
(
filterName
=
"MyCorsFilter"
,
urlPatterns
=
"/*"
)
@Order
(
2
)
public
class
FpCorsFilter
implements
Filter
{
@Override
public
void
doFilter
(
ServletRequest
req
,
ServletResponse
res
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
HttpServletRequest
request
=
(
HttpServletRequest
)
req
;
HttpServletResponse
response
=
(
HttpServletResponse
)
res
;
// 设置响应头的权限信息 request.getHeader("Origin")
response
.
setHeader
(
"Access-Control-Allow-Origin"
,
request
.
getHeader
(
"Origin"
));
response
.
setHeader
(
"Access-Control-Allow-Credentials"
,
"true"
);
response
.
setHeader
(
"Access-Control-Allow-Methods"
,
"POST, GET, OPTIONS, PUT, PATCH, DELETE"
);
response
.
setHeader
(
"Access-Control-Max-Age"
,
"3600"
);
//original headers Origin, X-Requested-With, Content-Type, Accept
response
.
setHeader
(
"Access-Control-Allow-Headers"
,
"Origin, X-Requested-With, Content-Type, Accept"
);
chain
.
doFilter
(
req
,
res
);
}
@Override
public
void
init
(
FilterConfig
config
)
{
}
@Override
public
void
destroy
()
{
}
}
src/main/java/com/zjty/inspect/config/RedisConfig.java
浏览文件 @
81715037
...
...
@@ -17,32 +17,32 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
*/
@Configuration
public
class
RedisConfig
{
//
@Bean(name = "defaultRedisTpl")
//
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
//
RedisTemplate<String, Object> template = new RedisTemplate<>();
//
template.setConnectionFactory(factory);
//
//
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
//
ObjectMapper om = new ObjectMapper();
//
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
//
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
//
jackson2JsonRedisSerializer.setObjectMapper(om);
//
// value序列化方式采用jackson
//
template.setValueSerializer(jackson2JsonRedisSerializer);
//
//
template.setKeySerializer(new StringRedisSerializer());
//
template.setValueSerializer(jackson2JsonRedisSerializer);
//
return template;
//
}
//
//
//
//
@Bean
//
public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) {
//
//获得redis缓存管理类
//
RedisCacheManager redisCacheManager = RedisCacheManager.create(connectionFactory);
//
// 开启使用缓存名称做为key前缀(这样所有同名缓存会整理在一起比较容易查找)
//
//
return redisCacheManager;
//
}
@Bean
(
name
=
"defaultRedisTpl"
)
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
factory
)
{
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<>();
template
.
setConnectionFactory
(
factory
);
Jackson2JsonRedisSerializer
jackson2JsonRedisSerializer
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
ObjectMapper
om
=
new
ObjectMapper
();
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
om
.
enableDefaultTyping
(
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
jackson2JsonRedisSerializer
.
setObjectMapper
(
om
);
// value序列化方式采用jackson
template
.
setValueSerializer
(
jackson2JsonRedisSerializer
);
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setValueSerializer
(
jackson2JsonRedisSerializer
);
return
template
;
}
@Bean
public
RedisCacheManager
cacheManager
(
RedisConnectionFactory
connectionFactory
)
{
//获得redis缓存管理类
RedisCacheManager
redisCacheManager
=
RedisCacheManager
.
create
(
connectionFactory
);
// 开启使用缓存名称做为key前缀(这样所有同名缓存会整理在一起比较容易查找)
return
redisCacheManager
;
}
}
src/main/java/com/zjty/inspect/controller/InspectController.java
浏览文件 @
81715037
...
...
@@ -29,13 +29,19 @@ public class InspectController {
* @return
*/
@PostMapping
(
"/path"
)
public
ResponseEntity
inspect
(
@RequestBody
InspectParameter
inspectParameter
,
MultipartFile
file
)
{
public
ResponseEntity
inspect
(
@RequestBody
InspectParameter
inspectParameter
,
MultipartFile
file
)
throws
IOException
{
//得到压缩包,进行解压
//File file1 = file.getResource().getFile();
//String path = FileUtil.unZip(file1, "/Users/mcj/IdeaProjects/t5");
File
file2
=
new
File
(
"/Users/mcj/IdeaProjects/inspect"
);
File
file1
=
file
.
getResource
().
getFile
();
if
(
file1
.
getName
().
endsWith
(
"zip"
)){
FileUtil
.
unPackZip
(
file1
,
""
,
"./"
);
}
else
{
FileUtil
.
unPackRar
(
file1
,
"./"
);
}
String
[]
split
=
file1
.
getName
().
split
(
"\\."
);
File
file2
=
new
File
(
"./"
+
split
[
0
]);
String
path1
=
file2
.
getPath
();
inspectService
.
inspect
(
inspectParameter
,
path1
);
return
ResponseEntity
.
ok
(
200
);
}
...
...
src/main/java/com/zjty/inspect/utils/FileUtil.java
浏览文件 @
81715037
package
com
.
zjty
.
inspect
.
utils
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.zjty.inspect.entity.Report
;
import
com.github.junrar.Archive
;
import
com.github.junrar.rarfile.FileHeader
;
import
com.zjty.inspect.entity.VueDep
;
import
org.dom4j.Attribute
;
import
lombok.extern.slf4j.Slf4j
;
import
net.lingala.zip4j.core.ZipFile
;
import
org.apache.commons.io.FileUtils
;
import
org.dom4j.Document
;
import
org.dom4j.DocumentException
;
import
org.dom4j.Element
;
import
org.dom4j.io.SAXReader
;
import
java.io.*
;
import
java.util.Enumeration
;
import
java.util.List
;
import
java.util.Properties
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
@Slf4j
public
class
FileUtil
{
static
int
BUFFER_SIZE
=
1024
;
/**
* zip解压
* zip
文件
解压
*
* @param
srcFile zip源文件
* @param
destDirPath 解压后的目标文件夹
* @
throws RuntimeException 解压失败会抛出运行时异常
* @param
destPath 解压文件路径
* @param
zipFile 压缩文件
* @
param password 解压密码(如果有)
*/
public
static
String
unZip
(
File
srcFile
,
String
destDirPath
)
throws
RuntimeException
{
long
start
=
System
.
currentTimeMillis
();
// 判断源文件是否存在
if
(!
srcFile
.
exists
())
{
throw
new
RuntimeException
(
srcFile
.
getPath
()
+
"所指文件不存在"
);
}
// 开始解压
ZipFile
zipFile
=
null
;
public
static
void
unPackZip
(
File
zipFile
,
String
password
,
String
destPath
)
{
try
{
zipFile
=
new
ZipFile
(
srcFile
);
Enumeration
<?>
entries
=
zipFile
.
entries
();
while
(
entries
.
hasMoreElements
())
{
ZipEntry
entry
=
(
ZipEntry
)
entries
.
nextElement
();
System
.
out
.
println
(
"解压"
+
entry
.
getName
());
// 如果是文件夹,就创建个文件夹
if
(
entry
.
isDirectory
())
{
String
dirPath
=
destDirPath
+
"/"
+
entry
.
getName
();
File
dir
=
new
File
(
dirPath
);
dir
.
mkdirs
();
}
else
{
// 如果是文件,就先创建一个文件,然后用io流把内容copy过去
File
targetFile
=
new
File
(
destDirPath
+
"/"
+
entry
.
getName
());
// 保证这个文件的父文件夹必须要存在
if
(!
targetFile
.
getParentFile
().
exists
())
{
targetFile
.
getParentFile
().
mkdirs
();
}
targetFile
.
createNewFile
();
// 将压缩文件内容写入到这个文件中
InputStream
is
=
zipFile
.
getInputStream
(
entry
);
FileOutputStream
fos
=
new
FileOutputStream
(
targetFile
);
int
len
;
byte
[]
buf
=
new
byte
[
BUFFER_SIZE
];
while
((
len
=
is
.
read
(
buf
))
!=
-
1
)
{
fos
.
write
(
buf
,
0
,
len
);
}
// 关流顺序,先打开的后关闭
fos
.
close
();
is
.
close
();
return
targetFile
.
getPath
();
}
ZipFile
zip
=
new
ZipFile
(
zipFile
);
/*zip4j默认用GBK编码去解压,这里设置编码为GBK的*/
zip
.
setFileNameCharset
(
"GBK"
);
log
.
info
(
"begin unpack zip file...."
);
zip
.
extractAll
(
destPath
);
// 如果解压需要密码
if
(
zip
.
isEncrypted
())
{
zip
.
setPassword
(
password
);
}
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"解压完成,耗时:"
+
(
end
-
start
)
+
" ms"
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"unzip error from ZipUtils"
,
e
);
}
finally
{
if
(
zipFile
!=
null
)
{
try
{
zipFile
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
log
.
error
(
"unPack zip file to "
+
destPath
+
" fail ...."
,
e
.
getMessage
(),
e
);
}
return
""
;
}
private
static
void
recursiveFiles
(
String
path
)
{
// 创建 File对象
File
file
=
new
File
(
path
);
// 取 文件/文件夹
File
files
[]
=
file
.
listFiles
();
// 对象为空 直接返回
if
(
files
==
null
)
{
return
;
}
// 存在文件 遍历 判断
for
(
File
f
:
files
)
{
// 判断是否为 文件夹
if
(
f
.
isDirectory
())
{
// 为 文件夹继续遍历
recursiveFiles
(
f
.
getAbsolutePath
());
// 判断是否为 文件
}
else
if
(
f
.
isFile
())
{
if
(
"pom.xml"
.
equals
(
f
.
getName
()))
{
System
.
out
.
println
(
"解析pom"
);
/**
* rar文件解压(不支持有密码的压缩包)
*
* @param rarFile rar压缩包
* @param destPath 解压保存路径
*/
public
static
void
unPackRar
(
File
rarFile
,
String
destPath
)
{
try
(
Archive
archive
=
new
Archive
(
rarFile
))
{
if
(
null
!=
archive
)
{
FileHeader
fileHeader
=
archive
.
nextFileHeader
();
File
file
=
null
;
while
(
null
!=
fileHeader
)
{
// 防止文件名中文乱码问题的处理
String
fileName
=
fileHeader
.
getFileNameW
().
isEmpty
()
?
fileHeader
.
getFileNameString
()
:
fileHeader
.
getFileNameW
();
if
(
fileHeader
.
isDirectory
())
{
//是文件夹
file
=
new
File
(
destPath
+
File
.
separator
+
fileName
);
file
.
mkdirs
();
}
else
{
//不是文件夹
file
=
new
File
(
destPath
+
File
.
separator
+
fileName
.
trim
());
if
(!
file
.
exists
())
{
if
(!
file
.
getParentFile
().
exists
())
{
// 相对路径可能多级,可能需要创建父目录.
file
.
getParentFile
().
mkdirs
();
}
file
.
createNewFile
();
}
FileOutputStream
os
=
new
FileOutputStream
(
file
);
archive
.
extractFile
(
fileHeader
,
os
);
os
.
close
();
}
fileHeader
=
archive
.
nextFileHeader
();
}
System
.
out
.
println
(
f
.
getName
());
// System.out.println(f.getAbsolutePath());
}
else
{
System
.
out
.
print
(
"未知错误文件"
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"unpack rar file fail...."
,
e
.
getMessage
(),
e
);
}
}
...
...
@@ -125,12 +94,13 @@ public class FileUtil {
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
File
file
=
new
File
(
"/Users/mcj/Downloads/acq-server.zip"
);
String
[]
split
=
file
.
getName
().
split
(
"\\."
);
System
.
out
.
println
(
split
[
0
]);
System
.
out
.
println
(
file
.
getName
());
File
file
=
new
File
(
"/Users/mcj/Downloads/package.json"
);
VueDep
vueDep
=
new
ObjectMapper
().
readValue
(
file
,
VueDep
.
class
);
System
.
out
.
println
(
vueDep
);
// FileUtil.unPackZip(new File("/Users/mcj/Downloads/acq-server.zip"),"", "./");
//FileUtils.deleteDirectory(new File("./acq-server"));
SAXReader
reader
=
new
SAXReader
();
Document
document
=
null
;
...
...
src/main/java/com/zjty/inspect/utils/Inspector.java
浏览文件 @
81715037
...
...
@@ -33,8 +33,8 @@ import java.util.stream.Collectors;
@Scope
(
"prototype"
)
public
class
Inspector
{
//
@Autowired
//
private RedisUtil redisUtil;
@Autowired
private
RedisUtil
redisUtil
;
@Autowired
private
AnalysisFile
analysisFile
;
@Autowired
...
...
@@ -250,7 +250,7 @@ public class Inspector {
depTreeVo
.
getDepTreeList
().
add
(
depTreePom
.
getDepTree
());
//savetoredis
//
redisUtil.set(report.getId(),depTreeVo);
redisUtil
.
set
(
report
.
getId
(),
depTreeVo
);
}
}
break
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论