ob-java.el 2.7 KB

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