Perforce

com.perforce.api
Class Env

java.lang.Object
  |
  +--com.perforce.api.Env

public class Env
extends 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: 2003/09/05 $ $Revision: #1 $
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(Properties props)
          Constructor that uses a set of Properties to set up the environment.
Env(String propfile)
          Constructs an environment from a properties file.
 
Method Summary
 void appendPath(String path)
          Append the path element to the existing path.
 void checkValidity()
          Checks the environment to see if it is valid.
 String getClient()
          Returns the P4CLIENT.
 String getenv(String name)
          Returns the value for the named environment variable.
 String[] getEnvp()
          Returns the environment in a String array.
 String getExecutable()
          Returns the path to the executable.
 String getPassword()
          Returns the P4PASSWORD.
 String getPath()
          Returns the PATH.
 String getPort()
          Returns the P4PORT.
 Properties getProperties()
          Returns a new Properties instance that is set using the environments properties as its default.
 String getProperty(String key)
          Searches for the property with the specified key in this property list.
 String getProperty(String key, String defaultValue)
          Searches for the property with the specified key in this property list.
 Vector getPropertyList(String key, String defaultValue)
          Returns a Vector containing the property value list, as split up by the commas.
 Vector getPropertyList(String key, String defaultValue, String delimeter)
          Returns a Vector containing the property value list, as split up by the specified delimeter.
 long getServerTimeout()
          Return the server timeout threshold.
 String getUser()
          Returns the P4USER.
 void setClient(String client)
          Sets the P4CLIENT in the class information.
 void setenv(String name, String value)
          Allows the user to set any environment variable.
 void setExecutable(String exe)
          Sets up the path to reach the p4 executable.
 void setFromProperties(Properties props)
          Uses a set of Properties to set up the environment.
 void setFromProperties(String propfile)
          Sets the environment using the specified properties file.
 void setPassword(String password)
          Sets the P4PASSWD in the class information.
 void setPath(String path)
          Sets the PATH in the class information.
 void setPort(String port)
          Sets the P4PORT in the class information.
 String setProperty(String key, String value)
          Calls the hashtable method put.
 void setServerTimeout(long threshold)
          Set the server timeout threshold.
 void setSystemDrive(String drive)
          Sets the SystemDrive in the class information.
 void setSystemRoot(String root)
          Sets the SystemRoot in the class information.
 void setUser(String user)
          Sets the P4USER in the class information.
 String toString()
           
 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(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(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)

Env

public Env(String propfile)
    throws PerforceException
Constructs an environment from a properties file.
Parameters:
propfile - full path to a properties file.
Method Detail

appendPath

public void appendPath(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.

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.


getClient

public String getClient()
Returns the P4CLIENT.

getenv

public String getenv(String name)
Returns the value for the named environment variable.
Parameters:
name - environment variable name

getEnvp

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

getExecutable

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

getPassword

public String getPassword()
Returns the P4PASSWORD.

getPath

public String getPath()
Returns the PATH.

getPort

public String getPort()
Returns the P4PORT.

getProperties

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

getProperty

public String getProperty(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

getProperty

public String getProperty(String key,
                          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

getPropertyList

public Vector getPropertyList(String key,
                              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 Vector getPropertyList(String key,
                              String defaultValue,
                              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

getServerTimeout

public long getServerTimeout()
Return the server timeout threshold.

getUser

public String getUser()
Returns the P4USER.

setClient

public void setClient(String client)
Sets the P4CLIENT in the class information.
Parameters:
user - P4CLIENT value.

setenv

public void setenv(String name,
                   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

setExecutable

public void setExecutable(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
 p4.executable=/usr/bin      # This won't work
 
Parameters:
exe - Full path to the p4 executable.

setFromProperties

public void setFromProperties(Properties props)
Uses a set of Properties to set up the environment. The properties that are used used by this method are:
PropertyValue Set
p4.userP4USER
p4.clientP4CLIENT
p4.portP4PORT
p4.passwordP4PASSWORD
p4.executableExecutable
p4.sysdriveSystemDrive
p4.sysrootSystemRoot
p4.thresholdServer Timeout Threshold
Parameters:
props - Used to construct the environment.

setFromProperties

public void setFromProperties(String propfile)
                       throws PerforceException
Sets the environment using the specified properties file.
Parameters:
propfile - Path to a properties file.
See Also:
setFromProperties(Properties)

setPassword

public void setPassword(String password)
Sets the P4PASSWD in the class information.
Parameters:
user - P4PASSWD value.

setPath

public void setPath(String path)
Sets the PATH in the class information.
Parameters:
path - PATH value.

setPort

public void setPort(String port)
Sets the P4PORT in the class information.
Parameters:
user - P4PORT value.

setProperty

public String setProperty(String key,
                          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)

setServerTimeout

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

setSystemDrive

public void setSystemDrive(String drive)
Sets the SystemDrive in the class information. This is only meaningful under Windows.
Parameters:
user - SystemDrive value.

setSystemRoot

public void setSystemRoot(String root)
Sets the SystemRoot in the class information. This is only meaningful under Windows.
Parameters:
user - SystemRoot value.

setUser

public void setUser(String user)
Sets the P4USER in the class information.
Parameters:
user - P4USER value.

toString

public String toString()
Overrides:
toString in class Object

toXML

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

Perforce

Copyright © 2001, Perforce Software, All rights reserved.