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 |
|
|
133 |
;; (maven-central.last-version "junit" "junit")
|
|
134 |
|
|
135 |
(provide 'maven-central)
|
|
136 |
|
|
137 |
(provide 'maven-central)
|
|
138 |
|
|
139 |
;;; maven-central.el ends here
|