class SyncWrap::JRubyVM

Provision JRuby (jruby.org - Ruby on the Java Virtual Machine) by direct download from the public S3 repo. Includes utility methods for checking and installing JRuby gems.

Host component dependencies: <Distro>

Constants

DEFAULT_VERSION

Default jruby_version to install

KNOWN_HASHES

A set of known cryptographic hashes, keyed by version string. We prefer sha256 but sha1 is what is published for 1.7.x.

Attributes

hash[W]

A cryptographic hash value (hexadecimal, some standard length) to use for verifying the 'jruby-bin-*.tar.gz' package. (Default: KNOWN_HASHES[ #jruby_version ])

jruby_gem_home_prop[W]

True if jruby (1.7.x) supports an alternative system gem home via the jruby.gem.home java property. By default, for jruby 1.7.x this will be used to move gems outside to allow for graceful jruby upgrades without needing to reinstall gems.

Jruby 9.x continues to abide by this property, through 9.1.12.0 atleast, but with an incessant warning, so the setting is dropped by default.

jruby_version[RW]

JRuby version to install (default: DEFAULT_VERSION)

Example values: '1.7.27', '9.1.15.0'

ruby_compat_version[W]

The ruby compatability version, as can be found in RbConfig::CONFIG on the same ruby, and used as a sub-directory of the user gem directory. In recent rubies this is 3 version numbers with 0 in the least significant (ruby naming: TEENY) position, e.g. '2.3.0'. By default, computed based on #jruby_version for known versions.

Public Class Methods

new( opts = {} ) click to toggle source
Calls superclass method SyncWrap::RubySupport.new
# File lib/syncwrap/components/jruby_vm.rb, line 64
def initialize( opts = {} )
  @jruby_version = DEFAULT_VERSION
  @hash = nil
  super( { ruby_command: 'jruby',
            gem_command: 'jgem' }.merge( opts ) )
end

Public Instance Methods

gem_install( gem, opts = {} ) click to toggle source

See SyncWrap::RubySupport#gem_install for usage.

The jruby jgem command tends to be slow on virtual hardware. This implementation adds a faster short-circuit when an exact, single :version is given that avoids calling jgem if the rubygems same version gemspec file is found.

Calls superclass method SyncWrap::RubySupport#gem_install
# File lib/syncwrap/components/jruby_vm.rb, line 169
def gem_install( gem, opts = {} )
  version = Array( opts[ :version ] )
  ver = (version.length == 1) && version[0] =~ /^=?\s*([0-9]\S+)/ && $1

  unless ( opts[:check] ||
           opts[:minimize] == false ||
           opts[:spec_check] == false ||
           ver.nil? )

    prefix = if opts[:user_install]
               jruby_user_gem_dir( opts[:user_install] )
             else
               jruby_gem_home
             end

    specs = [ "#{prefix}/specifications/#{gem}-#{ver}-java.gemspec",
              "#{prefix}/specifications/#{gem}-#{ver}.gemspec" ]

    shopts = {}
    case opts[ :user_install ]
    when String
      shopts[ :user ] = opts[ :user_install ]
    when nil, false
      shopts[ :user ] = :root
    end

    sh_if( "[ ! -e #{specs[0]} -a ! -e #{specs[1]} ]", shopts ) do
      super
    end
  else
    super
  end
end
Also aliased as: jruby_gem_install
gemrc_path() click to toggle source
# File lib/syncwrap/components/jruby_vm.rb, line 79
def gemrc_path
  "#{jruby_dist_path}/etc"
end
hash() click to toggle source
# File lib/syncwrap/components/jruby_vm.rb, line 71
def hash
  @hash || KNOWN_HASHES[ jruby_version ]
end
install() click to toggle source

Install jruby if the #jruby_version is not already present.

# File lib/syncwrap/components/jruby_vm.rb, line 123
def install
  jruby_install
  install_gemrc
end
jruby_bin_url() click to toggle source
# File lib/syncwrap/components/jruby_vm.rb, line 128
def jruby_bin_url
  [ 'http://jruby.org.s3.amazonaws.com/downloads',
    jruby_version,
    "jruby-bin-#{jruby_version}.tar.gz" ].join( '/' )
end
jruby_dist_path() click to toggle source
# File lib/syncwrap/components/jruby_vm.rb, line 75
def jruby_dist_path
  "#{local_root}/lib/jruby/jruby-#{jruby_version}"
end
jruby_gem_home() click to toggle source

The jruby system gem home, depending on jruby_gem_home_prop?

# File lib/syncwrap/components/jruby_vm.rb, line 84
def jruby_gem_home
  if jruby_gem_home_prop?
    "#{local_root}/lib/jruby/gems"
  else
    "#{jruby_dist_path}/lib/ruby/gems/shared"
  end
end
jruby_gem_home_prop?() click to toggle source
# File lib/syncwrap/components/jruby_vm.rb, line 106
def jruby_gem_home_prop?
  @jruby_gem_home_prop ||= version_lt?( jruby_version, [9] )
end
jruby_gem_install( gem, opts = {} )
Alias for: gem_install
jruby_install() click to toggle source

Install jruby, including usr/local/bin local contents

# File lib/syncwrap/components/jruby_vm.rb, line 135
def jruby_install

  root = "#{local_root}/lib/jruby"
  distro = "/tmp/jruby-bin-#{jruby_version}.tar.gz"

  dist_install( 'curl', minimal: true, check_install: true )

  sudo <<-SH
    if [ ! -d #{jruby_dist_path} ]; then
      mkdir -p #{root}
      mkdir -p #{root}/gems
      curl -sSL -o #{distro} #{jruby_bin_url}
  SH

  hash_verify( hash, distro, user: :root ) if hash

  sudo <<-SH
      tar -C #{root} -zxf #{distro}
      rm -f #{distro}
      mkdir -p #{gemrc_path}
      cd #{root} && ln -sfn jruby-#{jruby_version} jruby
      cd #{local_root}/bin && ln -sf ../lib/jruby/jruby/bin/jirb .
    fi
  SH

  rput( 'jruby/bin/', "#{local_root}/bin/", excludes: :dev, user: :root )
end
jruby_user_gem_dir( user ) click to toggle source
# File lib/syncwrap/components/jruby_vm.rb, line 92
def jruby_user_gem_dir( user )
  "~#{user}/.gem/jruby/#{ruby_compat_version}"
end
ruby_compat_version() click to toggle source
# File lib/syncwrap/components/jruby_vm.rb, line 118
def ruby_compat_version
  @ruby_compat_version ||= default_ruby_compat_version
end

Protected Instance Methods

default_ruby_compat_version() click to toggle source
# File lib/syncwrap/components/jruby_vm.rb, line 215
def default_ruby_compat_version
  if version_lt?( jruby_version, [9] )
    '1.9'
  elsif version_lt?( jruby_version, [9,1] )
    '2.2.0'
  else
    '2.3.0'
  end
end
jruby_gem_version_flags( reqs ) click to toggle source
# File lib/syncwrap/components/jruby_vm.rb, line 211
def jruby_gem_version_flags( reqs )
  Array( reqs ).flatten.compact.map { |req| "-v'#{req}'" }
end
min_deps_supported?() click to toggle source
# File lib/syncwrap/components/jruby_vm.rb, line 207
def min_deps_supported?
  version_gte?( jruby_version, [1,7,5] )
end