Package groovy.lang

Examples of groovy.lang.Script


            while (true) {
                // Create one script per socket connection.
                // This is purposefully not caching the Script
                // so that the script source file can be changed on the fly,
                // as each connection is made to the server.
                Script script;
                if (isScriptFile) {
                    GroovyMain gm = new GroovyMain();
                    script = groovy.parse(DefaultGroovyMethods.getText(gm.huntForTheScriptFile(scriptFilenameOrText)));
                } else {
                    script = groovy.parse(scriptFilenameOrText);
View Full Code Here


        }
    }

    private void parseAndRunScript(GroovyShell shell, String txt, Object mavenPom, String scriptName, File scriptFile, AntBuilder builder) {
        try {
            final Script script;
            if (scriptFile != null) {
                script = shell.parse(scriptFile);
            } else {
                script = shell.parse(txt, scriptName);
            }
            final Project project = getProject();
            script.setProperty("ant", builder);
            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 mme) {
            // not a script, try running through run method but properties will not be available
            if (scriptFile != null) {
                try {
View Full Code Here

    @SuppressWarnings({"unchecked"})
    @Override public ExecutableScript executable(Object compiledScript, Map<String, Object> vars) {
        try {
            Class scriptClass = (Class) compiledScript;
            Script scriptObject = (Script) scriptClass.newInstance();
            Binding binding = new Binding();
            if (vars != null) {
                binding.getVariables().putAll(vars);
            }
            scriptObject.setBinding(binding);
            return new GroovyExecutableScript(scriptObject);
        } catch (Exception e) {
            throw new ScriptException("failed to build executable script", e);
        }
    }
View Full Code Here

    }

    @Override public SearchScript search(Object compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars) {
        try {
            Class scriptClass = (Class) compiledScript;
            Script scriptObject = (Script) scriptClass.newInstance();
            Binding binding = new Binding();
            binding.getVariables().putAll(lookup.asMap());
            if (vars != null) {
                binding.getVariables().putAll(vars);
            }
            scriptObject.setBinding(binding);
            return new GroovySearchScript(scriptObject, lookup);
        } catch (Exception e) {
            throw new ScriptException("failed to build search script", e);
        }
    }
View Full Code Here

    }

    @Override public Object execute(Object compiledScript, Map<String, Object> vars) {
        try {
            Class scriptClass = (Class) compiledScript;
            Script scriptObject = (Script) scriptClass.newInstance();
            Binding binding = new Binding(vars);
            scriptObject.setBinding(binding);
            return scriptObject.run();
        } catch (Exception e) {
            throw new ScriptException("failed to execute script", e);
        }
    }
View Full Code Here

  @SuppressWarnings({ "rawtypes", "unchecked" })
  protected void resolveVariables(List arg) {
    List temp = new ArrayList();
    GroovyShell gs = new GroovyShell(getBinding());
    for(Object obj:arg) {
      Script scr = gs.parse("\""+(String)obj+"\"");
      try {
        temp.add(scr.run().toString());
      }
      catch(MissingPropertyException e) {
        throw new SqoopException(ClientError.CLIENT_0004, e.getMessage(), e);
      }
    }
View Full Code Here

    protected String assertionFailureMessage(Exchange exchange) {
        return "groovy: " + text;
    }

    public <T> T evaluate(Exchange exchange, Class<T> type) {
        Script script = ExchangeHelper.newInstance(exchange, scriptType);
        // lets configure the script
        configure(exchange, script);
        Object value = script.run();
        return exchange.getContext().getTypeConverter().convertTo(type, value);
    }
View Full Code Here

        }
    }

    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 {
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

        contexts.set((LinkedList<Map<String, Object>>) data.get("contexts"));
    }

    public Object build(Class viewClass) {
        if (Script.class.isAssignableFrom(viewClass)) {
            Script script = InvokerHelper.createScript(viewClass, this);
            return build(script);
        } else {
            throw new RuntimeException("Only scripts can be executed via build(Class)");
        }
    }
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.