summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Arcieri <tony@medioh.com>2010-01-07 14:52:02 -0700
committerTony Arcieri <tony@medioh.com>2010-01-07 14:52:02 -0700
commit3f73cd3655cf47e3c9acdf06bd0f1bc989f41505 (patch)
treea200d6e78b30ea507058b3ecaca7469a62d143b0
parent0ff13d7f3547fcce760004fc3071612a4866114d (diff)
downloadsystemu-3f73cd3655cf47e3c9acdf06bd0f1bc989f41505.tar.gz
Monkeypatch in JRuby support
-rw-r--r--lib/systemu.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/systemu.rb b/lib/systemu.rb
index a29087c..9dbddfc 100644
--- a/lib/systemu.rb
+++ b/lib/systemu.rb
@@ -247,6 +247,50 @@ class SystemUniversal
end
end
+# some monkeypatching for JRuby
+if defined? JRUBY_VERSION
+ require 'jruby'
+ import org.jruby.RubyProcess
+
+ class SystemUniversal
+ def systemu
+ split_argv = JRuby::PathHelper.smart_split_command @argv
+ process = java.lang.Runtime.runtime.exec split_argv.to_java(:string)
+
+ stdout, stderr = [process.input_stream, process.error_stream].map do |stream|
+ reader = StreamReader.new(stream)
+ reader.run
+ reader.result
+ end
+
+ exit_code = process.wait_for
+ [RubyProcess::RubyStatus.new_process_status(JRuby.runtime, exit_code), stdout, stderr]
+ end
+
+ class StreamReader
+ def initialize(stream)
+ @reader = java.io.BufferedReader.new java.io.InputStreamReader.new(stream)
+ @mutex = Mutex.new
+ @data = ""
+ end
+
+ def run
+ Thread.new do
+ @mutex.synchronize do
+ while line = @reader.read_line; @data << line << "\n"; end
+ end
+ end
+ end
+
+ def result
+ @mutex.synchronize { @data }
+ end
+ end
+ end
+end
+
+
+
SystemU = SystemUniversal unless defined? SystemU
Systemu = SystemUniversal unless defined? Systemu