Updated formating

Ran through testing individually for vendored Revel applications
This commit is contained in:
notzippy@gmail.com
2020-04-26 22:24:00 -07:00
parent 07d67846c1
commit 86736d6e43
22 changed files with 239 additions and 291 deletions

View File

@@ -1,4 +1,6 @@
package command
type (
New struct {
ImportCommand
@@ -6,6 +8,7 @@ type (
Package string `short:"p" long:"package" description:"The package name, this becomes the repfix to the app name, if defined vendored is set to true" required:"false"`
NotVendored bool `short:"V" long:"vendor" description:"True if project should not be configured with a go.mod"`
Run bool `short:"r" long:"run" description:"True if you want to run the application right away"`
Callback func() error
}
)

View File

@@ -177,7 +177,7 @@ func (c *CommandConfig) initAppFolder() (err error) {
appFolder = filepath.Join(wd,appFolder)
}
utils.Logger.Info("Determined app folder to be", "folder",appFolder, "working",wd)
utils.Logger.Info("Determined app folder to be", "appfolder",appFolder, "working",wd,"importPath",c.ImportPath)
// Use app folder to read the go.mod if it exists and extract the package information
goModFile := filepath.Join(appFolder,"go.mod")
@@ -214,24 +214,29 @@ func (c *CommandConfig) initAppFolder() (err error) {
workingDir, _ := os.Getwd()
goPathList := filepath.SplitList(c.GoPath)
bestpath := ""
for _, path := range goPathList {
if c.Index == NEW {
// If the GOPATH is part of the working dir this is the most likely target
if strings.HasPrefix(workingDir, path) {
bestpath = path
}
} else {
if utils.Exists(filepath.Join(path, "src", c.ImportPath)) {
c.SrcRoot = path
break
if !c.Vendored {
for _, path := range goPathList {
if c.Index == NEW {
// If the GOPATH is part of the working dir this is the most likely target
if strings.HasPrefix(workingDir, path) {
bestpath = path
}
} else {
if utils.Exists(filepath.Join(path, "src", c.ImportPath)) {
c.SrcRoot = path
break
}
}
}
if len(c.SrcRoot) == 0 && len(bestpath) > 0 {
c.SrcRoot = bestpath
}
} else {
c.SrcRoot = appFolder
}
utils.Logger.Info("Source root", "path", c.SrcRoot, "cwd", workingDir, "gopath", c.GoPath, "bestpath",bestpath)
if len(c.SrcRoot) == 0 && len(bestpath) > 0 {
c.SrcRoot = bestpath
}
// If source root is empty and this isn't a version then skip it
if len(c.SrcRoot) == 0 {
@@ -270,32 +275,11 @@ func (c *CommandConfig) InitPackageResolver() {
utils.Logger.Info("Request for package ", "package", pkgName, "use vendor", c.Vendored)
if c.Vendored {
goModCmd := exec.Command("go", "mod", "tidy")
utils.CmdInit(goModCmd, c.AppPath)
utils.CmdInit(goModCmd,!c.Vendored, c.AppPath)
goModCmd.Run()
return nil
}
//utils.Logger.Info("Using dependency manager to import package", "package", pkgName)
//
//// Check to see if the package exists locally
//_, err := build.Import(pkgName, c.AppPath, build.FindOnly)
//if err != nil {
// getCmd = exec.Command(depPath, "ensure", "-add", pkgName)
//} else {
// getCmd = exec.Command(depPath, "ensure", "-update", pkgName)
//}
//
//
//} else {
// utils.Logger.Info("No vendor folder detected, not using dependency manager to import package", "package", pkgName)
// getCmd = exec.Command(c.GoCmd, "get", "-u", pkgName)
//}
//
//utils.CmdInit(getCmd, c.AppPath)
//utils.Logger.Info("Go get command ", "exec", getCmd.Path, "dir", getCmd.Dir, "args", getCmd.Args, "env", getCmd.Env, "package", pkgName)
//output, err := getCmd.CombinedOutput()
//if err != nil {
// fmt.Printf("Error stack %v\n", logger.NewCallStack())
// utils.Logger.Error("Failed to import package", "error", err, "gopath", build.Default.GOPATH, "GO-ROOT", build.Default.GOROOT, "output", string(output))
//}
return nil
}
}

View File

@@ -12,14 +12,14 @@ import (
type SourceInfo struct {
// StructSpecs lists type info for all structs found under the code paths.
// They may be queried to determine which ones (transitively) embed certain types.
StructSpecs []*TypeInfo
StructSpecs []*TypeInfo
// ValidationKeys provides a two-level lookup. The keys are:
// 1. The fully-qualified function name,
// e.g. "github.com/revel/examples/chat/app/controllers.(*Application).Action"
// 2. Within that func's file, the line number of the (overall) expression statement.
// e.g. the line returned from runtime.Caller()
// The result of the lookup the name of variable being validated.
ValidationKeys map[string]map[int]string
ValidationKeys map[string]map[int]string
// A list of import paths.
// Revel notices files with an init() function and imports that package.
InitImportPaths []string
@@ -28,9 +28,9 @@ type SourceInfo struct {
// app/controllers/... that embed (directly or indirectly) revel.Controller
controllerSpecs []*TypeInfo
// testSuites list the types that constitute the set of application tests.
testSuites []*TypeInfo
testSuites []*TypeInfo
// packageMap a map of import to system directory (if available)
PackageMap map[string]string
PackageMap map[string]string
}
// TypesThatEmbed returns all types that (directly or indirectly) embed the
@@ -76,7 +76,7 @@ func (s *SourceInfo) TypesThatEmbed(targetType, packageFilter string) (filtered
utils.Logger.Info("Debug: Skipping adding spec for unexported type",
"type", filteredItem.StructName,
"package", filteredItem.ImportPath)
filtered = append(filtered[:i], filtered[i+1:]...)
filtered = append(filtered[:i], filtered[i + 1:]...)
exit = false
break
}
@@ -99,8 +99,8 @@ func (s *SourceInfo) TypesThatEmbed(targetType, packageFilter string) (filtered
// Report non controller structures in controller folder.
if !found && !strings.HasPrefix(spec.StructName, "Test") {
utils.Logger.Warn("Type found in package: "+packageFilter+
", but did not embed from: "+filepath.Base(targetType),
utils.Logger.Warn("Type found in package: " + packageFilter +
", but did not embed from: " + filepath.Base(targetType),
"name", spec.StructName, "importpath", spec.ImportPath, "foundstructures", unfoundNames)
}
}
@@ -112,7 +112,7 @@ func (s *SourceInfo) TypesThatEmbed(targetType, packageFilter string) (filtered
// `revel.Controller`
func (s *SourceInfo) ControllerSpecs() []*TypeInfo {
if s.controllerSpecs == nil {
s.controllerSpecs = s.TypesThatEmbed(RevelImportPath+".Controller", "controllers")
s.controllerSpecs = s.TypesThatEmbed(RevelImportPath + ".Controller", "controllers")
}
return s.controllerSpecs
}
@@ -121,7 +121,7 @@ func (s *SourceInfo) ControllerSpecs() []*TypeInfo {
// `testing.TestSuite`
func (s *SourceInfo) TestSuites() []*TypeInfo {
if s.testSuites == nil {
s.testSuites = s.TypesThatEmbed(RevelImportPath+"/testing.TestSuite", "testsuite")
s.testSuites = s.TypesThatEmbed(RevelImportPath + "/testing.TestSuite", "testsuite")
}
return s.testSuites
}

View File

@@ -8,20 +8,20 @@ import (
)
type Version struct {
Prefix string
Major int
Minor int
Maintenance int
Suffix string
BuildDate string
Prefix string
Major int
Minor int
Maintenance int
Suffix string
BuildDate string
MinGoVersion string
}
// The compatibility list
var frameworkCompatibleRangeList = [][]string{
{"0.0.0", "0.20.0"}, // minimum Revel version to use with this version of the tool
{"0.19.99", "0.30.0"}, // Compatible with Framework V 0.19.99 - 0.30.0
{"1.0.0", "1.1.0"}, // Compatible with Framework V 1.0 - 1.1
{"0.19.99", "0.30.0"}, // Compatible with Framework V 0.19.99 - 0.30.0
{"1.0.0", "1.1.0"}, // Compatible with Framework V 1.0 - 1.1
}
// Parses a version like v1.2.3a or 1.2