未验证 提交 af90d4c4 编写于 作者: P Phodal Huang

feat: add basic call svg

上级 f66243ed
...@@ -56,4 +56,6 @@ web/ ...@@ -56,4 +56,6 @@ web/
bs.json bs.json
nodeInfos.json nodeInfos.json
apis.json apis.json
output.dot output.dot
\ No newline at end of file call.dot
call.svg
\ No newline at end of file
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"log" "log"
"os/exec"
) )
...@@ -28,7 +29,14 @@ var callGraphCmd *cobra.Command = &cobra.Command{ ...@@ -28,7 +29,14 @@ var callGraphCmd *cobra.Command = &cobra.Command{
_ = json.Unmarshal(file, &parsedDeps) _ = json.Unmarshal(file, &parsedDeps)
analyser.Analysis(className, *&parsedDeps) content := analyser.Analysis(className, *&parsedDeps)
WriteToFile("call.dot", content)
cmd := exec.Command("dot", []string{"-Tsvg", "call.dot", "-o", "call.svg"}...)
_, err := cmd.CombinedOutput()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
} }
}, },
} }
......
...@@ -2,7 +2,6 @@ package domain ...@@ -2,7 +2,6 @@ package domain
import ( import (
"coca/src/adapter/models" "coca/src/adapter/models"
"fmt"
) )
type CallGraph struct { type CallGraph struct {
...@@ -12,12 +11,20 @@ func NewCallGraph() CallGraph { ...@@ -12,12 +11,20 @@ func NewCallGraph() CallGraph {
return *&CallGraph{} return *&CallGraph{}
} }
func (c CallGraph) Analysis(funcName string, clzs []models.JClassNode) { func (c CallGraph) Analysis(funcName string, clzs []models.JClassNode) string {
methodMap := c.BuildMethodMap(clzs) methodMap := c.BuildMethodMap(clzs)
BuildCallChain(funcName, methodMap) BuildCallChain(funcName, methodMap)
chain := BuildCallChain(funcName, methodMap) chain := BuildCallChain(funcName, methodMap)
fmt.Println(chain) dotContent := toGraphviz(chain)
return dotContent
}
func toGraphviz(chain string) string {
var result = "digraph G { \n"
result = result + chain
result = result + "}\n"
return result
} }
func BuildCallChain(funcName string, methodMap map[string][]string) string { func BuildCallChain(funcName string, methodMap map[string][]string) string {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册