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));
}
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));
}
}
Aggregations