Forum: JRuby Gem::Platform::Java Uninitialized Constant

486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2013-07-17 17:06
(Received via mailing list)
All -

I'm creating a gem whose dependencies differ by platform -- if MRI Ruby,
it
needs to require rjb, and if JRuby, it very much needs not to require
rjb.

In my gemspec file, I have something like this:

if /java/ === RUBY_PLATFORM
  spec.platform = Gem::Platform::JAVA
end

However, when I gem build this gemspec in JRuby, I get this error:

Invalid gemspec in [mygem.gemspec]: uninitialized constant
Gem::Platform::JAVA

I also get that error for MSWIN.  In pry, I can see that the constants
do
exist:

[8] pry(main)> cd Gem::Platform
[9] pry(Gem::Platform):1> ls
constants: CURRENT  JAVA  MINGW  MSWIN  RUBY
Gem::Platform.methods: local  match  new
Gem::Platform#methods:
  ==  ===  =~  _deprecated_empty?  cpu  cpu=  empty?  eql?  hash
inspect
 os  os=  to_a  to_s  version  version=
instance variables: @local
locals: _  __  _dir_  _ex_  _file_  _in_  _out_  _pry_

Anyone know what's going on here?  My ultimate goal is to have a gem
that's
dependent on this one install the one appropriate to the platform, and
itself have an MRI and JRuby version.

Thanks for any help,
Keith
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 kristian (Guest)
on 2013-07-17 17:20
(Received via mailing list)
On Wed, Jul 17, 2013 at 4:05 PM, Keith Bennett
<keithrbennett@gmail.com>wrote:

> Gem::Platform::JAVA



quick fix would be to use the string "java"

- christian

BTW: my ruby2 does not have Gem::Platform::JAVA either - which does not
mean much since today is the first time I use ruby2
748797a1a0dc3de4c50e722d90589129?d=identicon&s=25 Rhett Sutphin (Guest)
on 2013-07-17 17:27
(Received via mailing list)
Hi Keith,

I don't see a Gem::Platform::JAVA when running under plain JRuby 1.7.4:

jruby-1.7.4 :001 > RUBY_PLATFORM
=> "java"
jruby-1.7.4 :003 > Gem::VERSION
=> "1.8.24"
jruby-1.7.4 :004 > Gem::Platform::JAVA
NameError: uninitialized constant Gem::Platform::JAVA
  from org/jruby/RubyModule.java:2631:in `const_missing'
  from (irb):5:in `evaluate'
  from org/jruby/RubyKernel.java:1093:in `eval'
  from org/jruby/RubyKernel.java:1489:in `loop'
  from org/jruby/RubyKernel.java:1254:in `catch'
  from org/jruby/RubyKernel.java:1254:in `catch'
  from /Users/rsutphin/.rvm/rubies/jruby-1.7.4/bin/irb:13:in `(root)'

I also don't see it when grepping the source for rubygems.

Perhaps Gem::Platform::JAVA is something introduced by something that's
loaded in the pry environment but not from a general gem install
environment? Or perhaps there are different versions of rubygems
involved.

HTH,
Rhett



From:  Keith Bennett <keithrbennett@gmail.com>
Reply-To:  <user@jruby.codehaus.org>
Date:  Wednesday, July 17, 2013 10:05 AM
To:  <user@jruby.codehaus.org>
Subject:  [jruby-user] Gem::Platform::Java Uninitialized Constant
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2013-07-17 17:37
(Received via mailing list)
That's the irony.  It *does* have it -- it just can't be specified (see
pry
output below, running MRI 2.0).

I know I can specify "java", I was doing that before, but I'm skeptical
that something normally requiring a composite object can be assigned
only
one of those elements, and still work properly.  I'm having problems
getting platform detection and installation of the proper platform's gem
working properly, and I thought cleaning up this issue might help.

Thanks,
Keith


[1] pry(main)> cd Gem::Platform::JAVA
[2] pry(#<Gem::Platform>):1> ls
Gem::Platform#methods: ==  ===  =~  cpu  cpu=  eql?  hash  inspect  os
os=
 to_a  to_s  version  version=
self.methods: __pry__
instance variables: @cpu  @os  @version
locals: _  __  _dir_  _ex_  _file_  _in_  _out_  _pry_
[3] pry(#<Gem::Platform>):1> to_s
=> "java"
[4] pry(#<Gem::Platform>):1> @cpu
=> nil
[5] pry(#<Gem::Platform>):1> @os
=> "java"
[6] pry(#<Gem::Platform>):1> @version
=> nil
[7] pry(#<Gem::Platform>):1> RUBY_VERSION
=> "2.0.0"
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2013-07-17 17:41
(Received via mailing list)
Rhett -

You're right!  It didn't occur to me that the platforms might differ by
platform. ;)

This would be a JRuby bug, right?:

JRuby Gem::Platform Constants:

constants: CURRENT_SPECIFICATION_VERSION  MARSHAL_FIELDS
 NONEXISTENT_SPECIFICATION_VERSION  TODAY

MRI Ruby 1.9.3 Gem::Platform Constants:

constants: CURRENT  JAVA  MINGW  MSWIN  RUBY

- Keith
748797a1a0dc3de4c50e722d90589129?d=identicon&s=25 Rhett Sutphin (Guest)
on 2013-07-17 17:50
(Received via mailing list)
Hi Keith,

Gem::Platform::JAVA doesn't exist in my install of 1.9.3-p448, either:

1.9.3p448 :001 > RUBY_PLATFORM
 => "x86_64-darwin12.4.1"
1.9.3p448 :002 > Gem::VERSION
 => "1.8.25"
1.9.3p448 :003 > Gem::Platform::JAVA
NameError: uninitialized constant Gem::Platform::JAVA
  from (irb):4
  from /Users/rsutphin/.rvm/rubies/ruby-1.9.3-p448/bin/irb:16:in
`<main>'


