Author: boisvert
Date: Wed Oct 13 04:39:43 2010
New Revision: 1021993

URL: http://svn.apache.org/viewvc?rev=1021993&view=rev
Log:
BUILDR-531 Improve error message when build requires gem that can't be found in 
local/remote gem repositories (Peter Donald)

Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/lib/buildr/core/util.rb
    buildr/trunk/spec/core/application_spec.rb

Modified: buildr/trunk/CHANGELOG
URL: 
http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=1021993&r1=1021992&r2=1021993&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Wed Oct 13 04:39:43 2010
@@ -15,6 +15,8 @@
 * Fixed:  BUILDR-526 Gracefully handle h2 sections with no id in documentation 
(Peter Donald)
 * Fixed:  BUILDR-527 package(:war) if libs passed are files (instead of 
artifacts)
 * Fixed:  BUILDR-528 Stop using deprecated method 
Gem::Dependency.version_requirements correctly (Peter Donald)
+* Fixed:  BUILDR-531 Improve error message when build requires gem that can't 
be found in local/remote 
+          gem repositories (Peter Donald)
 * Fixed:  BUILDR-532 package_as_source does not package resources (Tammo van 
Lessen)
 * Fixed:  JavaRebel was previously not correctly detected.
 

Modified: buildr/trunk/lib/buildr/core/util.rb
URL: 
http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/util.rb?rev=1021993&r1=1021992&r2=1021993&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/util.rb (original)
+++ buildr/trunk/lib/buildr/core/util.rb Wed Oct 13 04:39:43 2010
@@ -142,8 +142,20 @@ module Buildr
       # is not running interactively (on a tty)
       def install(*dependencies)
         raise ArgumentError, "Expected at least one argument" if 
dependencies.empty?
-        remote = dependencies.map{ |dep| Gem.source_index.search(dep).last || 
Gem::SpecFetcher.fetcher.fetch( dep, true ).map{ |spec, source| spec }.last }
-        not_found_deps, to_install = remote.partition { |gem| 
gem.is_a?(Gem::Dependency) || gem.nil? }
+        not_found_deps = []
+        to_install = []
+        remote = dependencies.each do |dep|
+          if spec = Gem.source_index.search(dep).last
+            # Found in local repo
+            to_install << spec
+          elsif (spec = Gem::SpecFetcher.fetcher.fetch(dep, true).map { |spec, 
source| spec }.last)
+            # Found in remote repo
+            to_install << spec
+          else
+            # Not found anywhere
+            not_found_deps << "#{dep.name} #{dep.requirement}"
+          end
+        end
         fail Gem::LoadError, "Build requires the gems #{not_found_deps.join(', 
')}, which cannot be found in local or remote repository." unless 
not_found_deps.empty?
         uses = "This build requires the gems 
#{to_install.map(&:full_name).join(', ')}:"
         fail Gem::LoadError, "#{uses} to install, run Buildr interactively." 
unless $stdout.isatty

Modified: buildr/trunk/spec/core/application_spec.rb
URL: 
http://svn.apache.org/viewvc/buildr/trunk/spec/core/application_spec.rb?rev=1021993&r1=1021992&r2=1021993&view=diff
==============================================================================
--- buildr/trunk/spec/core/application_spec.rb (original)
+++ buildr/trunk/spec/core/application_spec.rb Wed Oct 13 04:39:43 2010
@@ -250,28 +250,32 @@ describe Buildr::Application do
     end
 
     it 'should default to >=0 version requirement if not specified' do
-      write 'build.yaml', 'gems: foo'
-      $terminal.should_receive(:agree).and_return(true)
-      Gem.source_index.should_receive(:search).with(Gem::Dependency.new('foo', 
'>=0')).and_return([])
-      lambda { Buildr.application.load_gems }.should raise_error
+      write 'build.yaml', 'gems: buildr-foo'
+      should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', '>= 
0'))
     end
 
     it 'should parse exact version requirement' do
-      write 'build.yaml', 'gems: foo 2.5'
-      Gem.source_index.should_receive(:search).with(Gem::Dependency.new('foo', 
'=2.5')).and_return([])
-      lambda { Buildr.application.load_gems }.should raise_error
+      write 'build.yaml', 'gems: buildr-foo 2.5'
+      should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', 
'=2.5'))
     end
 
     it 'should parse range version requirement' do
-      write 'build.yaml', 'gems: foo ~>2.3'
-     Gem.source_index.should_receive(:search).with(Gem::Dependency.new('foo', 
'~>2.3')).and_return([])
-      lambda { Buildr.application.load_gems }.should raise_error
+      write 'build.yaml', 'gems: buildr-foo ~>2.3'
+      should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', 
'~>2.3'))
     end
 
     it 'should parse multiple version requirements' do
-      write 'build.yaml', 'gems: foo >=2.0 !=2.1'
-      Gem.source_index.should_receive(:search).with(Gem::Dependency.new('foo', 
['>=2.0', '!=2.1'])).and_return([])
-      lambda { Buildr.application.load_gems }.should raise_error
+      write 'build.yaml', 'gems: buildr-foo >=2.0 !=2.1'
+      should_attempt_to_load_dependency(Gem::Dependency.new('buildr-foo', 
['>=2.0', '!=2.1']))
+    end
+
+    def should_attempt_to_load_dependency(dep)
+      Gem.source_index.should_receive(:search).with(dep).and_return([])
+      lambda { Buildr.application.load_gems }.should 
raise_missing_gem_error(dep)
+    end
+
+    def raise_missing_gem_error(dep)
+      raise_error(Gem::LoadError, /Build requires the gems #{dep.name} 
#{dep.requirement}, which cannot be found in local or remote repository./)
     end
   end
 


Reply via email to