Package groovy.lang

Examples of groovy.lang.Script


        final GroovyClassLoader classLoader = new GroovyClassLoader(baseClassLoader);
        addClassPathes(classLoader);
       
        final GroovyShell groovy = new GroovyShell(classLoader, new Binding(), configuration);
        try {
            final Script script = groovy.parse(txt, scriptName);
            script.setProperty("ant", new AntBuilder(this));
            script.setProperty("project", project);
            script.setProperty("properties", new AntProjectPropertiesDelegate(project));
            script.setProperty("target", getOwningTarget());
            script.setProperty("task", this);
            script.setProperty("args", cmdline.getCommandline());
            if (mavenPom != null) {
                script.setProperty("pom", mavenPom);
            }
            script.run();
        }
        catch (final MissingMethodException e) {
            // not a script, try running through run method but properties will not be available
            groovy.run(txt, scriptName, cmdline.getCommandline());
        }
View Full Code Here


            } else {
                LOG.fine("eval() - Using cached script...");
            }
            //can't cache the script because the context may be different.
            //but don't bother loading parsing the class again
            Script s = InvokerHelper.createScript(scriptClass, context);
            return s.run();
        } catch (Exception e) {
            throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
        }
    }
View Full Code Here

        mock.startElement("", "module", "module", attrs);
        mock.endElement("", "module", "module");

        replayControls();

        Script script = new GroovyShell().parse("processor.module(id:'basic', version:'1.0.0')");

        runScript(script, mock);
    }
View Full Code Here

        parser.initialize(resource, new DefaultClassResolver());

        GroovyCodeSource source = new GroovyCodeSource(resource.getResourceURL());

        Script script = new GroovyShell().parse(source);

        try
        {
            runScript(script, parser);
View Full Code Here

        mock.startElement("", "module", "module", attrs);
        mock.endElement("", "module", "module");

        replayControls();

        Script script = new GroovyShell().parse("processor.module(id:'basic', version:'1.0.0')");

        runScript(script, mock);
    }
View Full Code Here

        parser.initialize(resource, new DefaultClassResolver());

        GroovyCodeSource source = new GroovyCodeSource(resource.getResourceURL());

        Script script = new GroovyShell().parse(source);

        try
        {
            runScript(script, parser);
View Full Code Here

    @SuppressWarnings({"unchecked","rawtypes"})
    public List<UrlMapping> evaluateMappings(Class theClass) {
        GroovyObject obj = (GroovyObject) BeanUtils.instantiateClass(theClass);

        if (obj instanceof Script) {
            Script script = (Script) obj;
            Binding b = new Binding();

            MappingCapturingClosure closure = new MappingCapturingClosure(script);
            b.setVariable("mappings", closure);
            script.setBinding(b);

            script.run();

            Closure mappings = closure.getMappings();

            Binding binding = script.getBinding();
            return evaluateMappings(script, mappings, binding);
        }

        throw new UrlMappingException("Unable to configure URL mappings for class [" + theClass +
                "]. A URL mapping must be an instance of groovy.lang.Script.");
View Full Code Here

    public static BeanBuilder reloadSpringResourcesConfig(RuntimeSpringConfiguration config, GrailsApplication application, Class<?> groovySpringResourcesClass) throws InstantiationException, IllegalAccessException {
        springGroovyResourcesBeanBuilder = new BeanBuilder(null, config,Thread.currentThread().getContextClassLoader());
        springGroovyResourcesBeanBuilder.setBinding(new Binding(CollectionUtils.newMap(
            "application", application,
            "grailsApplication", application))); // GRAILS-7550
        Script script = (Script) groovySpringResourcesClass.newInstance();
        script.run();
        Object beans = script.getProperty("beans");
        springGroovyResourcesBeanBuilder.beans((Closure<?>)beans);
        return springGroovyResourcesBeanBuilder;
    }
View Full Code Here

public class DefaultUrlMappingEvaluatorTests extends AbstractGrailsMappingTests {

    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());
    }
View Full Code Here

    }

    public void testRedirectMappings() throws Exception {
        GroovyShell shell = new GroovyShell();
        Binding binding = new Binding();
        Script script = shell.parse("mappings = {\n" +
                "\"/first\"(redirect:[controller: 'foo', action: 'bar'])\n" +
                "\"/second\"(redirect: '/bing/bang')\n" +
        "}");

        script.setBinding(binding);
        script.run();

        Closure closure = (Closure)binding.getVariable("mappings");
        List<UrlMapping> mappings = evaluator.evaluateMappings(closure);
        assertEquals(2, mappings.size());
        Object redirectInfo = mappings.get(0).getRedirectInfo();
View Full Code Here

TOP

Related Classes of groovy.lang.Script

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.