Skip to content

Commit

Permalink
Retab
Browse files Browse the repository at this point in the history
  • Loading branch information
Grzegorz Miklaszewski committed Nov 3, 2011
1 parent 9f9e8d1 commit 14f8906
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
40 changes: 20 additions & 20 deletions lib/rake_bubbler/bubble_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@
require 'tempfile'

module RakeBubbler
module BubbleTask
module BubbleTask

def self.included(klass)
klass.class_eval do

def invoke_with_output_capture(*params)
return invoke_without_output_capture(*params) unless RakeBubbler.capture_task?(name)
duration, error = nil
def invoke_with_output_capture(*params)
return invoke_without_output_capture(*params) unless RakeBubbler.capture_task?(name)
duration, error = nil
started = Time.now
# capture task output
output = RakeBubbler.capture_output do
time = Benchmark.measure(name) do
# capture task output
output = RakeBubbler.capture_output do
time = Benchmark.measure(name) do
begin
# invoke task
invoke_without_output_capture(*params)
# invoke task
invoke_without_output_capture(*params)
rescue Exception => e
error = e
end
end
duration = time.real
end
RakeBubbler.executed(name, duration, output, started, error)
end
duration = time.real
end
RakeBubbler.executed(name, duration, output, started, error)
raise error if error
end # invoke_with_output_capture
end # invoke_with_output_capture

alias_method :invoke_without_output_capture, :invoke
alias_method :invoke, :invoke_with_output_capture

end
end
end # BubbleTask
end # BubbleTask
end # RakeBubbler
48 changes: 24 additions & 24 deletions lib/rake_bubbler/rake_bubbler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ def capture_task?(name)
end

def capture_output
file = Tempfile.new(Digest::MD5.hexdigest((Time.now.to_i + rand(2**16)).to_s))
read, write = IO.pipe
save_stdout = $stdout.dup
$stdout.reopen(write)
if fork
read.close
yield
write.close
$stdout.reopen(save_stdout)
save_stdout.close
Process.wait
file = Tempfile.new(Digest::MD5.hexdigest((Time.now.to_i + rand(2**16)).to_s))
read, write = IO.pipe
save_stdout = $stdout.dup
$stdout.reopen(write)
if fork
read.close
yield
write.close
$stdout.reopen(save_stdout)
save_stdout.close
Process.wait
file.unlink
file.read
else
write.close
$stdout.close
Shell.new.tee(file.path) < read > save_stdout
read.close
save_stdout.close
exit!
end # fork
end # capture_output
file.read
else
write.close
$stdout.close
Shell.new.tee(file.path) < read > save_stdout
read.close
save_stdout.close
exit!
end # fork
end # capture_output

end
end

0 comments on commit 14f8906

Please sign in to comment.