Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
5a169cb6
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5a169cb6
编写于
8月 21, 2020
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reuse TestCaseFileLoader in SQLCasesLoader
上级
c65642e8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
47 deletion
+10
-47
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/integrate/jaxb/sql/loader/SQLCasesLoader.java
.../sql/parser/integrate/jaxb/sql/loader/SQLCasesLoader.java
+9
-46
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/integrate/loader/TestCaseFileLoader.java
.../test/sql/parser/integrate/loader/TestCaseFileLoader.java
+1
-1
未找到文件。
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/integrate/jaxb/sql/loader/SQLCasesLoader.java
浏览文件 @
5a169cb6
...
...
@@ -24,24 +24,21 @@ import lombok.SneakyThrows;
import
org.apache.shardingsphere.test.sql.parser.integrate.jaxb.sql.SQLCase
;
import
org.apache.shardingsphere.test.sql.parser.integrate.jaxb.sql.SQLCaseType
;
import
org.apache.shardingsphere.test.sql.parser.integrate.jaxb.sql.SQLCases
;
import
org.apache.shardingsphere.test.sql.parser.integrate.loader.TestCaseFileLoader
;
import
javax.xml.bind.JAXBContext
;
import
javax.xml.bind.JAXBException
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Enumeration
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
/**
* SQL test cases loader.
...
...
@@ -57,59 +54,25 @@ public final class SQLCasesLoader {
@SneakyThrows
({
JAXBException
.
class
,
IOException
.
class
})
private
Map
<
String
,
SQLCase
>
loadSQLCases
(
final
String
path
)
{
File
file
=
new
File
(
SQLCasesLoader
.
class
.
getProtectionDomain
().
getCodeSource
().
getLocation
().
getPath
());
return
file
.
isFile
()
?
load
SQLCasesFromJar
(
path
,
file
)
:
loadSQLCases
FromTargetDirectory
(
path
);
return
file
.
isFile
()
?
load
FromJar
(
file
,
path
)
:
load
FromTargetDirectory
(
path
);
}
private
Map
<
String
,
SQLCase
>
load
SQLCasesFromJar
(
final
String
path
,
final
File
file
)
throws
IOException
,
JAXBException
{
private
Map
<
String
,
SQLCase
>
load
FromJar
(
final
File
file
,
final
String
path
)
throws
JAXBException
{
Map
<
String
,
SQLCase
>
result
=
new
TreeMap
<>();
try
(
JarFile
jar
=
new
JarFile
(
file
))
{
Enumeration
<
JarEntry
>
entries
=
jar
.
entries
();
while
(
entries
.
hasMoreElements
())
{
String
name
=
entries
.
nextElement
().
getName
();
if
(
name
.
startsWith
(
path
)
&&
name
.
endsWith
(
".xml"
))
{
fillSQLMap
(
result
,
SQLCasesLoader
.
class
.
getClassLoader
().
getResourceAsStream
(
name
));
}
}
for
(
String
each
:
TestCaseFileLoader
.
loadFileNamesFromJar
(
file
,
path
))
{
fillSQLMap
(
result
,
SQLCasesLoader
.
class
.
getClassLoader
().
getResourceAsStream
(
each
));
}
return
result
;
}
@SneakyThrows
(
URISyntaxException
.
class
)
private
Map
<
String
,
SQLCase
>
loadSQLCasesFromTargetDirectory
(
final
String
path
)
{
private
Map
<
String
,
SQLCase
>
loadFromTargetDirectory
(
final
String
path
)
throws
JAXBException
,
FileNotFoundException
{
Map
<
String
,
SQLCase
>
result
=
new
TreeMap
<>();
URL
url
=
SQLCasesLoader
.
class
.
getClassLoader
().
getResource
(
path
);
if
(
null
==
url
)
{
return
result
;
}
File
filePath
=
new
File
(
url
.
toURI
().
getPath
());
if
(!
filePath
.
exists
())
{
return
result
;
}
File
[]
files
=
filePath
.
listFiles
();
if
(
null
==
files
)
{
return
result
;
}
for
(
File
each
:
files
)
{
loadSQLCasesFromDirectory
(
result
,
each
);
for
(
File
each
:
TestCaseFileLoader
.
loadFilesFromTargetDirectory
(
path
))
{
fillSQLMap
(
result
,
new
FileInputStream
(
each
));
}
return
result
;
}
@SneakyThrows
({
JAXBException
.
class
,
IOException
.
class
})
private
void
loadSQLCasesFromDirectory
(
final
Map
<
String
,
SQLCase
>
sqlStatementMap
,
final
File
file
)
{
if
(
file
.
isDirectory
())
{
File
[]
files
=
file
.
listFiles
();
if
(
null
==
files
)
{
return
;
}
for
(
File
each
:
files
)
{
loadSQLCasesFromDirectory
(
sqlStatementMap
,
each
);
}
}
else
{
fillSQLMap
(
sqlStatementMap
,
new
FileInputStream
(
file
));
}
}
private
void
fillSQLMap
(
final
Map
<
String
,
SQLCase
>
sqlCaseMap
,
final
InputStream
inputStream
)
throws
JAXBException
{
SQLCases
sqlCases
=
(
SQLCases
)
JAXBContext
.
newInstance
(
SQLCases
.
class
).
createUnmarshaller
().
unmarshal
(
inputStream
);
for
(
SQLCase
each
:
sqlCases
.
getSqlCases
())
{
...
...
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/integrate/loader/TestCaseFileLoader.java
浏览文件 @
5a169cb6
...
...
@@ -85,7 +85,7 @@ public final class TestCaseFileLoader {
@Override
public
FileVisitResult
visitFile
(
final
Path
file
,
final
BasicFileAttributes
attributes
)
{
if
(
file
.
endsWith
(
FILE_EXTENSION
))
{
if
(
file
.
toString
().
endsWith
(
FILE_EXTENSION
))
{
result
.
add
(
file
.
toFile
());
}
return
FileVisitResult
.
CONTINUE
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录