author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Sat, 25 Mar 2017 02:12:56 +0300 | |
changeset 1508 | fad1a57bf25f |
parent 1302 | 82d6e8bd0861 |
child 1509 | f9b34ef28954 |
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) |
1508
fad1a57bf25f
Move maven handling logic from maven-central.el to separate file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1302
diff
changeset
|
8 |
(require 'maven) |
1082 | 9 |
|
10 |
;;; Code: |
|
11 |
||
12 |
(defvar maven-central.buffer-name "*Maven Central*") |
|
13 |
||
14 |
(defconst maven-central.search-url "http://search.maven.org/solrsearch/select?wt=json&rows=20") |
|
15 |
||
16 |
(defun maven-central.versions-url (groupId artifactId) |
|
17 |
(concat maven-central.search-url "&core=gav&q=g:" (url-hexify-string groupId) (url-hexify-string " AND ") "a:" (url-hexify-string artifactId))) |
|
18 |
;; (maven-central.versions-url "junit" "junit") |
|
19 |
||
20 |
(defun maven-central.versions-callback (status) |
|
21 |
(let ( (buffer (current-buffer)) json ) |
|
22 |
(with-temp-buffer |
|
23 |
(url-insert buffer) |
|
1245
545d1e17bfe3
Fix: Warning: `beginning-of-buffer' is for interactive use only; use `(goto-char (point-min))' instead.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1244
diff
changeset
|
24 |
(goto-char (point-min)) |
1082 | 25 |
(setq json (json-read)) |
26 |
;; (switch-to-buffer maven-central.buffer-name) |
|
27 |
;; (pp json) |
|
28 |
(message "Available versions: %s" (mapconcat (lambda (json) (cdr (assq 'v json))) (cdr (assq 'docs (cdr (assoc 'response json)))) ", ")) |
|
29 |
))) |
|
30 |
||
31 |
(defun maven-central.versions (groupId artifactId) |
|
32 |
"Retrieve available versions." |
|
33 |
(url-retrieve (maven-central.versions-url groupId artifactId) #'maven-central.versions-callback)) |
|
34 |
||
35 |
(defun maven-central.last-version-url (groupId artifactId) |
|
36 |
(concat maven-central.search-url "&q=g:" (url-hexify-string groupId) (url-hexify-string " AND ") "a:" (url-hexify-string artifactId))) |
|
37 |
;; (maven-central.versions-url "junit" "junit") |
|
38 |
||
39 |
(defun maven-central.last-version-callback (status) |
|
40 |
(let ( (buffer (current-buffer)) json ) |
|
41 |
(with-temp-buffer |
|
42 |
(url-insert buffer) |
|
1245
545d1e17bfe3
Fix: Warning: `beginning-of-buffer' is for interactive use only; use `(goto-char (point-min))' instead.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1244
diff
changeset
|
43 |
(goto-char (point-min)) |
1082 | 44 |
(setq json (json-read)) |
45 |
;; (switch-to-buffer maven-central.buffer-name) |
|
46 |
;; (pp json) |
|
47 |
(message "Latest version: %s" (cdr (assq 'latestVersion (elt (cdr (assq 'docs (cdr (assoc 'response json)))) 0)))) |
|
48 |
))) |
|
49 |
||
50 |
(defun maven-central.last-version (groupId artifactId) |
|
51 |
"Retrieve last package version." |
|
52 |
(url-retrieve (maven-central.last-version-url groupId artifactId) #'maven-central.last-version-callback)) |
|
53 |
||
1151
350534cdf7be
Add missing autoloads.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1145
diff
changeset
|
54 |
;;;###autoload |
1082 | 55 |
(defun maven-central.last-version-from-pom () |
56 |
(interactive) |
|
57 |
(let (dependency groupId artifactId) |
|
1508
fad1a57bf25f
Move maven handling logic from maven-central.el to separate file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1302
diff
changeset
|
58 |
(setq dependency (maven.parse-pom-dependency)) |
1082 | 59 |
(setq groupId (elt dependency 0)) |
60 |
(setq artifactId (elt dependency 1)) |
|
61 |
(when (and groupId artifactId) |
|
62 |
(maven-central.last-version groupId artifactId)) |
|
63 |
)) |
|
64 |
||
1151
350534cdf7be
Add missing autoloads.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1145
diff
changeset
|
65 |
;;;###autoload |
1082 | 66 |
(defun maven-central.versions-from-pom () |
67 |
(interactive) |
|
68 |
(let (dependency groupId artifactId) |
|
1508
fad1a57bf25f
Move maven handling logic from maven-central.el to separate file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1302
diff
changeset
|
69 |
(setq dependency (maven.parse-pom-dependency)) |
1082 | 70 |
(setq groupId (elt dependency 0)) |
71 |
(setq artifactId (elt dependency 1)) |
|
72 |
(when (and groupId artifactId) |
|
73 |
(maven-central.versions groupId artifactId)) |
|
74 |
)) |
|
75 |
||
76 |
;; (maven-central.last-version "junit" "junit") |
|
77 |
||
78 |
(provide 'maven-central) |
|
79 |
||
80 |
(provide 'maven-central) |
|
81 |
||
82 |
;;; maven-central.el ends here |