module Buildr::TestFramework::JRubyBased

Constants

VERSION

Public Class Methods

dependencies() click to toggle source
# File lib/buildr/java/bdd.rb, line 57
def dependencies
  unless @dependencies
    @dependencies = [jruby_artifact]
  end
  @dependencies
end
included(mod) click to toggle source
Calls superclass method
# File lib/buildr/java/bdd.rb, line 64
def included(mod)
  mod.extend ClassMethods
  super
end
jruby_artifact() click to toggle source
# File lib/buildr/java/bdd.rb, line 53
def jruby_artifact
  "org.jruby:jruby-complete:jar:#{version}"
end
version() click to toggle source
# File lib/buildr/java/bdd.rb, line 49
def version
  Buildr.settings.build['jruby'] || VERSION
end

Public Instance Methods

jruby_home() click to toggle source
# File lib/buildr/java/bdd.rb, line 117
def jruby_home
  @jruby_home ||= RUBY_PLATFORM =~ /java/ ? RbConfig::CONFIG['prefix'] :
    ( ENV['JRUBY_HOME'] || File.expand_path('~/.jruby') )
end
jruby_installed?() click to toggle source
# File lib/buildr/java/bdd.rb, line 122
def jruby_installed?
  !Dir.glob(File.join(jruby_home, 'lib', 'jruby*.jar')).empty?
end
run(tests, dependencies) click to toggle source
# File lib/buildr/java/bdd.rb, line 82
def run(tests, dependencies)
  maybe_install_jruby
  dependencies |= [task.compile.target.to_s]

  spec_dir = task.project.path_to(:source, :spec, :ruby)
  report_dir = task.report_to.to_s
  rm_rf report_dir
  mkdir_p report_dir
  ENV['CI_REPORTS'] = report_dir

  runner = runner_config
  runner.content = runner_content(binding)

  Buildr.write(runner.file, runner.content)
  rm_f runner.result

  if RUBY_PLATFORM[/java/] && !options.fork
    runtime = new_runtime
    runtime.getObject.java.lang.System.getProperties().putAll(options[:properties] || {})
    runtime.getLoadService.require runner.file
  else
    cmd_options = task.options.only(:properties, :java_args)
    cmd_options.update(:classpath => dependencies, :project => task.project)
    jruby runner.file, tests, cmd_options rescue nil
  end

  fail "Missing result YAML file: #{runner.result}" unless File.exist? runner.result

  result = YAML.load(File.read(runner.result))
  if Exception === result
    raise [result.message, result.backtrace].flatten.join("\n")
  end
  tests - result.failed
end

Protected Instance Methods

jruby(*args) click to toggle source
# File lib/buildr/java/bdd.rb, line 139
def jruby(*args)
  java_args = ['org.jruby.Main', *args]
  java_args << {} unless Hash === args.last
  cmd_options = java_args.last
  project = cmd_options.delete(:project)
  cmd_options[:classpath] ||= []
  if jruby_home && jruby_home != ''
    Dir.glob(File.join(jruby_home, 'lib', '*.jar')) { |jar| cmd_options[:classpath] << jar }
    cmd_options[:properties]['jruby.home'] = jruby_home
  end
  cmd_options[:java_args] ||= []
  cmd_options[:java_args] << '-Xmx512m' unless cmd_options[:java_args].detect {|a| a =~ /^-Xmx/}
  cmd_options[:properties] ||= {}
  Java::Commands.java(*java_args)
end
jruby_gem() click to toggle source
# File lib/buildr/java/bdd.rb, line 164
def jruby_gem
  %Q{
   require 'jruby'
   def JRuby.gem(name, version = '>0', *args)
      require 'rbconfig'
      jruby_home = RbConfig::CONFIG['prefix']
      expected_version = '#{TestFramework::JRubyBased.version}'
      unless JRUBY_VERSION >= expected_version
        fail "Expected JRuby version \#{expected_version} installed at \#{jruby_home} but got \#{JRUBY_VERSION}"
      end
      require 'rubygems'
      begin
        Kernel.send :gem, name, version
      rescue LoadError, Gem::LoadError => e
        require 'rubygems/gem_runner'
        args = ['install', name, '--version', version] + args
        Gem::GemRunner.new.run(args)
        Kernel.send :gem, name, version
      end
   end
  }
end
maybe_install_jruby() click to toggle source
# File lib/buildr/java/bdd.rb, line 127
def maybe_install_jruby
  unless jruby_installed?
    jruby_artifact = Buildr.artifact(TestFramework::JRubyBased.jruby_artifact)
    msg = "JRUBY_HOME is not correctly set or points to an invalid JRuby installation: #{jruby_home}"
    puts msg
    puts ''
    puts "You need to install JRuby version #{jruby_artifact.version} using your system package manager."

    fail msg unless jruby_installed?
  end
end
new_runtime(cfg = {}) { |config| ... } click to toggle source
# File lib/buildr/java/bdd.rb, line 155
def new_runtime(cfg = {})
  config = Java.org.jruby.RubyInstanceConfig.new
  cfg.each_pair do |name, value|
    config.send("#{name}=", value)
  end
  yield config if block_given?
  Java.org.jruby.Ruby.newInstance config
end
runner_config(runner = OpenStruct.new) click to toggle source
# File lib/buildr/java/bdd.rb, line 187
def runner_config(runner = OpenStruct.new)
  [:requires, :gems, :output, :format].each do |key|
    runner.send("#{key}=", options[key])
  end
  runner.html_report ||= File.join(task.report_to.to_s, 'report.html')
  runner.result ||= task.project.path_to(:target, :spec, 'result.yaml')
  runner.file ||= task.project.path_to(:target, :spec, 'runner.rb')
  runner.requires ||= []
  runner.requires.unshift File.join(File.dirname(__FILE__), 'test_result')
  runner.gems ||= {}
  runner.rspec ||= %w(--format progress --format documentation)
  runner.format.each { |format| runner.rspec << '--format' << format } if runner.format
  runner.rspec.push '--format', "Buildr::TestFramework::TestResult::YamlFormatter"
  runner.rspec.push '-o', runner.result
  runner
end