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

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
parent 788001a9c8
commit d478c7a734
60 changed files with 2174 additions and 1049 deletions

View file

@ -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>
* class.c (rb_make_metaclass): Made class of class of class

View file

@ -104,6 +104,11 @@ module Gem
@ruby = nil
@sources = []
@post_install_hooks = []
@post_uninstall_hooks = []
@pre_uninstall_hooks = []
@pre_install_hooks = []
##
# Activates an installed gem matching +gem+. The gem must satisfy
# +version_requirements+.
@ -244,7 +249,10 @@ module Gem
def self.clear_paths
@gem_home = nil
@gem_path = nil
@user_home = nil
@@source_index = nil
MUTEX.synchronize do
@searcher = nil
end
@ -261,9 +269,7 @@ module Gem
# The standard configuration object for gems.
def self.configuration
return @configuration if @configuration
require 'rubygems/config_file'
@configuration = Gem::ConfigFile.new []
@configuration ||= Gem::ConfigFile.new []
end
##
@ -336,6 +342,22 @@ module Gem
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.
#--
@ -353,7 +375,7 @@ module Gem
end
if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}"
return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
end
begin
@ -466,13 +488,11 @@ module Gem
##
# manage_gems is useless and deprecated. Don't call it anymore.
#--
# TODO warn w/ RubyGems 1.2.x release.
def self.manage_gems
#file, lineno = location_of_caller
def self.manage_gems # :nodoc:
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
##
@ -489,11 +509,7 @@ module Gem
@gem_path ||= nil
unless @gem_path then
paths = if ENV['GEM_PATH'] then
[ENV['GEM_PATH']]
else
[default_path]
end
paths = [ENV['GEM_PATH'] || Gem.configuration.path || default_path]
if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then
paths << APPLE_GEM_HOME
@ -523,6 +539,40 @@ module Gem
@platforms
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.
@ -600,6 +650,9 @@ module Gem
@ruby = File.join(ConfigMap[:bindir],
ConfigMap[:ruby_install_name])
@ruby << ConfigMap[:EXEEXT]
# escape string in case path to ruby executable contain spaces.
@ruby.sub!(/.*\s.*/m, '"\&"')
end
@ruby
@ -655,7 +708,13 @@ module Gem
end
@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
private_class_method :set_paths
@ -685,6 +744,14 @@ module Gem
@sources
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.
@ -731,6 +798,27 @@ module Gem
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:
alias cache source_index # an alias for the old name
@ -781,7 +869,10 @@ if defined?(RUBY_ENGINE) then
end
end
require 'rubygems/config_file'
if RUBY_VERSION < '1.9' then
require 'rubygems/custom_require'
end
Gem.clear_paths

View file

@ -51,7 +51,7 @@ class Gem::Commands::ContentsCommand < Gem::Command
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
say "Unable to find gem '#{gem}' in #{path_kind}"

View file

@ -18,6 +18,46 @@ class Gem::Commands::EnvironmentCommand < Gem::Command
return args.gsub(/^\s+/, '')
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:
"#{program_name} [arg]"
end

View file

@ -20,9 +20,9 @@ Some examples of 'gem' usage.
gem install --remote rake --test --rdoc --ri
* 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':

View file

@ -38,6 +38,19 @@ class Gem::Commands::InstallCommand < Gem::Command
"--no-test --install-dir #{Gem.dir}"
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:
"#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags"
end
@ -106,6 +119,8 @@ class Gem::Commands::InstallCommand < Gem::Command
installed_gems.each do |gem|
Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
end
Gem::DocManager.update_ri_cache
end
if options[:generate_rdoc] then

View file

@ -58,15 +58,15 @@ lock it down to the exact version.
end
def complain(message)
if options.strict then
raise message
if options[:strict] then
raise Gem::Exception, message
else
say "# #{message}"
end
end
def execute
say 'require "rubygems"'
say "require 'rubygems'"
locked = {}
@ -77,15 +77,20 @@ lock it down to the exact version.
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]
locked[spec.name] = true
spec.runtime_dependencies.each do |dep|
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
complain "Unable to satisfy '#{dep}' from currently installed gems."
complain "Unable to satisfy '#{dep}' from currently installed gems"
else
pending << candidates.last.full_name
end
@ -94,7 +99,11 @@ lock it down to the exact version.
end
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

View file

@ -19,7 +19,7 @@ class Gem::Commands::OutdatedCommand < Gem::Command
locals = Gem::SourceIndex.from_installed_gems
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}"
remotes = Gem::SpecFetcher.fetcher.fetch dep

View file

@ -57,7 +57,7 @@ revert the gem.
end
else
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])
end

View file

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

View file

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

View file

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

View file

@ -68,7 +68,7 @@ class Gem::Commands::UnpackCommand < Gem::Command
def get_path(gemname, version_req)
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

View file

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

View file

@ -3,10 +3,10 @@ require 'rubygems/gem_path_searcher'
class Gem::Commands::WhichCommand < Gem::Command
EXT = %w[.rb .rbw .so .dll] # HACK
EXT = %w[.rb .rbw .so .dll .bundle] # HACK
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
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
if paths.empty? then
say "Can't find #{arg}"
say "Can't find ruby library file or shared library #{arg}"
else
say paths
end
@ -84,3 +84,4 @@ class Gem::Commands::WhichCommand < Gem::Command
end
end

View file

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

View file

@ -1,36 +1,52 @@
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
%w[http://gems.rubyforge.org/]
end
##
# 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
if defined? RUBY_FRAMEWORK_VERSION then
File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
ConfigMap[:ruby_version]
elsif defined? RUBY_ENGINE then
File.join ConfigMap[:libdir], RUBY_ENGINE, 'gems',
ConfigMap[:ruby_version]
else
File.join ConfigMap[:libdir], 'ruby', 'gems', ConfigMap[:ruby_version]
File.join(ConfigMap[:libdir], ruby_engine, 'gems',
ConfigMap[:ruby_version])
end
end
# Default gem load path.
def self.default_path
[File.join(ENV['HOME'], '.gem'), default_dir]
##
# Path for gems in the user's home directory
def self.user_dir
File.join(Gem.user_home, '.gem', ruby_engine,
ConfigMap[:ruby_version])
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
baseruby = ConfigMap[:BASERUBY] || 'ruby'
ConfigMap[:RUBY_INSTALL_NAME].sub(baseruby, '%s') rescue '%s'
end
##
# The default directory for binaries
def self.default_bindir
if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
'/usr/bin'
@ -39,15 +55,30 @@ module Gem
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
File.join Gem.dir, 'source_cache'
end
# The default user-specific source info cache directory.
##
# The default user-specific source info cache directory
def self.default_user_source_cache_dir
File.join Gem.user_home, '.gem', 'source_cache'
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

View file

@ -38,9 +38,17 @@ class Gem::DependencyInstaller
# :ignore_dependencies:: Don't install any dependencies.
# :install_dir:: See Gem::Installer#install.
# :security_policy:: See Gem::Installer::new and Gem::Security.
# :user_install:: See Gem::Installer.new
# :wrappers:: See Gem::Installer::new
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
@bin_dir = options[:bin_dir]
@ -51,19 +59,13 @@ class Gem::DependencyInstaller
@format_executable = options[:format_executable]
@ignore_dependencies = options[:ignore_dependencies]
@security_policy = options[:security_policy]
@user_install = options[:user_install]
@wrappers = options[:wrappers]
@installed_gems = []
@install_dir = options[:install_dir] || Gem.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
##
@ -232,15 +234,17 @@ class Gem::DependencyInstaller
end
inst = Gem::Installer.new local_gem_path,
:env_shebang => @env_shebang,
:force => @force,
:format_executable => @format_executable,
:bin_dir => @bin_dir,
:development => @development,
:env_shebang => @env_shebang,
:force => @force,
:format_executable => @format_executable,
:ignore_dependencies => @ignore_dependencies,
:install_dir => @install_dir,
:security_policy => @security_policy,
:wrappers => @wrappers,
:bin_dir => @bin_dir,
:development => @development
:install_dir => @install_dir,
:security_policy => @security_policy,
:source_index => @source_index,
:user_install => @user_install,
:wrappers => @wrappers
spec = inst.install

View file

@ -5,132 +5,194 @@
#++
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.
#
# spec:: The Gem::Specification object representing the gem.
# rdoc_args:: Optional 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
@configured_args = []
def self.configured_args
@configured_args ||= []
end
def self.configured_args=(args)
case args
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
# Is the RDoc documentation installed?
def rdoc_installed?
return 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
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,
begin
require 'rdoc/rdoc'
rescue LoadError => e
raise Gem::DocumentError,
"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
def install_rdoc
rdoc_dir = File.join @doc_dir, 'rdoc'
FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
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}..."
run_rdoc '--op', rdoc_dir
def generate_rdoc
if @spec.has_rdoc then
setup_rdoc
install_rdoc
end
def install_ri
ri_dir = File.join @doc_dir, 'ri'
FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
end
FileUtils.rm_rf ri_dir
##
# Generate and install RDoc into the documentation directory
say "Installing ri documentation for #{@spec.full_name}..."
run_rdoc '--ri', '--op', ri_dir
def install_rdoc
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
def run_rdoc(*args)
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
FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
r = RDoc::RDoc.new
self.class.load_rdoc
end
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
##
# Remove RDoc and RI documentation
def uninstall_doc
raise Gem::FilePermissionError.new(@spec.installation_path) unless
File.writable? @spec.installation_path
def uninstall_doc
raise Gem::FilePermissionError.new(@spec.installation_path) unless
File.writable? @spec.installation_path
original_name = [
@spec.name, @spec.version, @spec.original_platform].join '-'
original_name = [
@spec.name, @spec.version, @spec.original_platform].join '-'
doc_dir = File.join @spec.installation_path, 'doc', @spec.full_name
unless File.directory? doc_dir then
@ -146,22 +208,7 @@ module Gem
end
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

