Skip to content

Commit

Permalink
[Fix #1824] Cider-jack-in dependency exclusions
Browse files Browse the repository at this point in the history
Add option to define exclusions for injected dependecies. Add
`org.cloure/clojure` exclusion to `org.clojure/tools.nrepl` to mitigate
problem with tools.nrepl clojure dependency.

Note about boot: the latest stable release does not support defining
depedency exclusions on the command line. However, this feature is
available in the upcoming 2.7.x release. This feature will be added
for boot when 2.7.x is released.
  • Loading branch information
benedekfazekas committed Sep 5, 2016
1 parent bdbb2d2 commit 7b5a2ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* [#1677](https://github.com/clojure-emacs/cider/issues/1677): Interpret `\r` as a newline.
* [#1819](https://github.com/clojure-emacs/cider/issues/1819): Handle properly missing commands on `cider-jack-in`.
* [#1824](https://github.com/clojure-emacs/cider/issues/1824): Can no longer jack-in to an inherited clojure version

## 0.13.0 (2016-07-25)

Expand Down
27 changes: 21 additions & 6 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ found for the PROJECT-TYPE"
(cider-add-to-alist 'cider-jack-in-dependencies
"org.clojure/tools.nrepl" "0.2.12")

(defvar cider-jack-in-dependencies-exclusions nil
"List of exclusions for jack in dependencies where elements are lists of artifact name and list of exclusions to apply for the artifact.")
(put 'cider-jack-in-dependencies-exclusions 'risky-local-variable t)
(cider-add-to-alist 'cider-jack-in-dependencies-exclusions
"org.clojure/tools.nrepl" '("org.clojure/clojure"))

(defcustom cider-jack-in-auto-inject-clojure nil
"Version of clojure to auto-inject into REPL.
Expand Down Expand Up @@ -300,18 +306,26 @@ string is quoted for passing as argument to an inferior shell."
(concat (cider-boot-command-prefix (append dependencies plugins))
(cider-boot-repl-task-params params middlewares)))

(defun cider--list-as-lein-artifact (list)
(defun cider--lein-artifact-exclusions (exclusions)
"Return an exclusions vector described by the elements of EXCLUSIONS."
(if exclusions
(format " :exclusions [%s]" (mapconcat #'identity exclusions " "))
""))

(defun cider--list-as-lein-artifact (list &optional exclusions)
"Return an artifact string described by the elements of LIST.
LIST should have the form (ARTIFACT-NAME ARTIFACT-VERSION). The returned
LIST should have the form (ARTIFACT-NAME ARTIFACT-VERSION). Optionally a list
of EXCLUSIONS can be provided as well. The returned
string is quoted for passing as argument to an inferior shell."
(shell-quote-argument (format "[%s %S]" (car list) (cadr list))))
(shell-quote-argument (format "[%s %S%s]" (car list) (cadr list) (cider--lein-artifact-exclusions exclusions))))

(defun cider-lein-jack-in-dependencies (params dependencies lein-plugins)
(defun cider-lein-jack-in-dependencies (params dependencies dependencies-exclusions lein-plugins)
(concat
(mapconcat #'identity
(append (seq-map (lambda (dep)
(concat "update-in :dependencies conj "
(cider--list-as-lein-artifact dep)))
(let ((exclusions (cadr (assoc (car dep) dependencies-exclusions))))
(concat "update-in :dependencies conj "
(cider--list-as-lein-artifact dep exclusions))))
dependencies)
(seq-map (lambda (plugin)
(concat "update-in :plugins conj "
Expand Down Expand Up @@ -351,6 +365,7 @@ dependencies."
params
(cider-add-clojure-dependencies-maybe
cider-jack-in-dependencies)
cider-jack-in-dependencies-exclusions
cider-jack-in-lein-plugins))
("boot" (cider-boot-jack-in-dependencies
params
Expand Down
18 changes: 15 additions & 3 deletions test/cider-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,29 @@
(kill-buffer "*cider-connections*")))))))))

(describe "cider-inject-jack-in-dependencies"
:var (cider-jack-in-dependencies cider-jack-in-nrepl-middlewares cider-jack-in-lein-plugins)
:var (cider-jack-in-dependencies cider-jack-in-nrepl-middlewares cider-jack-in-lein-plugins cider-jack-in-dependencies-exclusions)

(describe "when there is a single dependency"
(before-each
(setq-local cider-jack-in-dependencies '(("org.clojure/tools.nrepl" "0.2.12")))
(setq-local cider-jack-in-nrepl-middlewares '("cider.nrepl/cider-middleware"))
(setq-local cider-jack-in-lein-plugins '(("cider/cider-nrepl" "0.10.0-SNAPSHOT"))))
(setq-local cider-jack-in-lein-plugins '(("cider/cider-nrepl" "0.10.0-SNAPSHOT")))
(setq-local cider-jack-in-dependencies-exclusions '()))

(it "can inject dependencies in a lein project"
(expect (cider-inject-jack-in-dependencies "repl :headless" "lein")
:to-equal"update-in :dependencies conj \\[org.clojure/tools.nrepl\\ \\\"0.2.12\\\"\\] -- update-in :plugins conj \\[cider/cider-nrepl\\ \\\"0.10.0-SNAPSHOT\\\"\\] -- repl :headless"))

(it "can inject dependencies in a lein project with an exclusion"
(setq-local cider-jack-in-dependencies-exclusions '(("org.clojure/tools.nrepl" ("org.clojure/clojure"))))
(expect (cider-inject-jack-in-dependencies "repl :headless" "lein")
:to-equal"update-in :dependencies conj \\[org.clojure/tools.nrepl\\ \\\"0.2.12\\\"\\ \\:exclusions\\ \\[org.clojure/clojure\\]\\] -- update-in :plugins conj \\[cider/cider-nrepl\\ \\\"0.10.0-SNAPSHOT\\\"\\] -- repl :headless"))

(it "can inject dependencies in a lein project with multiple exclusions"
(setq-local cider-jack-in-dependencies-exclusions '(("org.clojure/tools.nrepl" ("org.clojure/clojure" "foo.bar/baz"))))
(expect (cider-inject-jack-in-dependencies "repl :headless" "lein")
:to-equal"update-in :dependencies conj \\[org.clojure/tools.nrepl\\ \\\"0.2.12\\\"\\ \\:exclusions\\ \\[org.clojure/clojure\\ foo.bar/baz\\]\\] -- update-in :plugins conj \\[cider/cider-nrepl\\ \\\"0.10.0-SNAPSHOT\\\"\\] -- repl :headless"))

(it "can inject dependencies in a boot project"
(expect (cider-inject-jack-in-dependencies "repl -s wait" "boot")
:to-equal "-d org.clojure/tools.nrepl\\:0.2.12 -d cider/cider-nrepl\\:0.10.0-SNAPSHOT repl -m cider.nrepl/cider-middleware -s wait"))
Expand All @@ -97,7 +108,8 @@
(describe "when there are multiple dependencies"
(before-each
(setq-local cider-jack-in-lein-plugins '(("refactor-nrepl" "2.0.0") ("cider/cider-nrepl" "0.11.0")))
(setq-local cider-jack-in-nrepl-middlewares '("refactor-nrepl.middleware/wrap-refactor" "cider.nrepl/cider-middleware")))
(setq-local cider-jack-in-nrepl-middlewares '("refactor-nrepl.middleware/wrap-refactor" "cider.nrepl/cider-middleware"))
(setq-local cider-jack-in-dependencies-exclusions '()))
(it "can inject dependencies in a lein project"
(expect (cider-inject-jack-in-dependencies "repl :headless" "lein")
:to-equal "update-in :dependencies conj \\[org.clojure/tools.nrepl\\ \\\"0.2.12\\\"\\] -- update-in :plugins conj \\[refactor-nrepl\\ \\\"2.0.0\\\"\\] -- update-in :plugins conj \\[cider/cider-nrepl\\ \\\"0.11.0\\\"\\] -- repl :headless"))
Expand Down

0 comments on commit 7b5a2ec

Please sign in to comment.