Search in sources :

Example 6 with GroovyCodeSource

use of groovy.lang.GroovyCodeSource in project groovy-core by groovy.

the class InvokerHelperTest method testCreateScriptWithScriptClass.

public void testCreateScriptWithScriptClass() {
    GroovyClassLoader classLoader = new GroovyClassLoader();
    String controlProperty = "text";
    String controlValue = "I am a script";
    String code = controlProperty + " = '" + controlValue + "'";
    GroovyCodeSource codeSource = new GroovyCodeSource(code, "testscript", "/groovy/shell");
    Class scriptClass = classLoader.parseClass(codeSource, false);
    Script script = InvokerHelper.createScript(scriptClass, new Binding(bindingVariables));
    assertEquals(bindingVariables, script.getBinding().getVariables());
    script.run();
    assertEquals(controlValue, script.getProperty(controlProperty));
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) Binding(groovy.lang.Binding) Script(groovy.lang.Script) GroovyCodeSource(groovy.lang.GroovyCodeSource)

Example 7 with GroovyCodeSource

use of groovy.lang.GroovyCodeSource in project hudson-2.x by hudson.

the class GroovyInitScript method init.

@Initializer(after = JOB_LOADED)
public static void init(Hudson h) throws IOException {
    URL bundledInitScript = h.servletContext.getResource("/WEB-INF/init.groovy");
    if (bundledInitScript != null) {
        LOGGER.info("Executing bundled init script: " + bundledInitScript);
        execute(new GroovyCodeSource(bundledInitScript));
    }
    File initScript = new File(h.getRootDir(), "init.groovy");
    if (initScript.exists()) {
        LOGGER.info("Executing " + initScript);
        execute(new GroovyCodeSource(initScript));
    }
}
Also used : GroovyCodeSource(groovy.lang.GroovyCodeSource) File(java.io.File) URL(java.net.URL) Initializer(hudson.init.Initializer)

Aggregations

GroovyCodeSource (groovy.lang.GroovyCodeSource)7 GroovyClassLoader (groovy.lang.GroovyClassLoader)3 File (java.io.File)3 Binding (groovy.lang.Binding)2 GroovyObject (groovy.lang.GroovyObject)2 Script (groovy.lang.Script)2 Initializer (hudson.init.Initializer)1 IOException (java.io.IOException)1 URL (java.net.URL)1 CodeSource (java.security.CodeSource)1 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)1 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)1 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)1 MultipleCompilationErrorsException (org.codehaus.groovy.control.MultipleCompilationErrorsException)1 GradleException (org.gradle.api.GradleException)1 Transformer (org.gradle.groovy.scripts.Transformer)1