mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-11 18:54:31 +00:00
Merge pull request #210 from revel/build_process_update
Updated Launch code
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,3 @@
|
|||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
|
.temp/
|
||||||
|
|||||||
21
.vscode/launch.json
vendored
21
.vscode/launch.json
vendored
@@ -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=9000","-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"
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
1
.vscode/load.sh
vendored
Executable file
1
.vscode/load.sh
vendored
Executable file
@@ -0,0 +1 @@
|
|||||||
|
http_load -rate 5 -seconds 10 load.web
|
||||||
2
.vscode/load.web
vendored
Normal file
2
.vscode/load.web
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
http://localhost:9000/
|
||||||
|
http://localhost:9000/miss
|
||||||
14
.vscode/tasks.json
vendored
14
.vscode/tasks.json
vendored
@@ -4,9 +4,17 @@
|
|||||||
"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"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"label": "Update Go Mod",
|
||||||
|
"type": "shell",
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}/.temp/revel/testproject"
|
||||||
|
},
|
||||||
|
"command": "go mod tidy && go mod edit -replace github.com/revel/revel => ../../../revel"
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/revel/cmd/model"
|
"github.com/revel/cmd/model"
|
||||||
@@ -64,6 +65,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 {
|
||||||
@@ -74,8 +76,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):
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
var importErrorPattern = regexp.MustCompile("cannot find package \"([^\"]+)\"")
|
var importErrorPattern = regexp.MustCompile("cannot find package \"([^\"]+)\"")
|
||||||
var importErrorPattern2 = regexp.MustCompile("no required module provides package ([^;]+)+")
|
var importErrorPattern2 = regexp.MustCompile("no required module provides package ([^;]+)+")
|
||||||
|
var addPackagePattern = regexp.MustCompile(`to add:\n\tgo get (.*)\n`)
|
||||||
|
|
||||||
type ByString []*model.TypeInfo
|
type ByString []*model.TypeInfo
|
||||||
|
|
||||||
@@ -214,6 +215,10 @@ func Build(c *model.CommandConfig, paths *model.RevelContainer) (_ *App, err err
|
|||||||
if matches == nil {
|
if matches == nil {
|
||||||
matches = importErrorPattern2.FindAllStringSubmatch(stOutput, -1)
|
matches = importErrorPattern2.FindAllStringSubmatch(stOutput, -1)
|
||||||
}
|
}
|
||||||
|
if matches == nil {
|
||||||
|
matches = addPackagePattern.FindAllStringSubmatch(stOutput, -1)
|
||||||
|
|
||||||
|
}
|
||||||
utils.Logger.Info("Build failed checking for missing imports", "message", stOutput, "missing_imports", len(matches))
|
utils.Logger.Info("Build failed checking for missing imports", "message", stOutput, "missing_imports", len(matches))
|
||||||
if matches == nil {
|
if matches == nil {
|
||||||
utils.Logger.Info("Build failed no missing imports", "message", stOutput)
|
utils.Logger.Info("Build failed no missing imports", "message", stOutput)
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -241,7 +243,7 @@ func (h *Harness) refresh() (err *utils.SourceError) {
|
|||||||
}
|
}
|
||||||
err = &utils.SourceError{
|
err = &utils.SourceError{
|
||||||
Title: "App failed to start up",
|
Title: "App failed to start up",
|
||||||
Description: err.Error(),
|
Description: newErr.Error(),
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -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()
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)),
|
||||||
|
|||||||
Reference in New Issue
Block a user