├── .gitignore ├── .travis.yml ├── Cask ├── Makefile ├── README.md ├── features ├── gradle-mode.feature ├── gradlew-support.feature ├── step-definitions │ └── gradle-mode-steps.el └── support │ └── env.el ├── gradle-mode.el └── test ├── gradle-mode-test.el └── test-helper.el /.gitignore: -------------------------------------------------------------------------------- 1 | .cask 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: emacs-lisp 2 | before_install: 3 | - sudo mkdir /usr/local/evm 4 | - sudo chown travis:travis /usr/local/evm 5 | - export PATH="/home/travis/.evm/bin:$PATH" 6 | - export PATH="/home/travis/.cask/bin:$PATH" 7 | - curl -fsSkL https://raw.github.com/rejeep/evm/master/go | bash 8 | - evm install emacs-24.3-bin --use 9 | - curl -fsSkL https://raw.github.com/cask/cask/master/go | python 10 | 11 | install: 12 | - cask 13 | - evm install $EVM_EMACS --use --skip 14 | 15 | env: 16 | # only emacs 24.3 seems to working for the ert tests. 17 | # - EVM_EMACS=emacs-23.4-bin 18 | # - EVM_EMACS=emacs-24.1-bin 19 | # - EVM_EMACS=emacs-24.2-bin 20 | - EVM_EMACS=emacs-24.3-bin 21 | 22 | script: 23 | - emacs --version 24 | - make travis 25 | -------------------------------------------------------------------------------- /Cask: -------------------------------------------------------------------------------- 1 | (source gnu) 2 | (source melpa) 3 | 4 | (package-file "gradle-mode.el") 5 | 6 | (development 7 | (depends-on "f") 8 | (depends-on "s") 9 | (depends-on "dash") 10 | (depends-on "ecukes") 11 | (depends-on "espuds") 12 | (depends-on "ert-runner") 13 | (depends-on "el-mock")) 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | EMACS ?= emacs 2 | CASK ?= cask 3 | 4 | all: test 5 | 6 | test: clean-elc 7 | ${MAKE} unit 8 | ${MAKE} ecukes 9 | ${MAKE} compile 10 | ${MAKE} unit 11 | ${MAKE} ecukes 12 | ${MAKE} clean-elc 13 | 14 | travis: clean-elc 15 | ${MAKE} unit 16 | ${MAKE} ecukes-travis 17 | ${MAKE} compile 18 | ${MAKE} unit 19 | ${MAKE} ecukes-travis 20 | ${MAKE} clean-elc 21 | 22 | unit: 23 | ${CASK} exec ert-runner 24 | 25 | ecukes: 26 | ${CASK} exec ecukes --reporter gangsta 27 | 28 | ecukes-travis: 29 | ${CASK} exec ecukes --reporter gangsta --no-win 30 | 31 | docs: 32 | ${CASK} exec ${EMACS} -Q --script bin/docs.el 33 | 34 | compile: 35 | ${CASK} build 36 | 37 | clean-elc: 38 | ${CASK} clean-elc 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | emacs-gradle-mode 2 | ================= 3 | [![Build Status](https://travis-ci.org/jacobono/emacs-gradle-mode.svg?branch=master)] 4 | (https://travis-ci.org/jacobono/emacs-gradle-mode) 5 | 6 | Minor mode for emacs to run gradle from emacs and not have to go to a terminal! 7 | 8 | # Installation # 9 | 10 | Available on [MELPA](https://melpa.org/): 11 | 12 | M-x package-install gradle-mode 13 | 14 | Or you can just dump `gradle-mode.el` in your load path somewhere. 15 | 16 | After installation, you can configure this mode to always be on with: 17 | 18 | ```lisp 19 | (require 'gradle-mode) 20 | 21 | (gradle-mode 1) 22 | ``` 23 | 24 | Or just 25 | 26 | M-x gradle-mode 27 | 28 | when you are ready to use it. 29 | 30 | ## Keybindings ## 31 | 32 | * `C-c C-g b` 33 | - run `gradle build` 34 | * `C-c C-g t` 35 | - run `gradle test` 36 | * `C-c C-g s` 37 | - run `gradle test -Dsingle.test="user-supplied"` 38 | - User supplies test to run from prompt 39 | * `C-c C-g C-d b` 40 | - run `gradle build --daemon` 41 | * `C-c C-g C-d t` 42 | - run `gradle test --daemon` 43 | * `C-c C-g C-d s` 44 | - run `gradle -Dsingle.test="user-supplied" --daemon` 45 | - User supplies test to run from prompt 46 | * `C-c C-g d` 47 | - run `gradle "user-supplied" --daemon` 48 | - User supplies tasks to run from prompt 49 | * `C-c C-g r` 50 | - run `gradle "user-supplied"` 51 | - User supplies tasks to run from prompt 52 | 53 | The prefix `C-d` runs the command with gradle's daemon, or creates one 54 | if it is not already present. 55 | 56 | # Limitations # 57 | **Currently**, the only versions of emacs that are passing are _24.3_. 58 | I plan on trying to look into it more, but both Travis and drone are 59 | barfing when I try and run the tests with <24.3. 60 | 61 | # Contribute # 62 | If you want to contribute, please fork and submit a pull request! 63 | 64 | # Changlog # 65 | ## 0.5.5 66 | - gradlew support added. Will find nearest gradlew file and run if 67 | `gradle-use-gradlew` is turned on 68 | 69 | ## 0.5.4 70 | - CI is breaking from 0.5.4, only version of Emacs that tests execute 71 | appropriately is **24.3** 72 | 73 | ## 0.5.3 74 | - losing dependencies on `f` and `dash` 75 | - `gradle-project-find-dir` uses `locate-dominating-file` instead of `f-traverse-upwards` 76 | 77 | ## 0.5.2 78 | - mode lighter string changed from _gra_ to _Gradle_ 79 | 80 | ## 0.5 81 | - First Release 82 | -------------------------------------------------------------------------------- /features/gradle-mode.feature: -------------------------------------------------------------------------------- 1 | Feature: Execute Key Bindings 2 | In order to execute gradle commands 3 | As a user 4 | I want to enter key bindings to run gradle commands 5 | and maybe enter input after prompts appear 6 | then the command is run, and the compilation directory is appropriately set 7 | 8 | Scenario: Run Build Command Without Daemon 9 | When I press "C-c C-g b" 10 | Then Compilation directory is "gradle-mode-root-path" 11 | And Compilation command is "gradle build" 12 | 13 | Scenario: Run Test Command Without Daemon 14 | When I press "C-c C-g t" 15 | Then Compilation directory is "gradle-mode-root-path" 16 | And Compilation command is "gradle test" 17 | 18 | Scenario: Run Build Command With Daemon 19 | When I press "C-c C-g C-d b" 20 | Then Compilation directory is "gradle-mode-root-path" 21 | And Compilation command is "gradle build --daemon" 22 | 23 | Scenario: Run Test Command With Daemon 24 | When I press "C-c C-g C-d t" 25 | Then Compilation directory is "gradle-mode-root-path" 26 | And Compilation command is "gradle test --daemon" 27 | 28 | Scenario: Run Single Test Without Daemon 29 | Given I start an action chain 30 | And I press "C-c C-g s" 31 | And I type "MySpec" 32 | When I execute the action chain 33 | Then Compilation directory is "gradle-mode-root-path" 34 | And Compilation command is "gradle test -Dtest.single=MySpec" 35 | 36 | Scenario: Run Single Test With Daemon 37 | Given I start an action chain 38 | And I press "C-c C-g C-d s" 39 | And I type "MySpec" 40 | When I execute the action chain 41 | Then Compilation directory is "gradle-mode-root-path" 42 | And Compilation command is "gradle test -Dtest.single=MySpec --daemon" 43 | 44 | Scenario: Execute User Prompted Task(s) Without Daemon 45 | Given I start an action chain 46 | And I press "C-c C-g r" 47 | And I type "clean build" 48 | When I execute the action chain 49 | Then Compilation directory is "gradle-mode-root-path" 50 | And Compilation command is "gradle clean build" 51 | 52 | Scenario: Execute User Prompted Task(s) With Daemon 53 | Given I start an action chain 54 | And I press "C-c C-g d" 55 | And I type "clean build" 56 | When I execute the action chain 57 | Then Compilation directory is "gradle-mode-root-path" 58 | And Compilation command is "gradle clean build --daemon" 59 | -------------------------------------------------------------------------------- /features/gradlew-support.feature: -------------------------------------------------------------------------------- 1 | Feature: Execute Key Bindings with gradlew 2 | 3 | Background: 4 | Given I set gradle-use-gradlew to t 5 | 6 | Scenario: Run gradlew Build Without Daemon 7 | When I press "C-c C-g b" 8 | Then Compilation directory is "gradle-mode-root-path" 9 | And Compilation command is "gradlew build" 10 | 11 | Scenario: Run gradlew Test Without Daemon 12 | When I press "C-c C-g t" 13 | Then Compilation directory is "gradle-mode-root-path" 14 | And Compilation command is "gradlew test" 15 | 16 | Scenario: Run gradlew Build Command With Daemon 17 | When I press "C-c C-g C-d b" 18 | Then Compilation directory is "gradle-mode-root-path" 19 | And Compilation command is "gradlew build --daemon" 20 | 21 | Scenario: Run gradlew Test Command With Daemon 22 | When I press "C-c C-g C-d t" 23 | Then Compilation directory is "gradle-mode-root-path" 24 | And Compilation command is "gradlew test --daemon" 25 | 26 | Scenario: Run gradlew Single Test Without Daemon 27 | Given I start an action chain 28 | And I press "C-c C-g s" 29 | And I type "MySpec" 30 | When I execute the action chain 31 | Then Compilation directory is "gradle-mode-root-path" 32 | And Compilation command is "gradlew test -Dtest.single=MySpec" 33 | 34 | Scenario: Run gradlew Single Test With Daemon 35 | Given I start an action chain 36 | And I press "C-c C-g C-d s" 37 | And I type "MySpec" 38 | When I execute the action chain 39 | Then Compilation directory is "gradle-mode-root-path" 40 | And Compilation command is "gradlew test -Dtest.single=MySpec --daemon" 41 | 42 | Scenario: Execute User Prompted Task(s) Without gradlew Daemon 43 | Given I start an action chain 44 | And I press "C-c C-g r" 45 | And I type "clean build" 46 | When I execute the action chain 47 | Then Compilation directory is "gradle-mode-root-path" 48 | And Compilation command is "gradlew clean build" 49 | 50 | Scenario: Execute User Prompted Task(s) With gradlew Daemon 51 | Given I start an action chain 52 | And I press "C-c C-g d" 53 | And I type "clean build" 54 | When I execute the action chain 55 | Then Compilation directory is "gradle-mode-root-path" 56 | And Compilation command is "gradlew clean build --daemon" 57 | -------------------------------------------------------------------------------- /features/step-definitions/gradle-mode-steps.el: -------------------------------------------------------------------------------- 1 | ;;; gradle-mode-steps.el --- gradle-mode: Step definitions for Ecukes tests 2 | 3 | ;; Copyright (C) 2014 by Daniel Mijares 4 | 5 | ;; Author: Daniel Mijares 6 | ;; Maintainer: Daniel Mijares 7 | ;; URL: http://github.com/jacobono/gradle-mode 8 | 9 | ;; This file is NOT part of GNU Emacs. 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | ;;; Commentary: 25 | 26 | ;; Step definitions for Ecukes integration tests of gradle-mode. 27 | ;; I didn't want to actually run the compilation, so I mocked it 28 | ;; out. I was just testing that the bindings were working and 29 | ;; making the correct calls to 'compile'. 30 | 31 | ;;; Code: 32 | 33 | ;;; -------------------------- 34 | ;; Definitions 35 | ;;; -------------------------- 36 | 37 | (Then "^Compilation directory is \"\\(.+\\)\"$" 38 | (lambda (compile-directory) 39 | (should 40 | (equal 41 | compilation-directory 42 | (f-short 43 | (f-slash 44 | (symbol-value (intern compile-directory)))))))) 45 | 46 | (And "^Compilation command is \"\\(.+\\)\"$" 47 | (lambda (compilation-command) 48 | (should 49 | (equal 50 | compile-command 51 | compilation-command)))) 52 | 53 | ;;; gradle-mode-steps.el ends here 54 | -------------------------------------------------------------------------------- /features/support/env.el: -------------------------------------------------------------------------------- 1 | ;;; env.el --- gradle-mode: ecukes environment setup 2 | 3 | ;; Copyright (C) 2014 by Daniel Mijares 4 | 5 | ;; Author: Daniel Mijares 6 | ;; Maintainer: Daniel Mijares 7 | ;; URL: http://github.com/jacobono/gradle-mode 8 | 9 | ;; This file is NOT part of GNU Emacs. 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | ;;; Commentary: 25 | 26 | ;;; Code: 27 | 28 | (require 'f) 29 | 30 | (defvar gradle-mode-support-path 31 | (f-dirname load-file-name)) 32 | 33 | (defvar gradle-mode-features-path 34 | (f-parent gradle-mode-support-path)) 35 | 36 | (defvar gradle-mode-root-path 37 | (f-parent gradle-mode-features-path)) 38 | 39 | (add-to-list 'load-path gradle-mode-root-path) 40 | 41 | ;; avoid emacs interrupting tests with 42 | ;; "Please answer yes or no" 43 | ;; which is think is happening because it is trying to delete the 44 | ;; compilation buffer after running one compilation? 45 | (fset 'yes-or-no-p (lambda (_) t)) 46 | 47 | (require 'gradle-mode) 48 | (require 'espuds) 49 | (require 'ert) 50 | 51 | (Setup 52 | ;; Before anything has run 53 | (f-touch "build.gradle") 54 | (f-touch "gradlew") 55 | (setq gradle-executable-path "gradle") 56 | (gradle-mode 1) 57 | ) 58 | 59 | (Before 60 | ;; Before each scenario is run 61 | ) 62 | 63 | (After 64 | ;; After each scenario is run 65 | ) 66 | 67 | (Teardown 68 | ;; After when everything has been run 69 | (f-delete "build.gradle") 70 | (f-delete "gradlew") 71 | (gradle-mode 0) 72 | ) 73 | 74 | ;;; env.el ends here 75 | -------------------------------------------------------------------------------- /gradle-mode.el: -------------------------------------------------------------------------------- 1 | ;;; gradle-mode.el --- Gradle integration with Emacs' compile 2 | 3 | ;; Copyright (C) 2014 by Daniel Mijares 4 | 5 | ;; Author: Daniel Mijares 6 | ;; Maintainer: Daniel Mijares 7 | ;; URL: http://github.com/jacobono/emacs-gradle-mode 8 | ;; Version: 0.5.3 9 | ;; Keywords: gradle 10 | ;; Package-Requires: ((s "1.8.0")) 11 | 12 | ;; This file is NOT part of GNU Emacs. 13 | 14 | ;; This program is free software; you can redistribute it and/or modify 15 | ;; it under the terms of the GNU General Public License as published by 16 | ;; the Free Software Foundation, either version 3 of the License, or 17 | ;; (at your option) any later version. 18 | 19 | ;; This program is distributed in the hope that it will be useful, 20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | ;; GNU General Public License for more details. 23 | 24 | ;; You should have received a copy of the GNU General Public License 25 | ;; along with this program. If not, see . 26 | 27 | ;;; Commentary: 28 | 29 | ;; Gradle integration into Emacs, through compile-mode. 30 | ;; see documentation on https://github.com/jacobono/emacs-gradle-mode 31 | 32 | ;;; Code: 33 | 34 | ;;; -------------------------- 35 | ;; gradle-mode dependencies 36 | ;;; -------------------------- 37 | 38 | (require 's) 39 | (require 'compile) 40 | 41 | ;;; -------------------------- 42 | ;; gradle-mode variables 43 | ;;; -------------------------- 44 | 45 | ;; error processing if no executable?? 46 | (defcustom gradle-executable-path (executable-find "gradle") 47 | "String representation of the Gradle executable location. 48 | Absolute path, usually found with `executable-find'." 49 | :group 'gradle 50 | :type 'string) 51 | 52 | (defcustom gradle-gradlew-executable "gradlew" 53 | "String representation of the gradlew executable." 54 | :group 'gradle 55 | :type 'string) 56 | 57 | (defcustom gradle-use-gradlew nil 58 | "Use gradlew or `gradle-executable-path'. 59 | If true, run gradlew from its location in the project file system. 60 | If false, will find project build file and run `gradle-executable-path' from there." 61 | :group 'gradle 62 | :type 'boolean) 63 | ;;; -------------------------- 64 | ;; gradle-mode private functions 65 | ;;; -------------------------- 66 | 67 | (defun gradle-is-project-dir (dir) 68 | "Is this DIR a gradle project directory with an extra convention. 69 | A project dir is always considered if there is a 'build.gradle' there. 70 | A project dir is also considered if there is a '{dirname}.gradle'. This 71 | is a convention for multi-build projects, where dirname is under some 72 | 'rootDir/dirname/dirname.gradle'." 73 | (let ((dirname (file-name-nondirectory 74 | (directory-file-name (expand-file-name dir))))) 75 | (or (file-exists-p (expand-file-name "build.gradle" dir)) 76 | (file-exists-p (expand-file-name 77 | (concat dirname ".gradle") dir))))) 78 | 79 | (defun gradle-is-gradlew-dir (dir) 80 | "Does this DIR contain a gradlew executable file." 81 | (file-exists-p (expand-file-name "gradlew" dir))) 82 | 83 | (defun gradle-run-from-dir (is-dir) 84 | "Find the closest dir to execute the gradle command under via IS-DIR function. 85 | If there is a folder you care to run from higher than this level, you need to move out to that level (eg. through dired etc.)." 86 | (locate-dominating-file default-directory is-dir)) 87 | 88 | (defun gradle-kill-compilation-buffer () 89 | "Kill compilation buffer if present." 90 | (progn 91 | (if (get-buffer "*compilation*") 92 | (progn 93 | (delete-windows-on (get-buffer "*compilation*")) 94 | (kill-buffer "*compilation*"))))) 95 | 96 | (defun gradle-run (gradle-tasks) 97 | "Run gradle command with `GRADLE-TASKS' and options supplied." 98 | (gradle-kill-compilation-buffer) 99 | (let ((default-directory 100 | (gradle-run-from-dir (if gradle-use-gradlew 101 | 'gradle-is-gradlew-dir 102 | 'gradle-is-project-dir)))) 103 | (compile (gradle-make-command gradle-tasks)))) 104 | 105 | (defun gradle-make-command (gradle-tasks) 106 | "Make the gradle command, using some executable path and GRADLE-TASKS." 107 | (let ((gradle-executable (if gradle-use-gradlew 108 | gradle-gradlew-executable 109 | gradle-executable-path))) 110 | (s-join " " (list gradle-executable gradle-tasks)))) 111 | 112 | ;;; -------------------------- 113 | ;; gradle-mode interactive functions 114 | ;;; -------------------------- 115 | 116 | (defun gradle-execute (tasks) 117 | "Execute gradle command with TASKS supplied by user input." 118 | (interactive "sType tasks to run: ") 119 | (gradle-run tasks)) 120 | 121 | (defun gradle-build () 122 | "Execute gradle build command." 123 | (interactive) 124 | (gradle-run "build")) 125 | 126 | (defun gradle-test () 127 | "Execute gradle test command." 128 | (interactive) 129 | (gradle-run "test")) 130 | 131 | (defun gradle-single-test (single-test-name) 132 | "Execute gradle test on file SINGLE-TEST-NAME supplied by user." 133 | (interactive "sType single test to run: ") 134 | (gradle-run 135 | (s-concat "test -Dtest.single=" single-test-name))) 136 | 137 | (defun gradle-execute--daemon (tasks) 138 | "Execute gradle command, using daemon, with TASKS supplied by user input." 139 | (interactive "sType tasks to run: ") 140 | (gradle-run 141 | (s-concat tasks " --daemon"))) 142 | 143 | (defun gradle-build--daemon () 144 | "Execute gradle build command, using daemon." 145 | (interactive) 146 | (gradle-run "build --daemon")) 147 | 148 | (defun gradle-test--daemon () 149 | "Execute gradle test command, using daemon." 150 | (interactive) 151 | (gradle-run "test --daemon")) 152 | 153 | (defun gradle-single-test--daemon (single-test-name) 154 | "Execute gradle test, using daemon, on file SINGLE-TEST-NAME supplied by user." 155 | (interactive "sType single test to run: ") 156 | (gradle-run 157 | (s-concat "test -Dtest.single=" single-test-name " --daemon"))) 158 | 159 | ;;; ---------- 160 | ;; gradle-mode keybindings 161 | ;;; ---------- 162 | 163 | (defvar gradle-mode-map 164 | (let ((map (make-sparse-keymap))) 165 | (define-key map (kbd "C-c C-g b") 'gradle-build) 166 | (define-key map (kbd "C-c C-g t") 'gradle-test) 167 | (define-key map (kbd "C-c C-g s") 'gradle-single-test) 168 | (define-key map (kbd "C-c C-g C-d b") 'gradle-build--daemon) 169 | (define-key map (kbd "C-c C-g C-d t") 'gradle-test--daemon) 170 | (define-key map (kbd "C-c C-g C-d s") 'gradle-single-test--daemon) 171 | (define-key map (kbd "C-c C-g d") 'gradle-execute--daemon) 172 | (define-key map (kbd "C-c C-g r") 'gradle-execute) 173 | map) 174 | "Keymap for the gradle minor mode.") 175 | 176 | ;;;###autoload 177 | (define-minor-mode gradle-mode 178 | "Emacs minor mode for integrating Gradle into compile. 179 | Run gradle tasks from any buffer, scanning up to nearest gradle 180 | directory to run tasks." 181 | :lighter " Gradle" 182 | :keymap 'gradle-mode-map 183 | :global t) 184 | 185 | (provide 'gradle-mode) 186 | 187 | ;;; gradle-mode.el ends here 188 | -------------------------------------------------------------------------------- /test/gradle-mode-test.el: -------------------------------------------------------------------------------- 1 | ;;; gradle-mode-test.el --- gradle-mode: ERT tests 2 | 3 | ;; Copyright (C) 2014 by Daniel Mijares 4 | 5 | ;; Author: Daniel Mijares 6 | ;; Maintainer: Daniel Mijares 7 | ;; URL: http://github.com/jacobono/gradle-mode 8 | 9 | ;; This file is NOT part of GNU Emacs. 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | ;;; Commentary: 25 | 26 | ;;; Code: 27 | 28 | ;; make the correct gradle command, combining executable with tasks 29 | 30 | (ert-deftest gradle-test-make-command () 31 | (should 32 | (equal 33 | (gradle-make-command "test -Dtest-single=MyTest --daemon") 34 | "gradle test -Dtest-single=MyTest --daemon")) 35 | (should 36 | (equal 37 | (gradle-make-command "build --daemon") 38 | "gradle build --daemon")) 39 | (should 40 | (equal 41 | (gradle-make-command "test") 42 | "gradle test")) 43 | (let ((gradle-use-gradlew t)) 44 | (should 45 | (equal 46 | (gradle-make-command "test -Dtest-single=MyTest --daemon") 47 | "gradlew test -Dtest-single=MyTest --daemon")) 48 | (should 49 | (equal 50 | (gradle-make-command "build --daemon") 51 | "gradlew build --daemon")) 52 | (should 53 | (equal 54 | (gradle-make-command "test") 55 | "gradlew test")))) 56 | 57 | ;; find the correct gradle project directory to run commands in 58 | 59 | (ert-deftest gradle-test-find-project-dir () 60 | ;; dominating-file returns the user path replace with "~/", 61 | ;; compare this with (f-short) and since f-short does not 62 | ;; add "/" to directory add, because dominating-file returns directory 63 | ;; with the "/" at its end. 64 | 65 | ;; make sandbox directories to find the correct gradle project fil 66 | (f-mkdir gradle-mode-test/sandbox-path "some-project" "src" "main") 67 | 68 | ;; touch gradle project files 69 | (f-touch (f-join gradle-mode-test/sandbox-path "build.gradle")) 70 | (f-touch (f-join gradle-mode-test/sandbox-path "gradlew")) 71 | (f-touch (f-join gradle-mode-test/sandbox-path "some-project" 72 | "some-project.gradle")) 73 | 74 | ;; test in the root project dir 75 | (let ((default-directory (f-long gradle-mode-test/sandbox-path))) 76 | (should 77 | (equal 78 | (gradle-run-from-dir 'gradle-is-project-dir) 79 | (f-slash (f-short gradle-mode-test/sandbox-path)))) 80 | (let ((gradle-use-gradlew t)) 81 | (should 82 | (equal 83 | (gradle-run-from-dir 'gradle-is-gradlew-dir) 84 | (f-slash 85 | (f-short gradle-mode-test/sandbox-path)))))) 86 | 87 | ;; test in the sub-project dir 88 | (let ((default-directory (f-join gradle-mode-test/sandbox-path 89 | "some-project"))) 90 | (should 91 | (equal 92 | (gradle-run-from-dir 'gradle-is-project-dir) 93 | (f-slash 94 | (f-short (f-join gradle-mode-test/sandbox-path "some-project"))))) 95 | (let ((gradle-use-gradlew t)) 96 | (should 97 | (equal 98 | (gradle-run-from-dir 'gradle-is-gradlew-dir) 99 | (f-slash 100 | (f-short gradle-mode-test/sandbox-path)))))) 101 | 102 | ;; test in a sub directory of sub-project dir 103 | (let ((default-directory (f-join gradle-mode-test/sandbox-path 104 | "some-project" "src" "main"))) 105 | (should 106 | (equal 107 | (gradle-run-from-dir 'gradle-is-project-dir) 108 | (f-slash 109 | (f-short (f-join gradle-mode-test/sandbox-path "some-project"))))) 110 | (let ((gradle-use-gradlew t)) 111 | (should 112 | (equal 113 | (gradle-run-from-dir 'gradle-is-gradlew-dir) 114 | (f-slash 115 | (f-short gradle-mode-test/sandbox-path)))))) 116 | 117 | ;; delete all sandbox directory 118 | (f-delete gradle-mode-test/sandbox-path t)) 119 | 120 | ;; kill compilation buffer if it is opened 121 | 122 | (ert-deftest gradle-test-close-compilation-buffer () 123 | ;; make compilation buffer 124 | (get-buffer-create "*compilation*") 125 | (gradle-kill-compilation-buffer) 126 | (should 127 | (equal 128 | (get-buffer "*compilation*") 129 | nil))) 130 | 131 | ;;; gradle-mode-test.el ends here 132 | 133 | -------------------------------------------------------------------------------- /test/test-helper.el: -------------------------------------------------------------------------------- 1 | ;;; test-helper.el --- gradle-mode: Test helper 2 | 3 | ;; Copyright (C) 2014 by Daniel Mijares 4 | 5 | ;; Author: Daniel Mijares 6 | ;; Maintainer: Daniel Mijares 7 | ;; URL: http://github.com/jacobono/gradle-mode 8 | 9 | ;; This file is NOT part of GNU Emacs. 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | ;;; Commentary: 25 | 26 | ;;; Code: 27 | 28 | (require 'f) 29 | (require 'dash) 30 | 31 | ;; for testing, always make executable path just 'gradle' 32 | (setq gradle-executable-path "gradle") 33 | 34 | (defvar gradle-mode-test/test-path 35 | (f-dirname (f-this-file)) 36 | "Path to tests directory.") 37 | 38 | (defvar gradle-mode-test/root-path 39 | (f-parent gradle-mode-test/test-path) 40 | "Path to root directory.") 41 | 42 | (defconst gradle-mode-test/sandbox-path 43 | (f-expand "sandbox" gradle-mode-test/test-path) 44 | "Path to 'sandbox' directory where gradle files are placed.") 45 | 46 | ;; load up gradle-mode to test it. 47 | (add-to-list 'load-path gradle-mode-test/root-path) 48 | (require 'gradle-mode) 49 | 50 | ;;; test-helper.el ends here 51 | --------------------------------------------------------------------------------