Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
d765e4a1
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,发现更多精彩内容 >>
未验证
提交
d765e4a1
编写于
1月 07, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: [dep] make gradle works
上级
743147e5
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
40 addition
and
15 deletion
+40
-15
core/context/deps/dep_app.go
core/context/deps/dep_app.go
+4
-3
core/context/deps/dep_app_test.go
core/context/deps/dep_app_test.go
+3
-2
core/infrastructure/ast/groovy/GroovyIdentifierListener.go
core/infrastructure/ast/groovy/GroovyIdentifierListener.go
+33
-10
未找到文件。
core/context/deps/dep_app.go
浏览文件 @
d765e4a1
...
...
@@ -64,22 +64,23 @@ func BuildDeps(val xmlparse.XmlNode) []domain.JDependency {
dependency
.
Scope
=
textNode
.
Val
.
(
string
)
}
}
}
deps
=
append
(
deps
,
*
dependency
)
deps
=
append
(
deps
,
*
dependency
)
}
return
deps
}
func
AnalysisGradle
(
str
string
)
{
func
AnalysisGradle
(
str
string
)
[]
domain
.
JDependency
{
parser
:=
ProcessGroovyString
(
str
)
context
:=
parser
.
CompilationUnit
()
listener
:=
groovy
.
NewGroovyIdentListener
()
antlr
.
NewParseTreeWalker
()
.
Walk
(
listener
,
context
)
return
listener
.
GetDepsInfo
()
}
func
ProcessGroovyString
(
code
string
)
*
GroovyParser
{
...
...
core/context/deps/dep_app_test.go
浏览文件 @
d765e4a1
...
...
@@ -14,9 +14,10 @@ func Test_ShouldReturnGradleDep(t *testing.T) {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}`
AnalysisGradle
(
pluginsStr
)
results
:=
AnalysisGradle
(
pluginsStr
)
g
.
Expect
(
true
)
.
To
(
Equal
(
true
))
g
.
Expect
(
len
(
results
))
.
To
(
Equal
(
2
))
g
.
Expect
(
results
[
0
]
.
ArtifactId
)
.
To
(
Equal
(
"spring-boot-starter-web"
))
}
func
Test_ShouldReturnCorrectMavenDeps
(
t
*
testing
.
T
)
{
...
...
core/infrastructure/ast/groovy/GroovyIdentifierListener.go
浏览文件 @
d765e4a1
package
groovy
import
(
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/domain"
parser
"github.com/phodal/coca/languages/groovy"
"reflect"
"strings"
)
var
nodeDeps
[]
domain
.
JDependency
type
GroovyIdentifierListener
struct
{
parser
.
BaseGroovyParserListener
}
func
NewGroovyIdentListener
()
*
GroovyIdentifierListener
{
nodeDeps
=
nil
return
&
GroovyIdentifierListener
{}
}
...
...
@@ -20,7 +24,6 @@ func NewGroovyIdentListener() *GroovyIdentifierListener {
// 2. use regex replace it
// 3. remove the features
func
(
s
*
GroovyIdentifierListener
)
EnterScriptStatement
(
ctx
*
parser
.
ScriptStatementContext
)
{
fmt
.
Println
(
"EnterScriptStatement"
)
if
reflect
.
TypeOf
(
ctx
.
GetChild
(
0
))
.
String
()
==
"*parser.ExpressionStmtAltContext"
{
cmdExpr
:=
ctx
.
GetChild
(
0
)
.
(
*
parser
.
ExpressionStmtAltContext
)
.
StatementExpression
()
.
GetChild
(
0
)
.
(
*
parser
.
CommandExpressionContext
)
.
Expression
()
if
cmdExpr
!=
nil
{
...
...
@@ -33,9 +36,15 @@ func (s *GroovyIdentifierListener) EnterScriptStatement(ctx *parser.ScriptStatem
}
}
func
buildGroovyMap
(
pathExprCtx
*
parser
.
PathExpressionContext
)
{
func
(
s
*
GroovyIdentifierListener
)
GetDepsInfo
()
[]
domain
.
JDependency
{
return
nodeDeps
}
func
buildGroovyMap
(
pathExprCtx
*
parser
.
PathExpressionContext
)
[]
domain
.
JDependency
{
if
reflect
.
TypeOf
(
pathExprCtx
.
GetChild
(
0
))
.
String
()
==
"*parser.IdentifierPrmrAltContext"
{
fmt
.
Println
(
pathExprCtx
.
GetChild
(
0
)
.
(
antlr
.
ParseTree
)
.
GetText
())
if
pathExprCtx
.
GetChild
(
0
)
.
(
antlr
.
ParseTree
)
.
GetText
()
!=
"dependencies"
{
return
nil
}
}
pathChild
:=
pathExprCtx
.
GetChild
(
1
)
if
pathChild
!=
nil
{
...
...
@@ -45,19 +54,22 @@ func buildGroovyMap(pathExprCtx *parser.PathExpressionContext) {
expressionContext
:=
pathElement
.
ClosureOrLambdaExpression
()
.
(
*
parser
.
ClosureOrLambdaExpressionContext
)
if
reflect
.
TypeOf
(
expressionContext
.
GetChild
(
0
))
.
String
()
==
"*parser.ClosureContext"
{
closureContext
:=
expressionContext
.
GetChild
(
0
)
.
(
*
parser
.
ClosureContext
)
buildBlockStatements
(
closureContext
)
nodeDeps
=
buildBlockStatements
(
closureContext
)
return
nodeDeps
}
}
}
return
nil
}
func
buildBlockStatements
(
closureContext
*
parser
.
ClosureContext
)
{
func
buildBlockStatements
(
closureContext
*
parser
.
ClosureContext
)
[]
domain
.
JDependency
{
var
results
[]
domain
.
JDependency
statementsContext
:=
closureContext
.
BlockStatementsOpt
()
.
(
*
parser
.
BlockStatementsOptContext
)
.
BlockStatements
()
.
(
*
parser
.
BlockStatementsContext
)
for
_
,
blockStatement
:=
range
statementsContext
.
AllBlockStatement
()
{
child
:=
blockStatement
.
GetChild
(
0
)
.
GetChild
(
0
)
.
GetChild
(
0
)
.
(
*
parser
.
CommandExpressionContext
)
declare
:=
child
.
GetChild
(
0
)
.
(
antlr
.
ParseTree
)
.
GetText
()
var
deps
[]
string
=
nil
var
result
*
domain
.
JDependency
=
nil
for
_
,
arg
:=
range
child
.
GetChild
(
1
)
.
(
antlr
.
ParseTree
)
.
(
*
parser
.
ArgumentListContext
)
.
AllArgumentListElement
()
{
if
reflect
.
TypeOf
(
arg
.
(
*
parser
.
ArgumentListElementContext
)
.
GetChild
(
0
))
.
String
()
==
"*parser.ExpressionListElementContext"
{
listElementContext
:=
arg
.
(
*
parser
.
ArgumentListElementContext
)
.
GetChild
(
0
)
.
(
*
parser
.
ExpressionListElementContext
)
...
...
@@ -68,11 +80,22 @@ func buildBlockStatements(closureContext *parser.ClosureContext) {
GetChild
(
0
)
.
(
*
parser
.
LiteralPrmrAltContext
)
result
:=
literalPrmrAltContext
.
Literal
()
.
GetChild
(
0
)
.
(
*
parser
.
StringLiteralContext
)
.
StringLiteral
()
.
GetText
()
deps
=
append
(
deps
,
result
)
result
Str
:=
literalPrmrAltContext
.
Literal
()
.
GetChild
(
0
)
.
(
*
parser
.
StringLiteralContext
)
.
StringLiteral
()
.
GetText
()
result
=
ConvertToJDep
(
resultStr
)
}
}
fmt
.
Println
(
declare
,
deps
)
if
result
!=
nil
{
result
.
Scope
=
declare
results
=
append
(
results
,
*
result
)
}
}
return
results
}
func
ConvertToJDep
(
result
string
)
*
domain
.
JDependency
{
withQuote
:=
strings
.
ReplaceAll
(
result
,
"'"
,
""
)
split
:=
strings
.
Split
(
withQuote
,
":"
)
return
domain
.
NewJDependency
(
split
[
0
],
split
[
1
])
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录