public abstract class EnvironmentScriptFileUpdate extends Object
You can update changes to existing environment variables or add new ones.
Note that this utility only works on simple environment script files where each name=value pair exists on single lines (i.e. they do not span multiple lines). But it can handle commented lines (i.e. comments are preserved).
| Modifier and Type | Class and Description |
|---|---|
static class |
EnvironmentScriptFileUpdate.NameValuePair |
| Constructor and Description |
|---|
EnvironmentScriptFileUpdate(String location)
Constructor given the full path to script file.
|
| Modifier and Type | Method and Description |
|---|---|
Properties |
convertNameValuePairListToProperties(List<EnvironmentScriptFileUpdate.NameValuePair> list) |
List<EnvironmentScriptFileUpdate.NameValuePair> |
convertPropertiesToNameValuePairList(Properties props) |
static EnvironmentScriptFileUpdate |
create(String location)
Factory method that creates an update object that is appropriate
to update the given file.
|
protected abstract String |
createEnvironmentVariableLine(EnvironmentScriptFileUpdate.NameValuePair nvp)
Creates a line that defines an environment variable name and its value.
|
List<EnvironmentScriptFileUpdate.NameValuePair> |
loadExisting()
Loads and returns the properties that exist currently in the properties file.
|
protected abstract EnvironmentScriptFileUpdate.NameValuePair |
parseEnvironmentVariableLine(String line)
Parses the given string that is a line from a environment script file.
|
void |
update(EnvironmentScriptFileUpdate.NameValuePair nvp)
Updates the script file so it will contain the key with the value (where the key is the
name of the environment variable).
|
void |
update(List<EnvironmentScriptFileUpdate.NameValuePair> newValuesList,
boolean deleteMissing)
Updates the existing script file with the new name/value settings.
|
public EnvironmentScriptFileUpdate(String location)
location - location of the filepublic static EnvironmentScriptFileUpdate create(String location)
JavaServiceWrapperConfigurationFileUpdateJavaServiceWrapperEnvironmentScriptFileUpdateWindowsEnvironmentScriptFileUpdateUnixEnvironmentScriptFileUpdatelocation - location of the script filepublic void update(EnvironmentScriptFileUpdate.NameValuePair nvp) throws IOException
null, an empty
string will be used in file. If the variable does not yet exist in the properties file, it will be
appended to the end of the file.key - the env var name whose value is to be updatedvalue - the new env var valueIOExceptionpublic void update(List<EnvironmentScriptFileUpdate.NameValuePair> newValuesList, boolean deleteMissing) throws IOException
newValues that
already exists in the file, the existing setting is updated in place. Any new setting found in
newValues that does not yet exist in the file will be added. Currently existing settings
in the script file that are not found in newValues will remain as-is.newValuesList - environment variable settings that are added or updated in the filedeleteMissing - if true, any settings found in the existing file that are missing
from the given newValues will be removed from the existing file.
if false, then newValues is assumed to be only a subset
of the settings that can go in the file and thus any settings found in the
existing file but are missing from the new values will not be deleted.IOExceptionpublic List<EnvironmentScriptFileUpdate.NameValuePair> loadExisting() throws IOException
IOExceptionpublic Properties convertNameValuePairListToProperties(List<EnvironmentScriptFileUpdate.NameValuePair> list)
public List<EnvironmentScriptFileUpdate.NameValuePair> convertPropertiesToNameValuePairList(Properties props)
protected abstract String createEnvironmentVariableLine(EnvironmentScriptFileUpdate.NameValuePair nvp)
nvp - the environment variable definitionprotected abstract EnvironmentScriptFileUpdate.NameValuePair parseEnvironmentVariableLine(String line)
null
is returned, otherwise, the environment variable name and value is returned.line - the line from the environment script filenull
if the line doesn't define an env var.Copyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.