Skip to content

Commit 2efc723

Browse files
committed
Remove JDK7 compatibility code
1 parent 48d28f4 commit 2efc723

File tree

3 files changed

+27
-52
lines changed

3 files changed

+27
-52
lines changed

project.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@
127127
:cljfmt {:indents {as-> [[:inner 0]]
128128
with-debug-bindings [[:inner 0]]
129129
merge-meta [[:inner 0]]
130-
try-if-let [[:block 1]]
131-
if-class [[:block 1]]}}}]
130+
try-if-let [[:block 1]]}}}]
132131

133132
:eastwood [:test
134133
{:plugins [[jonase/eastwood "0.3.4"]]

src/cider/nrepl/middleware/slurp.clj

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,13 @@
1111
[nrepl.misc :refer [response-for]]
1212
[nrepl.transport :as transport])
1313
(:import
14-
[java.net MalformedURLException URL]
15-
java.io.ByteArrayOutputStream
16-
[java.nio.file Files Path Paths]))
14+
(java.io ByteArrayOutputStream)
15+
(java.net MalformedURLException URL)
16+
(java.nio.file Files Path Paths)
17+
(java.util Base64)))
1718

1819
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1920

20-
(defmacro if-class
21-
"Conditional compilation macro for when a given class is available.
22-
23-
If the given class can be resolved, expands to `then-expr`,
24-
otherwise expands to `else-expr`. `else-expr` defaults to `nil`."
25-
([classname then-expr]
26-
`(if-class ~classname ~then-expr nil))
27-
([classname then-expr else-expr]
28-
(if (try (eval `(import ~classname)) true
29-
(catch ClassNotFoundException e false))
30-
then-expr else-expr)))
31-
3221
(def known-content-types
3322
(->> (io/resource "content-types.edn")
3423
(io/reader)
@@ -68,12 +57,9 @@
6857
(Files/probeContentType p)
6958
"application/octet-stream"))
7059

71-
;; FIXME (arrdem 2018-04-11):
72-
;; Remove this if-class when we have jdk1.8 min
7360
(defn base64-bytes
7461
[^bytes buff]
75-
(if-class java.util.Base64
76-
(.encodeToString (Base64/getEncoder) buff)))
62+
(.encodeToString (Base64/getEncoder) buff))
7763

7864
(defn slurp-reply [location content-type buff]
7965
(let [^String real-type (first content-type)
@@ -119,8 +105,6 @@
119105
(recur))))
120106
(slurp-reply url content-type (.toByteArray os))))))
121107

122-
;; FIXME (arrdem 2018-04-11):
123-
;; Remove this if-class when we have jdk1.8 min
124108
(defn handle-slurp
125109
"Message handler which just responds to slurp ops.
126110
@@ -129,10 +113,7 @@
129113
(let [{:keys [op url transport]} msg]
130114
(if (and (= "slurp" op) url)
131115
(do (transport/send transport
132-
(response-for msg
133-
(if-class java.util.Base64
134-
(slurp-url-to-content+body url)
135-
{:error "`java.util.Base64` cannot be found, `slurp` op is disabled."})))
116+
(response-for msg (slurp-url-to-content+body url)))
136117
(transport/send transport
137118
(response-for msg {:status ["done"]})))
138119
(handler msg))))
Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
(ns cider.nrepl.middleware.slurp-test
22
(:require
3-
[cider.nrepl.middleware.slurp :refer [if-class slurp-url-to-content+body]]
3+
[cider.nrepl.middleware.slurp :refer [slurp-url-to-content+body]]
44
[clojure.java.io :as io]
55
[clojure.test :as t]
66
[clojure.string :as str]))
77

8-
;; FIXME (arrdem 2018-04-11):
9-
;; Remove these if-classes when we have jdk1.8 min
10-
(if-class java.util.Base64
11-
(t/deftest test-project-clj-is-clj
12-
(let [resp (slurp-url-to-content+body
13-
(.toString
14-
(.toURL
15-
(io/file "project.clj"))))]
16-
(t/is (= ["text/clojure" {}] (:content-type resp)))
17-
(t/is (not= "base64" (:content-transfer-encoding resp))))))
8+
(t/deftest test-project-clj-is-clj
9+
(let [resp (slurp-url-to-content+body
10+
(.toString
11+
(.toURL
12+
(io/file "project.clj"))))]
13+
(t/is (= ["text/clojure" {}] (:content-type resp)))
14+
(t/is (not= "base64" (:content-transfer-encoding resp)))))
1815

19-
(if-class java.util.Base64
20-
(t/deftest test-sum-types-is-base64
21-
(let [resp (slurp-url-to-content+body
22-
(.toString
23-
(io/resource "sum-types-are-cool.jpg")))]
24-
(t/is (= ["image/jpeg" {}] (:content-type resp)))
25-
(t/is (= "base64" (:content-transfer-encoding resp))))))
16+
(t/deftest test-sum-types-is-base64
17+
(let [resp (slurp-url-to-content+body
18+
(.toString
19+
(io/resource "sum-types-are-cool.jpg")))]
20+
(t/is (= ["image/jpeg" {}] (:content-type resp)))
21+
(t/is (= "base64" (:content-transfer-encoding resp)))))
2622

27-
(if-class java.util.Base64
28-
(t/deftest test-unrecognized-file
29-
(let [resp (slurp-url-to-content+body
30-
(.toString (io/resource "unknown.bin")))]
31-
(t/is (= ["application/octet-stream" {}] (:content-type resp)))
32-
(t/is (str/starts-with? (:body resp) "#binary[location="))
33-
(t/is (str/ends-with? (:body resp) ",size=3]")))))
23+
(t/deftest test-unrecognized-file
24+
(let [resp (slurp-url-to-content+body
25+
(.toString (io/resource "unknown.bin")))]
26+
(t/is (= ["application/octet-stream" {}] (:content-type resp)))
27+
(t/is (str/starts-with? (:body resp) "#binary[location="))
28+
(t/is (str/ends-with? (:body resp) ",size=3]"))))

0 commit comments

Comments
 (0)