Skip to content

Commit

Permalink
Use inlined :cider/nrepl alias to inject -Djdk.attach.allowAttachSelf
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yakushev authored and bbatsov committed Jun 3, 2024
1 parent 9f93a5f commit 03664c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
11 changes: 7 additions & 4 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -910,13 +910,16 @@ your aliases contain any mains, the cider/nrepl one will be the one used."
(cider-jack-in-normalized-nrepl-middlewares)
","))
(main-opts (format "\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[%s]\"" middleware))
(deps (format "{:deps {%s} :aliases {:cider/nrepl {:main-opts [%s]}}}"
(string-join all-deps " ") main-opts))
(deps (format "{:deps {%s} :aliases {:cider/nrepl {%s:main-opts [%s]}}}"
(string-join all-deps " ")
(if cider-enable-nrepl-jvmti-agent
":jvm-opts [\"-Djdk.attach.allowAttachSelf\"], "
"")
main-opts))
(deps-quoted (cider--shell-quote-argument deps command)))
(format "%s%s-Sdeps %s -M%s:cider/nrepl%s"
(format "%s-Sdeps %s -M%s:cider/nrepl%s"
;; TODO: global-options are deprecated and should be removed in CIDER 2.0
(if global-options (format "%s " global-options) "")
(if cider-enable-nrepl-jvmti-agent "-J-Djdk.attach.allowAttachSelf " "")
deps-quoted
(cider--combined-aliases)
(if params (format " %s" params) ""))))
Expand Down
26 changes: 12 additions & 14 deletions test/cider-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@
(it "uses main opts in an alias to prevent other mains from winning"
(setq-local cider-jack-in-dependencies nil)
(setq-local cider-jack-in-nrepl-middlewares '("cider.nrepl/cider-middleware"))
(let ((expected (string-join `("clojure -J-Djdk.attach.allowAttachSelf -Sdeps "
,(shell-quote-argument "{:deps {nrepl/nrepl {:mvn/version \"0.9.0\"} cider/cider-nrepl {:mvn/version \"0.49.0\"}} :aliases {:cider/nrepl {:main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}")
(let ((expected (string-join `("clojure -Sdeps "
,(shell-quote-argument "{:deps {nrepl/nrepl {:mvn/version \"0.9.0\"} cider/cider-nrepl {:mvn/version \"0.49.0\"}} :aliases {:cider/nrepl {:jvm-opts [\"-Djdk.attach.allowAttachSelf\"], :main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}")
" -M:cider/nrepl")
"")))
(setq-local cider-allow-jack-in-without-project t)
Expand All @@ -470,8 +470,8 @@
:to-equal expected)))

