From 25dc05b31eed259b80d275e760765e10c45ef07a Mon Sep 17 00:00:00 2001 From: "notzippy@gmail.com" Date: Mon, 28 Feb 2022 20:01:01 -0800 Subject: [PATCH] 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. --- .gitignore | 2 +- .vscode/launch.json | 21 ++++++++++++++++----- .vscode/tasks.json | 4 ++-- harness/app.go | 5 ++++- harness/harness.go | 5 ++++- model/command_config.go | 2 -- revel/new.go | 2 +- revel/run.go | 4 ++-- revel/test.go | 2 +- utils/command.go | 5 ++++- watcher/watcher.go | 2 +- 11 files changed, 36 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 6ef72f8..ed465df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .idea/ *.iml - +.temp/ diff --git a/.vscode/launch.json b/.vscode/launch.json index 9276550..fdaf289 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,12 +16,12 @@ "name": "Create new", "type": "go", "request": "launch", - "preLaunchTask": "Clean", + "preLaunchTask": "Clean-Test-Project", "mode": "auto", "program": "${workspaceRoot}/revel", - "args": ["new", "-a", "/tmp/revel/aaa"], + "args": ["new", "-v","-a", "${workspaceRoot}/.temp/revel/reveltest", "-p","revel.com/testproject"], "env": { - "GOPATH": "/tmp/revel/GOPATH" + "GOPATH": "${workspaceRoot}/.temp/revel/GOPATH" }, }, { @@ -30,9 +30,20 @@ "request": "launch", "mode": "auto", "program": "${workspaceRoot}/revel", - "args": ["run","-v", "-a", "/tmp/revel/aaa"], + "args": ["run","-v", "-v","-a", "${workspaceRoot}/.temp/revel/reveltest"], "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" }, } ] diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7dd4621..c9112fb 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,9 +4,9 @@ "version": "2.0.0", "tasks": [ { - "label": "Clean", + "label": "Clean-Test-Project", "type": "shell", - "command": "rm -rf /tmp/revel/aaa" + "command": "rm -rf ${workspaceRoot}/.temp/revel/testproject" } ] } \ No newline at end of file diff --git a/harness/app.go b/harness/app.go index 3536dc9..e879ee5 100644 --- a/harness/app.go +++ b/harness/app.go @@ -13,6 +13,7 @@ import ( "os/exec" "runtime" "sync" + "sync/atomic" "time" "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 { listeningWriter := &startupListeningWriter{os.Stdout, make(chan bool), c, &bytes.Buffer{}} cmd.Stdout = listeningWriter + cmd.Stderr = listeningWriter 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) if err := cmd.Cmd.Start(); err != nil { @@ -75,8 +77,9 @@ func (cmd AppCmd) Start(c *model.CommandConfig) error { case exitState := <-cmd.waitChan(): 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, "") + atomic.SwapInt32(&startupError, 1) // TODO pretiffy command line output - // err.MetaError = listeningWriter.getLastOutput() + err.Stack = listeningWriter.buffer.String() return err case <-time.After(60 * time.Second): diff --git a/harness/harness.go b/harness/harness.go index 0bad2b0..10fbd7a 100644 --- a/harness/harness.go +++ b/harness/harness.go @@ -42,6 +42,8 @@ var ( doNotWatch = []string{"tmp", "views", "routes"} lastRequestHadError int32 + startupError int32 + startupErrorText error ) // 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 { 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 { utils.Logger.Error("Could not start application", "error", err2) @@ -297,6 +299,7 @@ func (h *Harness) Run() { paths = append(paths, h.paths.CodePaths...) h.watcher = watcher.NewWatcher(h.paths, false) h.watcher.Listen(h, paths...) + go h.Refresh() // h.watcher.Notify() diff --git a/model/command_config.go b/model/command_config.go index aa0ad8f..744a03e 100644 --- a/model/command_config.go +++ b/model/command_config.go @@ -165,8 +165,6 @@ func (c *CommandConfig) initAppFolder() (err error) { } else { appFolder = filepath.Join(wd, appFolder) } - } else if strings.Contains(appFolder, ".") { - appFolder = filepath.Join(wd, filepath.Base(c.ImportPath)) } else if !filepath.IsAbs(appFolder) { appFolder = filepath.Join(wd, appFolder) } diff --git a/revel/new.go b/revel/new.go index a1461ab..5cc913e 100644 --- a/revel/new.go +++ b/revel/new.go @@ -19,7 +19,7 @@ import ( ) var cmdNew = &Command{ - UsageLine: "new -i [path] -s [skeleton]", + UsageLine: "new -i [path] -s [skeleton] -p [package name]", Short: "create a skeleton Revel application", Long: ` New creates a few files to get a new Revel application running quickly. diff --git a/revel/run.go b/revel/run.go index 1bbb619..7a7b0c1 100644 --- a/revel/run.go +++ b/revel/run.go @@ -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 revelPath.Config.BoolDefault("watch", true) && revelPath.Config.BoolDefault("watch.code", true) { 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 { runMode = revelPath.RunMode } @@ -152,7 +152,7 @@ func runApp(c *model.CommandConfig) (err error) { if len(app.PackagePathMap) > 0 { 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 { runMode = revelPath.RunMode } diff --git a/revel/test.go b/revel/test.go index dcba329..18f6cb2 100644 --- a/revel/test.go +++ b/revel/test.go @@ -112,7 +112,7 @@ func testApp(c *model.CommandConfig) (err error) { if len(app.PackagePathMap) > 0 { 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 { runMode = app.Paths.RunMode } diff --git a/utils/command.go b/utils/command.go index a233659..12d1f38 100644 --- a/utils/command.go +++ b/utils/command.go @@ -17,6 +17,9 @@ func CmdInit(c *exec.Cmd, addGoPath bool, basePath string) { 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 { realPath := &bytes.Buffer{} env := []string{} @@ -38,7 +41,7 @@ func ReducedEnv(addGoPath bool) []string { if pair[0] == "GOMODCACHE" { continue } else if !addGoPath && (pair[0] == "GOPATH" || pair[0] == "GOROOT") { - + continue } env = append(env, e) } diff --git a/watcher/watcher.go b/watcher/watcher.go index 9a7c3f2..b3d7ad8 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -52,7 +52,7 @@ type Watcher struct { // Creates a new watched based on the container. func NewWatcher(paths *model.RevelContainer, eagerRefresh bool) *Watcher { return &Watcher{ - forceRefresh: false, + forceRefresh: true, lastError: -1, paths: paths, refreshTimerMS: time.Duration(paths.Config.IntDefault("watch.rebuild.delay", 1000)),