// Path: java/src/org/drupal/project/computing/exception/DSiteException.java
// public class DSiteException extends Exception {
//     public DSiteException() {
//         super();
//     }
// 
//     public DSiteException(String s) {
//         super(s);
//     }
// 
//     public DSiteException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DSiteException(Throwable throwable) {
//         super(throwable);
//     }
// 
//     /**
//      * The error code is arbitrary by the caller which sets it.
//      */
//     private int errorCode = 0;
// 
//     public int getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(int errorCode) {
//         this.errorCode = errorCode;
//     }
// 
// }
// 
// Path: java/src/org/drupal/project/computing/exception/DSystemExecutionException.java
// public class DSystemExecutionException extends Exception {
//     public DSystemExecutionException() {
//     }
// 
//     public DSystemExecutionException(String s) {
//         super(s);
//     }
// 
//     public DSystemExecutionException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DSystemExecutionException(Throwable throwable) {
//         super(throwable);
//     }
// }


import org.apache.commons.exec.CommandLine;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.drupal.project.computing.exception.DSiteException;
import org.drupal.project.computing.exception.DSystemExecutionException;
import javax.script.Bindings;
import javax.script.SimpleBindings;
import java.util.logging.Logger;
     * @return execution results in JSON.
     * @throws DSiteException
     */
    public String computingEval(String phpCode) throws DSiteException {
        String result;
        try {
            result = execute(new String[] {"computing-eval", "--pipe", "-"}, phpCode);
        } catch (Exception e) {
            logger.severe("Error executing PHP code through computing-eval: " + phpCode);
            throw new DSiteException("Cannot execute computing-eval.", e);
        }
        return result;
    }


    /**
     * Call any Drupal functions and returns results in json.
     *
     * @param params First param is the function name; the rest are parameters in json.
     *   Callers are responsible to wrap the params in json, but not responsible to escape them as command line args.
     * @return Execution results in JSON.
     * @throws DSiteException
     */
    public String computingCall(String[] params) throws DSiteException {
        String result;
        try {
            String[] args = {"computing-call", "--pipe"};
            args = ArrayUtils.addAll(args, params);
            result = execute(args);
        } catch (Exception e) {
// Path: java/src/org/drupal/project/computing/exception/DSiteException.java
// public class DSiteException extends Exception {
//     public DSiteException() {
//         super();
//     }
// 
//     public DSiteException(String s) {
//         super(s);
//     }
// 
//     public DSiteException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DSiteException(Throwable throwable) {
//         super(throwable);
//     }
// 
//     /**
//      * The error code is arbitrary by the caller which sets it.
//      */
//     private int errorCode = 0;
// 
//     public int getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(int errorCode) {
//         this.errorCode = errorCode;
//     }
// 
// }
// 
// Path: java/src/org/drupal/project/computing/exception/DSystemExecutionException.java
// public class DSystemExecutionException extends Exception {
//     public DSystemExecutionException() {
//     }
// 
//     public DSystemExecutionException(String s) {
//         super(s);
//     }
// 
//     public DSystemExecutionException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DSystemExecutionException(Throwable throwable) {
//         super(throwable);
//     }
// }


// Path: java/src/org/drupal/project/computing/DDrush.java
import org.apache.commons.exec.CommandLine;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.drupal.project.computing.exception.DSiteException;
import org.drupal.project.computing.exception.DSystemExecutionException;
import javax.script.Bindings;
import javax.script.SimpleBindings;
import java.util.logging.Logger;

     * @return execution results in JSON.
     * @throws DSiteException
     */
    public String computingEval(String phpCode) throws DSiteException {
        String result;
        try {
            result = execute(new String[] {"computing-eval", "--pipe", "-"}, phpCode);
        } catch (Exception e) {
            logger.severe("Error executing PHP code through computing-eval: " + phpCode);
            throw new DSiteException("Cannot execute computing-eval.", e);
        }
        return result;
    }


    /**
     * Call any Drupal functions and returns results in json.
     *
     * @param params First param is the function name; the rest are parameters in json.
     *   Callers are responsible to wrap the params in json, but not responsible to escape them as command line args.
     * @return Execution results in JSON.
     * @throws DSiteException
     */
    public String computingCall(String[] params) throws DSiteException {
        String result;
        try {
            String[] args = {"computing-call", "--pipe"};
            args = ArrayUtils.addAll(args, params);
            result = execute(args);
        } catch (Exception e) {
            logger.severe("Error executing function call through computing-call: " + ArrayUtils.toString(params));