-
Notifications
You must be signed in to change notification settings - Fork 102
/
eclim-project.el
398 lines (335 loc) · 14.4 KB
/
eclim-project.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
;; eclim-project.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 Project
(defvar eclim-project-mode-hook nil)
(defvar eclim-project-info-mode-hook nil)
(defvar eclim--project-scopes '("project"
"workspace"))
(defvar eclim-project-mode-map
(let ((map (make-keymap)))
(suppress-keymap map t)
(define-key map (kbd "N") 'eclim-project-create)
(define-key map (kbd "m") 'eclim-project-mark-current)
(define-key map (kbd "M") 'eclim-project-mark-all)
(define-key map (kbd "u") 'eclim-project-unmark-current)
(define-key map (kbd "U") 'eclim-project-unmark-all)
(define-key map (kbd "o") 'eclim-project-open)
(define-key map (kbd "c") 'eclim-project-close)
(define-key map (kbd "i") 'eclim-project-info-mode)
(define-key map (kbd "I") 'eclim-project-import)
(define-key map (kbd "RET") 'eclim-project-goto)
(define-key map (kbd "D") 'eclim-project-delete)
(define-key map (kbd "p") 'eclim-project-update)
(define-key map (kbd "g") 'eclim-project-mode-refresh)
(define-key map (kbd "R") 'eclim-project-rename)
(define-key map (kbd "q") 'eclim-quit-window)
(define-key map (kbd "r") 'eclim-project-refresh)
map))
(defvar eclim-project-info-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map special-mode-map)
map))
(define-key eclim-mode-map (kbd "C-c C-e g") 'eclim-project-goto)
(define-key eclim-mode-map (kbd "C-c C-e p p") 'eclim-project-mode)
(define-key eclim-mode-map (kbd "C-c C-e p m") 'eclim-project-mode)
(define-key eclim-mode-map (kbd "C-c C-e p i") 'eclim-project-import)
(define-key eclim-mode-map (kbd "C-c C-e p c") 'eclim-project-create)
(define-key eclim-mode-map (kbd "C-c C-e p g") 'eclim-project-goto)
(defun eclim--project-clear-cache ()
(setq eclim--project-natures-cache nil)
(setq eclim--projects-cache nil))
(defun eclim--check-nature (nature)
(let ((natures (or eclim--project-natures-cache
(setq eclim--project-natures-cache (eclim/project-nature-aliases)))))
(when (not (member nature (append natures nil)))
(error (concat "invalid project nature: " nature)))))
(defun eclim--check-project (project)
(let ((projects (or eclim--projects-cache
(setq eclim--projects-cache (mapcar (lambda (p) (assoc-default 'name p)) (eclim/project-list))))))
(when (not (assoc-string project projects))
(error (concat "invalid project: " project))))) ;
(defun eclim--project-read (&optional single)
(interactive)
(if (eq major-mode 'eclim-project-mode)
(progn
(or (if single nil (eclim--project-get-marked))
(eclim--project-current-line)))
(eclim--completing-read "Project: "
(mapcar (lambda (p) (assoc-default 'name p)) (eclim/project-list)))))
(defun eclim--project-buffer-refresh ()
(eclim--project-clear-cache)
(when (eq major-mode 'eclim-project-mode)
(let ((inhibit-read-only t)
(line-number (line-number-at-pos)))
(erase-buffer)
(loop for project across (eclim/project-list)
do (eclim--insert-project project))
(goto-line line-number))))
(defun eclim--insert-project (project)
(insert (format " | %-6s | %-30s | %s\n"
(if (eq :json-false (assoc-default 'open project)) "closed" "open")
(truncate-string-to-width (assoc-default 'name project) 30 0 nil t)
(assoc-default 'path project))))
(defun eclim--project-insert-mark-current (face)
(let ((inhibit-read-only t))
(save-excursion
(beginning-of-line)
(delete-char 1)
(insert "*")
(put-text-property (- (point) 1) (point) 'face face))))
(defun eclim--project-remove-mark-current ()
(let ((inhibit-read-only t))
(save-excursion
(beginning-of-line)
(delete-char 1)
(insert " "))))
(defun eclim--project-get-marked ()
(interactive)
(let ((marked-projects '()))
(save-excursion
(beginning-of-buffer)
(while (re-search-forward "*" nil t)
(push (eclim--project-current-line) marked-projects)))
marked-projects))
(defun eclim--project-column-start (column)
(save-excursion
(+ (re-search-forward "|" nil t (- column 1)) 1)))
(defun eclim--project-column-end (column)
(save-excursion
(- (re-search-forward "|" nil t column) 1)))
(defun eclim--project-current-line ()
(save-excursion
(beginning-of-line)
(eclim--string-strip (buffer-substring-no-properties
(eclim--project-column-start 3)
(eclim--project-column-end 3)))))
(defun eclim/project-list ()
(eclim/execute-command "project_list"))
(defun eclim/project-import (folder)
(eclim--project-clear-cache)
(eclim--call-process "project_import" "-f" (expand-file-name folder)))
(defun eclim/project-create (folder natures name &optional target package application depends)
;; TODO: allow multiple natures
;; add the vars target,package,application for android project
(eclim--project-clear-cache)
(eclim--call-process "project_create" "-f" folder "-n" natures "-p" name "-a" "--target" target "--package" package "--application" application))
(defun eclim/project-delete (project)
(eclim--check-project project)
(eclim--project-clear-cache)
(eclim--call-process "project_delete" "-p" project))
(defun eclim/project-open (project)
(eclim--check-project project)
(eclim--call-process "project_open" "-p" project))
(defun eclim/project-close (project)
(eclim--check-project project)
(eclim--call-process "project_close" "-p" project))
(defun eclim/project-info (project)
(eclim--check-project project)
(eclim--call-process "project_info" "-p" project))
(defun eclim/project-settings (project)
(eclim--check-project project)
;; TODO: make the output useable
(eclim--call-process "project_settings" "-p" project))
(defun eclim/project-setting (project setting)
(eclim--check-project project)
;; TODO: make the output useable
(eclim--call-process "project_setting" "-p" project "-s" setting))
(defun eclim/project-nature-add (project nature)
(eclim--check-project project)
(eclim--check-nature nature)
(eclim--call-process "project_nature_add" "-p" project "-n" nature))
(defun eclim/project-nature-remove (project nature)
(eclim--check-project project)
(eclim--check-nature nature)
(eclim--call-process "project_nature_remove" "-p" project "-n" nature))
(defun eclim/project-natures (project)
(eclim--check-project project)
(eclim--call-process "project_natures" "-p" project))
(defun eclim/project-refresh (project)
(eclim--check-project project)
(eclim--call-process "project_refresh" "-p" project))
(defun eclim/project-refresh-file (project file)
(eclim--check-project project)
(eclim--call-process "project_refresh_file" "-p" project "-f" file))
(defun eclim/project-nature-aliases ()
(eclim--call-process "project_nature_aliases"))
(defun eclim/project-links (project)
(eclim--check-project project)
(eclim--call-process "project_links" "-p" project))
(defun eclim/project-rename (project new-name)
(eclim--check-project project)
(eclim--call-process "project_rename" "-p" project "-n" new-name))
(defun eclim/project-classpath (&optional delimiter)
"return project classpath for the current buffer."
(eclim/execute-command "java_classpath" "-p" ("-d" delimiter)))
(defun eclim-project-rename (project name)
(interactive (let ((project-name (eclim--project-read t)))
(list project-name (read-string (concat "Rename <" project-name "> To: ")))))
(message (eclim/project-rename project name))
(eclim--project-buffer-refresh))
(defun eclim-project-delete (projects)
(interactive (list (eclim--project-read)))
(when (not (listp projects)) (set 'projects (list projects)))
(dolist (project projects)
(when (yes-or-no-p (concat "Delete Project: <" project"> "))
(message (eclim/project-delete project))))
(eclim--project-buffer-refresh))
(defun eclim-project-create (name path nature)
(interactive (list (read-string "Name: ")
(expand-file-name (read-directory-name "Project Directory: "))
(eclim--project-nature-read)))
;;android project is need the vars target,package,application
(if (string-equal nature "android")
(progn (setq target (read-string "Target: "))
(setq package (read-string "Package: "))
(setq application (read-string "Application: "))
(message (eclim/project-create path nature name target package application)))
(message (eclim/project-create path nature name))
(eclim--project-buffer-refresh)))
(defun eclim-project-import (folder)
(interactive "DProject Directory: ")
(message (eclim/project-import folder))
(eclim--project-buffer-refresh))
(defun eclim--project-nature-read ()
(completing-read "Nature: " (append (eclim/project-nature-aliases) nil)))
(defun eclim-project-nature-add (nature)
(interactive (list (eclim--project-nature-read)))
(message (eclim/project-nature-add (eclim--project-current-line) nature)))
(defun eclim-project-nature-remove (nature)
(interactive (list (completing-read "Remove nature: "
(append
(cdadr (aref (eclim/project-natures (eclim--project-current-line)) 0))
nil))))
(message (eclim/project-nature-remove (eclim--project-current-line) nature)))
(defun eclim-project-natures ()
(interactive)
(message (with-output-to-string
(princ (cdadr (aref (eclim/project-natures (eclim--project-current-line)) 0))))))
(defun eclim-project-dependencies (project)
(cdr (assoc 'depends (eclim/project-info project))))
(defun eclim-project-mode-refresh ()
(interactive)
(eclim--project-buffer-refresh)
(message "projects refreshed..."))
(defun eclim-project-update (projects)
(interactive (list (eclim--project-read)))
(when (not (listp projects)) (set 'projects (list projects)))
(dolist (project projects)
(eclim/execute-command "project_update" ("-p" project)))
(eclim--project-buffer-refresh))
(defun eclim-project-open (projects)
(interactive (list (eclim--project-read)))
(when (not (listp projects)) (set 'projects (list projects)))
(dolist (project projects)
(eclim/project-open project))
(eclim--project-buffer-refresh))
(defun eclim-project-close (projects)
(interactive (list (eclim--project-read)))
(when (not (listp projects)) (set 'projects (list projects)))
(dolist (project projects)
(eclim/project-close project))
(eclim--project-buffer-refresh))
(defun eclim-project-refresh (projects)
(interactive (list (eclim--project-read)))
(when (not (listp projects)) (set 'projects (list projects)))
(dolist (project projects)
(eclim/project-refresh project))
(eclim--project-buffer-refresh))
(defun eclim-project-mark-current ()
(interactive)
(eclim--project-insert-mark-current 'dired-mark)
(forward-line 1))
(defun eclim-project-mark-all ()
(interactive)
(save-excursion
(beginning-of-buffer)
(loop do (eclim--project-insert-mark-current 'dired-mark)
until (not (forward-line 1)))))
(defun eclim-project-unmark-current ()
(interactive)
(eclim--project-remove-mark-current)
(forward-line 1))
(defun eclim-project-unmark-all ()
(interactive)
(save-excursion
(beginning-of-buffer)
(loop do (eclim--project-remove-mark-current)
until (not (forward-line 1)))))
(defun eclim-project-goto (project)
(interactive (list (eclim--project-read t)))
(ido-find-file-in-dir
(assoc-default 'path
(find project (eclim/project-list)
:key (lambda (e) (assoc-default 'name e))
:test #'string=))))
(defun eclim-project-info-mode (project)
"Display detailed information about an eclim-project.
\\{eclim-project-info-mode-map}"
(interactive (list (eclim--project-read t)))
(with-help-window "*eclim: info*"
(with-current-buffer "*eclim: info*"
(kill-all-local-variables)
(save-excursion
(loop for attr in (eclim/project-info project)
do (princ (format "%s: %s\n" (car attr) (cdr attr))))
(princ "\n\nSETTINGS:\n")
(loop for attr across (eclim/project-settings project)
do (princ (format "%s: %s\n" (assoc-default 'name attr) (assoc-default 'value attr))))
(use-local-map eclim-project-info-mode-map)
(setq major-mode 'eclim-project-info-mode
mode-name "eclim/project-info")
(put 'eclim-project-info-mode 'mode-class 'special)
(run-mode-hooks eclim-project-info-mode-hook)))))
(defun eclim-project-build ()
"Triggers a build of the current project"
(interactive)
(eclim/execute-command-async
(lambda (res) (message res))
"project_build" "-p"))
;;;###autoload
(defun eclim-project-mode ()
"Manage all your eclim projects in one buffer.
\\{eclim-project-mode-map}"
(interactive)
(switch-to-buffer (get-buffer-create "*eclim: projects*"))
(eclim--project-clear-cache)
(kill-all-local-variables)
(buffer-disable-undo)
(setq major-mode 'eclim-project-mode
mode-name "eclim/project"
mode-line-process ""
truncate-lines t
buffer-read-only t
default-directory (eclim/workspace-dir))
(setq-local line-move-visual nil)
(put 'eclim-project-mode 'mode-class 'special)
(hl-line-mode t)
(use-local-map eclim-project-mode-map)
(cd "~") ;; setting a defualt directoy avoids some problems with tramp
(eclim--project-buffer-refresh)
(beginning-of-buffer)
(run-mode-hooks 'eclim-project-mode-hook))
(defalias 'eclim-manage-projects 'eclim-project-mode)
(provide 'eclim-project)