Monday, October 13, 2008

Finally back, with Glimmer on the Mac

So, I haven't blogged for a while as I've been busy in the last few months looking for homes, moving to a new place in Chicago, finishing work on a big client project, and joining a new Ruby on Rails project at our Obtiva main office (The Obtiva Studio.)

My Windows laptop, which had all my Glimmer work got stolen. So, I got a Mac Book Pro, and that became the perfect excuse for me to get Glimmer working on the Mac.

The key thing I learned about making Glimmer work on the Mac is that you need to run Java for JRuby with this switch "-XstartOnFirstThread" or else the SWT library, which Glimmer relies on, will freeze when attempting to trigger any UI events (mouse-click, tabbing, etc...)

One way of doing so is to simply append that switch at the end of a jruby call.


jruby samples/hello_world.rb -XstartOnFirstThread

A better way for the long-term though is to embed that switch in the Java environment variables or the jruby script file.

One last thing to note is that if you get Glimmer through the Gem and run it, it automatically gets a Ruby Faces gem that is more recent than the one originally used to develop Glimmer. Its API had a change that breaks Glimmer, so to fix it, replace all references of camelcase() in Glimmer's code-base with camelcase(false) (references are in r_widget.rb I believe.)

I am in the process of doing the long-due task of committing Glimmer's code into the Eclipse SVN repository. Once I have that done, I'll ensure it includes the Faces fix, and I'll blog about the commit.

Happy Mac Glimmering!


Unknown said...

May have found another bug after a bit of playing around.

(Running against the latest version of Facets having installed glimmer via rubygems, using JRuby on windows.)

The fix of replacing camelcase() with camelcase(false) leads to another issue, namely RWidget's method_missing being called and trying to call [SWTWidget].setInterface for some reason. Turns out that widget_method.getParameterTypes seems to be returning parameter(s) prefixed with the "interface" keyword.

I replaced the line:

listener_class.send :include, (eval listener_type.to_s)


listener_class.send :include, (eval listener_type.to_s.sub("interface ",""))

And it now seems to work.

Andy Maleh said...

Thanks for the feedback Tom.

Curious... what version of JRuby are you using?

I'm guessing the "interface" prefix is being added in a more recent version of JRuby to get around some interoperability problem with Java.

I do not have the problem on my machine (probably because I'm on JRuby 1.1.3.)

Unknown said...

Hi Andy,

I am on version 1.1.5 (running on Windows XP SP2 with Java 1.6.0_10). If I get time I will have a look to see if downgrading JRuby to 1.1.3 stops it from happening.

dacm4u said...

Hi Andy,

The issue occurred on my setup - glimmer rev. 20392(trunk as of today)/Windows XP SP2(Japanese)/IBM Java SDK 1.6.0 or Sun Java SDK 1.6.0_02/JRuby 1.1.5 - and downgrading JRuby to 1.1.3 stops it happening. Tom's patch works well, thanks Tom!

Should I open a new bug?

Stack traces are same for both Java SDK.

### Stack trace
D:>jruby login.rb
WidgetListenerCommandHandler will handle command: on_modify_text with arguments

(eval):1:in `eval': undefined method `setInterface' for #<Java::OrgEclipseSwtWidgets::Text:0x6e006e @java_object=Text {}> (NoMethodError)
from ./../src/command_handlers/models/r_widget.rb:62:in `method_missing'

from (eval):1:in `add_listener'
from ./../src/command_handlers/models/r_widget.rb:121:in `eval'
from ./../src/command_handlers/models/r_widget.rb:124:in `add_listener'
from ./../src/command_handlers/models/r_widget.rb:121:in `each'
from ./../src/command_handlers/models/r_widget.rb:121:in `add_listener'
from ./../src/command_handlers/models/r_widget.rb:120:in `each'
from ./../src/command_handlers/models/r_widget.rb:120:in `add_listener'
... 36 levels...
from ./../src/glimmer.rb:44:in `method_missing'
from login.rb:68:in `launch'
from login.rb:105

### IBM Java SDK version information
D:>%JAVA_HOME%\bin\java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build pwi3260sr1-20080416_01(SR1))
IBM J9 VM (build 2.4, J2RE 1.6.0 IBM J9 2.4 Windows XP x86-32 jvmwi3260-20080415
_18762 (JIT enabled, AOT enabled)
J9VM - 20080415_018762_lHdSMr
JIT - r9_20080415_1520
GC - 20080415_AA)
JCL - 20080412_01

### Sun Java SDK version information
D:>%JAVA_HOME%\bin\java -version
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)

### Tom's modification
--- src/command_handlers/models/r_widget.rb (revision 20392)
+++ src/command_handlers/models/r_widget.rb (working copy)
@@ -121,7 +121,7 @@
listener_type.getMethods.each do |listener_method|
if (listener_method.getName.match(listener_method_name))
listener_class =
- listener_class.send :include, (eval listener_type.to_s)
+ listener_class.send :include, (eval listener_type.to_s.sub("interface",""))
listener =
listener_type.getMethods.each do |t_method|
eval "def listener.#{t_method.getName}(event) end"
@@ -156,4 +156,4 @@
( & style) == style


Andy Maleh said...

Sure, feel free to open a bug, and I'll apply the fix. Thanks dacm4u.

dacm4u said...

Filed the issue as bug 257793.