lib/autobuild/reporting.rb in autobuild-1.5.20 vs lib/autobuild/reporting.rb in autobuild-1.5.21.rc1

- old
+ new

@@ -13,30 +13,58 @@ require 'autobuild/config' require 'autobuild/exceptions' module Autobuild - def self.progress(msg) + def self.progress(*args) if @last_msg progress_value(100) puts end @last_msg = nil - puts " #{msg}" + + if args.empty? + puts + else + puts " #{color(*args)}" + end end - def self.progress_with_value(msg) + def self.progress_with_value(*args) if @last_msg progress_value(100) puts end - @last_msg = msg - print " #{msg}" + @last_msg = " #{color(args[0], *args[1..-1])}" + + print @last_msg end def self.progress_value(value) - print "\r #{@last_msg} (#{value}%)" + print "\r#{@last_msg} (#{value}%)" end + # The exception type that is used to report multiple errors that occured + # when ignore_errors is set + class CompositeException < Autobuild::Exception + # The array of exception objects representing all the errors that + # occured during the build + attr_reader :original_errors + + def initialize(original_errors) + @original_errors = original_errors + end + + def mail?; true end + + def to_s + result = ["#{original_errors.size} errors occured"] + original_errors.each_with_index do |e, i| + result << "(#{i}) #{e.to_s}" + end + result.join("\n") + end + end + ## The reporting module provides the framework # to run commands in autobuild and report errors # to the user # # It does not use a logging framework like Log4r, but it should ;-) @@ -46,9 +74,24 @@ ## Run a block and report known exception # If an exception is fatal, the program is terminated using exit() def self.report begin yield + + # If ignore_erorrs is true, check if some packages have failed + # on the way. If so, raise an exception to inform the user about + # it + errors = [] + Autobuild::Package.each do |name, pkg| + if pkg.failed? + errors << pkg.failure + end + end + + if !errors.empty? + raise CompositeException.new(errors) + end + rescue Autobuild::Exception => e error(e) exit(1) if e.fatal? end end