You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by as...@apache.org on 2008/07/29 02:37:16 UTC

svn commit: r680585 - in /incubator/buildr/trunk: ./ lib/buildr/core/ lib/buildr/ide/ lib/buildr/java/ lib/buildr/packaging/ spec/

Author: assaf
Date: Mon Jul 28 17:37:12 2008
New Revision: 680585

URL: http://svn.apache.org/viewvc?rev=680585&view=rev
Log:
Added: error, info and trace methods.

Modified:
    incubator/buildr/trunk/CHANGELOG
    incubator/buildr/trunk/lib/buildr/core/application.rb
    incubator/buildr/trunk/lib/buildr/core/build.rb
    incubator/buildr/trunk/lib/buildr/core/checks.rb
    incubator/buildr/trunk/lib/buildr/core/compile.rb
    incubator/buildr/trunk/lib/buildr/core/project.rb
    incubator/buildr/trunk/lib/buildr/core/test.rb
    incubator/buildr/trunk/lib/buildr/core/transports.rb
    incubator/buildr/trunk/lib/buildr/ide/eclipse.rb
    incubator/buildr/trunk/lib/buildr/ide/idea.rb
    incubator/buildr/trunk/lib/buildr/ide/idea7x.rb
    incubator/buildr/trunk/lib/buildr/java/commands.rb
    incubator/buildr/trunk/lib/buildr/java/compilers.rb
    incubator/buildr/trunk/lib/buildr/java/packaging.rb
    incubator/buildr/trunk/lib/buildr/java/pom.rb
    incubator/buildr/trunk/lib/buildr/java/test_frameworks.rb
    incubator/buildr/trunk/lib/buildr/packaging/artifact.rb
    incubator/buildr/trunk/lib/buildr/packaging/zip.rb
    incubator/buildr/trunk/spec/compile_spec.rb
    incubator/buildr/trunk/spec/spec_helpers.rb
    incubator/buildr/trunk/spec/test_spec.rb

Modified: incubator/buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Mon Jul 28 17:37:12 2008
@@ -1,5 +1,6 @@
 1.3.3 (Pending)
 * Added: Growl notifications (OS X only).
+* Added: error, info and trace methods.
 * Changed: Error reporting now shows 'buildr aborted!' (used to say rake),
 more of the stack trace without running --trace, and when running with
 supported terminal, error message is red.

Modified: incubator/buildr/trunk/lib/buildr/core/application.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/application.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/application.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/application.rb Mon Jul 28 17:37:12 2008
@@ -187,7 +187,7 @@
         real << ("%ih" % (@times.real / 3600)) if @times.real >= 3600
         real << ("%im" % ((@times.real / 60) % 60)) if @times.real >= 60
         real << ("%.3fs" % (@times.real % 60))
-        puts "Completed in #{real.join}"
+        puts $terminal.color("Completed in #{real.join}", :green)
       end
       @on_completion.each { |block| block.call }
     end
@@ -430,13 +430,29 @@
   end
 end
 
-if HighLine.use_color?
-  module Kernel #:nodoc:
-    alias :warn_without_color :warn
-    def warn(message)
-      warn_without_color $terminal.color(message.to_s, :blue)
-    end
-  end
+
+alias :warn_without_color :warn
+
+# Show warning message.
+def warn(message)
+  warn_without_color $terminal.color(message.to_s, :blue) if verbose
+end
+
+# Show error message.  Use this when you need to show an error message and not throwing
+# an exception that will stop the build.
+def error(message)
+  puts $terminal.color(message.to_s, :red)
+end
+
+# Show optional information.  The message is printed only when running in verbose
+# mode (the default).
+def info(message)
+  puts message if verbose
+end
+
+# Show message.  The message is printed out only when running in trace mode.
+def trace(message)
+  puts message if Buildr.application.options.trace
 end
 
 

Modified: incubator/buildr/trunk/lib/buildr/core/build.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/build.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/build.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/build.rb Mon Jul 28 17:37:12 2008
@@ -237,7 +237,7 @@
       # Executes SVN command and returns the output.
       def svn(*args)
         cmd = 'svn ' + args.map { |arg| arg[' '] ? %Q{"#{arg}"} : arg }.join(' ')
-        puts cmd if verbose
+        info cmd
         `#{cmd}`.tap { fail 'SVN command failed' unless $?.exitstatus == 0 }
       end
 

Modified: incubator/buildr/trunk/lib/buildr/core/checks.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/checks.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/checks.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/checks.rb Mon Jul 28 17:37:12 2008
@@ -130,7 +130,7 @@
         # Run the expectation. We only print the expectation name when tracing (to know they all ran),
         # or when we get a failure.
         begin
