Search in sources :

Example 1 with DelegatingScript

use of org.spockframework.builder.DelegatingScript in project spock by spockframework.

the class RunContext method createBottomContext.

// This context will stay around until the thread dies.
// It would be more accurate to remove the context once the test run
// has finished, but the JUnit Runner SPI doesn't provide an adequate hook.
// That said, since most environments fork a new JVM for each test run,
// this shouldn't be much of a problem in practice.
private static RunContext createBottomContext() {
    File spockUserHome = SpockUserHomeUtil.getSpockUserHome();
    DelegatingScript script = new ConfigurationScriptLoader(spockUserHome).loadAutoDetectedScript();
    List<Class<?>> classes = new ExtensionClassesLoader().loadClassesFromDefaultLocation();
    return new RunContext("default", spockUserHome, script, classes);
}
Also used : DelegatingScript(org.spockframework.builder.DelegatingScript) File(java.io.File)

Example 2 with DelegatingScript

use of org.spockframework.builder.DelegatingScript in project spock by spockframework.

the class ConfigurationScriptLoader method loadScriptFromClassPathLocation.

@Nullable
private DelegatingScript loadScriptFromClassPathLocation(String location) {
    URL url = this.getClass().getClassLoader().getResource(location);
    if (url == null)
        return null;
    GroovyShell shell = createShell();
    try {
        return (DelegatingScript) shell.parse(new GroovyCodeSource(url));
    } catch (IOException e) {
        throw new ConfigurationException("Error reading configuration script '%s'", location);
    } catch (CompilationFailedException e) {
        throw new ConfigurationException("Error compiling configuration script '%s'", location);
    }
}
Also used : ConfigurationException(spock.config.ConfigurationException) DelegatingScript(org.spockframework.builder.DelegatingScript) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) IOException(java.io.IOException) URL(java.net.URL) Nullable(org.spockframework.util.Nullable)

Example 3 with DelegatingScript

use of org.spockframework.builder.DelegatingScript in project spock by spockframework.

the class ConfigurationScriptLoader method loadScriptFromSystemPropertyInducedLocation.

@Nullable
private DelegatingScript loadScriptFromSystemPropertyInducedLocation(String propertyKey) {
    String location = System.getProperty(propertyKey);
    if (location == null || location.length() == 0)
        return null;
    DelegatingScript script = loadScriptFromClassPathLocation(location);
    if (script != null)
        return script;
    script = loadScriptFromFileSystemLocation(location);
    if (script != null)
        return script;
    throw new ConfigurationException("Cannot find configuration script '%s'", location);
}
Also used : ConfigurationException(spock.config.ConfigurationException) DelegatingScript(org.spockframework.builder.DelegatingScript) Nullable(org.spockframework.util.Nullable)

Example 4 with DelegatingScript

use of org.spockframework.builder.DelegatingScript in project spock by spockframework.

the class ConfigurationScriptLoader method loadAutoDetectedScript.

@Nullable
public DelegatingScript loadAutoDetectedScript() {
    DelegatingScript script = loadScriptFromSystemPropertyInducedLocation(configPropertyKey);
    if (script != null)
        return script;
    script = loadScriptFromClassPathLocation(classPathLocation);
    if (script != null)
        return script;
    script = loadScriptFromFileSystemLocation(fileSystemLocation);
    if (script != null)
        return script;
    return null;
}
Also used : DelegatingScript(org.spockframework.builder.DelegatingScript) Nullable(org.spockframework.util.Nullable)

Example 5 with DelegatingScript

use of org.spockframework.builder.DelegatingScript in project spock by spockframework.

the class ConfigurationScriptLoader method loadScriptFromFileSystemLocation.

@Nullable
private DelegatingScript loadScriptFromFileSystemLocation(String location) {
    File file = new File(location);
    try {
        if (!file.exists())
            return null;
    } catch (AccessControlException e) {
        // so let's just assume it's not there and continue
        return null;
    }
    GroovyShell shell = createShell();
    try {
        return (DelegatingScript) shell.parse(file);
    } catch (IOException e) {
        throw new ConfigurationException("Error reading configuration script '%s'", location);
    } catch (CompilationFailedException e) {
        throw new ConfigurationException("Error compiling configuration script '%s'", location);
    }
}
Also used : ConfigurationException(spock.config.ConfigurationException) DelegatingScript(org.spockframework.builder.DelegatingScript) AccessControlException(java.security.AccessControlException) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) IOException(java.io.IOException) File(java.io.File) Nullable(org.spockframework.util.Nullable)

Aggregations

DelegatingScript (org.spockframework.builder.DelegatingScript)5 Nullable (org.spockframework.util.Nullable)4 ConfigurationException (spock.config.ConfigurationException)3 File (java.io.File)2 IOException (java.io.IOException)2 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)2 URL (java.net.URL)1 AccessControlException (java.security.AccessControlException)1