View file

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

View file

@ -20,6 +20,7 @@ require 'rubygems/require_paths_builder'
# filesystem including unpacking the gem into its gem dir, installing the
# gemspec in the specifications dir, storing the cached gem in the cache dir,
# and installing either wrappers or symlinks for executables.
class Gem::Installer
##
@ -31,8 +32,36 @@ class Gem::Installer
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
##
# 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
# Defaults to use Ruby's program prefix and suffix.
@ -61,11 +90,12 @@ class Gem::Installer
@gem = gem
options = {
:force => false,
:install_dir => Gem.dir,
:exec_format => false,
:env_shebang => false,
:bin_dir => nil
:bin_dir => nil,
:env_shebang => false,
:exec_format => false,
:force => false,
:install_dir => Gem.dir,
:source_index => Gem.source_index,
}.merge options
@env_shebang = options[:env_shebang]
@ -78,6 +108,7 @@ class Gem::Installer
@wrappers = options[:wrappers]
@bin_dir = options[:bin_dir]
@development = options[:development]
@source_index = options[:source_index]
begin
@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}"
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
# 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
not File.writable? Gem.bindir)
if options[:user_install] == false # You explicitly don't want to use ~
(@gem_home.to_s == Gem.dir and File.exist? Gem.bindir and
not File.writable? Gem.bindir) then
if options[:user_install] == false then # You don't want to use ~
raise Gem::FilePermissionError, @gem_home
elsif options[:user_install].nil?
say "Warning: falling back to user-level install since #{@gem_home} and #{@bin_dir} aren't both writable."
elsif options[:user_install].nil? then
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
options[:user_install] = true
end
if options[:user_install]
@gem_home = File.join(ENV['HOME'], '.gem')
if options[:user_install] then
@gem_home = Gem.user_dir
user_bin_dir = File.join(@gem_home, 'gems', 'bin')
if !ENV['PATH'].split(':').include?(user_bin_dir)
say "You don't have #{user_bin_dir} in your PATH."
say "You won't be able to run gem-installed executables until you add it."
user_bin_dir = File.join(@gem_home, 'bin')
unless ENV['PATH'].split(File::PATH_SEPARATOR).include? user_bin_dir then
unless self.class.path_warning then
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
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.
raise Gem::FilePermissionError, @gem_home if ! File.writable? @gem_home
raise Gem::FilePermissionError, @gem_home unless File.writable? @gem_home
end
@spec = @format.spec
@ -157,6 +199,10 @@ class Gem::Installer
end
end
Gem.pre_install_hooks.each do |hook|
hook.call self
end
FileUtils.mkdir_p @gem_home unless File.directory? @gem_home
Gem.ensure_gem_subdirectories @gem_home
@ -181,7 +227,11 @@ class Gem::Installer
@spec.loaded_from = File.join(@gem_home, 'specifications',
"#{@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
rescue Zlib::GzipFile::Error
@ -204,10 +254,10 @@ class Gem::Installer
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)
Gem.source_index.find_name(dependency.name, dependency.version_requirements).size > 0
@source_index.find_name(dependency.name, dependency.version_requirements).size > 0
end
##

