Fix for issue #2156
Usage of with-out-str with eval/sh should be replaced by utils/with-system-out-str as eval/sh is writing output to System/out.
This commit is contained in:
parent
66c7f9a8ea
commit
674eb86498
3 changed files with 31 additions and 28 deletions
|
@ -3,7 +3,8 @@
|
|||
[clojure.java.shell :as sh])
|
||||
(:import (com.hypirion.io RevivableInputStream)
|
||||
(clojure.lang LineNumberingPushbackReader)
|
||||
(java.io File FileDescriptor FileInputStream InputStreamReader)
|
||||
(java.io ByteArrayOutputStream PrintStream File FileDescriptor
|
||||
FileOutputStream FileInputStream InputStreamReader)
|
||||
(java.net URL)))
|
||||
|
||||
(def rebound-io? (atom false))
|
||||
|
@ -234,3 +235,25 @@
|
|||
hypothetical-descendant (.getCanonicalPath (io/file b))]
|
||||
(and (.startsWith hypothetical-descendant hypothetical-ancestor)
|
||||
(not (= hypothetical-descendant hypothetical-ancestor)))))
|
||||
|
||||
(defmacro with-system-out-str
|
||||
"Like with-out-str, but for System/out."
|
||||
[& body]
|
||||
`(try (let [o# (ByteArrayOutputStream.)]
|
||||
(System/setOut (PrintStream. o#))
|
||||
~@body
|
||||
(.toString o#))
|
||||
(finally
|
||||
(System/setOut
|
||||
(-> FileDescriptor/out FileOutputStream. PrintStream.)))))
|
||||
|
||||
(defmacro with-system-err-str
|
||||
"Like with-out-str, but for System/err."
|
||||
[& body]
|
||||
`(try (let [o# (ByteArrayOutputStream.)]
|
||||
(System/setErr (PrintStream. o#))
|
||||
~@body
|
||||
(.toString o#))
|
||||
(finally
|
||||
(System/setErr
|
||||
(-> FileDescriptor/err FileOutputStream. PrintStream.)))))
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
(:require [clojure.java.io :as io]
|
||||
[bultitude.core :as b]
|
||||
[leiningen.core.eval :as eval]
|
||||
[leiningen.core.main :as main]))
|
||||
[leiningen.core.main :as main]
|
||||
[leiningen.core.utils :as utils]))
|
||||
|
||||
;; TODO: make pom task use this ns by adding a few more methods
|
||||
|
||||
|
@ -79,11 +80,9 @@
|
|||
(defmethod assert-committed :git [project]
|
||||
(binding [eval/*dir* (:root project)]
|
||||
(when (re-find #"Changes (not staged for commit|to be committed)"
|
||||
(with-out-str (eval/sh-with-exit-code "Couldn't get status" "git" "status")))
|
||||
(utils/with-system-out-str (eval/sh-with-exit-code "Couldn't get status" "git" "status")))
|
||||
(main/abort "Uncommitted changes in" (:root project) "directory."))))
|
||||
|
||||
|
||||
|
||||
(defn- not-found [subtask]
|
||||
(partial #'main/task-not-found (str "vcs " subtask)))
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
(ns leiningen.test.helper
|
||||
(:require [leiningen.core.project :as project]
|
||||
[leiningen.core.user :as user]
|
||||
[leiningen.core.utils :as utils]
|
||||
[leiningen.core.test.helper :as helper]
|
||||
[clojure.java.io :as io])
|
||||
(:import (java.io ByteArrayOutputStream PrintStream FileDescriptor
|
||||
FileOutputStream)))
|
||||
[clojure.java.io :as io]))
|
||||
|
||||
;; TODO: fix
|
||||
(def local-repo (io/file (System/getProperty "user.home") ".m2" "repository"))
|
||||
|
@ -118,24 +117,6 @@
|
|||
(binding [*err* (java.io.StringWriter.)]
|
||||
(f)))
|
||||
|
||||
(defmacro with-system-out-str
|
||||
"Like with-out-str, but for System/out."
|
||||
[& body]
|
||||
`(try (let [o# (ByteArrayOutputStream.)]
|
||||
(System/setOut (PrintStream. o#))
|
||||
~@body
|
||||
(.toString o#))
|
||||
(finally
|
||||
(System/setOut
|
||||
(-> FileDescriptor/out FileOutputStream. PrintStream.)))))
|
||||
(def #^{:macro true} with-system-out-str #'utils/with-system-out-str)
|
||||
|
||||
(defmacro with-system-err-str
|
||||
"Like with-out-str, but for System/err."
|
||||
[& body]
|
||||
`(try (let [o# (ByteArrayOutputStream.)]
|
||||
(System/setErr (PrintStream. o#))
|
||||
~@body
|
||||
(.toString o#))
|
||||
(finally
|
||||
(System/setErr
|
||||
(-> FileDescriptor/err FileOutputStream. PrintStream.)))))
|
||||
(def #^{:macro true} with-system-err-str #'utils/with-system-err-str)
|
||||
|
|
Loading…
Reference in a new issue