I think there's something getting pulled into the environment where you
are running pry for 1.9.3 that's adding the JAVA constant. It looks like
bundler is one possible culprit:

1.9.3p448 :004 > require 'bundler'
 => true
1.9.3p448 :005 > Gem::Platform::JAVA
 => #<Gem::Platform:0x3fdfa2cf5a3c @cpu=nil, @os="java", @version=nil>

So you shouldn't rely on that constant in your gemspec. The only
constant
that rubygems itself defines is Gem::Platform::RUBY, and that's just the
string "ruby". I think that using the string "java" is what's expected
I
can back up kristian in saying that "java" definitely works. If you look
at the source for Gem::Platform, you can see where it maps from the
string
to the composite object.


Rhett

From:  Keith Bennett <keithrbennett@gmail.com>
Reply-To:  <user@jruby.codehaus.org>
Date:  Wednesday, July 17, 2013 10:39 AM
To:  <user@jruby.codehaus.org>
Subject:  Re: [jruby-user] Gem::Platform::Java Uninitialized Constant
C983ad33b47479f17a28e083e1bb3d8b?d=identicon&s=25 Eric West (edubkendo)
on 2013-07-17 18:08
(Received via mailing list)
It seems like something on your system is introducing those constants.
Do
you have any pry plugins or a .pryrc file or anything?


$ rbenv version
2.0.0-rc2

$ pry
[1] pry(main)> cd Gem::Platform
[2] pry(Gem::Platform):1> ls
constants: CURRENT  RUBY
Gem::Platform.methods: local  match  new
Gem::Platform#methods:
  ==   =~   cpu=  hash     os   to_a  version
  ===  cpu  eql?  inspect  os=  to_s  version=
instance variables: @local
locals: _  __  _dir_  _ex_  _file_  _in_  _out_  _pry_
[3] pry(Gem::Platform):1>
[4] pry(main)>

$ rbenv version
jruby-1.7.4

$ pry
[1] pry(main)> cd Gem::Platform
[2] pry(Gem::Platform):1> ls
constants: CURRENT  RUBY
Gem::Platform.methods: local  match  new
Gem::Platform#methods:
  ==   =~                  cpu   empty?  hash     os   to_a  version
  ===  _deprecated_empty?  cpu=  eql?    inspect  os=  to_s  version=
instance variables: @local
locals: _  __  _dir_  _ex_  _file_  _in_  _out_  _pry_
[3] pry(Gem::Platform):1>

$ rbenv version
1.9.3-p327

$ pry
[1] pry(main)> RUBY_VERSION
=> "1.9.3"
[2] pry(main)> cd Gem::Platform
[3] pry(Gem::Platform):1> ls
constants: CURRENT  RUBY
Gem::Platform.methods: local  match  new
Gem::Platform#methods:
  ==   =~                  cpu   empty?  hash     os   to_a  version
  ===  _deprecated_empty?  cpu=  eql?    inspect  os=  to_s  version=
instance variables: @local
locals: _  __  _dir_  _ex_  _file_  _in_  _out_  _pry_
[4] pry(Gem::Platform):1>

There are techniques for doing what you want though. Check out How do I
make a gem that targets both MRI and
JRuby?<http://stackoverflow.com/a/13540730/1200100>for instance.
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2013-07-17 20:34
(Received via mailing list)
Ok, guys, you have definitively answered my question now.  I'll use
"java".

Thanks,
Keith
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.