net.sourceforge.cruisecontrol.util
Class ManagedCommandline

java.lang.Object
  extended bynet.sourceforge.cruisecontrol.util.Commandline
      extended bynet.sourceforge.cruisecontrol.util.EnvCommandline
          extended bynet.sourceforge.cruisecontrol.util.ManagedCommandline
All Implemented Interfaces:
java.lang.Cloneable

public class ManagedCommandline
extends EnvCommandline

Extends EnvCommandline by adding stdout and stderr stream handling as well as some assertions to check for proper execution of the command.

Author:
Robert J. Smith

Nested Class Summary
 
Nested classes inherited from class net.sourceforge.cruisecontrol.util.Commandline
Commandline.Argument, Commandline.Marker
 
Constructor Summary
ManagedCommandline()
          Default constructor
ManagedCommandline(java.lang.String command)
          Constructor which takes a command line string and attempts to parse it into it's various components.
 
Method Summary
 void assertExitCode(int code)
          Asserts that the exit code of the command matches an expected value.
 void assertExitCodeGreaterThan(int code)
          Asserts that the exit code of the command is greater than a given value.
 void assertExitCodeLessThan(int code)
          Asserts that the exit code of the command is less than a given value.
 void assertExitCodeNot(int code)
          Asserts that the exit code of the command is not a given value.
 void assertStderrDoesNotContain(java.lang.String string)
          Asserts that the stderr of the command does not contain a given String.
 void assertStdoutContains(java.lang.String string)
          Asserts that the stdout of the command contains a given String.
 void assertStdoutDoesNotContain(java.lang.String string)
          Asserts that the stdout of the command does not contain a given String.
 void clear()
          Clear out the whole command line.
 void clearArgs()
          Clear out the arguments and stored command output, but leave the executable in place for another operation.
 java.lang.Process execute()
          Executes the command.
 int getExitCode()
          Returns the exit code of the command as reported by the OS.
 java.util.List getStderrAsList()
          Returns the stderr from the command as a List of Strings where each String is one line of the error.
 java.lang.String getStderrAsString()
          Returns the stderr from the command as a String
 java.util.List getStdoutAsList()
          Returns the stdout from the command as a List of Strings where each String is one line of the output.
 java.lang.String getStdoutAsString()
          Returns the stdout from the command as a String
 
Methods inherited from class net.sourceforge.cruisecontrol.util.EnvCommandline
getVariable, setVariable
 
Methods inherited from class net.sourceforge.cruisecontrol.util.Commandline
addArguments, clone, createArgument, createArgument, createArgument, createArguments, createMarker, executeAndWait, getArguments, getCommandline, getExecutable, getWorkingDir, getWorkingDirectory, quoteArgument, setExecutable, setWorkingDir, setWorkingDirectory, size, toString, toString, toString, toStringNoQuoting, translateCommandline, useSafeQuoting
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ManagedCommandline

public ManagedCommandline(java.lang.String command)
Constructor which takes a command line string and attempts to parse it into it's various components.

Parameters:
command - The command

ManagedCommandline

public ManagedCommandline()
Default constructor

Method Detail

getExitCode

public int getExitCode()
Returns the exit code of the command as reported by the OS.

Returns:
The exit code of the command

getStdoutAsString

public java.lang.String getStdoutAsString()
Returns the stdout from the command as a String

Returns:
The standard output of the command as a String

getStdoutAsList

public java.util.List getStdoutAsList()
Returns the stdout from the command as a List of Strings where each String is one line of the output.

Returns:
The standard output of the command as a List of output lines.

getStderrAsString

public java.lang.String getStderrAsString()
Returns the stderr from the command as a String

Returns:
The standard error of the command as a String

getStderrAsList

public java.util.List getStderrAsList()
Returns the stderr from the command as a List of Strings where each String is one line of the error.

Returns:
The standard error of the command as a List of output lines.

clear

public void clear()
Clear out the whole command line.

Overrides:
clear in class Commandline

clearArgs

public void clearArgs()
Clear out the arguments and stored command output, but leave the executable in place for another operation.

Overrides:
clearArgs in class Commandline

assertStdoutDoesNotContain

public void assertStdoutDoesNotContain(java.lang.String string)
                                throws CruiseControlException
Asserts that the stdout of the command does not contain a given String. Throws a CruiseControlException if it does.

Parameters:
string - The forbidden String
Throws:
CruiseControlException

assertStdoutContains

public void assertStdoutContains(java.lang.String string)
                          throws CruiseControlException
Asserts that the stdout of the command contains a given String. Throws a CruiseControlException if it does not.

Parameters:
string - The required String
Throws:
CruiseControlException

assertStderrDoesNotContain

public void assertStderrDoesNotContain(java.lang.String string)
                                throws CruiseControlException
Asserts that the stderr of the command does not contain a given String. Throws a CruiseControlException if it does.

Parameters:
string - The forbidden String
Throws:
CruiseControlException

assertExitCode

public void assertExitCode(int code)
                    throws CruiseControlException
Asserts that the exit code of the command matches an expected value. Throws a CruiseControlException if it does not.

Parameters:
code - The expected exit code of the command
Throws:
CruiseControlException

assertExitCodeNot

public void assertExitCodeNot(int code)
                       throws CruiseControlException
Asserts that the exit code of the command is not a given value. Throws a CruiseControlException if it is.

Parameters:
code - The expected exit code of the command
Throws:
CruiseControlException

assertExitCodeGreaterThan

public void assertExitCodeGreaterThan(int code)
                               throws CruiseControlException
Asserts that the exit code of the command is greater than a given value. Throws a CruiseControlException if it is not.

Parameters:
code - The expected exit code of the command
Throws:
CruiseControlException

assertExitCodeLessThan

public void assertExitCodeLessThan(int code)
                            throws CruiseControlException
Asserts that the exit code of the command is less than a given value. Throws a CruiseControlException if it is not.

Parameters:
code - The expected exit code of the command
Throws:
CruiseControlException

execute

public java.lang.Process execute()
                          throws java.io.IOException
Executes the command.

Overrides:
execute in class EnvCommandline
Throws:
java.io.IOException