org.drupal.project.computing
Class DUtils

java.lang.Object
  extended by org.drupal.project.computing.DUtils

public class DUtils
extends java.lang.Object

Singleton of the utilities class.


Nested Class Summary
static class DUtils.Drush
          This is the utility class to run drush command.
static class DUtils.Php
          Utility class to run PHP snippet
static class DUtils.UnitTest
           
 
Field Summary
 java.lang.String VERSION
           
 
Method Summary
 boolean checkJavaVersion()
          Check to make sure Java is > 1.6
 java.lang.String executeShell(org.apache.commons.exec.CommandLine commandLine, java.io.File workingDir, java.lang.String input)
          Execute a command in the working dir, and return the output as a String.
 java.lang.String executeShell(java.util.List<java.lang.String> command, java.io.File workingDir)
          Deprecated. 
 java.lang.String executeShell(java.lang.String command)
           
 com.google.gson.Gson getDefaultGson()
           
 java.lang.String getIdentifier(java.lang.Class<?> classObject)
          Get either the identifier if presented, or the class name.
static DUtils getInstance()
           
 java.lang.Long getLong(java.lang.Object value)
          Get the long value from any Object, if possible.
 java.util.logging.Logger getPackageLogger()
           
 java.util.Properties loadProperties(java.lang.String configString)
           
 java.lang.String readContent(java.io.Reader input)
          From the input reader and get all its content.
 java.lang.String toJson(java.lang.Object obj)
          Encapsulate json object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public final java.lang.String VERSION
See Also:
Constant Field Values
Method Detail

getInstance

public static DUtils getInstance()

getPackageLogger

public final java.util.logging.Logger getPackageLogger()

executeShell

@Deprecated
public java.lang.String executeShell(java.util.List<java.lang.String> command,
                                                java.io.File workingDir)
Deprecated. 

Execute a command in the working dir, and return the output as a String. If error, log the errors in logger. This is the un-refined version using Process and ProcessBuilder. See the other version with commons-exec.

Parameters:
command - The list of command and parameters.
workingDir - The working directory. Could be null. The it's default user.dir.
Returns:
command output.

executeShell

public java.lang.String executeShell(org.apache.commons.exec.CommandLine commandLine,
                                     java.io.File workingDir,
                                     java.lang.String input)
                              throws DSystemExecutionException
Execute a command in the working dir, and return the output as a String. If error, log the errors in logger. TODO: this should take care of arbitrary encoding/decoding. TODO: check to make sure it won't output confidential information from settings.php, etc.

Parameters:
commandLine - The command line object
workingDir - The working directory. Could be null. The it's default user.dir.
input - Input string
Returns:
command output.
Throws:
DSystemExecutionException

executeShell

public java.lang.String executeShell(java.lang.String command)
                              throws DSystemExecutionException
Throws:
DSystemExecutionException

readContent

public java.lang.String readContent(java.io.Reader input)
                             throws java.io.IOException
From the input reader and get all its content.

Parameters:
input - input reader
Returns:
the content of the reader in String.
Throws:
java.io.IOException

checkJavaVersion

public boolean checkJavaVersion()
Check to make sure Java is > 1.6

Returns:
True if Java version is satisfied.

getIdentifier

public java.lang.String getIdentifier(java.lang.Class<?> classObject)
Get either the identifier if presented, or the class name.

Parameters:
classObject -
Returns:

getLong

public java.lang.Long getLong(java.lang.Object value)
Get the long value from any Object, if possible.

Parameters:
value - The object that could either be null, or int, or string.
Returns:
The long value of the "value".

toJson

public java.lang.String toJson(java.lang.Object obj)
Encapsulate json object.

Parameters:
obj -
Returns:

getDefaultGson

public com.google.gson.Gson getDefaultGson()

loadProperties

public java.util.Properties loadProperties(java.lang.String configString)