1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Import rubygems 1.5.0 (released version @ 1fb59d0)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ryan 2011-02-01 03:11:34 +00:00
parent f4234c9b8f
commit ec84bfc9e3
17 changed files with 201 additions and 46 deletions

View file

@ -1,3 +1,8 @@
Tue Feb 1 11:03:47 2011 Ryan Davis <ryan@lust.local>
* lib/rubygems*: Import rubygems 1.5.0 (released version @ 1fb59d0)
* test/rubygems: Ditto
Tue Feb 1 08:01:39 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/io/console/console.c (console_set_winsize): new method to set

View file

@ -10,13 +10,9 @@
# See LICENSE.txt for permissions.
#++
require 'rubygems'
require 'rubygems/user_interaction'
begin
require 'psych'
rescue LoadError
end
Gem.load_yaml
require 'rubygems/package'

View file

@ -342,8 +342,10 @@ abort "#{deprecation_message}"
require 'rdoc/rdoc'
args << '--quiet'
args << '--main' << 'README'
args << '.' << 'README' << 'LICENSE.txt' << 'GPL.txt'
args << '--main' << 'README.rdoc'
args << '.'
args << 'README.rdoc' << 'UPGRADING.rdoc'
args << 'LICENSE.txt' << 'GPL.txt' << 'History.txt'
r = RDoc::RDoc.new
r.document args

View file

@ -71,6 +71,22 @@ class Gem::Commands::UnpackCommand < Gem::Command
end
end
##
#
# Find cached filename in Gem.path. Returns nil if the file cannot be found.
#
#--
# TODO: see comments in get_path() about general service.
def find_in_cache(filename)
Gem.path.each do |gem_dir|
this_path = File.join gem_dir, 'cache', filename
return this_path if File.exist? this_path
end
return nil
end
##
# Return the full path to the cached gem file matching the given
# name and version requirement. Returns 'nil' if no match.
@ -101,13 +117,9 @@ class Gem::Commands::UnpackCommand < Gem::Command
# We expect to find (basename).gem in the 'cache' directory. Furthermore,
# the name match must be exact (ignoring case).
filename = selected.file_name
path = nil
Gem.path.find do |gem_dir|
path = File.join gem_dir, 'cache', filename
File.exist? path
end
path = find_in_cache(selected.file_name)
return download(dependency) unless path
path
end

View file

@ -47,9 +47,14 @@ class Gem::Format
Gem::OldFormat.from_file_by_path file_path
else
begin
open file_path, Gem.binary_mode do |io|
from_io io, file_path, security_policy
end
rescue Gem::Package::TarInvalidError => e
message = "corrupt gem (#{e.class}: #{e.message})"
raise Gem::Package::FormatError.new(message, file_path)
end
end
end

View file

@ -395,19 +395,19 @@ class Gem::Installer
:force => false,
:install_dir => Gem.dir,
:source_index => Gem.source_index,
}.merge @options
}.merge options
@env_shebang = @options[:env_shebang]
@force = @options[:force]
gem_home = @options[:install_dir]
@env_shebang = options[:env_shebang]
@force = options[:force]
gem_home = options[:install_dir]
@gem_home = File.expand_path(gem_home)
@ignore_dependencies = @options[:ignore_dependencies]
@format_executable = @options[:format_executable]
@security_policy = @options[:security_policy]
@wrappers = @options[:wrappers]
@bin_dir = @options[:bin_dir]
@development = @options[:development]
@source_index = @options[:source_index]
@ignore_dependencies = options[:ignore_dependencies]
@format_executable = options[:format_executable]
@security_policy = options[:security_policy]
@wrappers = options[:wrappers]
@bin_dir = options[:bin_dir]
@development = options[:development]
@source_index = options[:source_index]
end
def load_gem_file

View file

@ -45,7 +45,23 @@ module Gem::Package
class ClosedIO < Error; end
class BadCheckSum < Error; end
class TooLongFileName < Error; end
class FormatError < Error; end
class FormatError < Error
attr_reader :path
def initialize message, path = nil
@path = path
message << " in #{path}" if path
super message
end
end
##
# Raised when a tar file is corrupt
class TarInvalidError < Error; end
def self.open(io, mode = "r", signer = nil, &block)
tar_type = case mode

View file

@ -117,7 +117,11 @@ class Gem::Package::TarInput
@tarreader.rewind
@fileops = Gem::FileOperations.new
raise Gem::Package::FormatError, "No metadata found!" unless has_meta
unless has_meta then
path = io.path if io.respond_to? :path
error = Gem::Package::FormatError.new 'no metadata found', path
raise error
end
end
def close

View file

@ -73,6 +73,10 @@ class Gem::Package::TarReader::Entry
else
@header.name
end
rescue ArgumentError => e
raise unless e.message == 'string contains null byte'
raise Gem::Package::TarInvalidError,
'tar is corrupt, name contains null byte'
end
##

View file

@ -92,7 +92,7 @@ class Gem::PackageTask < Rake::PackageTask
# Initialization tasks without the "yield self" or define operations.
def init(gem)
super gem.name, gem.version
super gem.full_name, :noversion
@gem_spec = gem
@package_files += gem_spec.files if gem_spec.files
end
@ -120,11 +120,13 @@ class Gem::PackageTask < Rake::PackageTask
chdir(gem_dir) do
when_writing "Creating #{gem_spec.file_name}" do
Gem::Builder.new(gem_spec).build
verbose(true) {
mv gem_file, ".."
}
verbose trace do
mv gem_file, '..'
end
end
end
end
end
end

View file

