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