Skip to content

Instantly share code, notes, and snippets.

@myabc
Created April 9, 2012 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myabc/2346845 to your computer and use it in GitHub Desktop.
Save myabc/2346845 to your computer and use it in GitHub Desktop.
task :java_compile do
# Pick the right class path, depending if we're using an rvm installed JRuby
jruby_cpath = ENV['MY_RUBY_HOME'] || ENV['JRUBY_HOME']
raise 'MY_RUBY_HOME or JRUBY_HOME are not set' unless jruby_cpath
puts 'Doing a simple compilation'
sh %(javac -source 1.6 -target 1.6 -cp #{jruby_cpath}/lib/jruby.jar java/**/*.java)
mkdir_p '../lib/jrubytesting'
sh %(jar cf ../lib/jrubytesting/test_jruby_library.jar -C java jrubytesting/TestJrubyLibraryService.class)
puts
end
task :c_compile do
require 'rubygems/ext'
gem_dir = File.expand_path(File.dirname(__FILE__) + '../../')
extension_dir = File.join(gem_dir, File.dirname('ext/jrubytesting/extconf.rb'))
dest_path = File.join(gem_dir, 'lib/jrubytesting')
Dir.chdir(extension_dir) do
results = Gem::Ext::ExtConfBuilder.build('extconf.rb', gem_dir, dest_path, [])
say results.join("\n") if Gem.configuration.really_verbose
end
end
def is_jruby?
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
end
task :default => is_jruby? ? :java_compile : :c_compile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment