From a6c92a85e418dd9b748e37d0f4445784ad1e9c71 Mon Sep 17 00:00:00 2001 From: drbrain Date: Wed, 27 Feb 2013 23:20:57 +0000 Subject: [PATCH] * lib/rubygems/available_set.rb: Undent for style * lib/rubygems/dependency_installer.rb: Pick latest prerelease gem to install. Fixes RubyGems bug #468. * test/rubygems/test_gem_dependency_installer.rb: Test for the above. * lib/rubygems/dependency_installer.rb: Don't display "Done installing documentation" if documentation will not be installed. * lib/rubygems/rdoc.rb: ditto * lib/rubygems/dependency_list.rb: Use Array#concat for Ruby 1.x performance. * lib/rubygems/installer.rb: Use formatted program name when comparing executables. RubyGems pull request #471 * test/rubygems/test_gem_installer.rb: Test for the above. * lib/rubygems/package.rb: Use more explicit feature check to work around JRuby bug #552 * lib/rubygems/ssl_certs/GeoTrust_Global_CA.pem: Added GeoTrust root certificate. * test/rubygems/test_gem_source_list.rb: Use "example" instead of real hostname git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 28 ++++ lib/rubygems/available_set.rb | 156 +++++++++--------- lib/rubygems/dependency_installer.rb | 28 ++-- lib/rubygems/dependency_list.rb | 2 +- lib/rubygems/installer.rb | 2 +- lib/rubygems/package.rb | 4 +- lib/rubygems/rdoc.rb | 11 +- lib/rubygems/ssl_certs/GeoTrust_Global_CA.pem | 20 +++ .../rubygems/test_gem_dependency_installer.rb | 55 ++++++ test/rubygems/test_gem_installer.rb | 37 +++++ test/rubygems/test_gem_source_list.rb | 2 +- 11 files changed, 250 insertions(+), 95 deletions(-) create mode 100644 lib/rubygems/ssl_certs/GeoTrust_Global_CA.pem diff --git a/ChangeLog b/ChangeLog index 7beeeb33c6..4ec2c131a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +Thu Feb 28 08:20:33 2013 Eric Hodel + + * lib/rubygems/available_set.rb: Undent for style + + * lib/rubygems/dependency_installer.rb: Pick latest prerelease gem to + install. Fixes RubyGems bug #468. + * test/rubygems/test_gem_dependency_installer.rb: Test for the above. + + * lib/rubygems/dependency_installer.rb: Don't display "Done installing + documentation" if documentation will not be installed. + * lib/rubygems/rdoc.rb: ditto + + * lib/rubygems/dependency_list.rb: Use Array#concat for Ruby 1.x + performance. + + * lib/rubygems/installer.rb: Use formatted program name when comparing + executables. RubyGems pull request #471 + * test/rubygems/test_gem_installer.rb: Test for the above. + + * lib/rubygems/package.rb: Use more explicit feature check to work + around JRuby bug #552 + + * lib/rubygems/ssl_certs/GeoTrust_Global_CA.pem: Added GeoTrust root + certificate. + + * test/rubygems/test_gem_source_list.rb: Use "example" instead of real + hostname + Thu Feb 28 05:57:00 2013 Zachary Scott * thread.c: rdoc formatting for Thread, ThreadGroup, and ThreadError diff --git a/lib/rubygems/available_set.rb b/lib/rubygems/available_set.rb index cd6df1ddc7..80539feee9 100644 --- a/lib/rubygems/available_set.rb +++ b/lib/rubygems/available_set.rb @@ -1,95 +1,93 @@ -module Gem - class AvailableSet - Tuple = Struct.new(:spec, :source) +class Gem::AvailableSet + Tuple = Struct.new(:spec, :source) - def initialize - @set = [] - @sorted = nil - end + def initialize + @set = [] + @sorted = nil + end - attr_reader :set + attr_reader :set - def add(spec, source) - @set << Tuple.new(spec, source) - @sorted = nil - self - end + def add(spec, source) + @set << Tuple.new(spec, source) + @sorted = nil + self + end - def <<(o) - case o - when AvailableSet - s = o.set - when Array - s = o.map do |sp,so| - if !sp.kind_of?(Specification) or !so.kind_of?(Source) - raise TypeError, "Array must be in [[spec, source], ...] form" - end - - Tuple.new(sp,so) + def <<(o) + case o + when Gem::AvailableSet + s = o.set + when Array + s = o.map do |sp,so| + if !sp.kind_of?(Gem::Specification) or !so.kind_of?(Gem::Source) + raise TypeError, "Array must be in [[spec, source], ...] form" end - else - raise TypeError, "Must be an AvailableSet" + + Tuple.new(sp,so) end - - @set += s - @sorted = nil - - self + else + raise TypeError, "must be a Gem::AvailableSet" end - def empty? - @set.empty? - end + @set += s + @sorted = nil - def all_specs - @set.map { |t| t.spec } - end + self + end - def match_platform! - @set.reject! { |t| !Gem::Platform.match(t.spec.platform) } - @sorted = nil - self - end + def empty? + @set.empty? + end - def sorted - @sorted ||= @set.sort do |a,b| - i = b.spec <=> a.spec - i != 0 ? i : (a.source <=> b.source) - end - end + def all_specs + @set.map { |t| t.spec } + end - def size - @set.size - end + def match_platform! + @set.reject! { |t| !Gem::Platform.match(t.spec.platform) } + @sorted = nil + self + end - def source_for(spec) - f = @set.find { |t| t.spec == spec } - f.source - end - - def pick_best! - return self if empty? - - @set = [sorted.first] - @sorted = nil - self - end - - def remove_installed!(dep) - @set.reject! do |t| - # already locally installed - Gem::Specification.any? do |installed_spec| - dep.name == installed_spec.name and - dep.requirement.satisfied_by? installed_spec.version - end - end - - @sorted = nil - self - end - - def inject_into_list(dep_list) - @set.each { |t| dep_list.add t.spec } + def sorted + @sorted ||= @set.sort do |a,b| + i = b.spec <=> a.spec + i != 0 ? i : (a.source <=> b.source) end end + + def size + @set.size + end + + def source_for(spec) + f = @set.find { |t| t.spec == spec } + f.source + end + + def pick_best! + return self if empty? + + @set = [sorted.first] + @sorted = nil + self + end + + def remove_installed!(dep) + @set.reject! do |t| + # already locally installed + Gem::Specification.any? do |installed_spec| + dep.name == installed_spec.name and + dep.requirement.satisfied_by? installed_spec.version + end + end + + @sorted = nil + self + end + + def inject_into_list(dep_list) + @set.each { |t| dep_list.add t.spec } + end end diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb index d811f62875..256c91ee9c 100644 --- a/lib/rubygems/dependency_installer.rb +++ b/lib/rubygems/dependency_installer.rb @@ -88,6 +88,7 @@ class Gem::DependencyInstaller # we absolutely must. @minimal_deps = options[:minimal_deps] + @available = nil @installed_gems = [] @toplevel_specs = nil @@ -100,6 +101,22 @@ class Gem::DependencyInstaller attr_reader :errors + ## + # Creates an AvailableSet to install from based on +dep_or_name+ and + # +version+ + + def available_set_for dep_or_name, version # :nodoc: + if String === dep_or_name then + find_spec_by_name_and_version dep_or_name, version, @prerelease + else + dep = dep_or_name.dup + dep.prerelease = @prerelease + @available = find_gems_with_sources dep + end + + @available.pick_best! + end + ## # Indicated, based on the requested domain, if local # gems should be considered. @@ -302,13 +319,7 @@ class Gem::DependencyInstaller # separately. def install dep_or_name, version = Gem::Requirement.default - if String === dep_or_name then - find_spec_by_name_and_version dep_or_name, version, @prerelease - else - dep = dep_or_name.dup - dep.prerelease = @prerelease - @available = find_gems_with_sources(dep).pick_best! - end + available_set_for dep_or_name, version @installed_gems = [] @@ -367,12 +378,9 @@ class Gem::DependencyInstaller # it's documentation. Ideally the hook adder could decide whether to be in # the background or not, and what to call it. in_background "Installing documentation" do - start = Time.now Gem.done_installing_hooks.each do |hook| hook.call self, @installed_gems end - finish = Time.now - say "Done installing documentation for #{@installed_gems.map(&:name).join(', ')} (#{(finish-start).to_i} sec)." end unless Gem.done_installing_hooks.empty? @installed_gems diff --git a/lib/rubygems/dependency_list.rb b/lib/rubygems/dependency_list.rb index c147efc1ca..3e40325527 100644 --- a/lib/rubygems/dependency_list.rb +++ b/lib/rubygems/dependency_list.rb @@ -49,7 +49,7 @@ class Gem::DependencyList # Adds +gemspecs+ to the dependency list. def add(*gemspecs) - @specs.push(*gemspecs) + @specs.concat gemspecs end def clear diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index fcfb2836dc..3f4c6943df 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -132,7 +132,7 @@ class Gem::Installer def check_executable_overwrite filename # :nodoc: return if @force - generated_bin = File.join @bin_dir, filename + generated_bin = File.join @bin_dir, formatted_program_filename(filename) return unless File.exist? generated_bin diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index d56316e1ba..301eef48cc 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -387,8 +387,8 @@ EOM @spec = Gem::Specification.from_yaml entry.read when 'metadata.gz' then args = [entry] - args << { :external_encoding => Encoding::UTF_8 } if - Object.const_defined? :Encoding + args << { :external_encoding => Encoding::UTF_8 } unless + Zlib::GzipReader.method(:wrap).arity == 1 Zlib::GzipReader.wrap(*args) do |gzio| @spec = Gem::Specification.from_yaml gzio.read diff --git a/lib/rubygems/rdoc.rb b/lib/rubygems/rdoc.rb index 15ccc3e455..f16c8696f0 100644 --- a/lib/rubygems/rdoc.rb +++ b/lib/rubygems/rdoc.rb @@ -37,6 +37,7 @@ end class Gem::RDoc # :nodoc: all include Gem::UserInteraction + extend Gem::UserInteraction @rdoc_version = nil @specs = [] @@ -70,7 +71,8 @@ class Gem::RDoc # :nodoc: all # +specs+ def self.generation_hook installer, specs - types = installer.document + start = Time.now + types = installer.document generate_rdoc = types.include? 'rdoc' generate_ri = types.include? 'ri' @@ -78,6 +80,13 @@ class Gem::RDoc # :nodoc: all specs.each do |spec| new(spec, generate_rdoc, generate_ri).generate end + + return unless generate_rdoc or generate_ri + + duration = (Time.now - start).to_i + names = specs.map(&:name).join ', ' + + say "Done installing documentation for #{names} after #{duration} seconds" end ## diff --git a/lib/rubygems/ssl_certs/GeoTrust_Global_CA.pem b/lib/rubygems/ssl_certs/GeoTrust_Global_CA.pem new file mode 100644 index 0000000000..5d795bba55 --- /dev/null +++ b/lib/rubygems/ssl_certs/GeoTrust_Global_CA.pem @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT +MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i +YWwgQ0EwHhcNMDIwNTIxMDQwMDAwWhcNMjIwNTIxMDQwMDAwWjBCMQswCQYDVQQG +EwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEbMBkGA1UEAxMSR2VvVHJ1c3Qg +R2xvYmFsIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2swYYzD9 +9BcjGlZ+W988bDjkcbd4kdS8odhM+KhDtgPpTSEHCIjaWC9mOSm9BXiLnTjoBbdq +fnGk5sRgprDvgOSJKA+eJdbtg/OtppHHmMlCGDUUna2YRpIuT8rxh0PBFpVXLVDv +iS2Aelet8u5fa9IAjbkU+BQVNdnARqN7csiRv8lVK83Qlz6cJmTM386DGXHKTubU +1XupGc1V3sjs0l44U+VcT4wt/lAjNvxm5suOpDkZALeVAjmRCw7+OC7RHQWa9k0+ +bw8HHa8sHo9gOeL6NlMTOdReJivbPagUvTLrGAMoUgRx5aszPeE4uwc2hGKceeoW +MPRfwCvocWvk+QIDAQABo1MwUTAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTA +ephojYn7qwVkDBF9qn1luMrMTjAfBgNVHSMEGDAWgBTAephojYn7qwVkDBF9qn1l +uMrMTjANBgkqhkiG9w0BAQUFAAOCAQEANeMpauUvXVSOKVCUn5kaFOSPeCpilKIn +Z57QzxpeR+nBsqTP3UEaBU6bS+5Kb1VSsyShNwrrZHYqLizz/Tt1kL/6cdjHPTfS +tQWVYrmm3ok9Nns4d0iXrKYgjy6myQzCsplFAMfOEVEiIuCl6rYVSAlk6l5PdPcF +PseKUgzbFbS9bZvlxrFUaKnjaZC2mqUPuLk/IH2uSrW4nOQdtqvmlKXBx4Ot2/Un +hw4EbNX/3aBd7YdStysVAq45pmp06drE57xNNB6pXE0zX5IJL4hmXXeXxx12E6nV +5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3CBWaAocvmMw== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index d515505922..bfebc6f63b 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -35,6 +35,61 @@ class TestGemDependencyInstaller < Gem::TestCase util_reset_gems end + def test_available_set_for_name + util_setup_gems + p1a, gem = util_gem 'a', '10.a' + util_setup_spec_fetcher p1a, @a1, @a1_pre + + inst = Gem::DependencyInstaller.new + + available = inst.available_set_for 'a', Gem::Requirement.default + + assert_equal %w[a-1], available.set.map { |s| s.spec.full_name } + end + + def test_available_set_for_name_prerelease + util_setup_gems + p1a, gem = util_gem 'a', '10.a' + util_setup_spec_fetcher p1a, @a1, @a1_pre + + inst = Gem::DependencyInstaller.new :prerelease => true + + available = inst.available_set_for 'a', Gem::Requirement.default + + assert_equal %w[a-10.a], + available.sorted.map { |s| s.spec.full_name } + end + + def test_available_set_for_dep + util_setup_gems + p1a, gem = util_gem 'a', '10.a' + util_setup_spec_fetcher p1a, @a1, @a1_pre + + inst = Gem::DependencyInstaller.new + + dep = Gem::Dependency.new 'a', Gem::Requirement.default + + available = inst.available_set_for dep, Gem::Requirement.default + + assert_equal %w[a-1], available.set.map { |s| s.spec.full_name } + end + + def test_available_set_for_dep_prerelease + util_setup_gems + p1a, gem = util_gem 'a', '10.a' + util_setup_spec_fetcher p1a, @a1, @a1_pre + + inst = Gem::DependencyInstaller.new :prerelease => true + + dep = Gem::Dependency.new 'a', Gem::Requirement.default + dep.prerelease = true + + available = inst.available_set_for dep, Gem::Requirement.default + + assert_equal %w[a-10.a], + available.sorted.map { |s| s.spec.full_name } + end + def test_install util_setup_gems diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index bb48f35d9f..ddedd8144c 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -190,6 +190,43 @@ load Gem.bin_path('a', 'executable', version) Gem::ConfigMap[:bindir] = orig_bindir end + def test_check_executable_overwrite_format_executable + @installer.generate_bin + + @spec = Gem::Specification.new do |s| + s.files = ['lib/code.rb'] + s.name = "a" + s.version = "3" + s.summary = "summary" + s.description = "desc" + s.require_path = 'lib' + end + + open File.join(util_inst_bindir, 'executable'), 'w' do |io| + io.write <<-EXEC +#!/usr/local/bin/ruby +# +# This file was generated by RubyGems + +gem 'other', version + EXEC + end + + util_make_exec + Gem::Installer.exec_format = 'foo-%s-bar' + @installer.gem_dir = @spec.gem_dir + @installer.wrappers = true + @installer.format_executable = true + + @installer.generate_bin # should not raise + + installed_exec = File.join util_inst_bindir, 'foo-executable-bar' + assert File.exist? installed_exec + + wrapper = File.read installed_exec + assert_match %r|generated by RubyGems|, wrapper + end + def test_check_executable_overwrite_other_gem util_conflict_executable true diff --git a/test/rubygems/test_gem_source_list.rb b/test/rubygems/test_gem_source_list.rb index d6e253833e..e2d6da62cd 100644 --- a/test/rubygems/test_gem_source_list.rb +++ b/test/rubygems/test_gem_source_list.rb @@ -5,7 +5,7 @@ class TestGemSourceList < Gem::TestCase def setup super - @uri = "http://blah.com" + @uri = "http://example" @source = Gem::Source.new(@uri) @sl = Gem::SourceList.new