-;;;###autoload
-(defun javaimp-maven-visit-root (path)
- "Loads all modules starting from root module identified by
-PATH. PATH should point to a directory."
- (interactive "DVisit maven root project: ")
- (let ((root-pom (expand-file-name
- (concat (file-name-as-directory path) "pom.xml")))
- modules existing-module)
- (unless (file-readable-p root-pom)
- (error "Cannot read root pom: %s" root-pom))
- (setq modules (javaimp-maven-load-module-tree root-pom))
- ;; if a root module with such path is already loaded, replace its
- ;; modules
- (setq existing-module (assoc root-pom javaimp-maven-root-modules))
- (if existing-module
- (setcdr existing-module modules)
- (push (cons root-pom modules) javaimp-maven-root-modules))
- (message "Loaded modules for %s" path)))
-
-(defun javaimp-get-projects (xml-tree)
- (cond ((assq 'projects xml-tree)
- (javaimp-xml-child-list (assq 'projects xml-tree) 'project))
- ((assq 'project xml-tree)
- (list (assq 'project xml-tree)))
- (t
- (error "Cannot find projects in mvn output"))))
-
-(defun javaimp-maven-load-module-tree (pom)
- "Returns an alist of all Maven modules in a hierarchy starting
-with POM"
- (message "Loading root pom %s..." pom)
- (javaimp-call-mvn
- pom "help:effective-pom"
- (lambda ()
- (let (xml-start-pos xml-end-pos)
- ;; find where we should start parsing XML
- (goto-char (point-min))
- (re-search-forward "<\\?xml\\|<projects?")
- (setq xml-start-pos (match-beginning 0))
- ;; determine the start tag
- (goto-char (point-min))
- (re-search-forward "<\\(projects?\\)")
- ;; find closing tag which is also the end of the region to parse
- (search-forward (concat "</" (match-string 1) ">"))
- (setq xml-end-pos (match-end 0))
- ;; parse
- (let ((artifact-pomfile-alist
- (javaimp-build-artifact-pomfile-alist (list pom)))
- (children (javaimp-get-projects
- (xml-parse-region xml-start-pos xml-end-pos))))
- (javaimp-maven-build-children children artifact-pomfile-alist))))))
-
-(defun javaimp-make-artifact-from-xml (node)
- (javaimp-make-artifact
- (javaimp-xml-first-child (javaimp-xml-child 'groupId node))
- (javaimp-xml-first-child (javaimp-xml-child 'artifactId node))
- (javaimp-xml-first-child (javaimp-xml-child 'version node))))
-
-(defun javaimp-get-pom-file-path-lax (artifact artifact-pomfile-alist)
- (assoc-default
- artifact artifact-pomfile-alist
- (lambda (tested target)
- (or (equal target tested)
- (equal (javaimp-artifact-artifact-id target)
- (javaimp-artifact-artifact-id tested))))))
-
-(defun javaimp-maven-build-children (projects artifact-pomfile-alist)
- (let (result)
- (dolist (proj projects result)
- (let* ((artifact (javaimp-make-artifact-from-xml proj))
- (pom-file-path (javaimp-get-pom-file-path-lax
- artifact artifact-pomfile-alist))
- (build (javaimp-xml-child 'build proj))
- (source-dir (javaimp-xml-first-child
- (javaimp-xml-child 'sourceDirectory build)))
- (test-source-dir (javaimp-xml-first-child
- (javaimp-xml-child 'testSourceDirectory
- build)))
- (build-dir (javaimp-xml-first-child
- (javaimp-xml-child 'directory build)))
- (parent (javaimp-make-artifact-from-xml
- (javaimp-xml-child 'parent proj))))
- (push (javaimp-make-mod
- artifact
- pom-file-path
- (file-name-as-directory
- (if (eq system-type 'cygwin)
- (car (process-lines javaimp-cygpath-program "-u"
- source-dir))
- source-dir))
- (file-name-as-directory
- (if (eq system-type 'cygwin)
- (car (process-lines javaimp-cygpath-program "-u"
- test-source-dir))
- test-source-dir))
- (file-name-as-directory
- (if (eq system-type 'cygwin)
- (car (process-lines javaimp-cygpath-program "-u"
- build-dir))
- build-dir))
- nil nil parent nil)
- result)))))
-
-(defun javaimp-build-artifact-pomfile-alist (pom-file-list)
- "Recursively builds an alist where each element is of the
-form (\"ARTIFACT\" . \"POM-FILE-PATH\"). This is needed because
-there is no pom file path in the output of `mvn
-help:effective-pom'. Each pom file path in POM-FILE-LIST should
-be in platform's default format."
- (when pom-file-list
- (let ((pom-file (car pom-file-list))
- xml-tree project)
- (message "Saving artifact id -> pom file mapping for %s" pom-file)
- (with-temp-buffer
- (insert-file-contents pom-file)
- (setq xml-tree (xml-parse-region (point-min) (point-max))))
- (setq project (if (assq 'top xml-tree)
- (assq 'project (cddr (assq 'top xml-tree)))
- (assq 'project xml-tree)))
- (cons
- ;; this pom
- (cons (javaimp-make-artifact-from-xml project) pom-file)
- (append
- ;; submodules
- (javaimp-build-artifact-pomfile-alist
- (mapcar (lambda (submodule)
- (expand-file-name
- (concat
- ;; this pom's path
- (file-name-directory pom-file)
- ;; relative submodule directory
- (file-name-as-directory
- (let ((submodule-path (car (cddr submodule))))
- (if (eq system-type 'cygwin)
- (car (process-lines javaimp-cygpath-program "-u"
- submodule-path))
- submodule-path)))
- ;; well-known file name
- "pom.xml")))
- (javaimp-xml-child-list (assq 'modules (cddr project)) 'module)))
- ;; rest items
- (javaimp-build-artifact-pomfile-alist (cdr pom-file-list)))))))
-
-(defun javaimp-call-mvn (pom-file target handler)