class Buildr::Shell::JIRB

Constants

JRUBY_VERSION

Public Instance Methods

launch(task) click to toggle source
# File lib/buildr/core/shell.rb, line 55
def launch(task)
  if jruby_home     # if JRuby is installed, use it
    cp = project.compile.dependencies +
      [project.path_to(:target, :classes)] +
      Dir.glob("#{jruby_home}#{File::SEPARATOR}lib#{File::SEPARATOR}*.jar") +
      task.classpath

    props = {
      'jruby.home' => jruby_home,
      'jruby.lib' => "#{jruby_home}#{File::SEPARATOR}lib"
    }
    props.merge! jrebel_props(project)
    props.merge! task.properties

    unless Util.win_os?
      uname = %xuname -m`
      cpu = if uname =~ /i[34567]86/
        'i386'
      elsif uname == 'i86pc'
        'x86'
      elsif uname =~ /amd64|x86_64/
        'amd64'
      end

      os = %xuname -s | tr '[A-Z]' '[a-z]'`
      path = if os == 'darwin'
        'darwin'
      else
        "#{os}-#{cpu}"
      end

      props['jna.boot.library.path'] = "#{jruby_home}/lib/native/#{path}"
    end

    props['jruby.script'] = if Util.win_os? then 'jruby.bat' else 'jruby' end
    props['jruby.shell'] = if Util.win_os? then 'cmd.exe' else '/bin/sh' end

    args = [
      "-Xbootclasspath/a:#{Dir.glob("#{jruby_home}#{File::SEPARATOR}lib#{File::SEPARATOR}jruby*.jar").join File::PATH_SEPARATOR}"
    ] + jrebel_args + task.java_args

    Java::Commands.java 'org.jruby.Main', "#{jruby_home}#{File::SEPARATOR}bin#{File::SEPARATOR}jirb", {
      :properties => props,
      :classpath => cp,
      :java_args => args
    }
  else
    cp = project.compile.dependencies + [ jruby_artifact, project.path_to(:target, :classes) ] +
         task.classpath
    props = jrebel_props(project).merge(task.properties)
    args = jrebel_args + task.java_args

    Java::Commands.java 'org.jruby.Main', '--command', 'irb', {
      :properties => props,
      :classpath => cp,
      :java_args => args
    }
  end
end