View file

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

View file

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

View file

@ -13,23 +13,6 @@ class Gem::Platform
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
arch = Gem::ConfigMap[:arch]
arch = "#{arch}_60" if arch =~ /mswin32$/
@ -73,7 +56,7 @@ class Gem::Platform
else cpu
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
return
end

View file

@ -78,7 +78,7 @@ class Gem::RemoteFetcher
if File.writable?(install_dir)
cache_dir = File.join install_dir, 'cache'
else
cache_dir = File.join(ENV['HOME'], '.gem', 'cache')
cache_dir = File.join(Gem.user_dir, 'cache')
end
gem_file_name = "#{spec.full_name}.gem"
@ -93,7 +93,7 @@ class Gem::RemoteFetcher
scheme = nil if scheme =~ /^[a-z]$/i
case scheme
when 'http' then
when 'http', 'https' then
unless File.exist? local_gem_path then
begin
say "Downloading gem #{gem_file_name}" if
@ -139,8 +139,8 @@ class Gem::RemoteFetcher
# Downloads +uri+ and returns it as a String.
def fetch_path(uri, mtime = nil, head = false)
data = open_uri_or_path(uri, mtime, head)
data = Gem.gunzip data if uri.to_s =~ /gz$/ and not head
data = open_uri_or_path uri, mtime, head
data = Gem.gunzip data if data and not head and uri.to_s =~ /gz$/
data
rescue FetchError
raise
@ -216,8 +216,9 @@ class Gem::RemoteFetcher
connection = @connections[connection_id]
if uri.scheme == 'https' and not connection.started? then
http_obj.use_ssl = true
http_obj.verify_mode = OpenSSL::SSL::VERIFY_NONE
require 'net/https'
connection.use_ssl = true
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
connection.start unless connection.started?
@ -241,9 +242,10 @@ class Gem::RemoteFetcher
response = request uri, fetch_type, last_modified
case response
when Net::HTTPOK then
when Net::HTTPOK, Net::HTTPNotModified then
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
open_uri_or_path(response['Location'], last_modified, head, depth + 1)
@ -274,6 +276,7 @@ class Gem::RemoteFetcher
request.add_field 'Keep-Alive', '30'
if last_modified then
last_modified = last_modified.utc
request.add_field 'If-Modified-Since', last_modified.rfc2822
end
@ -282,9 +285,6 @@ class Gem::RemoteFetcher
retried = 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
@requests[connection.object_id] += 1
response = connection.request request
@ -297,6 +297,9 @@ class Gem::RemoteFetcher
bad_response = true
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
requests = @requests[connection.object_id]
say "connection reset after #{requests} requests, retrying" if

View file

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

View file

@ -7,7 +7,9 @@
require 'rubygems'
require 'rubygems/user_interaction'
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
@ -80,8 +82,14 @@ class Gem::SourceIndex
def load_specification(file_name)
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
if gemspec.is_a?(Gem::Specification)
gemspec.loaded_from = file_name
return gemspec
@ -93,7 +101,7 @@ class Gem::SourceIndex
alert_warning e
alert_warning spec_code
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}'"
end
return nil
@ -230,7 +238,8 @@ class Gem::SourceIndex
# Find a gem by an exact match on the short name.
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
##
@ -246,7 +255,13 @@ class Gem::SourceIndex
version_requirement = nil
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
version_requirement = platform_only || Gem::Requirement.default
when Gem::Dependency then
@ -270,7 +285,7 @@ class Gem::SourceIndex
specs = @gems.values.select do |spec|
spec.name =~ gem_pattern and
version_requirement.satisfied_by? spec.version
version_requirement.satisfied_by? spec.version
end
if only_platform then
@ -539,7 +554,7 @@ module Gem
# objects to load properly.
Cache = SourceIndex
# :starddoc:
# :startdoc:
end

