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
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.util.AbstractMap

    java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
  • Constructor Summary

    Constructors 
    Constructor Description
    EnvVars()  
    EnvVars​(java.lang.String... keyValuePairs)
    Builds an environment variables from an array of the form "key","value","key","value"...
    EnvVars​(java.util.Map<java.lang.String,​java.lang.String> m)  
    EnvVars​(EnvVars m)  
  • Method Summary

    Modifier and Type Method Description
    void addLine​(java.lang.String line)
    Takes a string that looks like "a=b" and adds that to this map.
    static EnvVars createCookie()
    Creates a magic cookie that can be used as the model environment variable when we later kill the processes.
    java.lang.String expand​(java.lang.String s)
    Expands the variables in the given string by using environment variables represented in 'this'.
    java.lang.String get​(java.lang.String key, java.lang.String defaultValue)
    Convenience message
    void override​(java.lang.String key, java.lang.String value)
    Overrides the current entry by the given entry.
    EnvVars overrideAll​(java.util.Map<java.lang.String,​java.lang.String> all)
    Overrides all values in the map by the given map.
    EnvVars overrideExpandingAll​(java.util.Map<java.lang.String,​java.lang.String> all)
    Overrides all values in the map by the given map.
    java.lang.String put​(java.lang.String key, java.lang.String value)  
    void putIfNotNull​(java.lang.String key, java.lang.String value)
    Add a key/value but only if the value is not-null.
    static void resolve​(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

    Methods inherited from class java.util.AbstractMap

    equals, hashCode, isEmpty, toString

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Map

    compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove
  • Constructor Details

    • 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 Details

    • 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. See override(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. See override(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:
      put in interface java.util.Map<java.lang.String,​java.lang.String>
      Overrides:
      put in class java.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.