-(defun javaimp--maven-xml-load-tree (file)
- "Invokes `mvn help:effective-pom' on FILE and using its output
-creates a tree of Maven projects starting from FILE. Children
-which link to the parent via the <parent> element are inheriting
-children and are also included. Subordinate modules with no
-inheritance are not included."
- (let ((xml-tree (javaimp--maven-xml-read-effective-pom file)))
- (cond ((assq 'project xml-tree)
- (let ((project-elt (assq 'project xml-tree))
- (submodules (javaimp--xml-children
- (javaimp--xml-child 'modules project-elt) 'module)))
- (and submodules
- ;; no real children
- (message "Independent submodules: %s"
- (mapconcat #'javaimp--xml-first-child submodules ", ")))
- (let ((module (javaimp--maven-xml-parse-module project-elt)))
- (javaimp--maven-build-tree
- (javaimp-module-id module) nil (list module) file))))
- ((assq 'projects xml-tree)
- ;; we have are inheriting children - they and their children, if
- ;; any, are listed in a linear list
- (let* ((project-elts (javaimp--xml-children
- (assq 'projects xml-tree) 'project))
- (all-modules (mapcar #'javaimp--maven-xml-parse-module project-elts)))
- (message "Total modules: %d" (length all-modules))
- (javaimp--maven-build-tree
- (javaimp-module-id (car all-modules)) nil all-modules file)))
+(defun javaimp--maven-xml-effective-pom-handler ()
+ (let ((start
+ (save-excursion
+ (progn
+ (goto-char (point-min))
+ (re-search-forward "<\\?xml\\|<projects?")
+ (match-beginning 0))))
+ (end
+ (save-excursion
+ (progn
+ (goto-char (point-min))
+ (re-search-forward "<\\(projects?\\)")
+ ;; corresponding close tag is the end of parse region
+ (search-forward (concat "</" (match-string 1) ">"))
+ (match-end 0)))))
+ (xml-parse-region start end)))
+
+(defun javaimp--maven-xml-extract-projects (xml-tree)
+ "Analyzes result of `mvn help:effective-pom' and returns list
+of <project> elements"
+ (let ((project (assq 'project xml-tree))
+ (projects (assq 'projects xml-tree)))
+ (cond (project
+ (list project))
+ (projects
+ (javaimp--xml-children projects 'project))