Class EnvVars
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.TreeMap<java.lang.String,java.lang.String>
-
- org.ow2.proactive.process_tree_killer.EnvVars
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<java.lang.String,java.lang.String>,java.util.NavigableMap<java.lang.String,java.lang.String>,java.util.SortedMap<java.lang.String,java.lang.String>
public class EnvVars extends java.util.TreeMap<java.lang.String,java.lang.String>Environment variables.While all the platforms I tested (Linux 2.6, Solaris, and Windows XP) have the case sensitive environment variable table, Windows batch script handles environment variable in the case preserving but case insensitive way (that is, cmd.exe can get both FOO and foo as environment variables when it's launched, and the "set" command will display it accordingly, but "echo %foo%" results in echoing the value of "FOO", not "foo" — this is presumably caused by the behavior of the underlying Win32 API GetEnvironmentVariable acting in case insensitive way.) Windows users are also used to write environment variable case-insensitively (like %Path% vs %PATH%), and you can see many documents on the web that claims Windows environment variables are case insensitive.
So for a consistent cross platform behavior, it creates the least confusion to make the table case insensitive but case preserving.
In Jenkins, often we need to build up "environment variable overrides" on master, then to execute the process on slaves. This causes a problem when working with variables like PATH. So to make this work, we introduce a special convention PATH+FOO — all entries that starts with PATH+ are merged and prepended to the inherited PATH variable, on the process where a new process is executed.
- Author:
- Kohsuke Kawaguchi
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLine(java.lang.String line)Takes a string that looks like "a=b" and adds that to this map.static EnvVarscreateCookie()Creates a magic cookie that can be used as the model environment variable when we later kill the processes.java.lang.Stringexpand(java.lang.String s)Expands the variables in the given string by using environment variables represented in 'this'.java.lang.Stringget(java.lang.String key, java.lang.String defaultValue)Convenience messagevoidoverride(java.lang.String key, java.lang.String value)Overrides the current entry by the given entry.EnvVarsoverrideAll(java.util.Map<java.lang.String,java.lang.String> all)Overrides all values in the map by the given map.EnvVarsoverrideExpandingAll(java.util.Map<java.lang.String,java.lang.String> all)Overrides all values in the map by the given map.java.lang.Stringput(java.lang.String key, java.lang.String value)voidputIfNotNull(java.lang.String key, java.lang.String value)Add a key/value but only if the value is not-null.static voidresolve(java.util.Map<java.lang.String,java.lang.String> env)Resolves environment variables against each other.-
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clear, clone, comparator, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, forEach, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, putAll, remove, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, values
-
-
-
-
Constructor Detail
-
EnvVars
public EnvVars()
-
EnvVars
public EnvVars(java.util.Map<java.lang.String,java.lang.String> m)
-
EnvVars
public EnvVars(EnvVars m)
-
EnvVars
public EnvVars(java.lang.String... keyValuePairs)
Builds an environment variables from an array of the form "key","value","key","value"...
-
-
Method Detail
-
override
public void override(java.lang.String key, java.lang.String value)Overrides the current entry by the given entry.Handles PATH+XYZ notation.
-
overrideAll
public EnvVars overrideAll(java.util.Map<java.lang.String,java.lang.String> all)
Overrides all values in the map by the given map. Seeoverride(String, String).- Returns:
- this
-
overrideExpandingAll
public EnvVars overrideExpandingAll(java.util.Map<java.lang.String,java.lang.String> all)
Overrides all values in the map by the given map. Expressions in values will be expanded. Seeoverride(String, String).- Returns:
- this
-
resolve
public static void resolve(java.util.Map<java.lang.String,java.lang.String> env)
Resolves environment variables against each other.
-
get
public java.lang.String get(java.lang.String key, java.lang.String defaultValue)Convenience message- Since:
- 1.485
-
put
public java.lang.String put(java.lang.String key, java.lang.String value)- Specified by:
putin interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
putin classjava.util.TreeMap<java.lang.String,java.lang.String>
-
putIfNotNull
public void putIfNotNull(java.lang.String key, java.lang.String value)Add a key/value but only if the value is not-null. Otherwise no-op.- Since:
- 1.556
-
addLine
public void addLine(java.lang.String line)
Takes a string that looks like "a=b" and adds that to this map.
-
expand
public java.lang.String expand(java.lang.String s)
Expands the variables in the given string by using environment variables represented in 'this'.
-
createCookie
public static EnvVars createCookie()
Creates a magic cookie that can be used as the model environment variable when we later kill the processes.
-
-