emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/cider c2744a85f2 2/3: For Gradle jack-in use wrapper by de


From: ELPA Syncer
Subject: [nongnu] elpa/cider c2744a85f2 2/3: For Gradle jack-in use wrapper by default
Date: Sat, 30 Jul 2022 22:58:15 -0400 (EDT)

branch: elpa/cider
commit c2744a85f2e04824254a03fe2a291fd9b57a377b
Author: Andrew Oberstar <andrew.oberstar@outlook.com>
Commit: Andrew Oberstar <andrew.oberstar@outlook.com>

    For Gradle jack-in use wrapper by default
    
    While Gradle does support a global install on the PATH called via
    "gradle" it is much more common for projects to have the Gradle wrapper
    in their project, which allows each project to be pinned to a specific
    version of Gradle.
    
    This file is either "gradlew" or "gradlew.bat" in the project root.
    
    Since this file isn't on the exec-path, I use locate-file to resolve the
    file relative to the clojure-project-dir, but only if the file is
    clearly a relative path starting "./" or "../". We still fall back to
    looking up on the exec-path if someone sets their cider-gradle-command
    back to "gradle".
---
 CHANGELOG.md                                      |  1 +
 cider.el                                          | 16 ++++++++++++++--
 doc/modules/ROOT/pages/basics/up_and_running.adoc |  6 +++---
 test/cider-tests.el                               | 17 +++++++++++++++++
 4 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9dbed8e6f8..88d73f8c6d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
 
 - [#3226](https://github.com/clojure-emacs/cider/pull/3226): Populate 
completions metadata, making it possible to change the style of completion via 
`completion-category-override` or `completion-category-defaults`.
 - [#2946](https://github.com/clojure-emacs/cider/issues/2946): Add custom var 
`cider-merge-sessions` to allow combining sessions in two different ways: 
Setting `cider-merge-sessions` to `'host` will merge all sessions associated 
with the same host within a project. Setting it to `'project` will combine all 
sessions of a project irrespective of their host.
+- Support Gradle jack-in via the Gradle wrapper, instead of just a globally 
installed `gradle` on the `PATH`.
 
 ## Changes
 
diff --git a/cider.el b/cider.el
index 8484946d68..2f65c98d10 100644
--- a/cider.el
+++ b/cider.el
@@ -189,7 +189,7 @@ By default we favor the project-specific shadow-cljs over 
the system-wide."
   :package-version '(cider . "0.17.0"))
 
 (defcustom cider-gradle-command
-  "gradle"
+  "./gradlew"
   "The command used to execute Gradle."
   :type 'string
   :safe #'stringp
@@ -352,7 +352,11 @@ Throws an error if PROJECT-TYPE is unknown."
     ('shadow-cljs (let ((parts (split-string cider-shadow-cljs-command)))
                     (when-let* ((command (cider--resolve-command (car parts))))
                       (mapconcat #'identity (cons command (cdr parts)) " "))))
-    ('gradle (cider--resolve-command cider-gradle-command))
+    ;; here we have to account for use of the Gradle wrapper which is
+    ;; a shell script within their project, so if they have a clearly
+    ;; relative path like "./gradlew" use locate file instead of checking
+    ;; the exec-path
+    ('gradle (cider--resolve-project-command cider-gradle-command))
     (_ (user-error "Unsupported project type `%S'" project-type))))
 
 (defun cider-jack-in-global-options (project-type)
@@ -1652,6 +1656,14 @@ assume the command is available."
                            (executable-find (concat command ".bat")))))
     (shell-quote-argument command)))
 
+(defun cider--resolve-project-command (command)
+  "Find COMMAND in project dir or exec path (see variable `exec-path').
+If COMMAND starts with ./ or ../ resolve relative to `clojure-project-dir',
+otherwise resolve via `cider--resolve-command'."
+  (if (string-match-p "\\`\\.\\{1,2\\}/" command)
+      (locate-file command (list (clojure-project-dir)) '("" ".bat") 
'executable)
+    (cider--resolve-command command)))
+
 (defcustom cider-connection-message-fn #'cider-random-words-of-inspiration
   "The function to use to generate the message displayed on connect.
 When set to nil no additional message will be displayed.  A good
diff --git a/doc/modules/ROOT/pages/basics/up_and_running.adoc 
b/doc/modules/ROOT/pages/basics/up_and_running.adoc
index 8b91749188..c435a5e151 100644
--- a/doc/modules/ROOT/pages/basics/up_and_running.adoc
+++ b/doc/modules/ROOT/pages/basics/up_and_running.adoc
@@ -175,9 +175,9 @@ wait`)
 
 ==== Gradle Options
 
-* `cider-gradle-command` - the name of the Gradle executable (`gradle` by 
default)
-* `cider-gradle-parameters`
-* `cider-gradle-global-options`
+* `cider-gradle-command` - the name of the Gradle executable (`./gradlew` by 
default)
+* `cider-gradle-parameters` - the Gradle arguments to invoke the repl task 
(`clojureRepl` by default)
+* `cider-gradle-global-options` - these are usually global options to gradle, 
such as `--no-daemon` or `--configuration-cache` (empty by default)
 
 ==== shadow-cljs
 
diff --git a/test/cider-tests.el b/test/cider-tests.el
index 7abb7b30a1..f661741897 100644
--- a/test/cider-tests.el
+++ b/test/cider-tests.el
@@ -525,6 +525,23 @@
               :to-equal
               "(do (require '[shadow.cljs.devtools.api :as shadow]) 
(shadow/watch :client-build) (shadow/watch :other-build) (shadow/nrepl-select 
:client-build))"))))
 
+(describe "cider--resolve-project-command"
+  (it "if command starts with ./ it resolves relative to clojure-project-dir"
+    (spy-on 'locate-file :and-return-value "/project/command")
+    (spy-on 'executable-find :and-return-value "/bin/command")
+    (expect (cider--resolve-project-command "./command")
+            :to-equal "/project/command"))
+  (it "if command starts with ../ it resolves relative to clojure-project-dir"
+    (spy-on 'locate-file :and-return-value "/project/command")
+    (spy-on 'executable-find :and-return-value "/bin/command")
+    (expect (cider--resolve-project-command "../command")
+            :to-equal "/project/command"))
+  (it "if command is bare it resolves against the exec-path"
+    (spy-on 'locate-file :and-return-value "/project/command")
+    (spy-on 'executable-find :and-return-value "/bin/command")
+    (expect (cider--resolve-project-command "command")
+            :to-equal "/bin/command")))
+
 (provide 'cider-tests)
 
 ;;; cider-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]