Skip to content

Commit

Permalink
Use popen3 instead of `` for pack200 operations to drain STDIO.
Browse files Browse the repository at this point in the history
If the pack200 operation is writing to STDOUT or STDERR and the buffer fills, the process will block.  Since Kernel#`` is itself a blocking operation and won't drain STDIO until the command finishes, the whole process blocks forever.
nirvdrum committed Sep 24, 2015
1 parent a30da98 commit b40bc95
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion maven/jruby-dist/pom.rb
Original file line number Diff line number Diff line change
@@ -47,6 +47,8 @@
end

execute :pack200 do |ctx|
require 'open3'

jruby_home = Dir[ File.join( ctx.project.build.directory.to_pathname,
'META-INF/jruby.home/**/*.jar' ) ]
gem_home = Dir[ File.join( ctx.project.build.directory.to_pathname,
@@ -58,7 +60,21 @@
file = f.sub /.jar$/, ''
unless File.exists?( file + '.pack.gz' )
puts "pack200 #{f.sub(/.*jruby.home./, '').sub(/.*rubygems-provided./, '')}"
`pack200 #{file}.pack.gz #{file}.jar`

Open3.popen3('pack200', "#{file}.pack.gz", "#{file}.jar") do |stdin, stdout, stderr, wait_thread|
stdio_threads = []

stdio_threads << Thread.new(stdout) do |stdout|
stdout.each { |line| $stdout.puts line }
end

stdio_threads << Thread.new(stderr) do |stderr|
stderr.each { |line| $stderr.puts line }
end

stdio_threads.each(&:join)
wait_thread.value
end
end
end
end

2 comments on commit b40bc95

@nirvdrum
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkristian This tested out okay for me, but please review when you have a moment.

Sorry, something went wrong.

@mkristian
Copy link
Member

@mkristian mkristian commented on b40bc95 Sep 25, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, something went wrong.

Please sign in to comment.