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: 2002/01/23 $ $Revision: #4 $
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 checkValidity()
          Checks the environment to see if it is valid.
 String getClient()
          Returns the P4CLIENT.
protected  String[] getEnvp()
           
 String getExecutable()
          Returns the path to the executable.
 String getPassword()
          Returns the P4PASSWORD.
 String getPath()
          Returns the PATH.
 String getPort()
          Returns the P4PORT.
 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.
 long getServerTimeout()
          Return the server timeout threshold.
 String getUser()
          Returns the P4USER.
 void setClient(String client)
          Sets the P4CLIENT in the class information.
 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 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

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.

getEnvp

protected String[] getEnvp()

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.

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

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.

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.
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:
user - 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.