Updated Launch code

Added output to error stack, so terminal errors are displayed
Ficed c.Verbose, it was changed to an array which causes issues launching
Removed . notation from doing anything special. This was already replaced with the -p CLI option
Added documentaiton on adding the package name
Started watcher with force refresh.
This commit is contained in:
notzippy@gmail.com
2022-02-28 20:01:01 -08:00
parent ea5acb720f
commit 25dc05b31e
11 changed files with 36 additions and 18 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
.idea/ .idea/
*.iml *.iml
.temp/

21
.vscode/launch.json vendored
View File

@@ -16,12 +16,12 @@
"name": "Create new", "name": "Create new",
"type": "go", "type": "go",
"request": "launch", "request": "launch",
"preLaunchTask": "Clean", "preLaunchTask": "Clean-Test-Project",
"mode": "auto", "mode": "auto",
"program": "${workspaceRoot}/revel", "program": "${workspaceRoot}/revel",
"args": ["new", "-a", "/tmp/revel/aaa"], "args": ["new", "-v","-a", "${workspaceRoot}/.temp/revel/reveltest", "-p","revel.com/testproject"],
"env": { "env": {
"GOPATH": "/tmp/revel/GOPATH" "GOPATH": "${workspaceRoot}/.temp/revel/GOPATH"
}, },
}, },
{ {
@@ -30,9 +30,20 @@
"request": "launch", "request": "launch",
"mode": "auto", "mode": "auto",
"program": "${workspaceRoot}/revel", "program": "${workspaceRoot}/revel",
"args": ["run","-v", "-a", "/tmp/revel/aaa"], "args": ["run","-v", "-v","-a", "${workspaceRoot}/.temp/revel/reveltest"],
"env": { "env": {
"GOPATH": "/tmp/revel/GOPATH" "GOPATH": "${workspaceRoot}/.temp/revel/GOPATH"
},
},
{
"name": "Run program Directly",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/.temp/revel/reveltest/app/tmp/main.go",
"args": ["-port=34373","-importPath=revel.com/testproject/reveltest", "-runMode={\"mode\":\"dev\", \"specialUseFlag\":true,\"packagePathMap\":{\"github.com/revel/modules/static\":\"/home/notzippy/go/pkg/mod/github.com/revel/modules@v1.0.0/static\",\"github.com/revel/modules/testrunner\":\"/home/notzippy/go/pkg/mod/github.com/revel/modules@v1.0.0/testrunner\",\"github.com/revel/revel\":\"/home/notzippy/go/pkg/mod/github.com/revel/revel@v1.0.0\",\"revel.com/testproject/reveltest\":\"/mnt/DevSystem/Work/Workareas/revel/revel3/cmd/.temp/revel/reveltest\"}}"],
"env": {
"GOPATH": "${workspaceRoot}/.temp/revel/GOPATH"
}, },
} }
] ]

4
.vscode/tasks.json vendored
View File

@@ -4,9 +4,9 @@
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{ {
"label": "Clean", "label": "Clean-Test-Project",
"type": "shell", "type": "shell",
"command": "rm -rf /tmp/revel/aaa" "command": "rm -rf ${workspaceRoot}/.temp/revel/testproject"
} }
] ]
} }

View File