View file

@ -284,6 +284,10 @@ class Gem::SourceInfoCache
cache_data.map do |source_uri, sic_entry|
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
end.flatten.compact
end
@ -300,6 +304,11 @@ class Gem::SourceInfoCache
cache_data.map do |source_uri, sic_entry|
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|
results << [spec, source_uri]
end

View file

@ -167,7 +167,7 @@ class Gem::SpecFetcher
if all and @specs.include? source_uri then
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]
else
specs = load_specs source_uri, file
@ -182,6 +182,10 @@ class Gem::SpecFetcher
list
end
##
# Loads specs in +file+, fetching from +source_uri+ if the on-disk cache is
# out of date.
def load_specs(source_uri, file)
file_name = "#{file}.#{Gem.marshal_version}"
spec_path = source_uri + "#{file_name}.gz"
@ -192,7 +196,7 @@ class Gem::SpecFetcher
if File.exist? local_file then
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
else
loaded = true

File diff suppressed because it is too large Load diff

View file

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

View file

@ -18,9 +18,23 @@ class Gem::Uninstaller
include Gem::UserInteraction
##
# Constructs an Uninstaller instance
#
# gem:: [String] The Gem name to uninstall
# 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 uninstalled, only set during
# #uninstall_gem
attr_reader :spec
##
# Constructs an uninstaller that will uninstall +gem+
def initialize(gem, options = {})
@gem = gem
@ -31,41 +45,62 @@ class Gem::Uninstaller
@force_all = options[:all]
@force_ignore = options[:ignore]
@bin_dir = options[:bin_dir]
spec_dir = File.join @gem_home, 'specifications'
@source_index = Gem::SourceIndex.from_gems_in spec_dir
end
##
# Performs the uninstall of the Gem. This removes the spec, the
# Gem directory, and the cached .gem file,
# Performs the uninstall of the gem. This removes the spec, the Gem
# directory, and the cached .gem file.
def uninstall
list = Gem.source_index.search(/^#{@gem}$/, @version)
list = @source_index.find_name @gem, @version
if list.empty? then
raise Gem::InstallError, "Unknown gem #{@gem} #{@version}"
elsif list.size > 1 && @force_all
remove_all(list.dup)
remove_executables(list.last)
elsif list.size > 1
say
elsif list.size > 1 and @force_all then
remove_all list.dup
elsif list.size > 1 then
gem_names = list.collect {|gem| gem.full_name} + ["All versions"]
gem_name, index =
choose_from_list("Select gem to uninstall:", gem_names)
if index == list.size
remove_all(list.dup)
remove_executables(list.last)
elsif index >= 0 && index < list.size
to_remove = list[index]
remove(to_remove, list)
remove_executables(to_remove)
say
gem_name, index = choose_from_list "Select gem to uninstall:", gem_names
if index == list.size then
remove_all list.dup
elsif index >= 0 && index < list.size then
uninstall_gem list[index], list.dup
else
say "Error: must enter a number [1-#{list.size+1}]"
end
else
remove(list[0], list.dup)
remove_executables(list.last)
uninstall_gem list.first, list.dup
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
# +gemspec+.
@ -76,7 +111,7 @@ class Gem::Uninstaller
if gemspec.executables.size > 0 then
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
}
@ -118,7 +153,7 @@ class Gem::Uninstaller
# NOTE: removes uninstalled gems from +list+.
def remove_all(list)
list.dup.each { |spec| remove spec, list }
list.dup.each { |spec| uninstall_gem spec, list }
end
##
@ -185,8 +220,7 @@ class Gem::Uninstaller
def dependencies_ok?(spec)
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)
end

View file

