Class UsageOptions
Intended to implement some of the options described in the main Perforce p4 usage and p4 undoc documentation on a per-IOptionsServer object basis, and also implements some of the broader environment settings (such as the client name used by the P4Java server implementation when no client has been associated with the server).
The UsageOptions object associated with a server is read and used for a small number of usage values (currently programName, programVersion, unsetUserName, and unsetClientName) each time a command is issued to the corresponding Perforce server, so updates to the UsageOptions object and / or any associated Properties object will be reflected at the next command execution except where noted. Note that this means that UsageOption objects shared between multiple servers are sensitive to such changes, and that changes that occur when a server is processing command requests may cause unexpected results.
A UsageOption object is associated with a server instance when the server is issued by the server factory; this can be the default object or one passed-in to the server factory specifically for that server.
Note that the UsageOptions class should be used with some care as the possible side effects of setting some of the usage parameters to the wrong value can lead to unexpected or odd behaviour.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringDefault working directory from the JVM to fall back to if not working directory is set on the usage optionsprotected StringIf not null, specifies the host name used by the server's commands.protected StringIf not null, will be used to identify the P4Java application's program name to the Perforce server.protected StringIf not null, will be used to identify the P4Java application's program version to the Perforce server.protected PropertiesProperties object used to get default field values from.protected StringIf not null, use this field to tell the server which language to use in text messages it sends back to the client.protected StringIf set, this will be used as the name of the client when no client has actually been explicitly set for the associated server(s).protected StringWhat will be sent to the Perforce server with each command as the user name if no user name has been explicitly set for servers associated with this UsageOption.static final StringThe name of the system property used to determine the JVM's current working directory.protected StringIf not null, this specifies the Perforce server's idea of each command's working directory for the associated server object. -
Constructor Summary
ConstructorsConstructorDescriptionUsageOptions(Properties props) Default constructor.UsageOptions(Properties props, String programName, String programVersion, String workingDirectory, String hostName, String textLanguage, String unsetUserName, String noClientName) Explicit value constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturn the program name.protected StringgetProgramNameDefault(Properties props) Get a suitable default value for the programName field.Return the program version.protected StringGet a suitable default value for the programVersion field.getProps()Return the unset client name.protected StringGet a suitable default value for the unsetClientName field.Return the unset user name.protected StringGet a suitable default value for the unsetUserName field.Return the current value of the working directory; this can be dynamically set explicitly using the setter method or implicitly when the object is constructed using the JVM's working directory as reflected in the System properties.protected StringGet a suitable default value for the workingDirectory field.protected voidsetFieldDefaults(Properties props) Set any non-null default values when the object is constructed.setHostName(String hostName) Set the host name.setProgramName(String programName) setProgramVersion(String programVersion) setProps(Properties props) setTextLanguage(String textLanguage) setUnsetClientName(String unsetClientName) setUnsetUserName(String unsetUserName) setWorkingDirectory(String workingDirectory)
-
Field Details
-
WORKING_DIRECTORY_PROPNAME
The name of the system property used to determine the JVM's current working directory.- See Also:
-
props
Properties object used to get default field values from. Note that these properties are potentially accessed for each command, so any changes in the properties will be reflected the next time the options object is used. -
programName
If not null, will be used to identify the P4Java application's program name to the Perforce server. -
programVersion
If not null, will be used to identify the P4Java application's program version to the Perforce server. -
workingDirectory
If not null, this specifies the Perforce server's idea of each command's working directory for the associated server object. Corresponds to the p4 -d usage option.This affects all commands on the associated server from this point on, and the passed-in path should be both absolute and valid, otherwise strange errors may appear from the server. If workingDirectory is null, the Java VM's actual current working directory at the time this object is constructed is used instead (which is almost always a safe option unless you're using Perforce alt roots).
Note: no checking is done at any time for correctness (or otherwise) of the workingDirectory option.
-
hostName
If not null, specifies the host name used by the server's commands. Set to null by the default constructor. Corresponds to the p4 -H usage option. HostName is not live -- that is, unlike many other UsageOption fields, its value is only read once when the associated server is created; subsequent changes will not be reflected in the associated server. -
textLanguage
If not null, use this field to tell the server which language to use in text messages it sends back to the client. Corresponds to the p4 -L option, with the same limitations. Set to null by the default constructor. -
unsetUserName
What will be sent to the Perforce server with each command as the user name if no user name has been explicitly set for servers associated with this UsageOption. -
unsetClientName
If set, this will be used as the name of the client when no client has actually been explicitly set for the associated server(s). -
defaultWorkingDirectory
Default working directory from the JVM to fall back to if not working directory is set on the usage options
-
-
Constructor Details
-
UsageOptions
Default constructor. Sets props field then calls setFieldDefaults to set appropriate field default values; otherwise does nothing.- Parameters:
props- properties
-
UsageOptions
public UsageOptions(Properties props, String programName, String programVersion, String workingDirectory, String hostName, String textLanguage, String unsetUserName, String noClientName) Explicit value constructor. After setting any values explicitly, calls setFieldDefaults() to tidy up any still-null fields that shouldn't be null.- Parameters:
props- propertiesprogramName- program nameprogramVersion- program versionworkingDirectory- working directoryhostName- host nametextLanguage- languageunsetUserName- user namenoClientName- client name
-
-
Method Details
-
setFieldDefaults
Set any non-null default values when the object is constructed. Basically, this means running down the fields and if a field is null and it's not a field that should have a null default value, calling the corresponding getXXXXDefault method.Fields set here: workingDirectory.
- Parameters:
props- properties
-
getProgramNameDefault
Get a suitable default value for the programName field. This version tries to find a suitable value in the passed-in properties with the key PropertyDefs.PROG_NAME_KEY_SHORTFORM, then with the key PropertyDefs.PROG_NAME_KEY; if that comes up null, it uses the value of PropertyDefs.PROG_NAME_DEFAULT.- Parameters:
props- properties- Returns:
- non-null default programName value.
-
getProgramVersionDefault
Get a suitable default value for the programVersion field. This version tries to find a suitable value in the passed-in properties with the key PropertyDefs.PROG_VERSION_KEY_SHORTFORM, then with the key PropertyDefs.PROG_VERSION_KEY; if that comes up null, it uses the value of PropertyDefs.PROG_VERSION_DEFAULT.- Parameters:
props- properties- Returns:
- non-null default programVersion value.
-
getWorkingDirectoryDefault
Get a suitable default value for the workingDirectory field. This is taken from the JVM's system properties using the WORKING_DIRECTORY_PROPNAME system properties key (which is normally user.dir).- Parameters:
props- properties- Returns:
- non-null working directory.
-
getUnsetUserNameDefault
Get a suitable default value for the unsetUserName field. This version returns the value of the property associated with the PropertyDefs.USER_UNSET_NAME_KEY if it exists, or PropertyDefs.USER_UNSET_NAME_DEFAULT if not.- Parameters:
props- properties- Returns:
- non-null default unsetUserName value.
-
getUnsetClientNameDefault
Get a suitable default value for the unsetClientName field. This version returns the value of the property associated with the PropertyDefs.CLIENT_UNSET_NAME_KEY if it exists, or PropertyDefs.CLIENT_UNSET_NAME_DEFAULT if not.- Parameters:
props- properties- Returns:
- non-null default unsetClientName value.
-
getProgramName
Return the program name. The current program name is determined by first seeing if there's been one explicitly set in this options object; if so, it's returned, otherwise the associated properties are searched for a value with the key PropertyDefs.PROG_NAME_KEY_SHORTFORM, then with the key PropertyDefs.PROG_NAME_KEY; if that comes up null, it returns the value of PropertyDefs.PROG_NAME_DEFAULT.- Returns:
- program name
-
setProgramName
-
getProgramVersion
Return the program version. The current program version is determined by first seeing if there's been one explicitly set in this options object; if so, it's returned, otherwise the associated properties are searched for a value with the key PropertyDefs.PROG_VERSION_KEY_SHORTFORM, then with the key PropertyDefs.PROG_VERSION_KEY; if that comes up null, it returns the value of PropertyDefs.PROG_VERSION_DEFAULT.- Returns:
- program version
-
setProgramVersion
- Parameters:
programVersion- program version- Returns:
- usage options
-
getWorkingDirectory
Return the current value of the working directory; this can be dynamically set explicitly using the setter method or implicitly when the object is constructed using the JVM's working directory as reflected in the System properties.- Returns:
- working directory
-
setWorkingDirectory
- Parameters:
workingDirectory- working directory- Returns:
- usage options
-
getHostName
- Returns:
- host name
-
setHostName
Set the host name. Calling this method has no effect at all after any associated server object is created.- Parameters:
hostName- host name- Returns:
- usage options
-
getTextLanguage
- Returns:
- language
-
setTextLanguage
- Parameters:
textLanguage- language- Returns:
- usage options
-
getProps
- Returns:
- properties
-
setProps
- Parameters:
props- properties- Returns:
- usage options
-
getUnsetClientName
Return the unset client name. The current value is determined by first seeing if there's been one explicitly set in this options object; if so, it's returned; otherwise the associated properties are searched for a value with the key PropertyDefs.CLIENT_UNSET_NAME_KEY; if that comes up null, it returns the value of PropertyDefs.CLIENT_UNSET_NAME_DEFAULT.- Returns:
- client name
-
setUnsetClientName
- Parameters:
unsetClientName- client name- Returns:
- usage options
-
getUnsetUserName
Return the unset user name. The current value is determined by first seeing if there's been one explicitly set in this options object; if so, it's returned; otherwise the associated properties are searched for a value with the key PropertyDefs.USER_UNSET_NAME_KEY; if that comes up null, it returns the value of PropertyDefs.USER_UNSET_NAME_DEFAULT.- Returns:
- user name
-
setUnsetUserName
- Parameters:
unsetUserName- user name- Returns:
- usage options
-