|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.rhq.enterprise.agent.EnvironmentScriptFileUpdate
public abstract class EnvironmentScriptFileUpdate
This utility helps update one or more environment script files without losing the ordering of existing variables or comment lines. An "environment script" is a script file that simply contains lines that set environment variables (i.e. "RHQ_AGENT_MY_VAR=some.value" or "set NAME=VALUE" for Windows scripts).
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).
| Nested Class Summary | |
|---|---|
static class |
EnvironmentScriptFileUpdate.NameValuePair
|
| Constructor Summary | |
|---|---|
EnvironmentScriptFileUpdate(String location)
Constructor given the full path to script file. |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public EnvironmentScriptFileUpdate(String location)
location - location of the file| Method Detail |
|---|
public static EnvironmentScriptFileUpdate create(String location)
JavaServiceWrapperConfigurationFileUpdateJavaServiceWrapperEnvironmentScriptFileUpdateWindowsEnvironmentScriptFileUpdateUnixEnvironmentScriptFileUpdate
location - location of the script file
public 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 value
IOException
public 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.
IOException
public 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 definition
protected 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 file
null
if the line doesn't define an env var.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||