How should ruby libraries that access the native os determine the underlying
platform?
--------------------------------------------------------------------------------------
Key: JRUBY-1887
URL: http://jira.codehaus.org/browse/JRUBY-1887
Project: JRuby
Issue Type: New Feature
Affects Versions: JRuby 1.1b2
Reporter: Stephen Bannasch
Assignee: Thomas E Enebo
Some Ruby programs use RUBY_PLATFORM to choose operating system specific
commands to execute such as the uuidtools gem when it's looking for the local
MAC address as part of the information to construct a UUID.
The pattern basically looks like this:
{code}
if RUBY_PLATFORM =~ /netbsd/
<do something on netbsd ...>
elsif RUBY_PLATFORM =~ /openbsd/
<do something on openbsd ...>
end
{code}
Mostly Java tries to supply all the stuff that an OS supplies so on JRuby:
RUBY_PLATFORM == 'java'
But of course Java doesn't supply everything and there are lots of good reasons
to be able to run an native command and lots of Ruby code uses this
functionality.
I know there's no JAVA_PLATFORM -- maybe there should be -- or is there another
way to solve this problem?
see: [JRUBY-1857], [JRUBY-1557], [JRUBY-1626], and [JRUBY-1878] for other
issues related to running native commands.
Here's part of a email conversation I've had with Bob Aman, the author of the
gem uuidtools:
I originally wrote:
{quote}
> uuidtools 1.0.2 wasn't working on JRuby because the UUID.mac_address
> wasn't working.
>
> You can see more details about the problem here.
>
> http://jira.codehaus.org/browse/JRUBY-1857
>
> I've attached a patch for uuidtools-1.0.2 that adds a gem dependency
> on Ara Howard's macaddr gem which is working. You can find out more
> about the macaddr gem from Ara's posting on ruby-talk:
{quote}
At 4:08 PM -0500 1/4/08, Bob Aman wrote:
{quote}
I saw this gem, but decided against using it for a couple reasons.
# I don't want a dependancy if i can help it.
# Ara's gem doesn't support several operating systems.
# It's version 0.0.1 and I'm not inclined to move from something stable to
something unstable.
{quote}
I basically agree that you shouldn't use my patch.
Your reasons are pretty good and here's another: the reason Ara's gem works now
in jruby is a fluke:
This doesn't work:
* IO.popen("/sbin/ifconfig 2> /dev/null") {|fd| fd.readlines}
while this does:
* stdout = IO.popen("ifconfig 2> /dev/null") {|fd| fd.readlines}
But /sbin/ifconfig is where ifconfig is on my system.
{quote}
Could you check the code again after the update, and see if it's still having
problems?
{quote}
The problem is still there.
bq. Does it really set RUBY_PLATFORM to "java"?
Yes, and there is a way to get the mac address in Java 6 but not in Java 5.
So once the problems running native commands in JRuby get fixed:
if RUBY_PLATFORM == 'java'
then your program would need the OS underlying the Java platform to execute
properly.
Once the problems running native commands in JRuby get fixed then I can supply
a better patch perhaps which abstracts RUBY_PLATFORM into os_platform and
{code}
os_platform = RUBY_PLATFORM
if RUBY_PLATFORM =~ /java/
os_platform = real_os_platform
{code}
and then use os_platform
The strange part here is normally in Java *Java* is the platform but Ruby in
Java makes use of Java *AND* the underlying os platform.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email