net.sourceforge.cruisecontrol.util
Class OSEnvironment

java.lang.Object
  extended bynet.sourceforge.cruisecontrol.util.OSEnvironment

public class OSEnvironment
extends java.lang.Object

A simple utility class for obtaining and parsing system environment variables. It has been tested on Windows 2000, Windows XP, Solaris, and HP-UX, though it should work with any Win32 (95+) or Unix based palatform.

Author:
Robert J. Smith

Constructor Summary
OSEnvironment()
          Constructor Creates an instance of OSEnvironment, queries the OS to discover it's environment variables and makes them available through the getter methods
 
Method Summary
 void add(java.lang.String variable, java.lang.String value)
          Adds a variable to this representation of the environment.
 java.util.List getEnvironment()
          Returns all environment variables which were set at the time the class was instantiated, as well as any which have been added programatically.
 java.lang.String getVariable(java.lang.String variable)
          Gets the value of an environment variable.
 java.lang.String getVariable(java.lang.String variable, java.lang.String defaultValue)
          Gets the value of an environment variable.
 java.lang.String getVariableIgnoreCase(java.lang.String variable)
          Gets the value of an environment variable.
 java.lang.String[] toArray()
          Returns all environment variables which were set at the time the class was instantiated, as well as any which have been added programatically.
 java.lang.String toString()
          Returns a String representation of the environment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OSEnvironment

public OSEnvironment()
Constructor Creates an instance of OSEnvironment, queries the OS to discover it's environment variables and makes them available through the getter methods

Method Detail

getVariable

public java.lang.String getVariable(java.lang.String variable)
Gets the value of an environment variable. The variable name is case sensitive.

Parameters:
variable - The variable for which you wish the value
Returns:
The value of the variable, or null if not found
See Also:
getVariable(String variable, String defaultValue)

getVariable

public java.lang.String getVariable(java.lang.String variable,
                                    java.lang.String defaultValue)
Gets the value of an environment variable. The variable name is case sensitive.

Parameters:
variable - the variable for which you wish the value
defaultValue - The value to return if the variable is not set in the environment.
Returns:
The value of the variable. If the variable is not found, the defaultValue is returned.

getVariableIgnoreCase

public java.lang.String getVariableIgnoreCase(java.lang.String variable)
Gets the value of an environment variable. The variable name is NOT case sensitive. If more than one variable matches the pattern provided, the result is unpredictable. You are greatly encouraged to use getVariable() instead.

Parameters:
variable - the variable for which you wish the value
See Also:
getVariable(String variable), getVariable(String variable, String defaultValue)

add

public void add(java.lang.String variable,
                java.lang.String value)
Adds a variable to this representation of the environment. If the variable already existed, the value will be replaced.

Parameters:
variable - the variable to set
value - the value of the variable

getEnvironment

public java.util.List getEnvironment()
Returns all environment variables which were set at the time the class was instantiated, as well as any which have been added programatically.

Returns:
a List of all environment variables. The List is made up of Strings of the form "variable=value".
See Also:
toArray()

toArray

public java.lang.String[] toArray()
Returns all environment variables which were set at the time the class was instantiated, as well as any which have been added programatically.

Returns:
a String[] containing all environment variables. The Strings are of the form "variable=value". This is the format expected by java.lang.Runtime.exec().
See Also:
Runtime

toString

public java.lang.String toString()
Returns a String representation of the environment.

Returns:
A String representation of the environment