From edec4c324aed86858005336d144d3474f29182fd Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Sat, 16 May 2015 20:26:36 -0700 Subject: [Path] Validate the gemspecs we find when globbing --- lib/bundler.rb | 16 ++++++++++++++++ lib/bundler/dsl.rb | 17 +---------------- lib/bundler/source/path.rb | 3 +-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/bundler.rb b/lib/bundler.rb index 197e88c222..f487d2c69d 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -364,6 +364,22 @@ module Bundler end end + def load_and_validate_gemspec(file, allow_nil = false) + spec = load_gemspec(file) + + unless spec + return if allow_nil + raise InvalidOption, "There was an error loading the gemspec at " \ + "#{file}. Make sure you can build the gem, then try again." + end + + spec.validate + spec + rescue Gem::InvalidSpecificationException => e + raise InvalidOption, "The gemspec at #{file} is not valid. " \ + "The validation error was '#{e.message}'" + end + def clear_gemspec_cache @gemspec_cache = {} end diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index cd0c80b3ff..84fafa7d62 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -48,7 +48,7 @@ module Bundler case gemspecs.size when 1 - spec = load_valid_gemspec(gemspecs.first) + spec = Bundler.load_and_validate_gemspec(gemspecs.first) gem spec.name, :path => path, :glob => glob @@ -360,21 +360,6 @@ module Bundler end end - def load_valid_gemspec(path) - spec = Bundler.load_gemspec(path) - - unless spec - raise InvalidOption, "There was an error loading the gemspec at " \ - "#{path}. Make sure you can build the gem, then try again." - end - - spec.validate - spec - rescue Gem::InvalidSpecificationException => e - raise InvalidOption, "The gemspec at #{path} is not valid. " \ - "The validation error was '#{e.message}'" - end - class DSLError < GemfileError # @return [String] the description that should be presented to the user. # diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 862fbcb97a..9d2cbb708d 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -132,8 +132,7 @@ module Bundler if File.directory?(expanded_path) # We sort depth-first since `<<` will override the earlier-found specs Dir["#{expanded_path}/#{@glob}"].sort_by { |p| -p.split(File::SEPARATOR).size }.each do |file| - spec = Bundler.load_gemspec(file) - if spec + if spec = Bundler.load_and_validate_gemspec(file, true) spec.loaded_from = file.to_s spec.source = self index << spec -- cgit v1.2.1