-
Notifications
You must be signed in to change notification settings - Fork 102
/
eclim-ant.el
105 lines (89 loc) · 3.95 KB
/
eclim-ant.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
;; eclim-ant.el --- an interface to the Eclipse IDE.
;;
;; Copyright (C) 2009 Yves Senn <yves senn * gmx ch>
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Contributors
;;
;;
;;; Conventions
;;
;; Conventions used in this file: Name internal variables and functions
;; "eclim--<descriptive-name>", and name eclim command invocations
;; "eclim/command-name", like eclim/project-list.
;;* Eclim Ant
(define-key eclim-mode-map (kbd "C-c C-e a c") 'eclim-ant-clear-cache)
(define-key eclim-mode-map (kbd "C-c C-e a r") 'eclim-ant-run)
(define-key eclim-mode-map (kbd "C-c C-e a a") 'eclim-ant-run)
(define-key eclim-mode-map (kbd "C-c C-e a v") 'eclim-ant-validate)
(defgroup eclim-ant nil
"Build java projects using Apache Ant"
:group 'eclim)
(defcustom eclim-ant-directory ""
"This variable contains the location, where the main buildfile is
stored. It is used globally for all eclim projects."
:group 'eclim-ant
:type 'directory)
(defcustom eclim-ant-buildfile-name "build.xml"
"The name of the main buildfile from your projects."
:group 'eclim-ant
:type 'string)
(defvar eclim--ant-target-cache nil)
(defun eclim--ant-buildfile-name ()
(concat (file-name-as-directory eclim-ant-directory) eclim-ant-buildfile-name))
(defun eclim--ant-buildfile-path ()
(file-name-directory (concat (eclim--project-dir) "/" (eclim--ant-buildfile-name))))
(defun eclim--ant-targets (project buildfile)
(when (null eclim--ant-target-cache)
(setq eclim--ant-target-cache (make-hash-table :test 'equal)))
(or (gethash buildfile eclim--ant-target-cache)
(puthash buildfile (eclim/ant-target-list project buildfile) eclim--ant-target-cache)))
(defun eclim--ant-read-target (project buildfile)
(eclim--completing-read "Target: " (append (eclim--ant-targets project buildfile) nil)))
(defun eclim/ant-validate (project buildfile)
(eclim--check-project project)
(mapcar (lambda (line)
(split-string line "|"))
(eclim--call-process "ant_validate" "-p" project "-f" file)))
(defun eclim/ant-target-list (project buildfile)
(eclim--check-project project)
(eclim--call-process "ant_targets" "-p" project "-f" buildfile))
(defun eclim-ant-clear-cache ()
"Clear the cached ant target list. This can be usefull when the
buildfile for the current project has changed and needs to be updated"
(interactive)
(setq eclim--ant-target-cache nil))
(defun eclim-ant-validate (project file)
"Run ant-xml validation against the file opened in the current
buffer. The results are displayed in a dedicated compilation buffer."
(interactive (list (eclim-project-name) (buffer-file-name)))
(pop-to-buffer (get-buffer-create "*eclim: build*"))
(let ((buffer-read-only nil))
(erase-buffer)
(dolist (line (eclim/ant-validate project file))
(insert (eclim--convert-find-result-to-string line))
(newline)))
(beginning-of-buffer)
(compilation-mode))
(defun eclim-ant-run (target)
"run a specified ant target in the scope of the current project. If
the function is called interactively the users is presented with a
list of all available ant targets."
(interactive (list (eclim--ant-read-target (eclim-project-name)
(eclim--ant-buildfile-name))))
(let ((default-directory (eclim--ant-buildfile-path)))
;; TODO: use the right version of java to execute ant
(compile (concat "ant " target))))
(provide 'eclim-ant)