diff options
author | danielsdeleo <dan@opscode.com> | 2013-02-24 12:16:55 -0800 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-05-30 09:18:48 -0700 |
commit | 604a563e8000e0c5af51bc61f1997c8987dc46aa (patch) | |
tree | 130d6aedc595b230a640246da79ff2db2a79ae8a | |
parent | b04d31e6d3f21031bcc2e2b3326232d20d8ed0c2 (diff) | |
download | chef-604a563e8000e0c5af51bc61f1997c8987dc46aa.tar.gz |
[CHEF-3933] use rubygems 2.0 files/classes/methods
* rubygems/format file removed
* Gem::Package replaces functionality in Gem::Format
* Gem.sources returns a SourceList which must be coerced to array
-rw-r--r-- | chef/lib/chef/provider/package/rubygems.rb | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/chef/lib/chef/provider/package/rubygems.rb b/chef/lib/chef/provider/package/rubygems.rb index e60d73ab62..2a778fdb14 100644 --- a/chef/lib/chef/provider/package/rubygems.rb +++ b/chef/lib/chef/provider/package/rubygems.rb @@ -31,7 +31,14 @@ require 'rubygems/version' require 'rubygems/dependency' require 'rubygems/spec_fetcher' require 'rubygems/platform' -require 'rubygems/format' + +# Compatibility note: Rubygems 2.0 removes rubygems/format in favor of +# rubygems/package. +begin + require 'rubygems/format' +rescue LoadError + require 'rubygems/package' +end require 'rubygems/dependency_installer' require 'rubygems/uninstaller' require 'rubygems/specification' @@ -106,6 +113,22 @@ class Chef end ## + # Extracts the gemspec from a (on-disk) gem package. + # === Returns + # Gem::Specification + # + #-- + # Compatibility note: Rubygems 1.x uses Gem::Format, 2.0 moved this + # code into Gem::Package. + def spec_from_file(file) + if defined?(Gem::Format) + Gem::Format.from_file_by_path(source).spec + else + Gem::Package.new(file).spec + end + end + + ## # Determines the candidate version for a gem from a .gem file on disk # and checks if it matches the version contraints in +gem_dependency+ # === Returns @@ -114,7 +137,7 @@ class Chef # nil returns nil if the gem on disk doesn't match the # version constraints for +gem_dependency+ def candidate_version_from_file(gem_dependency, source) - spec = Gem::Format.from_file_by_path(source).spec + spec = spec_from_file(source) if spec.satisfies_requirement?(gem_dependency) logger.debug {"#{@new_resource} found candidate gem version #{spec.version} from local gem package #{source}"} spec.version @@ -152,7 +175,7 @@ class Chef logger.debug { "#{@new_resource} found gem #{spec.name} version #{version} for platform #{spec.platform} from #{spec_with_source[1]}" } version else - source_list = sources.compact.empty? ? "[#{Gem.sources.join(', ')}]" : "[#{sources.join(', ')}]" + source_list = sources.compact.empty? ? "[#{Gem.sources.to_a.join(', ')}]" : "[#{sources.join(', ')}]" logger.warn { "#{@new_resource} failed to find gem #{gem_dependency} from #{source_list}" } nil end |