Refine search
@Override public Object invokeMethod(String name, Object args) { return InvokerHelper.invokeMethod(this.propertyValue, name, args); }
public static Object runScript(Class scriptClass, String[] args) { Binding context = new Binding(args); Script script = createScript(scriptClass, context); return invokeMethod(script, "run", EMPTY_ARGS); }
@Override public void setProperty(Object object, Object newValue) { InvokerHelper.getMetaClass(object).invokeMethod(object, setterName, new Object[]{newValue}); }
static Object invokePojoMethod(Object object, String methodName, Object arguments) { MetaClass metaClass = InvokerHelper.getMetaClass(object); return metaClass.invokeMethod(object, methodName, asArray(arguments)); }
private static String asString(GPathResult node) { // little bit of hackery to avoid Groovy dependency in this file try { Object builder = ((Class) Class.forName("groovy.xml.StreamingMarkupBuilder")).newInstance(); InvokerHelper.setProperty(builder, "encoding", "UTF-8"); Writable w = (Writable) InvokerHelper.invokeMethod(builder, "bindNode", node); return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + w.toString(); } catch (Exception e) { return "Couldn't convert node to string because: " + e.getMessage(); } }
public void testPublicField() { DymmyClass dymmyClass = new DymmyClass(); MetaClass metaClass = InvokerHelper.getMetaClass(dymmyClass); assertEquals(metaClass.getProperty(dymmyClass, "x"), new Integer(0)); assertEquals(metaClass.getProperty(dymmyClass, "y"), "none"); metaClass.setProperty(dymmyClass, "x", new Integer(25)); assertEquals(dymmyClass.x, 25); metaClass.setProperty(dymmyClass, "y", "newvalue"); assertEquals(dymmyClass.y, "newvalue"); }
public Object call(Object receiver, Object[] args) throws Throwable { if (receiver != null && info.hasPerInstanceMetaClasses()) { try { return InvokerHelper.getMetaClass(receiver).invokeMethod(receiver, name, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else { return CallSiteArray.defaultCall(this, receiver, args); } } }
public void testSetPropertyWithInt() { DymmyClass dymmyClass = new DymmyClass(); MetaClass metaClass = InvokerHelper.getMetaClass(dymmyClass); metaClass.setProperty(dymmyClass, "anInt", new Integer(10)); }
/** * Returns the string representation of the given array. * * @param self an array * @return the string representation * @since 1.6.0 */ public static String toString(byte[] self) { return InvokerHelper.toString(self); }
@Override public Object getProperty(String name) { return InvokerHelper.getProperty(this.propertyValue, name); }
public static Object invokeMethodN(Class senderClass, Object receiver, String messageName, Object[] messageArguments) throws Throwable { try { return InvokerHelper.invokeMethod(receiver, messageName, messageArguments); } catch (GroovyRuntimeException gre) { throw unwrap(gre); } }
public Object callGetProperty(Object receiver) throws Throwable { try { return InvokerHelper.getProperty(receiver, name); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } }
/** * 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 */ public Script createScript(String scriptName, Binding binding) throws ResourceException, ScriptException { return InvokerHelper.createScript(loadScriptByName(scriptName), binding); }
/** * Utility method to run a TestNG test. * * @param scriptClass the class we want to run as a test * @param loader the class loader to use * @return the result of running the test */ public Object run(Class scriptClass, GroovyClassLoader loader) { // invoke through reflection to eliminate mandatory TestNG jar dependency try { Class testNGClass = loader.loadClass("org.testng.TestNG"); Object testng = InvokerHelper.invokeConstructorOf(testNGClass, new Object[]{}); InvokerHelper.invokeMethod(testng, "setTestClasses", new Object[]{scriptClass}); Class listenerClass = loader.loadClass("org.testng.TestListenerAdapter"); Object listener = InvokerHelper.invokeConstructorOf(listenerClass, new Object[]{}); InvokerHelper.invokeMethod(testng, "addListener", new Object[]{listener}); return InvokerHelper.invokeMethod(testng, "run", new Object[]{}); } catch (ClassNotFoundException e) { throw new GroovyRuntimeException("Error running TestNG test.", e); } }
private Map findAttributes(Object args) { List list = InvokerHelper.asList(args); for (Object o : list) { if (o instanceof Map) { return (Map) o; } } return Collections.EMPTY_MAP; }
public GroovyRuntimeBeanReference(String beanName, GroovyBeanDefinitionWrapper beanDefinition, boolean toParent) { super(beanName, toParent); this.beanDefinition = beanDefinition; this.metaClass = InvokerHelper.getMetaClass(this); }
public static void checkPropNames(Object instance, Map<String, Object> args) { final MetaClass metaClass = InvokerHelper.getMetaClass(instance); for (String k : args.keySet()) { if (metaClass.hasProperty(instance, k) == null) throw new MissingPropertyException(k, instance.getClass()); } }
@Override public void setProperty(String name, Object value) { InvokerHelper.setProperty(this.propertyValue, name, value); }
/** * Run the specified class extending TestCase as a unit test. * This is done through reflection, to avoid adding a dependency to the JUnit framework. * Otherwise, developers embedding Groovy and using GroovyShell to load/parse/compile * groovy scripts and classes would have to add another dependency on their classpath. * * @param scriptClass the class to be run as a unit test * @param loader the class loader */ @Override public Object run(Class<?> scriptClass, GroovyClassLoader loader) { try { Object testSuite = InvokerHelper.invokeConstructorOf("junit.framework.TestSuite", new Object[]{scriptClass}); return InvokerHelper.invokeStaticMethod("junit.textui.TestRunner", "run", new Object[]{testSuite}); } catch (ClassNotFoundException e) { throw new GroovyRuntimeException("Failed to run the unit test. JUnit is not on the Classpath.", e); } } }
public static void setProperty(Object messageArgument, Class senderClass, Object receiver, String messageName) throws Throwable { try { if (receiver==null) receiver=NullObject.getNullObject(); InvokerHelper.setProperty(receiver, messageName, messageArgument); } catch (GroovyRuntimeException gre) { throw unwrap(gre); } }