ob-java.el 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ;;; ob-java.el --- org-babel functions for java evaluation
  2. ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Currently this only supports the external compilation and execution
  19. ;; of java code blocks (i.e., no session support).
  20. ;;; Code:
  21. (require 'ob)
  22. (require 'ob-eval)
  23. (defvar org-babel-tangle-lang-exts)
  24. (add-to-list 'org-babel-tangle-lang-exts '("java" . "java"))
  25. (defvar org-babel-java-command "java"
  26. "Name of the java command.")
  27. (defvar org-babel-java-compiler "javac"
  28. "Name of the java compiler.")
  29. (defun org-babel-execute:java (body params)
  30. (let* ((classname (or (cdr (assoc :classname params))
  31. (error
  32. "Can't compile a java block without a classname")))
  33. (packagename (file-name-directory classname))
  34. (src-file (concat classname ".java"))
  35. (cmpflag (or (cdr (assoc :cmpflag params)) ""))
  36. (cmdline (or (cdr (assoc :cmdline params)) ""))
  37. (full-body (org-babel-expand-body:generic body params))
  38. (compile
  39. (progn (with-temp-file src-file (insert full-body))
  40. (org-babel-eval
  41. (concat org-babel-java-compiler
  42. " " cmpflag " " src-file) ""))))
  43. ;; created package-name directories if missing
  44. (unless (or (not packagename) (file-exists-p packagename))
  45. (make-directory packagename 'parents))
  46. ((lambda (results)
  47. (org-babel-reassemble-table
  48. (if (member "vector" (cdr (assoc :result-params params)))
  49. (let ((tmp-file (org-babel-temp-file "c-")))
  50. (with-temp-file tmp-file (insert results))
  51. (org-babel-import-elisp-from-file tmp-file))
  52. (org-babel-read results))
  53. (org-babel-pick-name
  54. (cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
  55. (org-babel-pick-name
  56. (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params)))))
  57. (org-babel-eval (concat org-babel-java-command
  58. " " cmdline " " classname) ""))))
  59. (provide 'ob-java)
  60. ;;; ob-java.el ends here