mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-11 18:54:31 +00:00
Lint fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
package command
|
||||
|
||||
type (
|
||||
Build struct {
|
||||
ImportCommand
|
||||
@@ -6,5 +7,4 @@ type (
|
||||
Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"`
|
||||
CopySource bool `short:"s" long:"include-source" description:"Copy the source code as well"`
|
||||
}
|
||||
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package command
|
||||
|
||||
type (
|
||||
Clean struct {
|
||||
ImportCommand
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package command
|
||||
|
||||
|
||||
type (
|
||||
New struct {
|
||||
ImportCommand
|
||||
@@ -8,7 +7,6 @@ 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 `long:"no-vendor" description:"True if project should not be configured with a go.mod, this requires you to have the project on the GOPATH, this is only compatible with go versions v1.12 or older"`
|
||||
Run bool `short:"r" long:"run" description:"True if you want to run the application right away"`
|
||||
Callback func() error
|
||||
Callback func() error
|
||||
}
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package command
|
||||
|
||||
type (
|
||||
Package struct {
|
||||
ImportCommand
|
||||
@@ -6,4 +7,4 @@ type (
|
||||
Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"`
|
||||
CopySource bool `short:"s" long:"include-source" description:"Copy the source code as well"`
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package command
|
||||
|
||||
type (
|
||||
Run struct {
|
||||
ImportCommand
|
||||
Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"`
|
||||
Port int `short:"p" long:"port" default:"-1" description:"The port to listen" `
|
||||
NoProxy bool `short:"n" long:"no-proxy" description:"True if proxy server should not be started. This will only update the main and routes files on change"`
|
||||
Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"`
|
||||
Port int `short:"p" long:"port" default:"-1" description:"The port to listen" `
|
||||
NoProxy bool `short:"n" long:"no-proxy" description:"True if proxy server should not be started. This will only update the main and routes files on change"`
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package command
|
||||
type (
|
||||
Test struct {
|
||||
ImportCommand
|
||||
Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"`
|
||||
Function string `short:"f" long:"suite-function" description:"The suite.function"`
|
||||
Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"`
|
||||
Function string `short:"f" long:"suite-function" description:"The suite.function"`
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package command
|
||||
|
||||
type (
|
||||
Version struct {
|
||||
ImportCommand
|
||||
|
||||
@@ -2,8 +2,6 @@ package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/revel/cmd"
|
||||
"github.com/revel/cmd/utils"
|
||||
"go/ast"
|
||||
"go/build"
|
||||
"go/parser"
|
||||
@@ -13,10 +11,13 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/revel/cmd"
|
||||
"github.com/revel/cmd/model/command"
|
||||
"github.com/revel/cmd/utils"
|
||||
)
|
||||
|
||||
// The constants
|
||||
// The constants.
|
||||
const (
|
||||
NEW COMMAND = iota + 1
|
||||
RUN
|
||||
@@ -28,38 +29,38 @@ const (
|
||||
)
|
||||
|
||||
type (
|
||||
// The Revel command type
|
||||
// The Revel command type.
|
||||
COMMAND int
|
||||
|
||||
// The Command config for the line input
|
||||
// The Command config for the line input.
|
||||
CommandConfig struct {
|
||||
Index COMMAND // The index
|
||||
Verbose []bool `short:"v" long:"debug" description:"If set the logger is set to verbose"` // True if debug is active
|
||||
FrameworkVersion *Version // The framework version
|
||||
CommandVersion *Version // The command version
|
||||
HistoricMode bool `long:"historic-run-mode" description:"If set the runmode is passed a string not json"` // True if debug is active
|
||||
ImportPath string // The import path (relative to a GOPATH)
|
||||
GoPath string // The GoPath
|
||||
GoCmd string // The full path to the go executable
|
||||
//SrcRoot string // The source root
|
||||
AppPath string // The application path (absolute)
|
||||
AppName string // The application name
|
||||
HistoricBuildMode bool `long:"historic-build-mode" description:"If set the code is scanned using the original parsers, not the go.1.11+"` // True if debug is active
|
||||
Vendored bool // True if the application is vendored
|
||||
PackageResolver func(pkgName string) error // a package resolver for the config
|
||||
Index COMMAND // The index
|
||||
Verbose []bool `short:"v" long:"debug" description:"If set the logger is set to verbose"` // True if debug is active
|
||||
FrameworkVersion *Version // The framework version
|
||||
CommandVersion *Version // The command version
|
||||
HistoricMode bool `long:"historic-run-mode" description:"If set the runmode is passed a string not json"` // True if debug is active
|
||||
ImportPath string // The import path (relative to a GOPATH)
|
||||
GoPath string // The GoPath
|
||||
GoCmd string // The full path to the go executable
|
||||
// SrcRoot string // The source root
|
||||
AppPath string // The application path (absolute)
|
||||
AppName string // The application name
|
||||
HistoricBuildMode bool `long:"historic-build-mode" description:"If set the code is scanned using the original parsers, not the go.1.11+"` // True if debug is active
|
||||
Vendored bool // True if the application is vendored
|
||||
PackageResolver func(pkgName string) error // a package resolver for the config
|
||||
BuildFlags []string `short:"X" long:"build-flags" description:"These flags will be used when building the application. May be specified multiple times, only applicable for Build, Run, Package, Test commands"`
|
||||
GoModFlags []string `long:"gomod-flags" description:"These flags will execute go mod commands for each flag, this happens during the build process"`
|
||||
New command.New `command:"new"`
|
||||
Build command.Build `command:"build"`
|
||||
Run command.Run `command:"run"`
|
||||
Package command.Package `command:"package"`
|
||||
Clean command.Clean `command:"clean"`
|
||||
Test command.Test `command:"test"`
|
||||
Version command.Version `command:"version"`
|
||||
GoModFlags []string `long:"gomod-flags" description:"These flags will execute go mod commands for each flag, this happens during the build process"`
|
||||
New command.New `command:"new"`
|
||||
Build command.Build `command:"build"`
|
||||
Run command.Run `command:"run"`
|
||||
Package command.Package `command:"package"`
|
||||
Clean command.Clean `command:"clean"`
|
||||
Test command.Test `command:"test"`
|
||||
Version command.Version `command:"version"`
|
||||
}
|
||||
)
|
||||
|
||||
// Updates the import path depending on the command
|
||||
// Updates the import path depending on the command.
|
||||
func (c *CommandConfig) UpdateImportPath() error {
|
||||
var importPath string
|
||||
required := true
|
||||
@@ -102,14 +103,14 @@ func (c *CommandConfig) UpdateImportPath() error {
|
||||
if err == nil {
|
||||
for _, path := range strings.Split(build.Default.GOPATH, string(filepath.ListSeparator)) {
|
||||
utils.Logger.Infof("Checking import path %s with %s", currentPath, path)
|
||||
if strings.HasPrefix(currentPath, path) && len(currentPath) > len(path) + 1 {
|
||||
importPath = currentPath[len(path) + 1:]
|
||||
if strings.HasPrefix(currentPath, path) && len(currentPath) > len(path)+1 {
|
||||
importPath = currentPath[len(path)+1:]
|
||||
// Remove the source from the path if it is there
|
||||
if len(importPath) > 4 && (strings.ToLower(importPath[0:4]) == "src/" || strings.ToLower(importPath[0:4]) == "src\\") {
|
||||
importPath = importPath[4:]
|
||||
} else if importPath == "src" {
|
||||
if c.Index != VERSION {
|
||||
return fmt.Errorf("Invlaid import path, working dir is in GOPATH root")
|
||||
return fmt.Errorf("invalid import path, working dir is in GOPATH root")
|
||||
}
|
||||
importPath = ""
|
||||
}
|
||||
@@ -137,7 +138,7 @@ func (c *CommandConfig) UpdateImportPath() error {
|
||||
return nil
|
||||
}
|
||||
if len(importPath) == 0 {
|
||||
return fmt.Errorf("Unable to determine import path from : %s", importPath)
|
||||
return fmt.Errorf("unable to determine import path from : %s", importPath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -153,11 +154,11 @@ func (c *CommandConfig) initAppFolder() (err error) {
|
||||
|
||||
// First try to determine where the application is located - this should be the import value
|
||||
appFolder := c.ImportPath
|
||||
wd, err := os.Getwd()
|
||||
wd, _ := os.Getwd()
|
||||
if len(appFolder) == 0 {
|
||||
// We will assume the working directory is the appFolder
|
||||
appFolder = wd
|
||||
} else if strings.LastIndex(wd, appFolder) == len(wd) - len(appFolder) {
|
||||
} else if strings.LastIndex(wd, appFolder) == len(wd)-len(appFolder) {
|
||||
// Check for existence of an /app folder
|
||||
if utils.Exists(filepath.Join(wd, "app")) {
|
||||
appFolder = wd
|
||||
@@ -174,7 +175,7 @@ func (c *CommandConfig) initAppFolder() (err error) {
|
||||
|
||||
// Use app folder to read the go.mod if it exists and extract the package information
|
||||
goModFile := filepath.Join(appFolder, "go.mod")
|
||||
utils.Logger.Info("Checking gomod, extracting from file", "path", goModFile,"exists", utils.Exists(goModFile))
|
||||
utils.Logger.Info("Checking gomod, extracting from file", "path", goModFile, "exists", utils.Exists(goModFile))
|
||||
if utils.Exists(goModFile) {
|
||||
c.Vendored = true
|
||||
utils.Logger.Info("Found go mod, extracting from file", "path", goModFile)
|
||||
@@ -186,7 +187,7 @@ func (c *CommandConfig) initAppFolder() (err error) {
|
||||
if strings.Index(line, "module ") == 0 {
|
||||
c.ImportPath = strings.TrimSpace(strings.Split(line, "module")[1])
|
||||
c.AppPath = appFolder
|
||||
//c.SrcRoot = appFolder
|
||||
// c.SrcRoot = appFolder
|
||||
utils.Logger.Info("Set application path and package based on go mod", "path", c.AppPath)
|
||||
return nil
|
||||
}
|
||||
@@ -216,17 +217,16 @@ func (c *CommandConfig) initAppFolder() (err error) {
|
||||
c.AppPath = filepath.Join(bestpath, "src", c.ImportPath)
|
||||
}
|
||||
// Recalculate the appFolder because we are using a GOPATH
|
||||
|
||||
} else {
|
||||
// This is new and not vendored, so the app path is the appFolder
|
||||
c.AppPath = appFolder
|
||||
}
|
||||
|
||||
utils.Logger.Info("Set application path", "path", c.AppPath, "vendored",c.Vendored, "importpath",c.ImportPath)
|
||||
utils.Logger.Info("Set application path", "path", c.AppPath, "vendored", c.Vendored, "importpath", c.ImportPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Used to initialize the package resolver
|
||||
// Used to initialize the package resolver.
|
||||
func (c *CommandConfig) InitPackageResolver() {
|
||||
c.initGoPaths()
|
||||
utils.Logger.Info("InitPackageResolver", "useVendor", c.Vendored, "path", c.AppPath)
|
||||
@@ -255,7 +255,7 @@ func (c *CommandConfig) InitPackageResolver() {
|
||||
}
|
||||
}
|
||||
|
||||
// lookup and set Go related variables
|
||||
// lookup and set Go related variables.
|
||||
func (c *CommandConfig) initGoPaths() {
|
||||
utils.Logger.Info("InitGoPaths", "vendored", c.Vendored)
|
||||
// check for go executable
|
||||
@@ -275,10 +275,7 @@ func (c *CommandConfig) initGoPaths() {
|
||||
utils.Logger.Fatal("Abort: GOPATH environment variable is not set. " +
|
||||
"Please refer to http://golang.org/doc/code.html to configure your Go environment.")
|
||||
}
|
||||
return
|
||||
//todo determine if the rest needs to happen
|
||||
|
||||
|
||||
// todo determine if the rest needs to happen
|
||||
// revel/revel#1004 choose go path relative to current working directory
|
||||
|
||||
// What we want to do is to add the import to the end of the
|
||||
@@ -303,11 +300,10 @@ func (c *CommandConfig) initGoPaths() {
|
||||
c.AppPath = filepath.Join(c.SrcRoot, filepath.FromSlash(c.ImportPath))
|
||||
utils.Logger.Info("Set application path", "path", c.AppPath)
|
||||
|
||||
*/
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
// Sets the versions on the command config
|
||||
// Sets the versions on the command config.
|
||||
func (c *CommandConfig) SetVersions() (err error) {
|
||||
c.CommandVersion, _ = ParseVersion(cmd.Version)
|
||||
pathMap, err := utils.FindSrcPaths(c.AppPath, []string{RevelImportPath}, c.PackageResolver)
|
||||
@@ -339,7 +335,7 @@ func (c *CommandConfig) SetVersions() (err error) {
|
||||
spec := a.(*ast.ValueSpec)
|
||||
r := spec.Values[0].(*ast.BasicLit)
|
||||
if spec.Names[0].Name == "Version" {
|
||||
c.FrameworkVersion, err = ParseVersion(strings.Replace(r.Value, `"`, ``, -1))
|
||||
c.FrameworkVersion, err = ParseVersion(strings.ReplaceAll(r.Value, `"`, ``))
|
||||
if err != nil {
|
||||
utils.Logger.Errorf("Failed to parse version")
|
||||
} else {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package model
|
||||
|
||||
// The embedded type name takes the import path and structure name
|
||||
// The embedded type name takes the import path and structure name.
|
||||
type EmbeddedTypeName struct {
|
||||
ImportPath, StructName string
|
||||
}
|
||||
|
||||
// Convert the type to a properly formatted import line
|
||||
// Convert the type to a properly formatted import line.
|
||||
func (s *EmbeddedTypeName) String() string {
|
||||
return s.ImportPath + "." + s.StructName
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package model
|
||||
|
||||
type (
|
||||
// The event type
|
||||
// The event type.
|
||||
Event int
|
||||
// The event response
|
||||
// The event response.
|
||||
EventResponse int
|
||||
// The handler signature
|
||||
// The handler signature.
|
||||
EventHandler func(typeOf Event, value interface{}) (responseOf EventResponse)
|
||||
RevelCallback interface {
|
||||
FireEvent(key Event, value interface{}) (response EventResponse)
|
||||
@@ -14,40 +14,40 @@ type (
|
||||
)
|
||||
|
||||
const (
|
||||
// Event type when templates are going to be refreshed (receivers are registered template engines added to the template.engine conf option)
|
||||
// Event type when templates are going to be refreshed (receivers are registered template engines added to the template.engine conf option).
|
||||
TEMPLATE_REFRESH_REQUESTED Event = iota
|
||||
// Event type when templates are refreshed (receivers are registered template engines added to the template.engine conf option)
|
||||
// Event type when templates are refreshed (receivers are registered template engines added to the template.engine conf option).
|
||||
TEMPLATE_REFRESH_COMPLETED
|
||||
// Event type before all module loads, events thrown to handlers added to AddInitEventHandler
|
||||
// Event type before all module loads, events thrown to handlers added to AddInitEventHandler.
|
||||
|
||||
// Event type before all module loads, events thrown to handlers added to AddInitEventHandler
|
||||
// Event type before all module loads, events thrown to handlers added to AddInitEventHandler.
|
||||
REVEL_BEFORE_MODULES_LOADED
|
||||
// Event type before module loads, events thrown to handlers added to AddInitEventHandler
|
||||
// Event type before module loads, events thrown to handlers added to AddInitEventHandler.
|
||||
REVEL_BEFORE_MODULE_LOADED
|
||||
// Event type after module loads, events thrown to handlers added to AddInitEventHandler
|
||||
// Event type after module loads, events thrown to handlers added to AddInitEventHandler.
|
||||
REVEL_AFTER_MODULE_LOADED
|
||||
// Event type after all module loads, events thrown to handlers added to AddInitEventHandler
|
||||
// Event type after all module loads, events thrown to handlers added to AddInitEventHandler.
|
||||
REVEL_AFTER_MODULES_LOADED
|
||||
|
||||
// Event type before server engine is initialized, receivers are active server engine and handlers added to AddInitEventHandler
|
||||
// Event type before server engine is initialized, receivers are active server engine and handlers added to AddInitEventHandler.
|
||||
ENGINE_BEFORE_INITIALIZED
|
||||
// Event type before server engine is started, receivers are active server engine and handlers added to AddInitEventHandler
|
||||
// Event type before server engine is started, receivers are active server engine and handlers added to AddInitEventHandler.
|
||||
ENGINE_STARTED
|
||||
// Event type after server engine is stopped, receivers are active server engine and handlers added to AddInitEventHandler
|
||||
// Event type after server engine is stopped, receivers are active server engine and handlers added to AddInitEventHandler.
|
||||
ENGINE_SHUTDOWN
|
||||
|
||||
// Called before routes are refreshed
|
||||
// Called before routes are refreshed.
|
||||
ROUTE_REFRESH_REQUESTED
|
||||
// Called after routes have been refreshed
|
||||
// Called after routes have been refreshed.
|
||||
ROUTE_REFRESH_COMPLETED
|
||||
|
||||
// Fired when a panic is caught during the startup process
|
||||
// Fired when a panic is caught during the startup process.
|
||||
REVEL_FAILURE
|
||||
)
|
||||
|
||||
var initEventList = []EventHandler{} // Event handler list for receiving events
|
||||
|
||||
// Fires system events from revel
|
||||
// Fires system events from revel.
|
||||
func RaiseEvent(key Event, value interface{}) (response EventResponse) {
|
||||
for _, handler := range initEventList {
|
||||
response |= handler(key, value)
|
||||
@@ -55,8 +55,7 @@ func RaiseEvent(key Event, value interface{}) (response EventResponse) {
|
||||
return
|
||||
}
|
||||
|
||||
// Add event handler to listen for all system events
|
||||
// Add event handler to listen for all system events.
|
||||
func AddInitEventHandler(handler EventHandler) {
|
||||
initEventList = append(initEventList, handler)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package model_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/revel/revel"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Test that the event handler can be attached and it dispatches the event received
|
||||
// Test that the event handler can be attached and it dispatches the event received.
|
||||
func TestEventHandler(t *testing.T) {
|
||||
counter := 0
|
||||
newListener := func(typeOf revel.Event, value interface{}) (responseOf revel.EventResponse) {
|
||||
@@ -21,4 +22,3 @@ func TestEventHandler(t *testing.T) {
|
||||
revel.StopServer(1)
|
||||
assert.Equal(t, counter, 2, "Expected event handler to have been called")
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@ type MethodCall struct {
|
||||
Names []string
|
||||
}
|
||||
|
||||
// MethodSpec holds the information of one Method
|
||||
// MethodSpec holds the information of one Method.
|
||||
type MethodSpec struct {
|
||||
Name string // Name of the method, e.g. "Index"
|
||||
Args []*MethodArg // Argument descriptors
|
||||
RenderCalls []*MethodCall // Descriptions of Render() invocations from this Method.
|
||||
}
|
||||
|
||||
// MethodArg holds the information of one argument
|
||||
// MethodArg holds the information of one argument.
|
||||
type MethodArg struct {
|
||||
Name string // Name of the argument.
|
||||
TypeExpr TypeExpr // The name of the type, e.g. "int", "*pkg.UserType"
|
||||
|
||||
@@ -2,18 +2,19 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/revel/cmd/utils"
|
||||
"github.com/revel/config"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/revel/cmd/utils"
|
||||
"github.com/revel/config"
|
||||
"golang.org/x/tools/go/packages"
|
||||
)
|
||||
|
||||
type (
|
||||
// The container object for describing all Revels variables
|
||||
// The container object for describing all Revels variables.
|
||||
RevelContainer struct {
|
||||
BuildPaths struct {
|
||||
Revel string
|
||||
@@ -39,36 +40,36 @@ type (
|
||||
Root string
|
||||
}
|
||||
|
||||
ImportPath string // The import path
|
||||
SourcePath string // The full source path
|
||||
RunMode string // The current run mode
|
||||
RevelPath string // The path to the Revel source code
|
||||
BasePath string // The base path to the application
|
||||
AppPath string // The application path (BasePath + "/app")
|
||||
ViewsPath string // The application views path
|
||||
CodePaths []string // All the code paths
|
||||
TemplatePaths []string // All the template paths
|
||||
ConfPaths []string // All the configuration paths
|
||||
Config *config.Context // The global config object
|
||||
Packaged bool // True if packaged
|
||||
DevMode bool // True if running in dev mode
|
||||
HTTPPort int // The http port
|
||||
HTTPAddr string // The http address
|
||||
HTTPSsl bool // True if running https
|
||||
HTTPSslCert string // The SSL certificate
|
||||
HTTPSslKey string // The SSL key
|
||||
AppName string // The application name
|
||||
AppRoot string // The application root from the config `app.root`
|
||||
CookiePrefix string // The cookie prefix
|
||||
CookieDomain string // The cookie domain
|
||||
CookieSecure bool // True if cookie is secure
|
||||
SecretStr string // The secret string
|
||||
MimeConfig *config.Context // The mime configuration
|
||||
ImportPath string // The import path
|
||||
SourcePath string // The full source path
|
||||
RunMode string // The current run mode
|
||||
RevelPath string // The path to the Revel source code
|
||||
BasePath string // The base path to the application
|
||||
AppPath string // The application path (BasePath + "/app")
|
||||
ViewsPath string // The application views path
|
||||
CodePaths []string // All the code paths
|
||||
TemplatePaths []string // All the template paths
|
||||
ConfPaths []string // All the configuration paths
|
||||
Config *config.Context // The global config object
|
||||
Packaged bool // True if packaged
|
||||
DevMode bool // True if running in dev mode
|
||||
HTTPPort int // The http port
|
||||
HTTPAddr string // The http address
|
||||
HTTPSsl bool // True if running https
|
||||
HTTPSslCert string // The SSL certificate
|
||||
HTTPSslKey string // The SSL key
|
||||
AppName string // The application name
|
||||
AppRoot string // The application root from the config `app.root`
|
||||
CookiePrefix string // The cookie prefix
|
||||
CookieDomain string // The cookie domain
|
||||
CookieSecure bool // True if cookie is secure
|
||||
SecretStr string // The secret string
|
||||
MimeConfig *config.Context // The mime configuration
|
||||
ModulePathMap map[string]*ModuleInfo // The module path map
|
||||
}
|
||||
ModuleInfo struct {
|
||||
ImportPath string
|
||||
Path string
|
||||
Path string
|
||||
}
|
||||
|
||||
WrappedRevelCallback struct {
|
||||
@@ -77,25 +78,28 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// Simple Wrapped RevelCallback
|
||||
// Simple Wrapped RevelCallback.
|
||||
func NewWrappedRevelCallback(fe func(key Event, value interface{}) (response EventResponse), ie func(pkgName string) error) RevelCallback {
|
||||
return &WrappedRevelCallback{fe, ie}
|
||||
}
|
||||
|
||||
// Function to implement the FireEvent
|
||||
// Function to implement the FireEvent.
|
||||
func (w *WrappedRevelCallback) FireEvent(key Event, value interface{}) (response EventResponse) {
|
||||
if w.FireEventFunction != nil {
|
||||
response = w.FireEventFunction(key, value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WrappedRevelCallback) PackageResolver(pkgName string) error {
|
||||
return w.ImportFunction(pkgName)
|
||||
}
|
||||
|
||||
// RevelImportPath Revel framework import path
|
||||
var RevelImportPath = "github.com/revel/revel"
|
||||
var RevelModulesImportPath = "github.com/revel/modules"
|
||||
// RevelImportPath Revel framework import path.
|
||||
var (
|
||||
RevelImportPath = "github.com/revel/revel"
|
||||
RevelModulesImportPath = "github.com/revel/modules"
|
||||
)
|
||||
|
||||
// This function returns a container object describing the revel application
|
||||
// eventually this type of function will replace the global variables.
|
||||
@@ -107,7 +111,7 @@ func NewRevelPaths(mode, importPath, appSrcPath string, callback RevelCallback)
|
||||
rp.RunMode = mode
|
||||
|
||||
// We always need to determine the paths for files
|
||||
pathMap, err := utils.FindSrcPaths(appSrcPath, []string{importPath+"/app", RevelImportPath}, callback.PackageResolver)
|
||||
pathMap, err := utils.FindSrcPaths(appSrcPath, []string{importPath + "/app", RevelImportPath}, callback.PackageResolver)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -118,11 +122,11 @@ func NewRevelPaths(mode, importPath, appSrcPath string, callback RevelCallback)
|
||||
rp.AppPath = filepath.Join(rp.BasePath, "app")
|
||||
|
||||
// Sanity check , ensure app and conf paths exist
|
||||
if !utils.DirExists(rp.AppPath) {
|
||||
return rp, fmt.Errorf("No application found at path %s", rp.AppPath)
|
||||
if !utils.DirExists(rp.AppPath) {
|
||||
return rp, fmt.Errorf("no application found at path %s", rp.AppPath)
|
||||
}
|
||||
if !utils.DirExists(filepath.Join(rp.BasePath, "conf")) {
|
||||
return rp, fmt.Errorf("No configuration found at path %s", filepath.Join(rp.BasePath, "conf"))
|
||||
return rp, fmt.Errorf("no configuration found at path %s", filepath.Join(rp.BasePath, "conf"))
|
||||
}
|
||||
|
||||
rp.ViewsPath = filepath.Join(rp.AppPath, "views")
|
||||
@@ -146,7 +150,7 @@ func NewRevelPaths(mode, importPath, appSrcPath string, callback RevelCallback)
|
||||
|
||||
rp.Config, err = config.LoadContext("app.conf", rp.ConfPaths)
|
||||
if err != nil {
|
||||
return rp, fmt.Errorf("Unable to load configuartion file %s", err)
|
||||
return rp, fmt.Errorf("unable to load configuration file %s", err)
|
||||
}
|
||||
|
||||
// Ensure that the selected runmode appears in app.conf.
|
||||
@@ -168,10 +172,10 @@ func NewRevelPaths(mode, importPath, appSrcPath string, callback RevelCallback)
|
||||
rp.HTTPSslKey = rp.Config.StringDefault("http.sslkey", "")
|
||||
if rp.HTTPSsl {
|
||||
if rp.HTTPSslCert == "" {
|
||||
return rp, errors.New("No http.sslcert provided.")
|
||||
return rp, errors.New("no http.sslcert provided")
|
||||
}
|
||||
if rp.HTTPSslKey == "" {
|
||||
return rp, errors.New("No http.sslkey provided.")
|
||||
return rp, errors.New("no http.sslkey provided")
|
||||
}
|
||||
}
|
||||
//
|
||||
@@ -197,7 +201,7 @@ func NewRevelPaths(mode, importPath, appSrcPath string, callback RevelCallback)
|
||||
func (rp *RevelContainer) LoadMimeConfig() (err error) {
|
||||
rp.MimeConfig, err = config.LoadContext("mime-types.conf", rp.ConfPaths)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to load mime type config: %s %s", "error", err)
|
||||
return fmt.Errorf("failed to load mime type config: %s %s", "error", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -206,12 +210,10 @@ func (rp *RevelContainer) LoadMimeConfig() (err error) {
|
||||
// This will fire the REVEL_BEFORE_MODULE_LOADED, REVEL_AFTER_MODULE_LOADED
|
||||
// for each module loaded. The callback will receive the RevelContainer, name, moduleImportPath and modulePath
|
||||
// It will automatically add in the code paths for the module to the
|
||||
// container object
|
||||
// container object.
|
||||
func (rp *RevelContainer) loadModules(callback RevelCallback) (err error) {
|
||||
keys := []string{}
|
||||
for _, key := range rp.Config.Options("module.") {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
keys = append(keys, rp.Config.Options("module.")...)
|
||||
|
||||
// Reorder module order by key name, a poor mans sort but at least it is consistent
|
||||
sort.Strings(keys)
|
||||
@@ -223,11 +225,11 @@ func (rp *RevelContainer) loadModules(callback RevelCallback) (err error) {
|
||||
|
||||
modulePath, err := rp.ResolveImportPath(moduleImportPath)
|
||||
if err != nil {
|
||||
utils.Logger.Info("Missing module ", "module_import_path", moduleImportPath, "error",err)
|
||||
utils.Logger.Info("Missing module ", "module_import_path", moduleImportPath, "error", err)
|
||||
callback.PackageResolver(moduleImportPath)
|
||||
modulePath, err = rp.ResolveImportPath(moduleImportPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to load module. Import of path failed %s:%s %s:%s ", "modulePath", moduleImportPath, "error", err)
|
||||
return fmt.Errorf("failed to load module. Import of path failed %s:%s %s:%s ", "modulePath", moduleImportPath, "error", err)
|
||||
}
|
||||
}
|
||||
// Drop anything between module.???.<name of module>
|
||||
@@ -242,9 +244,9 @@ func (rp *RevelContainer) loadModules(callback RevelCallback) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Adds a module paths to the container object
|
||||
// Adds a module paths to the container object.
|
||||
func (rp *RevelContainer) addModulePaths(name, importPath, modulePath string) {
|
||||
utils.Logger.Info("Adding module path","name", name,"import path", importPath,"system path", modulePath)
|
||||
utils.Logger.Info("Adding module path", "name", name, "import path", importPath, "system path", modulePath)
|
||||
if codePath := filepath.Join(modulePath, "app"); utils.DirExists(codePath) {
|
||||
rp.CodePaths = append(rp.CodePaths, codePath)
|
||||
rp.ModulePathMap[name] = &ModuleInfo{importPath, modulePath}
|
||||
@@ -271,19 +273,21 @@ func (rp *RevelContainer) ResolveImportPath(importPath string) (string, error) {
|
||||
return filepath.Join(rp.SourcePath, importPath), nil
|
||||
}
|
||||
config := &packages.Config{
|
||||
// TODO: packages.LoadSyntax deprecated, Need instead
|
||||
//nolint:staticcheck
|
||||
Mode: packages.LoadSyntax,
|
||||
Dir:rp.AppPath,
|
||||
Dir: rp.AppPath,
|
||||
}
|
||||
|
||||
pkgs, err := packages.Load(config, importPath)
|
||||
if len(pkgs)==0 {
|
||||
return "", errors.New("No packages found for import " + importPath +" using app path "+ rp.AppPath)
|
||||
pkgs, err := packages.Load(config, importPath)
|
||||
if len(pkgs) == 0 {
|
||||
return "", errors.New("No packages found for import " + importPath + " using app path " + rp.AppPath)
|
||||
}
|
||||
// modPkg, err := build.Import(importPath, rp.AppPath, build.FindOnly)
|
||||
// modPkg, err := build.Import(importPath, rp.AppPath, build.FindOnly)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(pkgs[0].GoFiles)>0 {
|
||||
if len(pkgs[0].GoFiles) > 0 {
|
||||
return filepath.Dir(pkgs[0].GoFiles[0]), nil
|
||||
}
|
||||
return pkgs[0].PkgPath, errors.New("No files found in import path " + importPath)
|
||||
|
||||
@@ -3,23 +3,24 @@ package model
|
||||
// SourceInfo is the top-level struct containing all extracted information
|
||||
// about the app source code, used to generate main.go.
|
||||
import (
|
||||
"github.com/revel/cmd/utils"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/revel/cmd/utils"
|
||||
)
|
||||
|
||||
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,14 +29,14 @@ 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
|
||||
// target type, which must be a fully qualified type name,
|
||||
// e.g. "github.com/revel/revel.Controller"
|
||||
// e.g. "github.com/revel/revel.Controller".
|
||||
func (s *SourceInfo) TypesThatEmbed(targetType, packageFilter string) (filtered []*TypeInfo) {
|
||||
// Do a search in the "embedded type graph", starting with the target type.
|
||||
var (
|
||||
@@ -75,7 +76,8 @@ 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:]...)
|
||||
//nolint:ineffassign // huh?
|
||||
exit = false
|
||||
break
|
||||
}
|
||||
@@ -98,8 +100,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)
|
||||
}
|
||||
}
|
||||
@@ -108,20 +110,20 @@ func (s *SourceInfo) TypesThatEmbed(targetType, packageFilter string) (filtered
|
||||
}
|
||||
|
||||
// ControllerSpecs returns the all the controllers that embeds
|
||||
// `revel.Controller`
|
||||
// `revel.Controller`.
|
||||
func (s *SourceInfo) ControllerSpecs() []*TypeInfo {
|
||||
utils.Logger.Info("Scanning controller specifications for types ","typePath",RevelImportPath + ".Controller", "speclen",len(s.controllerSpecs))
|
||||
utils.Logger.Info("Scanning controller specifications for types ", "typePath", RevelImportPath+".Controller", "speclen", len(s.controllerSpecs))
|
||||
if s.controllerSpecs == nil {
|
||||
s.controllerSpecs = s.TypesThatEmbed(RevelImportPath + ".Controller", "controllers")
|
||||
s.controllerSpecs = s.TypesThatEmbed(RevelImportPath+".Controller", "controllers")
|
||||
}
|
||||
return s.controllerSpecs
|
||||
}
|
||||
|
||||
// TestSuites returns the all the Application tests that embeds
|
||||
// `testing.TestSuite`
|
||||
// `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
|
||||
}
|
||||
@@ -136,4 +138,4 @@ func (s *SourceInfo) Merge(srcInfo2 *SourceInfo) {
|
||||
}
|
||||
s.ValidationKeys[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ type TypeExpr struct {
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// Returns a new type from the data
|
||||
// Returns a new type from the data.
|
||||
func NewTypeExprFromData(expr, pkgName string, pkgIndex int, valid bool) TypeExpr {
|
||||
return TypeExpr{expr, pkgName, pkgIndex, valid}
|
||||
}
|
||||
@@ -47,7 +47,6 @@ func NewTypeExprFromAst(pkgName string, expr ast.Expr) TypeExpr {
|
||||
return NewTypeExprFromData("[]"+e.Expr, e.PkgName, e.pkgIndex+2, e.Valid)
|
||||
default:
|
||||
error = fmt.Sprintf("Failed to generate name for field: %v Package: %v. Make sure the field name is valid.", expr, pkgName)
|
||||
|
||||
}
|
||||
return NewTypeExprFromData(error, "", 0, false)
|
||||
}
|
||||
@@ -85,13 +84,13 @@ var builtInTypes = map[string]struct{}{
|
||||
"uintptr": {},
|
||||
}
|
||||
|
||||
// IsBuiltinType checks the given type is built-in types of Go
|
||||
// IsBuiltinType checks the given type is built-in types of Go.
|
||||
func IsBuiltinType(name string) bool {
|
||||
_, ok := builtInTypes[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// Returns the first non empty string from a list of arguements
|
||||
// Returns the first non empty string from a list of arguments.
|
||||
func FirstNonEmpty(strs ...string) string {
|
||||
for _, str := range strs {
|
||||
if len(str) > 0 {
|
||||
|
||||
@@ -9,7 +9,7 @@ type TypeInfo struct {
|
||||
EmbeddedTypes []*EmbeddedTypeName // Used internally to identify controllers that indirectly embed *revel.Controller.
|
||||
}
|
||||
|
||||
// Return the type information as a properly formatted import string
|
||||
// Return the type information as a properly formatted import string.
|
||||
func (s *TypeInfo) String() string {
|
||||
return s.ImportPath + "." + s.StructName
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Version struct {
|
||||
@@ -17,26 +18,24 @@ type Version struct {
|
||||
MinGoVersion string
|
||||
}
|
||||
|
||||
// The compatibility list
|
||||
// The compatibility list.
|
||||
var frameworkCompatibleRangeList = [][]string{
|
||||
{"0.0.0", "0.20.0"}, // minimum Revel version to use with this version of the tool
|
||||
{"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.9.0"}, // Compatible with Framework V 1.0 - 1.9
|
||||
{"1.0.0", "1.9.0"}, // Compatible with Framework V 1.0 - 1.9
|
||||
}
|
||||
|
||||
// Parses a version like v1.2.3a or 1.2
|
||||
// Parses a version like v1.2.3a or 1.2.
|
||||
var versionRegExp = regexp.MustCompile(`([^\d]*)?([0-9]*)\.([0-9]*)(\.([0-9]*))?(.*)`)
|
||||
|
||||
// Parse the version and return it as a Version object
|
||||
// Parse the version and return it as a Version object.
|
||||
func ParseVersion(version string) (v *Version, err error) {
|
||||
|
||||
v = &Version{}
|
||||
return v, v.ParseVersion(version)
|
||||
}
|
||||
|
||||
// Parse the version and return it as a Version object
|
||||
func (v *Version)ParseVersion(version string) (err error) {
|
||||
|
||||
// Parse the version and return it as a Version object.
|
||||
func (v *Version) ParseVersion(version string) (err error) {
|
||||
parsedResult := versionRegExp.FindAllStringSubmatch(version, -1)
|
||||
if len(parsedResult) != 1 {
|
||||
err = errors.Errorf("Invalid version %s", version)
|
||||
@@ -55,7 +54,8 @@ func (v *Version)ParseVersion(version string) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
// Returns 0 or an int value for the string, errors are returned as 0
|
||||
|
||||
// Returns 0 or an int value for the string, errors are returned as 0.
|
||||
func (v *Version) intOrZero(input string) (value int) {
|
||||
if input != "" {
|
||||
value, _ = strconv.Atoi(input)
|
||||
@@ -63,7 +63,7 @@ func (v *Version) intOrZero(input string) (value int) {
|
||||
return value
|
||||
}
|
||||
|
||||
// Returns true if this major revision is compatible
|
||||
// Returns true if this major revision is compatible.
|
||||
func (v *Version) CompatibleFramework(c *CommandConfig) error {
|
||||
for i, rv := range frameworkCompatibleRangeList {
|
||||
start, _ := ParseVersion(rv[0])
|
||||
@@ -81,7 +81,7 @@ func (v *Version) CompatibleFramework(c *CommandConfig) error {
|
||||
return errors.New("Tool out of date - do a 'go get -u github.com/revel/cmd/revel'")
|
||||
}
|
||||
|
||||
// Returns true if this major revision is newer then the passed in
|
||||
// Returns true if this major revision is newer then the passed in.
|
||||
func (v *Version) MajorNewer(o *Version) bool {
|
||||
if v.Major != o.Major {
|
||||
return v.Major > o.Major
|
||||
@@ -89,7 +89,7 @@ func (v *Version) MajorNewer(o *Version) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Returns true if this major or major and minor revision is newer then the value passed in
|
||||
// Returns true if this major or major and minor revision is newer then the value passed in.
|
||||
func (v *Version) MinorNewer(o *Version) bool {
|
||||
if v.Major != o.Major {
|
||||
return v.Major > o.Major
|
||||
@@ -100,7 +100,7 @@ func (v *Version) MinorNewer(o *Version) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Returns true if the version is newer then the current on
|
||||
// Returns true if the version is newer then the current on.
|
||||
func (v *Version) Newer(o *Version) bool {
|
||||
if v.Major != o.Major {
|
||||
return v.Major > o.Major
|
||||
@@ -114,13 +114,13 @@ func (v *Version) Newer(o *Version) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Convert the version to a string
|
||||
// Convert the version to a string.
|
||||
func (v *Version) VersionString() string {
|
||||
return fmt.Sprintf("%s%d.%d.%d%s", v.Prefix, v.Major, v.Minor, v.Maintenance, v.Suffix)
|
||||
}
|
||||
|
||||
// Convert the version build date and go version to a string
|
||||
// Convert the version build date and go version to a string.
|
||||
func (v *Version) String() string {
|
||||
return fmt.Sprintf("Version: %s%d.%d.%d%s\nBuild Date: %s\n Minimium Go Version: %s",
|
||||
return fmt.Sprintf("Version: %s%d.%d.%d%s\nBuild Date: %s\n Minimum Go Version: %s",
|
||||
v.Prefix, v.Major, v.Minor, v.Maintenance, v.Suffix, v.BuildDate, v.MinGoVersion)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package model_test
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/revel/cmd/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var versionTests = [][]string{
|
||||
@@ -12,22 +13,23 @@ var versionTests = [][]string{
|
||||
{"v0.20.", "v0.20.0"},
|
||||
{"2.0", "2.0.0"},
|
||||
}
|
||||
// Test that the event handler can be attached and it dispatches the event received
|
||||
|
||||
// Test that the event handler can be attached and it dispatches the event received.
|
||||
func TestVersion(t *testing.T) {
|
||||
for _, v:= range versionTests {
|
||||
p,e:=model.ParseVersion(v[0])
|
||||
assert.Nil(t,e,"Should have parsed %s",v)
|
||||
assert.Equal(t,p.String(),v[1], "Should be equal %s==%s",p.String(),v)
|
||||
for _, v := range versionTests {
|
||||
p, e := model.ParseVersion(v[0])
|
||||
assert.Nil(t, e, "Should have parsed %s", v)
|
||||
assert.Equal(t, p.String(), v[1], "Should be equal %s==%s", p.String(), v)
|
||||
}
|
||||
}
|
||||
|
||||
// test the ranges
|
||||
// test the ranges.
|
||||
func TestVersionRange(t *testing.T) {
|
||||
a,_ := model.ParseVersion("0.1.2")
|
||||
b,_ := model.ParseVersion("0.2.1")
|
||||
c,_ := model.ParseVersion("1.0.1")
|
||||
a, _ := model.ParseVersion("0.1.2")
|
||||
b, _ := model.ParseVersion("0.2.1")
|
||||
c, _ := model.ParseVersion("1.0.1")
|
||||
assert.True(t, b.MinorNewer(a), "B is newer then A")
|
||||
assert.False(t, b.MajorNewer(a), "B is not major newer then A")
|
||||
assert.False(t, b.MajorNewer(c), "B is not major newer then A")
|
||||
assert.True(t, c.MajorNewer(b), "C is major newer then b")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user