/** * Initialize the engine. */ public void initialize(final BSFManager mgr, String lang, Vector declaredBeans) throws BSFException { super.initialize(mgr, lang, declaredBeans); ClassLoader parent = mgr.getClassLoader(); if (parent == null) parent = GroovyShell.class.getClassLoader(); setLoader(mgr, parent); execScripts = new HashMap<Object, Class>(); evalScripts = new HashMap<Object, Class>(); context = shell.getContext(); // create a shell // register the mgr with object name "bsf" context.setVariable("bsf", new BSFFunctions(mgr, this)); int size = declaredBeans.size(); for (int i = 0; i < size; i++) { declareBean((BSFDeclaredBean) declaredBeans.elementAt(i)); } }
private String eval(ShellSession session, String name, String def) { try { GroovyShell shell = getGroovyShell(session); Object ret = shell.getContext().getVariable(name); if (ret instanceof Closure) { log.log(Level.FINEST, "Invoking " + name + " closure"); Closure c = (Closure)ret; ret = c.call(); } else if (ret == null) { log.log(Level.FINEST, "No " + name + " will use empty"); return def; } return String.valueOf(ret); } catch (Exception e) { log.log(Level.SEVERE, "Could not get a " + name + " message, will use empty", e); return def; } }
public void open(CommandContext<? super Object> consumer) throws IOException, CommandException { this.consumer = (CommandContext<Object>)consumer; GroovyShell shell = GroovyCompiler.getGroovyShell(session); ShellBinding binding = (ShellBinding)shell.getContext(); binding.setCurrent(new InvocationContextImpl<Object>(this.consumer)); Object o; try { o = shell.evaluate(request); } finally { binding.setCurrent(null); } if (o != null) { try { consumer.provide(o); } catch (IOException e) { throw e; } catch (CommandException e) { throw e; } catch (Exception e) { throw new CommandException(ErrorKind.EVALUATION, "An error occured during the evalution of '" + request + "'", e); } } } public void close() throws IOException, CommandException {
private String eval(ShellSession session, String name, String def) { try { GroovyShell shell = getGroovyShell(session); Object ret = shell.getContext().getVariable(name); if (ret instanceof Closure) { log.log(Level.FINEST, "Invoking " + name + " closure"); Closure c = (Closure)ret; ret = c.call(); } else if (ret == null) { log.log(Level.FINEST, "No " + name + " will use empty"); return def; } return String.valueOf(ret); } catch (Exception e) { log.log(Level.SEVERE, "Could not get a " + name + " message, will use empty", e); return def; } }
/** * Displays the current binding used when instanciating the shell. */ private void displayBinding() { Binding context = shell.getContext(); Map variables = context.getVariables(); Set set = variables.keySet(); if (set.isEmpty()) { out.println(MESSAGES.getMessage("command.binding.binding_empty")); } else { out.println(MESSAGES.getMessage("command.binding.available_variables")); Iterator iter = set.iterator(); while (iter.hasNext()) { Object key = iter.next(); out.print(" "); out.print(key); out.print(" = "); out.println(variables.get(key)); } } }
private String eval(ShellSession session, String name, String def) { try { GroovyShell shell = getGroovyShell(session); Object ret = shell.getContext().getVariable(name); if (ret instanceof Closure) { log.log(Level.FINEST, "Invoking " + name + " closure"); Closure c = (Closure)ret; ret = c.call(); } else if (ret == null) { log.log(Level.FINEST, "No " + name + " will use empty"); return def; } return String.valueOf(ret); } catch (Exception e) { log.log(Level.SEVERE, "Could not get a " + name + " message, will use empty", e); return def; } }
/** * Displays the current binding used when instantiating the shell. */ private void displayBinding() { Binding context = shell.getContext(); Map variables = context.getVariables(); Set set = variables.keySet(); if (set.isEmpty()) { out.println(MESSAGES.getMessage("command.binding.binding_empty")); } else { out.println(MESSAGES.getMessage("command.binding.available_variables")); for (Object key : set) { out.print(" "); out.print(key); out.print(" = "); out.println(variables.get(key)); } } }
/** * Displays the current binding used when instanciating the shell. */ private void displayBinding() { Binding context = shell.getContext(); Map variables = context.getVariables(); Set set = variables.keySet(); if (set.isEmpty()) { out.println(MESSAGES.getMessage("command.binding.binding_empty")); } else { out.println(MESSAGES.getMessage("command.binding.available_variables")); Iterator iter = set.iterator(); while (iter.hasNext()) { Object key = iter.next(); out.print(" "); out.print(key); out.print(" = "); out.println(variables.get(key)); } } }
/** * Displays the current binding used when instanciating the shell. */ private void displayBinding() { Binding context = shell.getContext(); Map variables = context.getVariables(); Set set = variables.keySet(); if (set.isEmpty()) { out.println(MESSAGES.getMessage("command.binding.binding_empty")); } else { out.println(MESSAGES.getMessage("command.binding.available_variables")); Iterator iter = set.iterator(); while (iter.hasNext()) { Object key = iter.next(); out.print(" "); out.print(key); out.print(" = "); out.println(variables.get(key)); } } }
@SuppressWarnings("unchecked") private Object readResolve() { execution = CpsFlowExecution.PROGRAM_STATE_SERIALIZATION.get(); setupTransients(); assert execution!=null; if (scripts != null) { // compatibility: the field will be null in old programs GroovyShell shell = execution.getShell(); assert shell.getContext().getVariables().isEmpty(); if (!scripts.isEmpty()) { // Take the canonical bindings from the main script and relink that object with that of the shell and all other loaded scripts which kept the same bindings. shell.getContext().getVariables().putAll(scripts.get(0).getBinding().getVariables()); for (Script script : scripts) { if (script.getBinding().getVariables().equals(shell.getContext().getVariables())) { script.setBinding(shell.getContext()); } } } } return this; }
private String eval(String name, String def) { ClassLoader previous = setCRaSHLoader(); try { GroovyShell shell = getGroovyShell(); Object ret = shell.getContext().getVariable(name); if (ret instanceof Closure) { log.log(Level.FINEST, "Invoking " + name + " closure"); Closure c = (Closure)ret; ret = c.call(); } else if (ret == null) { log.log(Level.FINEST, "No " + name + " will use empty"); return def; } return String.valueOf(ret); } catch (Exception e) { log.log(Level.SEVERE, "Could not get a " + name + " message, will use empty", e); return def; } finally { setPreviousLoader(previous); } }
/** * Initialize the engine. */ public void initialize(final BSFManager mgr, String lang, Vector declaredBeans) throws BSFException { super.initialize(mgr, lang, declaredBeans); ClassLoader parent = mgr.getClassLoader(); if (parent == null) parent = GroovyShell.class.getClassLoader(); final ClassLoader finalParent = parent; this.loader = (GroovyClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { CompilerConfiguration configuration = new CompilerConfiguration(); configuration.setClasspath(mgr.getClassPath()); return new GroovyClassLoader(finalParent, configuration); } }); execScripts = new HashMap(); evalScripts = new HashMap(); context = shell.getContext(); // create a shell // register the mgr with object name "bsf" context.setVariable("bsf", new BSFFunctions(mgr, this)); int size = declaredBeans.size(); for (int i = 0; i < size; i++) { declareBean((BSFDeclaredBean) declaredBeans.elementAt(i)); } } }
/** * Initialize the engine. */ public void initialize(final BSFManager mgr, String lang, Vector declaredBeans) throws BSFException { super.initialize(mgr, lang, declaredBeans); ClassLoader parent = mgr.getClassLoader(); if (parent == null) parent = GroovyShell.class.getClassLoader(); final ClassLoader finalParent = parent; this.loader = (GroovyClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { CompilerConfiguration configuration = new CompilerConfiguration(); configuration.setClasspath(mgr.getClassPath()); return new GroovyClassLoader(finalParent, configuration); } }); execScripts = new HashMap(); evalScripts = new HashMap(); context = shell.getContext(); // create a shell // register the mgr with object name "bsf" context.setVariable("bsf", new BSFFunctions(mgr, this)); int size = declaredBeans.size(); for (int i = 0; i < size; i++) { declareBean((BSFDeclaredBean) declaredBeans.elementAt(i)); } } }
/** * Initialize the engine. */ public void initialize(final BSFManager mgr, String lang, Vector declaredBeans) throws BSFException { super.initialize(mgr, lang, declaredBeans); ClassLoader parent = mgr.getClassLoader(); if (parent == null) parent = GroovyShell.class.getClassLoader(); final ClassLoader finalParent = parent; this.loader = (GroovyClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { CompilerConfiguration configuration = new CompilerConfiguration(); configuration.setClasspath(mgr.getClassPath()); return new GroovyClassLoader(finalParent, configuration); } }); execScripts = new HashMap(); evalScripts = new HashMap(); context = shell.getContext(); // create a shell // register the mgr with object name "bsf" context.setVariable("bsf", new BSFFunctions(mgr, this)); int size = declaredBeans.size(); for (int i = 0; i < size; i++) { declareBean((BSFDeclaredBean) declaredBeans.elementAt(i)); } } }
/** * Initialize the engine. */ public void initialize(final BSFManager mgr, String lang, Vector declaredBeans) throws BSFException { super.initialize(mgr, lang, declaredBeans); ClassLoader parent = mgr.getClassLoader(); if (parent == null) parent = GroovyShell.class.getClassLoader(); final ClassLoader finalParent = parent; this.loader = (GroovyClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { CompilerConfiguration configuration = new CompilerConfiguration(); configuration.setClasspath(mgr.getClassPath()); return new GroovyClassLoader(finalParent, configuration); } }); execScripts = new HashMap(); evalScripts = new HashMap(); context = shell.getContext(); // create a shell // register the mgr with object name "bsf" context.setVariable("bsf", new BSFFunctions(mgr, this)); int size = declaredBeans.size(); for (int i = 0; i < size; i++) { declareBean((BSFDeclaredBean) declaredBeans.elementAt(i)); } } }
/** * Initialize the engine. */ public void initialize(final BSFManager mgr, String lang, Vector declaredBeans) throws BSFException { super.initialize(mgr, lang, declaredBeans); ClassLoader parent = mgr.getClassLoader(); if (parent == null) parent = GroovyShell.class.getClassLoader(); setLoader(mgr, parent); execScripts = new HashMap<Object, Class>(); evalScripts = new HashMap<Object, Class>(); context = shell.getContext(); // create a shell // register the mgr with object name "bsf" context.setVariable("bsf", new BSFFunctions(mgr, this)); int size = declaredBeans.size(); for (int i = 0; i < size; i++) { declareBean((BSFDeclaredBean) declaredBeans.elementAt(i)); } }
@Override public void loadGlue(Glue glue, List<String> gluePaths) { this.glue = glue; final Binding context = shell.getContext(); for (String gluePath : gluePaths) { // Load sources for (Resource resource : resourceLoader.resources(gluePath, ".groovy")) { Script script = parse(resource); runIfScript(context, script); } // Load compiled scripts for (Class<? extends Script> glueClass : classFinder.getDescendants(Script.class, packageName(gluePath))) { try { Script script = glueClass.getConstructor(Binding.class).newInstance(context); runIfScript(context, script); } catch (Exception e) { throw new CucumberException(e); } } } }
Binding binding = shell.getContext(); context.putAll(binding.getVariables()); } catch (CompilationFailedException e) {
public void open(CommandContext<? super Object> consumer) throws IOException, CommandException { this.consumer = (CommandContext<Object>)consumer; GroovyShell shell = GroovyCompiler.getGroovyShell(session); ShellBinding binding = (ShellBinding)shell.getContext(); binding.setCurrent(new InvocationContextImpl<Object>(this.consumer)); Object o; try { o = shell.evaluate(request); } finally { binding.setCurrent(null); } if (o != null) { try { consumer.provide(o); } catch (IOException e) { throw e; } catch (CommandException e) { throw e; } catch (Exception e) { throw new CommandException(ErrorKind.EVALUATION, "An error occured during the evalution of '" + request + "'", e); } } } public void close() throws IOException, CommandException {
public void open(CommandContext<? super Object> consumer) throws IOException, CommandException { this.consumer = (CommandContext<Object>)consumer; GroovyShell shell = GroovyCompiler.getGroovyShell(session); ShellBinding binding = (ShellBinding)shell.getContext(); binding.setCurrent(new InvocationContextImpl<Object>(this.consumer)); Object o; try { o = shell.evaluate(request); } finally { binding.setCurrent(null); } if (o != null) { try { consumer.provide(o); } catch (IOException e) { throw e; } catch (CommandException e) { throw e; } catch (Exception e) { throw new CommandException(ErrorKind.EVALUATION, "An error occured during the evalution of '" + request + "'", e); } } } public void close() throws IOException, CommandException {