Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
16386f44
C
Coca
项目概览
Phodal
/
Coca
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coca
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
16386f44
编写于
1月 06, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: [dep] add basic maven xml parser
上级
543e09f5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
80 addition
and
13 deletion
+80
-13
core/context/deps/dep_app.go
core/context/deps/dep_app.go
+49
-1
core/context/deps/dep_app_test.go
core/context/deps/dep_app_test.go
+21
-2
core/infrastructure/xmlparse/xml_parser.go
core/infrastructure/xmlparse/xml_parser.go
+10
-10
未找到文件。
core/context/deps/dep_app.go
浏览文件 @
16386f44
...
...
@@ -4,7 +4,9 @@ import (
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast/groovy"
"github.com/phodal/coca/core/infrastructure/xmlparse"
.
"github.com/phodal/coca/languages/groovy"
"os"
)
type
DepApp
struct
{
...
...
@@ -25,7 +27,53 @@ func (d *DepApp) BuildImportMap(deps []domain.JClassNode) map[string]domain.JImp
return
impMap
}
func
Analysis
(
str
string
)
{
func
AnalysisMaven
(
xmlPath
string
)
[]
domain
.
JDependency
{
xmlFile
,
_
:=
os
.
Open
(
xmlPath
)
parseXml
:=
xmlparse
.
ParseXml
(
xmlFile
)
for
_
,
element
:=
range
parseXml
.
Elements
{
val
:=
element
.
Val
.
(
xmlparse
.
XmlNode
)
if
val
.
Name
==
"dependencies"
{
return
BuildDeps
(
val
)
}
}
return
nil
}
func
BuildDeps
(
val
xmlparse
.
XmlNode
)
[]
domain
.
JDependency
{
var
deps
[]
domain
.
JDependency
=
nil
for
_
,
depElement
:=
range
val
.
Elements
{
depNode
:=
depElement
.
Val
.
(
xmlparse
.
XmlNode
)
dependency
:=
domain
.
NewJDependency
(
""
,
""
)
for
_
,
depValue
:=
range
depNode
.
Elements
{
node
:=
depValue
.
Val
.
(
xmlparse
.
XmlNode
)
if
node
.
Name
==
"groupId"
{
for
_
,
textNode
:=
range
node
.
Elements
{
dependency
.
GroupId
=
textNode
.
Val
.
(
string
)
}
}
if
node
.
Name
==
"artifactId"
{
for
_
,
textNode
:=
range
node
.
Elements
{
dependency
.
ArtifactId
=
textNode
.
Val
.
(
string
)
}
}
if
node
.
Name
==
"scope"
{
for
_
,
textNode
:=
range
node
.
Elements
{
dependency
.
Scope
=
textNode
.
Val
.
(
string
)
}
}
}
deps
=
append
(
deps
,
*
dependency
)
}
return
deps
}
func
AnalysisGradle
(
str
string
)
{
parser
:=
ProcessGroovyString
(
str
)
context
:=
parser
.
CompilationUnit
()
...
...
core/context/deps/dep_app_test.go
浏览文件 @
16386f44
...
...
@@ -6,7 +6,7 @@ import (
"testing"
)
func
Test
Analysis
(
t
*
testing
.
T
)
{
func
Test
_ShouldReturnGradleDep
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
pluginsStr
:=
`dependencies {
...
...
@@ -14,11 +14,30 @@ func TestAnalysis(t *testing.T) {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}`
Analysis
(
pluginsStr
)
Analysis
Gradle
(
pluginsStr
)
g
.
Expect
(
true
)
.
To
(
Equal
(
true
))
}
func
Test_ShouldReturnCorrectMavenDeps
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
codePath
:=
"../../../_fixtures/deps/maven/pom.xml"
mavenDeps
:=
AnalysisMaven
(
codePath
)
g
.
Expect
(
len
(
mavenDeps
))
.
To
(
Equal
(
12
))
g
.
Expect
(
true
)
.
To
(
Equal
(
true
))
}
func
Test_ShouldReturnNilWhenErrorPath
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
codePath
:=
"../../../_fixtures/god_know_it"
mavenDeps
:=
AnalysisMaven
(
codePath
)
g
.
Expect
(
len
(
mavenDeps
))
.
To
(
Equal
(
0
))
}
func
Test_ShouldCountDeps_WhenHadClassNodes
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
...
...
core/infrastructure/xmlparse/xml_parser.go
浏览文件 @
16386f44
...
...
@@ -10,10 +10,10 @@ type ElemType string
const
(
eleTpText
ElemType
=
"text"
// 静态文本节点
eleTpNode
ElemType
=
"
n
ode"
// 节点子节点
eleTpNode
ElemType
=
"
XmlN
ode"
// 节点子节点
)
type
n
ode
struct
{
type
XmlN
ode
struct
{
Id
string
Name
string
Attrs
map
[
string
]
xml
.
Attr
...
...
@@ -25,9 +25,9 @@ type element struct {
Val
interface
{}
}
func
ParseXml
(
r
io
.
Reader
)
*
n
ode
{
func
ParseXml
(
r
io
.
Reader
)
*
XmlN
ode
{
parser
:=
xml
.
NewDecoder
(
r
)
var
root
n
ode
var
root
XmlN
ode
st
:=
NewStack
()
for
{
...
...
@@ -44,7 +44,7 @@ func ParseXml(r io.Reader) *node {
for
_
,
val
:=
range
attr
{
attrMap
[
val
.
Name
.
Local
]
=
val
}
node
:=
n
ode
{
node
:=
XmlN
ode
{
Name
:
name
,
Attrs
:
attrMap
,
Elements
:
make
([]
element
,
0
),
...
...
@@ -58,15 +58,15 @@ func ParseXml(r io.Reader) *node {
case
xml
.
EndElement
:
//tag end
if
st
.
Len
()
>
0
{
//cur
n
ode
n
:=
st
.
Pop
()
.
(
n
ode
)
if
st
.
Len
()
>
0
{
//if the root
n
ode then append to element
//cur
XmlN
ode
n
:=
st
.
Pop
()
.
(
XmlN
ode
)
if
st
.
Len
()
>
0
{
//if the root
XmlN
ode then append to element
e
:=
element
{
ElementType
:
eleTpNode
,
Val
:
n
,
}
pn
:=
st
.
Pop
()
.
(
n
ode
)
pn
:=
st
.
Pop
()
.
(
XmlN
ode
)
els
:=
pn
.
Elements
els
=
append
(
els
,
e
)
pn
.
Elements
=
els
...
...
@@ -77,7 +77,7 @@ func ParseXml(r io.Reader) *node {
}
case
xml
.
CharData
:
//tag content
if
st
.
Len
()
>
0
{
n
:=
st
.
Pop
()
.
(
n
ode
)
n
:=
st
.
Pop
()
.
(
XmlN
ode
)
bytes
:=
xml
.
CharData
(
t
)
content
:=
strings
.
TrimSpace
(
string
(
bytes
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录