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

refactor: [ddd] extract vars

上级 fb0533bb
......@@ -8,7 +8,6 @@ import (
"github.com/phodal/coca/core/context/api"
"github.com/phodal/coca/core/context/call"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast"
"github.com/spf13/cobra"
"log"
"os"
......@@ -31,7 +30,7 @@ var (
apiCmdConfig ApiCmdConfig
restApis []domain.RestApi
identifiers = ast.LoadIdentify(apiCmdConfig.DependencePath)
identifiers = cmd_util.LoadIdentify(apiCmdConfig.DependencePath)
identifiersMap = domain.BuildIdentifierMap(identifiers)
diMap = domain.BuildDIMap(identifiers, identifiersMap)
)
......
......@@ -7,7 +7,6 @@ import (
"github.com/phodal/coca/core/context/arch"
"github.com/phodal/coca/core/context/arch/tequila"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast"
"github.com/spf13/cobra"
"os"
"strings"
......@@ -27,7 +26,7 @@ var archCmd = &cobra.Command{
Short: "project package visualization",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
identifiers = ast.LoadIdentify(apiCmdConfig.DependencePath)
identifiers = cmd_util.LoadIdentify(apiCmdConfig.DependencePath)
identifiersMap = domain.BuildIdentifierMap(identifiers)
parsedDeps := cmd_util.GetDepsFromJson(archCmdConfig.DependencePath)
......
package cmd_util
import (
"encoding/json"
"github.com/phodal/coca/core/domain"
"log"
)
func GetDepsFromJson(depPath string) []domain.JClassNode {
var parsedDeps []domain.JClassNode
file := ReadFile(depPath)
if file == nil {
log.Fatal("lost file:" + depPath)
}
_ = json.Unmarshal(file, &parsedDeps)
return parsedDeps
}
package ast
package cmd_util
import (
"encoding/json"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/core/context/analysis"
"github.com/phodal/coca/core/domain"
)
......@@ -10,13 +9,13 @@ import (
func LoadIdentify(importPath string) []domain.JIdentifier {
var identifiers []domain.JIdentifier
apiContent := cmd_util.ReadCocaFile("identify.json")
apiContent := ReadCocaFile("identify.json")
if apiContent == nil || string(apiContent) == "null" {
identifierApp := new(analysis.JavaIdentifierApp)
ident := identifierApp.AnalysisPath(importPath)
identModel, _ := json.MarshalIndent(ident, "", "\t")
cmd_util.WriteToCocaFile("identify.json", string(identModel))
WriteToCocaFile("identify.json", string(identModel))
return *&ident
}
......@@ -28,14 +27,14 @@ func LoadIdentify(importPath string) []domain.JIdentifier {
func LoadTestIdentify(files []string) []domain.JIdentifier {
var identifiers []domain.JIdentifier
apiContent := cmd_util.ReadCocaFile("tidentify.json")
apiContent := ReadCocaFile("tidentify.json")
if apiContent == nil || string(apiContent) == "null" {
identifierApp := analysis.NewJavaIdentifierApp()
ident := identifierApp.AnalysisFiles(files)
identModel, _ := json.MarshalIndent(ident, "", "\t")
cmd_util.WriteToCocaFile("tidentify.json", string(identModel))
WriteToCocaFile("tidentify.json", string(identModel))
return *&ident
}
......
package cmd_util
import (
"encoding/json"
"fmt"
"github.com/phodal/coca/cmd/config"
"github.com/phodal/coca/core/domain"
"log"
"os/exec"
)
func GetDepsFromJson(depPath string) []domain.JClassNode {
var parsedDeps []domain.JClassNode
file := ReadFile(depPath)
if file == nil {
log.Fatal("lost file:" + depPath)
}
_ = json.Unmarshal(file, &parsedDeps)
return parsedDeps
}
func ConvertToSvg(name string) {
cmd := exec.Command("dot", []string{"-Tsvg", config.CocaConfig.ReporterPath + "/" + name + ".dot", "-o", config.CocaConfig.ReporterPath + "/" + name + ".svg"}...)
_, err := cmd.CombinedOutput()
......
......@@ -9,7 +9,6 @@ import (
"github.com/phodal/coca/core/context/analysis"
"github.com/phodal/coca/core/context/tbs"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast"
"github.com/spf13/cobra"
"os"
"strconv"
......@@ -32,7 +31,7 @@ var tbsCmd = &cobra.Command{
files := coca_file.GetJavaTestFiles(tbsCmdConfig.Path)
var identifiers []domain.JIdentifier
identifiers = ast.LoadTestIdentify(files)
identifiers = cmd_util.LoadTestIdentify(files)
identifiersMap := domain.BuildIdentifierMap(identifiers)
var classes []string = nil
......
......@@ -2,10 +2,10 @@ package tbs
import (
. "github.com/onsi/gomega"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/core/adapter/coca_file"
"github.com/phodal/coca/core/context/analysis"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast"
"path/filepath"
"testing"
)
......@@ -115,7 +115,7 @@ func buildTbsResult(codePath string) []TestBadSmell {
files := coca_file.GetJavaTestFiles(codePath)
var identifiers []domain.JIdentifier
identifiers = ast.LoadTestIdentify(files)
identifiers = cmd_util.LoadTestIdentify(files)
identifiersMap := domain.BuildIdentifierMap(identifiers)
var classes []string = nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册