Created
March 28, 2016 04:53
-
-
Save mattn/39dc97d6baed97321b9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/harness/build.go b/harness/build.go | |
index 31241e7..b52ec92 100755 | |
--- a/harness/build.go | |
+++ b/harness/build.go | |
@@ -5,7 +5,6 @@ import ( | |
"go/build" | |
"os" | |
"os/exec" | |
- "path" | |
"path/filepath" | |
"regexp" | |
"runtime" | |
@@ -63,7 +62,7 @@ func Build(buildFlags ...string) (app *App, compileError *revel.Error) { | |
} | |
// Binary path is a combination of $GOBIN/revel.d directory, app's import path and its name. | |
- binName := path.Join(pkg.BinDir, "revel.d", revel.ImportPath, path.Base(revel.BasePath)) | |
+ binName := filepath.Join(pkg.BinDir, "revel.d", revel.ImportPath, filepath.Base(revel.BasePath)) | |
// Change binary path for Windows build | |
goos := runtime.GOOS | |
@@ -77,7 +76,7 @@ func Build(buildFlags ...string) (app *App, compileError *revel.Error) { | |
gotten := make(map[string]struct{}) | |
for { | |
appVersion := getAppVersion() | |
- versionLinkerFlags := fmt.Sprintf("-X %s/app.APP_VERSION \"%s\"", revel.ImportPath, appVersion) | |
+ versionLinkerFlags := fmt.Sprintf("-X %s/app.APP_VERSION=\"%s\"", revel.ImportPath, appVersion) | |
flags := []string{ | |
"build", | |
"-ldflags", versionLinkerFlags, | |
@@ -88,7 +87,7 @@ func Build(buildFlags ...string) (app *App, compileError *revel.Error) { | |
flags = append(flags, buildFlags...) | |
// The main path | |
- flags = append(flags, path.Join(revel.ImportPath, "app", "tmp")) | |
+ flags = append(flags, filepath.Join(revel.ImportPath, "app", "tmp")) | |
buildCmd := exec.Command(goPath, flags...) | |
revel.TRACE.Println("Exec:", buildCmd.Args) | |
@@ -142,7 +141,7 @@ func getAppVersion() string { | |
// Check for the git binary | |
if gitPath, err := exec.LookPath("git"); err == nil { | |
// Check for the .git directory | |
- gitDir := path.Join(revel.BasePath, ".git") | |
+ gitDir := filepath.Join(revel.BasePath, ".git") | |
info, err := os.Stat(gitDir) | |
if (err != nil && os.IsNotExist(err)) || !info.IsDir() { | |
return "" | |
@@ -170,7 +169,7 @@ func cleanSource(dirs ...string) { | |
func cleanDir(dir string) { | |
revel.INFO.Println("Cleaning dir " + dir) | |
- tmpPath := path.Join(revel.AppPath, dir) | |
+ tmpPath := filepath.Join(revel.AppPath, dir) | |
f, err := os.Open(tmpPath) | |
if err != nil { | |
revel.ERROR.Println("Failed to clean dir:", err) | |
@@ -181,7 +180,7 @@ func cleanDir(dir string) { | |
revel.ERROR.Println("Failed to clean dir:", err) | |
} else { | |
for _, info := range infos { | |
- path := path.Join(tmpPath, info.Name()) | |
+ path := filepath.Join(tmpPath, info.Name()) | |
if info.IsDir() { | |
err := os.RemoveAll(path) | |
if err != nil { | |
@@ -198,7 +197,6 @@ func cleanDir(dir string) { | |
} | |
} | |
- | |
// genSource renders the given template to produce source code, which it writes | |
// to the given directory and file. | |
func genSource(dir, filename, templateSource string, args map[string]interface{}) { | |
@@ -208,14 +206,14 @@ func genSource(dir, filename, templateSource string, args map[string]interface{} | |
// Create a fresh dir. | |
cleanSource(dir) | |
- tmpPath := path.Join(revel.AppPath, dir) | |
+ tmpPath := filepath.Join(revel.AppPath, dir) | |
err := os.Mkdir(tmpPath, 0777) | |
if err != nil && !os.IsExist(err) { | |
revel.ERROR.Fatalf("Failed to make '%v' directory: %v", dir, err) | |
} | |
// Create the file | |
- file, err := os.Create(path.Join(tmpPath, filename)) | |
+ file, err := os.Create(filepath.Join(tmpPath, filename)) | |
defer file.Close() | |
if err != nil { | |
revel.ERROR.Fatalf("Failed to create file: %v", err) | |
diff --git a/revel/build.go b/revel/build.go | |
index 45e7d07..4ad1933 100644 | |
--- a/revel/build.go | |
+++ b/revel/build.go | |
@@ -3,12 +3,11 @@ package main | |
import ( | |
"fmt" | |
"os" | |
- "path" | |
"path/filepath" | |
"strings" | |
- "github.com/revel/revel" | |
"github.com/revel/cmd/harness" | |
+ "github.com/revel/revel" | |
) | |
var cmdBuild = &Command{ | |
@@ -43,7 +42,7 @@ func buildApp(args []string) { | |
// First, verify that it is either already empty or looks like a previous | |
// build (to avoid clobbering anything) | |
- if exists(destPath) && !empty(destPath) && !exists(path.Join(destPath, "run.sh")) { | |
+ if exists(destPath) && !empty(destPath) && !exists(filepath.Join(destPath, "run.sh")) { | |
errorf("Abort: %s exists and does not look like a build directory.", destPath) | |
} | |
@@ -60,14 +59,14 @@ func buildApp(args []string) { | |
// - app | |
// Revel and the app are in a directory structure mirroring import path | |
- srcPath := path.Join(destPath, "src") | |
- destBinaryPath := path.Join(destPath, filepath.Base(app.BinaryPath)) | |
- tmpRevelPath := path.Join(srcPath, filepath.FromSlash(revel.REVEL_IMPORT_PATH)) | |
+ srcPath := filepath.Join(destPath, "src") | |
+ destBinaryPath := filepath.Join(destPath, filepath.Base(app.BinaryPath)) | |
+ tmpRevelPath := filepath.Join(srcPath, filepath.FromSlash(revel.REVEL_IMPORT_PATH)) | |
mustCopyFile(destBinaryPath, app.BinaryPath) | |
mustChmod(destBinaryPath, 0755) | |
- mustCopyDir(path.Join(tmpRevelPath, "conf"), path.Join(revel.RevelPath, "conf"), nil) | |
- mustCopyDir(path.Join(tmpRevelPath, "templates"), path.Join(revel.RevelPath, "templates"), nil) | |
- mustCopyDir(path.Join(srcPath, filepath.FromSlash(appImportPath)), revel.BasePath, nil) | |
+ mustCopyDir(filepath.Join(tmpRevelPath, "conf"), filepath.Join(revel.RevelPath, "conf"), nil) | |
+ mustCopyDir(filepath.Join(tmpRevelPath, "templates"), filepath.Join(revel.RevelPath, "templates"), nil) | |
+ mustCopyDir(filepath.Join(srcPath, filepath.FromSlash(appImportPath)), revel.BasePath, nil) | |
// Find all the modules used and copy them over. | |
config := revel.Config.Raw() | |
@@ -90,13 +89,13 @@ func buildApp(args []string) { | |
} | |
} | |
for importPath, fsPath := range modulePaths { | |
- mustCopyDir(path.Join(srcPath, importPath), fsPath, nil) | |
+ mustCopyDir(filepath.Join(srcPath, importPath), fsPath, nil) | |
} | |
tmplData, runShPath := map[string]interface{}{ | |
"BinName": filepath.Base(app.BinaryPath), | |
"ImportPath": appImportPath, | |
- }, path.Join(destPath, "run.sh") | |
+ }, filepath.Join(destPath, "run.sh") | |
mustRenderTemplate( | |
runShPath, | |
diff --git a/revel/clean.go b/revel/clean.go | |
index 1af29bf..d882df8 100644 | |
--- a/revel/clean.go | |
+++ b/revel/clean.go | |
@@ -4,7 +4,7 @@ import ( | |
"fmt" | |
"go/build" | |
"os" | |
- "path" | |
+ "path/filepath" | |
) | |
var cmdClean = &Command{ | |
@@ -38,7 +38,7 @@ func cleanApp(args []string) { | |
} | |
// Remove the app/tmp directory. | |
- tmpDir := path.Join(appPkg.Dir, "app", "tmp") | |
+ tmpDir := filepath.Join(appPkg.Dir, "app", "tmp") | |
fmt.Println("Removing:", tmpDir) | |
err = os.RemoveAll(tmpDir) | |
if err != nil { | |
diff --git a/revel/test.go b/revel/test.go | |
index 3128cd6..83de718 100644 | |
--- a/revel/test.go | |
+++ b/revel/test.go | |
@@ -3,14 +3,14 @@ package main | |
import ( | |
"encoding/json" | |
"fmt" | |
- "github.com/revel/revel" | |
"github.com/revel/cmd/harness" | |
"github.com/revel/modules/testrunner/app/controllers" | |
+ "github.com/revel/revel" | |
"io" | |
"io/ioutil" | |
"net/http" | |
"os" | |
- "path" | |
+ "path/filepath" | |
"strings" | |
"time" | |
) | |
@@ -78,7 +78,7 @@ You can add it to a run mode configuration with the following line: | |
} | |
// Create a directory to hold the test result files. | |
- resultPath := path.Join(revel.BasePath, "test-results") | |
+ resultPath := filepath.Join(revel.BasePath, "test-results") | |
if err = os.RemoveAll(resultPath); err != nil { | |
errorf("Failed to remove test result directory %s: %s", resultPath, err) | |
} | |
@@ -87,7 +87,7 @@ You can add it to a run mode configuration with the following line: | |
} | |
// Direct all the output into a file in the test-results directory. | |
- file, err := os.OpenFile(path.Join(resultPath, "app.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | |
+ file, err := os.OpenFile(filepath.Join(resultPath, "app.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | |
if err != nil { | |
errorf("Failed to create log file: %s", err) | |
} | |
@@ -137,7 +137,7 @@ You can add it to a run mode configuration with the following line: | |
// Load the result template, which we execute for each suite. | |
module, _ := revel.ModuleByName("testrunner") | |
- TemplateLoader := revel.NewTemplateLoader([]string{path.Join(module.Path, "app", "views")}) | |
+ TemplateLoader := revel.NewTemplateLoader([]string{filepath.Join(module.Path, "app", "views")}) | |
if err := TemplateLoader.Refresh(); err != nil { | |
errorf("Failed to compile templates: %s", err) | |
} | |
@@ -187,7 +187,7 @@ You can add it to a run mode configuration with the following line: | |
} | |
fmt.Printf("%8s%3s%6ds\n", suiteResultStr, suiteAlert, int(time.Since(startTime).Seconds())) | |
// Create the result HTML file. | |
- suiteResultFilename := path.Join(resultPath, | |
+ suiteResultFilename := filepath.Join(resultPath, | |
fmt.Sprintf("%s.%s.html", suite.Name, strings.ToLower(suiteResultStr))) | |
suiteResultFile, err := os.Create(suiteResultFilename) | |
if err != nil { | |
@@ -218,8 +218,8 @@ You can add it to a run mode configuration with the following line: | |
} | |
func writeResultFile(resultPath, name, content string) { | |
- if err := ioutil.WriteFile(path.Join(resultPath, name), []byte(content), 0666); err != nil { | |
- errorf("Failed to write result file %s: %s", path.Join(resultPath, name), err) | |
+ if err := ioutil.WriteFile(filepath.Join(resultPath, name), []byte(content), 0666); err != nil { | |
+ errorf("Failed to write result file %s: %s", filepath.Join(resultPath, name), err) | |
} | |
} | |
diff --git a/revel/util.go b/revel/util.go | |
index 4240565..1a54fca 100644 | |
--- a/revel/util.go | |
+++ b/revel/util.go | |
@@ -6,7 +6,6 @@ import ( | |
"fmt" | |
"io" | |
"os" | |
- "path" | |
"path/filepath" | |
"strings" | |
"text/template" | |
@@ -82,7 +81,7 @@ func mustCopyDir(destDir, srcDir string, data map[string]interface{}) error { | |
// Get the relative path from the source base, and the corresponding path in | |
// the dest directory. | |
relSrcPath := strings.TrimLeft(srcPath[len(fullSrcDir):], string(os.PathSeparator)) | |
- destPath := path.Join(destDir, relSrcPath) | |
+ destPath := filepath.Join(destDir, relSrcPath) | |
// Skip dot files and dot directories. | |
if strings.HasPrefix(relSrcPath, ".") { | |
@@ -94,7 +93,7 @@ func mustCopyDir(destDir, srcDir string, data map[string]interface{}) error { | |
// Create a subdirectory if necessary. | |
if info.IsDir() { | |
- err := os.MkdirAll(path.Join(destDir, relSrcPath), 0777) | |
+ err := os.MkdirAll(filepath.Join(destDir, relSrcPath), 0777) | |
if !os.IsExist(err) { | |
panicOnError(err, "Failed to create directory") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment