diff --git a/README.md b/README.md index 561a262e4eaebf8effd10de2ad72644abef533ae..9e0b5a80b09458f6db0fb9701afe36f431ae367c 100644 --- a/README.md +++ b/README.md @@ -487,7 +487,11 @@ results - [x] Architecture Visualization - [ ] Architecture Guard - [ ] DSL Design - + +Tech Debt + + - Duplicate Code + - cmd/ -> user builder to refactoring ## Dev diff --git a/cmd/tbs.go b/cmd/tbs.go index cc2a7610453dce28ec6599eb8456aff54a2afba1..8b7318afd9f1dd811314b2eca4f85978e59f8267 100644 --- a/cmd/tbs.go +++ b/cmd/tbs.go @@ -27,7 +27,7 @@ var tbsCmd = &cobra.Command{ var identifiers []models.JIdentifier identifiers = adapter.LoadTestIdentify(files) - identifiersMap = adapter.BuildIdentifierMap(identifiers) + identifiersMap := adapter.BuildIdentifierMap(identifiers) var classes []string = nil for _, node := range identifiers { diff --git a/core/adapter/call/java_call_app.go b/core/adapter/call/java_call_app.go index 8753e4e9e8f57f4623d1330e1d8bd33c404401fc..47d0ce56426c961e1992299a0c359ff56cc7a840 100644 --- a/core/adapter/call/java_call_app.go +++ b/core/adapter/call/java_call_app.go @@ -28,9 +28,7 @@ func (j *JavaCallApp) AnalysisFiles(identNodes []models.JIdentifier, files []str identMap[ident.Package+"."+ident.ClassName] = ident } - for index := range files { - file := files[index] - + for _, file := range files { displayName := filepath.Base(file) fmt.Println("Start parse java call: " + displayName) diff --git a/core/adapter/helper.go b/core/adapter/helper.go index 174118634ef928c21e8fdd98f43a50b126cda792..aea392a58b76201eb2d88b74de324ccc6c070e71 100644 --- a/core/adapter/helper.go +++ b/core/adapter/helper.go @@ -1,10 +1,10 @@ package adapter import ( + "encoding/json" "github.com/phodal/coca/core/adapter/identifier" "github.com/phodal/coca/core/models" "github.com/phodal/coca/core/support" - "encoding/json" ) func BuildIdentifierMap(identifiers []models.JIdentifier) map[string]models.JIdentifier { @@ -20,7 +20,7 @@ func LoadIdentify(importPath string) []models.JIdentifier { var identifiers []models.JIdentifier apiContent := support.ReadCocaFile("identify.json") - if apiContent == nil { + if apiContent == nil || string(apiContent) == "null" { identifierApp := new(identifier.JavaIdentifierApp) ident := identifierApp.AnalysisPath(importPath) @@ -38,8 +38,9 @@ func LoadTestIdentify(files []string) []models.JIdentifier { var identifiers []models.JIdentifier apiContent := support.ReadCocaFile("tidentify.json") - if apiContent == nil { - identifierApp := new(identifier.JavaIdentifierApp) + + if apiContent == nil || string(apiContent) == "null" { + identifierApp := identifier.NewJavaIdentifierApp() ident := identifierApp.AnalysisFiles(files) identModel, _ := json.MarshalIndent(ident, "", "\t") @@ -60,7 +61,7 @@ func BuildDIMap(identifiers []models.JIdentifier, identifierMap map[string]model name := annotation.QualifiedName if (name == "Component" || name == "Repository") && len(clz.Implements) > 0 { superClz := identifierMap[clz.Implements[0]] - diMap[superClz.Package + "." + superClz.ClassName] = clz.Package + "." + clz.ClassName + diMap[superClz.Package+"."+superClz.ClassName] = clz.Package + "." + clz.ClassName } } } @@ -68,4 +69,3 @@ func BuildDIMap(identifiers []models.JIdentifier, identifierMap map[string]model return diMap } - diff --git a/core/domain/tbs/tbs_app_test.go b/core/domain/tbs/tbs_app_test.go new file mode 100644 index 0000000000000000000000000000000000000000..761db1baa6489ef70d9411caee6ed27a5b4c896f --- /dev/null +++ b/core/domain/tbs/tbs_app_test.go @@ -0,0 +1,34 @@ +package tbs + +import ( + . "github.com/onsi/gomega" + "github.com/phodal/coca/core/adapter" + "github.com/phodal/coca/core/adapter/call" + "github.com/phodal/coca/core/models" + "github.com/phodal/coca/core/support" + "testing" +) + +func TestTbsApp_AnalysisPath(t *testing.T) { + g := NewGomegaWithT(t) + + codePath := "../../../_fixtures/tbs/code/EmptyTest.java" + files := support.GetJavaTestFiles(codePath) + var identifiers []models.JIdentifier + + identifiers = adapter.LoadTestIdentify(files) + identifiersMap := adapter.BuildIdentifierMap(identifiers) + + var classes []string = nil + for _, node := range identifiers { + classes = append(classes, node.Package+"."+node.ClassName) + } + + analysisApp := call.NewJavaCallApp() + classNodes := analysisApp.AnalysisFiles(identifiers, files, classes) + + app := NewTbsApp() + result := app.AnalysisPath(classNodes, identifiersMap) + + g.Expect(result[0].Type).To(Equal("EmptyTest")) +} \ No newline at end of file diff --git a/core/support/file_analysis_helper.go b/core/support/file_analysis_helper.go index e6452f94a3cf68e5214eb393195d67260f11946b..2be4db9489439b26ceba24a2d72322e7c693d49d 100644 --- a/core/support/file_analysis_helper.go +++ b/core/support/file_analysis_helper.go @@ -17,6 +17,17 @@ func GetJavaFiles(codeDir string) []string { fmt.Println(err) } + fi, err := os.Stat(codeDir) + if err != nil { + fmt.Println(err) + return nil + } + + if fi.Mode().IsRegular() { + files = append(files, codeDir) + return files + } + _ = filepath.Walk(codeDir, func(path string, fi os.FileInfo, err error) error { if gitIgnore != nil { if gitIgnore.MatchesPath(path) { @@ -39,6 +50,17 @@ func GetJavaTestFiles(codeDir string) []string { fmt.Println(err) } + fi, err := os.Stat(codeDir) + if err != nil { + fmt.Println(err) + return nil + } + + if fi.Mode().IsRegular() { + files = append(files, codeDir) + return files + } + _ = filepath.Walk(codeDir, func(path string, fi os.FileInfo, err error) error { if gitIgnore != nil { if gitIgnore.MatchesPath(path) {