/** * Run a script identified by name with a given binding. * * @param scriptName name of the script to run * @param binding the binding to pass to the script * @return an object * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script */ public Object run(String scriptName, Binding binding) throws ResourceException, ScriptException { return createScript(scriptName, binding).run(); }
/** * Run a script identified by name with a given binding. * * @param scriptName name of the script to run * @param binding the binding to pass to the script * @return an object * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script */ public Object run(String scriptName, Binding binding) throws ResourceException, ScriptException { return createScript(scriptName, binding).run(); }
/** * Run a script identified by name with a given binding. * * @param scriptName name of the script to run * @param binding the binding to pass to the script * @return an object * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script */ public Object run(String scriptName, Binding binding) throws ResourceException, ScriptException { return createScript(scriptName, binding).run(); }
/** * Run a script identified by name with a given binding. * * @param scriptName name of the script to run * @param binding the binding to pass to the script * @return an object * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script */ public Object run(String scriptName, Binding binding) throws ResourceException, ScriptException { return createScript(scriptName, binding).run(); }
/** * Run a script identified by name with a given binding. * * @param scriptName name of the script to run * @param binding the binding to pass to the script * @return an object * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script */ public Object run(String scriptName, Binding binding) throws ResourceException, ScriptException { return createScript(scriptName, binding).run(); }
@Override public BlazeGroovyScript compile(Context context) throws BlazeException { try { // must be valid url... String path = context.scriptFile().toUri().toURL().toString(); Binding binding = new Binding(); // add small number of useful bindings // not sure its best practice to polute namespace at all //binding.setVariable("context", context); //binding.setVariable("log", context.logger()); //binding.setVariable("config", context.config()); Script script = script = this.groovy.createScript(path, binding); script.run(); return new BlazeGroovyScript(this, script); } catch (ResourceException | IOException | ScriptException e) { throw new BlazeException("Unable to compile groovy script", e); } } }
/** * Creates a Script with a given scriptName and binding. * * @param scriptName name of the script to run * @param binding the binding to pass to the script * @return the script object * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script */ @Override public synchronized final B createScript(final String scriptName, final Binding binding) throws ResourceException, ScriptException { final Script result; final Binding bindingUnion = binding == null ? rootBinding : concatBindings(rootBinding, binding); try (final SafeCloseable ignored = Utils.withContextClassLoader(getGroovyClassLoader())) { result = super.createScript(scriptName, bindingUnion); } catch (final ResourceException | ScriptException e) { throw e; } catch (final Exception e) { throw new ScriptException(e); } final B typedResult = baseScriptClass.cast(result); interceptCreate(typedResult); return typedResult; }
/** * Creates a Script with a given scriptName and binding. * * @param scriptName name of the script to run * @param binding the binding to pass to the script * @param baseScriptClass Parent class of Groovy script. * @return the script object * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script */ public synchronized final <C extends B> C createScript(final String scriptName, final Binding binding, final Class<C> baseScriptClass) throws ResourceException, ScriptException{ final Script result; final Binding bindingUnion = binding == null ? rootBinding : concatBindings(rootBinding, binding); try(final SafeCloseable ignored = Utils.withContextClassLoader(getGroovyClassLoader()); final SafeCloseable ignored2 = withBaseClass(baseScriptClass)) { result = super.createScript(scriptName, bindingUnion); } catch (final ResourceException | ScriptException e){ throw e; } catch (final Exception e) { throw new ScriptException(e); } final C typedResult = baseScriptClass.cast(result); interceptCreate(typedResult); return typedResult; }