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

Filter non file urls from classpath response #667

Merged
merged 2 commits into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, doesn't it make more sense for this to be in orchard as well? Or at least a private function here?

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

(defn classpath-reply [msg]
{:classpath (->> (cp/classpath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also been thinking we can just add a classpath-files function to orchard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if that would filter out too much for other clients of orchard. Maybe some clients want to fix this problem instead of just removing the classpath entries which causes this function to fail. Would it not take that possibility from them if we filter on the orchard side?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, adding the function there wouldn't mean that people are forced to use it. It simply seems to me like something that's generally useful outside cider-nrepl.

(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")))))