@ -530,9 +530,21 @@ end
##
# SilentUI is a UI choice that is absolutely silent.
class Gem::SilentUI
def method_missing(sym, *args, &block)
self
class Gem::SilentUI < Gem::StreamUI
def initialize
reader, writer = nil, nil
if Gem.win_platform?
reader = File.open('nul', 'r')
writer = File.open('nul', 'w')
else
reader = File.open('/dev/null', 'r')
writer = File.open('/dev/null', 'w')
end
super reader, writer, writer
end
end

View file

@ -17,6 +17,46 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
def test_find_in_cache
util_make_gems
assert_equal(
@cmd.find_in_cache(@a1.file_name),
File.join(@gemhome, 'cache', @a1.file_name),
'found a-1.gem in the cache'
)
end
def test_get_path
util_make_gems
util_setup_fake_fetcher
util_setup_spec_fetcher @a1
a1_data = nil
open File.join(@gemhome, 'cache', @a1.file_name), 'rb' do |fp|
a1_data = fp.read
end
Gem::RemoteFetcher.fetcher.data['http://gems.example.com/gems/a-1.gem'] =
a1_data
dep = Gem::Dependency.new(@a1.name, @a1.version)
assert_equal(
@cmd.get_path(dep),
File.join(@gemhome, 'cache', @a1.file_name),
'fetches a-1 and returns the cache path'
)
FileUtils.rm File.join(@gemhome, 'cache', @a1.file_name)
assert_equal(
@cmd.get_path(dep),
File.join(@gemhome, 'cache', @a1.file_name),
'when removed from cache, refetches a-1'
)
end
def test_execute
util_make_gems

View file

@ -4,11 +4,11 @@
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
######################################################################
require 'rubygems/test_case'
require "test/rubygems/simple_gem"
require 'rubygems/package/tar_test_case'
require 'test/rubygems/simple_gem'
require 'rubygems/format'
class TestGemFormat < Gem::TestCase
class TestGemFormat < Gem::Package::TarTestCase
def setup
super
@ -16,6 +16,7 @@ class TestGemFormat < Gem::TestCase
@simple_gem = SIMPLE_GEM
end
# HACK this test should do less
def test_class_from_file_by_path
util_make_gems
@ -34,6 +35,23 @@ class TestGemFormat < Gem::TestCase
end
end
def test_class_from_file_by_path_corrupt
Tempfile.open 'corrupt' do |io|
data = Gem.gzip 'a' * 10
io.write tar_file_header('metadata.gz', "\000x", 0644, data.length)
io.write data
io.rewind
e = assert_raises Gem::Package::FormatError do
Gem::Format.from_file_by_path io.path
end
sub_message = 'Gem::Package::TarInvalidError: tar is corrupt, name contains null byte'
assert_equal "corrupt gem (#{sub_message}) in #{io.path}", e.message
assert_equal io.path, e.path
end
end
def test_class_from_file_by_path_empty
util_make_gems
@ -55,21 +73,21 @@ class TestGemFormat < Gem::TestCase
Gem::Format.from_io(StringIO.new(@simple_gem.upcase))
end
assert_equal 'No metadata found!', e.message
assert_equal 'no metadata found', e.message
e = assert_raises Gem::Package::FormatError do
# Totally bogus input
Gem::Format.from_io(StringIO.new(@simple_gem.reverse))
end
assert_equal 'No metadata found!', e.message
assert_equal 'no metadata found', e.message
e = assert_raises Gem::Package::FormatError do
# This was intentionally screws up YAML parsing.
Gem::Format.from_io(StringIO.new(@simple_gem.gsub(/:/, "boom")))
end
assert_equal 'No metadata found!', e.message
assert_equal 'no metadata found', e.message
end
end

View file

@ -59,7 +59,24 @@ class TestGemPackageTarInput < Gem::Package::TarTestCase
@entry_contents = %w[0123456789 01234]
end
def test_each_works
def test_initialize_no_metadata_file
Tempfile.open 'no_meta' do |io|
io.write tar_file_header('a', '', 0644, 1)
io.write 'a'
io.rewind
e = assert_raises Gem::Package::FormatError do
open io.path, Gem.binary_mode do |file|
Gem::Package::TarInput.open file do end
end
end
assert_equal "no metadata found in #{io.path}", e.message
assert_equal io.path, e.path
end
end
def test_each
open @file, 'rb' do |io|
Gem::Package::TarInput.open io do |tar_input|
count = 0
@ -79,7 +96,7 @@ class TestGemPackageTarInput < Gem::Package::TarTestCase
end
end
def test_extract_entry_works
def test_extract_entry
open @file, 'rb' do |io|
Gem::Package::TarInput.open io do |tar_input|
assert_equal @spec, tar_input.metadata

View file

@ -67,6 +67,16 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase
assert_equal 'lib/foo', @entry.full_name
end
def test_full_name_null
@entry.header.prefix << "\000"
e = assert_raises Gem::Package::TarInvalidError do
@entry.full_name
end
assert_equal 'tar is corrupt, name contains null byte', e.message
end
def test_getc
assert_equal ?a, @entry.getc
end

View file

@ -48,5 +48,18 @@ class TestGemPackageTask < Gem::TestCase
assert_equal ["x", "y"], pkg.package_files
end
def test_package_dir_path
gem = Gem::Specification.new do |g|
g.name = 'nokogiri'
g.version = '1.5.0'
g.platform = 'java'
end
pkg = Gem::PackageTask.new gem
pkg.define
assert_equal 'pkg/nokogiri-1.5.0-java', pkg.package_dir_path
end
end

View file

@ -93,4 +93,3 @@ class TestGemSecurity < Gem::TestCase
end
end if defined?(OpenSSL)