--- a/maven-central.el Sun Jul 20 01:29:22 2014 +0300
+++ b/maven-central.el Tue Jul 22 00:37:47 2014 +0300
@@ -169,6 +169,45 @@
(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 +\\([[:alnum:]_]+\\)\s *" nil t)
+ (setq cls (match-string-no-properties 1))
+ (when (and pkg cls)
+ (concat pkg "." cls))) ))
+
+(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))))))
+
+(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)