diff --git a/output/build.go b/output/build.go index 368537f..6ad40f4 100644 --- a/output/build.go +++ b/output/build.go @@ -22,6 +22,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" "github.com/b3log/wide/conf" @@ -193,6 +194,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { }() errReader := bufio.NewReader(stderr) + lines := []string{} for { wsChannel := session.OutputWS[sid] if nil == wsChannel { @@ -204,6 +206,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { break } + lines = append(lines, line) + if nil != err { logger.Warn(err) @@ -212,60 +216,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { // path process errOutWithPath := parsePath(curDir, line) - channelRet["output"] = "" + errOutWithPath + "" - // lint process - - // if lines[0][0] == '#' { - // lines = lines[1:] // skip the first line - // } - - // lints := []*Lint{} - - // for _, line := range lines { - // if len(line) < 1 { - // continue - // } - - // if line[0] == '\t' { - // // append to the last lint - // last := len(lints) - // msg := lints[last-1].Msg - // msg += line - - // lints[last-1].Msg = msg - - // continue - // } - - // file := line[:strings.Index(line, ":")] - // left := line[strings.Index(line, ":")+1:] - // index := strings.Index(left, ":") - // lineNo := 0 - // msg := left - // if index >= 0 { - // lineNo, err = strconv.Atoi(left[:index]) - - // if nil != err { - // continue - // } - - // msg = left[index+2:] - // } - - // lint := &Lint{ - // File: filepath.Join(curDir, file), - // LineNo: lineNo - 1, - // Severity: lintSeverityError, - // Msg: msg, - // } - - // lints = append(lints, lint) - // } - - // channelRet["lints"] = lints - err = wsChannel.WriteJSON(&channelRet) if nil != err { logger.Warn(err) @@ -275,17 +227,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { wsChannel.Refresh() } - ///////////// - - // if 0 < len(stderrBuf) { // build error - // // build gutter lint - - // errOut := string(stderrBuf) - // lines := strings.Split(errOut, "\n") - - // - // } - if nil == cmd.Wait() { channelRet["nextCmd"] = args["nextCmd"] channelRet["output"] = "" + i18n.Get(locale, "build-succ").(string) + "\n" @@ -305,6 +246,57 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { }() } else { channelRet["output"] = "" + i18n.Get(locale, "build-error").(string) + "\n" + + logger.Info(lines) + // lint process + if lines[0][0] == '#' { + lines = lines[1:] // skip the first line + } + + lints := []*Lint{} + + for _, line := range lines { + if len(line) < 1 || !strings.Contains(line, ":") { + continue + } + + if line[0] == '\t' { + // append to the last lint + last := len(lints) + msg := lints[last-1].Msg + msg += line + + lints[last-1].Msg = msg + + continue + } + + file := line[:strings.Index(line, ":")] + left := line[strings.Index(line, ":")+1:] + index := strings.Index(left, ":") + lineNo := 0 + msg := left + if index >= 0 { + lineNo, err = strconv.Atoi(left[:index]) + + if nil != err { + continue + } + + msg = left[index+2:] + } + + lint := &Lint{ + File: filepath.ToSlash(filepath.Join(curDir, file)), + LineNo: lineNo - 1, + Severity: lintSeverityError, + Msg: msg, + } + + lints = append(lints, lint) + } + + channelRet["lints"] = lints } wsChannel := session.OutputWS[sid] diff --git a/static/js/bottomGroup.js b/static/js/bottomGroup.js index 996a77a..8c2876f 100644 --- a/static/js/bottomGroup.js +++ b/static/js/bottomGroup.js @@ -19,7 +19,7 @@ * * @author Liyuan Li * @author Liang Ding - * @version 1.1.0.1, Dec 8, 2015 + * @version 1.1.1.1, Mar 15, 2017 */ var bottomGroup = { tabs: undefined, @@ -82,6 +82,7 @@ var bottomGroup = { fillOutput: function (data) { var $output = $('.bottom-window-group .output'); + data = data.replace(/\r/g, ''); data = data.replace(/\n/g, '
'); if (-1 !== data.indexOf("
")) { diff --git a/static/js/menu.js b/static/js/menu.js index 2418b2a..455c841 100644 --- a/static/js/menu.js +++ b/static/js/menu.js @@ -19,7 +19,7 @@ * * @author Liyuan Li * @author Liang Ding - * @version 1.0.0.1, Dec 8, 2015 + * @version 1.0.1.1, Mar 15, 2017 */ var menu = { init: function () { @@ -313,10 +313,11 @@ var menu = { dataType: "json", beforeSend: function () { bottomGroup.resetOutput(); - }, - success: function (result) { + $("#buildRun").addClass("ico-stop") .removeClass("ico-buildrun").attr("title", config.label.stop); + }, + success: function (result) { } }); },