diff --git a/core/domain/refactor/move_class/move_class_app.go b/core/domain/refactor/move_class/move_class_app.go index 25bd24f4fdbbfea2a9fb362db803ca0758ae3ad6..30522f299c316c348942760f33214b9857a84b64 100644 --- a/core/domain/refactor/move_class/move_class_app.go +++ b/core/domain/refactor/move_class/move_class_app.go @@ -12,7 +12,6 @@ import ( "log" "os" "path/filepath" - "runtime" "strings" ) @@ -55,11 +54,10 @@ func (j *MoveClassApp) Analysis() []models2.JMoveStruct { nodes = append(nodes, *moveStruct) } - parseRename() return nodes } -func parseRename() { +func (j *MoveClassApp) Refactoring() { file, err := os.Open(moveConfig) if err != nil { log.Fatal(err) @@ -76,9 +74,11 @@ func parseRename() { originImport := splitStr[0] newImport := splitStr[1] - originFile, _ := filepath.Abs(configPath + originImport) - newFile, _ := filepath.Abs(configPath + newImport) + originFile := buildJavaPath(configPath, originImport) + newFile := buildJavaPath(configPath, newImport) + // for travis test + fmt.Println(originFile, newFile) copyClass(originFile, newFile) updatePackageInfo(originImport, newImport) @@ -99,7 +99,7 @@ func updatePackageInfo(originImport string, newImport string) { return } - path := buildJavaPath(configPath + newImport) + path := buildJavaPath(configPath, newImport) split := strings.Split(newImport, ".") pkg := strings.Join(split[:len(split)-1], ".") updateFile(path, originNode.GetPkgInfo().StartLine, "package "+pkg+";") @@ -138,24 +138,18 @@ func updateFile(path string, lineNum int, newImp string) { } func copyClass(originFile string, newFile string) { - originFile = buildJavaPath(originFile) - newFile = buildJavaPath(newFile) - _, err := CopyFile(originFile, newFile) if err != nil { log.Fatalln(err) } } -func buildJavaPath(originFile string) string { - // TODO: 适配 Windows - str := "" - if runtime.GOOS == "windows" { - str = strings.ReplaceAll(originFile, ".", "\\") + ".java" - } else { - str = strings.ReplaceAll(originFile, ".", "/") + ".java" +func buildJavaPath(configPath string, importStr string) string { + if !strings.HasSuffix(configPath, "/") { + configPath = configPath + "/" } - return str + path := configPath + strings.ReplaceAll(importStr, ".", "/") + ".java" + return filepath.FromSlash(path) } func CopyFile(src, dst string) (int64, error) { diff --git a/core/domain/refactor/move_class/move_class_app_test.go b/core/domain/refactor/move_class/move_class_app_test.go index b3d20e3d52dc6247f0224f7f86c52ef5f79c011b..1d3b3b0ee6ad9be9394837466a784a50d666e578 100644 --- a/core/domain/refactor/move_class/move_class_app_test.go +++ b/core/domain/refactor/move_class/move_class_app_test.go @@ -1,7 +1,10 @@ package move_class import ( + "fmt" . "github.com/onsi/gomega" + "os" + "os/exec" "path/filepath" "testing" ) @@ -10,14 +13,21 @@ func TestMoveClassApp(t *testing.T) { g := NewGomegaWithT(t) config := filepath.FromSlash("../../../../_fixtures/refactor/move.config") - path := filepath.FromSlash("../../../../_fixtures/refactor/") + path := filepath.FromSlash("../../../../_fixtures/refactor") absPath, _ := filepath.Abs(path) - NewMoveClassApp(config, filepath.FromSlash(absPath+ "/")) - //app.Analysis() + app := NewMoveClassApp(config, filepath.FromSlash(absPath)) + app.Analysis() + app.Refactoring() + + cmd := exec.Command("pwd") + output, _ := cmd.CombinedOutput() + fmt.Println("////////////////////////") + fmt.Println(string(output)) + // todo: fix in CI - //stat, _ := os.Stat(filepath.FromSlash(absPath + "/move/b/ImportForB.java")) - //g.Expect(stat.Name()).To(Equal("ImportForB.java")) + stat, _ := os.Stat(filepath.FromSlash(absPath + "/move/b/ImportForB.java")) + g.Expect(stat.Name()).To(Equal("ImportForB.java")) g.Expect(true).To(Equal(true)) } \ No newline at end of file diff --git a/core/domain/todo/todo_app.go b/core/domain/todo/todo_app.go index c4d6b466372e79f6030948e834aaa44f64455d1d..c54b41c0092343e87a14607543da8297ce2e055d 100644 --- a/core/domain/todo/todo_app.go +++ b/core/domain/todo/todo_app.go @@ -99,6 +99,7 @@ func runGitGetLog(line int, fileName string) string { cmd := exec.Command("git", historyArgs...) out, err := cmd.CombinedOutput() if err != nil { + fmt.Println(out) log.Fatalf("cmd.Run() failed with %s\n", err) }