Package: geb

## [Groovy] Class ConfigurationLoader

- geb.ConfigurationLoader

-     class ConfigurationLoader
      extends Object

  Manages the process of creating Configuration objects, which control the runtime behaviour of Geb.

  Typically usage of this class is hidden from the user as the Browser uses this class internally to load configuration based on its construction. If however custom configuration loading mechanics are necessary, users can use this class or a subclass of to create a Configuration object and construct the Browser with that.

  Another avenue for custom configuration is usage of the build adapter. The build adapter that will be used with any loaded configurations will be what is provided by ConfigurationLoader.createBuildAdapter.

  See Also:
    Configuration
    Browser

- - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `String` | `environment`
    `Properties` | `properties`
    `GroovyClassLoader` | `specialClassLoader`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ConfigurationLoader ()` Configures the loader using the defaults.
    `ConfigurationLoader (String environment)` Configures the loader with the given environment for parsing config scripts, and defaults for everything else.
    `ConfigurationLoader (String environment, Properties properties, GroovyClassLoader classLoader)` Sets the loader environment.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected BuildAdapter` | `createBuildAdapter(GroovyClassLoader classLoader)` Uses the build adapter factory to load a build adapter with the `classLoader` passed in.
    `` | `protected Object` | `createConf(groovy.util.ConfigObject rawConfig, GroovyClassLoader classLoader)` Creates a new Configuration backed by `rawConfig` with the `properties` we were constructed with, the `classLoader` passed in and a build adapter.
    `` | `protected groovy.util.ConfigSlurper` | `createSlurper(GroovyClassLoader classLoader)` Creates a config slurper with environment we were constructed with (if any) and sets the slurpers classloader to the classloader we were constructed with.
    `` | `protected groovy.util.ConfigSlurper` | `createSlurper()` Creates a config slurper with environment we were constructed with (if any).
    `` | `protected Configuration` | `doGetConf(String configFileResourcePath)`
    `` | `protected Configuration` | `doGetConfFromClass(String className)`
    `` | `Configuration` | `getConf()` Creates a config using the default path for the config script and the default config class name.
    `` | `Configuration` | `getConf(String configFileResourcePath)`
    `` | `Configuration` | `getConf(URL configLocation, GroovyClassLoader classLoader)` Creates a config backed by the config script at the given URL.
    `` | `Configuration` | `getConf(Class configClass, GroovyClassLoader classLoader)` Creates a config backed by a given class.
    `` | `Configuration` | `getConfFromClass(String className)`
    `` | `protected Configuration` | `getDefaultConf()` Result of this method is used as the default configuration when there is no configuration script or class.
    `` | `String` | `getDefaultConfigClassName()` This implementation returns `"GebConfig"`
    `` | `String` | `getDefaultConfigScriptResourcePath()` This implementation returns `"GebConfig.groovy"`
    `` | `protected String` | `getDefaultEnvironment()` This implementation returns `System.properties["geb.env"]`
    `` | `protected Properties` | `getDefaultProperties()` This implementation returns `System.properties`
    `` | `protected GroovyClassLoader` | `getDefaultSpecialClassLoader()` This implementation returns a new GroovyClassLoader which uses the `Thread.currentThread ( ) .contextClassLoader` as the parent.
    `` | `protected groovy.util.ConfigObject` | `loadRawConfig(URL configLocation, GroovyClassLoader classLoader)` Reads the config scripts at `configLocation` with the createSlurper()
    `` | `protected groovy.util.ConfigObject` | `loadRawConfig(Class configClass)` Reads the config class with the createSlurper()
    `` | `protected groovy.util.ConfigObject` | `loadRawConfig(groovy.util.ConfigSlurper slurper, URL source)`
    `` | `protected groovy.util.ConfigObject` | `loadRawConfig(groovy.util.ConfigSlurper slurper, Class source)`
    `` | `protected Class` | `tryToLoadClass(String className, ClassLoader loader)`

  - ### Inherited Methods Summary

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

