diff --git a/CHANGELOG.md b/CHANGELOG.md index e1a2c8d7a..fc54355fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. +* Add option to define exclusions for injected dependecies. Fixes [#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) diff --git a/cider.el b/cider.el index d7fd1c5d1..04a255692 100644 --- a/cider.el +++ b/cider.el @@ -245,6 +245,14 @@ 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. + +Elements of the list are 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. @@ -300,18 +308,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 " @@ -351,6 +367,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 diff --git a/test/cider-tests.el b/test/cider-tests.el index 8de16d251..c9c0d39e4 100644 --- a/test/cider-tests.el +++ b/test/cider-tests.el @@ -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")) @@ -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"))