-          puts description if Buildr.application.options.trace
+          trace description
           klass.new.instance_eval &@block
         rescue Exception=>error
           raise error.exception("#{description}\n#{error}").tap { |wrapped| wrapped.set_backtrace(error.backtrace) }
@@ -149,10 +149,10 @@
           begin
             expect.run_against project
             passed
-          rescue Exception=>error
+          rescue Exception=>ex
             if verbose
-              puts error.backtrace.detect { |line| line =~ /#{Buildr.application.buildfile}/ } || ""
-              puts error
+              error ex.backtrace.select { |line| line =~ /#{Buildr.application.buildfile}/ }.join("\n")
+              error ex
             end
             false
           end

Modified: incubator/buildr/trunk/lib/buildr/core/compile.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/compile.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/compile.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/compile.rb Mon Jul 28 17:37:12 2008
@@ -123,7 +123,7 @@
         return false if map.empty?
         return true unless File.exist?(target.to_s)
         source_files_not_yet_compiled = map.select { |source, target| !File.exist?(target) }
-        puts "Compile needed because source file #{source_files_not_yet_compiled[0][0]} has no corresponding #{source_files_not_yet_compiled[0][1]}" if Buildr.application.options.trace && !source_files_not_yet_compiled.empty?
+        trace "Compile needed because source file #{source_files_not_yet_compiled[0][0]} has no corresponding #{source_files_not_yet_compiled[0][1]}" unless source_files_not_yet_compiled.empty?
         return true if map.any? { |source, target| !File.exist?(target) || File.stat(source).mtime > File.stat(target).mtime }
         oldest = map.map { |source, target| File.stat(target).mtime }.min
         return dependencies.any? { |path| file(path).timestamp > oldest }
@@ -175,7 +175,7 @@
             FileList["#{source}/**/*.{#{ext_glob}}"].reject { |file| File.directory?(file) }.
               each { |file| map[file] = File.join(target, Util.relative_path(file, source).ext(target_ext)) }
           else
-            map[source] = File.join(target, File.basename(source).ext(target_ext))
+            map[source] = target # File.join(target, File.basename(source).ext(target_ext))
           end
           map
         end
@@ -225,7 +225,7 @@
           raise 'No compiler selected and can\'t determine which compiler to use' unless compiler
           raise 'No target directory specified' unless target
           mkpath target.to_s, :verbose=>false
-          puts "Compiling #{task.name.gsub(/:[^:]*$/, '')} into #{target.to_s}" if verbose
+          info "Compiling #{task.name.gsub(/:[^:]*$/, '')} into #{target.to_s}"
           @compiler.compile(sources.map(&:to_s), target.to_s, dependencies.map(&:to_s))
           # By touching the target we let other tasks know we did something,
           # and also prevent recompiling again for dependencies.
@@ -498,9 +498,7 @@
         # This comes last because the target path is set inside the project definition.
         project.build project.compile.target
         project.clean do
-          verbose(false) do
-            rm_rf project.compile.target.to_s
-          end
+          rm_rf project.compile.target.to_s, :verbose=>false
         end
       end
     end

Modified: incubator/buildr/trunk/lib/buildr/core/project.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/project.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/project.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/project.rb Mon Jul 28 17:37:12 2008
@@ -319,7 +319,7 @@
       def local_task(args, &block)
         task args do |task|
           local_projects do |project|
-            puts block.call(project.name) if block && verbose
+            info block.call(project.name) if block
             task("#{project.name}:#{task.name}").invoke
           end
         end
@@ -342,7 +342,7 @@
           local_projects(File.dirname(dir), &block)
         elsif block
           if projects.empty?
-            warn "No projects defined for directory #{Buildr.application.original_dir}" if verbose
+            warn "No projects defined for directory #{Buildr.application.original_dir}"
           else
             projects.each { |project| block[project] }
           end

Modified: incubator/buildr/trunk/lib/buildr/core/test.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/test.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/test.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/test.rb Mon Jul 28 17:37:12 2008
@@ -159,7 +159,7 @@
           # !(foo ^ bar) tests for equality and accepts nil as false (and select is less obfuscated than reject on ^).
           projects = ([project] + project.projects).select { |project| !(project.test.options[:integration] ^ integration) }
           projects.each do |project|
-            puts "Testing #{project.name}" if verbose
+            info "Testing #{project.name}"
             begin
               project.test.invoke
             rescue
@@ -424,11 +424,11 @@
       if @tests.empty?
         @passed_tests, @failed_tests = [], []
       else
-        puts "Running tests in #{@project.name}" if verbose
+        info "Running tests in #{@project.name}"
         @passed_tests = @framework.run(@tests, dependencies)
         @failed_tests = @tests - @passed_tests
         unless @failed_tests.empty?
-          warn "The following tests failed:\n#{@failed_tests.join("\n")}" if verbose
+          error "The following tests failed:\n#{@failed_tests.join("\n")}"
           fail 'Tests failed!'
         end
       end
@@ -458,7 +458,7 @@
       @setup = task("#{name}:setup")
       @teardown = task("#{name}:teardown")
       enhance do
-        puts 'Running integration tests...'  if verbose
+        info 'Running integration tests...'
         TestTask.run_local_tests true
       end
     end
@@ -565,10 +565,8 @@
       test.framework
 
       project.clean do
-        verbose(false) do
-          rm_rf test.compile.target.to_s if test.compile.target
-          rm_rf test.report_to.to_s
-        end
+        rm_rf test.compile.target.to_s, :verbose=>false if test.compile.target
+        rm_rf test.report_to.to_s, :verbose=>false
       end
     end
 

Modified: incubator/buildr/trunk/lib/buildr/core/transports.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/transports.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/transports.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/transports.rb Mon Jul 28 17:37:12 2008
@@ -292,7 +292,7 @@
     def read(options = nil, &block)
       options ||= {}
       connect do |http|
-        puts "Requesting #{self}"  if Buildr.application.options.trace
+        trace "Requesting #{self}"
         headers = { 'If-Modified-Since' => CGI.rfc1123_date(options[:modified].utc) } if options[:modified]
         request = Net::HTTP::Get.new(request_uri.empty? ? '/' : request_uri, headers)
         request.basic_auth self.user, self.password if self.user
@@ -300,14 +300,14 @@
           case response
           when Net::HTTPNotModified
             # No modification, nothing to do.
-            puts 'Not modified since last download' if Buildr.application.options.trace
+            trace 'Not modified since last download'
             return nil
           when Net::HTTPRedirection
             # Try to download from the new URI, handle relative redirects.
-            puts "Redirected to #{response['Location']}" if Buildr.application.options.trace
+            trace "Redirected to #{response['Location']}"
             return (self + URI.parse(response['location'])).read(options, &block)
           when Net::HTTPOK
-            puts "Downloading #{self}" if verbose
+            info "Downloading #{self}"
             result = nil
             with_progress_bar options[:progress], path.split('/').last, response.content_length do |progress|
               if block
@@ -338,7 +338,7 @@
     def write_internal(options, &block) #:nodoc:
       options ||= {}
       connect do |http|
-        puts "Uploading to #{path}" if Buildr.application.options.trace
+        trace "Uploading to #{path}"
         content = StringIO.new
         while chunk = yield(32 * 4096)
           content << chunk
@@ -363,7 +363,7 @@
         case response
         when Net::HTTPRedirection
           # Try to download from the new URI, handle relative redirects.
-          puts "Redirected to #{response['Location']}" if Buildr.application.options.trace
+          trace "Redirected to #{response['Location']}"
           content.rewind
           return (self + URI.parse(response['location'])).write_internal(options) { |bytes| content.read(bytes) }
         when Net::HTTPSuccess
@@ -408,14 +408,14 @@
       ssh_options = { :port=>port, :password=>password }.merge(options[:ssh_options] || {})
       ssh_options[:password] ||= SFTP.passwords[host]
       begin
-        puts "Connecting to #{host}" if Buildr.application.options.trace
+        trace "Connecting to #{host}"
         result = nil
         Net::SFTP.start(host, user, ssh_options) do |sftp|
           SFTP.passwords[host] = ssh_options[:password]
-          puts 'connected' if Buildr.application.options.trace
+          trace 'connected'
 
           with_progress_bar options[:progress] && options[:size], path.split('/'), options[:size] || 0 do |progress|
-            puts "Downloading to #{path}" if Buildr.application.options.trace
+            trace "Downloading to #{path}"
             sftp.file.open(path, 'r') do |file|
               if block
                 while chunk = file.read(32 * 4096)
@@ -451,14 +451,14 @@
       ssh_options = { :port=>port, :password=>password }.merge(options[:ssh_options] || {})
       ssh_options[:password] ||= SFTP.passwords[host]
       begin
-        puts "Connecting to #{host}" if Buildr.application.options.trace
+        trace "Connecting to #{host}"
         Net::SFTP.start(host, user, ssh_options) do |sftp|
           SFTP.passwords[host] = ssh_options[:password]
-          puts 'connected' if Buildr.application.options.trace
+          trace 'Connected'
 
           # To create a path, we need to create all its parent. We use realpath to determine if
           # the path already exists, otherwise mkdir fails.
-          puts "Creating path #{path}" if Buildr.application.options.trace
+          trace "Creating path #{path}"
           File.dirname(path).split('/').reject(&:empty?).inject('/') do |base, part|
             combined = base + part
             sftp.close(sftp.opendir!(combined)) rescue sftp.mkdir! combined, {}
@@ -466,7 +466,7 @@
           end
 
           with_progress_bar options[:progress] && options[:size], path.split('/'), options[:size] || 0 do |progress|
-            puts "Uploading to #{path}" if Buildr.application.options.trace
+            trace "Uploading to #{path}"
             sftp.file.open(path, 'w') do |file|
               while chunk = yield(32 * 4096)
                 file.write chunk

Modified: incubator/buildr/trunk/lib/buildr/ide/eclipse.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/eclipse.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/eclipse.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/eclipse.rb Mon Jul 28 17:37:12 2008
@@ -57,7 +57,7 @@
 
         # The only thing we need to look for is a change in the Buildfile.
         file(project.path_to(".classpath")=>sources) do |task|
-          puts "Writing #{task.name}" if verbose
+          info "Writing #{task.name}"
 
           # Find a path relative to the project's root directory.
           relative = lambda do |path|
@@ -143,7 +143,7 @@
 
         # The only thing we need to look for is a change in the Buildfile.
         file(project.path_to(".project")=>sources) do |task|
-          puts "Writing #{task.name}" if verbose
+          info "Writing #{task.name}"
           File.open(task.name, "w") do |file|
             xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
             xml.projectDescription do

Modified: incubator/buildr/trunk/lib/buildr/ide/idea.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/idea.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/idea.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/idea.rb Mon Jul 28 17:37:12 2008
@@ -58,7 +58,7 @@
 
       # The only thing we need to look for is a change in the Buildfile.
       file(task_name=>sources) do |task|
-        puts "Writing #{task.name}" if verbose
+        info "Writing #{task.name}"
 
         # Idea handles modules slightly differently if they're WARs
         idea_types = Hash.new("JAVA_MODULE")
@@ -154,7 +154,7 @@
         idea.enhance [ file(task_name) ]
 
         file(task_name=>sources) do |task|
-          puts "Writing #{task.name}" if verbose
+          info "Writing #{task.name}"
 
           # Generating just the little stanza that chanages from one project to another
           partial = StringIO.new

Modified: incubator/buildr/trunk/lib/buildr/ide/idea7x.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/idea7x.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/idea7x.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/idea7x.rb Mon Jul 28 17:37:12 2008
@@ -78,7 +78,7 @@
 
         # Project type is going to be the first package type
         if package = project.packages.first
-          puts "Writing #{task.name}" if verbose
+          info "Writing #{task.name}"
           File.open(task.name, "w") do |file|
             xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
             xml.module(:version=>"4", :relativePaths=>"true", :type=>"JAVA_MODULE") do
@@ -173,7 +173,7 @@
         task_name = project.path_to("#{project.name.gsub(':', '-')}-7x.ipr")
         idea7x.enhance [ file(task_name) ]
         file(task_name=>sources) do |task|
-          puts "Writing #{task.name}" if verbose
+          info "Writing #{task.name}"
 
           # Generating just the little stanza that chanages from one project to another
           partial = StringIO.new

Modified: incubator/buildr/trunk/lib/buildr/java/commands.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/commands.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/commands.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/commands.rb Mon Jul 28 17:37:12 2008
@@ -47,7 +47,7 @@
         cmd_args += (options[:java_args] || (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split).flatten
         cmd_args += args.flatten.compact
         unless Buildr.application.options.dryrun
-          puts "Running #{name}" if verbose
+          info "Running #{name}"
           block = lambda { |ok, res| fail "Failed to execute #{name}, see errors above" unless ok } unless block
           puts cmd_args.join(' ') if Buildr.application.options.trace
           cmd_args = cmd_args.map(&:inspect).join(' ') if Util.win_os?
@@ -88,8 +88,8 @@
         cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
         cmd_args += files
         unless Buildr.application.options.dryrun
-          puts 'Running apt' if verbose
-          puts (['apt'] + cmd_args).join(' ') if Buildr.application.options.trace
+          info 'Running apt'
+          trace (['apt'] + cmd_args).join(' ')
           Java.load
           Java.com.sun.tools.apt.Main.process(cmd_args.to_java(Java.java.lang.String)) == 0 or
             fail 'Failed to process annotations, see errors above'
@@ -124,8 +124,8 @@
         cmd_args += options[:javac_args].flatten if options[:javac_args]
         cmd_args += files
         unless Buildr.application.options.dryrun
-          puts "Compiling #{files.size} source files in #{name}" if verbose
-          puts (['javac'] + cmd_args).join(' ') if Buildr.application.options.trace
+          info "Compiling #{files.size} source files in #{name}"
+          trace (['javac'] + cmd_args).join(' ')
           Java.load
           Java.com.sun.tools.javac.Main.compile(cmd_args.to_java(Java.java.lang.String)) == 0 or 
             fail 'Failed to compile, see errors above'
@@ -174,8 +174,8 @@
         cmd_args += args.flatten.uniq
         name = options[:name] || Dir.pwd
         unless Buildr.application.options.dryrun
-          puts "Generating Javadoc for #{name}" if verbose
-          puts (['javadoc'] + cmd_args).join(' ') if Buildr.application.options.trace
+          info "Generating Javadoc for #{name}"
+          trace (['javadoc'] + cmd_args).join(' ')
           Java.load
           Java.com.sun.tools.javadoc.Main.execute(cmd_args.to_java(Java.java.lang.String)) == 0 or
             fail 'Failed to generate Javadocs, see errors above'

Modified: incubator/buildr/trunk/lib/buildr/java/compilers.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/compilers.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/compilers.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/compilers.rb Mon Jul 28 17:37:12 2008
@@ -63,7 +63,7 @@
         cmd_args += javac_args
         cmd_args += files_from_sources(sources)
         unless Buildr.application.options.dryrun
-          puts (['javac'] + cmd_args).join(' ') if Buildr.application.options.trace
+          trace((['javac'] + cmd_args).join(' '))
           Java.load
           Java.com.sun.tools.javac.Main.compile(cmd_args.to_java(Java.java.lang.String)) == 0 or
             fail 'Failed to compile, see errors above'
@@ -144,7 +144,7 @@
 
         unless Buildr.application.options.dryrun
           Scalac.scala_home or fail 'Are we forgetting something? SCALA_HOME not set.'
-          puts (['scalac'] + cmd_args).join(' ') if Buildr.application.options.trace
+          trace((['scalac'] + cmd_args).join(' '))
           if Scalac.use_fsc
             system(([File.expand_path('bin/fsc', Scalac.scala_home)] + cmd_args).join(' ')) or
               fail 'Failed to compile, see errors above'
@@ -338,8 +338,8 @@
         end
         cmd_args += sources.flatten.uniq
         unless Buildr.application.options.dryrun
-          puts "Generating Javadoc for #{name}" if verbose
-          puts (['javadoc'] + cmd_args).join(' ') if Buildr.application.options.trace
+          info "Generating Javadoc for #{name}"
+          trace (['javadoc'] + cmd_args).join(' ')
           Java.load
           Java.com.sun.tools.javadoc.Main.execute(cmd_args.to_java(Java.java.lang.String)) == 0 or
             fail 'Failed to generate Javadocs, see errors above'
@@ -410,8 +410,8 @@
         cmd_args += (sources.map(&:to_s) - [task.name]).
           map { |file| File.directory?(file) ? FileList["#{file}/**/*.java"] : file }.flatten
         unless Buildr.application.options.dryrun
-          puts 'Running apt' if verbose
-          puts (['apt'] + cmd_args).join(' ') if Buildr.application.options.trace
+          info 'Running apt'
+          trace (['apt'] + cmd_args).join(' ')
           Java.com.sun.tools.apt.Main.process(cmd_args.to_java(Java.java.lang.String)) == 0 or
             fail 'Failed to process annotations, see errors above'
         end

Modified: incubator/buildr/trunk/lib/buildr/java/packaging.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/packaging.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/packaging.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/packaging.rb Mon Jul 28 17:37:12 2008
@@ -546,7 +546,7 @@
           return @descriptor if @descriptor
           descriptor_path = path_to('META-INF/application.xml')
           @descriptor = file(descriptor_path) do |task|
-            puts "Creating EAR Descriptor: #{task.to_s}" if Buildr.application.options.trace
+            trace "Creating EAR Descriptor: #{task.to_s}"
             mkpath File.dirname(task.name), :verbose=>false
             File.open(task.name, 'w') { |file| file.print task.xml }
           end

Modified: incubator/buildr/trunk/lib/buildr/java/pom.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/pom.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/pom.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/pom.rb Mon Jul 28 17:37:12 2008
@@ -51,7 +51,7 @@
         when String
           filename = File.expand_path(source)
           unless pom = cache[filename]
-            puts "Loading m2 pom file from #{filename}" if Buildr.application.options.trace
+            trace "Loading m2 pom file from #{filename}"
             pom = POM.new(IO.read(filename))
             cache[filename] = pom
           end

Modified: incubator/buildr/trunk/lib/buildr/java/test_frameworks.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/test_frameworks.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/test_frameworks.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/test_frameworks.rb Mon Jul 28 17:37:12 2008
@@ -67,7 +67,7 @@
           end
           result.concat filter.filter(candidates.to_java(Java.java.lang.String)).map(&:to_s)
         rescue =>ex
-          puts "#{ex.class}: #{ex.message}" if verbose
+          info "#{ex.class}: #{ex.message}"
           raise
         end
         result.uniq
@@ -246,7 +246,7 @@
       desc "Generate JUnit tests report in #{report.target}"
       task('report') do |task|
         report.generate Project.projects
-        puts "Generated JUnit tests report in #{report.target}" if verbose
+        info "Generated JUnit tests report in #{report.target}"
       end
     end
 
@@ -392,7 +392,7 @@
       # ScalaTest
       reporter_options = 'TFGBSAR' # testSucceeded, testFailed, testIgnored, suiteAborted, runStopped, runAborted, runCompleted
       scalatest.each do |suite|
-        puts "ScalaTest #{suite.inspect}" if verbose
+        info "ScalaTest #{suite.inspect}"
         # Use Ant to execute the ScalaTest task, gives us performance and reporting.
         reportFile = File.join(task.report_to.to_s, "TEST-#{suite}.txt")
         Buildr.ant('scalatest') do |ant|

Modified: incubator/buildr/trunk/lib/buildr/packaging/artifact.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/packaging/artifact.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/packaging/artifact.rb (original)
+++ incubator/buildr/trunk/lib/buildr/packaging/artifact.rb Mon Jul 28 17:37:12 2008
@@ -120,7 +120,7 @@
           mkpath File.dirname(installed)
           cp name, installed
         end
-        puts "Installed #{installed}" if verbose
+        info "Installed #{installed}"
       end
     end
 
@@ -161,7 +161,7 @@
       uri.password = upload_to[:password] if upload_to[:password]
 
       # Upload artifact relative to base URL, need to create path before uploading.
-      puts "Deploying #{to_spec}" if verbose
+      info "Deploying #{to_spec}"
       path = group.gsub('.', '/') + "/#{id}/#{version}/#{File.basename(name)}"
       URI.upload uri + path, name, :permissions=>upload_to[:permissions]
     end
@@ -298,7 +298,7 @@
         # so don't perform it if the task found a different way to create the artifact.
         task.enhance do
           unless File.exist?(name)
-            puts "Downloading #{to_spec}" if verbose
+            info "Downloading #{to_spec}"
             download
             pom.invoke rescue nil if pom && pom != self
           end
@@ -320,7 +320,7 @@
           mkpath File.dirname(name)
           pom.invoke unless type == :pom
           cp path, name
-          puts "Installed #{path} as #{to_spec}" if verbose
+          info "Installed #{path} as #{to_spec}"
         end
       end
       unless type == :pom
@@ -346,7 +346,7 @@
     # This method attempts to download the artifact from each repository in the order in
     # which they are returned from #remote, until successful. It always downloads the POM first.
     def download
-      puts "Downloading #{to_spec}" if Buildr.application.options.trace
+      trace "Downloading #{to_spec}"
       remote = Buildr.repositories.remote.map { |repo_url| URI === repo_url ? repo_url : URI.parse(repo_url) }
       remote = remote.each { |repo_url| repo_url.path += '/' unless repo_url.path[-1] == '/' }
       fail 'No remote repositories defined!' if remote.empty?
@@ -358,8 +358,8 @@
         rescue URI::NotFoundError
           false
         rescue Exception=>error
-          puts error if verbose
-          puts error.backtrace.join("\n") if Buildr.application.options.trace
+          info error
+          trace error.backtrace.join("\n")
           false
         end
       end

Modified: incubator/buildr/trunk/lib/buildr/packaging/zip.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/packaging/zip.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/packaging/zip.rb (original)
+++ incubator/buildr/trunk/lib/buildr/packaging/zip.rb Mon Jul 28 17:37:12 2008
@@ -45,11 +45,11 @@
               if File.directory?(path)
                 in_directory path do |file, rel_path|
                   dest = "#{@path}#{rel_path}"
-                  puts "Adding #{dest}" if Buildr.application.options.trace
+                  trace "Adding #{dest}"
                   file_map[dest] = file
                 end
               else
-                puts "Adding #{@path}#{File.basename(path)}" if Buildr.application.options.trace
+                trace "Adding #{@path}#{File.basename(path)}"
                 file_map["#{@path}#{File.basename(path)}"] = path
               end
             end
@@ -150,11 +150,11 @@
                 path = rel_path.split('/')[1..-1]
                 path.unshift as unless as == '.'
                 dest = "#{@path}#{path.join('/')}"
-                puts "Adding #{dest}" if Buildr.application.options.trace
+                trace "Adding #{dest}"
                 file_map[dest] = file
               end
             else
-              puts "Adding #{@path}#{as}" if Buildr.application.options.trace
+              trace "Adding #{@path}#{as}"
               file_map["#{@path}#{as}"] = file
             end
           end
@@ -218,7 +218,7 @@
             if @includes.any? { |pattern| File.fnmatch(pattern, entry.name, File::FNM_PATHNAME) } &&
                !@excludes.any? { |pattern| File.fnmatch(pattern, entry.name, File::FNM_PATHNAME) }
               dest = path =~ /^\/?$/ ? entry.name : Util.relative_path(path + "/" + entry.name)
-              puts "Adding #{dest}" if Buildr.application.options.trace
+              trace "Adding #{dest}"
               file_map[dest] = lambda { |output| output.write source.read(entry) }
             end
           end
@@ -546,7 +546,7 @@
           patterns.map(entries).each do |dest, entry|
             next if entry.directory?
             dest = File.expand_path(dest, target.to_s)
-            puts "Extracting #{dest}" if Buildr.application.options.trace
+            trace "Extracting #{dest}"
             mkpath File.dirname(dest), :verbose=>false rescue nil
             entry.extract(dest) { true }
           end

Modified: incubator/buildr/trunk/spec/compile_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/compile_spec.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/compile_spec.rb (original)
+++ incubator/buildr/trunk/spec/compile_spec.rb Mon Jul 28 17:37:12 2008
@@ -23,8 +23,8 @@
   end
 
   def sources
-    @sources ||= ['Test1.java', 'Test2.java'].map { |f| File.join('src/main/java', f) }.
-      each { |src| write src, "class #{src.pathmap('%n')} {}" }
+    @sources ||= ['Test1.java', 'Test2.java'].map { |f| File.join('src/main/java/thepackage', f) }.
+      each { |src| write src, "package thepackage; class #{src.pathmap('%n')} {}" }
   end
 
   def jars
@@ -146,12 +146,12 @@
 
   it 'should allow files' do
     compile_task.from(sources).into('classes').invoke
-    sources.each { |src| file(src.pathmap('classes/%n.class')).should exist }
+    sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
   end
 
   it 'should allow directories' do
     compile_task.from(File.dirname(sources.first)).into('classes').invoke
-    sources.each { |src| file(src.pathmap('classes/%n.class')).should exist }
+    sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
   end
 
   it 'should allow tasks' do
@@ -179,7 +179,7 @@
 
   it 'should allow files' do
     compile_task.from(sources).with(jars).into('classes').invoke
-    sources.each { |src| file(src.pathmap('classes/%n.class')).should exist }
+    sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
   end
 
   it 'should allow tasks' do
@@ -261,7 +261,7 @@
 
   it 'should compile into target directory' do
     compile_task.from(sources).into('code').invoke
-    Dir['code/*.class'].should_not be_empty
+    Dir['code/thepackage/*.class'].should_not be_empty
   end
 
   it 'should compile only once' do
@@ -302,7 +302,9 @@
   end
 
   it 'should force compilation if target empty' do
+    time = Time.now
     mkpath compile_task.target.to_s
+    File.utime(time - 1, time - 1, compile_task.target.to_s)
     lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
   end
 
@@ -310,7 +312,7 @@
     # Simulate class files that are older than source files.
     time = Time.now
     sources.each { |src| File.utime(time + 1, time + 1, src) }
-    sources.map { |src| src.pathmap("#{compile_task.target}/%n.class") }.
+    sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
       each { |kls| write kls ; File.utime(time, time, kls) }
     lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
   end
@@ -318,7 +320,7 @@
   it 'should not force compilation if sources older than compiled' do
     # When everything has the same timestamp, nothing is compiled again.
     time = Time.now
-    sources.map { |src| src.pathmap("#{compile_task.target}/%n.class") }.
+    sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
       each { |kls| write kls ; File.utime(time, time, kls) }
     lambda { compile_task.from(sources).invoke }.should_not run_task('foo:compile')
   end
@@ -327,7 +329,7 @@
     jars; project('jars').task("package").invoke
     # On my machine the times end up the same, so need to push dependencies in the past.
     time = Time.now
-    sources.map { |src| src.pathmap("#{compile_task.target}/%n.class") }.
+    sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
       each { |kls| write kls ; File.utime(time, time, kls) }
     jars.each { |jar| File.utime(time + 1, time + 1, jar) }
     lambda { compile_task.from(sources).with(jars).invoke }.should run_task('foo:compile')
@@ -337,7 +339,7 @@
     jars; project('jars').task("package").invoke
     time = Time.now
     jars.each { |jar| File.utime(time - 1 , time - 1, jar) }
-    sources.map { |src| File.utime(time, time, src); src.pathmap("#{compile_task.target}/%n.class") }.
+    sources.map { |src| File.utime(time, time, src); src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
       each { |kls| write kls ; File.utime(time, time, kls) }
     lambda { compile_task.from(sources).with(jars).invoke }.should_not run_task('foo:compile')
   end

Modified: incubator/buildr/trunk/spec/spec_helpers.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/spec_helpers.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/spec_helpers.rb (original)
+++ incubator/buildr/trunk/spec/spec_helpers.rb Mon Jul 28 17:37:12 2008
@@ -28,7 +28,7 @@
 
     include Checks::Matchers
 
-    module ::Kernel #:nodoc:
+    class ::Object #:nodoc:
       def warn(message)
         $warning ||= []
         $warning << message
@@ -66,10 +66,45 @@
     #
     # For example:
     #   lambda { warn 'ze test' }.should warn_that(/ze test/)
-    def warn_that(message)
+    def show_warning(message)
       WarningMatcher.new message
     end
 
+    class ::Object  #:nodoc:
+      def error(message)
+        $error ||= []
+        $error << message
+      end
+    end
+
+    class ErrorMessageMatcher
+      def initialize(message)
+        @expect = message
+      end
+
+      def matches?(target)
+        $error = []
+        target.call
+        return Regexp === @expect ? $error.join('\n') =~ @expect : $error.include?(@expect.to_s)
+      end
+
+      def failure_message
+        $error ? "Expected error #{@expect.source}, found #{$error}" : "Expected error #{@expect.source}, no error issued"
+      end
+
+      def negative_failure_message
+        "Found unexpected #{$error}"
+      end
+    end
+    
+    # Test if error message was shown.  You can use a string or regular expression.
+    #
+    # For example:
+    #   lambda { error 'ze test' }.should show_error(/ze test/)
+    def show_error(message)
+      ErrorMessageMatcher.new message
+    end
+
 
     class ::Rake::Task
       alias :execute_without_a_record :execute

Modified: incubator/buildr/trunk/spec/test_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/test_spec.rb?rev=680585&r1=680584&r2=680585&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/test_spec.rb (original)
+++ incubator/buildr/trunk/spec/test_spec.rb Mon Jul 28 17:37:12 2008
@@ -244,7 +244,7 @@
   end
 
   it 'should report no failed tests' do
-    lambda { verbose(true) { define('foo').test.invoke } }.should_not warn_that(/fail/i)
+    lambda { verbose(true) { define('foo').test.invoke } }.should_not show_error(/fail/i)
   end
   
   it 'should return no failed tests' do
@@ -284,7 +284,7 @@
   end
 
   it 'should report no failed tests' do
-    lambda { verbose(true) { test_task.invoke } }.should_not warn_that(/fail/i)
+    lambda { verbose(true) { test_task.invoke } }.should_not show_error(/fail/i)
   end
   
   it 'should return passed tests' do
@@ -322,7 +322,7 @@
   end
 
   it 'should report failed tests' do
-    lambda { verbose(true) { test_task.invoke rescue nil } }.should warn_that(/FailingTest/)
+    lambda { verbose(true) { test_task.invoke rescue nil } }.should show_error(/FailingTest/)
   end
 
   it 'should return failed tests' do
@@ -342,7 +342,7 @@
 
   it 'should report failed tests even if fail_on_failure is false' do
     test_task.using(:fail_on_failure=>false)
-    lambda { verbose(true) { test_task.invoke } }.should warn_that(/FailingTest/)
+    lambda { verbose(true) { test_task.invoke } }.should show_error(/FailingTest/)
   end
 
   it 'should return failed tests even if fail_on_failure is false' do
@@ -668,7 +668,7 @@
 
   it 'should be true and warn for any other value' do
     ENV['TEST'] = 'funky'
-    lambda { Buildr.options.test.should be(true) }.should warn_that(/expecting the environment variable/i)
+    lambda { Buildr.options.test.should be(true) }.should show_warning(/expecting the environment variable/i)
   end
 end