public String doCallBack(ShellSession session, String name, String defaultValue) { return eval(session, name, defaultValue); }
public GroovyLanguage(PluginContext context) { compiler = new GroovyCompiler(context); repl = new GroovyRepl(this); scriptCache = new ClassCache<GroovyScript>(context, new GroovyClassFactory<GroovyScript>(context.getLoader(), GroovyScript.class, GroovyScript.class), ResourceKind.LIFECYCLE); }
public void testExplicitReturnFromDefaultScript() throws Exception { assertHasNoTag(null, "return 'something'"); }
@Override public void init(ShellSession session) { try { GroovyScript login = getLifeCycle(session, "login"); if (login != null) { login.setBinding(new Binding(session)); login.run(); } } catch (CommandException e) { e.printStackTrace(); } }
protected List<CRaSHPlugin<?>> getPlugins() { ArrayList<CRaSHPlugin<?>> plugins = new ArrayList<CRaSHPlugin<?>>(); plugins.add(new GroovyLanguageProxy()); plugins.add(new JavaLanguage()); return plugins; }
public void testShortOption() throws Exception { lifeCycle.bindGroovy("option_command", option_command); assertEquals("bar", assertOk("option_command -o bar")); // String foo = "class foo {\n" + "@Command\n" + "public String main() {\n" + "option_command o:'bar'\n" + "}\n" + "}"; lifeCycle.bindGroovy("foo", foo); lifeCycle.bindGroovy("option_command", option_command); // assertEquals("bar", assertOk("foo")); }
@Override public final Object invokeMethod(String name, Object args) { // try { return super.invokeMethod(name, args); } catch (MissingMethodException missing) { return Helper.invokeMethod(context, name, args, missing); } }
public GroovyCompiler(PluginContext context) { this.objectGroovyClassFactory = new GroovyClassFactory<Object>(context.getLoader(), Object.class, GroovyScriptCommand.class); }
public void testCommandExecutionFailureThrowsException() throws Exception { String script = "try {\n" + "thrower();\n" + "}\n" + "catch(javax.naming.NamingException e) {\n" + "e.printStackTrace();\n" + "org.crsh.lang.impl.groovy.ScriptTestCase.failed = true\n" + "}"; lifeCycle.bindClass("thrower", Commands.ThrowCheckedException.class); lifeCycle.bindGroovy("script", script); failed = false; assertOk("script"); assertTrue(failed); } }
@Override public Object invokeMethod(String name, Object args) { SafeCallable runnable = Helper.resolveMethodInvocation(new InvocationContextImpl(context), name, args); if (runnable != null) { return runnable.call(); } else { return InvokerHelper.invokeMethod(owner, name, args); } } }
@Override public void destroy(ShellSession session) { try { GroovyScript logout = getLifeCycle(session, "logout"); if (logout != null) { logout.setBinding(new Binding(session)); logout.run(); } } catch (CommandException e) { e.printStackTrace(); } }
@Override protected List<CRaSHPlugin<?>> getPlugins() { List<CRaSHPlugin<?>> plugins = super.getPlugins(); plugins.add(new GroovyLanguageProxy()); return plugins; }
public void testLongOption() throws Exception { String foo = "class foo {\n" + "@Command\n" + "public String main() {\n" + "option_command option:'bar'\n" + "}\n" + "}"; lifeCycle.bindGroovy("foo", foo); lifeCycle.bindGroovy("option_command", option_command); // assertEquals("bar", assertOk("foo")); }
public final Object invokeMethod(String name, Object args) { try { return getMetaClass().invokeMethod(this, name, args); } catch (MissingMethodException missing) { return Helper.invokeMethod(context, name, args, missing); } }
public void testImplicitReturnFromCRaSHScript() throws Exception { assertHasNoTag(GroovyScriptCommand.class, "def implicit = 'something'"); }
public Support(final String crontab) throws Exception { lifecycle = new TestPluginLifeCycle(new CronPlugin() { @Override protected Resource getConfig() { return new Resource("contrab", crontab.getBytes(), 0); } }, new GroovyLanguageProxy(), new CRaSHShellFactory()); lifecycle.start(); } }
public void testShortOptionInScript() throws Exception { String foo = "option_command o:'bar'\n"; lifeCycle.bindGroovy("foo", foo); lifeCycle.bindGroovy("option_command", option_command); // assertEquals("bar", assertOk("foo")); }
public void testImplicitReturnFromDefaultScript() throws Exception { assertHasNoTag(null, "def implicit = 'something'"); }
protected TestPluginLifeCycle createLifeCycle() throws Exception { TestPluginLifeCycle test = new TestPluginLifeCycle(new MailPlugin(), new GroovyLanguageProxy(), new JavaLanguage()); test.setProperty(MailPlugin.SMTP_HOST, "localhost"); test.setProperty(MailPlugin.SMTP_PORT, 5000); test.setProperty(MailPlugin.SMTP_FROM, "foo@gmail.com"); return test; }
public void testLongOptionInScript() throws Exception { String foo = "option_command option:'bar'\n"; lifeCycle.bindGroovy("foo", foo); lifeCycle.bindGroovy("option_command", option_command); // assertEquals("bar", assertOk("foo")); } }