(it "allows specifying custom aliases with `cider-clojure-cli-aliases`"
(let ((expected (string-join `("clojure -J-Djdk.attach.allowAttachSelf -Sdeps "
,(shell-quote-argument "{:deps {nrepl/nrepl {:mvn/version \"0.9.0\"} cider/cider-nrepl {:mvn/version \"0.49.0\"}} :aliases {:cider/nrepl {:main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}")
(let ((expected (string-join `("clojure -Sdeps "
,(shell-quote-argument "{:deps {nrepl/nrepl {:mvn/version \"0.9.0\"} cider/cider-nrepl {:mvn/version \"0.49.0\"}} :aliases {:cider/nrepl {:jvm-opts [\"-Djdk.attach.allowAttachSelf\"], :main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}")
" -M:dev:test:cider/nrepl")
"")))
(setq-local cider-jack-in-dependencies nil)
Expand All @@ -488,9 +488,8 @@
(dolist (command '("clojure" "powershell"))
(it (format "should remove duplicates, yielding the same result (for %S command invocation)" command)
;; repeat the same test for PowerShell too
(let ((expected (string-join `("-J-Djdk.attach.allowAttachSelf "
"-Sdeps "
,(cider--shell-quote-argument "{:deps {cider/cider-nrepl {:mvn/version \"0.49.0\"} nrepl/nrepl {:mvn/version \"0.9.0\"}} :aliases {:cider/nrepl {:main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}"
(let ((expected (string-join `("-Sdeps "
,(cider--shell-quote-argument "{:deps {cider/cider-nrepl {:mvn/version \"0.49.0\"} nrepl/nrepl {:mvn/version \"0.9.0\"}} :aliases {:cider/nrepl {:jvm-opts [\"-Djdk.attach.allowAttachSelf\"], :main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}"
command)
" -M:dev:test:cider/nrepl")
"")))
Expand All @@ -499,9 +498,8 @@
command)
:to-equal expected))))
(it "handles aliases correctly"
(let ((expected (string-join `("-J-Djdk.attach.allowAttachSelf "
"-Sdeps "
,(shell-quote-argument "{:deps {cider/cider-nrepl {:mvn/version \"0.49.0\"} nrepl/nrepl {:mvn/version \"0.9.0\"}} :aliases {:cider/nrepl {:main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}")
(let ((expected (string-join `("-Sdeps "
,(shell-quote-argument "{:deps {cider/cider-nrepl {:mvn/version \"0.49.0\"} nrepl/nrepl {:mvn/version \"0.9.0\"}} :aliases {:cider/nrepl {:jvm-opts [\"-Djdk.attach.allowAttachSelf\"], :main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}")
" -M:test:cider/nrepl")
""))
(deps '(("nrepl/nrepl" "0.9.0"))))
Expand All @@ -528,8 +526,8 @@
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps)
:to-equal expected)))))
(it "allows for global options"
(let ((expected (string-join `("-J-Xverify:none -J-Djdk.attach.allowAttachSelf -Sdeps "
,(shell-quote-argument "{:deps {cider/cider-nrepl {:mvn/version \"0.49.0\"} nrepl/nrepl {:mvn/version \"0.9.0\"}} :aliases {:cider/nrepl {:main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}")
(let ((expected (string-join `("-J-Xverify:none -Sdeps "
,(shell-quote-argument "{:deps {cider/cider-nrepl {:mvn/version \"0.49.0\"} nrepl/nrepl {:mvn/version \"0.9.0\"}} :aliases {:cider/nrepl {:jvm-opts [\"-Djdk.attach.allowAttachSelf\"], :main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}")
" -M:test:cider/nrepl")
""))
(deps '(("nrepl/nrepl" "0.9.0"))))
Expand All @@ -539,8 +537,8 @@
(it "allows to specify git coordinate as cider-jack-in-dependency"
(setq-local cider-jack-in-dependencies '(("org.clojure/tools.deps" (("git/sha" . "6ae2b6f71773de7549d7f22759e8b09fec27f0d9")
("git/url" . "https://github.com/clojure/tools.deps/")))))
(let ((expected (string-join `("clojure -J-Djdk.attach.allowAttachSelf -Sdeps "
,(shell-quote-argument "{:deps {nrepl/nrepl {:mvn/version \"0.9.0\"} cider/cider-nrepl {:mvn/version \"0.49.0\"} org.clojure/tools.deps { :git/sha \"6ae2b6f71773de7549d7f22759e8b09fec27f0d9\" :git/url \"https://github.com/clojure/tools.deps/\" }} :aliases {:cider/nrepl {:main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}")
(let ((expected (string-join `("clojure -Sdeps "
,(shell-quote-argument "{:deps {nrepl/nrepl {:mvn/version \"0.9.0\"} cider/cider-nrepl {:mvn/version \"0.49.0\"} org.clojure/tools.deps { :git/sha \"6ae2b6f71773de7549d7f22759e8b09fec27f0d9\" :git/url \"https://github.com/clojure/tools.deps/\" }} :aliases {:cider/nrepl {:jvm-opts [\"-Djdk.attach.allowAttachSelf\"], :main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}}")
" -M:cider/nrepl")
"")))
(setq-local cider-allow-jack-in-without-project t)
Expand Down

0 comments on commit 03664c1

Please sign in to comment.