Package: groovy.util

## [Groovy] Class ConfigSlurper

- groovy.util.ConfigSlurper

-     class ConfigSlurper
      extends Object

  ConfigSlurper is a utility class for reading configuration files defined in the form of Groovy scripts. Configuration settings can be defined using dot notation or scoped using closures:

       grails.webflow.stateless = true
       smtp {
           mail.host = 'smtp.myisp.com'
           mail.auth.user = 'server'
       }
       resources.URL = 'http://localhost:80/resources'

  Settings can either be bound into nested maps or onto a specified JavaBean instance. In the latter case, an error will be thrown if a property cannot be bound.

  The configuration is a Groovy script and reading it runs it. That is what makes the dot notation and the closures above work, and it also means a configuration file can do anything the application itself can. Despite the name, this is not one of the data slurpers: JsonSlurper and its siblings map a document to values, whereas `parse` here compiles and executes what it is given. Read configuration only from somewhere you would accept code from.

  Since:
    1.5

- - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `GroovyClassLoader` | `classLoader` The class loader used to parse configuration scripts.
    `String` | `environment`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ConfigSlurper()` Constructs a new ConfigSlurper for the default environment.
    `ConfigSlurper(String env)` Constructs a new ConfigSlurper instance using the given environment

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `Map<String, String>` | `getConditionalBlockValues()` Returns the currently registered conditional block values.
    `` | `String` | `getEnvironment()` Returns the configured environment name.
    `` | `ConfigObject` | `parse(Properties properties)` Parses a ConfigObject instances from an instance of java.util.Properties
    `` | `ConfigObject` | `parse(String script)` Parse the given script as a string and return the configuration object
    `` | `ConfigObject` | `parse(Class scriptClass)` Create a new instance of the given script class and parse a configuration object from it
    `` | `ConfigObject` | `parse(Script script)` Parse the given script into a configuration object (a Map) (This method creates a new class to parse the script each time it is called.)
    `` | `ConfigObject` | `parse(URL scriptLocation)` Parses a Script represented by the given URL into a ConfigObject
    `` | `ConfigObject` | `parse(Script script, URL location)` Parses the passed groovy.lang.Script instance using the second argument to allow the ConfigObject to retain an reference to the original location other Groovy script
    `` | `void` | `registerConditionalBlock(String blockName, String blockValue)` Registers or removes a named conditional block value.
    `` | `void` | `setBinding(Map vars)` Sets any additional variables that should be placed into the binding when evaluating Config scripts
    `` | `void` | `setEnvironment(String environment)` Sets the configured environment name.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Property Detail

    - #### GroovyClassLoader classLoader

      The class loader used to parse configuration scripts.

    - #### String environment

  - ### Constructor Detail

    - #### ConfigSlurper()

      Constructs a new ConfigSlurper for the default environment.

    - #### ConfigSlurper(String env)

      Constructs a new ConfigSlurper instance using the given environment

      Parameters:
        `env` - The Environment to use

  - ### Method Detail

    - #### Map<String, String> getConditionalBlockValues()

      Returns the currently registered conditional block values.

      Returns:
        an unmodifiable view of the conditional block values

    - #### String getEnvironment()

      Returns the configured environment name.

      Returns:
        the environment name

    - #### ConfigObject parse(Properties properties)

      Parses a ConfigObject instances from an instance of java.util.Properties

      Parameters:
        `properties` - the properties to convert
      Returns:
        the parsed configuration object

    - #### ConfigObject parse(String script)

      Parse the given script as a string and return the configuration object

      Parameters:
        `script` - the script text to parse
      Returns:
        the parsed configuration object
      See Also:
        ConfigSlurper.parse

    - #### ConfigObject parse(Class scriptClass)

      Create a new instance of the given script class and parse a configuration object from it

      Parameters:
        `scriptClass` - the script class to instantiate
      Returns:
        the parsed configuration object
      See Also:
        ConfigSlurper.parse

    - #### ConfigObject parse(Script script)

      Parse the given script into a configuration object (a Map) (This method creates a new class to parse the script each time it is called.)

      Parameters:
        `script` - The script to parse
      Returns:
        A Map of maps that can be navigating with dot de-referencing syntax to obtain configuration entries

    - #### ConfigObject parse(URL scriptLocation)

      Parses a Script represented by the given URL into a ConfigObject

      Parameters:
        `scriptLocation` - The location of the script to parse
      Returns:
        The ConfigObject instance

    - #### @SuppressWarnings(value="Instanceof")
      ConfigObject parse(Script script, URL location)

      Parses the passed groovy.lang.Script instance using the second argument to allow the ConfigObject to retain an reference to the original location other Groovy script

      Parameters:
        `script` - The groovy.lang.Script instance
        `location` - The original location of the Script as a URL
      Returns:
        The ConfigObject instance

    - #### void registerConditionalBlock(String blockName, String blockValue)

      Registers or removes a named conditional block value.

      Parameters:
        `blockName` - the conditional block name
        `blockValue` - the value to match, or `null` to remove the registration

    - #### void setBinding(Map vars)

      Sets any additional variables that should be placed into the binding when evaluating Config scripts

      Parameters:
        `vars` - the variables to expose to configuration scripts

    - #### void setEnvironment(String environment)

      Sets the configured environment name.

      Parameters:
        `environment` - the environment name