- - ### Property Detail

    - #### final String environment

    - #### final Properties properties

    - #### final GroovyClassLoader specialClassLoader

  - ### Constructor Detail

    - #### ConfigurationLoader()

      Configures the loader using the defaults.

      See Also:
        ( ClassLoader , String , Properties )

    - #### ConfigurationLoader(String environment)

      Configures the loader with the given environment for parsing config scripts, and defaults for everything else.

      See Also:
        ( String , Properties , ClassLoader )

    - #### ConfigurationLoader(String environment, Properties properties, GroovyClassLoader classLoader)

      Sets the loader environment.

      If any of the parameters are `null`, the appropriate `getDefault«something»()` method will be used to supply the value.

      Parameters:
        `classLoader` - The loader to use to find classpath resources and to load the build adapter
        `environment` - If loading a config script, the environment to load it with
        `properties` - The properties given to created Configuration objects
      See Also:
        getDefaultEnvironment()
        getDefaultProperties()

  - ### Method Detail

    - #### protected BuildAdapter createBuildAdapter(GroovyClassLoader classLoader)

      Uses the build adapter factory to load a build adapter with the `classLoader` passed in.

    - #### protected Object createConf(groovy.util.ConfigObject rawConfig, GroovyClassLoader classLoader)

      Creates a new Configuration backed by `rawConfig` with the `properties` we were constructed with, the `classLoader` passed in and a build adapter.

      See Also:
        Configuration.Configuration

    - #### protected groovy.util.ConfigSlurper createSlurper(GroovyClassLoader classLoader)

      Creates a config slurper with environment we were constructed with (if any) and sets the slurpers classloader to the classloader we were constructed with.

    - #### protected groovy.util.ConfigSlurper createSlurper()

      Creates a config slurper with environment we were constructed with (if any).

    - #### protected Configuration doGetConf(String configFileResourcePath)

      Creates a config backed by the classpath config script resource at the given path. This method is used by getConf(String).

      The resource is first searched for using the special class loader (thread context loader by default), and then the class loader of this class if it wasn't found. If no classpath resource can be found at the given path null is returned.

      The class loader that is used is then propagated to the created configuration object. This means that if it is the special loader it must have the same copy of the Geb classes as this class loader and any other classes Geb depends on.

      throws:
        geb.error.UnableToLoadException if the config script exists but could not be read or parsed.
      Parameters:
        `configFileResourcePath` - the classpath relative path to the config script to use (if `null`, default will be used).
      See Also:
        getConf(URL, GroovyClassLoader)
        getConf(String)

    - #### protected Configuration doGetConfFromClass(String className)

      Creates a config backed by the config class with a given name. This method is used by getConfFromClass(String).

      The class is first searched for using the special class loader (thread context loader by default), and then the class loader of this class if it wasn't found. If no such class can be found, null is returned.

      The class loader that is used is then propagated to the created configuration object. This means that if it is the special loader it must have the same copy of the Geb classes as this class loader and any other classes Geb depends on.

      throws:
        geb.error.UnableToLoadException if the config script exists but could not be read or parsed.
      Parameters:
        `configFileResourcePath` - the classpath relative path to the config script to use (if `null`, default will be used).
      See Also:
        getConfFromClass(String)
        getConf(Class, GroovyClassLoader)

    - #### Configuration getConf()

      Creates a config using the default path for the config script and the default config class name. It loads the configuration from class only if the configuration script was not found.

      Uses getDefaultConfigScriptResourcePath() for the path and getDefaultConfigClassName() for the class name.

      throws:
        geb.error.UnableToLoadException if the config script or class exists but could not be read or parsed.
      See Also:
        getConf(String)
        getConfFromClass(String)

    - #### Configuration getConf(String configFileResourcePath)

      Creates a config backed by the classpath config script resource at the given path.

      The resource is first searched for using the special class loader (thread context loader by default), and then the class loader of this class if it wasn't found. If no classpath resource can be found at the given path, an empty config object will be used with the class loader of this class.

      The class loader that is used is then propagated to the created configuration object. This means that if it is the special loader it must have the same copy of the Geb classes as this class loader and any other classes Geb depends on.

      throws:
        geb.error.UnableToLoadException if the config script exists but could not be read or parsed.
      Parameters:
        `configFileResourcePath` - the classpath relative path to the config script to use (if `null`, default will be used).
      See Also:
        getConf(URL, GroovyClassLoader)
        getConfFromClass(String)

    - #### Configuration getConf(URL configLocation, GroovyClassLoader classLoader)

      Creates a config backed by the config script at the given URL.

      If URL is `null` or doesn't exist, an exception will be thrown.

      throws:
        geb.error.UnableToLoadException if the config script exists but could not be read or parsed.
      Parameters:
        `configLocation` - The absolute URL to the config script to use for the config (cannot be `null`)
        `classLoader` - The class loader to load the config script with (must be the same or a child of the class loader of this class)

    - #### Configuration getConf(Class configClass, GroovyClassLoader classLoader)

      Creates a config backed by a given class.

      throws:
        geb.error.UnableToLoadException when config class cannot be read
      Parameters:
        `configClass` - Class that contains configuration
        `classLoader` - The class loader to load the config script with (must be the same or a child of the class loader of this class)

    - #### Configuration getConfFromClass(String className)

      Creates a config backed by the config class with a given name.

      The class is first searched for using the special class loader (thread context loader by default), and then the class loader of this class if it wasn't found. If no such class can be found, an empty config object will be used with the class loader of this class.

      The class loader that is used is then propagated to the created configuration object. This means that if it is the special loader it must have the same copy of the Geb classes as this class loader and any other classes Geb depends on.

      throws:
        geb.error.UnableToLoadException if the config script exists but could not be read or parsed.
      Parameters:
        `configFileResourcePath` - the classpath relative path to the config script to use (if `null`, default will be used).
      See Also:
        getConf(Class, GroovyClassLoader)
        getConf(String)

    - #### protected Configuration getDefaultConf()

      Result of this method is used as the default configuration when there is no configuration script or class. This implementation returns a configuration as if the loaded configuration script/class was empty.

    - #### String getDefaultConfigClassName()

      This implementation returns `"GebConfig"`

    - #### String getDefaultConfigScriptResourcePath()

      This implementation returns `"GebConfig.groovy"`

    - #### protected String getDefaultEnvironment()

      This implementation returns `System.properties["geb.env"]`

    - #### protected Properties getDefaultProperties()

      This implementation returns `System.properties`

    - #### protected GroovyClassLoader getDefaultSpecialClassLoader()

      This implementation returns a new GroovyClassLoader which uses the `Thread.currentThread ( ) .contextClassLoader` as the parent.

    - #### protected groovy.util.ConfigObject loadRawConfig(URL configLocation, GroovyClassLoader classLoader)

      Reads the config scripts at `configLocation` with the createSlurper()

      throws:
        geb.error.UnableToLoadException if the config script could not be read.

    - #### protected groovy.util.ConfigObject loadRawConfig(Class configClass)

      Reads the config class with the createSlurper()

      throws:
        geb.error.UnableToLoadException if the config class could not be read.

    - #### protected groovy.util.ConfigObject loadRawConfig(groovy.util.ConfigSlurper slurper, URL source)

    - #### protected groovy.util.ConfigObject loadRawConfig(groovy.util.ConfigSlurper slurper, Class source)

    - #### protected Class tryToLoadClass(String className, ClassLoader loader)