/** * Declare a bean */ public void declareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, bean.bean); }
/** * Undeclare a previously declared bean. */ public void undeclareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, null); }
public void setProperty(String property, Object newValue) { setVariable(property, newValue); try { super.setProperty(property, newValue); } catch (GroovyRuntimeException e) { // ignore, was probably a dynamic property } }
public String call() throws RuntimeException { // if we run locally, cl!=null. Otherwise the delegating classloader will be available as context classloader. if (cl==null) cl = Thread.currentThread().getContextClassLoader(); CompilerConfiguration cc = new CompilerConfiguration(); cc.addCompilationCustomizers(new ImportCustomizer().addStarImports( "jenkins", "jenkins.model", "hudson", "hudson.model")); GroovyShell shell = new GroovyShell(cl,new Binding(),cc); StringWriter out = new StringWriter(); PrintWriter pw = new PrintWriter(out); shell.setVariable("out", pw); try { Object output = shell.evaluate(script); if(output!=null) pw.println("Result: "+output); } catch (Throwable t) { Functions.printStackTrace(t, pw); } return out.toString(); } }
/** * Initialize the engine. */ public void initialize(BSFManager mgr, String lang, Vector declaredBeans) throws BSFException { super.initialize(mgr, lang, declaredBeans); // create a shell shell = new GroovyShell(mgr.getClassLoader()); // register the mgr with object name "bsf" shell.setVariable("bsf", new BSFFunctions(mgr, this)); int size = declaredBeans.size(); for (int i = 0; i < size; i++) { declareBean((BSFDeclaredBean) declaredBeans.elementAt(i)); } }
private void testKeyHandler(String command) throws Exception { CountDownLatch latch1 = new CountDownLatch(1); ArrayBlockingQueue<int[]> queue = new ArrayBlockingQueue<int[]>(1); groovyShell.setVariable("queue", queue); groovyShell.setVariable("latch1", latch1); groovyShell.setVariable("latch2", new CountDownLatch(1)); lifeCycle.bindGroovy("foo", command); final BaseProcessContext process = create("foo"); new Thread() { @Override public void run() { process.execute(); } }.start(); latch1.await(10, TimeUnit.SECONDS); process.on(null, new int[]{'a'}); ShellResponse response = process.getResponse(); assertInstance(ShellResponse.Ok.class, response); int[] event = queue.poll(10, TimeUnit.SECONDS); assertEquals(1, event.length); assertEquals('a', event[0]); } }
/** * Declare a bean */ public void declareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, bean.bean); }
/** * Undeclare a previously declared bean. */ public void undeclareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, null); }
/** * Declare a bean */ public void declareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, bean.bean); }
/** * Undeclare a previously declared bean. */ public void undeclareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, null); }
/** * Declare a bean */ public void declareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, bean.bean); }
/** * Undeclare a previously declared bean. */ public void undeclareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, null); }
/** * Undeclare a previously declared bean. */ public void undeclareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, null); }
/** * Declare a bean */ public void declareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, bean.bean); }
/** * Declare a bean */ public void declareBean(BSFDeclaredBean bean) throws BSFException { shell.setVariable(bean.name, bean.bean); }
private void setBindings(GroovyShell shell, String bindings) throws IOException { if(bindings != null) { Properties p = new Properties(); p.load(new StringReader(bindings)); for(Map.Entry<Object, Object> entry: p.entrySet()) { shell.setVariable((String)entry.getKey(), entry.getValue()); } } }
public void setProperty(String property, Object newValue) { setVariable(property, newValue); try { super.setProperty(property, newValue); } catch (GroovyRuntimeException e) { // ignore, was probably a dynamic property } }
public void setProperty(String property, Object newValue) { setVariable(property, newValue); try { super.setProperty(property, newValue); } catch (GroovyRuntimeException e) { // ignore, was probably a dynamic property } }
public void setProperty(String property, Object newValue) { setVariable(property, newValue); try { super.setProperty(property, newValue); } catch (GroovyRuntimeException e) { // ignore, was probably a dynamic property } }
public void setProperty(String property, Object newValue) { setVariable(property, newValue); try { super.setProperty(property, newValue); } catch (GroovyRuntimeException e) { // ignore, was probably a dynamic property } }