@ -19,6 +19,10 @@ require 'rubygems/test_utilities'
require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui')
module Gem
def self.searcher=(searcher)
MUTEX.synchronize do @searcher = searcher end
end
def self.source_index=(si)
@@source_index = si
end
@ -26,7 +30,7 @@ module Gem
def self.win_platform=(val)
@@win_platform = val
end
module DefaultUserInteraction
@ui = MockGemUi.new
end
@ -89,6 +93,27 @@ class RubyGemTestCase < Test::Unit::TestCase
'private_key.pem')
@public_cert = File.expand_path File.join(File.dirname(__FILE__),
'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
def teardown
@ -435,7 +460,15 @@ class RubyGemTestCase < Test::Unit::TestCase
end
@@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

View file

@ -12,8 +12,28 @@ require 'rubygems/user_interaction'
class MockGemUi < Gem::StreamUI
class TermError < RuntimeError; end
def initialize(input="")
super(StringIO.new(input), StringIO.new, StringIO.new)
module TTY
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
end

View file

@ -45,7 +45,12 @@ class TestGem < RubyGemTestCase
def test_self_bindir_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(Pathname.new(default))
end
@ -218,6 +223,36 @@ class TestGem < RubyGemTestCase
Gem.ssl_available = orig_Gem_ssl_available
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
util_make_gems
@ -261,20 +296,21 @@ class TestGem < RubyGemTestCase
unless win_platform?
def test_self_path_APPLE_GEM_HOME
Gem.clear_paths
Dir.mktmpdir("apple_gem_home") {|d|
Gem.const_set :APPLE_GEM_HOME, d
assert Gem.path.include?(d)
}
apple_gem_home = File.join @tempdir, 'apple_gem_home'
Gem.const_set :APPLE_GEM_HOME, apple_gem_home
assert Gem.path.include?(apple_gem_home)
ensure
Gem.send :remove_const, :APPLE_GEM_HOME
end
def test_self_path_APPLE_GEM_HOME_GEM_PATH
Gem.clear_paths
ENV['GEM_PATH'] = @gemhome
Gem.const_set :APPLE_GEM_HOME, '/tmp/apple_gem_home'
assert !Gem.path.include?('/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?(apple_gem_home)
ensure
Gem.send :remove_const, :APPLE_GEM_HOME
end
@ -291,7 +327,7 @@ class TestGem < RubyGemTestCase
assert_equal path_count + @additional.size, Gem.path.size,
"extra path components: #{Gem.path[2..-1].inspect}"
assert_match Gem.dir, Gem.path.last
assert_equal Gem.dir, Gem.path.last
end
def test_self_path_duplicate
@ -390,6 +426,44 @@ class TestGem < RubyGemTestCase
Gem.required_location("a", "code.rb", "= 2")
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
version = RUBY_VERSION.dup
version << ".#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
@ -430,6 +504,11 @@ class TestGem < RubyGemTestCase
assert_equal @additional + [Gem.dir], Gem.path
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
if ENV['HOME'] then
assert_equal ENV['HOME'], Gem.user_home
@ -438,6 +517,28 @@ class TestGem < RubyGemTestCase
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
Gem.ensure_gem_subdirectories @gemhome
@additional.each do |dir|

View file

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

View file

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

View file

@ -199,7 +199,7 @@ ERROR: Only reverse dependencies for local gems are supported.
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
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',
"#{foo.full_name}.gemspec")

View file

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

View file

@ -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

View file

@ -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

View file

@ -180,7 +180,7 @@ pl (1)
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
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]
@ -265,6 +265,27 @@ pl (1)
assert_equal '', @ui.error
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
@cmd.handle_options %w[-r --no-versions]
@ -284,5 +305,23 @@ pl
assert_equal '', @ui.error
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

View file

@ -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

View file

