Hi,
I'm trying to run a JRuby script with Spring DM and run into problems.
Java Base class
JRuby ClassCode:package org.codingkata.unit.api; public abstract class BaseKataSolution { abstract String reply(); }
Spring Beans contextCode:class MyKata include org.codingkata.unit.api.BaseKataSolution def reply return "hello world" end end
So far so clear - the JRuby class inherits the 'BaseKataSolution' class. In Spring I configure this as the interface (cglib is present, in the java and groovy version everything works flawlessly).Code:[...] <osgi:service ref="kataSolution" interface="org.codingkata.unit.api.BaseKataSolution"/> [...]
But when I try to run a test which loads the JRuby class, it results in:
Exported service object does not implement the given interface: class org.codingkata.unit.MyKata is not assignable to interface org.codingkata.unit.api.BaseKataSolution.
Then I tried to look at the classes in detail by using a decompiler:
Decompiled Groovy version
Decompiled JRuby versionCode:public class MyKata extends BaseKataSolution implements GroovyObject { public MyKata() { MyKata this; [...] } public String reply() { for (CallSite[] arrayOfCallSite = $getCallSiteArray(); ; return ((String)ScriptBytecodeAdapter.castToType("hello world", $get$$class$java$lang$String()))); } [...] }
Obviously Groovy directly inherits the base class while JRuby does not. Bummer. I opened a discussion in the JRuby mailing list if this is the desired behavior.Code:public class MyKata extends AbstractScript { private final Class $class = Class.forName("org.codingkata.unit.MyKata"); public MyKata() { [...] } @JRubyMethod(name="reply", frame=true, required=0, optional=0, rest=-1) public static IRubyObject method__1$RUBY$reply(MyKata paramMyKata, ThreadContext paramThreadContext, IRubyObject paramIRubyObject, Block paramBlock) { Ruby localRuby = paramThreadContext.getRuntime(); IRubyObject localIRubyObject = localRuby.getNil(); setPosition(paramThreadContext, 5); return paramMyKata.getString1(localRuby); } [...] }
Still, I'm wondering if there is anything I can do to make it work with Spring DM - because I expect most of the JSR223 languages to act like JRuby.
Any ideas?
Cheers,
stephanos


