com.perforce.api
Class Env

java.lang.Object
  extended by com.perforce.api.Env

public class Env
extends java.lang.Object

Representation of a source control environment. This information is typically passed to a P4Process instance by the SourceControlObject instances. It can also be set in the base P4Process instance. This will cause it to be used as the default environment for all command execution.

Values for the environment can be easily loaded from a Properties file. This makes configuration of the environment much simpler.

Version:
$Date: 2002/05/16 $ $Revision: #5 $
Author:
David Markley
See Also:
Properties

Constructor Summary
Env()
          Default, no-argument constructor.
Env(Env base)
          Constructor that uses another environment as its basis.
Env(java.util.Properties props)
          Constructor that uses a set of Properties to set up the environment.
Env(java.lang.String propfile)
          Constructs an environment from a properties file.
 
Method Summary
 void appendPath(java.lang.String path)
          Append the path element to the existing path.
 void checkValidity()
          Checks the environment to see if it is valid.
 java.lang.String getClient()
          Returns the P4CLIENT.
 java.lang.String getenv(java.lang.String name)
          Returns the value for the named environment variable.
 java.lang.String[] getEnvp()
          Returns the environment in a String array.
 java.lang.String getExecutable()
          Returns the path to the executable.
 java.lang.String getPassword()
          Returns the P4PASSWORD.
 java.lang.String getPath()
          Returns the PATH.
 java.lang.String getPort()
          Returns the P4PORT.
 java.util.Properties getProperties()
          Returns a new Properties instance that is set using the environments properties as its default.
 java.lang.String getProperty(java.lang.String key)
          Searches for the property with the specified key in this property list.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          Searches for the property with the specified key in this property list.
 java.util.Vector getPropertyList(java.lang.String key, java.lang.String defaultValue)
          Returns a Vector containing the property value list, as split up by the commas.
 java.util.Vector getPropertyList(java.lang.String key, java.lang.String defaultValue, java.lang.String delimeter)
          Returns a Vector containing the property value list, as split up by the specified delimeter.
 long getServerTimeout()
          Return the server timeout threshold.
 java.lang.String getUser()
          Returns the P4USER.
 void setClient(java.lang.String client)
          Sets the P4CLIENT in the class information.
 void setenv(java.lang.String name, java.lang.String value)
          Allows the user to set any environment variable.
 void setExecutable(java.lang.String exe)
          Sets up the path to reach the p4 executable.
 void setFromProperties(java.util.Properties props)
          Uses a set of Properties to set up the environment.
 void setFromProperties(java.lang.String propfile)
          Sets the environment using the specified properties file.
 void setPassword(java.lang.String password)
          Sets the P4PASSWD in the class information.
 void setPath(java.lang.String path)
          Sets the PATH in the class information.
 void setPort(java.lang.String port)
          Sets the P4PORT in the class information.
 java.lang.String setProperty(java.lang.String key, java.lang.String value)
          Calls the hashtable method put.
 void setServerTimeout(long threshold)
          Set the server timeout threshold.
 void setSystemDrive(java.lang.String drive)
          Sets the SystemDrive in the class information.
 void setSystemRoot(java.lang.String root)
          Sets the SystemRoot in the class information.
 void setUser(java.lang.String user)
          Sets the P4USER in the class information.
 java.lang.String toString()
           
 java.lang.String toXML()
          Returns an XML representation of the environment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Env

public Env()
Default, no-argument constructor.


Env

public Env(java.lang.String propfile)
    throws PerforceException
Constructs an environment from a properties file.

Parameters:
propfile - full path to a properties file.
Throws:
PerforceException

Env

public Env(Env base)
Constructor that uses another environment as its basis. This is useful for cloning environments and then changing a few attributes.

Parameters:
base - Environment to be copied into the new environment.

Env

public Env(java.util.Properties props)
Constructor that uses a set of Properties to set up the environment.

Parameters:
props - Used to construct the environment.
See Also:
setFromProperties(Properties)
Method Detail

setenv

public void setenv(java.lang.String name,
                   java.lang.String value)
Allows the user to set any environment variable. If the variable name starts with 'P4', the value can not be set to null. It will instead be set to the empty string. For all other variable, supplying a null value will remove that variable form the environment.

Parameters:
name - environment variable name
value - environment variable value

getenv

public java.lang.String getenv(java.lang.String name)
Returns the value for the named environment variable.

Parameters:
name - environment variable name

getEnvp

public java.lang.String[] getEnvp()
Returns the environment in a String array.


checkValidity

public void checkValidity()
                   throws PerforceException
Checks the environment to see if it is valid. To check the validity of the environment, the user information is accessed. This ensures that the server can be contacted and that the password is set properly.

