Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using spoon for JRuby support #140

Merged
merged 2 commits into from
Jan 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ source "http://rubygems.org"

gemspec

platform :jruby do
gem 'spoon', '~> 0.0.1'
end

group :development do
gem 'parka'
gem 'rake'
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GEM
diff-lcs (1.1.3)
fakefs (0.3.2)
hpricot (0.8.2)
hpricot (0.8.2-java)
mime-types (1.16)
mustache (0.11.2)
parka (0.6.2)
Expand All @@ -25,6 +26,7 @@ GEM
thor
rake (0.9.2.2)
rcov (0.9.8)
rcov (0.9.8-java)
rdiscount (1.6.5)
rest-client (1.6.1)
mime-types (>= 1.16)
Expand All @@ -42,11 +44,13 @@ GEM
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
rubyzip (0.9.4)
spoon (0.0.1)
term-ansicolor (1.0.7)
thor (0.14.6)
xml-simple (1.0.15)

PLATFORMS
java
ruby

DEPENDENCIES
Expand All @@ -60,3 +64,4 @@ DEPENDENCIES
rr (~> 1.0.2)
rspec (~> 2.0)
rubyzip
spoon (~> 0.0.1)
25 changes: 18 additions & 7 deletions lib/foreman/process.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "foreman"
require "rubygems"
require "spoon" if RUBY_PLATFORM == "java"

class Foreman::Process

Expand Down Expand Up @@ -27,15 +29,24 @@ def name

private

def jruby?
defined?(RUBY_PLATFORM) and RUBY_PLATFORM == "java"
end

def fork_with_io(command)
reader, writer = IO.pipe
pid = fork do
trap("INT", "IGNORE")
writer.sync = true
$stdout.reopen writer
$stderr.reopen writer
reader.close
exec Foreman.runner, replace_command_env(command)
command = replace_command_env(command)
pid = if jruby?
Spoon.spawnp Foreman.runner, command
else
fork do
trap("INT", "IGNORE")
writer.sync = true
$stdout.reopen writer
$stderr.reopen writer
reader.close
exec Foreman.runner, command
end
end
[ reader, pid ]
end
Expand Down