@ -57,6 +57,9 @@ class TestGemConfigFile < RubyGemTestCase
fp.puts ":sources:"
fp.puts " - http://more-gems.example.com"
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
util_config_file
@ -68,6 +71,8 @@ class TestGemConfigFile < RubyGemTestCase
assert_equal false, @cfg.update_sources
assert_equal %w[http://more-gems.example.com], Gem.sources
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
def test_initialize_handle_arguments_config_file

View file

@ -53,12 +53,13 @@ class TestGemExtConfigureBuilder < RubyGemTestCase
expected = %r(configure failed:
#{Regexp.escape sh_prefix_configure}#{Regexp.escape @dest_path}
.*?: #{shell_error_msg})
.*?: #{shell_error_msg}
)
assert_match expected, error.message
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?
end

View file

@ -32,6 +32,8 @@ class TestGemExtRakeBuilder < RubyGemTestCase
end
end
output = output.join "\n"
expected = [
"#{@@ruby} mkrf_conf.rb",
"",
@ -39,7 +41,9 @@ class TestGemExtRakeBuilder < RubyGemTestCase
"(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
def test_class_build_fail
@ -69,7 +73,9 @@ rake failed:
#{@@rake} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}
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

View file

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

View file

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

View file

@ -70,7 +70,10 @@ load 'my_exec'
#{Gem.ruby}: No such file or directory -- extconf.rb (LoadError)
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
def test_build_extensions_unsupported
@ -287,7 +290,7 @@ load 'my_exec'
Dir.mkdir util_inst_bindir
File.chmod 0000, util_inst_bindir
assert_raise Gem::FilePermissionError do
assert_raises Gem::FilePermissionError do
@installer.generate_bin
end
@ -372,7 +375,7 @@ load 'my_exec'
Dir.mkdir util_inst_bindir
File.chmod 0000, util_inst_bindir
assert_raise Gem::FilePermissionError do
assert_raises Gem::FilePermissionError do
@installer.generate_bin
end
@ -529,6 +532,16 @@ load 'my_exec'
Dir.mkdir util_inst_bindir
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
use_ui @ui do
assert_equal @spec, @installer.install
@ -552,6 +565,9 @@ load 'my_exec'
assert_equal spec_file, @spec.loaded_from
assert File.exist?(spec_file)
assert_same @installer, @pre_install_hook_arg
assert_same @installer, @post_install_hook_arg
end
def test_install_bad_gem
@ -586,6 +602,29 @@ load 'my_exec'
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
use_ui @ui do
installer = Gem::Installer.new old_ruby_required, :force => true
@ -641,13 +680,13 @@ load 'my_exec'
assert File.exist?(File.join(@gemhome, 'specifications',
"#{@spec.full_name}.gemspec"))
end
unless win_platform? # File.chmod doesn't work
def test_install_user_local_fallback
Dir.mkdir util_inst_bindir
File.chmod 0755, @userhome
File.chmod 0000, util_inst_bindir
File.chmod 0000, Gem.dir
install_dir = File.join @userhome, '.gem', 'gems', @spec.full_name
@spec.executables = ["executable"]
build_rake_in do
@ -656,9 +695,10 @@ load 'my_exec'
@installer.install
end
end
assert File.exist?(File.join(install_dir, 'lib', 'code.rb'))
assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable'))
assert File.exist?(File.join(Gem.user_dir, 'gems',
@spec.full_name, 'lib', 'code.rb'))
assert File.exist?(File.join(Gem.user_dir, 'bin', 'executable'))
ensure
File.chmod 0755, Gem.dir
File.chmod 0755, util_inst_bindir
@ -676,13 +716,13 @@ load 'my_exec'
@installer.install
end
end
assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable'))
assert File.exist?(File.join(Gem.user_dir, 'bin', 'executable'))
ensure
File.chmod 0755, util_inst_bindir
end
end
def test_install_with_message
@spec.post_install_message = 'I am a shiny gem!'

View file

@ -19,6 +19,18 @@ class TestGemLocalRemoteOptions < RubyGemTestCase
assert @cmd.handles?(args)
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
assert_equal false, @cmd.local?

View file

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

View file

@ -5,19 +5,6 @@ require 'rbconfig'
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
util_set_arch 'i686-darwin8.10.1'
@ -105,6 +92,12 @@ class TestGemPlatform < RubyGemTestCase
platform = Gem::Platform.new '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
def test_initialize_mswin32_vc6

View file

@ -268,15 +268,15 @@ gems:
ensure
File.chmod 0755, File.join(@gemhome, 'cache')
end
def test_download_read_only
File.chmod 0555, File.join(@gemhome, 'cache')
File.chmod 0555, File.join(@gemhome)
fetcher = util_fuck_with_fetcher File.read(@a1_gem)
fetcher.download(@a1, 'http://gems.example.com')
assert File.exist?(File.join(@userhome, '.gem',
'cache', "#{@a1.full_name}.gem"))
assert File.exist?(File.join(Gem.user_dir, 'cache',
"#{@a1.full_name}.gem"))
ensure
File.chmod 0755, File.join(@gemhome)
File.chmod 0755, File.join(@gemhome, 'cache')
@ -391,6 +391,16 @@ gems:
assert_equal 'foo', fetcher.fetch_path(@uri + 'foo.gz')
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
fetcher = Gem::RemoteFetcher.new nil
@ -441,10 +451,10 @@ gems:
fetcher = Gem::RemoteFetcher.new nil
def fetcher.open_uri_or_path(uri, mtime, head = nil)
''
nil
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
def test_get_proxy_from_env_empty
@ -504,7 +514,7 @@ gems:
def conn.request(req)
unless defined? @requested then
@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
else
@ -528,7 +538,7 @@ gems:
conn = Object.new
def conn.started?() true end
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
end

View file

@ -64,6 +64,54 @@ class TestGemSourceIndex < RubyGemTestCase
assert_equal a1.author, spec.author
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
spec_dir = File.join @gemhome, 'specifications'
@ -437,6 +485,27 @@ WARNING: Invalid .gemspec format in '#{spec_file}'
assert_equal [], missing
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
p1_ruby = quick_gem 'p', '1'
p1_platform = quick_gem 'p', '1' do |spec|
@ -573,28 +642,12 @@ WARNING: Invalid .gemspec format in '#{spec_file}'
end
def test_search
assert_equal [@a1, @a2, @a_evil9], @source_index.search('a')
assert_equal [@a2], @source_index.search('a', '= 2')
requirement = Gem::Requirement.create '= 9'
with_version = Gem::Dependency.new(/^a/, requirement)
assert_equal [@a_evil9], @source_index.search(with_version)
assert_equal [], @source_index.search('bogusstring')
assert_equal [], @source_index.search('a', '= 3')
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")
with_default = Gem::Dependency.new(/^a/, Gem::Requirement.default)
assert_equal [@a1, @a2, @a_evil9], @source_index.search(with_default)
end
def test_search_platform

View file

@ -224,7 +224,8 @@ class TestGemSourceInfoCache < RubyGemTestCase
@sic.set_cache_data @gem_repo => sice
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
end

View file

@ -67,7 +67,7 @@ class TestGemSpecFetcher < RubyGemTestCase
end
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"] = ''
util_setup_source_info_cache @a1, @a2
@ -259,6 +259,16 @@ RubyGems will revert to legacy indexes degrading performance.
assert_equal specs, cached_specs
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
specs = @sf.load_specs @uri, 'specs'
@ -280,7 +290,7 @@ RubyGems will revert to legacy indexes degrading performance.
end
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}"] =
' ' * Marshal.dump(@latest_specs).length

View file

@ -500,7 +500,7 @@ end
end
def test_has_rdoc_eh
assert_equal true, @a1.has_rdoc?
assert @a1.has_rdoc?
end
def test_hash
@ -634,7 +634,10 @@ end
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.version = \"2\"
@ -654,7 +657,7 @@ end
current_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\"])
else
s.add_dependency(%q<b>, [\"= 1\"])
@ -663,7 +666,7 @@ end
s.add_dependency(%q<b>, [\"= 1\"])
end
end
"
SPEC
assert_equal expected, ruby_code
@ -679,7 +682,10 @@ end
local = Gem::Platform.local
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.version = \"1\"
s.platform = Gem::Platform.new(#{expected_platform})
@ -706,7 +712,7 @@ end
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
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<jabber4r>, [\"> 0.0.0\"])
s.add_runtime_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
@ -721,7 +727,7 @@ end
s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
end
end
"
SPEC
assert_equal expected, ruby_code

View file

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

View file

@ -62,5 +62,26 @@ class TestGemUninstaller < GemInstallerTestCase
assert_equal true, uninstaller.path_ok?(@spec)
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

View file

@ -107,7 +107,7 @@ class TestGemVersion < RubyGemTestCase
def test_illformed_requirements
[ ">>> 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)
}
end