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

Import RubyGems r1601. [ruby-core:15381].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2008-02-10 08:00:19 +00:00
parent c12b289362
commit 5d613c83cc
26 changed files with 165 additions and 85 deletions

View file

@ -1,3 +1,8 @@
Sun Feb 10 16:58:20 2008 Eric Hodel <drbrain@segment7.net>
* lib/rubygems*, test/rubygems*, gem_prelude.rb: Import RubyGems
* r1601. [ruby-core:15381]
Sun Feb 10 15:07:23 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* {bcc32,win32,wince}/Makefile.sub (MISSING): added cbrt.obj.

View file

@ -8,7 +8,7 @@
require 'rubygems'
require 'rubygems/gem_runner'
required_version = Gem::Requirement.new ">= 1.8.2"
required_version = Gem::Requirement.new ">= 1.8.3"
unless required_version.satisfied_by? Gem::Version.new(RUBY_VERSION) then
abort "Expected Ruby Version #{required_version}, was #{RUBY_VERSION}"

View file

@ -167,6 +167,12 @@ module Gem
end
end
# "tag" the first require_path inserted into the $LOAD_PATH to enable
# indexing correctly with rubygems proper when it inserts an explicitly
# gem version
unless require_paths.empty?
require_paths.first.instance_variable_set(:@gem_prelude_index, true)
end
# gem directories must come after -I and ENV['RUBYLIB']
$:[$:.index(ConfigMap[:sitelibdir]),0] = require_paths
end

View file

@ -290,6 +290,24 @@ module Gem
@ruby
end
# Return the index to insert activated gem paths into the $LOAD_PATH
# Defaults to the site lib directory unless gem_prelude.rb has loaded
# paths then it inserts the path before those paths so you can override
# the gem_prelude.rb default $LOAD_PATH paths.
def load_path_insert_index
index = $LOAD_PATH.index ConfigMap[:sitelibdir]
$LOAD_PATH.each_with_index do |path, i|
if path.instance_variables.include?(:@gem_prelude_index) or
path.instance_variables.include?('@gem_prelude_index') then
index = i
break
end
end
index
end
# Activate a gem (i.e. add it to the Ruby load path). The gem
# must satisfy all the specified version constraints. If
# +autorequire+ is true, then automatically require the specified
@ -345,11 +363,13 @@ module Gem
end
sitelibdir = ConfigMap[:sitelibdir]
sitelibdir_index = $LOAD_PATH.index sitelibdir
if sitelibdir_index then
# gem directories must come after -I and ENV['RUBYLIB']
insert_index = load_path_insert_index
if insert_index then
# gem directories must come after -I and ENV['RUBYLIB']
$LOAD_PATH.insert(sitelibdir_index, *require_paths)
$LOAD_PATH.insert(insert_index, *require_paths)
else
# we are probably testing in core, -I and RUBYLIB don't apply
$LOAD_PATH.unshift(*require_paths)

View file

@ -58,7 +58,11 @@ class Gem::Commands::EnvironmentCommand < Gem::Command
end
out << " - GEM PATHS:\n"
Gem.path.each do |p|
out << " - #{Gem.dir}\n"
path = Gem.path.dup
path.delete Gem.dir
path.each do |p|
out << " - #{p}\n"
end

View file

