Add support in maven run-command to run in project root or local pom

This commit is contained in:
Jeremy Dormitzer 2022-04-21 10:57:18 -04:00
parent c9420cf1a6
commit 224c5a6b29

View File

@ -217,54 +217,68 @@
(defun run-command-recipe-maven ()
(when-let* ((root-dir (or (projectile-project-root) default-directory))
(project-dir (locate-dominating-file root-dir "pom.xml")))
(list
(list :command-name "validate"
:command-line "mvn validate"
:working-dir project-dir)
(list :command-name "compile"
:command-line "mvn compile"
:working-dir project-dir)
(list :command-name "clean compile"
:command-line "mvn clean compile"
:working-dir project-dir)
(list :command-name "test"
:command-line "mvn test -DfailIfNoTests=false"
:working-dir project-dir)
(list :command-name "package"
:command-line "mvn package"
:working-dir project-dir)
(list :command-name "verify"
:command-line "mvn verify"
:working-dir project-dir)
(list :command-name "install"
:command-line "mvn install"
:working-dir project-dir)
(list :command-name "deploy"
:command-line "mvn deploy"
:working-dir project-dir)
(list :command-name "clean"
:command-line "mvn clean"
:working-dir project-dir)
(list :command-name "exec:java"
:command-line "mvn compile exec:java"
:working-dir project-dir)
(when-let ((test-class (and (buffer-file-name)
(let ((case-fold-search nil))
(string-match-p ".*\\(Test\\|IT\\).*\\.java$" (buffer-file-name)))
(fboundp 'dap-java-test-class)
(dap-java-test-class))))
(list :command-name "test this class"
:command-line (format "mvn test -DfailIfNoTests=false -Dtest=%s" test-class)
:working-dir project-dir))
(when-let ((test-method (and (buffer-file-name)
(let ((case-fold-search nil))
(string-match-p ".*\\(Test\\|IT\\).*\\.java$" (buffer-file-name)))
(fboundp 'dap-java-test-method-at-point)
(dap-java-test-method-at-point t))))
(list :command-name "test this method"
:command-line (format "mvn test -DfailIfNoTests=false -Dtest=%s" test-method)
:working-dir project-dir)))))
(local-pom-dir (locate-dominating-file default-directory "pom.xml"))
(project-dir (locate-dominating-file root-dir "pom.xml"))
(commands (list
(list :command-name "validate"
:command-line "mvn validate"
:working-dir local-pom-dir)
(list :command-name "compile"
:command-line "mvn compile"
:working-dir local-pom-dir)
(list :command-name "clean compile"
:command-line "mvn clean compile"
:working-dir local-pom-dir)
(list :command-name "test"
:command-line "mvn test -DfailIfNoTests=false"
:working-dir local-pom-dir)
(list :command-name "package"
:command-line "mvn package"
:working-dir local-pom-dir)
(list :command-name "verify"
:command-line "mvn verify"
:working-dir local-pom-dir)
(list :command-name "install"
:command-line "mvn install"
:working-dir local-pom-dir)
(list :command-name "deploy"
:command-line "mvn deploy"
:working-dir local-pom-dir)
(list :command-name "clean"
:command-line "mvn clean"
:working-dir local-pom-dir)
(list :command-name "exec:java"
:command-line "mvn compile exec:java"
:working-dir local-pom-dir)
(when-let ((test-class (and (buffer-file-name)
(let ((case-fold-search nil))
(string-match-p ".*\\(Test\\|IT\\).*\\.java$"
(buffer-file-name)))
(fboundp 'dap-java-test-class)
(dap-java-test-class))))
(list :command-name "test this class"
:command-line (format "mvn test -DfailIfNoTests=false -Dtest=%s" test-class)
:working-dir local-pom-dir))
(when-let ((test-method (and (buffer-file-name)
(let ((case-fold-search nil))
(string-match-p ".*\\(Test\\|IT\\).*\\.java$"
(buffer-file-name)))
(fboundp 'dap-java-test-method-at-point)
(dap-java-test-method-at-point t))))
(list :command-name "test this method"
:command-line (format "mvn test -DfailIfNoTests=false -Dtest=%s" test-method)
:working-dir local-pom-dir)))))
(if (s-equals? local-pom-dir project-dir)
commands
(-concat commands
(-map (lambda (cmd)
(when cmd
(-> (-copy cmd)
(plist-put :command-name
(format "%s (root POM)"
(plist-get cmd :command-name)))
(plist-put :working-dir project-dir))))
commands)))))
(defun get-cargo-commands (dir)
(when (executable-find "cargo")