use of groovy.lang.GroovyShell in project groovy by apache.
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'));
}
configuration.setParameters(cli.hasOption("pa"));
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[] namedValues = cli.getOptionValues("J");
compilerOptions.put("namedValues", namedValues);
String[] flags = cli.getOptionValues("F");
if (flags != null && cli.hasOption("pa")) {
flags = Arrays.copyOf(flags, flags.length + 1);
flags[flags.length - 1] = "parameters";
}
compilerOptions.put("flags", flags);
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.GroovyShell in project groovy by apache.
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.GroovyShell in project groovy by apache.
the class SeansBug method testBug.
public void testBug() throws Exception {
String code = "for (i in 1..10) \n{\n println(i)\n}";
GroovyShell shell = new GroovyShell();
shell.evaluate(code);
}
use of groovy.lang.GroovyShell in project groovy by apache.
the class ClassicGroovyTestGeneratorHelper method evaluate.
/** evaluate the source text against the classic AST with the JSR parser implementation*/
public Object evaluate(String theSrcText, String testName) throws Exception {
// fail early with a direct message if possible')
parse(theSrcText, testName);
GroovyShell groovy = new GroovyShell(new CompilerConfiguration());
return groovy.run(theSrcText, "main", new ArrayList());
}
use of groovy.lang.GroovyShell in project groovy by apache.
the class J2eeConsole method main.
public static void main(String[] args) {
if (args.length <= 0) {
System.out.println("Usage: home [configuaration] [localcopy]");
return;
}
String home = args[0];
Properties p = new Properties();
System.setProperty("openejb.home", home);
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.LocalInitialContextFactory");
p.put("openejb.loader", "embed");
p.put("openejb.home", home);
if (args.length > 1) {
String conf = args[1];
System.setProperty("openejb.configuration", conf);
p.put("openejb.configuration", conf);
}
if (args.length > 2) {
String copy = args[2];
System.setProperty("openejb.localcopy", copy);
p.put("openejb.localcopy", copy);
}
try {
InitialContext ctx = new InitialContext(p);
GroovyShell shell = new GroovyShell();
shell.setVariable("context", ctx);
//shell.evaluate("src/test/groovy/j2ee/CreateData.groovy");
//shell.evaluate("src/main/groovy/ui/Console.groovy");
GroovyObject console = (GroovyObject) InvokerHelper.invokeConstructorOf("groovy.ui.Console", null);
console.setProperty("shell", shell);
console.invokeMethod("run", null);
/*
*/
} catch (Exception e) {
System.out.println("Caught: " + e);
}
}
Aggregations