Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fake.class.path as classpath in Boot projects #455

Merged
merged 1 commit into from
Dec 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cider/nrepl/middleware/classpath.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
(ns cider.nrepl.middleware.classpath
(:require [cider.nrepl.middleware.util.error-handling :refer [with-safe-transport]]
[cider.nrepl.middleware.util.misc :as u]
[clojure.java.classpath :as cp]
[clojure.string :as str]
[clojure.tools.nrepl.middleware :refer [set-descriptor!]]))

(defn classpath []
(map str (cp/classpath)))
(if-let [classpath (u/boot-fake-classpath)]
(str/split classpath #":")
(map str (cp/classpath))))

(defn classpath-reply [msg]
{:classpath (classpath)})
Expand Down
8 changes: 6 additions & 2 deletions src/cider/nrepl/middleware/util/misc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
(:require [clojure.string :as str]
[clojure.stacktrace :as stacktrace]))

(defn boot-project? []
(defn boot-fake-classpath
;; fake.class.path under boot contains the original directories with source
;; files, see https://github.com/boot-clj/boot/issues/249
(not (nil? (System/getProperty "fake.class.path"))))
[]
(System/getProperty "fake.class.path"))

(defn boot-project? []
(not (nil? (boot-fake-classpath))))

(def java-api-version
(try (-> (System/getProperty "java.version") (str/split #"\.") second)
Expand Down
14 changes: 14 additions & 0 deletions test/clj/cider/nrepl/middleware/classpath_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns cider.nrepl.middleware.classpath-test
(:require [cider.nrepl.test-session :as session]
[cider.nrepl.middleware.classpath :as cp]
[clojure.string :as str]
[clojure.test :refer :all]))

(use-fixtures :each session/session-fixture)
Expand All @@ -19,3 +20,16 @@
(is (.startsWith (:err response) "java.lang.Exception: cp error"))
(is (= (:ex response) "class java.lang.Exception"))
(is (:pp-stacktrace response)))))

(deftest boot-fake-classpath-test
(let [fake-paths [(System/getProperty "java.io.tmpdir")]
fake-classpath (str/join ":" fake-paths)]
(testing "when fake.class.path is not set"
(is (not= fake-classpath (cp/classpath))))
(testing "when fake.class.path is set"
(try
(System/setProperty "fake.class.path" fake-classpath)
(is (= ["/some/file/path/src" "/some/file/path/test"]
(cp/classpath)))
(finally
(System/clearProperty "fake.class.path"))))))
17 changes: 16 additions & 1 deletion test/clj/cider/nrepl/middleware/util/misc_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
(ns cider.nrepl.middleware.util.misc-test
(:require [clojure.test :refer :all]
(:require [clojure.string :as str]
[clojure.test :refer :all]
[cider.nrepl.middleware.util.misc :as misc]))

(deftest boot-fake-classpath-test
(let [fake-paths [(System/getProperty "java.io.tmpdir")]
fake-classpath (str/join ":" fake-paths)]
(testing "when fake.class.path is not set"
(is (nil? (misc/boot-fake-classpath)))
(is (not (misc/boot-project?))))
(testing "when fake.class.path is set"
(try
(System/setProperty "fake.class.path" fake-classpath)
(is (= fake-classpath (misc/boot-fake-classpath)))
(is (misc/boot-project?))
(finally
(System/clearProperty "fake.class.path"))))))

(deftest transform-value-test
(is (= (misc/transform-value (array-map
:a "b"
Expand Down