Groovy Documentation

geb
[Groovy] Class ConfigurationLoader

java.lang.Object
  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 createBuildAdapter()

See Also:
Configuration
Browser


Nested Class Summary
static class ConfigurationLoader.UnableToLoadException

 
Property Summary
BuildAdapter buildAdapter

String environment

Properties properties

GroovyClassLoader specialClassLoader

 
Constructor Summary
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.

 
Method Summary
protected BuildAdapter createBuildAdapter(GroovyClassLoader classLoader)

Uses the build adapter factory to load a build adapter with the classLoader we were constructed with.

protected def createConf(groovy.util.ConfigObject rawConfig, GroovyClassLoader classLoader)

Creates a new Configuration backed by rawConfig with the properties and classLoader we were constructed with, 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)

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

protected Configuration doGetConfFromClass(String className)

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

Configuration getConf()

Creates a config using the default path for the config script and the default config class name.

Configuration getConf(String configFileResourcePath)

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

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)

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

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, def source)

protected Class tryToLoadClass(String className, ClassLoader loader)

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Property Detail

buildAdapter

final BuildAdapter buildAdapter


environment

final String environment


properties

final Properties properties


specialClassLoader

final GroovyClassLoader specialClassLoader


 
Constructor Detail

ConfigurationLoader

ConfigurationLoader()
Configures the loader using the defaults.
See Also:
ConfigurationLoader(java.lang.ClassLoader, java.lang.String, java.util.Properties)


ConfigurationLoader

ConfigurationLoader(String environment)
Configures the loader with the given environment for parsing config scripts, and defaults for everything else.
See Also:
ConfigurationLoader(java.lang.String, java.util.Properties, java.lang.ClassLoader)


ConfigurationLoader

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

createBuildAdapter

protected BuildAdapter createBuildAdapter(GroovyClassLoader classLoader)
Uses the build adapter factory to load a build adapter with the classLoader we were constructed with.


createConf

protected def createConf(groovy.util.ConfigObject rawConfig, GroovyClassLoader classLoader)
Creates a new Configuration backed by rawConfig with the properties and classLoader we were constructed with, and a build adapter.
See Also:
Configuration.Configuration


createSlurper

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.


createSlurper

protected groovy.util.ConfigSlurper createSlurper()
Creates a config slurper with environment we were constructed with (if any).


doGetConf

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.ConfigurationLoader.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)


doGetConfFromClass

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.ConfigurationLoader.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)


getConf

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.ConfigurationLoader.UnableToLoadException if the config script or class exists but could not be read or parsed.
See Also:
getConf(String)
getConfFromClass(String)


getConf

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.ConfigurationLoader.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)


getConf

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.ConfigurationLoader.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)


getConf

Configuration getConf(Class configClass, GroovyClassLoader classLoader)
Creates a config backed by a given class.
throws:
geb.ConfigurationLoader.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)


getConfFromClass

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.ConfigurationLoader.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)


getDefaultConf

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.


getDefaultConfigClassName

String getDefaultConfigClassName()
This implementation returns "GebConfig"


getDefaultConfigScriptResourcePath

String getDefaultConfigScriptResourcePath()
This implementation returns "GebConfig.groovy"


getDefaultEnvironment

protected String getDefaultEnvironment()
This implementation returns System.properties["geb.env"]


getDefaultProperties

protected Properties getDefaultProperties()
This implementation returns System.properties


getDefaultSpecialClassLoader

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


loadRawConfig

protected groovy.util.ConfigObject loadRawConfig(URL configLocation, GroovyClassLoader classLoader)
Reads the config scripts at configLocation with the createSlurper()
throws:
geb.ConfigurationLoader.UnableToLoadException if the config script could not be read.


loadRawConfig

protected groovy.util.ConfigObject loadRawConfig(Class configClass)
Reads the config class with the createSlurper()
throws:
geb.ConfigurationLoader.UnableToLoadException if the config class could not be read.


loadRawConfig

protected groovy.util.ConfigObject loadRawConfig(groovy.util.ConfigSlurper slurper, def source)


tryToLoadClass

protected Class tryToLoadClass(String className, ClassLoader loader)


 

Groovy API Documentation for geb-core 0.6.2 - Licensed under the Apache License, Version 2.0 - http://www.gebish.org