Update to RubyGems 1.3.0 r1891

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2008-09-25 10:13:50 +00:00
Родитель 788001a9c8
Коммит d478c7a734
60 изменённых файлов: 2174 добавлений и 1049 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Thu Sep 25 19:13:12 2008
* lib/rubygems*: Update to RubyGems 1.3.0 r1891.
Thu Sep 25 18:40:42 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp> Thu Sep 25 18:40:42 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* class.c (rb_make_metaclass): Made class of class of class * class.c (rb_make_metaclass): Made class of class of class

Просмотреть файл

@ -104,6 +104,11 @@ module Gem
@ruby = nil @ruby = nil
@sources = [] @sources = []
@post_install_hooks = []
@post_uninstall_hooks = []
@pre_uninstall_hooks = []
@pre_install_hooks = []
## ##
# Activates an installed gem matching +gem+. The gem must satisfy # Activates an installed gem matching +gem+. The gem must satisfy
# +version_requirements+. # +version_requirements+.
@ -244,7 +249,10 @@ module Gem
def self.clear_paths def self.clear_paths
@gem_home = nil @gem_home = nil
@gem_path = nil @gem_path = nil
@user_home = nil
@@source_index = nil @@source_index = nil
MUTEX.synchronize do MUTEX.synchronize do
@searcher = nil @searcher = nil
end end
@ -261,9 +269,7 @@ module Gem
# The standard configuration object for gems. # The standard configuration object for gems.
def self.configuration def self.configuration
return @configuration if @configuration @configuration ||= Gem::ConfigFile.new []
require 'rubygems/config_file'
@configuration = Gem::ConfigFile.new []
end end
## ##
@ -336,6 +342,22 @@ module Gem
end end
end end
##
# Returns a list of paths matching +file+ that can be used by a gem to pick
# up features from other gems. For example:
#
# Gem.find_files('rdoc/discover').each do |path| load path end
#
# find_files does not search $LOAD_PATH for files, only gems.
def self.find_files(path)
specs = searcher.find_all path
specs.map do |spec|
searcher.matching_files spec, path
end.flatten
end
## ##
# Finds the user's home directory. # Finds the user's home directory.
#-- #--
@ -353,7 +375,7 @@ module Gem
end end
if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}" return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
end end
begin begin
@ -466,13 +488,11 @@ module Gem
## ##
# manage_gems is useless and deprecated. Don't call it anymore. # manage_gems is useless and deprecated. Don't call it anymore.
#--
# TODO warn w/ RubyGems 1.2.x release.
def self.manage_gems def self.manage_gems # :nodoc:
#file, lineno = location_of_caller file, lineno = location_of_caller
#warn "#{file}:#{lineno}:Warning: Gem#manage_gems is deprecated and will be removed on or after September 2008." warn "#{file}:#{lineno}:Warning: Gem::manage_gems is deprecated and will be removed on or after March 2009."
end end
## ##
@ -489,11 +509,7 @@ module Gem
@gem_path ||= nil @gem_path ||= nil
unless @gem_path then unless @gem_path then
paths = if ENV['GEM_PATH'] then paths = [ENV['GEM_PATH'] || Gem.configuration.path || default_path]
[ENV['GEM_PATH']]
else
[default_path]
end
if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then
paths << APPLE_GEM_HOME paths << APPLE_GEM_HOME
@ -523,6 +539,40 @@ module Gem
@platforms @platforms
end end
##
# Adds a post-install hook that will be passed an Gem::Installer instance
# when Gem::Installer#install is called
def self.post_install(&hook)
@post_install_hooks << hook
end
##
# Adds a post-uninstall hook that will be passed a Gem::Uninstaller instance
# and the spec that was uninstalled when Gem::Uninstaller#uninstall is
# called
def self.post_uninstall(&hook)
@post_uninstall_hooks << hook
end
##
# Adds a pre-install hook that will be passed an Gem::Installer instance
# when Gem::Installer#install is called
def self.pre_install(&hook)
@pre_install_hooks << hook
end
##
# Adds a pre-uninstall hook that will be passed an Gem::Uninstaller instance
# and the spec that will be uninstalled when Gem::Uninstaller#uninstall is
# called
def self.pre_uninstall(&hook)
@pre_uninstall_hooks << hook
end
## ##
# The directory prefix this RubyGems was installed at. # The directory prefix this RubyGems was installed at.
@ -600,6 +650,9 @@ module Gem
@ruby = File.join(ConfigMap[:bindir], @ruby = File.join(ConfigMap[:bindir],
ConfigMap[:ruby_install_name]) ConfigMap[:ruby_install_name])
@ruby << ConfigMap[:EXEEXT] @ruby << ConfigMap[:EXEEXT]
# escape string in case path to ruby executable contain spaces.
@ruby.sub!(/.*\s.*/m, '"\&"')
end end
@ruby @ruby
@ -655,7 +708,13 @@ module Gem
end end
@gem_path.uniq! @gem_path.uniq!
@gem_path.each do |gp| ensure_gem_subdirectories(gp) end @gem_path.each do |path|
if 0 == File.expand_path(path).index(Gem.user_home) and
Etc.getpwuid.uid != File::Stat.new(Gem.user_home).uid then
next # only create by matching user
end
ensure_gem_subdirectories path
end
end end
private_class_method :set_paths private_class_method :set_paths
@ -685,6 +744,14 @@ module Gem
@sources @sources
end end
##
# Need to be able to set the sources without calling
# Gem.sources.replace since that would cause an infinite loop.
def self.sources=(new_sources)
@sources = new_sources
end
## ##
# Glob pattern for require-able path suffixes. # Glob pattern for require-able path suffixes.
@ -731,6 +798,27 @@ module Gem
attr_reader :loaded_specs attr_reader :loaded_specs
##
# The list of hooks to be run before Gem::Install#install does any work
attr_reader :post_install_hooks
##
# The list of hooks to be run before Gem::Uninstall#uninstall does any
# work
attr_reader :post_uninstall_hooks
##
# The list of hooks to be run after Gem::Install#install is finished
attr_reader :pre_install_hooks
##
# The list of hooks to be run after Gem::Uninstall#uninstall is finished
attr_reader :pre_uninstall_hooks
# :stopdoc: # :stopdoc:
alias cache source_index # an alias for the old name alias cache source_index # an alias for the old name
@ -781,7 +869,10 @@ if defined?(RUBY_ENGINE) then
end end
end end
require 'rubygems/config_file'
if RUBY_VERSION < '1.9' then if RUBY_VERSION < '1.9' then
require 'rubygems/custom_require' require 'rubygems/custom_require'
end end
Gem.clear_paths

Просмотреть файл

@ -51,7 +51,7 @@ class Gem::Commands::ContentsCommand < Gem::Command
si = Gem::SourceIndex.from_gems_in(*s) si = Gem::SourceIndex.from_gems_in(*s)
gem_spec = si.search(/\A#{gem}\z/, version).last gem_spec = si.find_name(gem, version).last
unless gem_spec then unless gem_spec then
say "Unable to find gem '#{gem}' in #{path_kind}" say "Unable to find gem '#{gem}' in #{path_kind}"

Просмотреть файл

@ -18,6 +18,46 @@ class Gem::Commands::EnvironmentCommand < Gem::Command
return args.gsub(/^\s+/, '') return args.gsub(/^\s+/, '')
end end
def description # :nodoc:
<<-EOF
The RubyGems environment can be controlled through command line arguments,
gemrc files, environment variables and built-in defaults.
Command line argument defaults and some RubyGems defaults can be set in
~/.gemrc file for individual users and a /etc/gemrc for all users. A gemrc
is a YAML file with the following YAML keys:
:sources: A YAML array of remote gem repositories to install gems from
:verbose: Verbosity of the gem command. false, true, and :really are the
levels
:update_sources: Enable/disable automatic updating of repository metadata
:backtrace: Print backtrace when RubyGems encounters an error
:bulk_threshold: Switch to a bulk update when this many sources are out of
date (legacy setting)
:gempath: The paths in which to look for gems
gem_command: A string containing arguments for the specified gem command
Example:
:verbose: false
install: --no-wrappers
update: --no-wrappers
RubyGems' default local repository can be overriden with the GEM_PATH and
GEM_HOME environment variables. GEM_HOME sets the default repository to
install into. GEM_PATH allows multiple local repositories to be searched for
gems.
If you are behind a proxy server, RubyGems uses the HTTP_PROXY,
HTTP_PROXY_USER and HTTP_PROXY_PASS environment variables to discover the
proxy server.
If you are packaging RubyGems all of RubyGems' defaults are in
lib/rubygems/defaults.rb. You may override these in
lib/rubygems/defaults/operating_system.rb
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} [arg]" "#{program_name} [arg]"
end end

Просмотреть файл

@ -20,9 +20,9 @@ Some examples of 'gem' usage.
gem install --remote rake --test --rdoc --ri gem install --remote rake --test --rdoc --ri
* Install 'rake', but only version 0.3.1, even if dependencies * Install 'rake', but only version 0.3.1, even if dependencies
are not met, and into a specific directory: are not met, and into a user-specific directory:
gem install rake --version 0.3.1 --force --install-dir $HOME/.gems gem install rake --version 0.3.1 --force --user-install
* List local gems whose name begins with 'D': * List local gems whose name begins with 'D':

Просмотреть файл

@ -38,6 +38,19 @@ class Gem::Commands::InstallCommand < Gem::Command
"--no-test --install-dir #{Gem.dir}" "--no-test --install-dir #{Gem.dir}"
end end
def description # :nodoc:
<<-EOF
The install command installs local or remote gem into a gem repository.
For gems with executables ruby installs a wrapper file into the executable
directory by deault. This can be overridden with the --no-wrappers option.
The wrapper allows you to choose among alternate gem versions using _version_.
For example `rake _0.7.3_ --version` will run rake version 0.7.3 if a newer
version is also installed.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags" "#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags"
end end
@ -106,6 +119,8 @@ class Gem::Commands::InstallCommand < Gem::Command
installed_gems.each do |gem| installed_gems.each do |gem|
Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
end end
Gem::DocManager.update_ri_cache
end end
if options[:generate_rdoc] then if options[:generate_rdoc] then

Просмотреть файл

@ -58,15 +58,15 @@ lock it down to the exact version.
end end
def complain(message) def complain(message)
if options.strict then if options[:strict] then
raise message raise Gem::Exception, message
else else
say "# #{message}" say "# #{message}"
end end
end end
def execute def execute
say 'require "rubygems"' say "require 'rubygems'"
locked = {} locked = {}
@ -77,15 +77,20 @@ lock it down to the exact version.
spec = Gem::SourceIndex.load_specification spec_path(full_name) spec = Gem::SourceIndex.load_specification spec_path(full_name)
if spec.nil? then
complain "Could not find gem #{full_name}, try using the full name"
next
end
say "gem '#{spec.name}', '= #{spec.version}'" unless locked[spec.name] say "gem '#{spec.name}', '= #{spec.version}'" unless locked[spec.name]
locked[spec.name] = true locked[spec.name] = true
spec.runtime_dependencies.each do |dep| spec.runtime_dependencies.each do |dep|
next if locked[dep.name] next if locked[dep.name]
candidates = Gem.source_index.search dep.name, dep.requirement_list candidates = Gem.source_index.search dep
if candidates.empty? then if candidates.empty? then
complain "Unable to satisfy '#{dep}' from currently installed gems." complain "Unable to satisfy '#{dep}' from currently installed gems"
else else
pending << candidates.last.full_name pending << candidates.last.full_name
end end
@ -94,7 +99,11 @@ lock it down to the exact version.
end end
def spec_path(gem_full_name) def spec_path(gem_full_name)
File.join Gem.path, "specifications", "#{gem_full_name }.gemspec" gemspecs = Gem.path.map do |path|
File.join path, "specifications", "#{gem_full_name}.gemspec"
end
gemspecs.find { |gemspec| File.exist? gemspec }
end end
end end

Просмотреть файл