If the environment is valid, this method will return quietly. Otherwise, it will throw a PerforceException with a message regarding the failure.

Throws:
PerforceException

getPropertyList

public java.util.Vector getPropertyList(java.lang.String key,
                                        java.lang.String defaultValue)
Returns a Vector containing the property value list, as split up by the commas. This is used to get the values for a property in the form of:

some.property.key=val1,val2,val3

Will always return a Vector, even if it is empty.

Parameters:
key - the property key
defaultValue - a default value

getPropertyList

public java.util.Vector getPropertyList(java.lang.String key,
                                        java.lang.String defaultValue,
                                        java.lang.String delimeter)
Returns a Vector containing the property value list, as split up by the specified delimeter. This is used to get the values for a property in the form of:

some.property.key=val1,val2,val3

Will always return a Vector, even if it is empty.

Parameters:
key - the property key
defaultValue - a default value
delimeter - string that seperates the values

getProperties

public java.util.Properties getProperties()
Returns a new Properties instance that is set using the environments properties as its default.


getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns the default value argument if the property is not found.

Parameters:
key - the property key
defaultValue - a default value
Returns:
the value in this property list with the specified key value
See Also:
Properties

getProperty

public java.lang.String getProperty(java.lang.String key)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns null if the property is not found.

Parameters:
key - the property key
Returns:
the value in this property list with the specified key value
See Also:
Properties

setProperty

public java.lang.String setProperty(java.lang.String key,
                                    java.lang.String value)
Calls the hashtable method put. Provided for parallelism with the getProperty method. Enforces use of strings for property keys and values.

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
See Also:
Properties.setProperty(String,String)

setFromProperties

public void setFromProperties(java.lang.String propfile)
                       throws PerforceException
Sets the environment using the specified properties file.

Parameters:
propfile - Path to a properties file.
Throws:
PerforceException
See Also:
setFromProperties(Properties)

setFromProperties

public void setFromProperties(java.util.Properties props)
Uses a set of Properties to set up the environment. The properties that are used used by this method are:
Property Value Set
p4.user P4USER
p4.client P4CLIENT
p4.port P4PORT
p4.password P4PASSWORD
p4.executable Executable
p4.sysdrive SystemDrive
p4.sysroot SystemRoot
p4.threshold Server Timeout Threshold

Parameters:
props - Used to construct the environment.

setUser

public void setUser(java.lang.String user)
Sets the P4USER in the class information.

Parameters:
user - P4USER value.

getUser

public java.lang.String getUser()
Returns the P4USER.


setClient

public void setClient(java.lang.String client)
Sets the P4CLIENT in the class information.

Parameters:
user - P4CLIENT value.

getClient

public java.lang.String getClient()
Returns the P4CLIENT.


setPort

public void setPort(java.lang.String port)
Sets the P4PORT in the class information.

Parameters:
user - P4PORT value.

getPort

public java.lang.String getPort()
Returns the P4PORT.


setPassword

public void setPassword(java.lang.String password)
Sets the P4PASSWD in the class information.

Parameters:
user - P4PASSWD value.

getPassword

public java.lang.String getPassword()
Returns the P4PASSWORD.


setPath

public void setPath(java.lang.String path)
Sets the PATH in the class information.

Parameters:
path - PATH value.

appendPath

public void appendPath(java.lang.String path)
Append the path element to the existing path. If the path element given is already in the path, no change is made.

Parameters:
path - the path element to be appended.

getPath

public java.lang.String getPath()
Returns the PATH.


setSystemDrive

public void setSystemDrive(java.lang.String drive)
Sets the SystemDrive in the class information. This is only meaningful under Windows.

Parameters:
user - SystemDrive value.

setSystemRoot

public void setSystemRoot(java.lang.String root)
Sets the SystemRoot in the class information. This is only meaningful under Windows.

Parameters:
user - SystemRoot value.

setExecutable

public void setExecutable(java.lang.String exe)
Sets up the path to reach the p4 executable. The full path passed in must contain the executable or at least end in the system's file separator character. This gotten from the file.separator property. For example:
 p4.executable=/usr/bin/p4   # This will work
 p4.executable=/usr/bin/     # This will work
 <font color=Red>p4.executable=/usr/bin      # This won't work</font>
 

Parameters:
exe - Full path to the p4 executable.

getExecutable

public java.lang.String getExecutable()
Returns the path to the executable.


setServerTimeout

public void setServerTimeout(long threshold)
Set the server timeout threshold.


getServerTimeout

public long getServerTimeout()
Return the server timeout threshold.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toXML

public java.lang.String toXML()
Returns an XML representation of the environment.



Copyright © 2010. All Rights Reserved.