// Path: java/src/org/drupal/project/computing/exception/DRuntimeException.java
// public class DRuntimeException extends RuntimeException {
// 
//     public DRuntimeException() {
//         super();
//     }
// 
//     public DRuntimeException(String s) {
//         super(s);
//     }
// 
//     public DRuntimeException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DRuntimeException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// 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 com.google.gson.*;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteWatchdog;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.drupal.project.computing.exception.DRuntimeException;
import org.drupal.project.computing.exception.DSystemExecutionException;
import javax.script.Bindings;
import javax.script.SimpleBindings;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.*;
import java.util.logging.Logger;
     */
    public String encodeURLQueryParameters(Properties params) {
        StringBuilder sb = new StringBuilder();
        Iterator<String> keysIterator = params.stringPropertyNames().iterator();

        while (keysIterator.hasNext()) {
            String key = keysIterator.next();
            try {
                sb.append(URLEncoder.encode(key, "UTF-8")).append('=').append(URLEncoder.encode(params.getProperty(key), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new IllegalArgumentException(e);
            }
            if (keysIterator.hasNext()) {
                sb.append('&');
            }
        }

        return sb.toString();
    }



    /**
     * Execute a command in the working dir, and return the output as a String. If error, log the errors in logger.
     *
     * @param commandLine The command line object
     * @param workingDir The working directory. Could be null. The it's default user.dir.
     * @param input Input string
     * @return command output.
     */
// Path: java/src/org/drupal/project/computing/exception/DRuntimeException.java
// public class DRuntimeException extends RuntimeException {
// 
//     public DRuntimeException() {
//         super();
//     }
// 
//     public DRuntimeException(String s) {
//         super(s);
//     }
// 
//     public DRuntimeException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// 
//     public DRuntimeException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// 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/DUtils.java
import com.google.gson.*;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteWatchdog;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.drupal.project.computing.exception.DRuntimeException;
import org.drupal.project.computing.exception.DSystemExecutionException;
import javax.script.Bindings;
import javax.script.SimpleBindings;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.*;
import java.util.logging.Logger;

     */
    public String encodeURLQueryParameters(Properties params) {
        StringBuilder sb = new StringBuilder();
        Iterator<String> keysIterator = params.stringPropertyNames().iterator();

        while (keysIterator.hasNext()) {
            String key = keysIterator.next();
            try {
                sb.append(URLEncoder.encode(key, "UTF-8")).append('=').append(URLEncoder.encode(params.getProperty(key), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new IllegalArgumentException(e);
            }
            if (keysIterator.hasNext()) {
                sb.append('&');
            }
        }

        return sb.toString();
    }



    /**
     * Execute a command in the working dir, and return the output as a String. If error, log the errors in logger.
     *
     * @param commandLine The command line object
     * @param workingDir The working directory. Could be null. The it's default user.dir.
     * @param input Input string
     * @return command output.
     */
    public String executeShell(CommandLine commandLine, File workingDir, String input) throws DSystemExecutionException {