;;; ob-java.el --- org-babel functions for java evaluation -*- lexical-binding: t -*- ;; Copyright (C) 2011-2020 Free Software Foundation, Inc. ;; Authors: Eric Schulte ;; Dan Davison ;; Maintainer: Ian Martins ;; Keywords: literate programming, reproducible research ;; Homepage: https://orgmode.org ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; Org-Babel support for evaluating java source code. ;;; Code: (require 'ob) (defvar org-babel-tangle-lang-exts) (add-to-list 'org-babel-tangle-lang-exts '("java" . "java")) (defvar org-babel-temporary-directory) ; from ob-core (defvar org-babel-default-header-args:java '() "Default header args for java source blocks.") (defconst org-babel-header-args:java '((imports . :any)) "Java-specific header arguments.") (defcustom org-babel-java-command "java" "Name of the java command. May be either a command in the path, like java or an absolute path name, like /usr/local/bin/java. Parameters may be used, like java -verbose." :group 'org-babel :package-version '(Org . "9.5") :type 'string) (defcustom org-babel-java-compiler "javac" "Name of the java compiler. May be either a command in the path, like javac or an absolute path name, like /usr/local/bin/javac. Parameters may be used, like javac -verbose." :group 'org-babel :package-version '(Org . "9.5") :type 'string) (defcustom org-babel-java-hline-to "null" "Replace hlines in incoming tables with this when translating to java." :group 'org-babel :package-version '(Org . "9.5") :type 'string) (defcustom org-babel-java-null-to 'hline "Replace `null' in java tables with this before returning." :group 'org-babel :package-version '(Org . "9.5") :type 'symbol) (defconst org-babel-java--package-re "^[[:space:]]*package[[:space:]]+\\\([[:alnum:]_\.]+\\\);$" "Regexp for the package statement.") (defconst org-babel-java--imports-re "^[[:space:]]*import[[:space:]]+\\\([[:alnum:]_\.]+\\\);$" "Regexp for import statements.") (defconst org-babel-java--class-re "^[[:space:]]*\\\(?:public[[:space:]]+\\\)?class[[:space:]]+\\\([[:alnum:]_]+\\\)[[:space:]]*\n?[[:space:]]*{" "Regexp for the class declaration.") (defconst org-babel-java--main-re "public static void main(String\\\(?:\\[]\\\)?[[:space:]]+[^ ]+\\\(?:\\[]\\\)?).*\n?[[:space:]]*{" "Regexp for the main method declaration.") (defconst org-babel-java--any-method-re "public .*(.*).*\n?[[:space:]]*{" "Regexp for any method.") (defconst org-babel-java--result-wrapper "\n public static String __toString(Object val) { if (val instanceof String) { return \"\\\"\" + val + \"\\\"\"; } else if (val == null) { return \"null\"; } else if (val.getClass().isArray()) { StringBuffer sb = new StringBuffer(); Object[] vals = (Object[])val; sb.append(\"[\"); for (int ii=0; ii