Class EnvUtils


  • public class EnvUtils
    extends Object
    This class is a unified provider of environment variables and system properties. It exposes a mutable copy of the environment variables. It also converts 'SOLR_FOO' variables to system properties 'solr.foo' and provide various convenience accessors for them.
    • Constructor Detail

      • EnvUtils

        public EnvUtils()
    • Method Detail

      • getEnvs

        public static SortedMap<String,​String> getEnvs()
        Get Solr's mutable copy of all environment variables.
        Returns:
        sorted map of environment variables
      • getEnv

        public static String getEnv​(String key)
        Get a single environment variable as string
      • getEnv

        public static String getEnv​(String key,
                                    String defaultValue)
        Get a single environment variable as string, or default
      • getEnvAsLong

        public static long getEnvAsLong​(String key)
        Get an environment variable as long
      • getEnvAsLong

        public static long getEnvAsLong​(String key,
                                        long defaultValue)
        Get an environment variable as long, or default value
      • getEnvAsBool

        public static boolean getEnvAsBool​(String key)
        Get an env var as boolean
      • getEnvAsBool

        public static boolean getEnvAsBool​(String key,
                                           boolean defaultValue)
        Get an env var as boolean, or default value
      • getEnvAsList

        public static List<String> getEnvAsList​(String key)
        Get comma separated strings from env as List
      • getEnvAsList

        public static List<String> getEnvAsList​(String key,
                                                List<String> defaultValue)
        Get comma separated strings from env as List
      • setEnv

        public static void setEnv​(String key,
                                  String value)
        Set an environment variable
      • setEnvs

        public static void setEnvs​(Map<String,​String> env)
        Set all environment variables
      • getProperties

        public static SortedMap<String,​String> getProperties()
        Get all Solr system properties as a sorted map
      • getProperty

        public static String getProperty​(String key)
        Get a property as string
      • getProperty

        public static String getProperty​(String key,
                                         String defaultValue)
        Get a property as string with a fallback value. All other getProperty* methods use this.
        Parameters:
        key - property key, which treats 'camelCase' the same as 'camel.case'
        defaultValue - fallback value if property is not found
      • getPropertyAsLong

        public static Long getPropertyAsLong​(String key)
        Get property as integer
      • getPropertyAsLong

        public static Long getPropertyAsLong​(String key,
                                             Long defaultValue)
        Get property as long, or default value
      • getPropertyAsBool

        public static Boolean getPropertyAsBool​(String key)
        Get property as boolean
      • getPropertyAsBool

        public static Boolean getPropertyAsBool​(String key,
                                                Boolean defaultValue)
        Get property as boolean, or default value
      • getPropertyAsList

        public static List<String> getPropertyAsList​(String key)
        Get comma separated strings from sysprop as List
        Returns:
        list of strings, or null if not found
      • getPropertyAsList

        public static List<String> getPropertyAsList​(String key,
                                                     List<String> defaultValue)
        Get comma separated strings from sysprop as List, or default value
        Returns:
        list of strings, or provided default if not found
      • envNameToSyspropName

        protected static String envNameToSyspropName​(String envName)