Skip to content

Commit

Permalink
Filter non file urls from classpath response
Browse files Browse the repository at this point in the history
Not all urls on a classpath are necessarily files. Eg. spring boot
adds "jar:file:..." urls
  • Loading branch information
fp7 committed Mar 5, 2020
1 parent 1673e08 commit 499eca1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* [#666](https://github.com/clojure-emacs/cider-nrepl/pull/666): Add a check in apropos var-query-map.
* [#669](https://github.com/clojure-emacs/cider-nrepl/pull/669): Fix NPE and add isDirectory check in slurp
* [#667](https://github.com/clojure-emacs/cider-nrepl/pull/667): Filter non file urls from classpath response.


### New Features

Expand Down
9 changes: 8 additions & 1 deletion src/cider/nrepl/middleware/classpath.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
(:require
[cider.nrepl.middleware.util.error-handling :refer [with-safe-transport]]
[clojure.java.io :as io]
[orchard.java.classpath :as cp]))
[orchard.java.classpath :as cp]
[orchard.misc :as misc]))

(defn file-url?
[u]
(and (misc/url? u)
(= (.getProtocol ^java.net.URL u) "file")))

(defn classpath-reply [msg]
{:classpath (->> (cp/classpath)
(filter file-url?)
(map io/as-file)
(map str))})

Expand Down
4 changes: 4 additions & 0 deletions test/clj/cider/nrepl/middleware/classpath_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
(is (.startsWith (:err response) "java.lang.Exception: cp error"))
(is (= (:ex response) "class java.lang.Exception"))
(is (:pp-stacktrace response)))))

(deftest file-url?-test
(is (file-url? (.toURL (.toURI (java.io.File. "")))))
(is (not (file-url? (java.net.URL. "jar:file:/tmp/test.jar!/BOOT-INF/classes")))))

0 comments on commit 499eca1

Please sign in to comment.