@ -19,7 +19,7 @@ class Gem::Commands::OutdatedCommand < Gem::Command
locals = Gem::SourceIndex.from_installed_gems locals = Gem::SourceIndex.from_installed_gems
locals.outdated.sort.each do |name| locals.outdated.sort.each do |name|
local = locals.search(/^#{name}$/).last local = locals.find_name(name).last
dep = Gem::Dependency.new local.name, ">= #{local.version}" dep = Gem::Dependency.new local.name, ">= #{local.version}"
remotes = Gem::SpecFetcher.fetcher.fetch dep remotes = Gem::SpecFetcher.fetcher.fetch dep

Просмотреть файл

@ -57,7 +57,7 @@ revert the gem.
end end
else else
gem_name = get_one_gem_name gem_name = get_one_gem_name
Gem::SourceIndex.from_installed_gems.search(gem_name, Gem::SourceIndex.from_installed_gems.find_name(gem_name,
options[:version]) options[:version])
end end

Просмотреть файл

@ -59,7 +59,7 @@ class Gem::Commands::QueryCommand < Gem::Command
if name.source.empty? then if name.source.empty? then
alert_error "You must specify a gem name" alert_error "You must specify a gem name"
exit_code |= 4 exit_code |= 4
elsif installed? name.source, options[:version] then elsif installed? name, options[:version] then
say "true" say "true"
else else
say "false" say "false"
@ -69,12 +69,16 @@ class Gem::Commands::QueryCommand < Gem::Command
raise Gem::SystemExitException, exit_code raise Gem::SystemExitException, exit_code
end end
if local? then dep = Gem::Dependency.new name, Gem::Requirement.default
say
say "*** LOCAL GEMS ***"
say
specs = Gem.source_index.search name if local? then
if ui.outs.tty? or both? then
say
say "*** LOCAL GEMS ***"
say
end
specs = Gem.source_index.search dep
spec_tuples = specs.map do |spec| spec_tuples = specs.map do |spec|
[[spec.name, spec.version, spec.original_platform, spec], :local] [[spec.name, spec.version, spec.original_platform, spec], :local]
@ -84,13 +88,14 @@ class Gem::Commands::QueryCommand < Gem::Command
end end
if remote? then if remote? then
say if ui.outs.tty? or both? then
say "*** REMOTE GEMS ***" say
say say "*** REMOTE GEMS ***"
say
end
all = options[:all] all = options[:all]
dep = Gem::Dependency.new name, Gem::Requirement.default
begin begin
fetcher = Gem::SpecFetcher.fetcher fetcher = Gem::SpecFetcher.fetcher
spec_tuples = fetcher.find_matching dep, all, false spec_tuples = fetcher.find_matching dep, all, false

Просмотреть файл

@ -59,11 +59,15 @@ module Gem
if specs.empty? if specs.empty?
fail "Failed to find gem #{gem_name} to generate RDoc for #{options[:version]}" fail "Failed to find gem #{gem_name} to generate RDoc for #{options[:version]}"
end end
if options[:include_ri] if options[:include_ri]
specs.each do |spec| specs.each do |spec|
Gem::DocManager.new(spec).generate_ri Gem::DocManager.new(spec).generate_ri
end end
Gem::DocManager.update_ri_cache
end end
if options[:include_rdoc] if options[:include_rdoc]
specs.each do |spec| specs.each do |spec|
Gem::DocManager.new(spec).generate_rdoc Gem::DocManager.new(spec).generate_rdoc
@ -73,6 +77,6 @@ module Gem
true true
end end
end end
end end
end end

Просмотреть файл

@ -40,6 +40,7 @@ class Gem::Commands::SpecificationCommand < Gem::Command
def execute def execute
specs = [] specs = []
gem = get_one_gem_name gem = get_one_gem_name
dep = Gem::Dependency.new gem, options[:version]
if local? then if local? then
if File.exist? gem then if File.exist? gem then
@ -47,12 +48,11 @@ class Gem::Commands::SpecificationCommand < Gem::Command
end end
if specs.empty? then if specs.empty? then
specs.push(*Gem.source_index.search(/\A#{gem}\z/, options[:version])) specs.push(*Gem.source_index.search(dep))
end end
end end
if remote? then if remote? then
dep = Gem::Dependency.new gem, options[:version]
found = Gem::SpecFetcher.fetcher.fetch dep found = Gem::SpecFetcher.fetcher.fetch dep
specs.push(*found.map { |spec,| spec }) specs.push(*found.map { |spec,| spec })

Просмотреть файл

@ -68,7 +68,7 @@ class Gem::Commands::UnpackCommand < Gem::Command
def get_path(gemname, version_req) def get_path(gemname, version_req)
return gemname if gemname =~ /\.gem$/i return gemname if gemname =~ /\.gem$/i
specs = Gem::source_index.search(/\A#{gemname}\z/, version_req) specs = Gem::source_index.find_name gemname, version_req
selected = specs.sort_by { |s| s.version }.last selected = specs.sort_by { |s| s.version }.last

Просмотреть файл

@ -45,6 +45,8 @@ class Gem::Commands::UpdateCommand < Gem::Command
end end
def execute def execute
hig = {}
if options[:system] then if options[:system] then
say "Updating RubyGems" say "Updating RubyGems"
@ -52,16 +54,22 @@ class Gem::Commands::UpdateCommand < Gem::Command
fail "No gem names are allowed with the --system option" fail "No gem names are allowed with the --system option"
end end
options[:args] = ["rubygems-update"] spec = Gem::Specification.new
spec.name = 'rubygems-update'
spec.version = Gem::Version.new Gem::RubyGemsVersion
spec.version = Gem::Version.new '1.1.1'
hig['rubygems-update'] = spec
options[:user_install] = false
else else
say "Updating installed gems" say "Updating installed gems"
end
hig = {} # highest installed gems hig = {} # highest installed gems
Gem.source_index.each do |name, spec| Gem.source_index.each do |name, spec|
if hig[spec.name].nil? or hig[spec.name].version < spec.version then if hig[spec.name].nil? or hig[spec.name].version < spec.version then
hig[spec.name] = spec hig[spec.name] = spec
end
end end
end end
@ -84,14 +92,14 @@ class Gem::Commands::UpdateCommand < Gem::Command
end end
if gems_to_update.include? "rubygems-update" then if gems_to_update.include? "rubygems-update" then
latest_ruby_gem = remote_gemspecs.select do |s| Gem.source_index.refresh!
s.name == 'rubygems-update'
end
latest_ruby_gem = latest_ruby_gem.sort_by { |s| s.version }.last update_gems = Gem.source_index.search 'rubygems-update'
say "Updating version of RubyGems to #{latest_ruby_gem.version}" latest_update_gem = update_gems.sort_by { |s| s.version }.last
installed = do_rubygems_update latest_ruby_gem.version
say "Updating RubyGems to #{latest_update_gem.version}"
installed = do_rubygems_update latest_update_gem.version
say "RubyGems system software updated" if installed say "RubyGems system software updated" if installed
else else
@ -103,6 +111,9 @@ class Gem::Commands::UpdateCommand < Gem::Command
end end
end end
##
# Update the RubyGems software to +version+.
def do_rubygems_update(version) def do_rubygems_update(version)
args = [] args = []
args.push '--prefix', Gem.prefix unless Gem.prefix.nil? args.push '--prefix', Gem.prefix unless Gem.prefix.nil?
@ -112,8 +123,6 @@ class Gem::Commands::UpdateCommand < Gem::Command
update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}" update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
success = false
Dir.chdir update_dir do Dir.chdir update_dir do
say "Installing RubyGems #{version}" say "Installing RubyGems #{version}"
setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}" setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"

Просмотреть файл

@ -3,10 +3,10 @@ require 'rubygems/gem_path_searcher'
class Gem::Commands::WhichCommand < Gem::Command class Gem::Commands::WhichCommand < Gem::Command
EXT = %w[.rb .rbw .so .dll] # HACK EXT = %w[.rb .rbw .so .dll .bundle] # HACK
def initialize def initialize
super 'which', 'Find the location of a library', super 'which', 'Find the location of a library file you can require',
:search_gems_first => false, :show_all => false :search_gems_first => false, :show_all => false
add_option '-a', '--[no-]all', 'show all matching files' do |show_all, options| add_option '-a', '--[no-]all', 'show all matching files' do |show_all, options|
@ -52,7 +52,7 @@ class Gem::Commands::WhichCommand < Gem::Command
paths = find_paths arg, dirs paths = find_paths arg, dirs
if paths.empty? then if paths.empty? then
say "Can't find #{arg}" say "Can't find ruby library file or shared library #{arg}"
else else
say paths say paths
end end
@ -84,3 +84,4 @@ class Gem::Commands::WhichCommand < Gem::Command
end end
end end

Просмотреть файл

@ -49,6 +49,9 @@ class Gem::ConfigFile
# List of arguments supplied to the config file object. # List of arguments supplied to the config file object.
attr_reader :args attr_reader :args
# Where to look for gems
attr_accessor :path
# True if we print backtraces on errors. # True if we print backtraces on errors.
attr_writer :backtrace attr_writer :backtrace
@ -123,9 +126,10 @@ class Gem::ConfigFile
@backtrace = @hash[:backtrace] if @hash.key? :backtrace @backtrace = @hash[:backtrace] if @hash.key? :backtrace
@benchmark = @hash[:benchmark] if @hash.key? :benchmark @benchmark = @hash[:benchmark] if @hash.key? :benchmark
@bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold
Gem.sources.replace @hash[:sources] if @hash.key? :sources Gem.sources = @hash[:sources] if @hash.key? :sources
@verbose = @hash[:verbose] if @hash.key? :verbose @verbose = @hash[:verbose] if @hash.key? :verbose
@update_sources = @hash[:update_sources] if @hash.key? :update_sources @update_sources = @hash[:update_sources] if @hash.key? :update_sources
@path = @hash[:gempath]
handle_arguments arg_list handle_arguments arg_list
end end

Просмотреть файл

@ -1,36 +1,52 @@
module Gem module Gem
# An Array of the default sources that come with RubyGems. ##
# An Array of the default sources that come with RubyGems
def self.default_sources def self.default_sources
%w[http://gems.rubyforge.org/] %w[http://gems.rubyforge.org/]
end end
##
# Default home directory path to be used if an alternate value is not # Default home directory path to be used if an alternate value is not
# specified in the environment. # specified in the environment
def self.default_dir def self.default_dir
if defined? RUBY_FRAMEWORK_VERSION then if defined? RUBY_FRAMEWORK_VERSION then
File.join File.dirname(ConfigMap[:sitedir]), 'Gems', File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
ConfigMap[:ruby_version] ConfigMap[:ruby_version]
elsif defined? RUBY_ENGINE then
File.join ConfigMap[:libdir], RUBY_ENGINE, 'gems',
ConfigMap[:ruby_version]
else else
File.join ConfigMap[:libdir], 'ruby', 'gems', ConfigMap[:ruby_version] File.join(ConfigMap[:libdir], ruby_engine, 'gems',
ConfigMap[:ruby_version])
end end
end end
# Default gem load path. ##
def self.default_path # Path for gems in the user's home directory
[File.join(ENV['HOME'], '.gem'), default_dir]
def self.user_dir
File.join(Gem.user_home, '.gem', ruby_engine,
ConfigMap[:ruby_version])
end end
# Deduce Ruby's --program-prefix and --program-suffix from its install name. ##
# Default gem load path
def self.default_path
[user_dir, default_dir]
end
##
# Deduce Ruby's --program-prefix and --program-suffix from its install name
def self.default_exec_format def self.default_exec_format
baseruby = ConfigMap[:BASERUBY] || 'ruby' baseruby = ConfigMap[:BASERUBY] || 'ruby'
ConfigMap[:RUBY_INSTALL_NAME].sub(baseruby, '%s') rescue '%s' ConfigMap[:RUBY_INSTALL_NAME].sub(baseruby, '%s') rescue '%s'
end end
##
# The default directory for binaries # The default directory for binaries
def self.default_bindir def self.default_bindir
if defined? RUBY_FRAMEWORK_VERSION then # mac framework support if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
'/usr/bin' '/usr/bin'
@ -39,15 +55,30 @@ module Gem
end end
end end
# The default system-wide source info cache directory. ##
# The default system-wide source info cache directory
def self.default_system_source_cache_dir def self.default_system_source_cache_dir
File.join Gem.dir, 'source_cache' File.join Gem.dir, 'source_cache'
end end
# The default user-specific source info cache directory. ##
# The default user-specific source info cache directory
def self.default_user_source_cache_dir def self.default_user_source_cache_dir
File.join Gem.user_home, '.gem', 'source_cache' File.join Gem.user_home, '.gem', 'source_cache'
end end
##
# A wrapper around RUBY_ENGINE const that may not be defined
def self.ruby_engine
if defined? RUBY_ENGINE then
RUBY_ENGINE
else
'ruby'
end
end
end end

Просмотреть файл

@ -38,9 +38,17 @@ class Gem::DependencyInstaller
# :ignore_dependencies:: Don't install any dependencies. # :ignore_dependencies:: Don't install any dependencies.
# :install_dir:: See Gem::Installer#install. # :install_dir:: See Gem::Installer#install.
# :security_policy:: See Gem::Installer::new and Gem::Security. # :security_policy:: See Gem::Installer::new and Gem::Security.
# :user_install:: See Gem::Installer.new
# :wrappers:: See Gem::Installer::new # :wrappers:: See Gem::Installer::new
def initialize(options = {}) def initialize(options = {})
if options[:install_dir] then
spec_dir = options[:install_dir], 'specifications'
@source_index = Gem::SourceIndex.from_gems_in spec_dir
else
@source_index = Gem.source_index
end
options = DEFAULT_OPTIONS.merge options options = DEFAULT_OPTIONS.merge options
@bin_dir = options[:bin_dir] @bin_dir = options[:bin_dir]
@ -51,19 +59,13 @@ class Gem::DependencyInstaller
@format_executable = options[:format_executable] @format_executable = options[:format_executable]
@ignore_dependencies = options[:ignore_dependencies] @ignore_dependencies = options[:ignore_dependencies]
@security_policy = options[:security_policy] @security_policy = options[:security_policy]
@user_install = options[:user_install]
@wrappers = options[:wrappers] @wrappers = options[:wrappers]
@installed_gems = [] @installed_gems = []
@install_dir = options[:install_dir] || Gem.dir @install_dir = options[:install_dir] || Gem.dir
@cache_dir = options[:cache_dir] || @install_dir @cache_dir = options[:cache_dir] || @install_dir
if options[:install_dir] then
spec_dir = File.join @install_dir, 'specifications'
@source_index = Gem::SourceIndex.from_gems_in spec_dir
else
@source_index = Gem.source_index
end
end end
## ##
@ -232,15 +234,17 @@ class Gem::DependencyInstaller
end end
inst = Gem::Installer.new local_gem_path, inst = Gem::Installer.new local_gem_path,
:env_shebang => @env_shebang, :bin_dir => @bin_dir,
:force => @force, :development => @development,
:format_executable => @format_executable, :env_shebang => @env_shebang,
:force => @force,
:format_executable => @format_executable,
:ignore_dependencies => @ignore_dependencies, :ignore_dependencies => @ignore_dependencies,
:install_dir => @install_dir, :install_dir => @install_dir,
:security_policy => @security_policy, :security_policy => @security_policy,
:wrappers => @wrappers, :source_index => @source_index,
:bin_dir => @bin_dir, :user_install => @user_install,
:development => @development :wrappers => @wrappers
spec = inst.install spec = inst.install

Просмотреть файл

@ -5,132 +5,194 @@
#++ #++
require 'fileutils' require 'fileutils'
require 'rubygems'
module Gem ##
# The documentation manager generates RDoc and RI for RubyGems.
class DocManager class Gem::DocManager
include UserInteraction include Gem::UserInteraction
# Create a document manager for the given gem spec. @configured_args = []
#
# spec:: The Gem::Specification object representing the gem. def self.configured_args
# rdoc_args:: Optional arguments for RDoc (template etc.) as a String. @configured_args ||= []
# end
def initialize(spec, rdoc_args="")
@spec = spec def self.configured_args=(args)
@doc_dir = File.join(spec.installation_path, "doc", spec.full_name) case args
@rdoc_args = rdoc_args.nil? ? [] : rdoc_args.split when Array
@configured_args = args
when String
@configured_args = args.split
end
end
##
# Load RDoc from a gem if it is available, otherwise from Ruby's stdlib
def self.load_rdoc
begin
gem 'rdoc'
rescue Gem::LoadError
# use built-in RDoc
end end
# Is the RDoc documentation installed? begin
def rdoc_installed? require 'rdoc/rdoc'
return File.exist?(File.join(@doc_dir, "rdoc")) rescue LoadError => e
end raise Gem::DocumentError,
# Generate the RI documents for this gem spec.
#
# Note that if both RI and RDoc documents are generated from the
# same process, the RI docs should be done first (a likely bug in
# RDoc will cause RI docs generation to fail if run after RDoc).
def generate_ri
if @spec.has_rdoc then
load_rdoc
install_ri # RDoc bug, ri goes first
end
FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
end
# Generate the RDoc documents for this gem spec.
#
# Note that if both RI and RDoc documents are generated from the
# same process, the RI docs should be done first (a likely bug in
# RDoc will cause RI docs generation to fail if run after RDoc).
def generate_rdoc
if @spec.has_rdoc then
load_rdoc
install_rdoc
end
FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
end
# Load the RDoc documentation generator library.
def load_rdoc
if File.exist?(@doc_dir) && !File.writable?(@doc_dir) then
raise Gem::FilePermissionError.new(@doc_dir)
end
FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
begin
gem 'rdoc'
rescue Gem::LoadError
# use built-in RDoc
end
begin
require 'rdoc/rdoc'
rescue LoadError => e
raise Gem::DocumentError,
"ERROR: RDoc documentation generator not installed!" "ERROR: RDoc documentation generator not installed!"
end end
end
##
# Updates the RI cache for RDoc 2 if it is installed
def self.update_ri_cache
load_rdoc rescue return
return unless defined? RDoc::VERSION # RDoc 1 does not have VERSION
require 'rdoc/ri/driver'
options = {
:use_cache => true,
:use_system => true,
:use_site => true,
:use_home => true,
:use_gems => true,
:formatter => RDoc::RI::Formatter,
}
driver = RDoc::RI::Driver.new(options).class_cache
end
##
# Create a document manager for +spec+. +rdoc_args+ contains arguments for
# RDoc (template etc.) as a String.
def initialize(spec, rdoc_args="")
@spec = spec
@doc_dir = File.join(spec.installation_path, "doc", spec.full_name)
@rdoc_args = rdoc_args.nil? ? [] : rdoc_args.split
end
##
# Is the RDoc documentation installed?
def rdoc_installed?
File.exist?(File.join(@doc_dir, "rdoc"))
end
##
# Generate the RI documents for this gem spec.
#
# Note that if both RI and RDoc documents are generated from the same
# process, the RI docs should be done first (a likely bug in RDoc will cause
# RI docs generation to fail if run after RDoc).
def generate_ri
if @spec.has_rdoc then
setup_rdoc
install_ri # RDoc bug, ri goes first
end end
def install_rdoc FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
rdoc_dir = File.join @doc_dir, 'rdoc' end
FileUtils.rm_rf rdoc_dir ##
# Generate the RDoc documents for this gem spec.
#
# Note that if both RI and RDoc documents are generated from the same
# process, the RI docs should be done first (a likely bug in RDoc will cause
# RI docs generation to fail if run after RDoc).
say "Installing RDoc documentation for #{@spec.full_name}..." def generate_rdoc
run_rdoc '--op', rdoc_dir if @spec.has_rdoc then
setup_rdoc
install_rdoc
end end
def install_ri FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
ri_dir = File.join @doc_dir, 'ri' end
FileUtils.rm_rf ri_dir ##
# Generate and install RDoc into the documentation directory
say "Installing ri documentation for #{@spec.full_name}..." def install_rdoc
run_rdoc '--ri', '--op', ri_dir rdoc_dir = File.join @doc_dir, 'rdoc'
FileUtils.rm_rf rdoc_dir
say "Installing RDoc documentation for #{@spec.full_name}..."
run_rdoc '--op', rdoc_dir
end
##
# Generate and install RI into the documentation directory
def install_ri
ri_dir = File.join @doc_dir, 'ri'
FileUtils.rm_rf ri_dir
say "Installing ri documentation for #{@spec.full_name}..."
run_rdoc '--ri', '--op', ri_dir
end
##
# Run RDoc with +args+, which is an ARGV style argument list
def run_rdoc(*args)
args << @spec.rdoc_options
args << self.class.configured_args
args << '--quiet'
args << @spec.require_paths.clone
args << @spec.extra_rdoc_files
args = args.flatten.map do |arg| arg.to_s end
r = RDoc::RDoc.new
old_pwd = Dir.pwd
Dir.chdir(@spec.full_gem_path)
begin
r.document args
rescue Errno::EACCES => e
dirname = File.dirname e.message.split("-")[1].strip
raise Gem::FilePermissionError.new(dirname)
rescue RuntimeError => ex
alert_error "While generating documentation for #{@spec.full_name}"
ui.errs.puts "... MESSAGE: #{ex}"
ui.errs.puts "... RDOC args: #{args.join(' ')}"
ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
Gem.configuration.backtrace
ui.errs.puts "(continuing with the rest of the installation)"
ensure
Dir.chdir(old_pwd)
end
end
def setup_rdoc
if File.exist?(@doc_dir) && !File.writable?(@doc_dir) then
raise Gem::FilePermissionError.new(@doc_dir)
end end
def run_rdoc(*args) FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
args << @spec.rdoc_options
args << DocManager.configured_args
args << '--quiet'
args << @spec.require_paths.clone
args << @spec.extra_rdoc_files
args = args.flatten.map do |arg| arg.to_s end
r = RDoc::RDoc.new self.class.load_rdoc
end
old_pwd = Dir.pwd ##
Dir.chdir(@spec.full_gem_path) # Remove RDoc and RI documentation
begin
r.document args
rescue Errno::EACCES => e
dirname = File.dirname e.message.split("-")[1].strip
raise Gem::FilePermissionError.new(dirname)
rescue RuntimeError => ex
alert_error "While generating documentation for #{@spec.full_name}"
ui.errs.puts "... MESSAGE: #{ex}"
ui.errs.puts "... RDOC args: #{args.join(' ')}"
ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
Gem.configuration.backtrace
ui.errs.puts "(continuing with the rest of the installation)"
ensure
Dir.chdir(old_pwd)
end
end
def uninstall_doc def uninstall_doc
raise Gem::FilePermissionError.new(@spec.installation_path) unless raise Gem::FilePermissionError.new(@spec.installation_path) unless
File.writable? @spec.installation_path File.writable? @spec.installation_path
original_name = [ original_name = [
@spec.name, @spec.version, @spec.original_platform].join '-' @spec.name, @spec.version, @spec.original_platform].join '-'
doc_dir = File.join @spec.installation_path, 'doc', @spec.full_name doc_dir = File.join @spec.installation_path, 'doc', @spec.full_name
unless File.directory? doc_dir then unless File.directory? doc_dir then
@ -146,22 +208,7 @@ module Gem
end end
FileUtils.rm_rf ri_dir FileUtils.rm_rf ri_dir
end
class << self
def configured_args
@configured_args ||= []
end
def configured_args=(args)
case args
when Array
@configured_args = args
when String
@configured_args = args.split
end
end
end
end end
end end

Просмотреть файл

@ -6,15 +6,15 @@
require 'rubygems' require 'rubygems'
# ##
# GemPathSearcher has the capability to find loadable files inside # GemPathSearcher has the capability to find loadable files inside
# gems. It generates data up front to speed up searches later. # gems. It generates data up front to speed up searches later.
#
class Gem::GemPathSearcher class Gem::GemPathSearcher
# ##
# Initialise the data we need to make searches later. # Initialise the data we need to make searches later.
#
def initialize def initialize
# We want a record of all the installed gemspecs, in the order # We want a record of all the installed gemspecs, in the order
# we wish to examine them. # we wish to examine them.
@ -27,7 +27,7 @@ class Gem::GemPathSearcher
end end
end end
# ##
# Look in all the installed gems until a matching _path_ is found. # Look in all the installed gems until a matching _path_ is found.
# Return the _gemspec_ of the gem where it was found. If no match # Return the _gemspec_ of the gem where it was found. If no match
# is found, return nil. # is found, return nil.
@ -46,36 +46,52 @@ class Gem::GemPathSearcher
# others), which may or may not already be attached to _file_. # others), which may or may not already be attached to _file_.
# This method doesn't care about the full filename that matches; # This method doesn't care about the full filename that matches;
# only that there is a match. # only that there is a match.
#
def find(path) def find(path)
@gemspecs.each do |spec| @gemspecs.find do |spec| matching_file? spec, path end
return spec if matching_file(spec, path) end
##
# Works like #find, but finds all gemspecs matching +path+.
def find_all(path)
@gemspecs.select do |spec|
matching_file? spec, path
end end
nil
end end
private ##
# Attempts to find a matching path using the require_paths of the given
# +spec+.
# Attempts to find a matching path using the require_paths of the def matching_file?(spec, path)
# given _spec_. !matching_files(spec, path).empty?
# end
# Some of the intermediate results are cached in @lib_dirs for
# speed. ##
def matching_file(spec, path) # :doc: # Returns files matching +path+ in +spec+.
#--
# Some of the intermediate results are cached in @lib_dirs for speed.
def matching_files(spec, path)
glob = File.join @lib_dirs[spec.object_id], "#{path}#{Gem.suffix_pattern}" glob = File.join @lib_dirs[spec.object_id], "#{path}#{Gem.suffix_pattern}"
return true unless Dir[glob].select { |f| File.file?(f.untaint) }.empty? Dir[glob].select { |f| File.file? f.untaint }
end end
# Return a list of all installed gemspecs, sorted by alphabetical ##
# order and in reverse version order. # Return a list of all installed gemspecs, sorted by alphabetical order and
# in reverse version order.
def init_gemspecs def init_gemspecs
Gem.source_index.map { |_, spec| spec }.sort { |a,b| Gem.source_index.map { |_, spec| spec }.sort { |a,b|
(a.name <=> b.name).nonzero? || (b.version <=> a.version) (a.name <=> b.name).nonzero? || (b.version <=> a.version)
} }
end end
##
# Returns library directories glob for a gemspec. For example, # Returns library directories glob for a gemspec. For example,
# '/usr/local/lib/ruby/gems/1.8/gems/foobar-1.0/{lib,ext}' # '/usr/local/lib/ruby/gems/1.8/gems/foobar-1.0/{lib,ext}'
def lib_dirs_for(spec) def lib_dirs_for(spec)
"#{spec.full_gem_path}/{#{spec.require_paths.join(',')}}" "#{spec.full_gem_path}/{#{spec.require_paths.join(',')}}"
end end

Просмотреть файл

@ -20,6 +20,7 @@ require 'rubygems/require_paths_builder'
# filesystem including unpacking the gem into its gem dir, installing the # filesystem including unpacking the gem into its gem dir, installing the
# gemspec in the specifications dir, storing the cached gem in the cache dir, # gemspec in the specifications dir, storing the cached gem in the cache dir,
# and installing either wrappers or symlinks for executables. # and installing either wrappers or symlinks for executables.
class Gem::Installer class Gem::Installer
## ##
@ -31,8 +32,36 @@ class Gem::Installer
include Gem::RequirePathsBuilder include Gem::RequirePathsBuilder
##
# The directory a gem's executables will be installed into
attr_reader :bin_dir
##
# The gem repository the gem will be installed into
attr_reader :gem_home
##
# The Gem::Specification for the gem being installed
attr_reader :spec
@home_install_warning = false
@path_warning = false
class << self class << self
##
# True if we've warned about ~/.gems install
attr_accessor :home_install_warning
##
# True if we've warned about PATH not including Gem.bindir
attr_accessor :path_warning
attr_writer :exec_format attr_writer :exec_format
# Defaults to use Ruby's program prefix and suffix. # Defaults to use Ruby's program prefix and suffix.
@ -61,11 +90,12 @@ class Gem::Installer
@gem = gem @gem = gem
options = { options = {
:force => false, :bin_dir => nil,
:install_dir => Gem.dir, :env_shebang => false,
:exec_format => false, :exec_format => false,
:env_shebang => false, :force => false,
:bin_dir => nil :install_dir => Gem.dir,
:source_index => Gem.source_index,
}.merge options }.merge options
@env_shebang = options[:env_shebang] @env_shebang = options[:env_shebang]
@ -78,6 +108,7 @@ class Gem::Installer
@wrappers = options[:wrappers] @wrappers = options[:wrappers]
@bin_dir = options[:bin_dir] @bin_dir = options[:bin_dir]
@development = options[:development] @development = options[:development]
@source_index = options[:source_index]
begin begin
@format = Gem::Format.from_file_by_path @gem, @security_policy @format = Gem::Format.from_file_by_path @gem, @security_policy
@ -85,30 +116,41 @@ class Gem::Installer
raise Gem::InstallError, "invalid gem format for #{@gem}" raise Gem::InstallError, "invalid gem format for #{@gem}"
end end
begin
FileUtils.mkdir_p @gem_home
rescue Errno::EACCESS, Errno::ENOTDIR
# We'll divert to ~/.gems below
end
if not File.writable? @gem_home or if not File.writable? @gem_home or
# TODO: Shouldn't have to test for existence of bindir; tests need it. # TODO: Shouldn't have to test for existence of bindir; tests need it.
(@gem_home.to_s == Gem.dir and File.exist? Gem.bindir and (@gem_home.to_s == Gem.dir and File.exist? Gem.bindir and
not File.writable? Gem.bindir) not File.writable? Gem.bindir) then
if options[:user_install] == false # You explicitly don't want to use ~ if options[:user_install] == false then # You don't want to use ~
raise Gem::FilePermissionError, @gem_home raise Gem::FilePermissionError, @gem_home
elsif options[:user_install].nil? elsif options[:user_install].nil? then
say "Warning: falling back to user-level install since #{@gem_home} and #{@bin_dir} aren't both writable." unless self.class.home_install_warning then
alert_warning "Installing to ~/.gem since #{@gem_home} and\n\t #{Gem.bindir} aren't both writable."
self.class.home_install_warning = true
end
end end
options[:user_install] = true options[:user_install] = true
end end
if options[:user_install] if options[:user_install] then
@gem_home = File.join(ENV['HOME'], '.gem') @gem_home = Gem.user_dir
user_bin_dir = File.join(@gem_home, 'gems', 'bin') user_bin_dir = File.join(@gem_home, 'bin')
if !ENV['PATH'].split(':').include?(user_bin_dir) unless ENV['PATH'].split(File::PATH_SEPARATOR).include? user_bin_dir then
say "You don't have #{user_bin_dir} in your PATH." unless self.class.path_warning then
say "You won't be able to run gem-installed executables until you add it." alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
self.class.path_warning = true
end
end end
Dir.mkdir @gem_home if ! File.directory? @gem_home FileUtils.mkdir_p @gem_home unless File.directory? @gem_home
# If it's still not writable, you've got issues. # If it's still not writable, you've got issues.
raise Gem::FilePermissionError, @gem_home if ! File.writable? @gem_home raise Gem::FilePermissionError, @gem_home unless File.writable? @gem_home
end end
@spec = @format.spec @spec = @format.spec
@ -157,6 +199,10 @@ class Gem::Installer
end end
end end
Gem.pre_install_hooks.each do |hook|
hook.call self
end
FileUtils.mkdir_p @gem_home unless File.directory? @gem_home FileUtils.mkdir_p @gem_home unless File.directory? @gem_home
Gem.ensure_gem_subdirectories @gem_home Gem.ensure_gem_subdirectories @gem_home
@ -181,7 +227,11 @@ class Gem::Installer
@spec.loaded_from = File.join(@gem_home, 'specifications', @spec.loaded_from = File.join(@gem_home, 'specifications',
"#{@spec.full_name}.gemspec") "#{@spec.full_name}.gemspec")
Gem.source_index.add_spec @spec @source_index.add_spec @spec
Gem.post_install_hooks.each do |hook|
hook.call self
end
return @spec return @spec
rescue Zlib::GzipFile::Error rescue Zlib::GzipFile::Error
@ -204,10 +254,10 @@ class Gem::Installer
end end
## ##
# True if the gems in Gem.source_index satisfy +dependency+. # True if the gems in the source_index satisfy +dependency+.
def installation_satisfies_dependency?(dependency) def installation_satisfies_dependency?(dependency)
Gem.source_index.find_name(dependency.name, dependency.version_requirements).size > 0 @source_index.find_name(dependency.name, dependency.version_requirements).size > 0
end end
## ##

Просмотреть файл

@ -109,6 +109,13 @@ module Gem::LocalRemoteOptions
end end
end end
##
# Is fetching of local and remote information enabled?
def both?
options[:domain] == :both
end
## ##
# Is local fetching enabled? # Is local fetching enabled?

Просмотреть файл

@ -46,17 +46,17 @@ class Gem::Package::TarReader
yield entry yield entry
skip = (512 - (size % 512)) % 512 skip = (512 - (size % 512)) % 512
pending = size - entry.bytes_read
if @io.respond_to? :seek then begin
# avoid reading... # avoid reading...
@io.seek(size - entry.bytes_read, IO::SEEK_CUR) @io.seek pending, IO::SEEK_CUR
else pending = 0
pending = size - entry.bytes_read rescue Errno::EINVAL, NameError
while pending > 0 do while pending > 0 do
bread = @io.read([pending, 4096].min).size bytes_read = @io.read([pending, 4096].min).size
raise UnexpectedEOF if @io.eof? raise UnexpectedEOF if @io.eof?
pending -= bread pending -= bytes_read
end end
end end

Просмотреть файл

@ -13,23 +13,6 @@ class Gem::Platform
attr_accessor :version attr_accessor :version
DEPRECATED_CONSTS = [
:DARWIN,
:LINUX_586,
:MSWIN32,
:PPC_DARWIN,
:WIN32,
:X86_LINUX
]
def self.const_missing(name) # TODO remove six months from 2007/12
if DEPRECATED_CONSTS.include? name then
raise NameError, "#{name} has been removed, use CURRENT instead"
else
super
end
end
def self.local def self.local
arch = Gem::ConfigMap[:arch] arch = Gem::ConfigMap[:arch]
arch = "#{arch}_60" if arch =~ /mswin32$/ arch = "#{arch}_60" if arch =~ /mswin32$/
@ -73,7 +56,7 @@ class Gem::Platform
else cpu else cpu
end end
if arch.length == 2 and arch.last =~ /^\d+$/ then # for command-line if arch.length == 2 and arch.last =~ /^\d+(\.\d+)?$/ then # for command-line
@os, @version = arch @os, @version = arch
return return
end end

Просмотреть файл

@ -78,7 +78,7 @@ class Gem::RemoteFetcher
if File.writable?(install_dir) if File.writable?(install_dir)
cache_dir = File.join install_dir, 'cache' cache_dir = File.join install_dir, 'cache'
else else
cache_dir = File.join(ENV['HOME'], '.gem', 'cache') cache_dir = File.join(Gem.user_dir, 'cache')
end end
gem_file_name = "#{spec.full_name}.gem" gem_file_name = "#{spec.full_name}.gem"
@ -93,7 +93,7 @@ class Gem::RemoteFetcher
scheme = nil if scheme =~ /^[a-z]$/i scheme = nil if scheme =~ /^[a-z]$/i
case scheme case scheme
when 'http' then when 'http', 'https' then
unless File.exist? local_gem_path then unless File.exist? local_gem_path then
begin begin
say "Downloading gem #{gem_file_name}" if say "Downloading gem #{gem_file_name}" if
@ -139,8 +139,8 @@ class Gem::RemoteFetcher
# Downloads +uri+ and returns it as a String. # Downloads +uri+ and returns it as a String.
def fetch_path(uri, mtime = nil, head = false) def fetch_path(uri, mtime = nil, head = false)
data = open_uri_or_path(uri, mtime, head) data = open_uri_or_path uri, mtime, head
data = Gem.gunzip data if uri.to_s =~ /gz$/ and not head data = Gem.gunzip data if data and not head and uri.to_s =~ /gz$/
data data
rescue FetchError rescue FetchError
raise raise
@ -216,8 +216,9 @@ class Gem::RemoteFetcher
connection = @connections[connection_id] connection = @connections[connection_id]
if uri.scheme == 'https' and not connection.started? then if uri.scheme == 'https' and not connection.started? then
http_obj.use_ssl = true require 'net/https'
http_obj.verify_mode = OpenSSL::SSL::VERIFY_NONE connection.use_ssl = true
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
end end
connection.start unless connection.started? connection.start unless connection.started?
@ -241,9 +242,10 @@ class Gem::RemoteFetcher
response = request uri, fetch_type, last_modified response = request uri, fetch_type, last_modified
case response case response
when Net::HTTPOK then when Net::HTTPOK, Net::HTTPNotModified then
head ? response : response.body head ? response : response.body
when Net::HTTPRedirection then when Net::HTTPMovedPermanently, Net::HTTPFound, Net::HTTPSeeOther,
Net::HTTPTemporaryRedirect then
raise FetchError.new('too many redirects', uri) if depth > 10 raise FetchError.new('too many redirects', uri) if depth > 10
open_uri_or_path(response['Location'], last_modified, head, depth + 1) open_uri_or_path(response['Location'], last_modified, head, depth + 1)
@ -274,6 +276,7 @@ class Gem::RemoteFetcher
request.add_field 'Keep-Alive', '30' request.add_field 'Keep-Alive', '30'
if last_modified then if last_modified then
last_modified = last_modified.utc
request.add_field 'If-Modified-Since', last_modified.rfc2822 request.add_field 'If-Modified-Since', last_modified.rfc2822
end end
@ -282,9 +285,6 @@ class Gem::RemoteFetcher
retried = false retried = false
bad_response = false bad_response = false
# HACK work around EOFError bug in Net::HTTP
# NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible
# to install gems.
begin begin
@requests[connection.object_id] += 1 @requests[connection.object_id] += 1
response = connection.request request response = connection.request request
@ -297,6 +297,9 @@ class Gem::RemoteFetcher
bad_response = true bad_response = true
retry retry
# HACK work around EOFError bug in Net::HTTP
# NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible
# to install gems.
rescue EOFError, Errno::ECONNABORTED, Errno::ECONNRESET rescue EOFError, Errno::ECONNABORTED, Errno::ECONNRESET
requests = @requests[connection.object_id] requests = @requests[connection.object_id]
say "connection reset after #{requests} requests, retrying" if say "connection reset after #{requests} requests, retrying" if

Просмотреть файл

@ -2,5 +2,5 @@
# This file is auto-generated by build scripts. # This file is auto-generated by build scripts.
# See: rake update_version # See: rake update_version
module Gem module Gem
RubyGemsVersion = '1.2.0.1824' RubyGemsVersion = '1.3.0'
end end

Просмотреть файл

@ -7,7 +7,9 @@
require 'rubygems' require 'rubygems'
require 'rubygems/user_interaction' require 'rubygems/user_interaction'
require 'rubygems/specification' require 'rubygems/specification'
require 'rubygems/spec_fetcher' module Gem
autoload(:SpecFetcher, 'rubygems/spec_fetcher')
end
## ##
# The SourceIndex object indexes all the gems available from a # The SourceIndex object indexes all the gems available from a
@ -80,8 +82,14 @@ class Gem::SourceIndex
def load_specification(file_name) def load_specification(file_name)
begin begin
spec_code = File.read(file_name).untaint spec_code = if RUBY_VERSION < '1.9' then
File.read file_name
else
File.read file_name, :encoding => 'UTF-8'
end.untaint
gemspec = eval spec_code, binding, file_name gemspec = eval spec_code, binding, file_name
if gemspec.is_a?(Gem::Specification) if gemspec.is_a?(Gem::Specification)
gemspec.loaded_from = file_name gemspec.loaded_from = file_name
return gemspec return gemspec
@ -93,7 +101,7 @@ class Gem::SourceIndex
alert_warning e alert_warning e
alert_warning spec_code alert_warning spec_code
rescue Exception => e rescue Exception => e
alert_warning(e.inspect.to_s + "\n" + spec_code) alert_warning "#{e.inspect}\n#{spec_code}"
alert_warning "Invalid .gemspec format in '#{file_name}'" alert_warning "Invalid .gemspec format in '#{file_name}'"
end end
return nil return nil
@ -230,7 +238,8 @@ class Gem::SourceIndex
# Find a gem by an exact match on the short name. # Find a gem by an exact match on the short name.
def find_name(gem_name, version_requirement = Gem::Requirement.default) def find_name(gem_name, version_requirement = Gem::Requirement.default)
search(/^#{gem_name}$/, version_requirement) dep = Gem::Dependency.new(/^#{gem_name}$/, version_requirement)
search dep
end end
## ##
@ -246,7 +255,13 @@ class Gem::SourceIndex
version_requirement = nil version_requirement = nil
only_platform = false only_platform = false
case gem_pattern # TODO warn after 2008/03, remove three months after # TODO - Remove support and warning for legacy arguments after 2008/11
unless Gem::Dependency === gem_pattern
warn "Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated"
warn "#{caller[0]} is outdated"
end
case gem_pattern
when Regexp then when Regexp then
version_requirement = platform_only || Gem::Requirement.default version_requirement = platform_only || Gem::Requirement.default
when Gem::Dependency then when Gem::Dependency then
@ -270,7 +285,7 @@ class Gem::SourceIndex
specs = @gems.values.select do |spec| specs = @gems.values.select do |spec|
spec.name =~ gem_pattern and spec.name =~ gem_pattern and
version_requirement.satisfied_by? spec.version version_requirement.satisfied_by? spec.version
end end
if only_platform then if only_platform then
@ -539,7 +554,7 @@ module Gem
# objects to load properly. # objects to load properly.
Cache = SourceIndex Cache = SourceIndex
# :starddoc: # :startdoc:
end end

Просмотреть файл

@ -284,6 +284,10 @@ class Gem::SourceInfoCache
cache_data.map do |source_uri, sic_entry| cache_data.map do |source_uri, sic_entry|
next unless Gem.sources.include? source_uri next unless Gem.sources.include? source_uri
# TODO - Remove this gunk after 2008/11
unless pattern.kind_of?(Gem::Dependency)
pattern = Gem::Dependency.new(pattern, Gem::Requirement.default)
end
sic_entry.source_index.search pattern, platform_only sic_entry.source_index.search pattern, platform_only
end.flatten.compact end.flatten.compact
end end
@ -300,6 +304,11 @@ class Gem::SourceInfoCache
cache_data.map do |source_uri, sic_entry| cache_data.map do |source_uri, sic_entry|
next unless Gem.sources.include? source_uri next unless Gem.sources.include? source_uri
# TODO - Remove this gunk after 2008/11
unless pattern.kind_of?(Gem::Dependency)
pattern = Gem::Dependency.new(pattern, Gem::Requirement.default)
end
sic_entry.source_index.search(pattern, only_platform).each do |spec| sic_entry.source_index.search(pattern, only_platform).each do |spec|
results << [spec, source_uri] results << [spec, source_uri]
end end

Просмотреть файл

@ -167,7 +167,7 @@ class Gem::SpecFetcher
if all and @specs.include? source_uri then if all and @specs.include? source_uri then
list[source_uri] = @specs[source_uri] list[source_uri] = @specs[source_uri]
elsif @latest_specs.include? source_uri then elsif not all and @latest_specs.include? source_uri then
list[source_uri] = @latest_specs[source_uri] list[source_uri] = @latest_specs[source_uri]
else else
specs = load_specs source_uri, file specs = load_specs source_uri, file
@ -182,6 +182,10 @@ class Gem::SpecFetcher
list list
end end
##
# Loads specs in +file+, fetching from +source_uri+ if the on-disk cache is
# out of date.
def load_specs(source_uri, file) def load_specs(source_uri, file)
file_name = "#{file}.#{Gem.marshal_version}" file_name = "#{file}.#{Gem.marshal_version}"
spec_path = source_uri + "#{file_name}.gz" spec_path = source_uri + "#{file_name}.gz"
@ -192,7 +196,7 @@ class Gem::SpecFetcher
if File.exist? local_file then if File.exist? local_file then
spec_dump = @fetcher.fetch_path spec_path, File.mtime(local_file) spec_dump = @fetcher.fetch_path spec_path, File.mtime(local_file)
if spec_dump.empty? then if spec_dump.nil? then
spec_dump = Gem.read_binary local_file spec_dump = Gem.read_binary local_file
else else
loaded = true loaded = true

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -34,16 +34,20 @@ class Gem::FakeFetcher
path = path.to_s path = path.to_s
@paths << path @paths << path
raise ArgumentError, 'need full URI' unless path =~ %r'^http://' raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
data = @data[path]
if data.nil? then unless @data.key? path then
raise Gem::RemoteFetcher::FetchError.new('no data', path) raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
end end
data = @data[path]
if data.respond_to?(:call) then if data.respond_to?(:call) then
data.call data.call
else else
data = Gem.gunzip data if path.to_s =~ /gz$/ unless data.empty? if path.to_s =~ /gz$/ and not data.nil? and not data.empty? then
data = Gem.gunzip data
end
data data
end end
end end
@ -51,13 +55,15 @@ class Gem::FakeFetcher
def fetch_size(path) def fetch_size(path)
path = path.to_s path = path.to_s
@paths << path @paths << path
raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
data = @data[path]
if data.nil? then raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", nil)
unless @data.key? path then
raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
end end
data = @data[path]
data.respond_to?(:call) ? data.call : data.length data.respond_to?(:call) ? data.call : data.length
end end

Просмотреть файл

@ -18,9 +18,23 @@ class Gem::Uninstaller
include Gem::UserInteraction include Gem::UserInteraction
## ##
# Constructs an Uninstaller instance # The directory a gem's executables will be installed into
#
# gem:: [String] The Gem name to uninstall attr_reader :bin_dir
##
# The gem repository the gem will be installed into
attr_reader :gem_home
##
# The Gem::Specification for the gem being uninstalled, only set during
# #uninstall_gem
attr_reader :spec
##
# Constructs an uninstaller that will uninstall +gem+
def initialize(gem, options = {}) def initialize(gem, options = {})
@gem = gem @gem = gem
@ -31,41 +45,62 @@ class Gem::Uninstaller
@force_all = options[:all] @force_all = options[:all]
@force_ignore = options[:ignore] @force_ignore = options[:ignore]
@bin_dir = options[:bin_dir] @bin_dir = options[:bin_dir]
spec_dir = File.join @gem_home, 'specifications'
@source_index = Gem::SourceIndex.from_gems_in spec_dir
end end
## ##
# Performs the uninstall of the Gem. This removes the spec, the # Performs the uninstall of the gem. This removes the spec, the Gem
# Gem directory, and the cached .gem file, # directory, and the cached .gem file.
def uninstall def uninstall
list = Gem.source_index.search(/^#{@gem}$/, @version) list = @source_index.find_name @gem, @version
if list.empty? then if list.empty? then
raise Gem::InstallError, "Unknown gem #{@gem} #{@version}" raise Gem::InstallError, "Unknown gem #{@gem} #{@version}"
elsif list.size > 1 && @force_all
remove_all(list.dup) elsif list.size > 1 and @force_all then
remove_executables(list.last) remove_all list.dup
elsif list.size > 1
say elsif list.size > 1 then
gem_names = list.collect {|gem| gem.full_name} + ["All versions"] gem_names = list.collect {|gem| gem.full_name} + ["All versions"]
gem_name, index =
choose_from_list("Select gem to uninstall:", gem_names) say
if index == list.size gem_name, index = choose_from_list "Select gem to uninstall:", gem_names
remove_all(list.dup)
remove_executables(list.last) if index == list.size then
elsif index >= 0 && index < list.size remove_all list.dup
to_remove = list[index] elsif index >= 0 && index < list.size then
remove(to_remove, list) uninstall_gem list[index], list.dup
remove_executables(to_remove)
else else
say "Error: must enter a number [1-#{list.size+1}]" say "Error: must enter a number [1-#{list.size+1}]"
end end
else else
remove(list[0], list.dup) uninstall_gem list.first, list.dup
remove_executables(list.last)
end end
end end
##
# Uninstalls gem +spec+
def uninstall_gem(spec, specs)
@spec = spec
Gem.pre_uninstall_hooks.each do |hook|
hook.call self
end
specs.each { |s| remove_executables s }
remove spec, specs
Gem.post_uninstall_hooks.each do |hook|
hook.call self
end
@spec = nil
end
## ##
# Removes installed executables and batch files (windows only) for # Removes installed executables and batch files (windows only) for
# +gemspec+. # +gemspec+.
@ -76,7 +111,7 @@ class Gem::Uninstaller
if gemspec.executables.size > 0 then if gemspec.executables.size > 0 then
bindir = @bin_dir ? @bin_dir : (Gem.bindir @gem_home) bindir = @bin_dir ? @bin_dir : (Gem.bindir @gem_home)
list = Gem.source_index.search(gemspec.name).delete_if { |spec| list = @source_index.find_name(gemspec.name).delete_if { |spec|
spec.version == gemspec.version spec.version == gemspec.version
} }
@ -118,7 +153,7 @@ class Gem::Uninstaller
# NOTE: removes uninstalled gems from +list+. # NOTE: removes uninstalled gems from +list+.
def remove_all(list) def remove_all(list)
list.dup.each { |spec| remove spec, list } list.dup.each { |spec| uninstall_gem spec, list }
end end
## ##
@ -185,8 +220,7 @@ class Gem::Uninstaller
def dependencies_ok?(spec) def dependencies_ok?(spec)
return true if @force_ignore return true if @force_ignore
source_index = Gem::SourceIndex.from_installed_gems deplist = Gem::DependencyList.from_source_index @source_index
deplist = Gem::DependencyList.from_source_index source_index
deplist.ok_to_remove?(spec.full_name) || ask_if_ok(spec) deplist.ok_to_remove?(spec.full_name) || ask_if_ok(spec)
end end

Просмотреть файл

@ -19,6 +19,10 @@ require 'rubygems/test_utilities'
require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui') require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui')
module Gem module Gem
def self.searcher=(searcher)
MUTEX.synchronize do @searcher = searcher end
end
def self.source_index=(si) def self.source_index=(si)
@@source_index = si @@source_index = si
end end
@ -26,7 +30,7 @@ module Gem
def self.win_platform=(val) def self.win_platform=(val)
@@win_platform = val @@win_platform = val
end end
module DefaultUserInteraction module DefaultUserInteraction
@ui = MockGemUi.new @ui = MockGemUi.new
end end
@ -89,6 +93,27 @@ class RubyGemTestCase < Test::Unit::TestCase
'private_key.pem') 'private_key.pem')
@public_cert = File.expand_path File.join(File.dirname(__FILE__), @public_cert = File.expand_path File.join(File.dirname(__FILE__),
'public_cert.pem') 'public_cert.pem')
Gem.post_install_hooks.clear
Gem.post_uninstall_hooks.clear
Gem.pre_install_hooks.clear
Gem.pre_uninstall_hooks.clear
Gem.post_install do |installer|
@post_install_hook_arg = installer
end
Gem.post_uninstall do |uninstaller|
@post_uninstall_hook_arg = uninstaller
end
Gem.pre_install do |installer|
@pre_install_hook_arg = installer
end
Gem.pre_uninstall do |uninstaller|
@pre_uninstall_hook_arg = uninstaller
end
end end
def teardown def teardown
@ -435,7 +460,15 @@ class RubyGemTestCase < Test::Unit::TestCase
end end
@@ruby = rubybin @@ruby = rubybin
@@rake = ENV["rake"] || (@@ruby + " " + File.expand_path("../../../bin/rake", __FILE__)) env_rake = ENV['rake']
ruby19_rake = @@ruby + " " + File.expand_path("../../../bin/rake", __FILE__)
@@rake = if env_rake then
ENV["rake"]
elsif File.exist? ruby19_rake then
ruby19_rake
else
'rake'
end
end end

Просмотреть файл

@ -12,8 +12,28 @@ require 'rubygems/user_interaction'
class MockGemUi < Gem::StreamUI class MockGemUi < Gem::StreamUI
class TermError < RuntimeError; end class TermError < RuntimeError; end
def initialize(input="") module TTY
super(StringIO.new(input), StringIO.new, StringIO.new)
attr_accessor :tty
def tty?()
@tty = true unless defined?(@tty)
@tty
end
end
def initialize(input = "")
ins = StringIO.new input
outs = StringIO.new
errs = StringIO.new
ins.extend TTY
outs.extend TTY
errs.extend TTY
super ins, outs, errs
@terminated = false @terminated = false
end end

Просмотреть файл

@ -45,7 +45,12 @@ class TestGem < RubyGemTestCase
def test_self_bindir_default_dir def test_self_bindir_default_dir
default = Gem.default_dir default = Gem.default_dir
bindir = (defined? RUBY_FRAMEWORK_VERSION) ? '/usr/bin' : Config::CONFIG['bindir'] bindir = if defined?(RUBY_FRAMEWORK_VERSION) then
'/usr/bin'
else
Config::CONFIG['bindir']
end
assert_equal bindir, Gem.bindir(default) assert_equal bindir, Gem.bindir(default)
assert_equal bindir, Gem.bindir(Pathname.new(default)) assert_equal bindir, Gem.bindir(Pathname.new(default))
end end
@ -218,6 +223,36 @@ class TestGem < RubyGemTestCase
Gem.ssl_available = orig_Gem_ssl_available Gem.ssl_available = orig_Gem_ssl_available
end end
def test_self_find_files
foo1 = quick_gem 'foo', '1' do |s|
s.files << 'lib/foo/discover.rb'
end
foo2 = quick_gem 'foo', '2' do |s|
s.files << 'lib/foo/discover.rb'
end
path = File.join 'gems', foo1.full_name, 'lib', 'foo', 'discover.rb'
write_file(path) { |fp| fp.puts "# #{path}" }
path = File.join 'gems', foo2.full_name, 'lib', 'foo', 'discover.rb'
write_file(path) { |fp| fp.puts "# #{path}" }
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
Gem.source_index = util_setup_spec_fetcher foo1, foo2
Gem.searcher = nil
expected = [
File.join(foo1.full_gem_path, 'lib', 'foo', 'discover.rb'),
File.join(foo2.full_gem_path, 'lib', 'foo', 'discover.rb'),
]
assert_equal expected, Gem.find_files('foo/discover').sort
end
def test_self_latest_load_paths def test_self_latest_load_paths
util_make_gems util_make_gems
@ -261,20 +296,21 @@ class TestGem < RubyGemTestCase
unless win_platform? unless win_platform?
def test_self_path_APPLE_GEM_HOME def test_self_path_APPLE_GEM_HOME
Gem.clear_paths Gem.clear_paths
Dir.mktmpdir("apple_gem_home") {|d| apple_gem_home = File.join @tempdir, 'apple_gem_home'
Gem.const_set :APPLE_GEM_HOME, d Gem.const_set :APPLE_GEM_HOME, apple_gem_home
assert Gem.path.include?(d)
} assert Gem.path.include?(apple_gem_home)
ensure ensure
Gem.send :remove_const, :APPLE_GEM_HOME Gem.send :remove_const, :APPLE_GEM_HOME
end end
def test_self_path_APPLE_GEM_HOME_GEM_PATH def test_self_path_APPLE_GEM_HOME_GEM_PATH
Gem.clear_paths Gem.clear_paths
ENV['GEM_PATH'] = @gemhome ENV['GEM_PATH'] = @gemhome
Gem.const_set :APPLE_GEM_HOME, '/tmp/apple_gem_home' apple_gem_home = File.join @tempdir, 'apple_gem_home'
Gem.const_set :APPLE_GEM_HOME, apple_gem_home
assert !Gem.path.include?('/tmp/apple_gem_home')
assert !Gem.path.include?(apple_gem_home)
ensure ensure
Gem.send :remove_const, :APPLE_GEM_HOME Gem.send :remove_const, :APPLE_GEM_HOME
end end
@ -291,7 +327,7 @@ class TestGem < RubyGemTestCase
assert_equal path_count + @additional.size, Gem.path.size, assert_equal path_count + @additional.size, Gem.path.size,
"extra path components: #{Gem.path[2..-1].inspect}" "extra path components: #{Gem.path[2..-1].inspect}"
assert_match Gem.dir, Gem.path.last assert_equal Gem.dir, Gem.path.last
end end
def test_self_path_duplicate def test_self_path_duplicate
@ -390,6 +426,44 @@ class TestGem < RubyGemTestCase
Gem.required_location("a", "code.rb", "= 2") Gem.required_location("a", "code.rb", "= 2")
end end
def test_self_ruby_escaping_spaces_in_path
orig_ruby = Gem.ruby
orig_bindir = Gem::ConfigMap[:bindir]
orig_ruby_install_name = Gem::ConfigMap[:ruby_install_name]
orig_exe_ext = Gem::ConfigMap[:EXEEXT]
Gem::ConfigMap[:bindir] = "C:/Ruby 1.8/bin"
Gem::ConfigMap[:ruby_install_name] = "ruby"
Gem::ConfigMap[:EXEEXT] = ".exe"
Gem.instance_variable_set("@ruby", nil)
assert_equal "\"C:/Ruby 1.8/bin/ruby.exe\"", Gem.ruby
ensure
Gem.instance_variable_set("@ruby", orig_ruby)
Gem::ConfigMap[:bindir] = orig_bindir
Gem::ConfigMap[:ruby_install_name] = orig_ruby_install_name
Gem::ConfigMap[:EXEEXT] = orig_exe_ext
end
def test_self_ruby_path_without_spaces
orig_ruby = Gem.ruby
orig_bindir = Gem::ConfigMap[:bindir]
orig_ruby_install_name = Gem::ConfigMap[:ruby_install_name]
orig_exe_ext = Gem::ConfigMap[:EXEEXT]
Gem::ConfigMap[:bindir] = "C:/Ruby18/bin"
Gem::ConfigMap[:ruby_install_name] = "ruby"
Gem::ConfigMap[:EXEEXT] = ".exe"
Gem.instance_variable_set("@ruby", nil)
assert_equal "C:/Ruby18/bin/ruby.exe", Gem.ruby
ensure
Gem.instance_variable_set("@ruby", orig_ruby)
Gem::ConfigMap[:bindir] = orig_bindir
Gem::ConfigMap[:ruby_install_name] = orig_ruby_install_name
Gem::ConfigMap[:EXEEXT] = orig_exe_ext
end
def test_self_ruby_version def test_self_ruby_version
version = RUBY_VERSION.dup version = RUBY_VERSION.dup
version << ".#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL version << ".#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
@ -430,6 +504,11 @@ class TestGem < RubyGemTestCase
assert_equal @additional + [Gem.dir], Gem.path assert_equal @additional + [Gem.dir], Gem.path
end end
def test_self_user_dir
assert_equal File.join(@userhome, '.gem', Gem.ruby_engine,
Gem::ConfigMap[:ruby_version]), Gem.user_dir
end
def test_self_user_home def test_self_user_home
if ENV['HOME'] then if ENV['HOME'] then
assert_equal ENV['HOME'], Gem.user_home assert_equal ENV['HOME'], Gem.user_home
@ -438,6 +517,28 @@ class TestGem < RubyGemTestCase
end end
end end
def test_self_user_home_user_drive_and_path
Gem.clear_paths
# safe-keep env variables
orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE']
orig_user_drive, orig_user_path = ENV['HOMEDRIVE'], ENV['HOMEPATH']
# prepare the environment
ENV.delete('HOME')
ENV.delete('USERPROFILE')
ENV['HOMEDRIVE'] = 'Z:'
ENV['HOMEPATH'] = '\\Users\\RubyUser'
assert_equal "Z:\\Users\\RubyUser", Gem.user_home
ensure
ENV['HOME'] = orig_home
ENV['USERPROFILE'] = orig_user_profile
ENV['USERDRIVE'] = orig_user_drive
ENV['USERPATH'] = orig_user_path
end
def util_ensure_gem_dirs def util_ensure_gem_dirs
Gem.ensure_gem_subdirectories @gemhome Gem.ensure_gem_subdirectories @gemhome
@additional.each do |dir| @additional.each do |dir|

Просмотреть файл

@ -25,7 +25,7 @@ class TestGemBuilder < RubyGemTestCase
def test_build_validates def test_build_validates
builder = Gem::Builder.new Gem::Specification.new builder = Gem::Builder.new Gem::Specification.new
assert_raise Gem::InvalidSpecificationException do assert_raises Gem::InvalidSpecificationException do
builder.build builder.build
end end
end end

Просмотреть файл

@ -31,7 +31,7 @@ class TestGemCommandManager < RubyGemTestCase
def test_run_interrupt def test_run_interrupt
use_ui @ui do use_ui @ui do
@command_manager.register_command :interrupt @command_manager.register_command :interrupt
assert_raise MockGemUi::TermError do assert_raises MockGemUi::TermError do
@command_manager.run 'interrupt' @command_manager.run 'interrupt'
end end
assert_equal '', ui.output assert_equal '', ui.output
@ -41,7 +41,7 @@ class TestGemCommandManager < RubyGemTestCase
def test_process_args_bad_arg def test_process_args_bad_arg
use_ui @ui do use_ui @ui do
assert_raise(MockGemUi::TermError) { assert_raises(MockGemUi::TermError) {
@command_manager.process_args("--bad-arg") @command_manager.process_args("--bad-arg")
} }
end end

Просмотреть файл

@ -199,7 +199,7 @@ ERROR: Only reverse dependencies for local gems are supported.
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
si.dump si.dump
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil @fetcher.data.delete "#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"
FileUtils.rm File.join(@gemhome, 'specifications', FileUtils.rm File.join(@gemhome, 'specifications',
"#{foo.full_name}.gemspec") "#{foo.full_name}.gemspec")

Просмотреть файл

@ -43,7 +43,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
orig_dir = Dir.pwd orig_dir = Dir.pwd
begin begin
Dir.chdir @tempdir Dir.chdir @tempdir
e = assert_raise Gem::SystemExitException do e = assert_raises Gem::SystemExitException do
@cmd.execute @cmd.execute
end end
assert_equal 0, e.exit_code assert_equal 0, e.exit_code
@ -65,7 +65,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
@cmd.options[:args] = %w[no_such_gem] @cmd.options[:args] = %w[no_such_gem]
use_ui @ui do use_ui @ui do
e = assert_raise Gem::SystemExitException do e = assert_raises Gem::SystemExitException do
@cmd.execute @cmd.execute
end end
assert_equal 2, e.exit_code assert_equal 2, e.exit_code
@ -91,7 +91,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
@cmd.options[:args] = %w[nonexistent] @cmd.options[:args] = %w[nonexistent]
use_ui @ui do use_ui @ui do
e = assert_raise Gem::SystemExitException do e = assert_raises Gem::SystemExitException do
@cmd.execute @cmd.execute
end end
assert_equal 2, e.exit_code assert_equal 2, e.exit_code
@ -114,7 +114,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
@cmd.options[:args] = [@a2.name] @cmd.options[:args] = [@a2.name]
use_ui @ui do use_ui @ui do
e = assert_raise Gem::SystemExitException do e = assert_raises Gem::SystemExitException do
@cmd.execute @cmd.execute
end end
assert_equal 0, e.exit_code assert_equal 0, e.exit_code
@ -146,7 +146,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
orig_dir = Dir.pwd orig_dir = Dir.pwd
begin begin
Dir.chdir @tempdir Dir.chdir @tempdir
e = assert_raise Gem::SystemExitException do e = assert_raises Gem::SystemExitException do
@cmd.execute @cmd.execute
end end
assert_equal 0, e.exit_code assert_equal 0, e.exit_code

Просмотреть файл

@ -0,0 +1,37 @@
require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/commands/list_command'
class TestGemCommandsListCommand < RubyGemTestCase
def setup
super
@cmd = Gem::Commands::ListCommand.new
util_setup_fake_fetcher
@si = util_setup_spec_fetcher @a1, @a2, @pl1
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
raise Gem::RemoteFetcher::FetchError
end
end
def test_execute_installed
@cmd.handle_options %w[c --installed]
e = assert_raise Gem::SystemExitException do
use_ui @ui do
@cmd.execute
end
end
assert_equal 0, e.exit_code
assert_equal "true\n", @ui.output
assert_equal '', @ui.error
end
end

Просмотреть файл

@ -0,0 +1,69 @@
require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/commands/lock_command'
class TestGemCommandsLockCommand < RubyGemTestCase
def setup
super
@a1 = quick_gem 'a', '1'
@b1 = quick_gem 'b', '1' do |s|
s.add_runtime_dependency 'a'
end
@d1 = quick_gem 'd', '1' do |s|
s.add_runtime_dependency 'z'
end
@cmd = Gem::Commands::LockCommand.new
end
def test_execute
@cmd.handle_options %w[b-1]
use_ui @ui do
@cmd.execute
end
expected = <<-EXPECTED
require 'rubygems'
gem 'b', '= 1'
gem 'a', '= 1'
EXPECTED
assert_equal expected, @ui.output
assert_equal '', @ui.error
end
def test_execute_missing_dependency
@cmd.handle_options %w[d-1]
use_ui @ui do
@cmd.execute
end
expected = <<-EXPECTED
require 'rubygems'
gem 'd', '= 1'
# Unable to satisfy 'z (>= 0, runtime)' from currently installed gems
EXPECTED
assert_equal expected, @ui.output
assert_equal '', @ui.error
end
def test_execute_strict
@cmd.handle_options %w[c-1 --strict]
e = assert_raise Gem::Exception do
use_ui @ui do
@cmd.execute
end
end
assert_equal 'Could not find gem c-1, try using the full name', e.message
end
end

Просмотреть файл

@ -180,7 +180,7 @@ pl (1)
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
si.dump si.dump
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil @fetcher.data.delete "#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"
@cmd.handle_options %w[-r] @cmd.handle_options %w[-r]
@ -265,6 +265,27 @@ pl (1)
assert_equal '', @ui.error assert_equal '', @ui.error
end end
def test_execute_local_notty
@cmd.handle_options %w[]
@ui.outs.tty = false
use_ui @ui do
@cmd.execute
end
expected = <<-EOF
a (2, 1)
a_evil (9)
b (2)
c (1.2)
pl (1)
EOF
assert_equal expected, @ui.output
assert_equal '', @ui.error
end
def test_execute_no_versions def test_execute_no_versions
@cmd.handle_options %w[-r --no-versions] @cmd.handle_options %w[-r --no-versions]
@ -284,5 +305,23 @@ pl
assert_equal '', @ui.error assert_equal '', @ui.error
end end
def test_execute_notty
@cmd.handle_options %w[-r]
@ui.outs.tty = false
use_ui @ui do
@cmd.execute
end
expected = <<-EOF
a (2)
pl (1)
EOF
assert_equal expected, @ui.output
assert_equal '', @ui.error
end
end end

Просмотреть файл

@ -0,0 +1,60 @@
require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require File.join(File.expand_path(File.dirname(__FILE__)),
'gem_installer_test_case')
require 'rubygems/commands/uninstall_command'
class TestGemCommandsUninstallCommand < GemInstallerTestCase
def setup
super
ui = MockGemUi.new
util_setup_gem ui
use_ui ui do
@installer.install
end
@cmd = Gem::Commands::UninstallCommand.new
@cmd.options[:executables] = true
@executable = File.join(@gemhome, 'bin', 'executable')
end
def test_execute_removes_executable
if win_platform?
assert_equal true, File.exist?(@executable)
else
assert_equal true, File.symlink?(@executable)
end
# Evil hack to prevent false removal success
FileUtils.rm_f @executable
File.open(@executable, "wb+") {|f| f.puts "binary"}
@cmd.options[:args] = Array(@spec.name)
use_ui @ui do
@cmd.execute
end
output = @ui.output.split "\n"
assert_match(/Removing executable/, output.shift)
assert_match(/Successfully uninstalled/, output.shift)
assert_equal false, File.exist?(@executable)
assert_nil output.shift, "UI output should have contained only two lines"
end
def test_execute_not_installed
@cmd.options[:args] = ["foo"]
e = assert_raise(Gem::InstallError) do
use_ui @ui do
@cmd.execute
end
end
assert_match(/\AUnknown gem foo >= 0$/, e.message)
output = @ui.output.split "\n"
assert output.empty?, "UI output should be empty after an uninstall error"
end
end

Просмотреть файл

@ -57,6 +57,9 @@ class TestGemConfigFile < RubyGemTestCase
fp.puts ":sources:" fp.puts ":sources:"
fp.puts " - http://more-gems.example.com" fp.puts " - http://more-gems.example.com"
fp.puts "install: --wrappers" fp.puts "install: --wrappers"
fp.puts ":gempath:"
fp.puts "- /usr/ruby/1.8/lib/ruby/gems/1.8"
fp.puts "- /var/ruby/1.8/gem_home"
end end
util_config_file util_config_file
@ -68,6 +71,8 @@ class TestGemConfigFile < RubyGemTestCase
assert_equal false, @cfg.update_sources assert_equal false, @cfg.update_sources
assert_equal %w[http://more-gems.example.com], Gem.sources assert_equal %w[http://more-gems.example.com], Gem.sources
assert_equal '--wrappers', @cfg[:install] assert_equal '--wrappers', @cfg[:install]
assert_equal(['/usr/ruby/1.8/lib/ruby/gems/1.8', '/var/ruby/1.8/gem_home'],
@cfg.path)
end end
def test_initialize_handle_arguments_config_file def test_initialize_handle_arguments_config_file

Просмотреть файл

@ -53,12 +53,13 @@ class TestGemExtConfigureBuilder < RubyGemTestCase
expected = %r(configure failed: expected = %r(configure failed:
#{Regexp.escape sh_prefix_configure}#{Regexp.escape @dest_path} #{Regexp.escape sh_prefix_configure}#{Regexp.escape @dest_path}
.*?: #{shell_error_msg}) .*?: #{shell_error_msg}
)
assert_match expected, error.message assert_match expected, error.message
assert_equal "#{sh_prefix_configure}#{@dest_path}", output.shift assert_equal "#{sh_prefix_configure}#{@dest_path}", output.shift
assert_match %r(#{shell_error_msg}\n), output.shift assert_match %r(#{shell_error_msg}), output.shift
assert_equal true, output.empty? assert_equal true, output.empty?
end end

Просмотреть файл

@ -32,6 +32,8 @@ class TestGemExtRakeBuilder < RubyGemTestCase
end end
end end
output = output.join "\n"
expected = [ expected = [
"#{@@ruby} mkrf_conf.rb", "#{@@ruby} mkrf_conf.rb",
"", "",
@ -39,7 +41,9 @@ class TestGemExtRakeBuilder < RubyGemTestCase
"(in #{realdir})\n" "(in #{realdir})\n"
] ]
assert_equal expected, output assert_no_match %r%^rake failed:%, output
assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, output
assert_match %r%^#{Regexp.escape @@rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, output
end end
def test_class_build_fail def test_class_build_fail
@ -69,7 +73,9 @@ rake failed:
#{@@rake} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path} #{@@rake} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}
EOF EOF
assert_equal expected, error.message.split("\n")[0..4].join("\n") assert_match %r%^rake failed:%, error.message
assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, error.message
assert_match %r%^#{Regexp.escape @@rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, error.message
end end
end end

Просмотреть файл

@ -5,10 +5,6 @@ require 'rubygems/gem_path_searcher'
class Gem::GemPathSearcher class Gem::GemPathSearcher
attr_accessor :gemspecs attr_accessor :gemspecs
attr_accessor :lib_dirs attr_accessor :lib_dirs
public :init_gemspecs
public :matching_file
public :lib_dirs_for
end end
class TestGemGemPathSearcher < RubyGemTestCase class TestGemGemPathSearcher < RubyGemTestCase
@ -40,6 +36,10 @@ class TestGemGemPathSearcher < RubyGemTestCase
assert_equal @foo1, @gps.find('foo') assert_equal @foo1, @gps.find('foo')
end end
def test_find_all
assert_equal [@foo1], @gps.find_all('foo')
end
def test_init_gemspecs def test_init_gemspecs
assert_equal [@bar2, @bar1, @foo2, @foo1], @gps.init_gemspecs assert_equal [@bar2, @bar1, @foo2, @foo1], @gps.init_gemspecs
end end
@ -51,9 +51,17 @@ class TestGemGemPathSearcher < RubyGemTestCase
assert_equal expected, lib_dirs assert_equal expected, lib_dirs
end end
def test_matching_file def test_matching_file_eh
assert !@gps.matching_file(@foo1, 'bar') assert !@gps.matching_file?(@foo1, 'bar')
assert @gps.matching_file(@foo1, 'foo') assert @gps.matching_file?(@foo1, 'foo')
end
def test_matching_files
assert_equal [], @gps.matching_files(@foo1, 'bar')
expected = File.join @foo1.full_gem_path, 'lib', 'foo.rb'
assert_equal [expected], @gps.matching_files(@foo1, 'foo')
end end
end end

Просмотреть файл

@ -41,8 +41,8 @@ class TestGemInstallUpdateOptions < GemInstallerTestCase
@installer = Gem::Installer.new @gem, @cmd.options @installer = Gem::Installer.new @gem, @cmd.options
@installer.install @installer.install
assert File.exist?(File.join(@userhome, '.gem', 'gems')) assert File.exist?(File.join(Gem.user_dir, 'gems'))
assert File.exist?(File.join(@userhome, '.gem', 'gems', assert File.exist?(File.join(Gem.user_dir, 'gems',
@spec.full_name)) @spec.full_name))
end end
@ -52,7 +52,7 @@ class TestGemInstallUpdateOptions < GemInstallerTestCase
File.chmod 0755, @userhome File.chmod 0755, @userhome
FileUtils.chmod 0000, @gemhome FileUtils.chmod 0000, @gemhome
assert_raise(Gem::FilePermissionError) do assert_raises(Gem::FilePermissionError) do
@installer = Gem::Installer.new @gem, @cmd.options @installer = Gem::Installer.new @gem, @cmd.options
end end
ensure ensure

Просмотреть файл

@ -70,7 +70,10 @@ load 'my_exec'
#{Gem.ruby}: No such file or directory -- extconf.rb (LoadError) #{Gem.ruby}: No such file or directory -- extconf.rb (LoadError)
EOF EOF
assert_equal expected, File.read(gem_make_out) assert_match %r%#{Regexp.escape Gem.ruby} extconf.rb%,
File.read(gem_make_out)
assert_match %r%#{Regexp.escape Gem.ruby}: No such file%,
File.read(gem_make_out)
end end
def test_build_extensions_unsupported def test_build_extensions_unsupported
@ -287,7 +290,7 @@ load 'my_exec'
Dir.mkdir util_inst_bindir Dir.mkdir util_inst_bindir
File.chmod 0000, util_inst_bindir File.chmod 0000, util_inst_bindir
assert_raise Gem::FilePermissionError do assert_raises Gem::FilePermissionError do
@installer.generate_bin @installer.generate_bin
end end
@ -372,7 +375,7 @@ load 'my_exec'
Dir.mkdir util_inst_bindir Dir.mkdir util_inst_bindir
File.chmod 0000, util_inst_bindir File.chmod 0000, util_inst_bindir
assert_raise Gem::FilePermissionError do assert_raises Gem::FilePermissionError do
@installer.generate_bin @installer.generate_bin
end end
@ -529,6 +532,16 @@ load 'my_exec'
Dir.mkdir util_inst_bindir Dir.mkdir util_inst_bindir
util_setup_gem util_setup_gem
cache_file = File.join @gemhome, 'cache', "#{@spec.full_name}.gem"
Gem.pre_install do |installer|
assert !File.exist?(cache_file), 'cache file should not exist yet'
end
Gem.post_install do |installer|
assert File.exist?(cache_file), 'cache file should exist'
end
build_rake_in do build_rake_in do
use_ui @ui do use_ui @ui do
assert_equal @spec, @installer.install assert_equal @spec, @installer.install
@ -552,6 +565,9 @@ load 'my_exec'
assert_equal spec_file, @spec.loaded_from assert_equal spec_file, @spec.loaded_from
assert File.exist?(spec_file) assert File.exist?(spec_file)
assert_same @installer, @pre_install_hook_arg
assert_same @installer, @post_install_hook_arg
end end
def test_install_bad_gem def test_install_bad_gem
@ -586,6 +602,29 @@ load 'my_exec'
end end
end end
def test_install_check_dependencies_install_dir
gemhome2 = "#{@gemhome}2"
@spec.add_dependency 'b'
b2 = quick_gem 'b', 2
FileUtils.mv @gemhome, gemhome2
Gem.source_index.gems.delete b2.full_name
source_index = Gem::SourceIndex.from_gems_in File.join(gemhome2,
'specifications')
util_setup_gem
@installer = Gem::Installer.new @gem, :install_dir => gemhome2,
:source_index => source_index
use_ui @ui do
@installer.install
end
assert File.exist?(File.join(gemhome2, 'gems', @spec.full_name))
end
def test_install_force def test_install_force
use_ui @ui do use_ui @ui do
installer = Gem::Installer.new old_ruby_required, :force => true installer = Gem::Installer.new old_ruby_required, :force => true
@ -641,13 +680,13 @@ load 'my_exec'
assert File.exist?(File.join(@gemhome, 'specifications', assert File.exist?(File.join(@gemhome, 'specifications',
"#{@spec.full_name}.gemspec")) "#{@spec.full_name}.gemspec"))
end end
unless win_platform? # File.chmod doesn't work unless win_platform? # File.chmod doesn't work
def test_install_user_local_fallback def test_install_user_local_fallback
Dir.mkdir util_inst_bindir Dir.mkdir util_inst_bindir
File.chmod 0755, @userhome File.chmod 0755, @userhome
File.chmod 0000, util_inst_bindir File.chmod 0000, util_inst_bindir
File.chmod 0000, Gem.dir File.chmod 0000, Gem.dir
install_dir = File.join @userhome, '.gem', 'gems', @spec.full_name
@spec.executables = ["executable"] @spec.executables = ["executable"]
build_rake_in do build_rake_in do
@ -656,9 +695,10 @@ load 'my_exec'
@installer.install @installer.install
end end
end end
assert File.exist?(File.join(install_dir, 'lib', 'code.rb')) assert File.exist?(File.join(Gem.user_dir, 'gems',
assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable')) @spec.full_name, 'lib', 'code.rb'))
assert File.exist?(File.join(Gem.user_dir, 'bin', 'executable'))
ensure ensure
File.chmod 0755, Gem.dir File.chmod 0755, Gem.dir
File.chmod 0755, util_inst_bindir File.chmod 0755, util_inst_bindir
@ -676,13 +716,13 @@ load 'my_exec'
@installer.install @installer.install
end end
end end
assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable')) assert File.exist?(File.join(Gem.user_dir, 'bin', 'executable'))
ensure ensure
File.chmod 0755, util_inst_bindir File.chmod 0755, util_inst_bindir
end end
end end
def test_install_with_message def test_install_with_message
@spec.post_install_message = 'I am a shiny gem!' @spec.post_install_message = 'I am a shiny gem!'

Просмотреть файл

@ -19,6 +19,18 @@ class TestGemLocalRemoteOptions < RubyGemTestCase
assert @cmd.handles?(args) assert @cmd.handles?(args)
end end
def test_both_eh
assert_equal false, @cmd.both?
@cmd.options[:domain] = :local
assert_equal false, @cmd.both?
@cmd.options[:domain] = :both
assert_equal true, @cmd.both?
end
def test_local_eh def test_local_eh
assert_equal false, @cmd.local? assert_equal false, @cmd.local?

Просмотреть файл

@ -62,19 +62,19 @@ class TestGemPackageTarHeader < TarTestCase
end end
def test_initialize_bad def test_initialize_bad
assert_raise ArgumentError do assert_raises ArgumentError do
Gem::Package::TarHeader.new :name => '', :size => '', :mode => '' Gem::Package::TarHeader.new :name => '', :size => '', :mode => ''
end end
assert_raise ArgumentError do assert_raises ArgumentError do
Gem::Package::TarHeader.new :name => '', :size => '', :prefix => '' Gem::Package::TarHeader.new :name => '', :size => '', :prefix => ''
end end
assert_raise ArgumentError do assert_raises ArgumentError do
Gem::Package::TarHeader.new :name => '', :prefix => '', :mode => '' Gem::Package::TarHeader.new :name => '', :prefix => '', :mode => ''
end end
assert_raise ArgumentError do assert_raises ArgumentError do
Gem::Package::TarHeader.new :prefix => '', :size => '', :mode => '' Gem::Package::TarHeader.new :prefix => '', :size => '', :mode => ''
end end
end end

Просмотреть файл

@ -5,19 +5,6 @@ require 'rbconfig'
class TestGemPlatform < RubyGemTestCase class TestGemPlatform < RubyGemTestCase
def test_self_const_missing
consts = [:DARWIN, :LINUX_586, :MSWIN32, :PPC_DARWIN, :WIN32, :X86_LINUX]
consts.each do |const|
e = assert_raise NameError do
Gem::Platform.const_missing const
end
assert_equal "#{const} has been removed, use CURRENT instead",
e.message
end
end
def test_self_local def test_self_local
util_set_arch 'i686-darwin8.10.1' util_set_arch 'i686-darwin8.10.1'
@ -105,6 +92,12 @@ class TestGemPlatform < RubyGemTestCase
platform = Gem::Platform.new 'i386-mswin32-80' platform = Gem::Platform.new 'i386-mswin32-80'
assert_equal expected, platform.to_a, 'i386-mswin32-80' assert_equal expected, platform.to_a, 'i386-mswin32-80'
expected = ['x86', 'solaris', '2.10']
platform = Gem::Platform.new 'i386-solaris-2.10'
assert_equal expected, platform.to_a, 'i386-solaris-2.10'
end end
def test_initialize_mswin32_vc6 def test_initialize_mswin32_vc6

Просмотреть файл

@ -268,15 +268,15 @@ gems:
ensure ensure
File.chmod 0755, File.join(@gemhome, 'cache') File.chmod 0755, File.join(@gemhome, 'cache')
end end
def test_download_read_only def test_download_read_only
File.chmod 0555, File.join(@gemhome, 'cache') File.chmod 0555, File.join(@gemhome, 'cache')
File.chmod 0555, File.join(@gemhome) File.chmod 0555, File.join(@gemhome)
fetcher = util_fuck_with_fetcher File.read(@a1_gem) fetcher = util_fuck_with_fetcher File.read(@a1_gem)
fetcher.download(@a1, 'http://gems.example.com') fetcher.download(@a1, 'http://gems.example.com')
assert File.exist?(File.join(@userhome, '.gem', assert File.exist?(File.join(Gem.user_dir, 'cache',
'cache', "#{@a1.full_name}.gem")) "#{@a1.full_name}.gem"))
ensure ensure
File.chmod 0755, File.join(@gemhome) File.chmod 0755, File.join(@gemhome)
File.chmod 0755, File.join(@gemhome, 'cache') File.chmod 0755, File.join(@gemhome, 'cache')
@ -391,6 +391,16 @@ gems:
assert_equal 'foo', fetcher.fetch_path(@uri + 'foo.gz') assert_equal 'foo', fetcher.fetch_path(@uri + 'foo.gz')
end end
def test_fetch_path_gzip_unmodified
fetcher = Gem::RemoteFetcher.new nil
def fetcher.open_uri_or_path(uri, mtime, head = nil)
nil
end
assert_equal nil, fetcher.fetch_path(@uri + 'foo.gz', Time.at(0))
end
def test_fetch_path_io_error def test_fetch_path_io_error
fetcher = Gem::RemoteFetcher.new nil fetcher = Gem::RemoteFetcher.new nil
@ -441,10 +451,10 @@ gems:
fetcher = Gem::RemoteFetcher.new nil fetcher = Gem::RemoteFetcher.new nil
def fetcher.open_uri_or_path(uri, mtime, head = nil) def fetcher.open_uri_or_path(uri, mtime, head = nil)
'' nil
end end
assert_equal '', fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0)) assert_equal nil, fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0))
end end
def test_get_proxy_from_env_empty def test_get_proxy_from_env_empty
@ -504,7 +514,7 @@ gems:
def conn.request(req) def conn.request(req)
unless defined? @requested then unless defined? @requested then
@requested = true @requested = true
res = Net::HTTPRedirection.new nil, 301, nil res = Net::HTTPMovedPermanently.new nil, 301, nil
res.add_field 'Location', 'http://gems.example.com/real_path' res.add_field 'Location', 'http://gems.example.com/real_path'
res res
else else
@ -528,7 +538,7 @@ gems:
conn = Object.new conn = Object.new
def conn.started?() true end def conn.started?() true end
def conn.request(req) def conn.request(req)
res = Net::HTTPRedirection.new nil, 301, nil res = Net::HTTPMovedPermanently.new nil, 301, nil
res.add_field 'Location', 'http://gems.example.com/redirect' res.add_field 'Location', 'http://gems.example.com/redirect'
res res
end end

Просмотреть файл

@ -64,6 +64,54 @@ class TestGemSourceIndex < RubyGemTestCase
assert_equal a1.author, spec.author assert_equal a1.author, spec.author
end end
def test_self_load_specification_utf_8
spec_dir = File.join @gemhome, 'specifications'
FileUtils.rm_r spec_dir
FileUtils.mkdir_p spec_dir
spec_file = File.join spec_dir, "utf-8.gemspec"
spec_data = <<-SPEC
Gem::Specification.new do |s|
s.name = %q{utf}
s.version = "8"
s.required_rubygems_version = Gem::Requirement.new(">= 0")
s.authors = ["\317\200"]
s.date = %q{2008-09-10}
s.description = %q{This is a test description}
s.email = %q{example@example.com}
s.has_rdoc = true
s.homepage = %q{http://example.com}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.2.0}
s.summary = %q{this is a summary}
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
else
end
else
end
end
SPEC
spec_data.force_encoding 'UTF-8'
File.open spec_file, 'w' do |io| io.write spec_data end
spec = Gem::SourceIndex.load_specification spec_file
pi = "\317\200"
pi.force_encoding 'UTF-8' if pi.respond_to? :force_encoding
assert_equal pi, spec.author
end if Gem.ruby_version > Gem::Version.new('1.9')
def test_self_load_specification_exception def test_self_load_specification_exception
spec_dir = File.join @gemhome, 'specifications' spec_dir = File.join @gemhome, 'specifications'
@ -437,6 +485,27 @@ WARNING: Invalid .gemspec format in '#{spec_file}'
assert_equal [], missing assert_equal [], missing
end end
def test_find_name
assert_equal [@a1, @a2], @source_index.find_name('a')
assert_equal [@a2], @source_index.find_name('a', '= 2')
assert_equal [], @source_index.find_name('bogusstring')
assert_equal [], @source_index.find_name('a', '= 3')
source_index = Gem::SourceIndex.new
source_index.add_spec @a1
source_index.add_spec @a2
assert_equal [@a1], source_index.find_name(@a1.name, '= 1')
r1 = Gem::Requirement.create '= 1'
assert_equal [@a1], source_index.find_name(@a1.name, r1)
end
def test_find_name_empty_cache
empty_source_index = Gem::SourceIndex.new({})
assert_equal [], empty_source_index.find_name("foo")
end
def test_latest_specs def test_latest_specs
p1_ruby = quick_gem 'p', '1' p1_ruby = quick_gem 'p', '1'
p1_platform = quick_gem 'p', '1' do |spec| p1_platform = quick_gem 'p', '1' do |spec|
@ -573,28 +642,12 @@ WARNING: Invalid .gemspec format in '#{spec_file}'
end end
def test_search def test_search
assert_equal [@a1, @a2, @a_evil9], @source_index.search('a') requirement = Gem::Requirement.create '= 9'
assert_equal [@a2], @source_index.search('a', '= 2') with_version = Gem::Dependency.new(/^a/, requirement)
assert_equal [@a_evil9], @source_index.search(with_version)
assert_equal [], @source_index.search('bogusstring') with_default = Gem::Dependency.new(/^a/, Gem::Requirement.default)
assert_equal [], @source_index.search('a', '= 3') assert_equal [@a1, @a2, @a_evil9], @source_index.search(with_default)
source_index = Gem::SourceIndex.new
source_index.add_spec @a1
source_index.add_spec @a2
assert_equal [@a1], source_index.search(@a1.name, '= 1')
r1 = Gem::Requirement.create '= 1'
assert_equal [@a1], source_index.search(@a1.name, r1)
dep = Gem::Dependency.new @a1.name, r1
assert_equal [@a1], source_index.search(dep)
end
def test_search_empty_cache
empty_source_index = Gem::SourceIndex.new({})
assert_equal [], empty_source_index.search("foo")
end end
def test_search_platform def test_search_platform

Просмотреть файл

@ -224,7 +224,8 @@ class TestGemSourceInfoCache < RubyGemTestCase
@sic.set_cache_data @gem_repo => sice @sic.set_cache_data @gem_repo => sice
latest = @sic.latest_cache_data latest = @sic.latest_cache_data
gems = latest[@gem_repo].source_index.search('a').map { |s| s.full_name } beginning_with_a = Gem::Dependency.new(/^a/, Gem::Requirement.default)
gems = latest[@gem_repo].source_index.search(beginning_with_a).map { |s| s.full_name }
assert_equal %w[a-2 a_evil-9], gems assert_equal %w[a-2 a_evil-9], gems
end end

Просмотреть файл

@ -67,7 +67,7 @@ class TestGemSpecFetcher < RubyGemTestCase
end end
def test_fetch_legacy_repo def test_fetch_legacy_repo
@fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] = nil @fetcher.data.delete "#{@gem_repo}specs.#{Gem.marshal_version}.gz"
@fetcher.data["#{@gem_repo}yaml"] = '' @fetcher.data["#{@gem_repo}yaml"] = ''
util_setup_source_info_cache @a1, @a2 util_setup_source_info_cache @a1, @a2
@ -259,6 +259,16 @@ RubyGems will revert to legacy indexes degrading performance.
assert_equal specs, cached_specs assert_equal specs, cached_specs
end end
def test_list_latest_all
specs = @sf.list false
assert_equal [@latest_specs], specs.values
specs = @sf.list true
assert_equal [@specs], specs.values, 'specs file not loaded'
end
def test_load_specs def test_load_specs
specs = @sf.load_specs @uri, 'specs' specs = @sf.load_specs @uri, 'specs'
@ -280,7 +290,7 @@ RubyGems will revert to legacy indexes degrading performance.
end end
def test_load_specs_cached def test_load_specs_cached
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = '' @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] = @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
' ' * Marshal.dump(@latest_specs).length ' ' * Marshal.dump(@latest_specs).length

Просмотреть файл

@ -500,7 +500,7 @@ end
end end
def test_has_rdoc_eh def test_has_rdoc_eh
assert_equal true, @a1.has_rdoc? assert @a1.has_rdoc?
end end
def test_hash def test_hash
@ -634,7 +634,10 @@ end
ruby_code = @a2.to_ruby ruby_code = @a2.to_ruby
expected = "Gem::Specification.new do |s| expected = <<-SPEC
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{a} s.name = %q{a}
s.version = \"2\" s.version = \"2\"
@ -654,7 +657,7 @@ end
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION} s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
if current_version >= 3 then if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<b>, [\"= 1\"]) s.add_runtime_dependency(%q<b>, [\"= 1\"])
else else
s.add_dependency(%q<b>, [\"= 1\"]) s.add_dependency(%q<b>, [\"= 1\"])
@ -663,7 +666,7 @@ end
s.add_dependency(%q<b>, [\"= 1\"]) s.add_dependency(%q<b>, [\"= 1\"])
end end
end end
" SPEC
assert_equal expected, ruby_code assert_equal expected, ruby_code
@ -679,7 +682,10 @@ end
local = Gem::Platform.local local = Gem::Platform.local
expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]" expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]"
expected = "Gem::Specification.new do |s| expected = <<-SPEC
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{a} s.name = %q{a}
s.version = \"1\" s.version = \"1\"
s.platform = Gem::Platform.new(#{expected_platform}) s.platform = Gem::Platform.new(#{expected_platform})
@ -706,7 +712,7 @@ end
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2 s.specification_version = 2
if current_version >= 3 then if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rake>, [\"> 0.4\"]) s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])
s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"]) s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"])
s.add_runtime_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"]) s.add_runtime_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
@ -721,7 +727,7 @@ end
s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"]) s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
end end
end end
" SPEC
assert_equal expected, ruby_code assert_equal expected, ruby_code

Просмотреть файл

@ -63,7 +63,7 @@ class TestGemStreamUI < RubyGemTestCase
@in.tty = false @in.tty = false
timeout(0.1) do timeout(0.1) do
assert_raise(Gem::OperationNotSupportedError) do assert_raises(Gem::OperationNotSupportedError) do
@sui.ask_yes_no("do coconuts migrate?") @sui.ask_yes_no("do coconuts migrate?")
end end
end end

Просмотреть файл

@ -62,5 +62,26 @@ class TestGemUninstaller < GemInstallerTestCase
assert_equal true, uninstaller.path_ok?(@spec) assert_equal true, uninstaller.path_ok?(@spec)
end end
def test_uninstall
uninstaller = Gem::Uninstaller.new @spec.name, :executables => true
gem_dir = File.join @gemhome, 'gems', @spec.full_name
Gem.pre_uninstall do
assert File.exist?(gem_dir), 'gem_dir should exist'
end
Gem.post_uninstall do
assert !File.exist?(gem_dir), 'gem_dir should not exist'
end
uninstaller.uninstall
assert !File.exist?(gem_dir)
assert_same uninstaller, @pre_uninstall_hook_arg
assert_same uninstaller, @post_uninstall_hook_arg
end
end end

Просмотреть файл

@ -107,7 +107,7 @@ class TestGemVersion < RubyGemTestCase
def test_illformed_requirements def test_illformed_requirements
[ ">>> 1.3.5", "> blah" ].each do |rq| [ ">>> 1.3.5", "> blah" ].each do |rq|
assert_raise(ArgumentError, "req [#{rq}] should fail") { assert_raises(ArgumentError, "req [#{rq}] should fail") {
Gem::Version::Requirement.new(rq) Gem::Version::Requirement.new(rq)
} }
end end