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

refactor: [ddd] extract vars

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