@ -18,18 +18,23 @@ module Gem
options[:all] = value
end
add_option('-i', '--[no-]ignore-dependencies',
'Ignore dependency requirements while',
'uninstalling') do |value, options|
add_option('-I', '--[no-]ignore-dependencies',
'Ignore dependency requirements while',
'uninstalling') do |value, options|
options[:ignore] = value
end
add_option('-x', '--[no-]executables',
add_option('-x', '--[no-]executables',
'Uninstall applicable executables without',
'confirmation') do |value, options|
options[:executables] = value
end
add_option('-i', '--install-dir DIR',
'Directory to uninstall gem from') do |value, options|
options[:install_dir] = File.expand_path(value)
end
add_version_option
add_platform_option
end
@ -39,7 +44,8 @@ module Gem
end
def defaults_str # :nodoc:
"--version '#{Gem::Requirement.default}' --no-force"
"--version '#{Gem::Requirement.default}' --no-force " \
"--install-dir #{Gem.dir}"
end
def usage # :nodoc:

View file

@ -11,6 +11,10 @@ class Gem::DependencyError < Gem::Exception; end
class Gem::DependencyRemovalException < Gem::Exception; end
##
# Raised when attempting to uninstall a gem that isn't in GEM_HOME.
class Gem::GemNotInHomeException < Gem::Exception; end
class Gem::DocumentError < Gem::Exception; end
##

View file

@ -37,7 +37,7 @@ module Gem::InstallUpdateOptions
options[:generate_ri] = value
end
add_option(:"Install/Update", '-E', '--env-shebang',
add_option(:"Install/Update", '-E', '--[no-]env-shebang',
"Rewrite the shebang line on installed",
"scripts to use /usr/bin/env") do |value, options|
options[:env_shebang] = value

View file

@ -63,6 +63,7 @@ class Gem::Installer
:force => false,
:install_dir => Gem.dir,
:exec_format => false,
:env_shebang => false
}.merge options
@env_shebang = options[:env_shebang]

View file

@ -614,14 +614,16 @@ module Gem::Package
# this method would use the String IO approach on all platforms at all
# times. And that's the way it is.
def zipped_stream(entry)
# This is Jamis Buck's ZLib workaround. The original code is
# commented out while we evaluate this patch.
entry.read(10) # skip the gzip header
zis = Zlib::Inflate.new(-Zlib::MAX_WBITS)
is = StringIO.new(zis.inflate(entry.read))
# zis = Zlib::GzipReader.new entry
# dis = zis.read
# is = StringIO.new(dis)
if defined? Rubinius then
zis = Zlib::GzipReader.new entry
dis = zis.read
is = StringIO.new(dis)
else
# This is Jamis Buck's ZLib workaround for some unknown issue
entry.read(10) # skip the gzip header
zis = Zlib::Inflate.new(-Zlib::MAX_WBITS)
is = StringIO.new(zis.inflate(entry.read))
end
ensure
zis.finish if zis
end

View file

@ -46,7 +46,7 @@ module Gem
if deprecated.empty?
from_gems_in(*installed_spec_directories)
else
from_gems_in(*deprecated)
from_gems_in(*deprecated) # HACK warn
end
end
@ -118,6 +118,7 @@ module Gem
def load_gems_in(*spec_dirs)
@gems.clear
specs = Dir.glob File.join("{#{spec_dirs.join(',')}}", "*.gemspec")
specs.each do |file_name|
gemspec = self.class.load_specification(file_name.untaint)
add_spec(gemspec) if gemspec

View file

@ -457,7 +457,7 @@ module Gem
overwrite_accessor :default_executable do
begin
if defined? @default_executable and @default_executable
if defined?(@default_executable) and @default_executable
result = @default_executable
elsif @executables and @executables.size == 1
result = Array(@executables).first
@ -471,14 +471,12 @@ module Gem
end
def add_bindir(executables)
if not defined? @executables || @executables.nil?
return nil
end
return nil if executables.nil?
if defined? @bindir and @bindir then
Array(@executables).map {|e| File.join(@bindir, e) }
if @bindir then
Array(executables).map { |e| File.join(@bindir, e) }
else
@executables
executables
end
rescue
return nil
@ -511,7 +509,7 @@ module Gem
@test_files = [@test_suite_file].flatten
@test_suite_file = nil
end
if defined? @test_files and @test_files then
if defined?(@test_files) and @test_files then
@test_files
else
@test_files = []
@ -903,7 +901,7 @@ module Gem
# Also, the summary and description are converted to a normal
# format.
def normalize
if defined? @extra_rdoc_files and @extra_rdoc_files then
if defined?(@extra_rdoc_files) and @extra_rdoc_files then
@extra_rdoc_files.uniq!
@files ||= []
@files.concat(@extra_rdoc_files)

View file

@ -25,6 +25,8 @@ class Gem::Uninstaller
def initialize(gem, options)
@gem = gem
@version = options[:version] || Gem::Requirement.default
gem_home = options[:install_dir] || Gem.dir
@gem_home = File.expand_path gem_home
@force_executables = options[:executables]
@force_all = options[:all]
@force_ignore = options[:ignore]
@ -71,31 +73,38 @@ class Gem::Uninstaller
#
def remove_executables(gemspec)
return if gemspec.nil?
if(gemspec.executables.size > 0)
raise Gem::FilePermissionError.new(Gem.bindir) unless
File.writable?(Gem.bindir)
if gemspec.executables.size > 0 then
bindir = Gem.bindir @gem_home
raise Gem::FilePermissionError, bindir unless File.writable? bindir
list = Gem.source_index.search(gemspec.name).delete_if { |spec|
spec.version == gemspec.version
}
executables = gemspec.executables.clone
list.each do |spec|
spec.executables.each do |exe_name|
executables.delete(exe_name)
end
end
return if executables.size == 0
answer = @force_executables || ask_yes_no(
"Remove executables and scripts for\n" +
"'#{gemspec.executables.join(", ")}' in addition to the gem?",
"Remove executables:\n" \
"\t#{gemspec.executables.join(", ")}\n\nin addition to the gem?",
true) # " # appease ruby-mode - don't ask
unless answer
unless answer then
say "Executables and scripts will remain installed."
return
else
gemspec.executables.each do |exe_name|
say "Removing #{exe_name}"
File.unlink File.join(Gem.bindir, exe_name) rescue nil
File.unlink File.join(Gem.bindir, exe_name + ".bat") rescue nil
FileUtils.rm_f File.join(bindir, exe_name)
FileUtils.rm_f File.join(bindir, "#{exe_name}.bat")
end
end
end
@ -119,11 +128,18 @@ class Gem::Uninstaller
# uninstalled a gem, it is removed from that list.
#
def remove(spec, list)
unless ok_to_remove? spec then
unless dependencies_ok? spec then
raise Gem::DependencyRemovalException,
"Uninstallation aborted due to dependent gem(s)"
end
unless path_ok? spec then
alert("In order to remove #{spec.name}, please execute:\n" \
"\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}")
raise Gem::GemNotInHomeException,
"Gem is not installed in directory #{@gem_home}"
end
raise Gem::FilePermissionError, spec.installation_path unless
File.writable?(spec.installation_path)
@ -157,7 +173,13 @@ class Gem::Uninstaller
list.delete spec
end
def ok_to_remove?(spec)
def path_ok?(spec)
match_path = File.join @gem_home, 'gems', spec.full_name
match_path == spec.full_gem_path
end
def dependencies_ok?(spec)
return true if @force_ignore
srcindex = Gem::SourceIndex.from_installed_gems

View file

@ -1,4 +1,3 @@
require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems'
require 'rubygems/gem_openssl'
@ -75,6 +74,8 @@ class TestGem < RubyGemTestCase
install_gem foo
end
Gem.source_index = nil
gem 'foo'
expected = File.join @gemhome, 'gems', foo.full_name, 'data', 'foo'
@ -280,9 +281,7 @@ class TestGem < RubyGemTestCase
def test_self_prefix
file_name = File.expand_path __FILE__
expected = File.dirname File.dirname(file_name)
expected = File.dirname expected if expected =~ %r|/test| # for Ruby trunk
assert_equal expected, Gem.prefix
assert_equal File.dirname(File.dirname(file_name)), Gem.prefix
end
def test_self_required_location

View file

@ -3,6 +3,10 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/commands/cert_command'
unless defined? OpenSSL then
warn "`gem cert` tests are being skipped, module OpenSSL not found"
end
class TestGemCommandsCertCommand < RubyGemTestCase
def setup
@ -118,5 +122,5 @@ class TestGemCommandsCertCommand < RubyGemTestCase
# HACK this test sucks
end
end
end if defined? OpenSSL

View file

@ -25,7 +25,8 @@ class TestGemCommandsEnvironmentCommand < RubyGemTestCase
assert_match %r|INSTALLATION DIRECTORY: #{Regexp.escape @gemhome}|,
@ui.output
assert_match %r|RUBYGEMS PREFIX: |, @ui.output
assert_match %r|RUBY EXECUTABLE:.*ruby|, @ui.output
assert_match %r|RUBY EXECUTABLE:.*#{Gem::ConfigMap[:RUBY_INSTALL_NAME]}|,
@ui.output
assert_match %r|RUBYGEMS PLATFORMS:|, @ui.output
assert_match %r|- #{Gem::Platform.local}|, @ui.output
assert_match %r|GEM PATHS:|, @ui.output

View file

@ -1,5 +1,7 @@
require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/package'
require 'rubygems/security'
require 'rubygems/commands/fetch_command'
class TestGemCommandsFetchCommand < RubyGemTestCase

View file

@ -85,7 +85,8 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase
@cmd.execute
end
assert_equal "#{foo.to_yaml}\n", @ui.output
assert_match %r|\A--- !ruby/object:Gem::Specification|, @ui.output
assert_match %r|name: foo|, @ui.output
assert_equal "WARNING: Remote information is not complete\n\n", @ui.error
end

View file

@ -288,19 +288,21 @@ class TestGemDependencyInstaller < RubyGemTestCase
assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
end
def test_install_security_policy
FileUtils.mv @a1_gem, @cache_dir
FileUtils.mv @b1_gem, @cache_dir
policy = Gem::Security::HighSecurity
inst = Gem::DependencyInstaller.new 'b', nil, :security_policy => policy
if defined? OpenSSL then
def test_install_security_policy
FileUtils.mv @a1_gem, @cache_dir
FileUtils.mv @b1_gem, @cache_dir
policy = Gem::Security::HighSecurity
inst = Gem::DependencyInstaller.new 'b', nil, :security_policy => policy
e = assert_raise Gem::Exception do
inst.install
e = assert_raise Gem::Exception do
inst.install
end
assert_equal 'Unsigned gem', e.message
assert_equal %w[], inst.installed_gems.map { |s| s.full_name }
end
assert_equal 'Unsigned gem', e.message
assert_equal %w[], inst.installed_gems.map { |s| s.full_name }
end
def test_install_wrappers

View file

@ -271,7 +271,7 @@ gems:
fetcher.fetch_path 'uri'
end
assert_match %r|\AErrno::ECONNREFUSED: .* - connect\(2\) reading uri\z|,
assert_match %r|ECONNREFUSED:.*connect\(2\) reading uri\z|,
e.message
end

View file

@ -53,10 +53,10 @@ class TestGemServer < RubyGemTestCase
assert_equal 200, @res.status, @res.body
assert @res['date']
assert_equal 'text/plain', @res['content-type']
yaml = Zlib::Inflate.inflate(@res.body)
assert_match %r|Gem::Specification|, yaml
assert_match %r|name: a|, yaml
assert_match %r|version: "1"|, yaml
spec = YAML.load Zlib::Inflate.inflate(@res.body)
assert_equal 'a', spec.name
assert_equal Gem::Version.new(1), spec.version
end
def test_quick_a_1_mswin32_gemspec_rz
@ -72,10 +72,11 @@ class TestGemServer < RubyGemTestCase
assert_equal 200, @res.status, @res.body
assert @res['date']
assert_equal 'text/plain', @res['content-type']
yaml = Zlib::Inflate.inflate(@res.body)
assert_match %r|Gem::Specification|, yaml
assert_match %r|name: a|, yaml
assert_match %r|version: "1"|, yaml
spec = YAML.load Zlib::Inflate.inflate(@res.body)
assert_equal 'a', spec.name
assert_equal Gem::Version.new(1), spec.version
assert_equal Gem::Platform.local, spec.platform
end
def test_quick_common_substrings
@ -91,10 +92,10 @@ class TestGemServer < RubyGemTestCase
assert_equal 200, @res.status, @res.body
assert @res['date']
assert_equal 'text/plain', @res['content-type']
yaml = Zlib::Inflate.inflate @res.body
assert_match %r|Gem::Specification|, yaml
assert_match %r|name: a$|, yaml
assert_match %r|version: "1"|, yaml
spec = YAML.load Zlib::Inflate.inflate(@res.body)
assert_equal 'a', spec.name
assert_equal Gem::Version.new(1), spec.version
end
def test_quick_z_9_gemspec_rz

View file

@ -401,7 +401,7 @@ class TestGemSourceIndex < RubyGemTestCase
def test_update_with_missing
marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
"#{@gem3.full_name}.gemspec.rz"
dumped = Marshal.dump(@gem3)
dumped = Marshal.dump @gem3
@fetcher.data[marshal_uri] = util_zip(dumped)
use_ui @ui do

View file

@ -185,7 +185,7 @@ class TestGemVersion < RubyGemTestCase
def assert_adequate(version, requirement)
ver = Gem::Version.new(version)
req = Gem::Version::Requirement.new(requirement)
req = Gem::Requirement.new(requirement)
assert req.satisfied_by?(ver),
"Version #{version} should be adequate for Requirement #{requirement}"
end

View file

@ -7,6 +7,7 @@
require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/package'
class TestKernel < RubyGemTestCase