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