use of groovy.lang.GroovyShell in project gradle by gradle.
the class ApiGroovyCompiler method applyConfigurationScript.
private void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
VersionNumber version = parseGroovyVersion();
if (version.compareTo(VersionNumber.parse("2.1")) < 0) {
throw new GradleException("Using a Groovy compiler configuration script requires Groovy 2.1+ but found Groovy " + version + "");
}
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);
try {
shell.evaluate(configScript);
} catch (Exception e) {
throw new GradleException("Could not execute Groovy compiler configuration script: " + configScript.getAbsolutePath(), e);
}
}
use of groovy.lang.GroovyShell in project grails-core by grails.
the class DefaultUrlMappingEvaluatorTests method testResourceMappingsWithVersionAndNamespace.
public void testResourceMappingsWithVersionAndNamespace() throws Exception {
GroovyShell shell = new GroovyShell();
Binding binding = new Binding();
// Resource Entry: "/api/foo"(resources:"foo", version:'1.0', namespace:'v1')
Script script = shell.parse("mappings = {\n" + "\"/api/foo\"(resources: 'foo', version: '1.0', namespace: 'v1')\n" + "}");
script.setBinding(binding);
script.run();
Closure closure = (Closure) binding.getVariable("mappings");
List<UrlMapping> mappings = evaluator.evaluateMappings(closure);
assertTrue(mappings.size() > 0);
//Check that version and namespace are correct for each mapping
for (UrlMapping mapping : mappings) {
assertEquals("1.0", mapping.getVersion());
assertEquals("v1", mapping.getNamespace());
}
}
use of groovy.lang.GroovyShell in project grails-core by grails.
the class DefaultUrlMappingEvaluatorTests method testNewMethod.
public void testNewMethod() throws Exception {
GroovyShell shell = new GroovyShell();
Binding binding = new Binding();
Script script = shell.parse("mappings = {\n" + " \"/$controller/$action?/$id?\" { \n" + " constraints {\n" + " id(matches:/\\d+/)\n" + " }\n" + " }\n" + "}\n");
script.setBinding(binding);
script.run();
Closure closure = (Closure) binding.getVariable("mappings");
List mappings = evaluator.evaluateMappings(closure);
assertEquals(1, mappings.size());
UrlMapping mapping = (UrlMapping) mappings.get(0);
assertNull(mapping.getActionName());
assertNull(mapping.getControllerName());
assertEquals("(*)", mapping.getUrlData().getTokens()[0]);
assertEquals("(*)?", mapping.getUrlData().getTokens()[1]);
assertEquals("(*)?", mapping.getUrlData().getTokens()[2]);
assertNotNull(mapping.getConstraints());
assertTrue(makeSureMatchesConstraintExistsOnId(mapping));
GrailsWebRequest r = GrailsWebMockUtil.bindMockWebRequest();
UrlMappingInfo info = mapping.match("/mycontroller");
info.configure(r);
assertEquals("mycontroller", info.getControllerName());
assertNull(mapping.match("/mycontroller").getActionName());
assertNull(mapping.match("/mycontroller").getId());
UrlMappingInfo info2 = mapping.match("/mycontroller/test");
info2.configure(r);
assertEquals("test", info2.getActionName());
assertNull(mapping.match("/mycontroller/test").getId());
assertEquals("234", mapping.match("/blog/test/234").getId());
}
use of groovy.lang.GroovyShell in project grails-core by grails.
the class DefaultUrlMappingEvaluatorTests method testNamedMappings.
public void testNamedMappings() throws Exception {
GroovyShell shell = new GroovyShell();
Binding binding = new Binding();
Script script = shell.parse("mappings = {\n" + "name firstMapping: \"/first/one\" {\n" + "}\n" + "\"/second/one\" {" + "}\n" + "name thirdMapping: \"/third/one\" {\n" + "}\n" + "}");
script.setBinding(binding);
script.run();
Closure closure = (Closure) binding.getVariable("mappings");
List mappings = evaluator.evaluateMappings(closure);
assertEquals(3, mappings.size());
}
use of groovy.lang.GroovyShell in project groovy-core by groovy.
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