net.sf.jomic.tools
Class ConsoleTools

java.lang.Object
  extended by net.sf.jomic.tools.ConsoleTools

public final class ConsoleTools
extends java.lang.Object

Utility methods to interact with command line interface.

Author:
Thomas Aglassinger

Field Summary
static int NO_RESULT
          Pseudo exit code indicating that exit code does not matter.
 
Method Summary
 java.lang.String asVersionNumber(float version)
          Render version as a version number.
 float getVersion(java.lang.String commandPath)
           
static ConsoleTools instance()
          Get accessor to unique instance.
 java.util.List run(java.lang.String[] arguments, java.io.File path, int expectedResult)
          Runs the specified (shell) command.
 java.util.List run(java.lang.String[] arguments, java.io.File path, int expectedResult, ConsoleOutputListener listener)
          Runs the specified (shell) command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_RESULT

public static final int NO_RESULT
Pseudo exit code indicating that exit code does not matter.

See Also:
Constant Field Values
Method Detail

instance

public static ConsoleTools instance()
Get accessor to unique instance.


asVersionNumber

public java.lang.String asVersionNumber(float version)
Render version as a version number. Unlike Float.toString(), always use a "." and never a "," independant of the current locale.


getVersion

public float getVersion(java.lang.String commandPath)
                 throws java.io.IOException,
                        java.lang.InterruptedException
Throws:
java.io.IOException
java.lang.InterruptedException

run

public java.util.List run(java.lang.String[] arguments,
                          java.io.File path,
                          int expectedResult)
                   throws java.io.IOException,
                          java.lang.InterruptedException
Runs the specified (shell) command.

Parameters:
arguments - arguments[0] is the actual command, all other entries are the arguments passed to it
path - the current directory in which the command is to be executed; if null, use property "user.dir" (the current working directory)
expectedResult - the expected exit code; typically 0 to indicate a successful run
Returns:
the lines written to System.out and System.err by the command
Throws:
java.io.IOException - if the exit code is not expectedResult
java.lang.InterruptedException

run

public java.util.List run(java.lang.String[] arguments,
                          java.io.File path,
                          int expectedResult,
                          ConsoleOutputListener listener)
                   throws java.io.IOException,
                          java.lang.InterruptedException
Runs the specified (shell) command.

Parameters:
arguments - arguments[0] is the actual command, all other entries are the arguments passed to it
path - the current directory in which the command is to be executed; if null, use the current working directory (as specified by System.getProperty("user.dir") )
expectedResult - the expected exit code; typically 0 to indicate a successful run. NO_RESULT means that the exit code should be ignored.
listener - to be informed about every line written to System.out or Syst.err
Returns:
the lines written to System.out and System.err by the command
Throws:
java.io.IOException - if the exit code is not expectedResult
java.lang.InterruptedException