[Libreoffice-commits] core.git: external/beanshell

Douglas Mencken dougmencken at gmail.com
Tue Mar 15 09:37:30 UTC 2016


 external/beanshell/UnpackedTarball_beanshell.mk |    5 +
 external/beanshell/beanshell-invoke.patch       |   78 ++++++++++++++++++++++++
 2 files changed, 83 insertions(+)

New commits:
commit 841a58da93e10f543876eefca470d8fd4bd96ded
Author: Douglas Mencken <dougmencken at gmail.com>
Date:   Wed Sep 30 12:16:08 2015 -0400

    beanshell: improve compatibility for script engine
    
    javax.script.Invocable may contain either
    • two `invoke' methods
    or
    • `invokeMethod' and `invokeFunction'
    so let's support any variant
    
    Change-Id: I47196af79cc2de75725ded29992ab1f6f4cd623e
    Reviewed-on: https://gerrit.libreoffice.org/23163
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/external/beanshell/UnpackedTarball_beanshell.mk b/external/beanshell/UnpackedTarball_beanshell.mk
index 828e4bd..f35dd7d 100644
--- a/external/beanshell/UnpackedTarball_beanshell.mk
+++ b/external/beanshell/UnpackedTarball_beanshell.mk
@@ -11,8 +11,13 @@ $(eval $(call gb_UnpackedTarball_UnpackedTarball,beanshell))
 
 $(eval $(call gb_UnpackedTarball_set_tarball,beanshell,$(BSH_TARBALL),,beanshell))
 
+$(eval $(call gb_UnpackedTarball_fix_end_of_line,beanshell,\
+	engine/src/TestBshScriptEngine.java \
+))
+
 $(eval $(call gb_UnpackedTarball_add_patches,beanshell,\
 	external/beanshell/bsh-2.0b1-src.patch \
+	external/beanshell/beanshell-invoke.patch \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/external/beanshell/beanshell-invoke.patch b/external/beanshell/beanshell-invoke.patch
new file mode 100644
index 0000000..b78f1db
--- /dev/null
+++ b/external/beanshell/beanshell-invoke.patch
@@ -0,0 +1,78 @@
+--- old/beanshell/engine/src/bsh/engine/BshScriptEngine.java
++++ new/beanshell/engine/src/bsh/engine/BshScriptEngine.java
+@@ -229,6 +229,12 @@
+ 		}
+ 	}
+ 
++	public Object invoke( Object thiz, String name, Object... args )
++	throws ScriptException, NoSuchMethodException
++	{
++		return invokeMethod( thiz, name, args );
++	}
++
+ 	/**
+ 	 * Same as invoke(Object, String, Object...) with <code>null</code> as the
+ 	 * first argument.  Used to call top-level procedures defined in scripts.
+@@ -249,6 +255,12 @@
+ 		return invokeMethod( getGlobal(), name, args );
+ 	}
+ 
++	public Object invoke( String name, Object... args )
++		throws ScriptException, NoSuchMethodException
++	{
++		return invokeFunction( name, args );
++	}
++
+     /**
+ 	 * Returns an implementation of an interface using procedures compiled in the
+ 	 * interpreter. The methods of the interface may be implemented using the
+--- old/beanshell/engine/src/TestBshScriptEngine.java
++++ new/beanshell/engine/src/TestBshScriptEngine.java
+@@ -2,11 +2,12 @@
+ import java.io.*;
+ import javax.script.*;
+ import static javax.script.ScriptContext.*;
++import java.lang.reflect.*;
+ 
+ public class TestBshScriptEngine
+ {
+ 	public static void main( String [] args )
+-		throws ScriptException, NoSuchMethodException, IOException
++		throws ScriptException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException
+ 	{
+ 		ScriptEngineManager manager =
+ 			new ScriptEngineManager( bsh.Interpreter.class.getClassLoader() );
+@@ -39,11 +40,23 @@
+ 		assertTrue( engine.get("bar").equals("gee") );
+ 		assertTrue( engine.eval("bar").equals("gee") );
+ 
++		// use reflection to pick available method
++		Method invokeMe = null;
++		try {
++			invokeMe = Invocable.class.getMethod( "invokeFunction", String.class, Object[].class );
++		} catch ( Exception e ) { }
++		if (invokeMe == null)
++		{
++			try {
++				invokeMe = Invocable.class.getMethod( "invoke", String.class, Object[].class );
++			} catch ( Exception e ) { }
++		}
++
+ 		// install and invoke a method
+ 		engine.eval("foo() { return foo+1; }");
+ 		// invoke a method
+ 		Invocable invocable = (Invocable) engine;
+-		int foo = (Integer)invocable.invokeFunction( "foo" );
++		int foo = (Integer)invokeMe.invoke( invocable, "foo", (Object) new Object[]{} );
+ 		assertTrue( foo == 43 );
+ 
+ 		// get interface
+@@ -58,7 +71,7 @@
+ 		engine.eval(
+ 			"flag2=false; myObj() { run() { flag2=true; } return this; }");
+ 		assertTrue( (Boolean)engine.get("flag2") == false );
+-		Object scriptedObject = invocable.invokeFunction("myObj");
++		Object scriptedObject = invokeMe.invoke( invocable, "myObj", (Object) new Object[]{} );
+ 		assertTrue( scriptedObject instanceof bsh.This );
+ 		runnable =
+ 			(Runnable)invocable.getInterface( scriptedObject, Runnable.class );


More information about the Libreoffice-commits mailing list