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

ci: add output for windows & macOS

上级 e4c81f02
......@@ -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) {
......
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
......@@ -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)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册