@@ -13,6 +13,7 @@ import (
"os/exec" "os/exec"
"runtime" "runtime"
"sync" "sync"
"sync/atomic"
"time" "time"
"github.com/revel/cmd/model" "github.com/revel/cmd/model"
@@ -65,6 +66,7 @@ func NewAppCmd(binPath string, port int, runMode string, paths *model.RevelConta
func (cmd AppCmd) Start(c *model.CommandConfig) error { func (cmd AppCmd) Start(c *model.CommandConfig) error {
listeningWriter := &startupListeningWriter{os.Stdout, make(chan bool), c, &bytes.Buffer{}} listeningWriter := &startupListeningWriter{os.Stdout, make(chan bool), c, &bytes.Buffer{}}
cmd.Stdout = listeningWriter cmd.Stdout = listeningWriter
cmd.Stderr = listeningWriter
utils.CmdInit(cmd.Cmd, !c.Vendored, c.AppPath) utils.CmdInit(cmd.Cmd, !c.Vendored, c.AppPath)
utils.Logger.Info("Exec app:", "path", cmd.Path, "args", cmd.Args, "dir", cmd.Dir, "env", cmd.Env) utils.Logger.Info("Exec app:", "path", cmd.Path, "args", cmd.Args, "dir", cmd.Dir, "env", cmd.Env)
if err := cmd.Cmd.Start(); err != nil { if err := cmd.Cmd.Start(); err != nil {
@@ -75,8 +77,9 @@ func (cmd AppCmd) Start(c *model.CommandConfig) error {
case exitState := <-cmd.waitChan(): case exitState := <-cmd.waitChan():
fmt.Println("Startup failure view previous messages, \n Proxy is listening :", c.Run.Port) fmt.Println("Startup failure view previous messages, \n Proxy is listening :", c.Run.Port)
err := utils.NewError("", "Revel Run Error", "starting your application there was an exception. See terminal output, "+exitState, "") err := utils.NewError("", "Revel Run Error", "starting your application there was an exception. See terminal output, "+exitState, "")
atomic.SwapInt32(&startupError, 1)
// TODO pretiffy command line output // TODO pretiffy command line output
// err.MetaError = listeningWriter.getLastOutput() err.Stack = listeningWriter.buffer.String()
return err return err
case <-time.After(60 * time.Second): case <-time.After(60 * time.Second):

View File

@@ -42,6 +42,8 @@ var (
doNotWatch = []string{"tmp", "views", "routes"} doNotWatch = []string{"tmp", "views", "routes"}
lastRequestHadError int32 lastRequestHadError int32
startupError int32
startupErrorText error
) )
// Harness reverse proxies requests to the application server. // Harness reverse proxies requests to the application server.
@@ -255,7 +257,7 @@ func (h *Harness) refresh() (err *utils.SourceError) {
if len(h.app.PackagePathMap) > 0 { if len(h.app.PackagePathMap) > 0 {
paths, _ = json.Marshal(h.app.PackagePathMap) paths, _ = json.Marshal(h.app.PackagePathMap)
} }
runMode = fmt.Sprintf(`{"mode":"%s", "specialUseFlag":%v,"packagePathMap":%s}`, h.app.Paths.RunMode, h.config.Verbose, string(paths)) runMode = fmt.Sprintf(`{"mode":"%s", "specialUseFlag":%v,"packagePathMap":%s}`, h.app.Paths.RunMode, h.config.Verbose[0], string(paths))
} }
if err2 := h.app.Cmd(runMode).Start(h.config); err2 != nil { if err2 := h.app.Cmd(runMode).Start(h.config); err2 != nil {
utils.Logger.Error("Could not start application", "error", err2) utils.Logger.Error("Could not start application", "error", err2)
@@ -297,6 +299,7 @@ func (h *Harness) Run() {
paths = append(paths, h.paths.CodePaths...) paths = append(paths, h.paths.CodePaths...)
h.watcher = watcher.NewWatcher(h.paths, false) h.watcher = watcher.NewWatcher(h.paths, false)
h.watcher.Listen(h, paths...) h.watcher.Listen(h, paths...)
go h.Refresh() go h.Refresh()
// h.watcher.Notify() // h.watcher.Notify()

View File

@@ -165,8 +165,6 @@ func (c *CommandConfig) initAppFolder() (err error) {
} else { } else {
appFolder = filepath.Join(wd, appFolder) appFolder = filepath.Join(wd, appFolder)
} }
} else if strings.Contains(appFolder, ".") {
appFolder = filepath.Join(wd, filepath.Base(c.ImportPath))
} else if !filepath.IsAbs(appFolder) { } else if !filepath.IsAbs(appFolder) {
appFolder = filepath.Join(wd, appFolder) appFolder = filepath.Join(wd, appFolder)
} }

View File

@@ -19,7 +19,7 @@ import (
) )
var cmdNew = &Command{ var cmdNew = &Command{
UsageLine: "new -i [path] -s [skeleton]", UsageLine: "new -i [path] -s [skeleton] -p [package name]",
Short: "create a skeleton Revel application", Short: "create a skeleton Revel application",
Long: ` Long: `
New creates a few files to get a new Revel application running quickly. New creates a few files to get a new Revel application running quickly.

View File

@@ -133,7 +133,7 @@ func runApp(c *model.CommandConfig) (err error) {
// If the app is run in "watched" mode, use the harness to run it. // If the app is run in "watched" mode, use the harness to run it.
if revelPath.Config.BoolDefault("watch", true) && revelPath.Config.BoolDefault("watch.code", true) { if revelPath.Config.BoolDefault("watch", true) && revelPath.Config.BoolDefault("watch.code", true) {
utils.Logger.Info("Running in watched mode.") utils.Logger.Info("Running in watched mode.")
runMode := fmt.Sprintf(`{"mode":"%s", "specialUseFlag":%v}`, revelPath.RunMode, c.Verbose) runMode := fmt.Sprintf(`{"mode":"%s", "specialUseFlag":%v}`, revelPath.RunMode, c.Verbose[0])
if c.HistoricMode { if c.HistoricMode {
runMode = revelPath.RunMode runMode = revelPath.RunMode
} }
@@ -152,7 +152,7 @@ func runApp(c *model.CommandConfig) (err error) {
if len(app.PackagePathMap) > 0 { if len(app.PackagePathMap) > 0 {
paths, _ = json.Marshal(app.PackagePathMap) paths, _ = json.Marshal(app.PackagePathMap)
} }
runMode := fmt.Sprintf(`{"mode":"%s", "specialUseFlag":%v,"packagePathMap":%s}`, app.Paths.RunMode, c.Verbose, string(paths)) runMode := fmt.Sprintf(`{"mode":"%s", "specialUseFlag":%v,"packagePathMap":%s}`, app.Paths.RunMode, c.Verbose[0], string(paths))
if c.HistoricMode { if c.HistoricMode {
runMode = revelPath.RunMode runMode = revelPath.RunMode
} }

View File

@@ -112,7 +112,7 @@ func testApp(c *model.CommandConfig) (err error) {
if len(app.PackagePathMap) > 0 { if len(app.PackagePathMap) > 0 {
paths, _ = json.Marshal(app.PackagePathMap) paths, _ = json.Marshal(app.PackagePathMap)
} }
runMode := fmt.Sprintf(`{"mode":"%s", "specialUseFlag":%v,"packagePathMap":%s}`, app.Paths.RunMode, c.Verbose, string(paths)) runMode := fmt.Sprintf(`{"mode":"%s", "specialUseFlag":%v,"packagePathMap":%s}`, app.Paths.RunMode, c.Verbose[0], string(paths))
if c.HistoricMode { if c.HistoricMode {
runMode = app.Paths.RunMode runMode = app.Paths.RunMode
} }

View File

@@ -17,6 +17,9 @@ func CmdInit(c *exec.Cmd, addGoPath bool, basePath string) {
c.Env = ReducedEnv(addGoPath) c.Env = ReducedEnv(addGoPath)
} }
// ReducedEnv returns a list of environment vairables by using os.Env
// it will remove the GOPATH, GOROOT if addGoPath is true
func ReducedEnv(addGoPath bool) []string { func ReducedEnv(addGoPath bool) []string {
realPath := &bytes.Buffer{} realPath := &bytes.Buffer{}
env := []string{} env := []string{}
@@ -38,7 +41,7 @@ func ReducedEnv(addGoPath bool) []string {
if pair[0] == "GOMODCACHE" { if pair[0] == "GOMODCACHE" {
continue continue
} else if !addGoPath && (pair[0] == "GOPATH" || pair[0] == "GOROOT") { } else if !addGoPath && (pair[0] == "GOPATH" || pair[0] == "GOROOT") {
continue
} }
env = append(env, e) env = append(env, e)
} }

View File

@@ -52,7 +52,7 @@ type Watcher struct {
// Creates a new watched based on the container. // Creates a new watched based on the container.
func NewWatcher(paths *model.RevelContainer, eagerRefresh bool) *Watcher { func NewWatcher(paths *model.RevelContainer, eagerRefresh bool) *Watcher {
return &Watcher{ return &Watcher{
forceRefresh: false, forceRefresh: true,
lastError: -1, lastError: -1,
paths: paths, paths: paths,
refreshTimerMS: time.Duration(paths.Config.IntDefault("watch.rebuild.delay", 1000)), refreshTimerMS: time.Duration(paths.Config.IntDefault("watch.rebuild.delay", 1000)),