Commit | Line | Data |
---|---|---|
3ab2c837 BG |
1 | ;;; ob-java.el --- org-babel functions for java evaluation |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2011-2014 Free Software Foundation, Inc. |
3ab2c837 BG |
4 | |
5 | ;; Author: Eric Schulte | |
6 | ;; Keywords: literate programming, reproducible research | |
7 | ;; Homepage: http://orgmode.org | |
3ab2c837 BG |
8 | |
9 | ;; This file is part of GNU Emacs. | |
10 | ||
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. | |
15 | ||
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. | |
20 | ||
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/>. | |
23 | ||
24 | ;;; Commentary: | |
25 | ||
26 | ;; Currently this only supports the external compilation and execution | |
27 | ;; of java code blocks (i.e., no session support). | |
28 | ||
29 | ;;; Code: | |
30 | (require 'ob) | |
3ab2c837 BG |
31 | |
32 | (defvar org-babel-tangle-lang-exts) | |
33 | (add-to-list 'org-babel-tangle-lang-exts '("java" . "java")) | |
34 | ||
35 | (defvar org-babel-java-command "java" | |
36 | "Name of the java command.") | |
37 | ||
38 | (defvar org-babel-java-compiler "javac" | |
39 | "Name of the java compiler.") | |
40 | ||
41 | (defun org-babel-execute:java (body params) | |
42 | (let* ((classname (or (cdr (assoc :classname params)) | |
43 | (error | |
44 | "Can't compile a java block without a classname"))) | |
45 | (packagename (file-name-directory classname)) | |
46 | (src-file (concat classname ".java")) | |
e66ba1df BG |
47 | (cmpflag (or (cdr (assoc :cmpflag params)) "")) |
48 | (cmdline (or (cdr (assoc :cmdline params)) "")) | |
3ab2c837 BG |
49 | (full-body (org-babel-expand-body:generic body params)) |
50 | (compile | |
51 | (progn (with-temp-file src-file (insert full-body)) | |
52 | (org-babel-eval | |
e66ba1df BG |
53 | (concat org-babel-java-compiler |
54 | " " cmpflag " " src-file) "")))) | |
3ab2c837 BG |
55 | ;; created package-name directories if missing |
56 | (unless (or (not packagename) (file-exists-p packagename)) | |
57 | (make-directory packagename 'parents)) | |
666ffc7e SM |
58 | (let ((results (org-babel-eval (concat org-babel-java-command |
59 | " " cmdline " " classname) ""))) | |
60 | (org-babel-reassemble-table | |
61 | (org-babel-result-cond (cdr (assoc :result-params params)) | |
62 | (org-babel-read results) | |
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-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))))))) | |
3ab2c837 BG |
70 | |
71 | (provide 'ob-java) | |
72 | ||
5b409b39 | 73 | |
3ab2c837 BG |
74 | |
75 | ;;; ob-java.el ends here |