Any word on Ruby support

4 views
Skip to first unread message

ToddH

unread,
Aug 22, 2010, 4:22:22 PM8/22/10
to coding kata
Does JRuby 1.5.1 fix the Ruby incompatibility issue?

I'm really enjoying these katas, great work!

-Todd

stephanos

unread,
Aug 23, 2010, 12:19:40 PM8/23/10
to coding kata
Hi Todd,

thanks for your feedback :-)

I just tried the version 1.5.1 of JRuby, still the same issue. I had
somebody familiar with JRuby investigate it in detail, but he gave up
at one point. I will see if there is a new workaround available - but
I can't promise anything.

PS: If anyone with deep JRuby experience reads this: I can't find a
way to make Maven compile the Ruby script into a 'proper' JAR -
meaning that a Java application could pick it up and call the methods
inside of it as if it was written in Java in the first place (this is
what Groovy and Scala are capable of for example).

Cheers,
Stephanos

ToddH

unread,
Sep 2, 2010, 1:44:40 AM9/2/10
to coding kata
Is the problem Maven specific or JRuby specific? For example this blog
post seems to indicate that calling JRuby code from Java works fine:

http://tommy.chheng.com/index.php/2010/06/call-a-jruby-method-from-java/

but I'm guessing the issue is more complicated. I'm not a JRuby expert
but I've done a lot of Maven 2 work so if you point me to the source
I'd be happy to take a crack at it.

-Todd

stephanos

unread,
Sep 3, 2010, 3:39:08 PM9/3/10
to coding kata
Well, the problem is JRuby specific I assume.

The main goal is to integrate the kata solution (any language) with
the kata task (java).
#1 With Scala, Clojure and Groovy this was trivial, as they provide a
proper maven plugin for compiling the script to a class file.
#2 For JavaFX and Javascript I used an Ant script that compiles the
script 'manually' (if you like simply look at the pom.xml).
#3 And for Jython I used a proprietary integration code
(PythonInterpreter) that would handle the integration
(KataSolvLoader.java).

But for some reason I can't get JRuby to work. For attempt #1 I can't
find a working plugin, for #2 I don't know which class to call via Ant
and #3 I didn't even investigate yet.

I uploaded a current version of my JRuby kata template - check it out
via:
mvn archetype:generate -DinteractiveMode=false -
DarchetypeRepository=http://www.codingkata.org/repo/release -
DarchetypeGroupId=org.codingkata.template -DarchetypeArtifactId=solv-
jruby-archetype -DarchetypeVersion=0.1 -DgroupId=org.codingkata.unit -
DartifactId=hello-world-solv-jruby -DkataId=hello-world -
DkataVersion=1.02 -DlangVersion=1.5.2 -DlibVersion=1.4.0 -
Dversion=1274199905

It contains the 2 approaches I was talking about.

PS: The JRuby forum wasn't of much help yet, either:
http://www.ruby-forum.com/topic/215554

Good luck :)

Cheers,
stephanos

ToddH

unread,
Sep 4, 2010, 5:50:42 PM9/4/10
to coding kata
Hi Stephanos,

I have the jruby-maven-plugin successfully generating the .java source
during the generate-sources build phase by changing the execution
phase for the jruby-maven-plugin to <phase>generate-sources</phase>
(and make sure generateJava is set to true). Maven then compiles it to
a .class on its own during the compile phase.

The catch I see is that jrubyc generated classes always inherit from
RubyObject which prevents them from inheriting from BaseKataSolution
and since your calling code is trying to cast it to a BaseKataSolution
it's failing on the cast. With JRuby's java_implements keyword though
you can however implement all the java interfaces you want.

The easiest option I see is to add an IBaseKataSolution interface and
then have the MyKata.rb implement the interface. Then in your calling
code instead of casting it to a BaseKataSolution you would always cast
it to an IBaseKataSolution. If there is underlying functionality in
BaseKataSolution that it needs it could then ALSO subclass
BaseKataSolution and it should get the underlying BaseKataSolution
functionality (you just can't cast it to a BaseKataSolution). The
MyKata.rb would look like this:

require 'java'
java_package 'org.codingkata.unit'
java_import 'org.codingkata.unit.api.IBaseKataSolution'
java_import 'org.codingkata.unit.api.BaseKataSolution'

class MyKata < BaseKataSolution
java_implements IBaseKataSolution

java_signature 'String reply()'
def reply
"hello world"
end
end

If there's no underlying functionality in BaseKataSolution then just
switch it from an abstract class to an interface and that would solve
the problem as well.

Here's a zip file of the hello world kata that compiles and runs but
fails when the calling code tries to cast it to a BaseKataSolution:
http://gabrito.com/files/hello-world-solv-jruby.zip

-Todd

stephanos

unread,
Sep 5, 2010, 10:27:52 AM9/5/10
to coding kata
Thanks for your looking into it!

But I'm wondering, what OS do you run? As I mentioned somewhere, the
plugin works flawlessly in Linux but appears to fail on Windows (at
least for me). When I run the project from your zip it creates a JAR
without any class files, just the one .rb file. Or am I missing
something?

When/if that is resolved, I agree with you that I'd have to look into
the class/interface issue. It's quite a few months back that I coded
it, but I remember there was some functionality in the
BaseKataSolution class; yet of course your suggestion is completely
logical and should work as you described.

Cheers,
stephanos

ToddH

unread,
Sep 5, 2010, 11:11:51 AM9/5/10
to coding kata
Hi Stephanos,

I'm on a Mac but I can install a Windows virtual machine to try and
get it working. In my zip file I only use the plugin now to generate
the .java file and then let Maven compile it. When you run "mvn
install" does the following file exist afterwards: target/jrubyc-
generated-sources/org/codingkata/unit/MyKata.java ?

Thanks,
Todd

stephanos

unread,
Sep 5, 2010, 12:04:05 PM9/5/10
to coding kata
The directory jrubyc-generated-sources/ is empty. No message in the
console hints to any error.

This is exactly what the problem was when I last collaborated with the
author of the plugin [http://www.ruby-forum.com/topic/210007].
I emailed him again now to see if in the meantime somehow fixed this
issue which seems to affect Windows only.

It would be awesome if you could try to make it work on a Windows VM -
maybe I'm not seeing something,
but my guess is that the issue is found inside the plugin.

Cheers,
stephanos

ToddH

unread,
Sep 5, 2010, 1:23:15 PM9/5/10
to coding kata
I'm able to reproduce the same problem on Windows as well, I'll take a
look at the plugin and see if I can figure out what the problem is...

ToddH

unread,
Sep 5, 2010, 2:06:23 PM9/5/10
to coding kata
The problem turns out to be with jrubyc failing silently on Windows.
Looks like the plugin author already filed a bug for it:

http://jira.codehaus.org/browse/JRUBY-5065

so we'll probably have to wait for the next JRuby release.

-Todd

stephanos

unread,
Sep 6, 2010, 6:06:48 AM9/6/10
to coding kata
Yes, I guess so.
Again: Thanks a lot for looking into the issue!

Once it works I will dedicate the JRuby support to you and the plugin
author :-)

ToddH

unread,
Sep 6, 2010, 2:16:49 PM9/6/10
to coding kata
I've submitted a possible patch to the JRuby project. I'll look and
see if I can publish an interim JRuby snapshot we can use for the time
being.
Reply all
Reply to author
Forward
0 new messages