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/
*.iml
.temp/

21
.vscode/launch.json vendored
View File

@@ -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"
},
}
]

4
.vscode/tasks.json vendored
View File

@@ -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"
}
]
}

View File

@@ -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):

View File

@@ -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()

View File

@@ -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)
}

View File

@@ -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.

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 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
}

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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)),