author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Mon, 10 Mar 2014 22:14:13 +0200 | |
changeset 1118 | ece4746ba12e |
parent 1109 | 09d967bff50f |
child 1143 | a7fb97ff9cb6 |
permissions | -rw-r--r-- |
1082 | 1 |
;;; maven-central.el --- Maven central auxility |
2 |
||
3 |
;;; Commentary: |
|
4 |
;; |
|
5 |
||
1091 | 6 |
(require 'json) |
1082 | 7 |
(require 'url-handlers) |
8 |
||
9 |
;;; Code: |
|
10 |
||
11 |
(defvar maven-central.buffer-name "*Maven Central*") |
|
12 |
||
13 |
(defconst maven-central.search-url "http://search.maven.org/solrsearch/select?wt=json&rows=20") |
|
14 |
||
15 |
(defun maven-central.callback1 (status) |
|
16 |
(let ( (buffer (current-buffer)) ) |
|
17 |
(switch-to-buffer maven-central.buffer-name) |
|
18 |
(url-insert buffer))) |
|
19 |
||
20 |
(defun maven-central.versions-url (groupId artifactId) |
|
21 |
(concat maven-central.search-url "&core=gav&q=g:" (url-hexify-string groupId) (url-hexify-string " AND ") "a:" (url-hexify-string artifactId))) |
|
22 |
;; (maven-central.versions-url "junit" "junit") |
|
23 |
||
24 |
(defun maven-central.versions-callback (status) |
|
25 |
(let ( (buffer (current-buffer)) json ) |
|
26 |
(with-temp-buffer |
|
27 |
(url-insert buffer) |
|
28 |
(beginning-of-buffer) |
|
29 |
(setq json (json-read)) |
|
30 |
;; (switch-to-buffer maven-central.buffer-name) |
|
31 |
;; (pp json) |
|
32 |
(message "Available versions: %s" (mapconcat (lambda (json) (cdr (assq 'v json))) (cdr (assq 'docs (cdr (assoc 'response json)))) ", ")) |
|
33 |
))) |
|
34 |
||
35 |
(defun maven-central.versions (groupId artifactId) |
|
36 |
"Retrieve available versions." |
|
37 |
(url-retrieve (maven-central.versions-url groupId artifactId) #'maven-central.versions-callback)) |
|
38 |
||
39 |
(defun maven-central.last-version-url (groupId artifactId) |
|
40 |
(concat maven-central.search-url "&q=g:" (url-hexify-string groupId) (url-hexify-string " AND ") "a:" (url-hexify-string artifactId))) |
|
41 |
;; (maven-central.versions-url "junit" "junit") |
|
42 |
||
43 |
(defun maven-central.last-version-callback (status) |
|
44 |
(let ( (buffer (current-buffer)) json ) |
|
45 |
(with-temp-buffer |
|
46 |
(url-insert buffer) |
|
47 |
(beginning-of-buffer) |
|
48 |
(setq json (json-read)) |
|
49 |
;; (switch-to-buffer maven-central.buffer-name) |
|
50 |
;; (pp json) |
|
51 |
(message "Latest version: %s" (cdr (assq 'latestVersion (elt (cdr (assq 'docs (cdr (assoc 'response json)))) 0)))) |
|
52 |
))) |
|
53 |
||
54 |
(defun maven-central.last-version (groupId artifactId) |
|
55 |
"Retrieve last package version." |
|
56 |
(url-retrieve (maven-central.last-version-url groupId artifactId) #'maven-central.last-version-callback)) |
|
57 |
||
58 |
(defun maven-central.parse-pom-dependency-in-region (start end) |
|
59 |
(let (groupId artifactId version) |
|
60 |
(save-restriction |
|
61 |
(narrow-to-region start end) |
|
62 |
(goto-char start) |
|
63 |
(re-search-forward "<groupId>\\([^<]*\\)</groupId>" nil t) |
|
64 |
(setq groupId (match-string-no-properties 1)) |
|
65 |
(goto-char start) |
|
66 |
(re-search-forward "<artifactId>\\([^<]*\\)</artifactId>" nil t) |
|
67 |
(setq artifactId (match-string-no-properties 1)) |
|
68 |
(goto-char start) |
|
69 |
(re-search-forward "<version>\\([^<]*\\)</version>" nil t) |
|
70 |
(setq version (match-string-no-properties 1)) |
|
71 |
(list groupId artifactId version) |
|
72 |
))) |
|
73 |
||
74 |
(defun maven-central.parse-pom-dependency (&optional point) |
|
75 |
(unless point |
|
76 |
(setq point (point))) |
|
77 |
(let (start end pos groupId artifactId version fs-o bs-o fs-c bs-c) |
|
78 |
(save-excursion |
|
79 |
(goto-char point) |
|
80 |
(unless (eq (char-after) ?<) |
|
81 |
(search-backward "<")) |
|
82 |
(setq point (point)) |
|
83 |
(setq fs-o (re-search-forward "<\\(?:plugin\\|dependency\\)>" nil t)) |
|
84 |
(when fs-o |
|
85 |
(setq fs-o (- fs-o 12))) |
|
86 |
(goto-char point) |
|
87 |
(setq bs-o (re-search-backward "<\\(?:plugin\\|dependency\\)>" nil t)) |
|
88 |
(goto-char point) |
|
89 |
(setq fs-c (re-search-forward "</\\(?:plugin\\|dependency\\)>" nil t)) |
|
90 |
(goto-char point) |
|
91 |
(setq bs-c (re-search-backward "</\\(?:plugin\\|dependency\\)>" nil t)) |
|
92 |
(when bs-c |
|
93 |
(setq bs-c (+ bs-c 13))) |
|
94 |
(cond |
|
95 |
((and fs-o (= fs-o point) fs-c) |
|
96 |
(maven-central.parse-pom-dependency-in-region fs-o fs-c)) |
|
97 |
((and bs-o (<= bs-o point) fs-c (<= point fs-c)) |
|
98 |
(maven-central.parse-pom-dependency-in-region bs-o fs-c)) |
|
99 |
((and fs-o fs-c) |
|
100 |
(maven-central.parse-pom-dependency-in-region fs-o fs-c)) |
|
101 |
((and bs-o bs-c) |
|
102 |
(maven-central.parse-pom-dependency-in-region bs-o bs-c)) |
|
103 |
(t |
|
104 |
(list nil nil nil))) |
|
105 |
))) |
|
106 |
||
107 |
(defun maven-central.parse-test (&optional point) |
|
108 |
(interactive) |
|
109 |
(pp (maven-central.parse-pom-dependency)) ) |
|
110 |
||
111 |
;;;###autoload |
|
112 |
(defun maven-central.last-version-from-pom () |
|
113 |
(interactive) |
|
114 |
(let (dependency groupId artifactId) |
|
115 |
(setq dependency (maven-central.parse-pom-dependency)) |
|
116 |
(setq groupId (elt dependency 0)) |
|
117 |
(setq artifactId (elt dependency 1)) |
|
118 |
(when (and groupId artifactId) |
|
119 |
(maven-central.last-version groupId artifactId)) |
|
120 |
)) |
|
121 |
||
122 |
;;;###autoload |
|
123 |
(defun maven-central.versions-from-pom () |
|
124 |
(interactive) |
|
125 |
(let (dependency groupId artifactId) |
|
126 |
(setq dependency (maven-central.parse-pom-dependency)) |
|
127 |
(setq groupId (elt dependency 0)) |
|
128 |
(setq artifactId (elt dependency 1)) |
|
129 |
(when (and groupId artifactId) |
|
130 |
(maven-central.versions groupId artifactId)) |
|
131 |
)) |
|
132 |
||
1108
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
133 |
(defvar maven.command "mvn") |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
134 |
|
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
135 |
(defvar maven.help-buffer-name "*Maven Help*") |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
136 |
|
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
137 |
(defun maven.help () |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
138 |
"Run help:describe for plugin at point." |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
139 |
(interactive) |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
140 |
(let (dependency groupId artifactId) |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
141 |
(setq dependency (maven-central.parse-pom-dependency)) |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
142 |
(setq groupId (elt dependency 0)) |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
143 |
(setq artifactId (elt dependency 1)) |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
144 |
(if (not (and groupId artifactId)) |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
145 |
(message "Can't find `groupId' or `artifactId'") |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
146 |
(shell-command |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
147 |
(format "%s help:describe -DgroupId=%s -DartifactId=%s" maven.command groupId artifactId) |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
148 |
(switch-to-buffer maven.help-buffer-name)) ) |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
149 |
)) |
8e730890ac85
maven.help - Run help:describe for plugin at point.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1091
diff
changeset
|
150 |
|
1109
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
151 |
(defun maven.effective-pom () |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
152 |
"Run help:effective-pom for plugin at point." |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
153 |
(interactive) |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
154 |
(shell-command |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
155 |
(format "%s help:effective-pom" maven.command) |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
156 |
(switch-to-buffer maven.help-buffer-name)) ) |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
157 |
|
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
158 |
(defun maven.effective-pom () |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
159 |
"Run help:effective-settings for plugin at point." |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
160 |
(interactive) |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
161 |
(shell-command |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
162 |
(format "%s help:effective-settings" maven.command) |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
163 |
(switch-to-buffer maven.help-buffer-name)) ) |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
164 |
|
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
165 |
(defun maven.dependency-tree () |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
166 |
"Run dependency:tree for plugin at point." |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
167 |
(interactive) |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
168 |
(shell-command |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
169 |
(format "%s dependency:tree" maven.command) |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
170 |
(switch-to-buffer maven.help-buffer-name)) ) |
09d967bff50f
help:effective-pom help:effective-settings dependency:tree
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1108
diff
changeset
|
171 |
|
1082 | 172 |
;; (maven-central.last-version "junit" "junit") |
173 |
||
174 |
(provide 'maven-central) |
|
175 |
||
176 |
(provide 'maven-central) |
|
177 |
||
178 |
;;; maven-central.el ends here |