maven-central.el
changeset 1508 fad1a57bf25f
parent 1302 82d6e8bd0861
child 1509 f9b34ef28954
--- a/maven-central.el	Sat Mar 25 02:06:03 2017 +0300
+++ b/maven-central.el	Sat Mar 25 02:12:56 2017 +0300
@@ -5,6 +5,7 @@
 
 (require 'json)
 (require 'url-handlers)
+(require 'maven)
 
 ;;; Code:
 
@@ -50,61 +51,11 @@
   "Retrieve last package version."
   (url-retrieve (maven-central.last-version-url groupId artifactId) #'maven-central.last-version-callback))
 
-(defun maven-central.parse-pom-dependency-in-region (start end)
-  (let (groupId artifactId version)
-    (save-restriction
-      (narrow-to-region start end)
-      (goto-char start)
-      (re-search-forward "<groupId>\\([^<]*\\)</groupId>" nil t)
-      (setq groupId (match-string-no-properties 1))
-      (goto-char start)
-      (re-search-forward "<artifactId>\\([^<]*\\)</artifactId>" nil t)
-      (setq artifactId (match-string-no-properties 1))
-      (goto-char start)
-      (re-search-forward "<version>\\([^<]*\\)</version>" nil t)
-      (setq version (match-string-no-properties 1))
-      (list groupId artifactId version)
-      )))
-
-(defun maven-central.parse-pom-dependency (&optional point)
-  (unless point
-    (setq point (point)))
-  (let (start end pos groupId artifactId version fs-o bs-o fs-c bs-c)
-    (save-excursion
-      (goto-char point)
-      (unless (eq (char-after) ?<)
-        (search-backward "<"))
-      (setq point (point))
-      (setq fs-o (re-search-forward "<\\(?:plugin\\|dependency\\)>" nil t))
-      (when fs-o
-        (setq fs-o (- fs-o 12)))
-      (goto-char point)
-      (setq bs-o (re-search-backward "<\\(?:plugin\\|dependency\\)>" nil t))
-      (goto-char point)
-      (setq fs-c (re-search-forward "</\\(?:plugin\\|dependency\\)>" nil t))
-      (goto-char point)
-      (setq bs-c (re-search-backward "</\\(?:plugin\\|dependency\\)>" nil t))
-      (when bs-c
-        (setq bs-c (+ bs-c 13)))
-      (cond
-       ((and fs-o (= fs-o point) fs-c)
-        (maven-central.parse-pom-dependency-in-region fs-o fs-c))
-       ((and bs-o (<= bs-o point) fs-c (<= point fs-c))
-        (maven-central.parse-pom-dependency-in-region bs-o fs-c))
-       ((and fs-o fs-c)
-        (maven-central.parse-pom-dependency-in-region fs-o fs-c))
-       ((and bs-o bs-c)
-        (maven-central.parse-pom-dependency-in-region bs-o bs-c))
-       (t
-        (list nil nil nil)))
-      )))
-;; (pp (maven-central.parse-pom-dependency))
-
 ;;;###autoload
 (defun maven-central.last-version-from-pom ()
   (interactive)
   (let (dependency groupId artifactId)
-    (setq dependency (maven-central.parse-pom-dependency))
+    (setq dependency (maven.parse-pom-dependency))
     (setq groupId (elt dependency 0))
     (setq artifactId (elt dependency 1))
     (when (and groupId artifactId)
@@ -115,97 +66,13 @@
 (defun maven-central.versions-from-pom ()
   (interactive)
   (let (dependency groupId artifactId)
-    (setq dependency (maven-central.parse-pom-dependency))
+    (setq dependency (maven.parse-pom-dependency))
     (setq groupId (elt dependency 0))
     (setq artifactId (elt dependency 1))
     (when (and groupId artifactId)
       (maven-central.versions groupId artifactId))
     ))
 
-(defvar maven.command "mvn")
-
-(defvar maven.help-buffer-name "*Maven Help*")
-
-;;;###autoload
-(defun maven.help ()
-  "Run help:describe for plugin at point."
-  (interactive)
-  (let (dependency groupId artifactId)
-    (setq dependency (maven-central.parse-pom-dependency))
-    (setq groupId (elt dependency 0))
-    (setq artifactId (elt dependency 1))
-    (if (not (and groupId artifactId))
-        (message "Can't find `groupId' or `artifactId'")
-      (shell-command
-       (format "%s help:describe -Ddetail -DgroupId=%s -DartifactId=%s" maven.command groupId artifactId)
-       (switch-to-buffer maven.help-buffer-name)) )
-    ))
-
-;;;###autoload
-(defun maven.effective-pom ()
-  "Run help:effective-pom for plugin at point."
-  (interactive)
-  (shell-command
-   (format "%s help:effective-pom" maven.command)
-   (switch-to-buffer maven.help-buffer-name)) )
-
-;;;###autoload
-(defun maven.effective-settings ()
-  "Run help:effective-settings for plugin at point."
-  (interactive)
-  (shell-command
-   (format "%s help:effective-settings" maven.command)
-   (switch-to-buffer maven.help-buffer-name)) )
-
-;;;###autoload
-(defun maven.dependency-tree ()
-  "Run dependency:tree for plugin at point."
-  (interactive)
-  (shell-command
-   (format "%s dependency:tree" maven.command)
-   (switch-to-buffer maven.help-buffer-name)) )
-
-(defun maven.project-root ()
-  "Root of project."
-  (let ( (dir default-directory) (found nil) )
-    (while (and (not found) (> (length dir) 5))
-      (when (file-exists-p (concat dir "/pom.xml"))
-        (setq found dir))
-      (setq dir (expand-file-name (concat dir "/.."))))
-    found))
-
-(defun maven.file-package ()
-  "Return file package."
-  (save-excursion
-    (goto-char (point-min))
-    (let (pkg cls)
-      (re-search-forward "package +\\([[:alnum:]_.]+\\) *;" nil t)
-      (setq pkg (match-string-no-properties 1))
-      (re-search-forward "class\\s +\\([[:alnum:]_]+\\)\\(\\s \\|\n\\|implements [^{]*\\|extents [^{]*\\)*{" nil t)
-      (setq cls (match-string-no-properties 1))
-      (when (and pkg cls)
-        (concat pkg "." cls))) ))
-
-;;;###autoload
-(defun maven.run-file ()
-  "Run exec:java for current file."
-  (interactive)
-  (let* ( (default-directory (concat (maven.project-root) "/")) )
-    (if (not default-directory)
-        (message "Can't find maven project root")
-      (compilation-start
-       (format "%s exec:java -Dexec.mainClass=%s" maven.command (maven.file-package))))))
-
-;;;###autoload
-(defun maven.run-test ()
-  "Run test -Dtest=... for current file."
-  (interactive)
-  (let* ( (default-directory (concat (maven.project-root) "/")) )
-    (if (not default-directory)
-        (message "Can't find maven project root")
-      (compilation-start
-       (format "%s test -Dtest=%s" maven.command (maven.file-package))))))
-
 ;; (maven-central.last-version "junit" "junit")
 
 (provide 'maven-central)