#!/usr/bin/env ruby if RUBY_PLATFORM =~ /java/i STDERR.puts "################################################################################" STDERR.puts "[WARN] embulk.gem is deprecated, and will be removed from v0.9." STDERR.puts "[WARN] embulk.gem's bin/embulk will be also removed from v0.9." STDERR.puts "[WARN] Use the jar version installed from http://dl.embulk.org/ instead." STDERR.puts "[WARN] See the issue and comment at: https://github.com/embulk/embulk/issues/628" STDERR.puts "################################################################################" STDERR.puts "" require 'java' if ENV['EMBULK_BIN_ENABLE_BUNDLE'] == File.expand_path(__FILE__) # bin/embulk is started by CRuby (embulk gem for CRuby is installed), and re-run by JRuby at the end of the script. # Bundler may be enabled in this path. ENV.delete('EMBULK_BIN_ENABLE_BUNDLE') else # bin/embulk is started by JRuby (embulk gem for JRuby is installed). # Bundler must be disabled in this path not to bother the JRuby's bundler. # org.embulk.EmbulkRunner processes the -b or --bundle option. The option should be removed to disable Bundler. # Search for -b or --bundle, and just remove it. bundle_option_index = ARGV.find_index {|arg| arg == '-b' || arg == '--bundle' } if bundle_option_index STDERR.puts "-b or --bundle options do not work when Embulk is triggered from command line by JRuby." ARGV.slice!(bundle_option_index, 2)[1] end $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__)) Dir.glob("#{File.expand_path('../classpath', File.dirname(__FILE__))}/*").each do |f_jar| $CLASSPATH << f_jar end end require 'embulk/version' embulk_run = Java::org.embulk.cli.EmbulkRun.new(Embulk::VERSION_INTERNAL) embulk_run.run(Java::JavaUtil::ArrayList.new(ARGV), Java::JavaUtil::ArrayList.new) exit 0 end java_args = [] jruby_args = [] default_optimize = false overwrite_optimize = nil until ARGV.empty? v = ARGV[0] case v when /-E(.*)/ external_script = v[2..-1] STDERR.puts "Running an external Ruby script: #{external_script}" load external_script ARGV.shift when "-J+O" overwrite_optimize = true ARGV.shift when "-J-O" overwrite_optimize = false ARGV.shift when "-J" prop_path = ARGV[1] unless prop_path STDERR.puts "-J option requires an option" exit 1 end props = File.read(prop_path) java_props = props.split("\n").reject {|prop| prop.strip.empty? } java_args = java_props + java_args ARGV.shift ARGV.shift when /-J(.*)/ java_args << v[2..-1] ARGV.shift when /-R(.*)/ jruby_args << v[2..-1] ARGV.shift when "run" default_optimize = true break else break end end # TODO cygwin check cygwin = false java_cmd = ENV['JAVACMD'] unless java_cmd if java_home = ENV['JAVA_HOME'] if cygwin java_cmd = "#{`cygpath -u "#{java_home}"`.strip}/bin/java" else java_cmd = "#{java_home}/bin/java" end else java_cmd = "java" end end if overwrite_optimize == true || (default_optimize == true && overwrite_optimize != false) java_args = %w[-XX:+AggressiveOpts -XX:+UseConcMarkSweepGC] + java_args else java_args = %w[-XX:+AggressiveOpts -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none] + java_args end # Disable bundler options of CRuby before starting JRuby ENV.delete('GEM_HOME') ENV.delete('GEM_PATH') ENV.delete('BUNDLE_GEMFILE') ENV.delete('BUNDLE_BIN_PATH') ENV.delete('RUBYLIB') ENV.delete('RUBYOPT') env = { 'EMBULK_BIN_ENABLE_BUNDLE' => File.expand_path(__FILE__) } begin require 'jruby-jars' rescue LoadError => e STDERR.puts "Could not load jruby-jar.gem. Did you run with \"bundle exec\"?" raise e end jruby_cp = "#{File.dirname(JRubyJars.core_jar_path)}/*" embulk_cp = "#{File.expand_path('../../classpath', __FILE__)}/*" # bundler is included in embulk-core.jar # java ... -jar ruby-complete.jar bin/embulk "$@" cmdline = [java_cmd] cmdline.concat java_args cmdline << '-cp' << [jruby_cp, embulk_cp].join(File::PATH_SEPARATOR) cmdline << 'org.jruby.Main' cmdline.concat jruby_args cmdline << __FILE__ cmdline.concat ARGV exec env, *cmdline exit 127