* lib/rubygems: Import RubyGems from master as of commit b165260
* test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
66cc0fa4ab
commit
4c2304f000
@ -1,3 +1,8 @@
|
|||||||
|
Tue Jul 23 07:44:59 2013 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* lib/rubygems: Import RubyGems from master as of commit b165260
|
||||||
|
* test/rubygems: ditto.
|
||||||
|
|
||||||
Tue Jul 23 07:14:31 2013 Tanaka Akira <akr@fsij.org>
|
Tue Jul 23 07:14:31 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* bignum.c (bary_mulsub_1xN): New function.
|
* bignum.c (bary_mulsub_1xN): New function.
|
||||||
|
@ -446,18 +446,48 @@ module Gem
|
|||||||
# $LOAD_PATH for files as well as gems.
|
# $LOAD_PATH for files as well as gems.
|
||||||
#
|
#
|
||||||
# Note that find_files will return all files even if they are from different
|
# Note that find_files will return all files even if they are from different
|
||||||
# versions of the same gem.
|
# versions of the same gem. See also find_latest_files
|
||||||
|
|
||||||
def self.find_files(glob, check_load_path=true)
|
def self.find_files(glob, check_load_path=true)
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
if check_load_path
|
files = find_files_from_load_path glob if check_load_path
|
||||||
files = $LOAD_PATH.map { |load_path|
|
|
||||||
|
files.concat Gem::Specification.map { |spec|
|
||||||
|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
|
||||||
|
}.flatten
|
||||||
|
|
||||||
|
# $LOAD_PATH might contain duplicate entries or reference
|
||||||
|
# the spec dirs directly, so we prune.
|
||||||
|
files.uniq! if check_load_path
|
||||||
|
|
||||||
|
return files
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.find_files_from_load_path glob # :nodoc:
|
||||||
|
$LOAD_PATH.map { |load_path|
|
||||||
Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
|
Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
|
||||||
}.flatten.select { |file| File.file? file.untaint }
|
}.flatten.select { |file| File.file? file.untaint }
|
||||||
end
|
end
|
||||||
|
|
||||||
files.concat Gem::Specification.map { |spec|
|
##
|
||||||
|
# Returns a list of paths matching +glob+ from the latest gems that can be
|
||||||
|
# used by a gem to pick up features from other gems. For example:
|
||||||
|
#
|
||||||
|
# Gem.find_latest_files('rdoc/discover').each do |path| load path end
|
||||||
|
#
|
||||||
|
# if +check_load_path+ is true (the default), then find_latest_files also
|
||||||
|
# searches $LOAD_PATH for files as well as gems.
|
||||||
|
#
|
||||||
|
# Unlike find_files, find_latest_files will return only files from the
|
||||||
|
# latest version of a gem.
|
||||||
|
|
||||||
|
def self.find_latest_files(glob, check_load_path=true)
|
||||||
|
files = []
|
||||||
|
|
||||||
|
files = find_files_from_load_path glob if check_load_path
|
||||||
|
|
||||||
|
files.concat Gem::Specification.latest_specs(true).map { |spec|
|
||||||
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
|
||||||
}.flatten
|
}.flatten
|
||||||
|
|
||||||
@ -947,7 +977,7 @@ module Gem
|
|||||||
##
|
##
|
||||||
# Load +plugins+ as Ruby files
|
# Load +plugins+ as Ruby files
|
||||||
|
|
||||||
def self.load_plugin_files(plugins)
|
def self.load_plugin_files plugins # :nodoc:
|
||||||
plugins.each do |plugin|
|
plugins.each do |plugin|
|
||||||
|
|
||||||
# Skip older versions of the GemCutter plugin: Its commands are in
|
# Skip older versions of the GemCutter plugin: Its commands are in
|
||||||
@ -965,10 +995,16 @@ module Gem
|
|||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Find all 'rubygems_plugin' files in installed gems and load them
|
# Find the 'rubygems_plugin' files in the latest installed gems and load
|
||||||
|
# them
|
||||||
|
|
||||||
def self.load_plugins
|
def self.load_plugins
|
||||||
|
# Remove this env var by at least 3.0
|
||||||
|
if ENV['RUBYGEMS_LOAD_ALL_PLUGINS']
|
||||||
load_plugin_files find_files('rubygems_plugin', false)
|
load_plugin_files find_files('rubygems_plugin', false)
|
||||||
|
else
|
||||||
|
load_plugin_files find_latest_files('rubygems_plugin', false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -33,6 +33,39 @@ class Gem::CommandManager
|
|||||||
|
|
||||||
include Gem::UserInteraction
|
include Gem::UserInteraction
|
||||||
|
|
||||||
|
BUILTIN_COMMANDS = [ # :nodoc:
|
||||||
|
:build,
|
||||||
|
:cert,
|
||||||
|
:check,
|
||||||
|
:cleanup,
|
||||||
|
:contents,
|
||||||
|
:dependency,
|
||||||
|
:environment,
|
||||||
|
:fetch,
|
||||||
|
:generate_index,
|
||||||
|
:help,
|
||||||
|
:install,
|
||||||
|
:list,
|
||||||
|
:lock,
|
||||||
|
:mirror,
|
||||||
|
:outdated,
|
||||||
|
:owner,
|
||||||
|
:pristine,
|
||||||
|
:push,
|
||||||
|
:query,
|
||||||
|
:rdoc,
|
||||||
|
:search,
|
||||||
|
:server,
|
||||||
|
:sources,
|
||||||
|
:specification,
|
||||||
|
:stale,
|
||||||
|
:uninstall,
|
||||||
|
:unpack,
|
||||||
|
:update,
|
||||||
|
:which,
|
||||||
|
:yank,
|
||||||
|
]
|
||||||
|
|
||||||
##
|
##
|
||||||
# Return the authoritative instance of the command manager.
|
# Return the authoritative instance of the command manager.
|
||||||
|
|
||||||
@ -61,36 +94,10 @@ class Gem::CommandManager
|
|||||||
def initialize
|
def initialize
|
||||||
require 'timeout'
|
require 'timeout'
|
||||||
@commands = {}
|
@commands = {}
|
||||||
register_command :build
|
|
||||||
register_command :cert
|
BUILTIN_COMMANDS.each do |name|
|
||||||
register_command :check
|
register_command name
|
||||||
register_command :cleanup
|
end
|
||||||
register_command :contents
|
|
||||||
register_command :dependency
|
|
||||||
register_command :environment
|
|
||||||
register_command :fetch
|
|
||||||
register_command :generate_index
|
|
||||||
register_command :help
|
|
||||||
register_command :install
|
|
||||||
register_command :list
|
|
||||||
register_command :lock
|
|
||||||
register_command :mirror
|
|
||||||
register_command :outdated
|
|
||||||
register_command :owner
|
|
||||||
register_command :pristine
|
|
||||||
register_command :push
|
|
||||||
register_command :query
|
|
||||||
register_command :rdoc
|
|
||||||
register_command :search
|
|
||||||
register_command :server
|
|
||||||
register_command :sources
|
|
||||||
register_command :specification
|
|
||||||
register_command :stale
|
|
||||||
register_command :uninstall
|
|
||||||
register_command :unpack
|
|
||||||
register_command :update
|
|
||||||
register_command :which
|
|
||||||
register_command :yank
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -132,14 +139,6 @@ class Gem::CommandManager
|
|||||||
alert_error "While executing gem ... (#{ex.class})\n #{ex.to_s}"
|
alert_error "While executing gem ... (#{ex.class})\n #{ex.to_s}"
|
||||||
ui.backtrace ex
|
ui.backtrace ex
|
||||||
|
|
||||||
if Gem.configuration.really_verbose and \
|
|
||||||
ex.kind_of?(Gem::Exception) and ex.source_exception
|
|
||||||
e = ex.source_exception
|
|
||||||
|
|
||||||
ui.errs.puts "Because of: (#{e.class})\n #{e.to_s}"
|
|
||||||
ui.backtrace e
|
|
||||||
end
|
|
||||||
|
|
||||||
terminate_interaction(1)
|
terminate_interaction(1)
|
||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
alert_error "Interrupted"
|
alert_error "Interrupted"
|
||||||
@ -147,8 +146,6 @@ class Gem::CommandManager
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process_args(args, build_args=nil)
|
def process_args(args, build_args=nil)
|
||||||
args = args.to_str.split(/\s+/) if args.respond_to?(:to_str)
|
|
||||||
|
|
||||||
if args.empty? then
|
if args.empty? then
|
||||||
say Gem::Command::HELP
|
say Gem::Command::HELP
|
||||||
terminate_interaction 1
|
terminate_interaction 1
|
||||||
|
@ -85,44 +85,52 @@ class Gem::Commands::CertCommand < Gem::Command
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def add_certificate certificate # :nodoc:
|
||||||
options[:add].each do |certificate|
|
|
||||||
Gem::Security.trust_dir.trust_cert certificate
|
Gem::Security.trust_dir.trust_cert certificate
|
||||||
|
|
||||||
say "Added '#{certificate.subject}'"
|
say "Added '#{certificate.subject}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
options[:remove].each do |filter|
|
def execute
|
||||||
certificates_matching filter do |certificate, path|
|
options[:add].each do |certificate|
|
||||||
FileUtils.rm path
|
add_certificate certificate
|
||||||
say "Removed '#{certificate.subject}'"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
options[:remove].each do |filter|
|
||||||
|
remove_certificates_matching filter
|
||||||
end
|
end
|
||||||
|
|
||||||
options[:list].each do |filter|
|
options[:list].each do |filter|
|
||||||
certificates_matching filter do |certificate, _|
|
list_certificates_matching filter
|
||||||
# this could probably be formatted more gracefully
|
|
||||||
say certificate.subject.to_s
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
options[:build].each do |name|
|
options[:build].each do |name|
|
||||||
build name
|
build name
|
||||||
end
|
end
|
||||||
|
|
||||||
unless options[:sign].empty? then
|
sign_certificates unless options[:sign].empty?
|
||||||
load_default_cert unless options[:issuer_cert]
|
|
||||||
load_default_key unless options[:key]
|
|
||||||
end
|
|
||||||
|
|
||||||
options[:sign].each do |cert_file|
|
|
||||||
sign cert_file
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def build name
|
def build name
|
||||||
if options[:key]
|
key, key_path = build_key
|
||||||
key = options[:key]
|
cert_path = build_cert name, key
|
||||||
|
|
||||||
|
say "Certificate: #{cert_path}"
|
||||||
|
|
||||||
|
if key_path
|
||||||
|
say "Private Key: #{key_path}"
|
||||||
|
say "Don't forget to move the key file to somewhere private!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_cert name, key # :nodoc:
|
||||||
|
cert = Gem::Security.create_cert_email name, key
|
||||||
|
Gem::Security.write cert, "gem-public_cert.pem"
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_key # :nodoc:
|
||||||
|
if options[:key] then
|
||||||
|
options[:key]
|
||||||
else
|
else
|
||||||
passphrase = ask_for_password 'Passphrase for your Private Key:'
|
passphrase = ask_for_password 'Passphrase for your Private Key:'
|
||||||
say "\n"
|
say "\n"
|
||||||
@ -135,16 +143,8 @@ class Gem::Commands::CertCommand < Gem::Command
|
|||||||
|
|
||||||
key = Gem::Security.create_key
|
key = Gem::Security.create_key
|
||||||
key_path = Gem::Security.write key, "gem-private_key.pem", 0600, passphrase
|
key_path = Gem::Security.write key, "gem-private_key.pem", 0600, passphrase
|
||||||
end
|
|
||||||
|
|
||||||
cert = Gem::Security.create_cert_email name, key
|
return key, key_path
|
||||||
cert_path = Gem::Security.write cert, "gem-public_cert.pem"
|
|
||||||
|
|
||||||
say "Certificate: #{cert_path}"
|
|
||||||
|
|
||||||
if key_path
|
|
||||||
say "Private Key: #{key_path}"
|
|
||||||
say "Don't forget to move the key file to somewhere private!"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -200,6 +200,13 @@ For further reading on signing gems see `ri Gem::Security`.
|
|||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def list_certificates_matching filter # :nodoc:
|
||||||
|
certificates_matching filter do |certificate, _|
|
||||||
|
# this could probably be formatted more gracefully
|
||||||
|
say certificate.subject.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def load_default_cert
|
def load_default_cert
|
||||||
cert_file = File.join Gem.default_cert_path
|
cert_file = File.join Gem.default_cert_path
|
||||||
cert = File.read cert_file
|
cert = File.read cert_file
|
||||||
@ -233,6 +240,18 @@ For further reading on signing gems see `ri Gem::Security`.
|
|||||||
terminate_interaction 1
|
terminate_interaction 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_defaults # :nodoc:
|
||||||
|
load_default_cert unless options[:issuer_cert]
|
||||||
|
load_default_key unless options[:key]
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_certificates_matching filter # :nodoc:
|
||||||
|
certificates_matching filter do |certificate, path|
|
||||||
|
FileUtils.rm path
|
||||||
|
say "Removed '#{certificate.subject}'"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def sign cert_file
|
def sign cert_file
|
||||||
cert = File.read cert_file
|
cert = File.read cert_file
|
||||||
cert = OpenSSL::X509::Certificate.new cert
|
cert = OpenSSL::X509::Certificate.new cert
|
||||||
@ -247,5 +266,13 @@ For further reading on signing gems see `ri Gem::Security`.
|
|||||||
Gem::Security.write cert, cert_file, permissions
|
Gem::Security.write cert, cert_file, permissions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_certificates # :nodoc:
|
||||||
|
load_defaults unless options[:sign].empty?
|
||||||
|
|
||||||
|
options[:sign].each do |cert_file|
|
||||||
|
sign cert_file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end if defined?(OpenSSL::SSL)
|
end if defined?(OpenSSL::SSL)
|
||||||
|
|
||||||
|
@ -31,6 +31,10 @@ class Gem::Commands::ContentsCommand < Gem::Command
|
|||||||
"Don't include installed path prefix") do |prefix, options|
|
"Don't include installed path prefix") do |prefix, options|
|
||||||
options[:prefix] = prefix
|
options[:prefix] = prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@path_kind = nil
|
||||||
|
@spec_dirs = nil
|
||||||
|
@version = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def arguments # :nodoc:
|
def arguments # :nodoc:
|
||||||
@ -46,43 +50,40 @@ class Gem::Commands::ContentsCommand < Gem::Command
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
version = options[:version] || Gem::Requirement.default
|
@version = options[:version] || Gem::Requirement.default
|
||||||
|
@spec_dirs = specification_directories
|
||||||
|
@path_kind = path_description @spec_dirs
|
||||||
|
|
||||||
spec_dirs = options[:specdirs].map do |i|
|
names = gem_names
|
||||||
[i, File.join(i, "specifications")]
|
|
||||||
end.flatten
|
|
||||||
|
|
||||||
path_kind = if spec_dirs.empty? then
|
names.each do |name|
|
||||||
spec_dirs = Gem::Specification.dirs
|
found = gem_contents name
|
||||||
"default gem paths"
|
|
||||||
|
terminate_interaction 1 unless found or names.length > 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def files_in spec
|
||||||
|
if spec.default_gem? then
|
||||||
|
files_in_default_gem spec
|
||||||
else
|
else
|
||||||
"specified path"
|
files_in_gem spec
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
gem_names = if options[:all] then
|
def files_in_gem spec
|
||||||
Gem::Specification.map(&:name)
|
gem_path = spec.full_gem_path
|
||||||
else
|
extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
|
||||||
get_all_gem_names
|
glob = "#{gem_path}#{extra}/**/*"
|
||||||
|
prefix_re = /#{Regexp.escape(gem_path)}\//
|
||||||
|
|
||||||
|
Dir[glob].map do |file|
|
||||||
|
[gem_path, file.sub(prefix_re, "")]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
gem_names.each do |name|
|
def files_in_default_gem spec
|
||||||
# HACK: find_by_name fails for some reason... ARGH
|
spec.files.sort.map do |file|
|
||||||
# How many places must we embed our resolve logic?
|
|
||||||
spec = Gem::Specification.find_all_by_name(name, version).last
|
|
||||||
|
|
||||||
unless spec then
|
|
||||||
say "Unable to find gem '#{name}' in #{path_kind}"
|
|
||||||
|
|
||||||
if Gem.configuration.verbose then
|
|
||||||
say "\nDirectories searched:"
|
|
||||||
spec_dirs.sort.each { |dir| say dir }
|
|
||||||
end
|
|
||||||
|
|
||||||
terminate_interaction 1 if gem_names.length == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if spec.default_gem?
|
|
||||||
files = spec.files.sort.map do |file|
|
|
||||||
case file
|
case file
|
||||||
when /\A#{spec.bindir}\//
|
when /\A#{spec.bindir}\//
|
||||||
[Gem::ConfigMap[:bindir], $POSTMATCH]
|
[Gem::ConfigMap[:bindir], $POSTMATCH]
|
||||||
@ -92,27 +93,69 @@ class Gem::Commands::ContentsCommand < Gem::Command
|
|||||||
[Gem::ConfigMap[:rubylibdir], file]
|
[Gem::ConfigMap[:rubylibdir], file]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def gem_contents name
|
||||||
|
spec = spec_for name
|
||||||
|
|
||||||
|
return false unless spec
|
||||||
|
|
||||||
|
files = files_in spec
|
||||||
|
|
||||||
|
show_files files
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def gem_names # :nodoc:
|
||||||
|
if options[:all] then
|
||||||
|
Gem::Specification.map(&:name)
|
||||||
else
|
else
|
||||||
gem_path = spec.full_gem_path
|
get_all_gem_names
|
||||||
extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
|
|
||||||
glob = "#{gem_path}#{extra}/**/*"
|
|
||||||
prefix_re = /#{Regexp.escape(gem_path)}\//
|
|
||||||
files = Dir[glob].map do |file|
|
|
||||||
[gem_path, file.sub(prefix_re, "")]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def path_description spec_dirs # :nodoc:
|
||||||
|
if spec_dirs.empty? then
|
||||||
|
spec_dirs = Gem::Specification.dirs
|
||||||
|
"default gem paths"
|
||||||
|
else
|
||||||
|
"specified path"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_files files
|
||||||
files.sort.each do |prefix, basename|
|
files.sort.each do |prefix, basename|
|
||||||
absolute_path = File.join(prefix, basename)
|
absolute_path = File.join(prefix, basename)
|
||||||
next if File.directory? absolute_path
|
next if File.directory? absolute_path
|
||||||
|
|
||||||
if options[:prefix]
|
if options[:prefix] then
|
||||||
say absolute_path
|
say absolute_path
|
||||||
else
|
else
|
||||||
say basename
|
say basename
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def spec_for name
|
||||||
|
spec = Gem::Specification.find_all_by_name(name, @version).last
|
||||||
|
|
||||||
|
return spec if spec
|
||||||
|
|
||||||
|
say "Unable to find gem '#{name}' in #{@path_kind}"
|
||||||
|
|
||||||
|
if Gem.configuration.verbose then
|
||||||
|
say "\nDirectories searched:"
|
||||||
|
@spec_dirs.sort.each { |dir| say dir }
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def specification_directories # :nodoc:
|
||||||
|
options[:specdirs].map do |i|
|
||||||
|
[i, File.join(i, "specifications")]
|
||||||
|
end.flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -42,67 +42,55 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|||||||
"#{program_name} GEMNAME"
|
"#{program_name} GEMNAME"
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def fetch_remote_specs dependency # :nodoc:
|
||||||
if options[:reverse_dependencies] and remote? and not local? then
|
fetcher = Gem::SpecFetcher.fetcher
|
||||||
alert_error 'Only reverse dependencies for local gems are supported.'
|
|
||||||
terminate_interaction 1
|
ss, = fetcher.spec_for_dependency dependency
|
||||||
|
|
||||||
|
ss.map { |spec, _| spec }
|
||||||
end
|
end
|
||||||
|
|
||||||
options[:args] << '' if options[:args].empty?
|
def fetch_specs dependency # :nodoc:
|
||||||
|
|
||||||
pattern = if options[:args].length == 1 and
|
|
||||||
options[:args].first =~ /\A\/(.*)\/(i)?\z/m then
|
|
||||||
flags = $2 ? Regexp::IGNORECASE : nil
|
|
||||||
Regexp.new $1, flags
|
|
||||||
else
|
|
||||||
/\A#{Regexp.union(*options[:args])}/
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO: deprecate for real damnit
|
|
||||||
dependency = Gem::Deprecate.skip_during {
|
|
||||||
Gem::Dependency.new pattern, options[:version]
|
|
||||||
}
|
|
||||||
dependency.prerelease = options[:prerelease]
|
|
||||||
|
|
||||||
specs = []
|
specs = []
|
||||||
|
|
||||||
specs.concat dependency.matching_specs if local?
|
specs.concat dependency.matching_specs if local?
|
||||||
|
specs.concat fetch_remote_specs dependency if remote?
|
||||||
|
|
||||||
if remote? and not options[:reverse_dependencies] then
|
ensure_specs specs
|
||||||
fetcher = Gem::SpecFetcher.fetcher
|
|
||||||
|
|
||||||
ss, _ = fetcher.spec_for_dependency dependency
|
specs.uniq.sort
|
||||||
|
|
||||||
ss.each { |s,o| specs << s }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if specs.empty? then
|
def gem_dependency args, version, prerelease # :nodoc:
|
||||||
patterns = options[:args].join ','
|
args << '' if args.empty?
|
||||||
say "No gems found matching #{patterns} (#{options[:version]})" if
|
|
||||||
Gem.configuration.verbose
|
|
||||||
|
|
||||||
terminate_interaction 1
|
pattern = if args.length == 1 and args.first =~ /\A\/(.*)\/(i)?\z/m then
|
||||||
|
flags = $2 ? Regexp::IGNORECASE : nil
|
||||||
|
Regexp.new $1, flags
|
||||||
|
else
|
||||||
|
/\A#{Regexp.union(*args)}/
|
||||||
end
|
end
|
||||||
|
|
||||||
specs = specs.uniq.sort
|
dependency = Gem::Deprecate.skip_during {
|
||||||
|
Gem::Dependency.new pattern, version
|
||||||
|
}
|
||||||
|
|
||||||
reverse = Hash.new { |h, k| h[k] = [] }
|
dependency.prerelease = prerelease
|
||||||
|
|
||||||
if options[:reverse_dependencies] then
|
dependency
|
||||||
|
end
|
||||||
|
|
||||||
|
def display_pipe specs # :nodoc:
|
||||||
specs.each do |spec|
|
specs.each do |spec|
|
||||||
reverse[spec.full_name] = find_reverse_dependencies spec
|
unless spec.dependencies.empty? then
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if options[:pipe_format] then
|
|
||||||
specs.each do |spec|
|
|
||||||
unless spec.dependencies.empty?
|
|
||||||
spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
|
spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
|
||||||
say "#{dep.name} --version '#{dep.requirement}'"
|
say "#{dep.name} --version '#{dep.requirement}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
|
|
||||||
|
def display_readable specs, reverse # :nodoc:
|
||||||
response = ''
|
response = ''
|
||||||
|
|
||||||
specs.each do |spec|
|
specs.each do |spec|
|
||||||
@ -118,9 +106,42 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|||||||
|
|
||||||
say response
|
say response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def execute
|
||||||
|
ensure_local_only_reverse_dependencies
|
||||||
|
|
||||||
|
dependency =
|
||||||
|
gem_dependency options[:args], options[:version], options[:prerelease]
|
||||||
|
|
||||||
|
specs = fetch_specs dependency
|
||||||
|
|
||||||
|
reverse = reverse_dependencies specs
|
||||||
|
|
||||||
|
if options[:pipe_format] then
|
||||||
|
display_pipe specs
|
||||||
|
else
|
||||||
|
display_readable specs, reverse
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_dependencies(spec, level = 0)
|
def ensure_local_only_reverse_dependencies # :nodoc:
|
||||||
|
if options[:reverse_dependencies] and remote? and not local? then
|
||||||
|
alert_error 'Only reverse dependencies for local gems are supported.'
|
||||||
|
terminate_interaction 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def ensure_specs specs # :nodoc:
|
||||||
|
return unless specs.empty?
|
||||||
|
|
||||||
|
patterns = options[:args].join ','
|
||||||
|
say "No gems found matching #{patterns} (#{options[:version]})" if
|
||||||
|
Gem.configuration.verbose
|
||||||
|
|
||||||
|
terminate_interaction 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def print_dependencies(spec, level = 0) # :nodoc:
|
||||||
response = ''
|
response = ''
|
||||||
response << ' ' * level + "Gem #{spec.full_name}\n"
|
response << ' ' * level + "Gem #{spec.full_name}\n"
|
||||||
unless spec.dependencies.empty? then
|
unless spec.dependencies.empty? then
|
||||||
@ -131,10 +152,30 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remote_specs dependency # :nodoc:
|
||||||
|
fetcher = Gem::SpecFetcher.fetcher
|
||||||
|
|
||||||
|
ss, _ = fetcher.spec_for_dependency dependency
|
||||||
|
|
||||||
|
ss.map { |s,o| s }
|
||||||
|
end
|
||||||
|
|
||||||
|
def reverse_dependencies specs # :nodoc:
|
||||||
|
reverse = Hash.new { |h, k| h[k] = [] }
|
||||||
|
|
||||||
|
return reverse unless options[:reverse_dependencies]
|
||||||
|
|
||||||
|
specs.each do |spec|
|
||||||
|
reverse[spec.full_name] = find_reverse_dependencies spec
|
||||||
|
end
|
||||||
|
|
||||||
|
reverse
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns an Array of [specification, dep] that are satisfied by +spec+.
|
# Returns an Array of [specification, dep] that are satisfied by +spec+.
|
||||||
|
|
||||||
def find_reverse_dependencies(spec)
|
def find_reverse_dependencies spec # :nodoc:
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
Gem::Specification.each do |sp|
|
Gem::Specification.each do |sp|
|
||||||
|
@ -69,20 +69,36 @@ lib/rubygems/defaults/operating_system.rb
|
|||||||
def execute
|
def execute
|
||||||
out = ''
|
out = ''
|
||||||
arg = options[:args][0]
|
arg = options[:args][0]
|
||||||
|
out <<
|
||||||
case arg
|
case arg
|
||||||
when /^packageversion/ then
|
when /^packageversion/ then
|
||||||
out << Gem::RubyGemsPackageVersion
|
Gem::RubyGemsPackageVersion
|
||||||
when /^version/ then
|
when /^version/ then
|
||||||
out << Gem::VERSION
|
Gem::VERSION
|
||||||
when /^gemdir/, /^gemhome/, /^home/, /^GEM_HOME/ then
|
when /^gemdir/, /^gemhome/, /^home/, /^GEM_HOME/ then
|
||||||
out << Gem.dir
|
Gem.dir
|
||||||
when /^gempath/, /^path/, /^GEM_PATH/ then
|
when /^gempath/, /^path/, /^GEM_PATH/ then
|
||||||
out << Gem.path.join(File::PATH_SEPARATOR)
|
Gem.path.join(File::PATH_SEPARATOR)
|
||||||
when /^remotesources/ then
|
when /^remotesources/ then
|
||||||
out << Gem.sources.to_a.join("\n")
|
Gem.sources.to_a.join("\n")
|
||||||
when /^platform/ then
|
when /^platform/ then
|
||||||
out << Gem.platforms.join(File::PATH_SEPARATOR)
|
Gem.platforms.join(File::PATH_SEPARATOR)
|
||||||
when nil then
|
when nil then
|
||||||
|
show_environment
|
||||||
|
else
|
||||||
|
raise Gem::CommandLineError, "Unknown environment option [#{arg}]"
|
||||||
|
end
|
||||||
|
say out
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_path out, path
|
||||||
|
path.each do |component|
|
||||||
|
out << " - #{component}\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_environment # :nodoc:
|
||||||
out = "RubyGems Environment:\n"
|
out = "RubyGems Environment:\n"
|
||||||
|
|
||||||
out << " - RUBYGEMS VERSION: #{Gem::VERSION}\n"
|
out << " - RUBYGEMS VERSION: #{Gem::VERSION}\n"
|
||||||
@ -129,17 +145,7 @@ lib/rubygems/defaults/operating_system.rb
|
|||||||
shell_path = ENV['PATH'].split(File::PATH_SEPARATOR)
|
shell_path = ENV['PATH'].split(File::PATH_SEPARATOR)
|
||||||
add_path out, shell_path
|
add_path out, shell_path
|
||||||
|
|
||||||
else
|
out
|
||||||
raise Gem::CommandLineError, "Unknown environment option [#{arg}]"
|
|
||||||
end
|
|
||||||
say out
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_path out, path
|
|
||||||
path.each do |component|
|
|
||||||
out << " - #{component}\n"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -94,6 +94,8 @@ platform.
|
|||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super 'help', "Provide help on the 'gem' command"
|
super 'help', "Provide help on the 'gem' command"
|
||||||
|
|
||||||
|
@command_manager = Gem::CommandManager.instance
|
||||||
end
|
end
|
||||||
|
|
||||||
def arguments # :nodoc:
|
def arguments # :nodoc:
|
||||||
@ -110,24 +112,46 @@ platform.
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
command_manager = Gem::CommandManager.instance
|
|
||||||
arg = options[:args][0]
|
arg = options[:args][0]
|
||||||
|
|
||||||
if begins? "commands", arg then
|
if begins? "commands", arg then
|
||||||
|
show_commands
|
||||||
|
|
||||||
|
elsif begins? "options", arg then
|
||||||
|
say Gem::Command::HELP
|
||||||
|
|
||||||
|
elsif begins? "examples", arg then
|
||||||
|
say EXAMPLES
|
||||||
|
|
||||||
|
elsif begins? "platforms", arg then
|
||||||
|
say PLATFORMS
|
||||||
|
|
||||||
|
elsif options[:help] then
|
||||||
|
show_help
|
||||||
|
|
||||||
|
elsif arg then
|
||||||
|
show_command_help arg
|
||||||
|
|
||||||
|
else
|
||||||
|
say Gem::Command::HELP
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_commands # :nodoc:
|
||||||
out = []
|
out = []
|
||||||
out << "GEM commands are:"
|
out << "GEM commands are:"
|
||||||
out << nil
|
out << nil
|
||||||
|
|
||||||
margin_width = 4
|
margin_width = 4
|
||||||
|
|
||||||
desc_width = command_manager.command_names.map { |n| n.size }.max + 4
|
desc_width = @command_manager.command_names.map { |n| n.size }.max + 4
|
||||||
|
|
||||||
summary_width = 80 - margin_width - desc_width
|
summary_width = 80 - margin_width - desc_width
|
||||||
wrap_indent = ' ' * (margin_width + desc_width)
|
wrap_indent = ' ' * (margin_width + desc_width)
|
||||||
format = "#{' ' * margin_width}%-#{desc_width}s%s"
|
format = "#{' ' * margin_width}%-#{desc_width}s%s"
|
||||||
|
|
||||||
command_manager.command_names.each do |cmd_name|
|
@command_manager.command_names.each do |cmd_name|
|
||||||
command = command_manager[cmd_name]
|
command = @command_manager[cmd_name]
|
||||||
|
|
||||||
summary =
|
summary =
|
||||||
if command then
|
if command then
|
||||||
@ -150,39 +174,31 @@ platform.
|
|||||||
out << "e.g. 'gem i rake' is short for 'gem install rake'."
|
out << "e.g. 'gem i rake' is short for 'gem install rake'."
|
||||||
|
|
||||||
say out.join("\n")
|
say out.join("\n")
|
||||||
|
end
|
||||||
|
|
||||||
elsif begins? "options", arg then
|
def show_command_help command_name # :nodoc:
|
||||||
say Gem::Command::HELP
|
command_name = command_name.downcase
|
||||||
|
|
||||||
elsif begins? "examples", arg then
|
possibilities = @command_manager.find_command_possibilities command_name
|
||||||
say EXAMPLES
|
|
||||||
|
|
||||||
elsif begins? "platforms", arg then
|
if possibilities.size == 1 then
|
||||||
say PLATFORMS
|
command = @command_manager[possibilities.first]
|
||||||
|
command.invoke("--help")
|
||||||
|
elsif possibilities.size > 1 then
|
||||||
|
alert_warning "Ambiguous command #{command_name} (#{possibilities.join(', ')})"
|
||||||
|
else
|
||||||
|
alert_warning "Unknown command #{command_name}. Try: gem help commands"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
elsif options[:help] then
|
def show_help # :nodoc:
|
||||||
command = command_manager[options[:help]]
|
command = @command_manager[options[:help]]
|
||||||
if command
|
if command then
|
||||||
# help with provided command
|
# help with provided command
|
||||||
command.invoke("--help")
|
command.invoke("--help")
|
||||||
else
|
else
|
||||||
alert_error "Unknown command #{options[:help]}. Try 'gem help commands'"
|
alert_error "Unknown command #{options[:help]}. Try 'gem help commands'"
|
||||||
end
|
end
|
||||||
|
|
||||||
elsif arg then
|
|
||||||
possibilities = command_manager.find_command_possibilities(arg.downcase)
|
|
||||||
if possibilities.size == 1
|
|
||||||
command = command_manager[possibilities.first]
|
|
||||||
command.invoke("--help")
|
|
||||||
elsif possibilities.size > 1
|
|
||||||
alert_warning "Ambiguous command #{arg} (#{possibilities.join(', ')})"
|
|
||||||
else
|
|
||||||
alert_warning "Unknown command #{arg}. Try gem help commands"
|
|
||||||
end
|
|
||||||
|
|
||||||
else
|
|
||||||
say Gem::Command::HELP
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -113,7 +113,44 @@ to write the specification by hand. For example:
|
|||||||
"#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags"
|
"#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags"
|
||||||
end
|
end
|
||||||
|
|
||||||
def install_from_gemdeps(gf)
|
def check_install_dir # :nodoc:
|
||||||
|
if options[:install_dir] and options[:user_install] then
|
||||||
|
alert_error "Use --install-dir or --user-install but not both"
|
||||||
|
terminate_interaction 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_version # :nodoc:
|
||||||
|
if options[:version] != Gem::Requirement.default and
|
||||||
|
get_all_gem_names.size > 1 then
|
||||||
|
alert_error "Can't use --version w/ multiple gems. Use name:ver instead."
|
||||||
|
terminate_interaction 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute
|
||||||
|
if gf = options[:gemdeps] then
|
||||||
|
install_from_gemdeps gf
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
@installed_specs = []
|
||||||
|
|
||||||
|
ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
|
||||||
|
|
||||||
|
check_install_dir
|
||||||
|
check_version
|
||||||
|
|
||||||
|
load_hooks
|
||||||
|
|
||||||
|
exit_code = install_gems
|
||||||
|
|
||||||
|
show_installed
|
||||||
|
|
||||||
|
raise Gem::SystemExitException, exit_code
|
||||||
|
end
|
||||||
|
|
||||||
|
def install_from_gemdeps gf # :nodoc:
|
||||||
require 'rubygems/request_set'
|
require 'rubygems/request_set'
|
||||||
rs = Gem::RequestSet.new
|
rs = Gem::RequestSet.new
|
||||||
rs.load_gemdeps gf
|
rs.load_gemdeps gf
|
||||||
@ -135,58 +172,26 @@ to write the specification by hand. For example:
|
|||||||
raise Gem::SystemExitException, 0
|
raise Gem::SystemExitException, 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def install_gem name, version # :nodoc:
|
||||||
if gf = options[:gemdeps] then
|
return if options[:conservative] and
|
||||||
install_from_gemdeps gf
|
not Gem::Dependency.new(name, version).matching_specs.empty?
|
||||||
return
|
|
||||||
end
|
inst = Gem::DependencyInstaller.new options
|
||||||
|
inst.install name, Gem::Requirement.create(version)
|
||||||
@installed_specs = []
|
|
||||||
|
@installed_specs.push(*inst.installed_gems)
|
||||||
ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
|
|
||||||
|
show_install_errors inst.errors
|
||||||
if options[:install_dir] and options[:user_install]
|
|
||||||
alert_error "Use --install-dir or --user-install but not both"
|
|
||||||
terminate_interaction 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def install_gems # :nodoc:
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
|
|
||||||
if options[:version] != Gem::Requirement.default &&
|
|
||||||
get_all_gem_names.size > 1 then
|
|
||||||
alert_error "Can't use --version w/ multiple gems. Use name:ver instead."
|
|
||||||
terminate_interaction 1
|
|
||||||
end
|
|
||||||
|
|
||||||
# load post-install hooks appropriate to options
|
|
||||||
if options[:install_as_default]
|
|
||||||
require 'rubygems/install_default_message'
|
|
||||||
else
|
|
||||||
require 'rubygems/install_message'
|
|
||||||
end
|
|
||||||
require 'rubygems/rdoc'
|
|
||||||
|
|
||||||
get_all_gem_names_and_versions.each do |gem_name, gem_version|
|
get_all_gem_names_and_versions.each do |gem_name, gem_version|
|
||||||
gem_version ||= options[:version]
|
gem_version ||= options[:version]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
next if options[:conservative] and
|
install_gem gem_name, gem_version
|
||||||
not Gem::Dependency.new(gem_name, gem_version).matching_specs.empty?
|
|
||||||
|
|
||||||
inst = Gem::DependencyInstaller.new options
|
|
||||||
inst.install gem_name, Gem::Requirement.create(gem_version)
|
|
||||||
|
|
||||||
@installed_specs.push(*inst.installed_gems)
|
|
||||||
|
|
||||||
next unless errs = inst.errors
|
|
||||||
|
|
||||||
errs.each do |x|
|
|
||||||
next unless Gem::SourceFetchProblem === x
|
|
||||||
|
|
||||||
msg = "Unable to pull data from '#{x.source.uri}': #{x.error.message}"
|
|
||||||
|
|
||||||
alert_warning msg
|
|
||||||
end
|
|
||||||
rescue Gem::InstallError => e
|
rescue Gem::InstallError => e
|
||||||
alert_error "Error installing #{gem_name}:\n\t#{e.message}"
|
alert_error "Error installing #{gem_name}:\n\t#{e.message}"
|
||||||
exit_code |= 1
|
exit_code |= 1
|
||||||
@ -197,13 +202,39 @@ to write the specification by hand. For example:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless @installed_specs.empty? then
|
exit_code
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Loads post-install hooks
|
||||||
|
|
||||||
|
def load_hooks # :nodoc:
|
||||||
|
if options[:install_as_default]
|
||||||
|
require 'rubygems/install_default_message'
|
||||||
|
else
|
||||||
|
require 'rubygems/install_message'
|
||||||
|
end
|
||||||
|
require 'rubygems/rdoc'
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_install_errors errors # :nodoc:
|
||||||
|
return unless errors
|
||||||
|
|
||||||
|
errors.each do |x|
|
||||||
|
return unless Gem::SourceFetchProblem === x
|
||||||
|
|
||||||
|
msg = "Unable to pull data from '#{x.source.uri}': #{x.error.message}"
|
||||||
|
|
||||||
|
alert_warning msg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_installed # :nodoc:
|
||||||
|
return if @installed_specs.empty?
|
||||||
|
|
||||||
gems = @installed_specs.length == 1 ? 'gem' : 'gems'
|
gems = @installed_specs.length == 1 ? 'gem' : 'gems'
|
||||||
say "#{@installed_specs.length} #{gems} installed"
|
say "#{@installed_specs.length} #{gems} installed"
|
||||||
end
|
end
|
||||||
|
|
||||||
raise Gem::SystemExitException, exit_code
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||||||
summary = 'Query gem information in local or remote repositories')
|
summary = 'Query gem information in local or remote repositories')
|
||||||
super name, summary,
|
super name, summary,
|
||||||
:name => //, :domain => :local, :details => false, :versions => true,
|
:name => //, :domain => :local, :details => false, :versions => true,
|
||||||
:installed => false, :version => Gem::Requirement.default
|
:installed => nil, :version => Gem::Requirement.default
|
||||||
|
|
||||||
add_option('-i', '--[no-]installed',
|
add_option('-i', '--[no-]installed',
|
||||||
'Check for installed gem') do |value, options|
|
'Check for installed gem') do |value, options|
|
||||||
@ -67,16 +67,21 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||||||
name = options[:name]
|
name = options[:name]
|
||||||
prerelease = options[:prerelease]
|
prerelease = options[:prerelease]
|
||||||
|
|
||||||
if options[:installed] then
|
unless options[:installed].nil? then
|
||||||
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, options[:version] then
|
else
|
||||||
|
installed = installed? name, options[:version]
|
||||||
|
installed = !installed unless options[:installed]
|
||||||
|
|
||||||
|
if installed then
|
||||||
say "true"
|
say "true"
|
||||||
else
|
else
|
||||||
say "false"
|
say "false"
|
||||||
exit_code |= 1
|
exit_code |= 1
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
terminate_interaction exit_code
|
terminate_interaction exit_code
|
||||||
end
|
end
|
||||||
|
@ -7,6 +7,8 @@ class Gem::Commands::SearchCommand < Gem::Commands::QueryCommand
|
|||||||
super 'search', 'Display all gems whose name contains STRING'
|
super 'search', 'Display all gems whose name contains STRING'
|
||||||
|
|
||||||
remove_option '--name-matches'
|
remove_option '--name-matches'
|
||||||
|
|
||||||
|
defaults[:domain] = :remote
|
||||||
end
|
end
|
||||||
|
|
||||||
def arguments # :nodoc:
|
def arguments # :nodoc:
|
||||||
|
@ -37,46 +37,8 @@ class Gem::Commands::SourcesCommand < Gem::Command
|
|||||||
add_proxy_option
|
add_proxy_option
|
||||||
end
|
end
|
||||||
|
|
||||||
def defaults_str
|
def add_source source_uri # :nodoc:
|
||||||
'--list'
|
check_rubygems_https source_uri
|
||||||
end
|
|
||||||
|
|
||||||
def execute
|
|
||||||
options[:list] = !(options[:add] ||
|
|
||||||
options[:clear_all] ||
|
|
||||||
options[:remove] ||
|
|
||||||
options[:update])
|
|
||||||
|
|
||||||
if options[:clear_all] then
|
|
||||||
path = Gem.spec_cache_dir
|
|
||||||
FileUtils.rm_rf path
|
|
||||||
|
|
||||||
unless File.exist? path then
|
|
||||||
say "*** Removed specs cache ***"
|
|
||||||
else
|
|
||||||
unless File.writable? path then
|
|
||||||
say "*** Unable to remove source cache (write protected) ***"
|
|
||||||
else
|
|
||||||
say "*** Unable to remove source cache ***"
|
|
||||||
end
|
|
||||||
|
|
||||||
terminate_interaction 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if source_uri = options[:add] then
|
|
||||||
uri = URI source_uri
|
|
||||||
|
|
||||||
if uri.scheme and uri.scheme.downcase == 'http' and
|
|
||||||
uri.host.downcase == 'rubygems.org' then
|
|
||||||
question = <<-QUESTION.chomp
|
|
||||||
https://rubygems.org is recommended for security over #{uri}
|
|
||||||
|
|
||||||
Do you want to add this insecure source?
|
|
||||||
QUESTION
|
|
||||||
|
|
||||||
terminate_interaction 1 unless ask_yes_no question
|
|
||||||
end
|
|
||||||
|
|
||||||
source = Gem::Source.new source_uri
|
source = Gem::Source.new source_uri
|
||||||
|
|
||||||
@ -99,9 +61,74 @@ Do you want to add this insecure source?
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:remove] then
|
def check_rubygems_https source_uri # :nodoc:
|
||||||
source_uri = options[:remove]
|
uri = URI source_uri
|
||||||
|
|
||||||
|
if uri.scheme and uri.scheme.downcase == 'http' and
|
||||||
|
uri.host.downcase == 'rubygems.org' then
|
||||||
|
question = <<-QUESTION.chomp
|
||||||
|
https://rubygems.org is recommended for security over #{uri}
|
||||||
|
|
||||||
|
Do you want to add this insecure source?
|
||||||
|
QUESTION
|
||||||
|
|
||||||
|
terminate_interaction 1 unless ask_yes_no question
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_all # :nodoc:
|
||||||
|
path = Gem.spec_cache_dir
|
||||||
|
FileUtils.rm_rf path
|
||||||
|
|
||||||
|
unless File.exist? path then
|
||||||
|
say "*** Removed specs cache ***"
|
||||||
|
else
|
||||||
|
unless File.writable? path then
|
||||||
|
say "*** Unable to remove source cache (write protected) ***"
|
||||||
|
else
|
||||||
|
say "*** Unable to remove source cache ***"
|
||||||
|
end
|
||||||
|
|
||||||
|
terminate_interaction 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def defaults_str # :nodoc:
|
||||||
|
'--list'
|
||||||
|
end
|
||||||
|
|
||||||
|
def list # :nodoc:
|
||||||
|
say "*** CURRENT SOURCES ***"
|
||||||
|
say
|
||||||
|
|
||||||
|
Gem.sources.each do |src|
|
||||||
|
say src
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def list? # :nodoc:
|
||||||
|
!(options[:list] ||
|
||||||
|
options[:add] ||
|
||||||
|
options[:clear_all] ||
|
||||||
|
options[:remove] ||
|
||||||
|
options[:update])
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute
|
||||||
|
clear_all if options[:clear_all]
|
||||||
|
|
||||||
|
source_uri = options[:add]
|
||||||
|
add_source source_uri if source_uri
|
||||||
|
|
||||||
|
source_uri = options[:remove]
|
||||||
|
remove_source source_uri if source_uri
|
||||||
|
|
||||||
|
update if options[:update]
|
||||||
|
|
||||||
|
list if list?
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_source source_uri # :nodoc:
|
||||||
unless Gem.sources.include? source_uri then
|
unless Gem.sources.include? source_uri then
|
||||||
say "source #{source_uri} not present in cache"
|
say "source #{source_uri} not present in cache"
|
||||||
else
|
else
|
||||||
@ -112,7 +139,7 @@ Do you want to add this insecure source?
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:update] then
|
def update # :nodoc:
|
||||||
Gem.sources.each_source do |src|
|
Gem.sources.each_source do |src|
|
||||||
src.load_specs :released
|
src.load_specs :released
|
||||||
src.load_specs :latest
|
src.load_specs :latest
|
||||||
@ -121,19 +148,7 @@ Do you want to add this insecure source?
|
|||||||
say "source cache successfully updated"
|
say "source cache successfully updated"
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:list] then
|
def remove_cache_file desc, path # :nodoc:
|
||||||
say "*** CURRENT SOURCES ***"
|
|
||||||
say
|
|
||||||
|
|
||||||
Gem.sources.each do |src|
|
|
||||||
say src
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def remove_cache_file(desc, path)
|
|
||||||
FileUtils.rm_rf path
|
FileUtils.rm_rf path
|
||||||
|
|
||||||
if not File.exist?(path) then
|
if not File.exist?(path) then
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
require 'rubygems/command'
|
require 'rubygems/command'
|
||||||
require 'rubygems/version_option'
|
require 'rubygems/version_option'
|
||||||
require 'rubygems/uninstaller'
|
require 'rubygems/uninstaller'
|
||||||
|
require 'fileutils'
|
||||||
|
|
||||||
##
|
##
|
||||||
# Gem uninstaller command line tool
|
# Gem uninstaller command line tool
|
||||||
@ -14,7 +15,7 @@ class Gem::Commands::UninstallCommand < Gem::Command
|
|||||||
def initialize
|
def initialize
|
||||||
super 'uninstall', 'Uninstall gems from the local repository',
|
super 'uninstall', 'Uninstall gems from the local repository',
|
||||||
:version => Gem::Requirement.default, :user_install => true,
|
:version => Gem::Requirement.default, :user_install => true,
|
||||||
:check_dev => false
|
:install_dir => Gem.dir, :check_dev => false
|
||||||
|
|
||||||
add_option('-a', '--[no-]all',
|
add_option('-a', '--[no-]all',
|
||||||
'Uninstall all matching versions'
|
'Uninstall all matching versions'
|
||||||
@ -92,8 +93,31 @@ class Gem::Commands::UninstallCommand < Gem::Command
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
# REFACTOR: stolen from cleanup_command
|
if options[:all] and not options[:args].empty? then
|
||||||
|
alert_error 'Gem names and --all may not be used together'
|
||||||
|
terminate_interaction 1
|
||||||
|
elsif options[:all] then
|
||||||
|
uninstall_all
|
||||||
|
else
|
||||||
|
uninstall_specific
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def uninstall_all
|
||||||
|
install_dir = options[:install_dir]
|
||||||
|
|
||||||
|
dirs_to_be_emptied = Dir[File.join(install_dir, '*')]
|
||||||
|
dirs_to_be_emptied.delete_if { |dir| dir.end_with? 'build_info' }
|
||||||
|
|
||||||
|
dirs_to_be_emptied.each do |dir|
|
||||||
|
FileUtils.rm_rf Dir[File.join(dir, '*')]
|
||||||
|
end
|
||||||
|
alert("Successfully uninstalled all gems in #{install_dir}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def uninstall_specific
|
||||||
deplist = Gem::DependencyList.new
|
deplist = Gem::DependencyList.new
|
||||||
|
|
||||||
get_all_gem_names.uniq.each do |name|
|
get_all_gem_names.uniq.each do |name|
|
||||||
Gem::Specification.find_all_by_name(name).each do |spec|
|
Gem::Specification.find_all_by_name(name).each do |spec|
|
||||||
deplist.add spec
|
deplist.add spec
|
||||||
|
@ -56,23 +56,33 @@ class Gem::Commands::UpdateCommand < Gem::Command
|
|||||||
"#{program_name} GEMNAME [GEMNAME ...]"
|
"#{program_name} GEMNAME [GEMNAME ...]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_latest_rubygems version # :nodoc:
|
||||||
|
if Gem.rubygems_version == version then
|
||||||
|
say "Latest version currently installed. Aborting."
|
||||||
|
terminate_interaction
|
||||||
|
end
|
||||||
|
|
||||||
|
options[:user_install] = false
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_update_arguments # :nodoc:
|
||||||
|
unless options[:args].empty? then
|
||||||
|
alert_error "Gem names are not allowed with the --system option"
|
||||||
|
terminate_interaction 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
hig = {}
|
hig = {}
|
||||||
|
|
||||||
if options[:system] then
|
if options[:system] then
|
||||||
update_rubygems
|
update_rubygems
|
||||||
return
|
return
|
||||||
else
|
end
|
||||||
|
|
||||||
say "Updating installed gems"
|
say "Updating installed gems"
|
||||||
|
|
||||||
hig = {} # highest installed gems
|
hig = highest_installed_gems
|
||||||
|
|
||||||
Gem::Specification.each do |spec|
|
|
||||||
if hig[spec.name].nil? or hig[spec.name].version < spec.version then
|
|
||||||
hig[spec.name] = spec
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
gems_to_update = which_to_update hig, options[:args].uniq
|
gems_to_update = which_to_update hig, options[:args].uniq
|
||||||
|
|
||||||
@ -85,6 +95,92 @@ class Gem::Commands::UpdateCommand < Gem::Command
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch_remote_gems spec # :nodoc:
|
||||||
|
dependency = Gem::Dependency.new spec.name, "> #{spec.version}"
|
||||||
|
dependency.prerelease = options[:prerelease]
|
||||||
|
|
||||||
|
fetcher = Gem::SpecFetcher.fetcher
|
||||||
|
|
||||||
|
spec_tuples, _ = fetcher.search_for_dependency dependency
|
||||||
|
|
||||||
|
spec_tuples
|
||||||
|
end
|
||||||
|
|
||||||
|
def highest_installed_gems # :nodoc:
|
||||||
|
hig = {} # highest installed gems
|
||||||
|
|
||||||
|
Gem::Specification.each do |spec|
|
||||||
|
if hig[spec.name].nil? or hig[spec.name].version < spec.version then
|
||||||
|
hig[spec.name] = spec
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
hig
|
||||||
|
end
|
||||||
|
|
||||||
|
def highest_remote_version spec # :nodoc:
|
||||||
|
spec_tuples = fetch_remote_gems spec
|
||||||
|
|
||||||
|
matching_gems = spec_tuples.select do |g,_|
|
||||||
|
g.name == spec.name and g.match_platform?
|
||||||
|
end
|
||||||
|
|
||||||
|
highest_remote_gem = matching_gems.sort_by { |g,_| g.version }.last
|
||||||
|
|
||||||
|
highest_remote_gem ||= [Gem::NameTuple.null]
|
||||||
|
|
||||||
|
highest_remote_gem.first.version
|
||||||
|
end
|
||||||
|
|
||||||
|
def install_rubygems version # :nodoc:
|
||||||
|
args = update_rubygems_arguments
|
||||||
|
|
||||||
|
update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
|
||||||
|
|
||||||
|
Dir.chdir update_dir do
|
||||||
|
say "Installing RubyGems #{version}"
|
||||||
|
|
||||||
|
# Make sure old rubygems isn't loaded
|
||||||
|
old = ENV["RUBYOPT"]
|
||||||
|
ENV.delete("RUBYOPT") if old
|
||||||
|
installed = system Gem.ruby, 'setup.rb', *args
|
||||||
|
say "RubyGems system software updated" if installed
|
||||||
|
ENV["RUBYOPT"] = old if old
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def rubygems_target_version
|
||||||
|
version = options[:system]
|
||||||
|
update_latest = version == true
|
||||||
|
|
||||||
|
if update_latest then
|
||||||
|
version = Gem::Version.new Gem::VERSION
|
||||||
|
requirement = Gem::Requirement.new ">= #{Gem::VERSION}"
|
||||||
|
else
|
||||||
|
version = Gem::Version.new version
|
||||||
|
requirement = Gem::Requirement.new version
|
||||||
|
end
|
||||||
|
|
||||||
|
rubygems_update = Gem::Specification.new
|
||||||
|
rubygems_update.name = 'rubygems-update'
|
||||||
|
rubygems_update.version = version
|
||||||
|
|
||||||
|
hig = {
|
||||||
|
'rubygems-update' => rubygems_update
|
||||||
|
}
|
||||||
|
|
||||||
|
gems_to_update = which_to_update hig, options[:args], :system
|
||||||
|
_, up_ver = gems_to_update.first
|
||||||
|
|
||||||
|
target = if update_latest then
|
||||||
|
up_ver
|
||||||
|
else
|
||||||
|
version
|
||||||
|
end
|
||||||
|
|
||||||
|
return target, requirement
|
||||||
|
end
|
||||||
|
|
||||||
def update_gem name, version = Gem::Requirement.default
|
def update_gem name, version = Gem::Requirement.default
|
||||||
return if @updated.any? { |spec| spec.name == name }
|
return if @updated.any? { |spec| spec.name == name }
|
||||||
|
|
||||||
@ -118,74 +214,28 @@ class Gem::Commands::UpdateCommand < Gem::Command
|
|||||||
# Update RubyGems software to the latest version.
|
# Update RubyGems software to the latest version.
|
||||||
|
|
||||||
def update_rubygems
|
def update_rubygems
|
||||||
unless options[:args].empty? then
|
check_update_arguments
|
||||||
alert_error "Gem names are not allowed with the --system option"
|
|
||||||
terminate_interaction 1
|
|
||||||
end
|
|
||||||
|
|
||||||
options[:user_install] = false
|
version, requirement = rubygems_target_version
|
||||||
|
|
||||||
# TODO: rename version and other variable name conflicts
|
check_latest_rubygems version
|
||||||
# TODO: get rid of all this indirection on name and other BS
|
|
||||||
|
|
||||||
version = options[:system]
|
update_gem 'rubygems-update', version
|
||||||
if version == true then
|
|
||||||
version = Gem::Version.new Gem::VERSION
|
|
||||||
requirement = Gem::Requirement.new ">= #{Gem::VERSION}"
|
|
||||||
else
|
|
||||||
version = Gem::Version.new version
|
|
||||||
requirement = Gem::Requirement.new version
|
|
||||||
end
|
|
||||||
|
|
||||||
rubygems_update = Gem::Specification.new
|
|
||||||
rubygems_update.name = 'rubygems-update'
|
|
||||||
rubygems_update.version = version
|
|
||||||
|
|
||||||
hig = {
|
|
||||||
'rubygems-update' => rubygems_update
|
|
||||||
}
|
|
||||||
|
|
||||||
gems_to_update = which_to_update hig, options[:args], :system
|
|
||||||
name, up_ver = gems_to_update.first
|
|
||||||
current_ver = Gem.rubygems_version
|
|
||||||
|
|
||||||
target = if options[:system] == true then
|
|
||||||
up_ver
|
|
||||||
else
|
|
||||||
version
|
|
||||||
end
|
|
||||||
|
|
||||||
if current_ver == target then
|
|
||||||
# if options[:system] != true and version == current_ver then
|
|
||||||
say "Latest version currently installed. Aborting."
|
|
||||||
terminate_interaction
|
|
||||||
end
|
|
||||||
|
|
||||||
update_gem name, target
|
|
||||||
|
|
||||||
installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement
|
installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement
|
||||||
version = installed_gems.last.version
|
version = installed_gems.last.version
|
||||||
|
|
||||||
|
install_rubygems version
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_rubygems_arguments # :nodoc:
|
||||||
args = []
|
args = []
|
||||||
args << '--prefix' << Gem.prefix if Gem.prefix
|
args << '--prefix' << Gem.prefix if Gem.prefix
|
||||||
# TODO use --document for >= 1.9 , --no-rdoc --no-ri < 1.9
|
# TODO use --document for >= 1.9 , --no-rdoc --no-ri < 1.9
|
||||||
args << '--no-rdoc' unless options[:document].include? 'rdoc'
|
args << '--no-rdoc' unless options[:document].include? 'rdoc'
|
||||||
args << '--no-ri' unless options[:document].include? 'ri'
|
args << '--no-ri' unless options[:document].include? 'ri'
|
||||||
args << '--no-format-executable' if options[:no_format_executable]
|
args << '--no-format-executable' if options[:no_format_executable]
|
||||||
|
args
|
||||||
update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
|
|
||||||
|
|
||||||
Dir.chdir update_dir do
|
|
||||||
say "Installing RubyGems #{version}"
|
|
||||||
setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
|
|
||||||
|
|
||||||
# Make sure old rubygems isn't loaded
|
|
||||||
old = ENV["RUBYOPT"]
|
|
||||||
ENV.delete("RUBYOPT") if old
|
|
||||||
installed = system setup_cmd
|
|
||||||
say "RubyGems system software updated" if installed
|
|
||||||
ENV["RUBYOPT"] = old if old
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def which_to_update highest_installed_gems, gem_names, system = false
|
def which_to_update highest_installed_gems, gem_names, system = false
|
||||||
@ -195,21 +245,7 @@ class Gem::Commands::UpdateCommand < Gem::Command
|
|||||||
next if not gem_names.empty? and
|
next if not gem_names.empty? and
|
||||||
gem_names.all? { |name| /#{name}/ !~ l_spec.name }
|
gem_names.all? { |name| /#{name}/ !~ l_spec.name }
|
||||||
|
|
||||||
dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
|
highest_remote_ver = highest_remote_version l_spec
|
||||||
dependency.prerelease = options[:prerelease]
|
|
||||||
|
|
||||||
fetcher = Gem::SpecFetcher.fetcher
|
|
||||||
|
|
||||||
spec_tuples, _ = fetcher.search_for_dependency dependency
|
|
||||||
|
|
||||||
matching_gems = spec_tuples.select do |g,_|
|
|
||||||
g.name == l_name and g.match_platform?
|
|
||||||
end
|
|
||||||
|
|
||||||
highest_remote_gem = matching_gems.sort_by { |g,_| g.version }.last
|
|
||||||
|
|
||||||
highest_remote_gem ||= [Gem::NameTuple.null]
|
|
||||||
highest_remote_ver = highest_remote_gem.first.version
|
|
||||||
|
|
||||||
if system or (l_spec.version < highest_remote_ver) then
|
if system or (l_spec.version < highest_remote_ver) then
|
||||||
result << [l_spec.name, [l_spec.version, highest_remote_ver].max]
|
result << [l_spec.name, [l_spec.version, highest_remote_ver].max]
|
||||||
|
@ -7,7 +7,13 @@
|
|||||||
# Base exception class for RubyGems. All exception raised by RubyGems are a
|
# Base exception class for RubyGems. All exception raised by RubyGems are a
|
||||||
# subclass of this one.
|
# subclass of this one.
|
||||||
class Gem::Exception < RuntimeError
|
class Gem::Exception < RuntimeError
|
||||||
attr_accessor :source_exception
|
|
||||||
|
##
|
||||||
|
#--
|
||||||
|
# TODO: remove in RubyGems 3, nobody sets this
|
||||||
|
|
||||||
|
attr_accessor :source_exception # :nodoc:
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Gem::CommandLineError < Gem::Exception; end
|
class Gem::CommandLineError < Gem::Exception; end
|
||||||
|
@ -23,11 +23,13 @@ class Gem::Ext::Builder
|
|||||||
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
|
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
destdir = '"DESTDIR=%s"' % ENV['DESTDIR'] if RUBY_VERSION > '2.0'
|
||||||
|
|
||||||
['', 'install'].each do |target|
|
['', 'install'].each do |target|
|
||||||
# Pass DESTDIR via command line to override what's in MAKEFLAGS
|
# Pass DESTDIR via command line to override what's in MAKEFLAGS
|
||||||
cmd = [
|
cmd = [
|
||||||
make_program,
|
make_program,
|
||||||
'"DESTDIR=%s"' % ENV['DESTDIR'],
|
destdir,
|
||||||
target
|
target
|
||||||
].join(' ').rstrip
|
].join(' ').rstrip
|
||||||
run(cmd, results, "make #{target}".rstrip)
|
run(cmd, results, "make #{target}".rstrip)
|
||||||
|
@ -39,6 +39,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
|
|||||||
run cmd, results
|
run cmd, results
|
||||||
|
|
||||||
ENV["DESTDIR"] = nil
|
ENV["DESTDIR"] = nil
|
||||||
|
ENV["RUBYOPT"] = rubyopt
|
||||||
siteconf.unlink
|
siteconf.unlink
|
||||||
|
|
||||||
make dest_path, results
|
make dest_path, results
|
||||||
@ -49,14 +50,14 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
|
|||||||
destent.exist? or File.rename(ent.path, destent.path)
|
destent.exist? or File.rename(ent.path, destent.path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
results
|
|
||||||
ensure
|
ensure
|
||||||
ENV["RUBYOPT"] = rubyopt
|
ENV["RUBYOPT"] = rubyopt
|
||||||
ENV["DESTDIR"] = destdir
|
ENV["DESTDIR"] = destdir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
t.unlink if t
|
t.unlink if t and t.path
|
||||||
|
|
||||||
|
results
|
||||||
ensure
|
ensure
|
||||||
FileUtils.rm_rf tmp_dest if tmp_dest
|
FileUtils.rm_rf tmp_dest if tmp_dest
|
||||||
end
|
end
|
||||||
|
@ -36,6 +36,8 @@ class Gem::PathSupport
|
|||||||
@spec_cache_dir =
|
@spec_cache_dir =
|
||||||
env["GEM_SPEC_CACHE"] || ENV["GEM_SPEC_CACHE"] ||
|
env["GEM_SPEC_CACHE"] || ENV["GEM_SPEC_CACHE"] ||
|
||||||
Gem.default_spec_cache_dir
|
Gem.default_spec_cache_dir
|
||||||
|
|
||||||
|
@spec_cache_dir = @spec_cache_dir.dup.untaint
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -324,7 +324,11 @@ class Gem::RemoteFetcher
|
|||||||
# connections to reduce connect overhead.
|
# connections to reduce connect overhead.
|
||||||
|
|
||||||
def request(uri, request_class, last_modified = nil)
|
def request(uri, request_class, last_modified = nil)
|
||||||
Gem::Request.new(uri, request_class, last_modified, @proxy).fetch
|
request = Gem::Request.new uri, request_class, last_modified, @proxy
|
||||||
|
|
||||||
|
request.fetch do |req|
|
||||||
|
yield req if block_given?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def https?(uri)
|
def https?(uri)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require 'net/http'
|
require 'net/http'
|
||||||
|
require 'thread'
|
||||||
require 'time'
|
require 'time'
|
||||||
require 'rubygems/user_interaction'
|
require 'rubygems/user_interaction'
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ class Gem::Request
|
|||||||
@last_modified = last_modified
|
@last_modified = last_modified
|
||||||
@requests = Hash.new 0
|
@requests = Hash.new 0
|
||||||
@connections = {}
|
@connections = {}
|
||||||
|
@connections_mutex = Mutex.new
|
||||||
@user_agent = user_agent
|
@user_agent = user_agent
|
||||||
|
|
||||||
@proxy_uri =
|
@proxy_uri =
|
||||||
@ -82,8 +84,11 @@ class Gem::Request
|
|||||||
end
|
end
|
||||||
|
|
||||||
connection_id = [Thread.current.object_id, *net_http_args].join ':'
|
connection_id = [Thread.current.object_id, *net_http_args].join ':'
|
||||||
|
|
||||||
|
connection = @connections_mutex.synchronize do
|
||||||
@connections[connection_id] ||= Net::HTTP.new(*net_http_args)
|
@connections[connection_id] ||= Net::HTTP.new(*net_http_args)
|
||||||
connection = @connections[connection_id]
|
@connections[connection_id]
|
||||||
|
end
|
||||||
|
|
||||||
if https?(uri) and not connection.started? then
|
if https?(uri) and not connection.started? then
|
||||||
configure_connection_for_https(connection)
|
configure_connection_for_https(connection)
|
||||||
|
@ -74,6 +74,12 @@ class Gem::SpecFetcher
|
|||||||
|
|
||||||
list, errors = available_specs(type)
|
list, errors = available_specs(type)
|
||||||
list.each do |source, specs|
|
list.each do |source, specs|
|
||||||
|
if dependency.name.is_a?(String) && specs.respond_to?(:bsearch)
|
||||||
|
start_index = (0 ... specs.length).bsearch{ |i| specs[i].name >= dependency.name }
|
||||||
|
end_index = (0 ... specs.length).bsearch{ |i| specs[i].name > dependency.name }
|
||||||
|
specs = specs[start_index ... end_index] if start_index && end_index
|
||||||
|
end
|
||||||
|
|
||||||
found[source] = specs.select do |tup|
|
found[source] = specs.select do |tup|
|
||||||
if dependency.match?(tup)
|
if dependency.match?(tup)
|
||||||
if matching_platform and !Gem::Platform.match(tup.platform)
|
if matching_platform and !Gem::Platform.match(tup.platform)
|
||||||
@ -214,15 +220,15 @@ class Gem::SpecFetcher
|
|||||||
def tuples_for(source, type, gracefully_ignore=false)
|
def tuples_for(source, type, gracefully_ignore=false)
|
||||||
cache = @caches[type]
|
cache = @caches[type]
|
||||||
|
|
||||||
if gracefully_ignore
|
tuples =
|
||||||
begin
|
begin
|
||||||
cache[source.uri] ||= source.load_specs(type)
|
cache[source.uri] ||= source.load_specs(type)
|
||||||
rescue Gem::RemoteFetcher::FetchError
|
rescue Gem::RemoteFetcher::FetchError
|
||||||
|
raise unless gracefully_ignore
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
else
|
|
||||||
cache[source.uri] ||= source.load_specs(type)
|
tuples.sort_by { |tup| tup.name }
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -954,7 +954,7 @@ class Gem::Specification < Gem::BasicSpecification
|
|||||||
result.map(&:last).map(&:values).flatten.reject { |spec|
|
result.map(&:last).map(&:values).flatten.reject { |spec|
|
||||||
minimum = native[spec.name]
|
minimum = native[spec.name]
|
||||||
minimum && spec.version < minimum
|
minimum && spec.version < minimum
|
||||||
}
|
}.sort_by{ |tup| tup.name }
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -1853,11 +1853,6 @@ class Gem::Specification < Gem::BasicSpecification
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Prevent ruby hitting spec.method_missing when [[spec]].flatten is called
|
|
||||||
def to_ary # :nodoc:
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Normalize the list of files so that:
|
# Normalize the list of files so that:
|
||||||
# * All file lists have redundancies removed.
|
# * All file lists have redundancies removed.
|
||||||
@ -2008,6 +2003,10 @@ class Gem::Specification < Gem::BasicSpecification
|
|||||||
@requirements = Array req
|
@requirements = Array req
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def respond_to_missing? m, include_private = false # :nodoc:
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns the full path to this spec's ri directory.
|
# Returns the full path to this spec's ri directory.
|
||||||
|
|
||||||
|
@ -6,6 +6,13 @@ module Gem
|
|||||||
# :nodoc:
|
# :nodoc:
|
||||||
PREFIX = "# stub: "
|
PREFIX = "# stub: "
|
||||||
|
|
||||||
|
OPEN_MODE = # :nodoc:
|
||||||
|
if Object.const_defined? :Encoding then
|
||||||
|
'r:UTF-8:-'
|
||||||
|
else
|
||||||
|
'r'
|
||||||
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
class StubLine
|
class StubLine
|
||||||
attr_reader :parts
|
attr_reader :parts
|
||||||
@ -96,7 +103,7 @@ module Gem
|
|||||||
|
|
||||||
def data
|
def data
|
||||||
unless @data
|
unless @data
|
||||||
File.open(filename, "r:UTF-8:-") do |file|
|
open filename, OPEN_MODE do |file|
|
||||||
begin
|
begin
|
||||||
file.readline # discard encoding line
|
file.readline # discard encoding line
|
||||||
stubline = file.readline.chomp
|
stubline = file.readline.chomp
|
||||||
|
@ -13,8 +13,13 @@ end
|
|||||||
|
|
||||||
class TestGem < Gem::TestCase
|
class TestGem < Gem::TestCase
|
||||||
|
|
||||||
|
PLUGINS_LOADED = []
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
|
|
||||||
|
PLUGINS_LOADED.clear
|
||||||
|
|
||||||
common_installer_setup
|
common_installer_setup
|
||||||
|
|
||||||
ENV.delete 'RUBYGEMS_GEMDEPS'
|
ENV.delete 'RUBYGEMS_GEMDEPS'
|
||||||
@ -345,9 +350,7 @@ class TestGem < Gem::TestCase
|
|||||||
spec
|
spec
|
||||||
}
|
}
|
||||||
|
|
||||||
# HACK should be Gem.refresh
|
Gem.refresh
|
||||||
Gem.searcher = nil
|
|
||||||
Gem::Specification.reset
|
|
||||||
|
|
||||||
expected = [
|
expected = [
|
||||||
File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
|
File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
|
||||||
@ -361,6 +364,37 @@ class TestGem < Gem::TestCase
|
|||||||
assert_equal cwd, $LOAD_PATH.shift
|
assert_equal cwd, $LOAD_PATH.shift
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_self_find_latest_files
|
||||||
|
cwd = File.expand_path("test/rubygems", @@project_dir)
|
||||||
|
$LOAD_PATH.unshift cwd
|
||||||
|
|
||||||
|
discover_path = File.join 'lib', 'sff', 'discover.rb'
|
||||||
|
|
||||||
|
_, foo2 = %w(1 2).map { |version|
|
||||||
|
spec = quick_gem 'sff', version do |s|
|
||||||
|
s.files << discover_path
|
||||||
|
end
|
||||||
|
|
||||||
|
write_file(File.join 'gems', spec.full_name, discover_path) do |fp|
|
||||||
|
fp.puts "# #{spec.full_name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
spec
|
||||||
|
}
|
||||||
|
|
||||||
|
Gem.refresh
|
||||||
|
|
||||||
|
expected = [
|
||||||
|
File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
|
||||||
|
File.join(foo2.full_gem_path, discover_path),
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal expected, Gem.find_latest_files('sff/discover')
|
||||||
|
assert_equal expected, Gem.find_latest_files('sff/**.rb'), '[ruby-core:31730]'
|
||||||
|
ensure
|
||||||
|
assert_equal cwd, $LOAD_PATH.shift
|
||||||
|
end
|
||||||
|
|
||||||
def test_self_latest_spec_for
|
def test_self_latest_spec_for
|
||||||
a1 = quick_spec 'a', 1
|
a1 = quick_spec 'a', 1
|
||||||
a2 = quick_spec 'a', 2
|
a2 = quick_spec 'a', 2
|
||||||
@ -883,14 +917,20 @@ class TestGem < Gem::TestCase
|
|||||||
Dir.chdir @tempdir do
|
Dir.chdir @tempdir do
|
||||||
FileUtils.mkdir_p 'lib'
|
FileUtils.mkdir_p 'lib'
|
||||||
File.open plugin_path, "w" do |fp|
|
File.open plugin_path, "w" do |fp|
|
||||||
fp.puts "class TestGem; TEST_SPEC_PLUGIN_LOAD = :loaded; end"
|
fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end"
|
||||||
end
|
end
|
||||||
|
|
||||||
foo = quick_spec 'foo', '1' do |s|
|
foo1 = quick_spec 'foo', '1' do |s|
|
||||||
s.files << plugin_path
|
s.files << plugin_path
|
||||||
end
|
end
|
||||||
|
|
||||||
install_gem foo
|
install_gem foo1
|
||||||
|
|
||||||
|
foo2 = quick_spec 'foo', '2' do |s|
|
||||||
|
s.files << plugin_path
|
||||||
|
end
|
||||||
|
|
||||||
|
install_gem foo2
|
||||||
end
|
end
|
||||||
|
|
||||||
Gem.searcher = nil
|
Gem.searcher = nil
|
||||||
@ -900,7 +940,7 @@ class TestGem < Gem::TestCase
|
|||||||
|
|
||||||
Gem.load_plugins
|
Gem.load_plugins
|
||||||
|
|
||||||
assert_equal :loaded, TEST_SPEC_PLUGIN_LOAD
|
assert_equal %w[plugin], PLUGINS_LOADED
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_load_env_plugins
|
def test_load_env_plugins
|
||||||
|
@ -58,7 +58,7 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
|
|
||||||
use_ui @ui do
|
use_ui @ui do
|
||||||
assert_raises Gem::MockGemUi::TermError do
|
assert_raises Gem::MockGemUi::TermError do
|
||||||
@command_manager.run 'interrupt'
|
@command_manager.run %w[interrupt]
|
||||||
end
|
end
|
||||||
assert_equal '', ui.output
|
assert_equal '', ui.output
|
||||||
assert_equal "ERROR: Interrupted\n", ui.error
|
assert_equal "ERROR: Interrupted\n", ui.error
|
||||||
@ -75,7 +75,7 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
@command_manager.register_command :crash
|
@command_manager.register_command :crash
|
||||||
use_ui @ui do
|
use_ui @ui do
|
||||||
assert_raises Gem::MockGemUi::TermError do
|
assert_raises Gem::MockGemUi::TermError do
|
||||||
@command_manager.run 'crash'
|
@command_manager.run %w[crash]
|
||||||
end
|
end
|
||||||
assert_equal '', ui.output
|
assert_equal '', ui.output
|
||||||
err = ui.error.split("\n").first
|
err = ui.error.split("\n").first
|
||||||
@ -89,7 +89,7 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
def test_process_args_bad_arg
|
def test_process_args_bad_arg
|
||||||
use_ui @ui do
|
use_ui @ui do
|
||||||
assert_raises Gem::MockGemUi::TermError do
|
assert_raises Gem::MockGemUi::TermError do
|
||||||
@command_manager.process_args("--bad-arg")
|
@command_manager.process_args %w[--bad-arg]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
#check defaults
|
#check defaults
|
||||||
@command_manager.process_args("install")
|
@command_manager.process_args %w[install]
|
||||||
assert_equal %w[ri], check_options[:document].sort
|
assert_equal %w[ri], check_options[:document].sort
|
||||||
assert_equal false, check_options[:force]
|
assert_equal false, check_options[:force]
|
||||||
assert_equal :both, check_options[:domain]
|
assert_equal :both, check_options[:domain]
|
||||||
@ -118,8 +118,10 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
|
|
||||||
#check settings
|
#check settings
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args(
|
@command_manager.process_args %w[
|
||||||
"install --force --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ")
|
install --force --local --rdoc --install-dir .
|
||||||
|
--version 3.0 --no-wrapper --bindir .
|
||||||
|
]
|
||||||
assert_equal %w[rdoc ri], check_options[:document].sort
|
assert_equal %w[rdoc ri], check_options[:document].sort
|
||||||
assert_equal true, check_options[:force]
|
assert_equal true, check_options[:force]
|
||||||
assert_equal :local, check_options[:domain]
|
assert_equal :local, check_options[:domain]
|
||||||
@ -130,17 +132,17 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
|
|
||||||
#check remote domain
|
#check remote domain
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args("install --remote")
|
@command_manager.process_args %w[install --remote]
|
||||||
assert_equal :remote, check_options[:domain]
|
assert_equal :remote, check_options[:domain]
|
||||||
|
|
||||||
#check both domain
|
#check both domain
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args("install --both")
|
@command_manager.process_args %w[install --both]
|
||||||
assert_equal :both, check_options[:domain]
|
assert_equal :both, check_options[:domain]
|
||||||
|
|
||||||
#check both domain
|
#check both domain
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args("install --both")
|
@command_manager.process_args %w[install --both]
|
||||||
assert_equal :both, check_options[:domain]
|
assert_equal :both, check_options[:domain]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -155,12 +157,12 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
#check defaults
|
#check defaults
|
||||||
@command_manager.process_args("uninstall")
|
@command_manager.process_args %w[uninstall]
|
||||||
assert_equal Gem::Requirement.default, check_options[:version]
|
assert_equal Gem::Requirement.default, check_options[:version]
|
||||||
|
|
||||||
#check settings
|
#check settings
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args("uninstall foobar --version 3.0")
|
@command_manager.process_args %w[uninstall foobar --version 3.0]
|
||||||
assert_equal "foobar", check_options[:args].first
|
assert_equal "foobar", check_options[:args].first
|
||||||
assert_equal Gem::Requirement.new('3.0'), check_options[:version]
|
assert_equal Gem::Requirement.new('3.0'), check_options[:version]
|
||||||
end
|
end
|
||||||
@ -175,12 +177,12 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
#check defaults
|
#check defaults
|
||||||
@command_manager.process_args("check")
|
@command_manager.process_args %w[check]
|
||||||
assert_equal true, check_options[:alien]
|
assert_equal true, check_options[:alien]
|
||||||
|
|
||||||
#check settings
|
#check settings
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args("check foobar --alien")
|
@command_manager.process_args %w[check foobar --alien]
|
||||||
assert_equal true, check_options[:alien]
|
assert_equal true, check_options[:alien]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -194,12 +196,12 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
#check defaults
|
#check defaults
|
||||||
@command_manager.process_args("build")
|
@command_manager.process_args %w[build]
|
||||||
#NOTE: Currently no defaults
|
#NOTE: Currently no defaults
|
||||||
|
|
||||||
#check settings
|
#check settings
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args("build foobar.rb")
|
@command_manager.process_args %w[build foobar.rb]
|
||||||
assert_equal 'foobar.rb', check_options[:args].first
|
assert_equal 'foobar.rb', check_options[:args].first
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -213,26 +215,26 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
#check defaults
|
#check defaults
|
||||||
@command_manager.process_args("query")
|
@command_manager.process_args %w[query]
|
||||||
assert_equal(//, check_options[:name])
|
assert_equal(//, check_options[:name])
|
||||||
assert_equal :local, check_options[:domain]
|
assert_equal :local, check_options[:domain]
|
||||||
assert_equal false, check_options[:details]
|
assert_equal false, check_options[:details]
|
||||||
|
|
||||||
#check settings
|
#check settings
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args("query --name foobar --local --details")
|
@command_manager.process_args %w[query --name foobar --local --details]
|
||||||
assert_equal(/foobar/i, check_options[:name])
|
assert_equal(/foobar/i, check_options[:name])
|
||||||
assert_equal :local, check_options[:domain]
|
assert_equal :local, check_options[:domain]
|
||||||
assert_equal true, check_options[:details]
|
assert_equal true, check_options[:details]
|
||||||
|
|
||||||
#remote domain
|
#remote domain
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args("query --remote")
|
@command_manager.process_args %w[query --remote]
|
||||||
assert_equal :remote, check_options[:domain]
|
assert_equal :remote, check_options[:domain]
|
||||||
|
|
||||||
#both (local/remote) domains
|
#both (local/remote) domains
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args("query --both")
|
@command_manager.process_args %w[query --both]
|
||||||
assert_equal :both, check_options[:domain]
|
assert_equal :both, check_options[:domain]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -246,12 +248,12 @@ class TestGemCommandManager < Gem::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
#check defaults
|
#check defaults
|
||||||
@command_manager.process_args("update")
|
@command_manager.process_args %w[update]
|
||||||
assert_includes check_options[:document], 'rdoc'
|
assert_includes check_options[:document], 'rdoc'
|
||||||
|
|
||||||
#check settings
|
#check settings
|
||||||
check_options = nil
|
check_options = nil
|
||||||
@command_manager.process_args("update --force --rdoc --install-dir .")
|
@command_manager.process_args %w[update --force --rdoc --install-dir .]
|
||||||
assert_includes check_options[:document], 'ri'
|
assert_includes check_options[:document], 'ri'
|
||||||
assert_equal true, check_options[:force]
|
assert_equal true, check_options[:force]
|
||||||
assert_equal Dir.pwd, check_options[:install_dir]
|
assert_equal Dir.pwd, check_options[:install_dir]
|
||||||
|
@ -91,6 +91,34 @@ class TestGemCommandsContentsCommand < Gem::TestCase
|
|||||||
assert_equal "", @ui.error
|
assert_equal "", @ui.error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_execute_missing_single
|
||||||
|
@cmd.options[:args] = %w[foo]
|
||||||
|
|
||||||
|
assert_raises Gem::MockGemUi::TermError do
|
||||||
|
use_ui @ui do
|
||||||
|
@cmd.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_match "Unable to find gem 'foo'", @ui.output
|
||||||
|
assert_empty @ui.error
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_execute_missing_multiple
|
||||||
|
@cmd.options[:args] = %w[foo bar]
|
||||||
|
|
||||||
|
gem 'foo'
|
||||||
|
|
||||||
|
use_ui @ui do
|
||||||
|
@cmd.execute
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_match "lib/foo.rb", @ui.output
|
||||||
|
assert_match "Unable to find gem 'bar'", @ui.output
|
||||||
|
|
||||||
|
assert_empty @ui.error
|
||||||
|
end
|
||||||
|
|
||||||
def test_execute_multiple
|
def test_execute_multiple
|
||||||
@cmd.options[:args] = %w[foo bar]
|
@cmd.options[:args] = %w[foo bar]
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ class TestGemCommandsHelpCommand < Gem::TestCase
|
|||||||
def test_gem_help_bad
|
def test_gem_help_bad
|
||||||
util_gem 'bad' do |out, err|
|
util_gem 'bad' do |out, err|
|
||||||
assert_equal('', out)
|
assert_equal('', out)
|
||||||
assert_match(/Unknown command bad. Try gem help commands\n/, err)
|
assert_match "Unknown command bad", err
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -104,9 +104,9 @@ class TestGemCommandsPristineCommand < Gem::TestCase
|
|||||||
assert_path_exists gem_exec
|
assert_path_exists gem_exec
|
||||||
|
|
||||||
if win_platform?
|
if win_platform?
|
||||||
assert_match /\A#!\s*ruby/, File.read(gem_exec)
|
assert_match %r%\A#!\s*ruby%, File.read(gem_exec)
|
||||||
else
|
else
|
||||||
assert_match /\A#!\s*\/usr\/bin\/env ruby/, File.read(gem_exec)
|
assert_match %r%\A#!\s*/usr/bin/env ruby%, File.read(gem_exec)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -195,6 +195,34 @@ pl (1)
|
|||||||
assert_equal '', @ui.error
|
assert_equal '', @ui.error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_execute_installed_inverse
|
||||||
|
@cmd.handle_options %w[-n a --no-installed]
|
||||||
|
|
||||||
|
e = assert_raises Gem::MockGemUi::TermError do
|
||||||
|
use_ui @ui do
|
||||||
|
@cmd.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal "false\n", @ui.output
|
||||||
|
assert_equal '', @ui.error
|
||||||
|
|
||||||
|
assert_equal 1, e.exit_code
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_execute_installed_inverse_not_installed
|
||||||
|
@cmd.handle_options %w[-n not_installed --no-installed]
|
||||||
|
|
||||||
|
assert_raises Gem::MockGemUi::SystemExitException do
|
||||||
|
use_ui @ui do
|
||||||
|
@cmd.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal "true\n", @ui.output
|
||||||
|
assert_equal '', @ui.error
|
||||||
|
end
|
||||||
|
|
||||||
def test_execute_installed_no_name
|
def test_execute_installed_no_name
|
||||||
@cmd.handle_options %w[--installed]
|
@cmd.handle_options %w[--installed]
|
||||||
|
|
||||||
|
17
test/rubygems/test_gem_commands_search_command.rb
Normal file
17
test/rubygems/test_gem_commands_search_command.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
require 'rubygems/test_case'
|
||||||
|
require 'rubygems/commands/search_command'
|
||||||
|
|
||||||
|
class TestGemCommandsSearchCommand < Gem::TestCase
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
|
||||||
|
@cmd = Gem::Commands::SearchCommand.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_initialize
|
||||||
|
assert_equal :remote, @cmd.defaults[:domain]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -16,6 +16,20 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
|
|||||||
@executable = File.join(@gemhome, 'bin', 'executable')
|
@executable = File.join(@gemhome, 'bin', 'executable')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_execute_all_gem_names
|
||||||
|
@cmd.options[:args] = %w[a b]
|
||||||
|
@cmd.options[:all] = true
|
||||||
|
|
||||||
|
assert_raises Gem::MockGemUi::TermError do
|
||||||
|
use_ui @ui do
|
||||||
|
@cmd.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal "ERROR: Gem names and --all may not be used together\n",
|
||||||
|
@ui.error
|
||||||
|
end
|
||||||
|
|
||||||
def test_execute_dependency_order
|
def test_execute_dependency_order
|
||||||
c = quick_gem 'c' do |spec|
|
c = quick_gem 'c' do |spec|
|
||||||
spec.add_dependency 'a'
|
spec.add_dependency 'a'
|
||||||
@ -43,6 +57,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
|
|||||||
|
|
||||||
def test_execute_removes_executable
|
def test_execute_removes_executable
|
||||||
ui = Gem::MockGemUi.new
|
ui = Gem::MockGemUi.new
|
||||||
|
|
||||||
util_setup_gem ui
|
util_setup_gem ui
|
||||||
|
|
||||||
build_rake_in do
|
build_rake_in do
|
||||||
@ -175,5 +190,23 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
|
|||||||
assert Gem::Specification.find_all_by_name('x').length == 0
|
assert Gem::Specification.find_all_by_name('x').length == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_execute_all
|
||||||
|
ui = Gem::MockGemUi.new "y\n"
|
||||||
|
|
||||||
|
util_make_gems
|
||||||
|
util_setup_gem ui
|
||||||
|
|
||||||
|
assert Gem::Specification.find_all_by_name('a').length > 1
|
||||||
|
|
||||||
|
@cmd.options[:all] = true
|
||||||
|
@cmd.options[:args] = []
|
||||||
|
|
||||||
|
use_ui ui do
|
||||||
|
@cmd.execute
|
||||||
|
end
|
||||||
|
|
||||||
|
refute_includes Gem::Specification.all_names, 'a'
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
58
test/rubygems/test_gem_ext_builder.rb
Normal file
58
test/rubygems/test_gem_ext_builder.rb
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
require 'rubygems/test_case'
|
||||||
|
require 'rubygems/ext'
|
||||||
|
|
||||||
|
class TestGemExtBuilder < Gem::TestCase
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
|
||||||
|
@ext = File.join @tempdir, 'ext'
|
||||||
|
@dest_path = File.join @tempdir, 'prefix'
|
||||||
|
|
||||||
|
FileUtils.mkdir_p @ext
|
||||||
|
FileUtils.mkdir_p @dest_path
|
||||||
|
|
||||||
|
@orig_DESTDIR = ENV['DESTDIR']
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
ENV['DESTDIR'] = @orig_DESTDIR
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_class_make
|
||||||
|
ENV['DESTDIR'] = 'destination'
|
||||||
|
results = []
|
||||||
|
|
||||||
|
Dir.chdir @ext do
|
||||||
|
open 'Makefile', 'w' do |io|
|
||||||
|
io.puts <<-MAKEFILE
|
||||||
|
all:
|
||||||
|
\t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}"
|
||||||
|
|
||||||
|
install:
|
||||||
|
\t@#{Gem.ruby} -e "puts %Q{install: \#{ENV['DESTDIR']}}"
|
||||||
|
MAKEFILE
|
||||||
|
end
|
||||||
|
|
||||||
|
Gem::Ext::Builder.make @dest_path, results
|
||||||
|
end
|
||||||
|
|
||||||
|
results = results.join "\n"
|
||||||
|
|
||||||
|
|
||||||
|
if RUBY_VERSION > '2.0' then
|
||||||
|
assert_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%, results
|
||||||
|
assert_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
|
||||||
|
else
|
||||||
|
refute_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%, results
|
||||||
|
refute_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_match %r%^all: destination$%, results
|
||||||
|
assert_match %r%^install: destination$%, results
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -27,7 +27,10 @@ class TestGemExtExtConfBuilder < Gem::TestCase
|
|||||||
output = []
|
output = []
|
||||||
|
|
||||||
Dir.chdir @ext do
|
Dir.chdir @ext do
|
||||||
|
result =
|
||||||
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
|
||||||
|
|
||||||
|
assert_same result, output
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
|
assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
|
||||||
@ -108,6 +111,42 @@ checking for main\(\) in .*?nonexistent/m, error.message)
|
|||||||
assert_equal("#{Gem.ruby} extconf.rb", output[0])
|
assert_equal("#{Gem.ruby} extconf.rb", output[0])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_class_build_unconventional
|
||||||
|
if vc_windows? && !nmake_found?
|
||||||
|
skip("test_class_build skipped - nmake not found")
|
||||||
|
end
|
||||||
|
|
||||||
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
||||||
|
extconf.puts <<-'EXTCONF'
|
||||||
|
include RbConfig
|
||||||
|
|
||||||
|
ruby_exe = "#{CONFIG['RUBY_INSTALL_NAME']}#{CONFIG['EXEEXT']}"
|
||||||
|
ruby = File.join CONFIG['bindir'], ruby_exe
|
||||||
|
|
||||||
|
open 'Makefile', 'w' do |io|
|
||||||
|
io.write <<-Makefile
|
||||||
|
all: ruby
|
||||||
|
install: ruby
|
||||||
|
|
||||||
|
ruby:
|
||||||
|
\t#{ruby} -e0
|
||||||
|
|
||||||
|
Makefile
|
||||||
|
end
|
||||||
|
EXTCONF
|
||||||
|
end
|
||||||
|
|
||||||
|
output = []
|
||||||
|
|
||||||
|
Dir.chdir @ext do
|
||||||
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_contains_make_command '', output[2]
|
||||||
|
assert_contains_make_command 'install', output[4]
|
||||||
|
assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
|
||||||
|
end
|
||||||
|
|
||||||
def test_class_make
|
def test_class_make
|
||||||
if vc_windows? && !nmake_found?
|
if vc_windows? && !nmake_found?
|
||||||
skip("test_class_make skipped - nmake not found")
|
skip("test_class_make skipped - nmake not found")
|
||||||
|
@ -580,6 +580,17 @@ gems:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_request_block
|
||||||
|
fetcher = Gem::RemoteFetcher.new nil
|
||||||
|
|
||||||
|
assert_throws :block_called do
|
||||||
|
fetcher.request URI('http://example'), Net::HTTP::Get do |req|
|
||||||
|
assert_kind_of Net::HTTPGenericRequest, req
|
||||||
|
throw :block_called
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_yaml_error_on_size
|
def test_yaml_error_on_size
|
||||||
use_ui @ui do
|
use_ui @ui do
|
||||||
self.class.enable_yaml = false
|
self.class.enable_yaml = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user