New option `org-properties-postprocess-alist'.
[org-mode.git] / lisp / ob-java.el
blobeaebe0f46d3e30c8df76ebe5e4f4b837dbb9864b
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
8 ;; Version: 7.7
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/>.
25 ;;; Commentary:
27 ;; Currently this only supports the external compilation and execution
28 ;; of java code blocks (i.e., no session support).
30 ;;; Code:
31 (require 'ob)
32 (require 'ob-eval)
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))
45 (error
46 "Can't compile a java block without a classname")))
47 (packagename (file-name-directory classname))
48 (src-file (concat classname ".java"))
49 (cmpflag (or (cdr (assoc :cmpflag params)) ""))
50 (cmdline (or (cdr (assoc :cmdline params)) ""))
51 (full-body (org-babel-expand-body:generic body params))
52 (compile
53 (progn (with-temp-file src-file (insert full-body))
54 (org-babel-eval
55 (concat org-babel-java-compiler
56 " " cmpflag " " src-file) ""))))
57 ;; created package-name directories if missing
58 (unless (or (not packagename) (file-exists-p packagename))
59 (make-directory packagename 'parents))
60 ((lambda (results)
61 (org-babel-reassemble-table
62 (if (member "vector" (cdr (assoc :result-params params)))
63 (let ((tmp-file (org-babel-temp-file "c-")))
64 (with-temp-file tmp-file (insert results))
65 (org-babel-import-elisp-from-file tmp-file))
66 (org-babel-read results))
67 (org-babel-pick-name
68 (cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
69 (org-babel-pick-name
70 (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params)))))
71 (org-babel-eval (concat org-babel-java-command
72 " " cmdline " " classname) ""))))
74 (provide 'ob-java)
78 ;;; ob-java.el ends here