diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-07-01 13:56:35 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-07-09 15:02:42 -0400 |
commit | 0d39db4990e5ca2d3f4450f57ab15941e03b2e3b (patch) | |
tree | b57e7080af0dbe4c29961fe594644fa9763b3c1e | |
parent | 31b6fb557a3c524c447d312f5c51b6262ffb9b0f (diff) |
#392 fix reflection warnings and tests + minor cleanup
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | src/clj/clojure/java/io.clj | 4 | ||||
-rw-r--r-- | src/clj/clojure/java/shell.clj | 21 | ||||
-rw-r--r-- | test/clojure/test_clojure/java/shell.clj | 20 |
3 files changed, 21 insertions, 24 deletions
diff --git a/src/clj/clojure/java/io.clj b/src/clj/clojure/java/io.clj index 4d6c551f..7af37ccd 100644 --- a/src/clj/clojure/java/io.clj +++ b/src/clj/clojure/java/io.clj @@ -33,8 +33,8 @@ (defprotocol ^{:added "1.2"} Coercions "Coerce between various 'resource-namish' things." - (^{:tag File, :added "1.2"} as-file [x] "Coerce argument to a file.") - (^{:tag URL, :added "1.2"} as-url [x] "Coerce argument to a URL.")) + (^{:tag java.io.File, :added "1.2"} as-file [x] "Coerce argument to a file.") + (^{:tag java.net.URL, :added "1.2"} as-url [x] "Coerce argument to a URL.")) (extend-protocol Coercions nil diff --git a/src/clj/clojure/java/shell.clj b/src/clj/clojure/java/shell.clj index f20c72e9..a0f06f33 100644 --- a/src/clj/clojure/java/shell.clj +++ b/src/clj/clojure/java/shell.clj @@ -32,11 +32,6 @@ collecting its stdout"} `(binding [*sh-env* ~env] ~@forms)) -(defn- stream-seq - "Takes an InputStream and returns a lazy seq of integers from the stream." - [stream] - (take-while #(>= % 0) (repeatedly #(.read stream)))) - (defn- aconcat "Concatenates arrays of given type." [type & xs] @@ -54,7 +49,7 @@ collecting its stdout"} [cmd opts] (split-with string? args)] [cmd (merge default-opts (apply hash-map opts))])) -(defn- as-env-string +(defn- ^"[Ljava.lang.String;" as-env-strings "Helper so that callers can pass a Clojure map for the :env to sh." [arg] (cond @@ -116,21 +111,21 @@ collecting its stdout"} [& args] (let [[cmd opts] (parse-args args) proc (.exec (Runtime/getRuntime) - (into-array cmd) - (as-env-string (:env opts)) + ^"[Ljava.lang.String;" (into-array cmd) + (as-env-strings (:env opts)) (as-file (:dir opts))) - in (:in opts)] + {:keys [in inenc outenc]} opts] (if in (future (if (instance? (class (byte-array 0)) in) (with-open [os (.getOutputStream proc)] - (.write os in)) - (with-open [osw (OutputStreamWriter. (.getOutputStream proc) (:inenc opts))] - (.write osw in)))) + (.write os ^"[B" in)) + (with-open [osw (OutputStreamWriter. (.getOutputStream proc) ^String inenc)] + (.write osw ^String in)))) (.close (.getOutputStream proc))) (with-open [stdout (.getInputStream proc) stderr (.getErrorStream proc)] - (let [out (stream-to-enc stdout (:outenc opts)) + (let [out (stream-to-enc stdout outenc) err (stream-to-string stderr) exit-code (.waitFor proc)] {:exit exit-code :out out :err err})))) diff --git a/test/clojure/test_clojure/java/shell.clj b/test/clojure/test_clojure/java/shell.clj index 777698e2..964e68c2 100644 --- a/test/clojure/test_clojure/java/shell.clj +++ b/test/clojure/test_clojure/java/shell.clj @@ -11,12 +11,14 @@ [clojure.java.shell :as sh]) (:import (java.io File))) +(def platform-enc (.name (java.nio.charset.Charset/defaultCharset))) + (deftest test-parse-args (are [x y] (= x y) - [[] {:out "UTF-8" :dir nil :env nil}] (#'sh/parse-args []) - [["ls"] {:out "UTF-8" :dir nil :env nil}] (#'sh/parse-args ["ls"]) - [["ls" "-l"] {:out "UTF-8" :dir nil :env nil}] (#'sh/parse-args ["ls" "-l"]) - [["ls"] {:out "ISO-8859-1" :dir nil :env nil}] (#'sh/parse-args ["ls" :out "ISO-8859-1"]))) + [[] {:inenc platform-enc :outenc platform-enc :dir nil :env nil}] (#'sh/parse-args []) + [["ls"] {:inenc platform-enc :outenc platform-enc :dir nil :env nil}] (#'sh/parse-args ["ls"]) + [["ls" "-l"] {:inenc platform-enc :outenc platform-enc :dir nil :env nil}] (#'sh/parse-args ["ls" "-l"]) + [["ls"] {:inenc platform-enc :outenc "ISO-8859-1" :dir nil :env nil}] (#'sh/parse-args ["ls" :outenc "ISO-8859-1"]))) (deftest test-with-sh-dir (are [x y] (= x y) @@ -28,10 +30,10 @@ nil *sh-env* {:KEY "VAL"} (with-sh-env {:KEY "VAL"} *sh-env*))) -(deftest test-as-env-string +(deftest test-as-env-strings (are [x y] (= x y) - nil (#'sh/as-env-string nil) - ["FOO=BAR"] (seq (#'sh/as-env-string {"FOO" "BAR"})) - ["FOO_SYMBOL=BAR"] (seq (#'sh/as-env-string {'FOO_SYMBOL "BAR"})) - ["FOO_KEYWORD=BAR"] (seq (#'sh/as-env-string {:FOO_KEYWORD "BAR"})))) + nil (#'sh/as-env-strings nil) + ["FOO=BAR"] (seq (#'sh/as-env-strings {"FOO" "BAR"})) + ["FOO_SYMBOL=BAR"] (seq (#'sh/as-env-strings {'FOO_SYMBOL "BAR"})) + ["FOO_KEYWORD=BAR"] (seq (#'sh/as-env-strings {:FOO_KEYWORD "BAR"})))) |