use of groovy.lang.Binding in project groovy-core by groovy.
the class FileSystemCompiler method generateCompilerConfigurationFromOptions.
public static CompilerConfiguration generateCompilerConfigurationFromOptions(CommandLine cli) throws IOException {
//
// Setup the configuration data
CompilerConfiguration configuration = new CompilerConfiguration();
if (cli.hasOption("classpath")) {
configuration.setClasspath(cli.getOptionValue("classpath"));
}
if (cli.hasOption('d')) {
configuration.setTargetDirectory(cli.getOptionValue('d'));
}
if (cli.hasOption("encoding")) {
configuration.setSourceEncoding(cli.getOptionValue("encoding"));
}
if (cli.hasOption("basescript")) {
configuration.setScriptBaseClass(cli.getOptionValue("basescript"));
}
// joint compilation parameters
if (cli.hasOption('j')) {
Map<String, Object> compilerOptions = new HashMap<String, Object>();
String[] opts = cli.getOptionValues("J");
compilerOptions.put("namedValues", opts);
opts = cli.getOptionValues("F");
compilerOptions.put("flags", opts);
configuration.setJointCompilationOptions(compilerOptions);
}
if (cli.hasOption("indy")) {
configuration.getOptimizationOptions().put("int", false);
configuration.getOptimizationOptions().put("indy", true);
}
if (cli.hasOption("configscript")) {
String path = cli.getOptionValue("configscript");
File groovyConfigurator = new File(path);
Binding binding = new Binding();
binding.setVariable("configuration", configuration);
CompilerConfiguration configuratorConfig = new CompilerConfiguration();
ImportCustomizer customizer = new ImportCustomizer();
customizer.addStaticStars("org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");
configuratorConfig.addCompilationCustomizers(customizer);
GroovyShell shell = new GroovyShell(binding, configuratorConfig);
shell.evaluate(groovyConfigurator);
}
return configuration;
}
use of groovy.lang.Binding in project groovy-core by groovy.
the class SecurityTestSupport method executeScript.
protected void executeScript(Class scriptClass, Permission missingPermission) {
try {
Script script = InvokerHelper.createScript(scriptClass, new Binding());
script.run();
// InvokerHelper.runScript(scriptClass, null);
} catch (AccessControlException ace) {
if (missingPermission != null && missingPermission.implies(ace.getPermission())) {
return;
} else {
fail(ace.toString());
}
}
if (missingPermission != null) {
fail("Should catch an AccessControlException");
}
}
use of groovy.lang.Binding in project groovy-core by groovy.
the class PlatformLineWriterTest method testPlatformLineWriter.
public void testPlatformLineWriter() throws IOException, ClassNotFoundException {
String LS = System.getProperty("line.separator");
Binding binding = new Binding();
binding.setVariable("first", "Tom");
binding.setVariable("last", "Adams");
StringWriter stringWriter = new StringWriter();
Writer platformWriter = new PlatformLineWriter(stringWriter);
GroovyShell shell = new GroovyShell(binding);
platformWriter.write(shell.evaluate("\"$first\\n$last\\n\"").toString());
platformWriter.flush();
assertEquals("Tom" + LS + "Adams" + LS, stringWriter.toString());
stringWriter = new StringWriter();
platformWriter = new PlatformLineWriter(stringWriter);
platformWriter.write(shell.evaluate("\"$first\\r\\n$last\\r\\n\"").toString());
platformWriter.flush();
assertEquals("Tom" + LS + "Adams" + LS, stringWriter.toString());
}
use of groovy.lang.Binding in project groovy-core by groovy.
the class Groovy1567_Bug method testGroovyScriptEngineVsGroovyShell.
public void testGroovyScriptEngineVsGroovyShell() throws IOException, ResourceException, ScriptException {
// @todo refactor this path
File currentDir = new File("./src/test/groovy/bugs");
String file = "bug1567_script.groovy";
Binding binding = new Binding();
GroovyShell shell = new GroovyShell(binding);
String[] test = null;
Object result = shell.run(new File(currentDir, file), test);
String[] roots = new String[] { currentDir.getAbsolutePath() };
GroovyScriptEngine gse = new GroovyScriptEngine(roots);
binding = new Binding();
// a MME was ensued here stating no 't.start()' was available
// in the script
gse.run(file, binding);
}
use of groovy.lang.Binding in project groovy-core by groovy.
the class ScriptLauncher method run.
public void run() {
final long id = Thread.currentThread().getId();
// run the script numIter times
for (int i = 0; i < numIter; i++) {
Builder builder = new Builder();
Binding binding = new Binding();
binding.setVariable("builder", builder);
script = InvokerHelper.createScript(scriptClass, binding);
script.run();
}
latch.countDown();
}
Aggregations