mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-12 02:55:16 +00:00
Compare commits
13 Commits
v0.18.0
...
release/v0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97ec142262 | ||
|
|
dfc873bc15 | ||
|
|
cca02dd5ff | ||
|
|
91f43bf94c | ||
|
|
0583fe7d32 | ||
|
|
6ca1d73b61 | ||
|
|
4c87861642 | ||
|
|
a2d7517ca0 | ||
|
|
8efaff19ce | ||
|
|
ac056d17af | ||
|
|
fc904827cd | ||
|
|
c240b05369 | ||
|
|
a2acbe32bf |
17
harness/build.go
Executable file → Normal file
17
harness/build.go
Executable file → Normal file
@@ -17,12 +17,19 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
"sort"
|
||||
|
||||
"github.com/revel/revel"
|
||||
)
|
||||
|
||||
var importErrorPattern = regexp.MustCompile("cannot find package \"([^\"]+)\"")
|
||||
|
||||
type ByString []*TypeInfo
|
||||
|
||||
func (c ByString) Len() int { return len(c) }
|
||||
func (c ByString) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
|
||||
func (c ByString) Less(i, j int) bool { return c[i].String() < c[j].String() }
|
||||
|
||||
// Build the app:
|
||||
// 1. Generate the the main.go file.
|
||||
// 2. Run the appropriate "go build" command.
|
||||
@@ -39,12 +46,16 @@ func Build(buildFlags ...string) (app *App, compileError *revel.Error) {
|
||||
|
||||
// Add the db.import to the import paths.
|
||||
if dbImportPath, found := revel.Config.String("db.import"); found {
|
||||
sourceInfo.InitImportPaths = append(sourceInfo.InitImportPaths, strings.Split(dbImportPath,",")...)
|
||||
sourceInfo.InitImportPaths = append(sourceInfo.InitImportPaths, strings.Split(dbImportPath, ",")...)
|
||||
}
|
||||
|
||||
// Sort controllers so that file generation is reproducible
|
||||
controllers := sourceInfo.ControllerSpecs()
|
||||
sort.Stable(ByString(controllers))
|
||||
|
||||
// Generate two source files.
|
||||
templateArgs := map[string]interface{}{
|
||||
"Controllers": sourceInfo.ControllerSpecs(),
|
||||
"Controllers": controllers,
|
||||
"ValidationKeys": sourceInfo.ValidationKeys,
|
||||
"ImportPaths": calcImportAliases(sourceInfo),
|
||||
"TestSuites": sourceInfo.TestSuites(),
|
||||
@@ -210,7 +221,7 @@ func getAppVersion() string {
|
||||
if (err != nil && os.IsNotExist(err)) || !info.IsDir() {
|
||||
return ""
|
||||
}
|
||||
gitCmd := exec.Command(gitPath, "--git-dir="+gitDir, "describe", "--always", "--dirty")
|
||||
gitCmd := exec.Command(gitPath, "--git-dir="+gitDir, "--work-tree="+revel.BasePath, "describe", "--always", "--dirty")
|
||||
revel.RevelLog.Debug("Exec:", "args", gitCmd.Args)
|
||||
output, err := gitCmd.Output()
|
||||
|
||||
|
||||
@@ -17,8 +17,10 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/revel/revel"
|
||||
"unicode"
|
||||
|
||||
"github.com/revel/revel"
|
||||
"log"
|
||||
)
|
||||
|
||||
// SourceInfo is the top-level struct containing all extracted information
|
||||
@@ -221,8 +223,8 @@ func processPackage(fset *token.FileSet, pkgImportPath, pkgPath string, pkg *ast
|
||||
)
|
||||
|
||||
// For each source file in the package...
|
||||
log.Println("Exaiming files in path", pkgPath)
|
||||
for _, file := range pkg.Files {
|
||||
|
||||
// Imports maps the package key to the full import path.
|
||||
// e.g. import "sample/app/models" => "models": "sample/app/models"
|
||||
imports := map[string]string{}
|
||||
@@ -239,8 +241,8 @@ func processPackage(fset *token.FileSet, pkgImportPath, pkgPath string, pkg *ast
|
||||
structSpecs = appendStruct(structSpecs, pkgImportPath, pkg, decl, imports, fset)
|
||||
}
|
||||
|
||||
// If this is a func...
|
||||
if funcDecl, ok := decl.(*ast.FuncDecl); ok {
|
||||
// If this is a func... (ignore nil for external (non-Go) function)
|
||||
if funcDecl, ok := decl.(*ast.FuncDecl); ok && funcDecl.Body != nil {
|
||||
// Scan it for validation calls
|
||||
lineKeys := getValidationKeys(fset, funcDecl, imports)
|
||||
if len(lineKeys) > 0 {
|
||||
@@ -782,11 +784,18 @@ func NewTypeExpr(pkgName string, expr ast.Expr) TypeExpr {
|
||||
case *ast.ArrayType:
|
||||
e := NewTypeExpr(pkgName, t.Elt)
|
||||
return TypeExpr{"[]" + e.Expr, e.PkgName, e.pkgIndex + 2, e.Valid}
|
||||
case *ast.MapType:
|
||||
if identKey, ok := t.Key.(*ast.Ident); ok && IsBuiltinType(identKey.Name) {
|
||||
e := NewTypeExpr(pkgName, t.Value)
|
||||
return TypeExpr{"map[" + identKey.Name + "]" + e.Expr, e.PkgName, e.pkgIndex + len("map["+identKey.Name+"]"), e.Valid}
|
||||
}
|
||||
|
||||
revel.RevelLog.Error("Failed to generate name for field. Make sure the field name is valid.")
|
||||
case *ast.Ellipsis:
|
||||
e := NewTypeExpr(pkgName, t.Elt)
|
||||
return TypeExpr{"[]" + e.Expr, e.PkgName, e.pkgIndex + 2, e.Valid}
|
||||
default:
|
||||
revel.RevelLog.Error("Failed to generate name for field. Make sure the field name is valid.")
|
||||
revel.RevelLog.Error("Failed to generate name for field. Make sure the field name is valid.", "package", pkgName, "expresion",expr)
|
||||
}
|
||||
return TypeExpr{Valid: false}
|
||||
}
|
||||
@@ -821,9 +830,8 @@ func IsBuiltinType(name string) bool {
|
||||
}
|
||||
|
||||
func importPathFromPath(root string) string {
|
||||
vendoringPath := revel.BasePath + "/vendor/"
|
||||
if strings.HasPrefix(root, vendoringPath) {
|
||||
return filepath.ToSlash(root[len(vendoringPath):])
|
||||
if vendorIdx := strings.Index(root, "/vendor/"); vendorIdx != -1 {
|
||||
return filepath.ToSlash(root[vendorIdx+8:])
|
||||
}
|
||||
for _, gopath := range filepath.SplitList(build.Default.GOPATH) {
|
||||
srcPath := filepath.Join(gopath, "src")
|
||||
|
||||
@@ -94,18 +94,20 @@ func TestGetValidationKeys(t *testing.T) {
|
||||
}
|
||||
|
||||
var TypeExprs = map[string]TypeExpr{
|
||||
"int": {"int", "", 0, true},
|
||||
"*int": {"*int", "", 1, true},
|
||||
"[]int": {"[]int", "", 2, true},
|
||||
"...int": {"[]int", "", 2, true},
|
||||
"[]*int": {"[]*int", "", 3, true},
|
||||
"...*int": {"[]*int", "", 3, true},
|
||||
"MyType": {"MyType", "pkg", 0, true},
|
||||
"*MyType": {"*MyType", "pkg", 1, true},
|
||||
"[]MyType": {"[]MyType", "pkg", 2, true},
|
||||
"...MyType": {"[]MyType", "pkg", 2, true},
|
||||
"[]*MyType": {"[]*MyType", "pkg", 3, true},
|
||||
"...*MyType": {"[]*MyType", "pkg", 3, true},
|
||||
"int": {"int", "", 0, true},
|
||||
"*int": {"*int", "", 1, true},
|
||||
"[]int": {"[]int", "", 2, true},
|
||||
"...int": {"[]int", "", 2, true},
|
||||
"[]*int": {"[]*int", "", 3, true},
|
||||
"...*int": {"[]*int", "", 3, true},
|
||||
"MyType": {"MyType", "pkg", 0, true},
|
||||
"*MyType": {"*MyType", "pkg", 1, true},
|
||||
"[]MyType": {"[]MyType", "pkg", 2, true},
|
||||
"...MyType": {"[]MyType", "pkg", 2, true},
|
||||
"[]*MyType": {"[]*MyType", "pkg", 3, true},
|
||||
"...*MyType": {"[]*MyType", "pkg", 3, true},
|
||||
"map[int]MyType": {"map[int]MyType", "pkg", 8, true},
|
||||
"map[int]*MyType": {"map[int]*MyType", "pkg", 9, true},
|
||||
}
|
||||
|
||||
func TestTypeExpr(t *testing.T) {
|
||||
|
||||
@@ -44,6 +44,7 @@ var HeaderFilter = func(c *revel.Controller, fc []revel.Filter) {
|
||||
c.Response.Out.Header().Add("X-Frame-Options", "SAMEORIGIN")
|
||||
c.Response.Out.Header().Add("X-XSS-Protection", "1; mode=block")
|
||||
c.Response.Out.Header().Add("X-Content-Type-Options", "nosniff")
|
||||
c.Response.Out.Header().Add("Referrer-Policy", "strict-origin-when-cross-origin")
|
||||
|
||||
fc[0](c, fc[1:]) // Execute the next filter stage.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user