2007-11-12

Maven + Emacs + JDEE = coding bliss

If you use Emacs/JDEE and Maven, you may want to look at my pom-parser.el, which lets you refer to information in your POM from your JDEE project files. The code is loosely based on Ole Arndt's work, but works with Maven 2. It delegates much of the work to Maven itself and the help and dependency plugins.

4 comments:

Brandon said...

This is great but i am having some issues and any help would be greatly appreciated!!
I have my prj.el defined as:
(jde-project-file-version "1.0")
(jde-set-variables
'(jde-compile-option-command-line-args
(quote ("-Xlint:all" "-Xlint:-serial"))))

(require 'pom-parser)
(with-pom ()
(pom-set-jde-variables pom))

but when i load a java file that has a pom i get the following:

Debugger entered--Lisp error: (error "No setf-method known for xml-node-attributes")
signal(error ("No setf-method known for xml-node-attributes"))
error("No setf-method known for %s" xml-node-attributes)
get-setf-method((xml-node-attributes pom) nil)
cl-setf-do-modify((xml-node-attributes pom) (list))
#[(func arg1 place &rest args) "SOME JUNK HERE" [arg1 place func args method temp cl-safe-expr-p cl-simple-expr-p setf cl-setf-do-modify list cl-const-expr-p make-symbol "--cl-arg1--" 2 let* append cl-setf-do-store funcall function rargs] 8 ("c:/development/emacs-22.1/lisp/emacs-lisp/cl-macs.elc" . 84781)](cons (cons (quote pom:classpath) classpath) (xml-node-attributes pom))
(callf2 cons (cons (quote pom:classpath) classpath) (xml-node-attributes pom))
(push (cons (quote pom:classpath) classpath) (xml-node-attributes pom))
(let ((classpath ...)) (push (cons ... classpath) (xml-node-attributes pom)))
(if (null pom) (error "Failed to parse effective POM; the contents of %s might help diagnose" temp-pom) (let (...) (push ... ...)) (puthash pom-file (cons pom-file-last-mod-time pom) *pom-cache*) (delete-file temp-pom) (delete-file temp-cpfile) pom)
(let ((pom ...)) (if (null pom) (error "Failed to parse effective POM; the contents of %s might help diagnose" temp-pom) (let ... ...) (puthash pom-file ... *pom-cache*) (delete-file temp-pom) (delete-file temp-cpfile) pom))
(if (> (let ... ...) 0) (progn (display-buffer *mvn-output-buffer* t) (error "%s call failed" pom-maven-command)) (let (...) (if ... ... ... ... ... ... pom)))
(let ((temp-pom ...) (temp-cpfile ...)) (with-current-buffer *mvn-output-buffer* (erase-buffer)) (if (> ... 0) (progn ... ...) (let ... ...)))
(if (and cached-pom-data (<= pom-file-last-mod-time ...)) (cdr cached-pom-data) (message "Calling %s help:effective-pom dependency:build-classpath..." pom-maven-command) (let (... ...) (with-current-buffer *mvn-output-buffer* ...) (if ... ... ...)))
(let* ((pom-file-last-mod-time ...) (cached-pom-data ...)) (if (and cached-pom-data ...) (cdr cached-pom-data) (message "Calling %s help:effective-pom dependency:build-classpath..." pom-maven-command) (let ... ... ...)))
(catch (quote --cl-block-pom-parse-pom--) (let* (... ...) (if ... ... ... ...)))
(cl-block-wrapper (catch (quote --cl-block-pom-parse-pom--) (let* ... ...)))
(block pom-parse-pom (let* (... ...) (if ... ... ... ...)))
(let* ((pom-file ...)) (if --cl-rest-- (signal ... ...)) (block pom-parse-pom (let* ... ...)))
pom-parse-pom("c:/development/workspace/accelerator7-services/business-services/pom.xml")
(let ((*pom-node* ...)) (pom-set-jde-variables pom))
(with-pom nil (pom-set-jde-variables pom))
eval-buffer(#buffer *load*<2>> nil "c:/development/workspace/accelerator7-services/business-services/prj.el" nil t) ; Reading at buffer position 204
load-with-code-conversion("c:/development/workspace/accelerator7-services/business-services/prj.el" "c:/development/workspace/accelerator7-services/business-services/prj.el" nil nil)
load("c:/development/workspace/accelerator7-services/business-services/prj.el" nil nil t)
load-file("c:/development/workspace/accelerator7-services/business-services/prj.el")
(while (consp --cl-var--) (setq file (car --cl-var--)) (setq jde-loading-project-file file) (jde-log-msg "jde-load-project-file: Loading %s" file) (setq jde-loaded-project-file-version nil) (load-file file) (setq jde-loading-project-file nil) (setq --cl-var-- (cdr --cl-var--)))
(let* ((--cl-var-- prj-files) (file nil)) (while (consp --cl-var--) (setq file ...) (setq jde-loading-project-file file) (jde-log-msg "jde-load-project-file: Loading %s" file) (setq jde-loaded-project-file-version nil) (load-file file) (setq jde-loading-project-file nil) (setq --cl-var-- ...)) nil)
(catch (quote --cl-block-nil--) (let* (... ...) (while ... ... ... ... ... ... ... ...) nil))
(cl-block-wrapper (catch (quote --cl-block-nil--) (let* ... ... nil)))
(block nil (let* (... ...) (while ... ... ... ... ... ... ... ...) nil))
(loop for file in prj-files do (setq jde-loading-project-file file) (jde-log-msg "jde-load-project-file: Loading %s" file) (setq jde-loaded-project-file-version nil) (load-file file) (setq jde-loading-project-file nil))
(progn (jde-set-variables-init-value) (loop for file in prj-files do (setq jde-loading-project-file file) (jde-log-msg "jde-load-project-file: Loading %s" file) (setq jde-loaded-project-file-version nil) (load-file file) (setq jde-loading-project-file nil)) (run-hooks (quote jde-project-hooks)))
(if prj-files (progn (jde-set-variables-init-value) (loop for file in prj-files do ... ... ... ... ...) (run-hooks ...)) (jde-set-variables-init-value t))
(let ((prj-files ...)) (if prj-files (progn ... ... ...) (jde-set-variables-init-value t)))
jde-load-project-file()
jde-update-autoloaded-symbols()
eval-buffer(#buffer *load*> nil "c:/Documents and Settings/Administrator/Application Data/.emacs.d/site/jde/lisp/jde-javadoc.el" nil t) ; Reading at buffer position 70452
load-with-code-conversion("c:/Documents and Settings/Administrator/Application Data/.emacs.d/site/jde/lisp/jde-javadoc.el" "c:/Documents and Settings/Administrator/Application Data/.emacs.d/site/jde/lisp/jde-javadoc.el" nil nil)
(jde-javadoc-enable-menu-p)

espenhw said...

I suspect the problem is one of Emacs version compatibility. Could you try the version found here:
http://svn.grumblesmurf.org/svn/pom-el/trunk/?

aaditya sood said...

Even with the latest file, the instructions at the top of the file seem to be incorrect to me.

The prj.el file should have:

(require 'pom-parser)
(with-pom ()
(pom-set-jde-variables *pom-node*))

rather than

(require 'pom-parser)
(with-pom ()
(pom-set-jde-variables pom))

since the macro with-pom uses *pom-node* for the let.

David said...

I've been trying to use pom-parser, and ran into a problem with classpath parsing. I found that I had an empty temp file when the goal: dependency:build-classpath was executed(pom-parse-pom).

I looked into the parameters and the documentation, http://maven.apache.org/plugins/maven-dependency-plugin/build-classpath-mojo.html#cpFile, indicates that this parameter, cpFile, is deprecated, and just doesn't work.

I tried the suggested replacement parameter, outputFile, and it also doesn't work. Seems like some with-out-to-temp-buffer parsing may be required, since it seems the documented parameters for writing the dependency classpath is broken.