summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-14 08:59:02 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-14 08:59:02 +0000
commit269503b544247b5b3e30dbe60a0bab4f2ca00e4e ()
treea6d0a3a9b34017c4c84d997152a3aaf3086e1ce1
parent2614d9ba2fb5ad171200cccc88f42fa659b527c6 (diff)
Revert r42938 "* lib/rubygems: Update to RubyGems 2.1.3"
It breaks build. http://u64.rubyci.org/~chkbuild/ruby-trunk/log/20130913T200302Z.diff.html.gz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog15
-rw-r--r--lib/rubygems.rb118
-rw-r--r--lib/rubygems/available_set.rb68
-rw-r--r--lib/rubygems/command_manager.rb77
-rw-r--r--lib/rubygems/commands/build_command.rb19
-rw-r--r--lib/rubygems/commands/cert_command.rb107
-rw-r--r--lib/rubygems/commands/check_command.rb7
-rw-r--r--lib/rubygems/commands/cleanup_command.rb14
-rw-r--r--lib/rubygems/commands/contents_command.rb167
-rw-r--r--lib/rubygems/commands/dependency_command.rb158
-rw-r--r--lib/rubygems/commands/environment_command.rb126
-rw-r--r--lib/rubygems/commands/fetch_command.rb16
-rw-r--r--lib/rubygems/commands/help_command.rb140
-rw-r--r--lib/rubygems/commands/install_command.rb126
-rw-r--r--lib/rubygems/commands/list_command.rb13
-rw-r--r--lib/rubygems/commands/mirror_command.rb6
-rw-r--r--lib/rubygems/commands/outdated_command.rb21
-rw-r--r--lib/rubygems/commands/owner_command.rb17
-rw-r--r--lib/rubygems/commands/pristine_command.rb19
-rw-r--r--lib/rubygems/commands/push_command.rb10
-rw-r--r--lib/rubygems/commands/query_command.rb9
-rw-r--r--lib/rubygems/commands/rdoc_command.rb8
-rw-r--r--lib/rubygems/commands/search_command.rb15
-rw-r--r--lib/rubygems/commands/sources_command.rb202
-rw-r--r--lib/rubygems/commands/specification_command.rb16
-rw-r--r--lib/rubygems/commands/stale_command.rb10
-rw-r--r--lib/rubygems/commands/uninstall_command.rb47
-rw-r--r--lib/rubygems/commands/unpack_command.rb18
-rw-r--r--lib/rubygems/commands/update_command.rb195
-rw-r--r--lib/rubygems/commands/which_command.rb11
-rw-r--r--lib/rubygems/commands/yank_command.rb18
-rw-r--r--lib/rubygems/config_file.rb17
-rwxr-xr-xlib/rubygems/core_ext/kernel_require.rb30
-rw-r--r--lib/rubygems/defaults.rb15
-rw-r--r--lib/rubygems/dependency.rb6
-rw-r--r--lib/rubygems/dependency_installer.rb339
-rw-r--r--lib/rubygems/dependency_resolver.rb721
-rw-r--r--lib/rubygems/exceptions.rb89
-rw-r--r--lib/rubygems/ext/builder.rb120
-rw-r--r--lib/rubygems/gem_runner.rb26
-rw-r--r--lib/rubygems/gemcutter_utilities.rb114
-rw-r--r--lib/rubygems/install_update_options.rb3
-rw-r--r--lib/rubygems/installer.rb148
-rw-r--r--lib/rubygems/name_tuple.rb25
-rw-r--r--lib/rubygems/package.rb81
-rw-r--r--lib/rubygems/package/tar_test_case.rb18
-rw-r--r--lib/rubygems/package/tar_writer.rb47
-rw-r--r--lib/rubygems/path_support.rb10
-rw-r--r--lib/rubygems/platform.rb12
-rw-r--r--lib/rubygems/psych_additions.rb2
-rw-r--r--lib/rubygems/remote_fetcher.rb266
-rw-r--r--lib/rubygems/request_set.rb251
-rw-r--r--lib/rubygems/security.rb55
-rw-r--r--lib/rubygems/security/policy.rb49
-rw-r--r--lib/rubygems/security/signer.rb24
-rw-r--r--lib/rubygems/server.rb6
-rw-r--r--lib/rubygems/source.rb36
-rw-r--r--lib/rubygems/source_local.rb91
-rw-r--r--lib/rubygems/source_specific_file.rb28
-rw-r--r--lib/rubygems/spec_fetcher.rb20
-rw-r--r--lib/rubygems/specification.rb291
-rw-r--r--lib/rubygems/test_case.rb200
-rw-r--r--lib/rubygems/uninstaller.rb23
-rw-r--r--lib/rubygems/version.rb16
-rw-r--r--lib/rubygems/version_option.rb10
-rw-r--r--test/rubygems/ca_cert.pem23
-rw-r--r--test/rubygems/test_gem.rb557
-rw-r--r--test/rubygems/test_gem_command_manager.rb44
-rw-r--r--test/rubygems/test_gem_commands_cert_command.rb168
-rw-r--r--test/rubygems/test_gem_commands_cleanup_command.rb15
-rw-r--r--test/rubygems/test_gem_commands_contents_command.rb36
-rw-r--r--test/rubygems/test_gem_commands_environment_command.rb10
-rw-r--r--test/rubygems/test_gem_commands_fetch_command.rb30
-rw-r--r--test/rubygems/test_gem_commands_help_command.rb9
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb66
-rw-r--r--test/rubygems/test_gem_commands_owner_command.rb49
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb30
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_uninstall_command.rb42
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb3
-rw-r--r--test/rubygems/test_gem_config_file.rb12
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb100
-rw-r--r--test/rubygems/test_gem_dependency_resolver.rb49
-rw-r--r--test/rubygems/test_gem_ext_builder.rb93
-rw-r--r--test/rubygems/test_gem_ext_ext_conf_builder.rb9
-rw-r--r--test/rubygems/test_gem_gem_runner.rb30
-rw-r--r--test/rubygems/test_gem_gemcutter_utilities.rb25
-rw-r--r--test/rubygems/test_gem_install_update_options.rb5
-rw-r--r--test/rubygems/test_gem_installer.rb247
-rw-r--r--test/rubygems/test_gem_name_tuple.rb22
-rw-r--r--test/rubygems/test_gem_package.rb134
-rw-r--r--test/rubygems/test_gem_package_old.rb8
-rw-r--r--test/rubygems/test_gem_package_tar_reader.rb17
-rw-r--r--test/rubygems/test_gem_package_tar_reader_entry.rb2
-rw-r--r--test/rubygems/test_gem_package_tar_writer.rb134
-rw-r--r--test/rubygems/test_gem_path_support.rb17
-rw-r--r--test/rubygems/test_gem_platform.rb18
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb333
-rw-r--r--test/rubygems/test_gem_security.rb60
-rw-r--r--test/rubygems/test_gem_security_policy.rb54
-rw-r--r--test/rubygems/test_gem_security_signer.rb20
-rw-r--r--test/rubygems/test_gem_security_trust_dir.rb6
-rw-r--r--test/rubygems/test_gem_source.rb31
-rw-r--r--test/rubygems/test_gem_source_local.rb37
-rw-r--r--test/rubygems/test_gem_source_specific_file.rb40
-rw-r--r--test/rubygems/test_gem_spec_fetcher.rb15
-rw-r--r--test/rubygems/test_gem_specification.rb474
-rw-r--r--test/rubygems/test_gem_uninstaller.rb14
-rw-r--r--test/rubygems/test_gem_version.rb15
-rw-r--r--test/rubygems/test_gem_version_option.rb64
110 files changed, 4800 insertions, 3351 deletions
@@ -8,7 +8,13 @@ Sat Sep 14 06:08:10 2013 Eric Hodel <[email protected]>
constants. (These won't show up in RDoc until a new RDoc is
imported.)
-Sat Sep 14 04:57:51 2013 Eric Hodel <[email protected]>
* lib/rubygems: Update to RubyGems 2.1.3
@@ -26,13 +32,6 @@ Sat Sep 14 04:57:51 2013 Eric Hodel <[email protected]>
* NEWS: Updated for RubyGems 2.1.3
-
-Thu Sep 12 14:58:58 2013 NARUSE, Yui <[email protected]>
-
- * lib/uri/generic.rb (URI::Generic.find_proxy): return nil if
- http_proxy environment variable is empty string.
- [ruby-core:57140] [Bug #8898]
-
Thu Sep 12 22:40:03 2013 Nobuyoshi Nakada <[email protected]>
* configure.in (RUBY_CHECK_SIGNEDNESS): macro to check signedness of a
@@ -8,7 +8,7 @@
require 'rbconfig'
module Gem
- VERSION = '2.0.8'
end
# Must be first since it unloads the prelude from 1.9.2
@@ -115,7 +115,7 @@ module Gem
RUBYGEMS_DIR = File.dirname File.expand_path(__FILE__)
##
- # An Array of Regexps that match windows ruby platforms.
WIN_PATTERNS = [
/bccwin/i,
@@ -143,6 +143,14 @@ module Gem
specifications
]
@@win_platform = nil
@configuration = nil
@@ -379,6 +387,10 @@ module Gem
paths.path
end
##
# Quietly ensure the Gem directory +dir+ contains all the proper
# subdirectories. If we can't create a directory due to a permission
@@ -389,6 +401,23 @@ module Gem
# World-writable directories will never be created.
def self.ensure_gem_subdirectories dir = Gem.dir, mode = nil
old_umask = File.umask
File.umask old_umask | 002
@@ -398,7 +427,7 @@ module Gem
options[:mode] = mode if mode
- REPOSITORY_SUBDIRECTORIES.each do |name|
subdir = File.join dir, name
next if File.exist? subdir
FileUtils.mkdir_p subdir, options rescue nil
@@ -417,16 +446,12 @@ module Gem
# $LOAD_PATH for files as well as gems.
#
# Note that find_files will return all files even if they are from different
- # versions of the same gem.
def self.find_files(glob, check_load_path=true)
files = []
- if check_load_path
- files = $LOAD_PATH.map { |load_path|
- Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
- }.flatten.select { |file| File.file? file.untaint }
- end
files.concat Gem::Specification.map { |spec|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
@@ -439,6 +464,40 @@ module Gem
return files
end
##
# Finds the user's home directory.
#--
@@ -793,7 +852,7 @@ module Gem
end
##
- # A Gem::Version for the currently running ruby.
def self.ruby_version
return @ruby_version if defined? @ruby_version
@@ -916,9 +975,9 @@ module Gem
end
##
- # Load +plugins+ as ruby files
- def self.load_plugin_files(plugins)
plugins.each do |plugin|
# Skip older versions of the GemCutter plugin: Its commands are in
@@ -936,10 +995,16 @@ module Gem
end
##
- # Find all 'rubygems_plugin' files in installed gems and load them
def self.load_plugins
- load_plugin_files find_files('rubygems_plugin', false)
end
##
@@ -971,10 +1036,31 @@ module Gem
attr_reader :loaded_specs
##
- # Register a Gem::Specification for default gem
def register_default_spec(spec)
spec.files.each do |file|
@path_to_default_spec_map[file] = spec
end
end
@@ -1091,7 +1177,7 @@ unless gem_preluded then # TODO: remove guard after 1.9.2 dropped
if defined?(RUBY_ENGINE) then
begin
##
- # Defaults the ruby implementation wants to provide for RubyGems
require "rubygems/defaults/#{RUBY_ENGINE}"
rescue LoadError
@@ -1,4 +1,7 @@
class Gem::AvailableSet
Tuple = Struct.new(:spec, :source)
def initialize
@@ -36,6 +39,28 @@ class Gem::AvailableSet
self
end
def empty?
@set.empty?
end
@@ -66,6 +91,49 @@ class Gem::AvailableSet
f.source
end
def pick_best!
return self if empty?
@@ -33,6 +33,39 @@ class Gem::CommandManager
include Gem::UserInteraction
##
# Return the authoritative instance of the command manager.
@@ -61,36 +94,10 @@ class Gem::CommandManager
def initialize
require 'timeout'
@commands = {}
- register_command :build
- register_command :cert
- register_command :check
- register_command :cleanup
- 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
##
@@ -132,14 +139,6 @@ class Gem::CommandManager
alert_error "While executing gem ... (#{ex.class})\n #{ex.to_s}"
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)
rescue Interrupt
alert_error "Interrupted"
@@ -147,8 +146,6 @@ class Gem::CommandManager
end
def process_args(args, build_args=nil)
- args = args.to_str.split(/\s+/) if args.respond_to?(:to_str)
-
if args.empty? then
say Gem::Command::HELP
terminate_interaction 1
@@ -15,6 +15,25 @@ class Gem::Commands::BuildCommand < Gem::Command
"GEMSPEC_FILE gemspec file name to build a gem for"
end
def usage # :nodoc:
"#{program_name} GEMSPEC_FILE"
end
@@ -1,6 +1,11 @@
require 'rubygems/command'
require 'rubygems/security'
-require 'openssl'
class Gem::Commands::CertCommand < Gem::Command
@@ -21,7 +26,8 @@ class Gem::Commands::CertCommand < Gem::Command
OptionParser.accept OpenSSL::PKey::RSA do |key_file|
begin
- key = OpenSSL::PKey::RSA.new File.read key_file
rescue Errno::ENOENT
raise OptionParser::InvalidArgument, "#{key_file}: does not exist"
rescue OpenSSL::PKey::RSAError
@@ -79,52 +85,67 @@ class Gem::Commands::CertCommand < Gem::Command
end
end
def execute
options[:add].each do |certificate|
- Gem::Security.trust_dir.trust_cert certificate
-
- say "Added '#{certificate.subject}'"
end
options[:remove].each do |filter|
- certificates_matching filter do |certificate, path|
- FileUtils.rm path
- say "Removed '#{certificate.subject}'"
- end
end
options[:list].each do |filter|
- certificates_matching filter do |certificate, _|
- # this could probably be formatted more gracefully
- say certificate.subject.to_s
- end
end
options[:build].each do |name|
build name
end
- unless options[:sign].empty? then
- 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
def build name
- key = options[:key] || Gem::Security.create_key
cert = Gem::Security.create_cert_email name, key
- key_path = Gem::Security.write key, "gem-private_key.pem"
- cert_path = Gem::Security.write cert, "gem-public_cert.pem"
- say "Certificate: #{cert_path}"
- say "Private Key: #{key_path}"
- say "Don't forget to move the key file to somewhere private!"
end
def certificates_matching filter
@@ -179,6 +200,13 @@ For further reading on signing gems see `ri Gem::Security`.
EOF
end
def load_default_cert
cert_file = File.join Gem.default_cert_path
cert = File.read cert_file
@@ -198,7 +226,8 @@ For further reading on signing gems see `ri Gem::Security`.
def load_default_key
key_file = File.join Gem.default_key_path
key = File.read key_file
- options[:key] = OpenSSL::PKey::RSA.new key
rescue Errno::ENOENT
alert_error \
"--private-key not specified and ~/.gem/gem-private_key.pem does not exist"
@@ -211,6 +240,18 @@ For further reading on signing gems see `ri Gem::Security`.
terminate_interaction 1
end
def sign cert_file
cert = File.read cert_file
cert = OpenSSL::X509::Certificate.new cert
@@ -225,5 +266,13 @@ For further reading on signing gems see `ri Gem::Security`.
Gem::Security.write cert, cert_file, permissions
end
-end
@@ -79,6 +79,13 @@ class Gem::Commands::CheckCommand < Gem::Command
'--gems --alien'
end
def usage # :nodoc:
"#{program_name} [OPTIONS] [GEMNAME ...]"
end
@@ -6,10 +6,11 @@ class Gem::Commands::CleanupCommand < Gem::Command
def initialize
super 'cleanup',
- 'Clean up old versions of installed gems in the local repository',
:force => false, :install_dir => Gem.dir
- add_option('-d', '--dryrun', "") do |value, options|
options[:dryrun] = true
end
@@ -32,11 +33,11 @@ class Gem::Commands::CleanupCommand < Gem::Command
def description # :nodoc:
<<-EOF
-The cleanup command removes old gems from GEM_HOME. If an older version is
-installed elsewhere in GEM_PATH the cleanup command won't touch it.
-Older gems that are required to satisify the dependencies of gems
-are not removed.
EOF
end
@@ -162,4 +163,3 @@ are not removed.
end
end
-
@@ -31,6 +31,10 @@ class Gem::Commands::ContentsCommand < Gem::Command
"Don't include installed path prefix") do |prefix, options|
options[:prefix] = prefix
end
end
def arguments # :nodoc:
@@ -41,79 +45,126 @@ class Gem::Commands::ContentsCommand < Gem::Command
"--no-lib-only --prefix"
end
def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...]"
end
def execute
- version = options[:version] || Gem::Requirement.default
- spec_dirs = options[:specdirs].map do |i|
- [i, File.join(i, "specifications")]
- end.flatten
- path_kind = if spec_dirs.empty? then
- spec_dirs = Gem::Specification.dirs
- "default gem paths"
- else
- "specified path"
- end
-
- gem_names = if options[:all] then
- Gem::Specification.map(&:name)
- else
- get_all_gem_names
- end
-
- gem_names.each do |name|
- # HACK: find_by_name fails for some reason... ARGH
- # 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
- when /\A#{spec.bindir}\//
- [Gem::ConfigMap[:bindir], $POSTMATCH]
- when /\.so\z/
- [Gem::ConfigMap[:archdir], file]
- else
- [Gem::ConfigMap[:rubylibdir], file]
- end
- end
else
- gem_path = spec.full_gem_path
- 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
- files.sort.each do |prefix, basename|
- absolute_path = File.join(prefix, basename)
- next if File.directory? absolute_path
- if options[:prefix]
- say absolute_path
- else
- say basename
- end
end
end
end
end
@@ -38,89 +38,121 @@ class Gem::Commands::DependencyCommand < Gem::Command
"--local --version '#{Gem::Requirement.default}' --no-reverse-dependencies"
end
def usage # :nodoc:
"#{program_name} GEMNAME"
end
- def execute
- if options[:reverse_dependencies] and remote? and not local? then
- alert_error 'Only reverse dependencies for local gems are supported.'
- terminate_interaction 1
- end
- options[:args] << '' if options[:args].empty?
- 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.concat dependency.matching_specs if local?
- if remote? and not options[:reverse_dependencies] then
- fetcher = Gem::SpecFetcher.fetcher
- ss, _ = fetcher.spec_for_dependency dependency
- ss.each { |s,o| specs << s }
end
- if specs.empty? then
- patterns = options[:args].join ','
- say "No gems found matching #{patterns} (#{options[:version]})" if
- Gem.configuration.verbose
- terminate_interaction 1
- end
- specs = specs.uniq.sort
- reverse = Hash.new { |h, k| h[k] = [] }
- if options[:reverse_dependencies] then
- specs.each do |spec|
- reverse[spec.full_name] = find_reverse_dependencies spec
- 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|
- say "#{dep.name} --version '#{dep.requirement}'"
- end
- end
- end
else
- response = ''
-
- specs.each do |spec|
- response << print_dependencies(spec)
- unless reverse[spec.full_name].empty? then
- response << " Used by\n"
- reverse[spec.full_name].each do |sp, dep|
- response << " #{sp} (#{dep})\n"
- end
- end
- response << "\n"
- end
- say response
end
end
- def print_dependencies(spec, level = 0)
response = ''
response << ' ' * level + "Gem #{spec.full_name}\n"
unless spec.dependencies.empty? then
@@ -131,10 +163,30 @@ class Gem::Commands::DependencyCommand < Gem::Command
response
end
##
# Returns an Array of [specification, dep] that are satisfied by +spec+.
- def find_reverse_dependencies(spec)
result = []
Gem::Specification.each do |sp|
@@ -21,6 +21,9 @@ class Gem::Commands::EnvironmentCommand < Gem::Command
def description # :nodoc:
<<-EOF
The RubyGems environment can be controlled through command line arguments,
gemrc files, environment variables and built-in defaults.
@@ -69,66 +72,83 @@ lib/rubygems/defaults/operating_system.rb
def execute
out = ''
arg = options[:args][0]
- case arg
- when /^packageversion/ then
- out << Gem::RubyGemsPackageVersion
- when /^version/ then
- out << Gem::VERSION
- when /^gemdir/, /^gemhome/, /^home/, /^GEM_HOME/ then
- out << Gem.dir
- when /^gempath/, /^path/, /^GEM_PATH/ then
- out << Gem.path.join(File::PATH_SEPARATOR)
- when /^remotesources/ then
- out << Gem.sources.to_a.join("\n")
- when /^platform/ then
- out << Gem.platforms.join(File::PATH_SEPARATOR)
- when nil then
- out = "RubyGems Environment:\n"
-
- out << " - RUBYGEMS VERSION: #{Gem::VERSION}\n"
-
- out << " - RUBY VERSION: #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}"
- out << " level #{RUBY_LEVEL}" if defined? RUBY_LEVEL
- out << ") [#{RUBY_PLATFORM}]\n"
-
- out << " - INSTALLATION DIRECTORY: #{Gem.dir}\n"
-
- out << " - RUBYGEMS PREFIX: #{Gem.prefix}\n" unless Gem.prefix.nil?
-
- out << " - RUBY EXECUTABLE: #{Gem.ruby}\n"
-
- out << " - EXECUTABLE DIRECTORY: #{Gem.bindir}\n"
-
- out << " - RUBYGEMS PLATFORMS:\n"
- Gem.platforms.each do |platform|
- out << " - #{platform}\n"
end
- out << " - GEM PATHS:\n"
- out << " - #{Gem.dir}\n"
- path = Gem.path.dup
- path.delete Gem.dir
- path.each do |p|
- out << " - #{p}\n"
- end
- out << " - GEM CONFIGURATION:\n"
- Gem.configuration.each do |name, value|
- value = value.gsub(/./, '*') if name == 'gemcutter_key'
- out << " - #{name.inspect} => #{value.inspect}\n"
- end
- out << " - REMOTE SOURCES:\n"
- Gem.sources.each do |s|
- out << " - #{s}\n"
- end
- else
- raise Gem::CommandLineError, "Unknown environment option [#{arg}]"
end
- say out
- true
end
end
@@ -28,6 +28,16 @@ class Gem::Commands::FetchCommand < Gem::Command
"--version '#{Gem::Requirement.default}'"
end
def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...]"
end
@@ -42,13 +52,15 @@ class Gem::Commands::FetchCommand < Gem::Command
dep = Gem::Dependency.new gem_name, version
dep.prerelease = options[:prerelease]
- specs_and_sources, errors = Gem::SpecFetcher.fetcher.spec_for_dependency dep
if platform then
filtered = specs_and_sources.select { |s,| s.platform == platform }
specs_and_sources = filtered unless filtered.empty?
end
- spec, source = specs_and_sources.sort_by { |s,| s.version }.first
if spec.nil? then
show_lookup_failure gem_name, version, errors, options[:domain]
@@ -46,6 +46,10 @@ Some examples of 'gem' usage.
* Update all gems on your system:
gem update
EOF
PLATFORMS = <<-'EOF'
@@ -55,8 +59,9 @@ your current platform by running `gem environment`.
RubyGems matches platforms as follows:
- * The CPU must match exactly, unless one of the platforms has
- "universal" as the CPU.
* The OS must match exactly.
* The versions must match exactly unless one of the versions is nil.
@@ -66,11 +71,20 @@ you pass must match "#{cpu}-#{os}" or "#{cpu}-#{os}-#{version}". On mswin
platforms, the version is the compiler version, not the OS version. (Ruby
compiled with VC6 uses "60" as the compiler version, VC8 uses "80".)
Example platforms:
x86-freebsd # Any FreeBSD version on an x86 CPU
universal-darwin-8 # Darwin 8 only gems that run on any CPU
x86-mswin32-80 # Windows gems compiled with VC8
When building platform gems, set the platform in the gem specification to
Gem::Platform::CURRENT. This will correctly mark the gem with your ruby's
@@ -80,6 +94,8 @@ platform.
def initialize
super 'help', "Provide help on the 'gem' command"
end
def arguments # :nodoc:
@@ -96,46 +112,10 @@ platform.
end
def execute
- command_manager = Gem::CommandManager.instance
arg = options[:args][0]
if begins? "commands", arg then
- out = []
- out << "GEM commands are:"
- out << nil
-
- margin_width = 4
-
- desc_width = command_manager.command_names.map { |n| n.size }.max + 4
-
- summary_width = 80 - margin_width - desc_width
- wrap_indent = ' ' * (margin_width + desc_width)
- format = "#{' ' * margin_width}%-#{desc_width}s%s"
-
- command_manager.command_names.each do |cmd_name|
- command = command_manager[cmd_name]
-
- summary =
- if command then
- command.summary
- else
- "[No command found for #{cmd_name}, bug?]"
- end
-
- summary = wrap(summary, summary_width).split "\n"
- out << sprintf(format, cmd_name, summary.shift)
- until summary.empty? do
- out << "#{wrap_indent}#{summary.shift}"
- end
- end
-
- out << nil
- out << "For help on a particular command, use 'gem help COMMAND'."
- out << nil
- out << "Commands may be abbreviated, so long as they are unambiguous."
- out << "e.g. 'gem i rake' is short for 'gem install rake'."
-
- say out.join("\n")
elsif begins? "options", arg then
say Gem::Command::HELP
@@ -147,29 +127,79 @@ platform.
say PLATFORMS
elsif options[:help] then
- command = command_manager[options[:help]]
- if command
- # help with provided command
- command.invoke("--help")
- else
- alert_error "Unknown command #{options[:help]}. Try 'gem help commands'"
- 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
@@ -4,8 +4,6 @@ require 'rubygems/dependency_installer'
require 'rubygems/local_remote_options'
require 'rubygems/validator'
require 'rubygems/version_option'
-require 'rubygems/install_message' # must come before rdoc for messaging
-require 'rubygems/rdoc'
##
# Gem installer command line tool
@@ -40,6 +38,12 @@ class Gem::Commands::InstallCommand < Gem::Command
o[:gemdeps] = v
end
@installed_specs = nil
end
@@ -109,7 +113,44 @@ to write the specification by hand. For example:
"#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags"
end
- def install_from_gemdeps(gf)
require 'rubygems/request_set'
rs = Gem::RequestSet.new
rs.load_gemdeps gf
@@ -131,51 +172,26 @@ to write the specification by hand. For example:
raise Gem::SystemExitException, 0
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'
- if options[:install_dir] and options[:user_install]
- alert_error "Use --install-dir or --user-install but not both"
- terminate_interaction 1
- end
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
-
-
get_all_gem_names_and_versions.each do |gem_name, gem_version|
gem_version ||= options[:version]
begin
- next if options[:conservative] and
- 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
alert_error "Error installing #{gem_name}:\n\t#{e.message}"
exit_code |= 1
@@ -186,12 +202,38 @@ to write the specification by hand. For example:
end
end
- unless @installed_specs.empty? then
- gems = @installed_specs.length == 1 ? 'gem' : 'gems'
- say "#{@installed_specs.length} #{gems} installed"
end
- raise Gem::SystemExitException, exit_code
end
end
@@ -8,7 +8,7 @@ require 'rubygems/commands/query_command'
class Gem::Commands::ListCommand < Gem::Commands::QueryCommand
def initialize
- super 'list', 'Display gems whose name starts with STRING'
remove_option('--name-matches')
end
@@ -21,6 +21,17 @@ class Gem::Commands::ListCommand < Gem::Commands::QueryCommand
"--local --no-details"
end
def usage # :nodoc:
"#{program_name} [STRING]"
end
@@ -10,6 +10,12 @@ class Gem::Commands::MirrorCommand < Gem::Command
end
end
def execute
alert_error "Install the rubygems-mirror gem for the mirror command"
end
@@ -15,19 +15,18 @@ class Gem::Commands::OutdatedCommand < Gem::Command
add_platform_option
end
- def execute
- Gem::Specification.outdated.sort.each do |name|
- local = Gem::Specification.find_all_by_name(name).max
- dep = Gem::Dependency.new local.name, ">= #{local.version}"
- remotes, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep
-
- next if remotes.empty?
-
- remotes.sort! { |a,b| a[0].version <=> b[0].version }
- highest = remotes.last.first
- say "#{local.name} (#{local.version} < #{highest.version})"
end
end
end
@@ -7,7 +7,14 @@ class Gem::Commands::OwnerCommand < Gem::Command
include Gem::GemcutterUtilities
def description # :nodoc:
- 'Manage gem owners on RubyGems.org.'
end
def arguments # :nodoc:
@@ -19,7 +26,7 @@ class Gem::Commands::OwnerCommand < Gem::Command
end
def initialize
- super 'owner', description
add_proxy_option
add_key_option
defaults.merge! :add => [], :remove => []
@@ -31,9 +38,15 @@ class Gem::Commands::OwnerCommand < Gem::Command
add_option '-r', '--remove EMAIL', 'Remove an owner' do |value, options|
options[:remove] << value
end
end
def execute
sign_in
name = get_one_gem_name
@@ -31,6 +31,12 @@ class Gem::Commands::PristineCommand < Gem::Command
options[:only_executables] = value
end
add_version_option('restore to', 'pristine condition')
end
@@ -105,16 +111,21 @@ with an extension.
Gem::RemoteFetcher.fetcher.download_to_cache dep
end
- # TODO use installer options
- install_defaults = Gem::ConfigFile::PLATFORM_DEFAULTS['install']
- installer_env_shebang = install_defaults.to_s['--env-shebang']
installer = Gem::Installer.new(gem,
:wrappers => true,
:force => true,
:install_dir => spec.base_dir,
- :env_shebang => installer_env_shebang,
:build_args => spec.build_args)
if options[:only_executables] then
installer.generate_bin
else
@@ -8,7 +8,13 @@ class Gem::Commands::PushCommand < Gem::Command
include Gem::GemcutterUtilities
def description # :nodoc:
- 'Push a gem up to RubyGems.org'
end
def arguments # :nodoc:
@@ -20,7 +26,7 @@ class Gem::Commands::PushCommand < Gem::Command
end
def initialize
- super 'push', description, :host => self.host
add_proxy_option
add_key_option
@@ -61,6 +61,15 @@ class Gem::Commands::QueryCommand < Gem::Command
"--local --name-matches // --no-details --versions --no-installed"
end
def execute
exit_code = 0
@@ -45,8 +45,12 @@ class Gem::Commands::RdocCommand < Gem::Command
def description # :nodoc:
<<-DESC
-The rdoc command builds RDoc and RI documentation for installed gems. Use
---overwrite to force rebuilding of documentation.
DESC
end
@@ -4,7 +4,7 @@ require 'rubygems/commands/query_command'
class Gem::Commands::SearchCommand < Gem::Commands::QueryCommand
def initialize
- super 'search', 'Display all gems whose name contains STRING'
remove_option '--name-matches'
@@ -19,6 +19,19 @@ class Gem::Commands::SearchCommand < Gem::Commands::QueryCommand
"--remote --no-details"
end
def usage # :nodoc:
"#{program_name} [STRING]"
end
@@ -37,103 +37,165 @@ class Gem::Commands::SourcesCommand < Gem::Command
add_proxy_option
end
- def defaults_str
- '--list'
- end
-
- def execute
- options[:list] = !(options[:add] ||
- options[:clear_all] ||
- options[:remove] ||
- options[:update])
- if options[:clear_all] then
- path = File.join Gem.user_home, '.gem', 'specs'
- 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
-
- begin
- if Gem.sources.include? source_uri then
- say "source #{source_uri} already present in the cache"
- else
- source.load_specs :released
- Gem.sources << source
- Gem.configuration.write
-
- say "#{source_uri} added to sources"
- end
- rescue URI::Error, ArgumentError
- say "#{source_uri} is not a URI"
- terminate_interaction 1
- rescue Gem::RemoteFetcher::FetchError => e
- say "Error fetching #{source_uri}:\n\t#{e.message}"
- terminate_interaction 1
- end
end
- if options[:remove] then
- source_uri = options[:remove]
- unless Gem.sources.include? source_uri then
- say "source #{source_uri} not present in cache"
else
- Gem.sources.delete source_uri
- Gem.configuration.write
-
- say "#{source_uri} removed from sources"
end
end
- if options[:update] then
- Gem.sources.each_source do |src|
- src.load_specs :released
- src.load_specs :latest
- end
- say "source cache successfully updated"
end
- if options[:list] then
- 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
if not File.exist?(path) then
@@ -50,6 +50,22 @@ FIELD name of gemspec field to show
"--local --version '#{Gem::Requirement.default}' --yaml"
end
def usage # :nodoc:
"#{program_name} [GEMFILE] [FIELD]"
end
@@ -5,6 +5,16 @@ class Gem::Commands::StaleCommand < Gem::Command
super('stale', 'List gems along with access times')
end
def usage # :nodoc:
"#{program_name}"
end
@@ -1,6 +1,7 @@
require 'rubygems/command'
require 'rubygems/version_option'
require 'rubygems/uninstaller'
##
# Gem uninstaller command line tool
@@ -14,7 +15,7 @@ class Gem::Commands::UninstallCommand < Gem::Command
def initialize
super 'uninstall', 'Uninstall gems from the local repository',
:version => Gem::Requirement.default, :user_install => true,
- :check_dev => false
add_option('-a', '--[no-]all',
'Uninstall all matching versions'
@@ -67,6 +68,12 @@ class Gem::Commands::UninstallCommand < Gem::Command
options[:force] = value
end
add_version_option
add_platform_option
end
@@ -81,13 +88,49 @@ class Gem::Commands::UninstallCommand < Gem::Command
"--user-install"
end
def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...]"
end
def execute
- # REFACTOR: stolen from cleanup_command
deplist = Gem::DependencyList.new
get_all_gem_names.uniq.each do |name|
Gem::Specification.find_all_by_name(name).each do |spec|
deplist.add spec
@@ -34,6 +34,24 @@ class Gem::Commands::UnpackCommand < Gem::Command
"--version '#{Gem::Requirement.default}'"
end
def usage # :nodoc:
"#{program_name} GEMNAME"
end
@@ -52,27 +52,46 @@ class Gem::Commands::UpdateCommand < Gem::Command
"--document --no-force --install-dir #{Gem.dir}"
end
def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...]"
end
def execute
hig = {}
if options[:system] then
update_rubygems
return
- else
- say "Updating 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
@@ -85,51 +104,65 @@ class Gem::Commands::UpdateCommand < Gem::Command
end
end
- def update_gem name, version = Gem::Requirement.default
- return if @updated.any? { |spec| spec.name == name }
- @installer ||= Gem::DependencyInstaller.new options
- success = false
- say "Updating #{name}"
- begin
- @installer.install name, Gem::Requirement.new(version)
- success = true
- rescue Gem::InstallError => e
- alert_error "Error installing #{name}:\n\t#{e.message}"
- success = false
- end
- @installer.installed_gems.each do |spec|
- @updated << spec
end
end
- def update_gems gems_to_update
- gems_to_update.uniq.sort.each do |(name, version)|
- update_gem name, version
end
- @updated
end
- ##
- # Update RubyGems software to the latest version.
- def update_rubygems
- unless options[:args].empty? then
- alert_error "Gem names are not allowed with the --system option"
- terminate_interaction 1
- end
- options[:user_install] = false
- # TODO: rename version and other variable name conflicts
- # TODO: get rid of all this indirection on name and other BS
version = options[:system]
- if version == true then
version = Gem::Version.new Gem::VERSION
requirement = Gem::Requirement.new ">= #{Gem::VERSION}"
else
@@ -146,46 +179,72 @@ class Gem::Commands::UpdateCommand < Gem::Command
}
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
version = installed_gems.last.version
args = []
args << '--prefix' << Gem.prefix if Gem.prefix
# TODO use --document for >= 1.9 , --no-rdoc --no-ri < 1.9
args << '--no-rdoc' unless options[:document].include? 'rdoc'
args << '--no-ri' unless options[:document].include? 'ri'
args << '--no-format-executable' if options[:no_format_executable]
-
- 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
def which_to_update highest_installed_gems, gem_names, system = false
@@ -195,21 +254,7 @@ class Gem::Commands::UpdateCommand < Gem::Command
next if not gem_names.empty? and
gem_names.all? { |name| /#{name}/ !~ l_spec.name }
- dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
- 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
result << [l_spec.name, [l_spec.version, highest_remote_ver].max]
@@ -23,6 +23,17 @@ class Gem::Commands::WhichCommand < Gem::Command
"--no-gems-first --no-all"
end
def execute
found = false
@@ -9,7 +9,21 @@ class Gem::Commands::YankCommand < Gem::Command
include Gem::GemcutterUtilities
def description # :nodoc:
- 'Remove a specific gem version release from RubyGems.org'
end
def arguments # :nodoc:
@@ -21,7 +35,7 @@ class Gem::Commands::YankCommand < Gem::Command
end
def initialize
- super 'yank', description
add_version_option("remove")
add_platform_option("remove")
@@ -141,6 +141,11 @@ class Gem::ConfigFile
attr_reader :ssl_ca_cert
##
# Create the config file object. +args+ is the list of arguments
# from the command line.
#
@@ -210,6 +215,7 @@ class Gem::ConfigFile
@ssl_verify_mode = @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode
@ssl_ca_cert = @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert
@api_keys = nil
@rubygems_api_key = nil
@@ -246,6 +252,10 @@ Your gem push credentials file located at:
has file permissions of 0#{existing_permissions.to_s 8} but 0600 is required.
You should reset your credentials at:
\thttps://rubygems.org/profile/edit
@@ -309,6 +319,9 @@ if you believe they were disclosed to a third party.
@rubygems_api_key = api_key
end
def load_file(filename)
Gem.load_yaml
@@ -321,8 +334,8 @@ if you believe they were disclosed to a third party.
return {}
end
return content
- rescue ArgumentError
- warn "Failed to load #{filename}"
rescue Errno::EACCES
warn "Failed to load #{filename} due to permissions problem."
end
@@ -48,7 +48,12 @@ module Kernel
# normal require handle loading a gem from the rescue below.
if Gem::Specification.unresolved_deps.empty? then
- return gem_original_require(path)
end
# If +path+ is for a gem that has already been loaded, don't
@@ -57,11 +62,16 @@ module Kernel
#--
# TODO request access to the C implementation of this to speed up RubyGems
- spec = Gem::Specification.find { |s|
s.activated? and s.contains_requirable_file? path
}
- return gem_original_require(path) if spec
# Attempt to find +path+ in any unresolved gems...
@@ -109,11 +119,21 @@ module Kernel
valid.activate
end
- gem_original_require path
rescue LoadError => load_error
if load_error.message.start_with?("Could not find") or
(load_error.message.end_with?(path) and Gem.try_activate(path)) then
- return gem_original_require(path)
end
raise load_error
@@ -15,6 +15,14 @@ module Gem
end
##
# Default home directory path to be used if an alternate value is not
# specified in the environment
@@ -126,4 +134,11 @@ module Gem
def self.default_cert_path
File.join Gem.user_home, ".gem", "gem-public_cert.pem"
end
end
@@ -203,6 +203,8 @@ class Gem::Dependency
requirement.satisfied_by? version
end
# DOC: this method needs either documented or :nodoc'd
def match? obj, version=nil
@@ -250,10 +252,10 @@ class Gem::Dependency
# DOC: this method needs either documented or :nodoc'd
def matching_specs platform_only = false
- matches = Gem::Specification.find_all { |spec|
self.name === spec.name and # TODO: == instead of ===
requirement.satisfied_by? spec.version
- }
if platform_only
matches.reject! { |spec|
@@ -1,11 +1,11 @@
require 'rubygems'
require 'rubygems/dependency_list'
require 'rubygems/package'
require 'rubygems/installer'
require 'rubygems/spec_fetcher'
require 'rubygems/user_interaction'
-require 'rubygems/source_local'
-require 'rubygems/source_specific_file'
require 'rubygems/available_set'
##
@@ -15,15 +15,7 @@ class Gem::DependencyInstaller
include Gem::UserInteraction
- attr_reader :gems_to_install
- attr_reader :installed_gems
-
- ##
- # Documentation types. For use by the Gem.done_installing hook
-
- attr_reader :document
-
- DEFAULT_OPTIONS = {
:env_shebang => false,
:document => %w[ri],
:domain => :both, # HACK dup
@@ -35,9 +27,31 @@ class Gem::DependencyInstaller
:wrappers => true,
:build_args => nil,
:build_docs_in_background => false,
}.freeze
##
# Creates a new installer instance.
#
# Options are:
@@ -56,7 +70,8 @@ class Gem::DependencyInstaller
# :wrappers:: See Gem::Installer::new
# :build_args:: See Gem::Installer::new
- def initialize(options = {})
@install_dir = options[:install_dir] || Gem.dir
if options[:install_dir] then
@@ -82,6 +97,7 @@ class Gem::DependencyInstaller
@wrappers = options[:wrappers]
@build_args = options[:build_args]
@build_docs_in_background = options[:build_docs_in_background]
# Indicates that we should not try to update any deps unless
# we absolutely must.
@@ -93,13 +109,61 @@ class Gem::DependencyInstaller
@cache_dir = options[:cache_dir] || @install_dir
- # Set with any errors that SpecFetcher finds while search through
- # gemspecs for a dep
@errors = nil
end
- attr_reader :errors
##
# Creates an AvailableSet to install from based on +dep_or_name+ and
# +version+
@@ -138,7 +202,7 @@ class Gem::DependencyInstaller
# sources. Gems are sorted with newer gems preferred over older gems, and
# local gems preferred over remote gems.
- def find_gems_with_sources(dep)
set = Gem::AvailableSet.new
if consider_local?
@@ -179,10 +243,50 @@ class Gem::DependencyInstaller
end
##
# Gathers all dependencies necessary for the installation from local and
# remote sources unless the ignore_dependencies was given.
- def gather_dependencies
specs = @available.all_specs
# these gems were listed by the user, always install them
@@ -214,93 +318,19 @@ class Gem::DependencyInstaller
@gems_to_install = dependency_list.dependency_order.reverse
end
- def add_found_dependencies to_do, dependency_list
- seen = {}
- dependencies = Hash.new { |h, name| h[name] = Gem::Dependency.new name }
-
- until to_do.empty? do
- spec = to_do.shift
-
- # HACK why is spec nil?
- next if spec.nil? or seen[spec.name]
- seen[spec.name] = true
-
- deps = spec.runtime_dependencies
-
- if @development
- if @dev_shallow
- if @toplevel_specs.include? spec.full_name
- deps |= spec.development_dependencies
- end
- else
- deps |= spec.development_dependencies
- end
- end
-
- deps.each do |dep|
- dependencies[dep.name] = dependencies[dep.name].merge dep
-
- if @minimal_deps
- next if Gem::Specification.any? do |installed_spec|
- dep.name == installed_spec.name and
- dep.requirement.satisfied_by? installed_spec.version
- end
- end
-
- results = find_gems_with_sources(dep)
-
- results.sorted.each do |t|
- to_do.push t.spec
- end
-
- results.remove_installed! dep
-
- @available << results
- results.inject_into_list dependency_list
- end
- end
-
- dependency_list.remove_specs_unsatisfied_by dependencies
- end
-
- ##
- # Finds a spec and the source_uri it came from for gem +gem_name+ and
- # +version+. Returns an Array of specs and sources required for
- # installation of the gem.
-
- def find_spec_by_name_and_version(gem_name,
- version = Gem::Requirement.default,
- prerelease = false)
-
- set = Gem::AvailableSet.new
-
- if consider_local?
- if gem_name =~ /\.gem$/ and File.file? gem_name then
- src = Gem::Source::SpecificFile.new(gem_name)
- set.add src.spec, src
- else
- local = Gem::Source::Local.new
-
- if s = local.find_gem(gem_name, version)
- set.add s, local
end
end
end
-
- if set.empty?
- dep = Gem::Dependency.new gem_name, version
- # HACK Dependency objects should be immutable
- dep.prerelease = true if prerelease
-
- set = find_gems_with_sources(dep)
- set.match_platform!
- end
-
- if set.empty?
- raise Gem::SpecificGemNotFoundException.new(gem_name, version, @errors)
- end
-
- @available = set
end
##
@@ -318,61 +348,30 @@ class Gem::DependencyInstaller
# separately.
def install dep_or_name, version = Gem::Requirement.default
- available_set_for dep_or_name, version
@installed_gems = []
- gather_dependencies
-
- # REFACTOR is the last gem always the one that the user requested?
- # This code assumes that but is that actually validated by the code?
-
- last = @gems_to_install.size - 1
- @gems_to_install.each_with_index do |spec, index|
- # REFACTOR more current spec set hardcoding, should be abstracted?
- next if Gem::Specification.include?(spec) and index != last
-
- # TODO: make this sorta_verbose so other users can benefit from it
- say "Installing gem #{spec.full_name}" if Gem.configuration.really_verbose
-
- source = @available.source_for spec
-
- begin
- # REFACTOR make the fetcher to use configurable
- local_gem_path = source.download spec, @cache_dir
- rescue Gem::RemoteFetcher::FetchError
- # TODO I doubt all fetch errors are recoverable, we should at least
- # report the errors probably.
- next if @force
- raise
- end
-
- if @development
- if @dev_shallow
- is_dev = @toplevel_specs.include? spec.full_name
- else
- is_dev = true
- end
- end
- inst = Gem::Installer.new local_gem_path,
- :bin_dir => @bin_dir,
- :development => is_dev,
- :env_shebang => @env_shebang,
- :force => @force,
- :format_executable => @format_executable,
- :ignore_dependencies => @ignore_dependencies,
- :install_dir => @install_dir,
- :security_policy => @security_policy,
- :user_install => @user_install,
- :wrappers => @wrappers,
- :build_args => @build_args
-
- spec = inst.install
-
- @installed_gems << spec
end
# Since this is currently only called for docs, we can be lazy and just say
# it's documentation. Ideally the hook adder could decide whether to be in
# the background or not, and what to call it.
@@ -385,18 +384,34 @@ class Gem::DependencyInstaller
@installed_gems
end
- def in_background what
- fork_happened = false
- if @build_docs_in_background and Process.respond_to?(:fork)
- begin
- Process.fork do
- yield
- end
- fork_happened = true
- say "#{what} in a background process."
- rescue NotImplementedError
- end
end
- yield unless fork_happened
end
end
@@ -1,575 +1,254 @@
require 'rubygems'
require 'rubygems/dependency'
require 'rubygems/exceptions'
require 'uri'
require 'net/http'
-module Gem
- # Raised when a DependencyConflict reaches the toplevel.
- # Indicates which dependencies were incompatible.
- #
- class DependencyResolutionError < Gem::Exception
- def initialize(conflict)
- @conflict = conflict
- a, b = conflicting_dependencies
- super "unable to resolve conflicting dependencies '#{a}' and '#{b}'"
- end
- attr_reader :conflict
- def conflicting_dependencies
- @conflict.conflicting_dependencies
- end
- end
- # Raised when a dependency requests a gem for which there is
- # no spec.
- #
- class UnsatisfiableDepedencyError < Gem::Exception
- def initialize(dep)
- super "unable to find any gem matching dependency '#{dep}'"
- @dependency = dep
- end
- attr_reader :dependency
- end
- # Raised when dependencies conflict and create the inability to
- # find a valid possible spec for a request.
- #
- class ImpossibleDependenciesError < Gem::Exception
- def initialize(request, conflicts)
- s = conflicts.size == 1 ? "" : "s"
- super "detected #{conflicts.size} conflict#{s} with dependency '#{request.dependency}'"
- @request = request
- @conflicts = conflicts
- end
- def dependency
- @request.dependency
- end
- attr_reader :conflicts
end
- # Given a set of Gem::Dependency objects as +needed+ and a way
- # to query the set of available specs via +set+, calculates
- # a set of ActivationRequest objects which indicate all the specs
- # that should be activated to meet the all the requirements.
#
- class DependencyResolver
-
- # Represents a specification retrieved via the rubygems.org
- # API. This is used to avoid having to load the full
- # Specification object when all we need is the name, version,
- # and dependencies.
- #
- class APISpecification
- attr_reader :set # :nodoc:
-
- def initialize(set, api_data)
- @set = set
- @name = api_data[:name]
- @version = Gem::Version.new api_data[:number]
- @dependencies = api_data[:dependencies].map do |name, ver|
- Gem::Dependency.new name, ver.split(/\s*,\s*/)
- end
- end
-
- attr_reader :name, :version, :dependencies
-
- def == other # :nodoc:
- self.class === other and
- @set == other.set and
- @name == other.name and
- @version == other.version and
- @dependencies == other.dependencies
- end
-
- def full_name
- "#{@name}-#{@version}"
- end
- end
-
- # The global rubygems pool, available via the rubygems.org API.
- # Returns instances of APISpecification.
- #
- class APISet
- def initialize
- @data = Hash.new { |h,k| h[k] = [] }
- @dep_uri = URI 'https://rubygems.org/api/v1/dependencies'
- end
-
- # Return data for all versions of the gem +name+.
- #
- def versions(name)
- if @data.key?(name)
- return @data[name]
- end
-
- uri = @dep_uri + "?gems=#{name}"
- str = Gem::RemoteFetcher.fetcher.fetch_path uri
-
- Marshal.load(str).each do |ver|
- @data[ver[:name]] << ver
- end
-
- @data[name]
- end
-
- # Return an array of APISpecification objects matching
- # DependencyRequest +req+.
- #
- def find_all(req)
- res = []
-
- versions(req.name).each do |ver|
- if req.dependency.match? req.name, ver[:number]
- res << APISpecification.new(self, ver)
- end
- end
-
- res
- end
-
- # A hint run by the resolver to allow the Set to fetch
- # data for DependencyRequests +reqs+.
- #
- def prefetch(reqs)
- names = reqs.map { |r| r.dependency.name }
- needed = names.find_all { |d| [email protected]?(d) }
-
- return if needed.empty?
-
- uri = @dep_uri + "?gems=#{needed.sort.join ','}"
- str = Gem::RemoteFetcher.fetcher.fetch_path uri
-
- Marshal.load(str).each do |ver|
- @data[ver[:name]] << ver
- end
- end
- end
-
- # Represents a possible Specification object returned
- # from IndexSet. Used to delay needed to download full
- # Specification objects when only the +name+ and +version+
- # are needed.
- #
- class IndexSpecification
- def initialize(set, name, version, source, plat)
- @set = set
- @name = name
- @version = version
- @source = source
- @platform = plat
-
- @spec = nil
- end
-
- attr_reader :name, :version, :source
-
- def full_name
- "#{@name}-#{@version}"
- end
-
- def spec
- @spec ||= @set.load_spec(@name, @version, @source)
- end
-
- def dependencies
- spec.dependencies
- end
- end
-
- # The global rubygems pool represented via the traditional
- # source index.
- #
- class IndexSet
- def initialize
- @f = Gem::SpecFetcher.fetcher
-
- @all = Hash.new { |h,k| h[k] = [] }
-
- list, _ = @f.available_specs(:released)
- list.each do |uri, specs|
- specs.each do |n|
- @all[n.name] << [uri, n]
- end
- end
-
- @specs = {}
- end
-
- # Return an array of IndexSpecification objects matching
- # DependencyRequest +req+.
- #
- def find_all(req)
- res = []
-
- name = req.dependency.name
-
- @all[name].each do |uri, n|
- if req.dependency.match? n
- res << IndexSpecification.new(self, n.name, n.version,
- uri, n.platform)
- end
- end
-
- res
- end
-
- # No prefetching needed since we load the whole index in
- # initially.
- #
- def prefetch(gems)
- end
-
- # Called from IndexSpecification to get a true Specification
- # object.
- #
- def load_spec(name, ver, source)
- key = "#{name}-#{ver}"
- @specs[key] ||= source.fetch_spec(Gem::NameTuple.new(name, ver))
- end
- end
-
- # A set which represents the installed gems. Respects
- # all the normal settings that control where to look
- # for installed gems.
- #
- class CurrentSet
- def find_all(req)
- req.dependency.matching_specs
- end
-
- def prefetch(gems)
- end
- end
- # Create DependencyResolver object which will resolve
- # the tree starting with +needed+ Depedency objects.
- #
- # +set+ is an object that provides where to look for
- # specifications to satisify the Dependencies. This
- # defaults to IndexSet, which will query rubygems.org.
- #
- def initialize(needed, set=IndexSet.new)
- @set = set || IndexSet.new # Allow nil to mean IndexSet
- @needed = needed
-
- @conflicts = nil
end
- # Provide a DependencyResolver that queries only against
- # the already installed gems.
- #
- def self.for_current_gems(needed)
- new needed, CurrentSet.new
- end
- # Contains all the conflicts encountered while doing resolution
- #
- attr_reader :conflicts
- # Proceed with resolution! Returns an array of ActivationRequest
- # objects.
- #
- def resolve
- @conflicts = []
- needed = @needed.map { |n| DependencyRequest.new(n, nil) }
- res = resolve_for needed, []
- if res.kind_of? DependencyConflict
- raise DependencyResolutionError.new(res)
- end
- res
end
- # Used internally to indicate that a dependency conflicted
- # with a spec that would be activated.
- #
- class DependencyConflict
- def initialize(dependency, activated, failed_dep=dependency)
- @dependency = dependency
- @activated = activated
- @failed_dep = failed_dep
- end
-
- attr_reader :dependency, :activated
- # Return the Specification that listed the dependency
- #
- def requester
- @failed_dep.requester
- end
-
- def for_spec?(spec)
- @dependency.name == spec.name
- end
- # Return the 2 dependency objects that conflicted
- #
- def conflicting_dependencies
- [@failed_dep.dependency, @activated.request.dependency]
- end
- end
-
- # Used Internally. Wraps a Depedency object to also track
- # which spec contained the Dependency.
- #
- class DependencyRequest
- def initialize(dep, act)
- @dependency = dep
- @requester = act
- end
-
- attr_reader :dependency, :requester
-
- def name
- @dependency.name
- end
-
- def matches_spec?(spec)
- @dependency.matches_spec? spec
- end
-
- def to_s
- @dependency.to_s
- end
- def ==(other)
- case other
- when Dependency
- @dependency == other
- when DependencyRequest
- @dependency == other.dependency && @requester == other.requester
else
- false
end
- end
- end
-
- # Specifies a Specification object that should be activated.
- # Also contains a dependency that was used to introduce this
- # activation.
- #
- class ActivationRequest
- def initialize(spec, req, others_possible=true)
- @spec = spec
- @request = req
- @others_possible = others_possible
- end
-
- attr_reader :spec, :request
-
- # Indicate if this activation is one of a set of possible
- # requests for the same Dependency request.
- #
- def others_possible?
- @others_possible
- end
-
- # Return the ActivationRequest that contained the dependency
- # that we were activated for.
- #
- def parent
- @request.requester
- end
- def name
- @spec.name
end
- def full_name
- @spec.full_name
- end
-
- def version
- @spec.version
- end
-
- def full_spec
- Gem::Specification === @spec ? @spec : @spec.spec
- end
-
- def download(path)
- if @spec.respond_to? :source
- source = @spec.source
- else
- source = Gem.sources.first
- end
-
- Gem.ensure_gem_subdirectories path
- source.download full_spec, path
- end
- def ==(other)
- case other
- when Gem::Specification
- @spec == other
- when ActivationRequest
- @spec == other.spec && @request == other.request
- else
- false
end
- end
-
- ##
- # Indicates if the requested gem has already been installed.
-
- def installed?
- this_spec = full_spec
-
- Gem::Specification.any? do |s|
- s == this_spec
end
- end
- end
- def requests(s, act)
- reqs = []
- s.dependencies.each do |d|
- next unless d.type == :runtime
- reqs << DependencyRequest.new(d, act)
- end
-
- @set.prefetch(reqs)
-
- reqs
- end
-
- # The meat of the algorithm. Given +needed+ DependencyRequest objects
- # and +specs+ being a list to ActivationRequest, calculate a new list
- # of ActivationRequest objects.
- #
- def resolve_for(needed, specs)
- until needed.empty?
- dep = needed.shift
-
- # If there is already a spec activated for the requested name...
- if existing = specs.find { |s| dep.name == s.name }
-
- # then we're done since this new dep matches the
- # existing spec.
- next if dep.matches_spec? existing
-
- # There is a conflict! We return the conflict
- # object which will be seen by the caller and be
- # handled at the right level.
-
- # If the existing activation indicates that there
- # are other possibles for it, then issue the conflict
- # on the dep for the activation itself. Otherwise, issue
- # it on the requester's request itself.
- #
- if existing.others_possible?
- conflict = DependencyConflict.new(dep, existing)
else
- depreq = existing.request.requester.request
- conflict = DependencyConflict.new(depreq, existing, dep)
end
- @conflicts << conflict
-
- return conflict
end
- # Get a list of all specs that satisfy dep
- possible = @set.find_all(dep)
- case possible.size
- when 0
- # If there are none, then our work here is done.
- raise UnsatisfiableDepedencyError.new(dep)
- when 1
- # If there is one, then we just add it to specs
- # and process the specs dependencies by adding
- # them to needed.
-
- spec = possible.first
- act = ActivationRequest.new(spec, dep, false)
-
- specs << act
-
- # Put the deps for at the beginning of needed
- # rather than the end to match the depth first
- # searching done by the multiple case code below.
- #
- # This keeps the error messages consistent.
- needed = requests(spec, act) + needed
- else
- # There are multiple specs for this dep. This is
- # the case that this class is built to handle.
-
- # Sort them so that we try the highest versions
- # first.
- possible = possible.sort_by { |s| s.version }
-
- # We track the conflicts seen so that we can report them
- # to help the user figure out how to fix the situation.
- conflicts = []
-
- # To figure out which to pick, we keep resolving
- # given each one being activated and if there isn't
- # a conflict, we know we've found a full set.
- #
- # We use an until loop rather than #reverse_each
- # to keep the stack short since we're using a recursive
- # algorithm.
- #
- until possible.empty?
- s = possible.pop
-
- # Recursively call #resolve_for with this spec
- # and add it's dependencies into the picture...
-
- act = ActivationRequest.new(s, dep)
-
- try = requests(s, act) + needed
-
- res = resolve_for(try, specs + [act])
-
- # While trying to resolve these dependencies, there may
- # be a conflict!
-
- if res.kind_of? DependencyConflict
- # The conflict might be created not by this invocation
- # but rather one up the stack, so if we can't attempt
- # to resolve this conflict (conflict isn't with the spec +s+)
- # then just return it so the caller can try to sort it out.
- return res unless res.for_spec? s
-
- # Otherwise, this is a conflict that we can attempt to fix
- conflicts << [s, res]
-
- # Optimization:
- #
- # Because the conflict indicates the dependency that trigger
- # it, we can prune possible based on this new information.
- #
- # This cuts down on the number of iterations needed.
- possible.delete_if { |x| !res.dependency.matches_spec? x }
- else
- # No conflict, return the specs
- return res
- end
- end
- # We tried all possibles and nothing worked, so we let the user
- # know and include as much information about the problem since
- # the user is going to have to take action to fix this.
- raise ImpossibleDependenciesError.new(dep, conflicts)
- end
- end
- specs
end
end
end
@@ -7,7 +7,13 @@
# Base exception class for RubyGems. All exception raised by RubyGems are a
# subclass of this one.
class Gem::Exception < RuntimeError
- attr_accessor :source_exception
end
class Gem::CommandLineError < Gem::Exception; end
@@ -17,6 +23,28 @@ class Gem::DependencyError < Gem::Exception; end
class Gem::DependencyRemovalException < Gem::Exception; end
##
# Raised when attempting to uninstall a gem that isn't in GEM_HOME.
class Gem::GemNotInHomeException < Gem::Exception
@@ -65,6 +93,42 @@ class Gem::SpecificGemNotFoundException < Gem::GemNotFoundException
attr_reader :name, :version, :errors
end
class Gem::InstallError < Gem::Exception; end
##
@@ -107,3 +171,26 @@ class Gem::SystemExitException < SystemExit
end
@@ -4,8 +4,23 @@
# See LICENSE.txt for permissions.
#++
class Gem::Ext::Builder
def self.class_name
name =~ /Ext::(.*)Builder/
$1.downcase
@@ -18,7 +33,7 @@ class Gem::Ext::Builder
# try to find make program from Ruby configure arguments first
RbConfig::CONFIG['configure_args'] =~ /with-make-prog\=(\w+)/
- make_program = $1 || ENV['MAKE'] || ENV['make']
unless make_program then
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
end
@@ -63,5 +78,108 @@ class Gem::Ext::Builder
end
end
end
@@ -33,17 +33,11 @@ class Gem::GemRunner
##
# Run the gem command with the following arguments.
- def run(args)
- if args.include?('--')
- # We need to preserve the original ARGV to use for passing gem options
- # to source gems. If there is a -- in the line, strip all options after
- # it...its for the source building process.
- # TODO use slice!
- build_args = args[args.index("--") + 1...args.length]
- args = args[0...args.index("--")]
- end
do_configuration args
cmd = @command_manager_class.instance
cmd.command_names.each do |command_name|
@@ -60,6 +54,20 @@ class Gem::GemRunner
cmd.run Gem.configuration.args, build_args
end
private
def do_configuration(args)
@@ -1,11 +1,17 @@
require 'rubygems/remote_fetcher'
module Gem::GemcutterUtilities
# TODO: move to Gem::Command
OptionParser.accept Symbol do |value|
value.to_sym
end
##
# Add the --key option
@@ -17,6 +23,9 @@ module Gem::GemcutterUtilities
end
end
def api_key
if options[:key] then
verify_api_key options[:key]
@@ -27,35 +36,10 @@ module Gem::GemcutterUtilities
end
end
- def sign_in sign_in_host = self.host
- return if Gem.configuration.rubygems_api_key
-
- pretty_host = if Gem::DEFAULT_HOST == sign_in_host then
- 'RubyGems.org'
- else
- sign_in_host
- end
-
- say "Enter your #{pretty_host} credentials."
- say "Don't have an account yet? " +
- "Create one at #{sign_in_host}/sign_up"
-
- email = ask " Email: "
- password = ask_for_password "Password: "
- say "\n"
-
- response = rubygems_api_request(:get, "api/v1/api_key",
- sign_in_host) do |request|
- request.basic_auth email, password
- end
-
- with_response response do |resp|
- say "Signed in."
- Gem.configuration.rubygems_api_key = resp.body
- end
- end
- attr_writer :host
def host
configured_host = Gem.host unless
Gem.configuration.disable_default_gem_server
@@ -70,6 +54,9 @@ module Gem::GemcutterUtilities
end
end
def rubygems_api_request(method, path, host = nil, &block)
require 'net/http'
@@ -86,23 +73,43 @@ module Gem::GemcutterUtilities
Gem::RemoteFetcher.fetcher.request(uri, request_method, &block)
end
- def with_response resp, error_prefix = nil
- case resp
- when Net::HTTPSuccess then
- if block_given? then
- yield resp
- else
- say resp.body
- end
- else
- message = resp.body
- message = "#{error_prefix}: #{message}" if error_prefix
- say message
- terminate_interaction 1 # TODO: question this
end
end
def verify_api_key(key)
if Gem.configuration.api_keys.key? key then
Gem.configuration.api_keys[key]
@@ -112,4 +119,29 @@ module Gem::GemcutterUtilities
end
end
end
@@ -26,6 +26,9 @@ module Gem::InstallUpdateOptions
OptionParser.accept Gem::Security::Policy do |value|
require 'rubygems/security'
value = Gem::Security::Policies[value]
valid = Gem::Security::Policies.keys.sort
message = "#{value} (#{valid.join ', '} are valid)"
@@ -9,7 +9,6 @@ require 'rubygems/package'
require 'rubygems/ext'
require 'rubygems/user_interaction'
require 'fileutils'
-require 'thread'
##
# The installer installs the files contained in the .gem into the Gem.home.
@@ -33,14 +32,6 @@ class Gem::Installer
ENV_PATHS = %w[/usr/bin/env /bin/env]
##
- # The builder shells-out to run various commands after changing the
- # directory. This means multiple installations cannot be allowed to build
- # extensions in parallel as they may change each other's directories leading
- # to broken extensions or failed installations.
-
- CHDIR_MUTEX = Mutex.new # :nodoc:
-
- ##
# Raised when there is an error while building extensions.
#
class ExtensionBuildError < Gem::InstallError; end
@@ -93,8 +84,8 @@ class Gem::Installer
# :env_shebang:: Use /usr/bin/env in bin wrappers.
# :force:: Overrides all version checks and security policy checks, except
# for a signed-gems-only policy.
- # :format_executable:: Format the executable the same as the ruby executable.
- # If your ruby is ruby18, foo_exec will be installed as
# foo_exec18.
# :ignore_dependencies:: Don't raise if a dependency is missing.
# :install_dir:: The directory to install the gem into.
@@ -153,7 +144,7 @@ class Gem::Installer
io.gets # blankline
# TODO detect a specially formatted comment instead of trying
- # to run a regexp against ruby code.
next unless io.gets =~ /This file was generated by RubyGems/
ruby_executable = true
@@ -222,19 +213,24 @@ class Gem::Installer
FileUtils.mkdir_p gem_dir
- extract_files
- build_extensions
- write_build_info_file
- run_post_build_hooks
- generate_bin
- write_spec
- write_cache_file
- say spec.post_install_message unless spec.post_install_message.nil?
- spec.loaded_from = spec_file
Gem::Specification.add_spec spec unless Gem::Specification.include? spec
@@ -336,6 +332,14 @@ class Gem::Installer
end
##
# Writes the .gemspec specification (in Ruby) to the gem home's
# specifications directory.
@@ -347,6 +351,16 @@ class Gem::Installer
end
##
# Creates windows .bat files for easy running of commands
def generate_windows_script(filename, bindir)
@@ -547,13 +561,13 @@ class Gem::Installer
:bin_dir => nil,
:env_shebang => false,
:force => false,
- :install_dir => Gem.dir,
:only_install_dir => false
}.merge options
@env_shebang = options[:env_shebang]
@force = options[:force]
- @gem_home = options[:install_dir]
@ignore_dependencies = options[:ignore_dependencies]
@format_executable = options[:format_executable]
@security_policy = options[:security_policy]
@@ -628,7 +642,7 @@ TEXT
end
##
- # return the stub script text used to launch the true ruby script
def windows_stub_script(bindir, bin_file_name)
ruby = File.basename(Gem.ruby).chomp('"')
@@ -647,75 +661,20 @@ TEXT
# configure scripts and rakefiles or mkrf_conf files.
def build_extensions
- return if spec.extensions.empty?
- if @build_args.empty?
- say "Building native extensions. This could take a while..."
- else
- say "Building native extensions with: '#{@build_args.join(' ')}'"
- say "This could take a while..."
- end
-
- dest_path = File.join gem_dir, spec.require_paths.first
- ran_rake = false # only run rake once
-
- spec.extensions.each do |extension|
- break if ran_rake
- results = []
-
- extension ||= ""
- extension_dir = File.join gem_dir, File.dirname(extension)
-
- builder = case extension
- when /extconf/ then
- Gem::Ext::ExtConfBuilder
- when /configure/ then
- Gem::Ext::ConfigureBuilder
- when /rakefile/i, /mkrf_conf/i then
- ran_rake = true
- Gem::Ext::RakeBuilder
- when /CMakeLists.txt/ then
- Gem::Ext::CmakeBuilder
- else
- message = "No builder for extension '#{extension}'"
- extension_build_error extension_dir, message
- end
-
- begin
- FileUtils.mkdir_p dest_path
-
- CHDIR_MUTEX.synchronize do
- Dir.chdir extension_dir do
- results = builder.build(extension, gem_dir, dest_path,
- results, @build_args)
-
- say results.join("\n") if Gem.configuration.really_verbose
- end
- end
- rescue
- extension_build_error(extension_dir, results.join("\n"), $@)
- end
- end
end
##
# Logs the build +output+ in +build_dir+, then raises ExtensionBuildError.
- def extension_build_error(build_dir, output, backtrace = nil)
- gem_make_out = File.join build_dir, 'gem_make.out'
-
- open gem_make_out, 'wb' do |io| io.puts output end
-
- message = <<-EOF
-ERROR: Failed to build gem native extension.
-
- #{output}
-
-Gem files will remain installed in #{gem_dir} for inspection.
-Results logged to #{gem_make_out}
-EOF
- raise ExtensionBuildError, message, backtrace
end
##
@@ -728,6 +687,15 @@ EOF
end
##
# Prefix and suffix the program filename the same as ruby.
def formatted_program_filename(filename)
@@ -750,7 +718,7 @@ EOF
##
# Performs various checks before installing the gem such as the install
- # repository is writable and its directories exist, required ruby and
# rubygems versions are met and that dependencies are installed.
#
# Version and dependency checks are skipped if this install is forced.
@@ -767,7 +735,11 @@ EOF
ensure_loadable_spec
- Gem.ensure_gem_subdirectories gem_home
return true if @force
@@ -43,6 +43,20 @@ class Gem::NameTuple
end
##
# Indicate if this NameTuple matches the current platform.
def match_platform?
@@ -59,12 +73,7 @@ class Gem::NameTuple
# Return the name that the gemspec file would be
def spec_name
- case @platform
- when nil, 'ruby', ''
- "#{@name}-#{@version}.gemspec"
- else
- "#{@name}-#{@version}-#{@platform}.gemspec"
- end
end
##
@@ -74,10 +83,12 @@ class Gem::NameTuple
[@name, @version, @platform]
end
- def to_s
"#<Gem::NameTuple #{@name}, #{@version}, #{@platform}>"
end
def <=> other
to_a <=> other.to_a
end
@@ -37,7 +37,7 @@
# the_gem.spec # get the spec out of the gem
# the_gem.verify # check the gem is OK (contains valid gem specification, contains a not corrupt contents archive)
#
-# #files are the files in the .gem tar file, not the ruby files in the gem
# #extract_files and #contents automatically call #verify
require 'rubygems/security'
@@ -280,11 +280,16 @@ EOM
algorithms = if @checksums then
@checksums.keys
else
- [Gem::Security::DIGEST_NAME]
end
algorithms.each do |algorithm|
- digester = OpenSSL::Digest.new algorithm
digester << entry.read(16384) until entry.eof?
@@ -298,8 +303,11 @@ EOM
##
# Extracts the files in this package into +destination_dir+
- def extract_files destination_dir
verify unless @spec
FileUtils.mkdir_p destination_dir
@@ -310,7 +318,7 @@ EOM
reader.each do |entry|
next unless entry.full_name == 'data.tar.gz'
- extract_tar_gz entry, destination_dir
return # ignore further entries
end
@@ -324,11 +332,20 @@ EOM
# If an entry in the archive contains a relative path above
# +destination_dir+ or an absolute path is encountered an exception is
# raised.
- def extract_tar_gz io, destination_dir # :nodoc:
open_tar_gz io do |tar|
tar.each do |entry|
- destination = install_location entry.full_name, destination_dir
FileUtils.rm_rf destination
@@ -428,12 +445,13 @@ EOM
# certificate and key are not present only checksum generation is set up.
def setup_signer
if @spec.signing_key then
- @signer = Gem::Security::Signer.new @spec.signing_key, @spec.cert_chain
@spec.signing_key = nil
@spec.cert_chain = @signer.cert_chain.map { |cert| cert.to_s }
else
- @signer = Gem::Security::Signer.new nil, nil
@spec.cert_chain = @signer.cert_chain.map { |cert| cert.to_pem } if
@signer.cert_chain
end
@@ -510,27 +528,38 @@ EOM
end
##
# Verifies the files of the +gem+
def verify_files gem
gem.each do |entry|
- file_name = entry.full_name
- @files << file_name
-
- case file_name
- when /\.sig$/ then
- @signatures[$`] = entry.read if @security_policy
- next
- else
- digest entry
- end
-
- case file_name
- when /^metadata(.gz)?$/ then
- load_spec entry
- when 'data.tar.gz' then
- verify_gz entry
- end
end
unless @spec then
@@ -71,7 +71,7 @@ class Gem::Package::TarTestCase < Gem::TestCase
SP(Z(to_oct(sum, 6)))
end
- def header(type, fname, dname, length, mode, checksum = nil)
checksum ||= " " * 8
arr = [ # struct tarfile_entry_posix
@@ -80,7 +80,7 @@ class Gem::Package::TarTestCase < Gem::TestCase
Z(to_oct(0, 7)), # char uid[8]; ditto
Z(to_oct(0, 7)), # char gid[8]; ditto
Z(to_oct(length, 11)), # char size[12]; 0 padded, octal, null
- Z(to_oct(0, 11)), # char mtime[12]; 0 padded, octal, null
checksum, # char checksum[8]; 0 padded, octal, null, space
type, # char typeflag[1]; file: "0" dir: "5"
"\0" * 100, # char linkname[100]; ASCII + (Z unless filled)
@@ -105,16 +105,16 @@ class Gem::Package::TarTestCase < Gem::TestCase
ret
end
- def tar_dir_header(name, prefix, mode)
- h = header("5", name, prefix, 0, mode)
checksum = calc_checksum(h)
- header("5", name, prefix, 0, mode, checksum)
end
- def tar_file_header(fname, dname, mode, length)
- h = header("0", fname, dname, length, mode)
checksum = calc_checksum(h)
- header("0", fname, dname, length, mode, checksum)
end
def to_oct(n, pad_size)
@@ -130,7 +130,7 @@ class Gem::Package::TarTestCase < Gem::TestCase
end
def util_dir_entry
- util_entry tar_dir_header("foo", "bar", 0)
end
end
@@ -4,6 +4,8 @@
# See LICENSE.txt for additional licensing information.
#++
##
# Allows writing of tar files
@@ -121,7 +123,8 @@ class Gem::Package::TarWriter
@io.pos = init_pos
header = Gem::Package::TarHeader.new :name => name, :mode => mode,
- :size => size, :prefix => prefix
@io.write header
@io.pos = final_pos
@@ -140,7 +143,15 @@ class Gem::Package::TarWriter
def add_file_digest name, mode, digest_algorithms # :yields: io
digests = digest_algorithms.map do |digest_algorithm|
digest = digest_algorithm.new
- [digest.name, digest]
end
digests = Hash[*digests.flatten]
@@ -165,22 +176,32 @@ class Gem::Package::TarWriter
def add_file_signed name, mode, signer
digest_algorithms = [
signer.digest_algorithm,
- OpenSSL::Digest::SHA512,
- ].uniq
digests = add_file_digest name, mode, digest_algorithms do |io|
yield io
end
- signature_digest = digests.values.find do |digest|
- digest.name == signer.digest_name
end
- signature = signer.sign signature_digest.digest
- add_file_simple "#{name}.sig", 0444, signature.length do |io|
- io.write signature
- end if signature
digests
end
@@ -195,7 +216,8 @@ class Gem::Package::TarWriter
name, prefix = split_name name
header = Gem::Package::TarHeader.new(:name => name, :mode => mode,
- :size => size, :prefix => prefix).to_s
@io.write header
os = BoundedStream.new @io, size
@@ -256,7 +278,8 @@ class Gem::Package::TarWriter
header = Gem::Package::TarHeader.new :name => name, :mode => mode,
:typeflag => "5", :size => 0,
- :prefix => prefix
@io.write header
@@ -13,6 +13,10 @@ class Gem::PathSupport
attr_reader :path
##
#
# Constructor. Takes a single argument which is to be treated like a
# hashtable, or defaults to ENV, the system environment.
@@ -28,6 +32,12 @@ class Gem::PathSupport
end
self.path = env["GEM_PATH"] || ENV["GEM_PATH"]
end
private
@@ -2,6 +2,8 @@ require "rubygems/deprecate"
##
# Available list of platforms for targeting Gem installations.
class Gem::Platform
@@ -129,12 +131,16 @@ class Gem::Platform
# Does +other+ match this platform? Two platforms match if they have the
# same CPU, or either has a CPU of 'universal', they have the same OS, and
# they have the same version, or either has no version.
def ===(other)
return nil unless Gem::Platform === other
# cpu
- (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu) and
# os
@os == other.os and
@@ -175,13 +181,13 @@ class Gem::Platform
end
##
- # A pure-ruby gem that may use Gem::Specification#extensions to build
# binary files.
RUBY = 'ruby'
##
- # A platform-specific gem that is built for the packaging ruby's platform.
# This will be replaced with Gem::Platform::local.
CURRENT = 'current'
@@ -3,7 +3,7 @@
# in Specification._load, but if we don't have the constant, Marshal
# blows up.
-module Psych
class PrivateType
end
end
@@ -1,7 +1,7 @@
require 'rubygems'
require 'rubygems/user_interaction'
-require 'thread'
-require 'uri'
require 'resolv'
##
@@ -72,18 +72,7 @@ class Gem::RemoteFetcher
Socket.do_not_reverse_lookup = true
- @connections = {}
- @connections_mutex = Mutex.new
- @requests = Hash.new 0
- @proxy_uri =
- case proxy
- when :no_proxy then nil
- when nil then get_proxy_from_env
- when URI::HTTP then proxy
- else URI.parse(proxy)
- end
- @user_agent = user_agent
- @env_no_proxy = get_no_proxy_from_env
@dns = dns
end
@@ -202,7 +191,7 @@ class Gem::RemoteFetcher
source_uri.path
end
- source_path = unescape source_path
begin
FileUtils.cp source_path, local_gem_path unless
@@ -321,128 +310,6 @@ class Gem::RemoteFetcher
response['content-length'].to_i
end
- def escape(str)
- return unless str
- @uri_parser ||= uri_escaper
- @uri_parser.escape str
- end
-
- def unescape(str)
- return unless str
- @uri_parser ||= uri_escaper
- @uri_parser.unescape str
- end
-
- def uri_escaper
- URI::Parser.new
- rescue NameError
- URI
- end
-
- ##
- # Returns list of no_proxy entries (if any) from the environment
-
- def get_no_proxy_from_env
- env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']
-
- return [] if env_no_proxy.nil? or env_no_proxy.empty?
-
- env_no_proxy.split(/\s*,\s*/)
- end
-
- ##
- # Returns an HTTP proxy URI if one is set in the environment variables.
-
- def get_proxy_from_env
- env_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
-
- return nil if env_proxy.nil? or env_proxy.empty?
-
- uri = URI.parse(normalize_uri(env_proxy))
-
- if uri and uri.user.nil? and uri.password.nil? then
- # Probably we have http_proxy_* variables?
- uri.user = escape(ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER'])
- uri.password = escape(ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS'])
- end
-
- uri
- end
-
- ##
- # Normalize the URI by adding "http://" if it is missing.
-
- def normalize_uri(uri)
- (uri =~ /^(https?|ftp|file):/i) ? uri : "http://#{uri}"
- end
-
- ##
- # Creates or an HTTP connection based on +uri+, or retrieves an existing
- # connection, using a proxy if needed.
-
- def connection_for(uri)
- net_http_args = [uri.host, uri.port]
-
- if @proxy_uri and not no_proxy?(uri.host) then
- net_http_args += [
- @proxy_uri.host,
- @proxy_uri.port,
- @proxy_uri.user,
- @proxy_uri.password
- ]
- end
-
- 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]
- end
-
- if https?(uri) and not connection.started? then
- configure_connection_for_https(connection)
- end
-
- connection.start unless connection.started?
-
- connection
- rescue defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : Errno::EHOSTDOWN,
- Errno::EHOSTDOWN => e
- raise FetchError.new(e.message, uri)
- end
-
- def configure_connection_for_https(connection)
- require 'net/https'
- connection.use_ssl = true
- connection.verify_mode =
- Gem.configuration.ssl_verify_mode || OpenSSL::SSL::VERIFY_PEER
- store = OpenSSL::X509::Store.new
- if Gem.configuration.ssl_ca_cert
- if File.directory? Gem.configuration.ssl_ca_cert
- store.add_path Gem.configuration.ssl_ca_cert
- else
- store.add_file Gem.configuration.ssl_ca_cert
- end
- else
- store.set_default_paths
- add_rubygems_trusted_certs(store)
- end
- connection.cert_store = store
- rescue LoadError => e
- raise unless (e.respond_to?(:path) && e.path == 'openssl') ||
- e.message =~ / -- openssl$/
-
- raise Gem::Exception.new(
- 'Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources')
- end
-
- def add_rubygems_trusted_certs(store)
- pattern = File.expand_path("./ssl_certs/*.pem", File.dirname(__FILE__))
- Dir.glob(pattern).each do |ssl_cert_file|
- store.add_file ssl_cert_file
- end
- end
-
def correct_for_windows_path(path)
if path[0].chr == '/' && path[1].chr =~ /[a-z]/i && path[2].chr == ':'
path = path[1..-1]
@@ -451,136 +318,17 @@ class Gem::RemoteFetcher
end
end
- def no_proxy? host
- host = host.downcase
- @env_no_proxy.each do |pattern|
- pattern = pattern.downcase
- return true if host[-pattern.length, pattern.length ] == pattern
- end
- return false
- end
-
##
# Performs a Net::HTTP request of type +request_class+ on +uri+ returning
# a Net::HTTP response object. request maintains a table of persistent
# connections to reduce connect overhead.
def request(uri, request_class, last_modified = nil)
- request = request_class.new uri.request_uri
-
- unless uri.nil? || uri.user.nil? || uri.user.empty? then
- request.basic_auth uri.user, uri.password
- end
-
- request.add_field 'User-Agent', @user_agent
- request.add_field 'Connection', 'keep-alive'
- 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
-
- yield request if block_given?
-
- connection = connection_for uri
-
- retried = false
- bad_response = false
-
- begin
- @requests[connection.object_id] += 1
-
- say "#{request.method} #{uri}" if
- Gem.configuration.really_verbose
-
- file_name = File.basename(uri.path)
- # perform download progress reporter only for gems
- if request.response_body_permitted? && file_name =~ /\.gem$/
- reporter = ui.download_reporter
- response = connection.request(request) do |incomplete_response|
- if Net::HTTPOK === incomplete_response
- reporter.fetch(file_name, incomplete_response.content_length)
- downloaded = 0
- data = ''
-
- incomplete_response.read_body do |segment|
- data << segment
- downloaded += segment.length
- reporter.update(downloaded)
- end
- reporter.done
- if incomplete_response.respond_to? :body=
- incomplete_response.body = data
- else
- incomplete_response.instance_variable_set(:@body, data)
- end
- end
- end
- else
- response = connection.request request
- end
-
- say "#{response.code} #{response.message}" if
- Gem.configuration.really_verbose
-
- rescue Net::HTTPBadResponse
- say "bad response" if Gem.configuration.really_verbose
-
- reset connection
-
- raise FetchError.new('too many bad responses', uri) if bad_response
-
- 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, Timeout::Error,
- Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE
-
- requests = @requests[connection.object_id]
- say "connection reset after #{requests} requests, retrying" if
- Gem.configuration.really_verbose
-
- raise FetchError.new('too many connection resets', uri) if retried
-
- reset connection
-
- retried = true
- retry
- end
- response
- end
-
- ##
- # Resets HTTP connection +connection+.
-
- def reset(connection)
- @requests.delete connection.object_id
-
- connection.finish
- connection.start
- end
-
- def user_agent
- ua = "RubyGems/#{Gem::VERSION} #{Gem::Platform.local}"
-
- ruby_version = RUBY_VERSION
- ruby_version += 'dev' if RUBY_LEVEL == -1
-
- ua << " Ruby/#{ruby_version} (#{RUBY_RELEASE_DATE}"
- if RUBY_LEVEL >= 0 then
- ua << " level #{RUBY_LEVEL}"
- elsif defined?(RUBY_REVISION) then
- ua << " revision #{RUBY_REVISION}"
end
- ua << ")"
-
- ua << " #{RUBY_ENGINE}" if defined?(RUBY_ENGINE) and RUBY_ENGINE != 'ruby'
-
- ua
end
def https?(uri)
@@ -5,178 +5,179 @@ require 'rubygems/dependency_list'
require 'rubygems/installer'
require 'tsort'
-module Gem
- class RequestSet
- include TSort
- def initialize(*deps)
- @dependencies = deps
- yield self if block_given?
- end
- attr_reader :dependencies
- # Declare that a gem of name +name+ with +reqs+ requirements
- # is needed.
- #
- def gem(name, *reqs)
- @dependencies << Gem::Dependency.new(name, reqs)
- end
- # Add +deps+ Gem::Depedency objects to the set.
- #
- def import(deps)
- @dependencies += deps
- end
- # Resolve the requested dependencies and return an Array of
- # Specification objects to be activated.
- #
- def resolve(set=nil)
- r = Gem::DependencyResolver.new(@dependencies, set)
- @requests = r.resolve
- end
- # Resolve the requested dependencies against the gems
- # available via Gem.path and return an Array of Specification
- # objects to be activated.
- #
- def resolve_current
- resolve DependencyResolver::CurrentSet.new
- end
- # Load a dependency management file.
- #
- def load_gemdeps(path)
- gf = GemDepedencyAPI.new(self, path)
- gf.load
- end
- def specs
- @specs ||= @requests.map { |r| r.full_spec }
- end
- def tsort_each_node(&block)
- @requests.each(&block)
- end
- def tsort_each_child(node)
- node.spec.dependencies.each do |dep|
- next if dep.type == :development
-
- match = @requests.find { |r| dep.match? r.spec.name, r.spec.version }
- if match
- begin
- yield match
- rescue TSort::Cyclic
- end
- else
- raise Gem::DependencyError, "Unresolved depedency found during sorting - #{dep}"
- end
- end
- end
- def sorted_requests
- @sorted ||= strongly_connected_components.flatten
end
- def specs_in(dir)
- Dir["#{dir}/specifications/*.gemspec"].map do |g|
- Gem::Specification.load g
end
- end
- def install_into(dir, force=true, &b)
- existing = force ? [] : specs_in(dir)
- dir = File.expand_path dir
- installed = []
- sorted_requests.each do |req|
- if existing.find { |s| s.full_name == req.spec.full_name }
- b.call req, nil if b
- next
- end
- path = req.download(dir)
- inst = Gem::Installer.new path, :install_dir => dir,
- :only_install_dir => true
- b.call req, inst if b
- inst.install
- installed << req
end
- installed
- end
- def install(options, &b)
- if dir = options[:install_dir]
- return install_into(dir, false, &b)
end
- cache_dir = options[:cache_dir] || Gem.dir
- specs = []
- sorted_requests.each do |req|
- if req.installed?
- b.call req, nil if b
- next
- end
- path = req.download cache_dir
- inst = Gem::Installer.new path, options
- b.call req, inst if b
- specs << inst.install
- end
- specs
- end
- # A semi-compatible DSL for Bundler's Gemfile format
- #
- class GemDepedencyAPI
- def initialize(set, path)
- @set = set
- @path = path
- end
- def load
- instance_eval File.read(@path).untaint, @path, 1
- end
- # DSL
- def source(url)
- end
- def gem(name, *reqs)
- # Ignore the opts for now.
- reqs.pop if reqs.last.kind_of?(Hash)
- @set.gem name, *reqs
- end
- def platform(what)
- if what == :ruby
- yield
- end
- end
- alias_method :platforms, :platform
- def group(*what)
end
end
end
end
@@ -12,20 +12,6 @@ begin
rescue LoadError => e
raise unless (e.respond_to?(:path) && e.path == 'openssl') ||
e.message =~ / -- openssl$/
-
- module OpenSSL # :nodoc:
- class Digest # :nodoc:
- class SHA1 # :nodoc:
- def name
- 'SHA1'
- end
- end
- end
- module PKey # :nodoc:
- class RSA # :nodoc:
- end
- end
- end
end
##
@@ -352,17 +338,26 @@ module Gem::Security
##
# Digest algorithm used to sign gems
- DIGEST_ALGORITHM = OpenSSL::Digest::SHA1
##
# Used internally to select the signing digest from all computed digests
- DIGEST_NAME = DIGEST_ALGORITHM.new.name # :nodoc:
##
# Algorithm for creating the key pair used to sign gems
- KEY_ALGORITHM = OpenSSL::PKey::RSA
##
# Length of keys created by KEY_ALGORITHM
@@ -370,6 +365,12 @@ module Gem::Security
KEY_LENGTH = 2048
##
# One year in seconds
ONE_YEAR = 86400 * 365
@@ -563,13 +564,18 @@ module Gem::Security
##
# Writes +pemmable+, which must respond to +to_pem+ to +path+ with the given
- # +permissions+.
- def self.write pemmable, path, permissions = 0600
path = File.expand_path path
open path, 'wb', permissions do |io|
- io.write pemmable.to_pem
end
path
@@ -579,8 +585,11 @@ module Gem::Security
end
-require 'rubygems/security/policy'
-require 'rubygems/security/policies'
require 'rubygems/security/signer'
-require 'rubygems/security/trust_dir'
@@ -1,3 +1,5 @@
##
# A Gem::Security::Policy object encapsulates the settings for verifying
# signed gem files. This is the base class. You can either declare an
@@ -6,6 +8,8 @@
class Gem::Security::Policy
attr_reader :name
attr_accessor :only_signed
@@ -175,6 +179,19 @@ class Gem::Security::Policy
true
end
def inspect # :nodoc:
("[Policy: %s - data: %p signer: %p chain: %p root: %p " +
"signed-only: %p trusted-only: %p]") % [
@@ -184,16 +201,24 @@ class Gem::Security::Policy
end
##
- # Verifies the certificate +chain+ is valid, the +digests+ match the
- # signatures +signatures+ created by the signer depending on the +policy+
- # settings.
#
# If +key+ is given it is used to validate the signing certificate.
- def verify chain, key = nil, digests = {}, signatures = {}
- if @only_signed and signatures.empty? then
- raise Gem::Security::Exception,
- "unsigned gems are not allowed by the #{name} policy"
end
opt = @opt
@@ -222,7 +247,13 @@ class Gem::Security::Policy
check_root chain, time if @verify_root
- check_trust chain, digester, trust_dir if @only_trusted
signatures.each do |file, _|
digest = signer_digests[file]
@@ -252,7 +283,7 @@ class Gem::Security::Policy
OpenSSL::X509::Certificate.new cert_pem
end
- verify chain, nil, digests, signatures
true
end
@@ -29,7 +29,7 @@ class Gem::Security::Signer
# +chain+ containing X509 certificates, encoding certificates or paths to
# certificates.
- def initialize key, cert_chain
@cert_chain = cert_chain
@key = key
@@ -46,7 +46,7 @@ class Gem::Security::Signer
@digest_algorithm = Gem::Security::DIGEST_ALGORITHM
@digest_name = Gem::Security::DIGEST_NAME
- @key = OpenSSL::PKey::RSA.new File.read @key if
@key and not OpenSSL::PKey::RSA === @key
if @cert_chain then
@@ -63,6 +63,22 @@ class Gem::Security::Signer
end
##
# Loads any missing issuers in the cert chain from the trusted certificates.
#
# If the issuer does not exist it is ignored as it will be checked later.
@@ -89,7 +105,9 @@ class Gem::Security::Signer
re_sign_key
end
- Gem::Security::SigningPolicy.verify @cert_chain, @key
@key.sign @digest_algorithm.new, data
end
@@ -670,13 +670,13 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
# documentation for the particular gem, otherwise a list with results is
# shown.
#
- # === Additional trick - install documentation for ruby core
#
# Note: please adjust paths accordingly use for example 'locate yaml.rb' and
# 'gem environment' to identify directories, that are specific for your
# local installation
#
- # 1. install ruby sources
# cd /usr/src
# sudo apt-get source ruby
#
@@ -702,7 +702,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
# name pattern was found.
#
# The search is based on the file system content, not on the gems metadata.
- # This allows additional documentation folders like 'core' for the ruby core
# documentation - just put it underneath the main doc folder.
def show_rdoc_for_pattern(pattern, res)
@@ -25,14 +25,23 @@ class Gem::Source
end
def <=>(other)
- if !@uri
- return 0 unless other.uri
- return -1
- end
- return 1 if !other.uri
- @uri.to_s <=> other.uri.to_s
end
include Comparable
@@ -58,8 +67,7 @@ class Gem::Source
def cache_dir(uri)
# Correct for windows paths
escaped_path = uri.path.sub(/^\/([a-z]):\//i, '/\\1-/')
- root = File.join Gem.user_home, '.gem', 'specs'
- File.join root, "#{uri.host}%#{uri.port}", File.dirname(escaped_path)
end
def update_cache?
@@ -141,4 +149,16 @@ class Gem::Source
fetcher = Gem::RemoteFetcher.fetcher
fetcher.download spec, @uri.to_s, dir
end
end
@@ -1,92 +1,5 @@
require 'rubygems/source'
-class Gem::Source::Local < Gem::Source
- def initialize
- @uri = nil
- end
- def load_specs(type)
- names = []
-
- @specs = {}
-
- Dir["*.gem"].each do |file|
- begin
- pkg = Gem::Package.new(file)
- rescue SystemCallError, Gem::Package::FormatError
- # ignore
- else
- tup = pkg.spec.name_tuple
- @specs[tup] = [File.expand_path(file), pkg]
-
- case type
- when :released
- unless pkg.spec.version.prerelease?
- names << pkg.spec.name_tuple
- end
- when :prerelease
- if pkg.spec.version.prerelease?
- names << pkg.spec.name_tuple
- end
- when :latest
- tup = pkg.spec.name_tuple
-
- cur = names.find { |x| x.name == tup.name }
- if !cur
- names << tup
- elsif cur.version < tup.version
- names.delete cur
- names << tup
- end
- else
- names << pkg.spec.name_tuple
- end
- end
- end
-
- names
- end
-
- def find_gem(gem_name, version=Gem::Requirement.default,
- prerelease=false)
- load_specs :complete
-
- found = []
-
- @specs.each do |n, data|
- if n.name == gem_name
- s = data[1].spec
-
- if version.satisfied_by?(s.version)
- if prerelease
- found << s
- elsif !s.version.prerelease?
- found << s
- end
- end
- end
- end
-
- found.sort_by { |s| s.version }.last
- end
-
- def fetch_spec(name)
- load_specs :complete
-
- if data = @specs[name]
- data.last.spec
- else
- raise Gem::Exception, "Unable to find spec for '#{name}'"
- end
- end
-
- def download(spec, cache_dir=nil)
- load_specs :complete
-
- @specs.each do |name, data|
- return data[0] if data[1].spec == spec
- end
-
- raise Gem::Exception, "Unable to find file for '#{spec.full_name}'"
- end
-end
@@ -1,28 +1,4 @@
-class Gem::Source::SpecificFile < Gem::Source
- def initialize(file)
- @uri = nil
- @path = ::File.expand_path(file)
- @package = Gem::Package.new @path
- @spec = @package.spec
- @name = @spec.name_tuple
- end
- attr_reader :spec
-
- def load_specs(*a)
- [@name]
- end
-
- def fetch_spec(name)
- return @spec if name == @name
- raise Gem::Exception, "Unable to find '#{name}'"
- @spec
- end
-
- def download(spec, dir=nil)
- return @path if spec == @spec
- raise Gem::Exception, "Unable to download '#{spec.full_name}'"
- end
-
-end
@@ -38,7 +38,6 @@ class Gem::SpecFetcher
end
def initialize
- @dir = File.join Gem.user_home, '.gem', 'specs'
@update_cache = File.stat(Gem.user_home).uid == Process.uid
@specs = {}
@@ -75,6 +74,12 @@ class Gem::SpecFetcher
list, errors = available_specs(type)
list.each do |source, specs|
found[source] = specs.select do |tup|
if dependency.match?(tup)
if matching_platform and !Gem::Platform.match(tup.platform)
@@ -195,8 +200,11 @@ class Gem::SpecFetcher
when :released
tuples_for source, :released
when :complete
- tuples_for(source, :prerelease, true) +
tuples_for(source, :released)
when :prerelease
tuples_for(source, :prerelease)
else
@@ -215,15 +223,15 @@ class Gem::SpecFetcher
def tuples_for(source, type, gracefully_ignore=false)
cache = @caches[type]
- if gracefully_ignore
begin
cache[source.uri] ||= source.load_specs(type)
rescue Gem::RemoteFetcher::FetchError
[]
end
- else
- cache[source.uri] ||= source.load_specs(type)
- end
end
end
@@ -5,10 +5,13 @@
# See LICENSE.txt for permissions.
#++
require 'rubygems/version'
require 'rubygems/requirement'
require 'rubygems/platform'
require 'rubygems/deprecate'
# :stopdoc:
# date.rb can't be loaded for `make install` due to miniruby
@@ -31,7 +34,7 @@ class Date; end
# s.homepage = 'https://rubygems.org/gems/example'
# end
#
-# Starting in RubyGems 1.9.0, a Specification can hold arbitrary
# metadata. This metadata is accessed via Specification#metadata
# and has the following restrictions:
#
@@ -45,7 +48,7 @@ class Date; end
#
# s.metadata = { "bugtracker" => "http://somewhere.com/blah" }
-class Gem::Specification
# REFACTOR: Consider breaking out this version stuff into a separate
# module. There's enough special stuff around it that it may justify
@@ -107,6 +110,10 @@ class Gem::Specification
today = Time.now.utc
TODAY = Time.utc(today.year, today.month, today.day)
# :startdoc:
##
@@ -156,6 +163,17 @@ class Gem::Specification
:version => nil,
}
@@attributes = @@default_value.keys.sort_by { |s| s.to_s }
@@array_attributes = @@default_value.reject { |k,v| v != [] }.keys
@@nil_attributes, @@non_nil_attributes = @@default_value.keys.partition { |k|
@@ -440,7 +458,7 @@ class Gem::Specification
#
# For example, the rake gem has rake as an executable. You don’t specify the
# full path (as in bin/rake); all application-style files are expected to be
- # found in bindir. These files must be executable ruby files. Files that
# use bash or other interpreters will not work.
#
# Usage:
@@ -599,17 +617,12 @@ class Gem::Specification
attr_writer :default_executable
##
- # Path this gemspec was loaded from. This attribute is not persisted.
-
- attr_reader :loaded_from
-
- ##
# Allows deinstallation of gems with legacy platforms.
attr_writer :original_platform # :nodoc:
##
- # The version of ruby required by this gem
attr_reader :required_ruby_version
@@ -633,58 +646,68 @@ class Gem::Specification
attr_accessor :specification_version
- class << self
- def default_specifications_dir
- File.join(Gem.default_dir, "specifications", "default")
end
- def each_spec(search_dirs) # :nodoc:
- search_dirs.each { |dir|
- Dir[File.join(dir, "*.gemspec")].each { |path|
- spec = Gem::Specification.load path.untaint
- # #load returns nil if the spec is bad, so we just ignore
- # it at this stage
- yield(spec) if spec
- }
- }
end
- def each_default(&block) # :nodoc:
- each_spec([default_specifications_dir],
- &block)
end
- def each_normal(&block) # :nodoc:
- each_spec(dirs, &block)
end
end
- def self._all # :nodoc:
- unless defined?(@@all) && @@all then
- specs = {}
- each_default do |spec|
- specs[spec.full_name] ||= spec
end
- each_normal do |spec|
- specs[spec.full_name] ||= spec
- end
-
- @@all = specs.values
- # After a reset, make sure already loaded specs
- # are still marked as activated.
- specs = {}
- Gem.loaded_specs.each_value{|s| specs[s] = true}
- @@all.each{|s| s.activated = true if specs[s]}
-
- _resort!
end
- @@all
end
- def self._resort! # :nodoc:
- @@all.sort! { |a, b|
names = a.name <=> b.name
next names if names.nonzero?
b.version <=> a.version
@@ -695,7 +718,9 @@ class Gem::Specification
# Loads the default specifications. It should be called only once.
def self.load_defaults
- each_default do |spec|
Gem.register_default_spec(spec)
end
end
@@ -718,7 +743,9 @@ class Gem::Specification
return if _all.include? spec
_all << spec
- _resort!
end
##
@@ -759,7 +786,7 @@ class Gem::Specification
# -- wilsonb
def self.all= specs
- @@all = specs
end
##
@@ -861,9 +888,10 @@ class Gem::Specification
# amongst the specs that are not activated.
def self.find_inactive_by_path path
- self.find { |spec|
- spec.contains_requirable_file? path unless spec.activated?
}
end
##
@@ -944,7 +972,7 @@ class Gem::Specification
result.map(&:last).map(&:values).flatten.reject { |spec|
minimum = native[spec.name]
minimum && spec.version < minimum
- }
end
##
@@ -955,6 +983,9 @@ class Gem::Specification
file = file.dup.untaint
return unless File.file?(file)
code = if defined? Encoding
File.read file, :mode => 'r:UTF-8:-'
else
@@ -968,6 +999,7 @@ class Gem::Specification
if Gem::Specification === spec
spec.loaded_from = file.to_s
return spec
end
@@ -1002,25 +1034,43 @@ class Gem::Specification
end
##
- # Return a list of all outdated specifications. This method is HEAVY
# as it must go fetch specifications from the server.
def self.outdated
- outdateds = []
# TODO: maybe we should switch to rubygems' version service?
fetcher = Gem::SpecFetcher.fetcher
- latest_specs(true).each do |local|
- dependency = Gem::Dependency.new local.name, ">= #{local.version}"
- remotes, _ = fetcher.search_for_dependency dependency
- remotes = remotes.map { |n, _| n.version }
- latest = remotes.sort.last
- outdateds << local.name if latest and local.version < latest
end
- outdateds
end
##
@@ -1031,6 +1081,7 @@ class Gem::Specification
raise "wtf: #{spec.full_name} not in #{all_names.inspect}" unless
_all.include? spec
_all.delete spec
end
##
@@ -1055,6 +1106,8 @@ class Gem::Specification
@@dirs = nil
Gem.pre_reset_hooks.each { |hook| hook.call }
@@all = nil
unresolved = unresolved_deps
unless unresolved.empty? then
w = "W" + "ARN"
@@ -1301,20 +1354,6 @@ class Gem::Specification
end
##
- # Returns the full path to the base gem directory.
- #
- # eg: /usr/local/lib/ruby/gems/1.8
-
- def base_dir
- return Gem.dir unless loaded_from
- @base_dir ||= if default_gem? then
- File.dirname File.dirname File.dirname loaded_from
- else
- File.dirname File.dirname loaded_from
- end
- end
-
- ##
# Returns the full path to installed gem's bin directory.
#
# NOTE: do not confuse this with +bindir+, which is just 'bin', not
@@ -1388,19 +1427,6 @@ class Gem::Specification
end
##
- # Return true if this spec can require +file+.
-
- def contains_requirable_file? file
- root = full_gem_path
- suffixes = Gem.suffixes
-
- require_paths.any? do |lib|
- base = "#{root}/#{lib}/#{file}"
- suffixes.any? { |suf| File.file? "#{base}#{suf}" }
- end
- end
-
- ##
# The date this gem was created. Lazily defaults to the current UTC date.
#
# There is no need to set this in your gem specification.
@@ -1645,35 +1671,14 @@ class Gem::Specification
spec
end
- ##
- # The full path to the gem (install path + full name).
-
- def full_gem_path
- # TODO: This is a heavily used method by gems, so we'll need
- # to aleast just alias it to #gem_dir rather than remove it.
-
- # TODO: also, shouldn't it default to full_name if it hasn't been written?
- return @full_gem_path if defined?(@full_gem_path) && @full_gem_path
-
- @full_gem_path = File.expand_path File.join(gems_dir, full_name)
- @full_gem_path.untaint
-
- return @full_gem_path if File.directory? @full_gem_path
-
- @full_gem_path = File.expand_path File.join(gems_dir, original_name)
end
-
- ##
- # Returns the full name (name-version) of this Gem. Platform information
- # is included (name-version-platform) if it is specified and not the
- # default Ruby platform.
def full_name
- @full_name ||= if platform == Gem::Platform::RUBY or platform.nil? then
- "#{@name}-#{@version}".untaint
- else
- "#{@name}-#{@version}-#{platform}".untaint
- end
end
##
@@ -1685,15 +1690,6 @@ class Gem::Specification
end
##
- # Returns the full path to the gems directory containing this spec's
- # gem directory. eg: /usr/local/lib/ruby/1.8/gems
-
- def gems_dir
- # TODO: this logic seems terribly broken, but tests fail if just base_dir
- @gems_dir ||= File.join(loaded_from && base_dir || Gem.dir, "gems")
- end
-
- ##
# Deprecated and ignored, defaults to true.
#
# Formerly used to indicate this gem was RDoc-capable.
@@ -1725,9 +1721,7 @@ class Gem::Specification
# :startdoc:
def hash # :nodoc:
- @@attributes.inject(0) { |hash_code, (name, _)|
- hash_code ^ self.send(name).hash
- }
end
def init_with coder # :nodoc:
@@ -1742,7 +1736,7 @@ class Gem::Specification
def initialize name = nil, version = nil
@loaded = false
@activated = false
- @loaded_from = nil
@original_platform = nil
@@nil_attributes.each do |key|
@@ -1751,11 +1745,7 @@ class Gem::Specification
@@non_nil_attributes.each do |key|
default = default_value(key)
- value = case default
- when Time, Numeric, Symbol, true, false, nil then default
- else default.dup
- end
-
instance_variable_set "@#{key}", value
end
@@ -1850,22 +1840,14 @@ class Gem::Specification
@licenses ||= []
end
- ##
- # Set the location a Specification was loaded from. +obj+ is converted
- # to a String.
-
- def loaded_from= path
- @loaded_from = path.to_s
- # reset everything @loaded_from depends upon
- @base_dir = nil
@bin_dir = nil
@cache_dir = nil
@cache_file = nil
@doc_dir = nil
- @full_gem_path = nil
@gem_dir = nil
- @gems_dir = nil
@ri_dir = nil
@spec_dir = nil
@spec_file = nil
@@ -2050,6 +2032,10 @@ class Gem::Specification
@requirements = Array req
end
##
# Returns the full path to this spec's ri directory.
@@ -2111,11 +2097,17 @@ class Gem::Specification
# Returns an object you can use to sort specifications in #sort_by.
def sort_obj
- # TODO: this is horrible. Deprecate it.
[@name, @version, @new_platform == Gem::Platform::RUBY ? -1 : 1]
end
##
# Returns the full path to the directory containing this spec's
# gemspec file. eg: /usr/local/lib/ruby/gems/1.8/specifications
@@ -2194,6 +2186,7 @@ class Gem::Specification
mark_version
result = []
result << "# -*- encoding: utf-8 -*-"
result << nil
result << "Gem::Specification.new do |s|"
@@ -2281,6 +2274,13 @@ class Gem::Specification
"#<Gem::Specification name=#{@name} version=#{@version}>"
end
def to_yaml(opts = {}) # :nodoc:
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? then
# Because the user can switch the YAML engine behind our
@@ -2581,11 +2581,6 @@ class Gem::Specification
end
end
- def default_gem?
- loaded_from &&
- File.dirname(loaded_from) == self.class.default_specifications_dir
- end
-
extend Gem::Deprecate
# TODO:
@@ -58,7 +58,7 @@ module Gem
end
##
- # Allows setting path to ruby. This method is available when requiring
# 'rubygems/test_case'
def self.ruby= ruby
@@ -84,6 +84,23 @@ end
class Gem::TestCase < MiniTest::Unit::TestCase
# TODO: move to minitest
def assert_path_exists path, msg = nil
msg = message(msg) { "Expected path '#{path}' to exist" }
@@ -206,10 +223,11 @@ class Gem::TestCase < MiniTest::Unit::TestCase
@gemhome = File.join @tempdir, 'gemhome'
@userhome = File.join @tempdir, 'userhome'
@orig_ruby = if ENV['RUBY'] then
- ruby = Gem.instance_variable_get :@ruby
- Gem.instance_variable_set :@ruby, ENV['RUBY']
ruby
end
@@ -227,6 +245,9 @@ class Gem::TestCase < MiniTest::Unit::TestCase
FileUtils.mkdir_p @gemhome
FileUtils.mkdir_p @userhome
@default_dir = File.join @tempdir, 'default'
@default_spec_dir = File.join @default_dir, "specifications", "default"
Gem.instance_variable_set :@default_dir, @default_dir
@@ -272,39 +293,6 @@ class Gem::TestCase < MiniTest::Unit::TestCase
end
@marshal_version = "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
-
- # TODO: move to installer test cases
- Gem.post_build_hooks.clear
- Gem.post_install_hooks.clear
- Gem.done_installing_hooks.clear
- Gem.post_reset_hooks.clear
- Gem.post_uninstall_hooks.clear
- Gem.pre_install_hooks.clear
- Gem.pre_reset_hooks.clear
- Gem.pre_uninstall_hooks.clear
-
- # TODO: move to installer test cases
- Gem.post_build do |installer|
- @post_build_hook_arg = installer
- true
- end
-
- 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
- true
- end
-
- Gem.pre_uninstall do |uninstaller|
- @pre_uninstall_hook_arg = uninstaller
- end
end
##
@@ -328,8 +316,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
ENV['GEM_HOME'] = @orig_gem_home
ENV['GEM_PATH'] = @orig_gem_path
- _ = @orig_ruby
- Gem.instance_variable_set :@ruby, @orig_ruby if @orig_ruby
if @orig_ENV_HOME then
ENV['HOME'] = @orig_ENV_HOME
@@ -338,6 +325,47 @@ class Gem::TestCase < MiniTest::Unit::TestCase
end
Gem.instance_variable_set :@default_dir, nil
end
##
@@ -566,6 +594,21 @@ class Gem::TestCase < MiniTest::Unit::TestCase
end
end
##
# Create a new spec (or gem if passed an array of files) and set it
# up properly. Use this instead of util_spec and util_gem.
@@ -742,7 +785,7 @@ Also, a list:
@a_evil9 = quick_gem('a_evil', '9', &init)
@b2 = quick_gem('b', '2', &init)
@c1_2 = quick_gem('c', '1.2', &init)
- @x = quick_gem('x', '1', &init)
@dep_x = quick_gem('dep_x', '1') do |s|
s.files = %w[lib/code.rb]
s.require_paths = %w[lib]
@@ -762,14 +805,15 @@ Also, a list:
util_build_gem @a2_pre
end
- write_file File.join(*%W[gems #{@a1.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@a2.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@a3a.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@b2.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@x.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@dep_x.original_name} lib code.rb])
[@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1, @x, @dep_x].each do |spec|
util_build_gem spec
@@ -972,7 +1016,7 @@ Also, a list:
end
##
- # Finds the path to the ruby executable
def self.rubybin
ruby = ENV["RUBY"]
@@ -1012,6 +1056,24 @@ Also, a list:
end
##
# Constructs a new Gem::Requirement.
def req *requirements
@@ -1035,7 +1097,11 @@ Also, a list:
class StaticSet
def initialize(specs)
- @specs = specs.sort_by { |s| s.full_name }
end
def find_spec(dep)
@@ -1048,6 +1114,15 @@ Also, a list:
@specs.find_all { |s| dep.matches_spec? s }
end
def prefetch(reqs)
end
end
@@ -1080,18 +1155,18 @@ Also, a list:
end
##
- # Loads an RSA private key named +key_name+ in <tt>test/rubygems/</tt>
- def self.load_key key_name
key_file = key_path key_name
key = File.read key_file
- OpenSSL::PKey::RSA.new key
end
##
- # Returns the path tot he key named +key_name+ from <tt>test/rubygems</tt>
def self.key_path key_name
File.expand_path "../../../test/rubygems/#{key_name}_key.pem", __FILE__
@@ -1100,17 +1175,24 @@ Also, a list:
# :stopdoc:
# only available in RubyGems tests
begin
- PRIVATE_KEY = load_key 'private'
- PRIVATE_KEY_PATH = key_path 'private'
- PUBLIC_KEY = PRIVATE_KEY.public_key
- PUBLIC_CERT = load_cert 'public'
- PUBLIC_CERT_PATH = cert_path 'public'
rescue Errno::ENOENT
PRIVATE_KEY = nil
PUBLIC_KEY = nil
PUBLIC_CERT = nil
- end
end
@@ -43,14 +43,15 @@ class Gem::Uninstaller
def initialize(gem, options = {})
# TODO document the valid options
- @gem = gem
- @version = options[:version] || Gem::Requirement.default
- @gem_home = File.expand_path(options[:install_dir] || Gem.dir)
- @force_executables = options[:executables]
- @force_all = options[:all]
- @force_ignore = options[:ignore]
- @bin_dir = options[:bin_dir]
- @format_executable = options[:format_executable]
# Indicate if development dependencies should be checked when
# uninstalling. (default: false)
@@ -143,7 +144,7 @@ class Gem::Uninstaller
@spec = spec
unless dependencies_ok? spec
- unless ask_if_ok(spec)
raise Gem::DependencyRemovalException,
"Uninstallation aborted due to dependent gem(s)"
end
@@ -290,6 +291,10 @@ class Gem::Uninstaller
deplist.ok_to_remove?(spec.full_name, @check_dev)
end
def ask_if_ok(spec)
msg = ['']
msg << 'You have requested to uninstall the gem:'
@@ -147,13 +147,16 @@ class Gem::Version
# FIX: These are only used once, in .correct?. Do they deserve to be
# constants?
- VERSION_PATTERN = '[0-9]+(?>\.[0-9a-zA-Z]+)*' # :nodoc:
ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})*\s*\z/ # :nodoc:
##
# A string representation of this Version.
- attr_reader :version
alias to_s version
##
@@ -183,6 +186,12 @@ class Gem::Version
end
end
##
# Constructs a Version from the +version+ string. A version string is a
# series of digits or ASCII letters separated by dots.
@@ -191,7 +200,8 @@ class Gem::Version
raise ArgumentError, "Malformed version number string #{version}" unless
self.class.correct?(version)
- @version = version.to_s.dup.strip
end
##
@@ -42,6 +42,7 @@ module Gem::VersionOption
add_option("--[no-]prerelease",
"Allow prerelease versions of a gem", *wrap) do |value, options|
options[:prerelease] = value
end
end
@@ -50,14 +51,19 @@ module Gem::VersionOption
def add_version_option(task = command, *wrap)
OptionParser.accept Gem::Requirement do |value|
- Gem::Requirement.new value
end
add_option('-v', '--version VERSION', Gem::Requirement,
"Specify version of gem to #{task}", *wrap) do
|value, options|
options[:version] = value
- options[:prerelease] = true if value.prerelease?
end
end
@@ -43,3 +43,26 @@ ySjIblqVQkPuzebv3Ror6ZnVDukn96Mg7kP4u6zgxOeqlJGRe1M949SS9Vudjl8X
SF4aZUUB9pQGhsqQJVqaz2OlhGOp9D0q54xko/rekjAIcuDjl1mdX4F2WRrzpUmZ
uY/bPeOBYiVsOYVe
-----END CERTIFICATE-----
@@ -13,128 +13,21 @@ end
class TestGem < Gem::TestCase
def setup
super
ENV.delete 'RUBYGEMS_GEMDEPS'
@additional = %w[a b].map { |d| File.join @tempdir, d }
util_remove_interrupt_command
end
- def assert_activate expected, *specs
- specs.each do |spec|
- case spec
- when String then
- Gem::Specification.find_by_name(spec).activate
- when Gem::Specification then
- spec.activate
- else
- flunk spec.inspect
- end
- end
-
- loaded = Gem.loaded_specs.values.map(&:full_name)
-
- assert_equal expected.sort, loaded.sort if expected
- end
-
- def test_self_activate
- foo = util_spec 'foo', '1'
-
- assert_activate %w[foo-1], foo
- end
-
- def loaded_spec_names
- Gem.loaded_specs.values.map(&:full_name).sort
- end
-
- def unresolved_names
- Gem::Specification.unresolved_deps.values.map(&:to_s).sort
- end
-
- # TODO: move these to specification
- def test_self_activate_via_require
- a1 = new_spec "a", "1", "b" => "= 1"
- b1 = new_spec "b", "1", nil, "lib/b/c.rb"
- b2 = new_spec "b", "2", nil, "lib/b/c.rb"
-
- install_specs a1, b1, b2
-
- a1.activate
- save_loaded_features do
- require "b/c"
- end
-
- assert_equal %w(a-1 b-1), loaded_spec_names
- end
-
- # TODO: move these to specification
- def test_self_activate_deep_unambiguous
- a1 = new_spec "a", "1", "b" => "= 1"
- b1 = new_spec "b", "1", "c" => "= 1"
- b2 = new_spec "b", "2", "c" => "= 2"
- c1 = new_spec "c", "1"
- c2 = new_spec "c", "2"
-
- install_specs a1, b1, b2, c1, c2
-
- a1.activate
- assert_equal %w(a-1 b-1 c-1), loaded_spec_names
- end
-
- def save_loaded_features
- old_loaded_features = $LOADED_FEATURES.dup
- yield
- ensure
- $LOADED_FEATURES.replace old_loaded_features
- end
-
- # TODO: move these to specification
- def test_self_activate_ambiguous_direct
- save_loaded_features do
- a1 = new_spec "a", "1", "b" => "> 0"
- b1 = new_spec("b", "1", { "c" => ">= 1" }, "lib/d.rb")
- b2 = new_spec("b", "2", { "c" => ">= 2" }, "lib/d.rb")
- c1 = new_spec "c", "1"
- c2 = new_spec "c", "2"
-
- Gem::Specification.reset
- install_specs a1, b1, b2, c1, c2
-
- a1.activate
- assert_equal %w(a-1), loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
-
- require "d"
-
- assert_equal %w(a-1 b-2 c-2), loaded_spec_names
- assert_equal [], unresolved_names
- end
- end
-
- # TODO: move these to specification
- def test_self_activate_ambiguous_indirect
- save_loaded_features do
- a1 = new_spec "a", "1", "b" => "> 0"
- b1 = new_spec "b", "1", "c" => ">= 1"
- b2 = new_spec "b", "2", "c" => ">= 2"
- c1 = new_spec "c", "1", nil, "lib/d.rb"
- c2 = new_spec "c", "2", nil, "lib/d.rb"
-
- install_specs a1, b1, b2, c1, c2
-
- a1.activate
- assert_equal %w(a-1), loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
-
- require "d"
-
- assert_equal %w(a-1 b-2 c-2), loaded_spec_names
- assert_equal [], unresolved_names
- end
- end
-
def test_self_finish_resolve
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -157,36 +50,6 @@ class TestGem < Gem::TestCase
end
end
- def test_self_activate_via_require_wtf
- save_loaded_features do
- a1 = new_spec "a", "1", "b" => "> 0", "d" => "> 0" # this
- b1 = new_spec "b", "1", { "c" => ">= 1" }, "lib/b.rb"
- b2 = new_spec "b", "2", { "c" => ">= 2" }, "lib/b.rb" # this
- c1 = new_spec "c", "1"
- c2 = new_spec "c", "2" # this
- d1 = new_spec "d", "1", { "c" => "< 2" }, "lib/d.rb"
- d2 = new_spec "d", "2", { "c" => "< 2" }, "lib/d.rb" # this
-
- install_specs a1, b1, b2, c1, c2, d1, d2
-
- a1.activate
-
- assert_equal %w(a-1), loaded_spec_names
- assert_equal ["b (> 0)", "d (> 0)"], unresolved_names
-
- require "b"
-
- e = assert_raises Gem::LoadError do
- require "d"
- end
-
- assert_equal "unable to find a version of 'd' to activate", e.message
-
- assert_equal %w(a-1 b-2 c-2), loaded_spec_names
- assert_equal ["d (> 0)"], unresolved_names
- end
- end
-
def test_self_finish_resolve_wtf
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0", "d" => "> 0" # this
@@ -211,94 +74,6 @@ class TestGem < Gem::TestCase
end
end
- # TODO: move these to specification
- def test_self_activate_ambiguous_unrelated
- save_loaded_features do
- a1 = new_spec "a", "1", "b" => "> 0"
- b1 = new_spec "b", "1", "c" => ">= 1"
- b2 = new_spec "b", "2", "c" => ">= 2"
- c1 = new_spec "c", "1"
- c2 = new_spec "c", "2"
- d1 = new_spec "d", "1", nil, "lib/d.rb"
-
- install_specs a1, b1, b2, c1, c2, d1
-
- a1.activate
- assert_equal %w(a-1), loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
-
- require "d"
-
- assert_equal %w(a-1 d-1), loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
- end
- end
-
- # TODO: move these to specification
- def test_self_activate_ambiguous_indirect_conflict
- save_loaded_features do
- a1 = new_spec "a", "1", "b" => "> 0"
- a2 = new_spec "a", "2", "b" => "> 0"
- b1 = new_spec "b", "1", "c" => ">= 1"
- b2 = new_spec "b", "2", "c" => ">= 2"
- c1 = new_spec "c", "1", nil, "lib/d.rb"
- c2 = new_spec("c", "2", { "a" => "1" }, "lib/d.rb") # conflicts with a-2
-
- install_specs a1, a2, b1, b2, c1, c2
-
- a2.activate
- assert_equal %w(a-2), loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
-
- require "d"
-
- assert_equal %w(a-2 b-1 c-1), loaded_spec_names
- assert_equal [], unresolved_names
- end
- end
-
- # TODO: move these to specification
- def test_require_already_activated
- save_loaded_features do
- a1 = new_spec "a", "1", nil, "lib/d.rb"
-
- install_specs a1 # , a2, b1, b2, c1, c2
-
- a1.activate
- assert_equal %w(a-1), loaded_spec_names
- assert_equal [], unresolved_names
-
- assert require "d"
-
- assert_equal %w(a-1), loaded_spec_names
- assert_equal [], unresolved_names
- end
- end
-
- # TODO: move these to specification
- def test_require_already_activated_indirect_conflict
- save_loaded_features do
- a1 = new_spec "a", "1", "b" => "> 0"
- a2 = new_spec "a", "2", "b" => "> 0"
- b1 = new_spec "b", "1", "c" => ">= 1"
- b2 = new_spec "b", "2", "c" => ">= 2"
- c1 = new_spec "c", "1", nil, "lib/d.rb"
- c2 = new_spec("c", "2", { "a" => "1" }, "lib/d.rb") # conflicts with a-2
-
- install_specs a1, a2, b1, b2, c1, c2
-
- a1.activate
- c1.activate
- assert_equal %w(a-1 c-1), loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
-
- assert require "d"
-
- assert_equal %w(a-1 c-1), loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
- end
- end
-
def test_require_missing
save_loaded_features do
assert_raises ::LoadError do
@@ -321,221 +96,6 @@ class TestGem < Gem::TestCase
end
end
- # TODO: move these to specification
- def test_self_activate_loaded
- foo = util_spec 'foo', '1'
-
- assert foo.activate
- refute foo.activate
- end
-
- ##
- # [A] depends on
- # [B] >= 1.0 (satisfied by 2.0)
- # [C] depends on nothing
-
- def test_self_activate_unrelated
- a = util_spec 'a', '1.0', 'b' => '>= 1.0'
- util_spec 'b', '1.0'
- c = util_spec 'c', '1.0'
-
- assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
- end
-
- ##
- # [A] depends on
- # [B] >= 1.0 (satisfied by 2.0)
- # [C] = 1.0 depends on
- # [B] ~> 1.0
- #
- # and should resolve using b-1.0
- # TODO: move these to specification
-
- def test_self_activate_over
- a = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0'
- util_spec 'b', '1.0'
- util_spec 'b', '1.1'
- util_spec 'b', '2.0'
- util_spec 'c', '1.0', 'b' => '~> 1.0'
-
- a.activate
-
- assert_equal %w[a-1.0 c-1.0], loaded_spec_names
- assert_equal ["b (>= 1.0, ~> 1.0)"], unresolved_names
- end
-
- ##
- # [A] depends on
- # [B] ~> 1.0 (satisfied by 1.1)
- # [C] = 1.0 depends on
- # [B] = 1.0
- #
- # and should resolve using b-1.0
- #
- # TODO: this is not under, but over... under would require depth
- # first resolve through a dependency that is later pruned.
-
- def test_self_activate_under
- a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0'
- util_spec 'b', '1.0'
- util_spec 'b', '1.1'
- c, _ = util_spec 'c', '1.0', 'b' => '= 1.0'
-
- assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
- end
-
- ##
- # [A1] depends on
- # [B] > 0 (satisfied by 2.0)
- # [B1] depends on
- # [C] > 0 (satisfied by 1.0)
- # [B2] depends on nothing!
- # [C1] depends on nothing
-
- def test_self_activate_dropped
- a1, = util_spec 'a', '1', 'b' => nil
- util_spec 'b', '1', 'c' => nil
- util_spec 'b', '2'
- util_spec 'c', '1'
-
- assert_activate %w[b-2 a-1], a1, "b"
- end
-
- ##
- # [A] depends on
- # [B] >= 1.0 (satisfied by 1.1) depends on
- # [Z]
- # [C] >= 1.0 depends on
- # [B] = 1.0
- #
- # and should backtrack to resolve using b-1.0, pruning Z from the
- # resolve.
-
- def test_self_activate_raggi_the_edgecase_generator
- a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '>= 1.0'
- util_spec 'b', '1.0'
- util_spec 'b', '1.1', 'z' => '>= 1.0'
- c, _ = util_spec 'c', '1.0', 'b' => '= 1.0'
-
- assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
- end
-
- def test_self_activate_conflict
- util_spec 'b', '1.0'
- util_spec 'b', '2.0'
-
- gem "b", "= 1.0"
-
- assert_raises Gem::LoadError do
- gem "b", "= 2.0"
- end
- end
-
- ##
- # [A] depends on
- # [C] = 1.0 depends on
- # [B] = 2.0
- # [B] ~> 1.0 (satisfied by 1.0)
-
- def test_self_activate_checks_dependencies
- a, _ = util_spec 'a', '1.0'
- a.add_dependency 'c', '= 1.0'
- a.add_dependency 'b', '~> 1.0'
-
- util_spec 'b', '1.0'
- util_spec 'b', '2.0'
- c, _ = util_spec 'c', '1.0', 'b' => '= 2.0'
-
- e = assert_raises Gem::LoadError do
- assert_activate nil, a, c, "b"
- end
-
- expected = "can't satisfy 'b (~> 1.0)', already activated 'b-2.0'"
- assert_equal expected, e.message
- end
-
- ##
- # [A] depends on
- # [B] ~> 1.0 (satisfied by 1.0)
- # [C] = 1.0 depends on
- # [B] = 2.0
-
- def test_self_activate_divergent
- a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0'
- util_spec 'b', '1.0'
- util_spec 'b', '2.0'
- c, _ = util_spec 'c', '1.0', 'b' => '= 2.0'
-
- e = assert_raises Gem::LoadError do
- assert_activate nil, a, c, "b"
- end
-
- assert_match(/Unable to activate c-1.0,/, e.message)
- assert_match(/because b-1.0 conflicts with b .= 2.0/, e.message)
- end
-
- ##
- # DOC
-
- def test_self_activate_platform_alternate
- @x1_m = util_spec 'x', '1' do |s|
- s.platform = Gem::Platform.new %w[cpu my_platform 1]
- end
-
- @x1_o = util_spec 'x', '1' do |s|
- s.platform = Gem::Platform.new %w[cpu other_platform 1]
- end
-
- @w1 = util_spec 'w', '1', 'x' => nil
-
- util_set_arch 'cpu-my_platform1'
-
- assert_activate %w[x-1-cpu-my_platform-1 w-1], @w1, @x1_m
- end
-
- ##
- # DOC
-
- def test_self_activate_platform_bump
- @y1 = util_spec 'y', '1'
-
- @y1_1_p = util_spec 'y', '1.1' do |s|
- s.platform = Gem::Platform.new %w[cpu my_platform 1]
- end
-
- @z1 = util_spec 'z', '1', 'y' => nil
-
- assert_activate %w[y-1 z-1], @z1, @y1
- end
-
- ##
- # [C] depends on
- # [A] = 1.a
- # [B] = 1.0 depends on
- # [A] >= 0 (satisfied by 1.a)
-
- def test_self_activate_prerelease
- @c1_pre = util_spec 'c', '1.a', "a" => "1.a", "b" => "1"
- @a1_pre = util_spec 'a', '1.a'
- @b1 = util_spec 'b', '1' do |s|
- s.add_dependency 'a'
- s.add_development_dependency 'aa'
- end
-
- assert_activate %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1
- end
-
- ##
- # DOC
-
- def test_self_activate_old_required
- e1, = util_spec 'e', '1', 'd' => '= 1'
- @d1 = util_spec 'd', '1'
- @d2 = util_spec 'd', '2'
-
- assert_activate %w[d-1 e-1], e1, "d"
- end
-
def test_self_bin_path_no_exec_name
e = assert_raises ArgumentError do
Gem.bin_path 'a'
@@ -790,9 +350,7 @@ class TestGem < Gem::TestCase
spec
}
- # HACK should be Gem.refresh
- Gem.searcher = nil
- Gem::Specification.reset
expected = [
File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
@@ -806,6 +364,37 @@ class TestGem < Gem::TestCase
assert_equal cwd, $LOAD_PATH.shift
end
def test_self_latest_spec_for
a1 = quick_spec 'a', 1
a2 = quick_spec 'a', 2
@@ -1328,14 +917,20 @@ class TestGem < Gem::TestCase
Dir.chdir @tempdir do
FileUtils.mkdir_p 'lib'
File.open plugin_path, "w" do |fp|
- fp.puts "class TestGem; TEST_SPEC_PLUGIN_LOAD = :loaded; end"
end
- foo = quick_spec 'foo', '1' do |s|
s.files << plugin_path
end
- install_gem foo
end
Gem.searcher = nil
@@ -1345,7 +940,7 @@ class TestGem < Gem::TestCase
Gem.load_plugins
- assert_equal :loaded, TEST_SPEC_PLUGIN_LOAD
end
def test_load_env_plugins
@@ -1558,6 +1153,61 @@ class TestGem < Gem::TestCase
assert_equal '["a-1", "b-1", "c-1"]', out.strip
end
def with_plugin(path)
test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}",
@@project_dir)
@@ -1634,4 +1284,3 @@ class TestGem < Gem::TestCase
File.join Gem.dir, "cache"
end
end
-
@@ -58,7 +58,7 @@ class TestGemCommandManager < Gem::TestCase
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
- @command_manager.run 'interrupt'
end
assert_equal '', ui.output
assert_equal "ERROR: Interrupted\n", ui.error
@@ -75,7 +75,7 @@ class TestGemCommandManager < Gem::TestCase
@command_manager.register_command :crash
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
- @command_manager.run 'crash'
end
assert_equal '', ui.output
err = ui.error.split("\n").first
@@ -89,7 +89,7 @@ class TestGemCommandManager < Gem::TestCase
def test_process_args_bad_arg
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
- @command_manager.process_args("--bad-arg")
end
end
@@ -107,7 +107,7 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("install")
assert_equal %w[ri], check_options[:document].sort
assert_equal false, check_options[:force]
assert_equal :both, check_options[:domain]
@@ -118,8 +118,10 @@ class TestGemCommandManager < Gem::TestCase
#check settings
check_options = nil
- @command_manager.process_args(
- "install --force --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ")
assert_equal %w[rdoc ri], check_options[:document].sort
assert_equal true, check_options[:force]
assert_equal :local, check_options[:domain]
@@ -130,17 +132,17 @@ class TestGemCommandManager < Gem::TestCase
#check remote domain
check_options = nil
- @command_manager.process_args("install --remote")
assert_equal :remote, check_options[:domain]
#check both domain
check_options = nil
- @command_manager.process_args("install --both")
assert_equal :both, check_options[:domain]
#check both domain
check_options = nil
- @command_manager.process_args("install --both")
assert_equal :both, check_options[:domain]
end
end
@@ -155,12 +157,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("uninstall")
assert_equal Gem::Requirement.default, check_options[:version]
#check settings
check_options = nil
- @command_manager.process_args("uninstall foobar --version 3.0")
assert_equal "foobar", check_options[:args].first
assert_equal Gem::Requirement.new('3.0'), check_options[:version]
end
@@ -175,12 +177,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("check")
assert_equal true, check_options[:alien]
#check settings
check_options = nil
- @command_manager.process_args("check foobar --alien")
assert_equal true, check_options[:alien]
end
@@ -194,12 +196,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("build")
#NOTE: Currently no defaults
#check settings
check_options = nil
- @command_manager.process_args("build foobar.rb")
assert_equal 'foobar.rb', check_options[:args].first
end
@@ -213,26 +215,26 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("query")
assert_equal(//, check_options[:name])
assert_equal :local, check_options[:domain]
assert_equal false, check_options[:details]
#check settings
check_options = nil
- @command_manager.process_args("query --name foobar --local --details")
assert_equal(/foobar/i, check_options[:name])
assert_equal :local, check_options[:domain]
assert_equal true, check_options[:details]
#remote domain
check_options = nil
- @command_manager.process_args("query --remote")
assert_equal :remote, check_options[:domain]
#both (local/remote) domains
check_options = nil
- @command_manager.process_args("query --both")
assert_equal :both, check_options[:domain]
end
@@ -246,12 +248,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("update")
assert_includes check_options[:document], 'rdoc'
#check settings
check_options = nil
- @command_manager.process_args("update --force --rdoc --install-dir .")
assert_includes check_options[:document], 'ri'
assert_equal true, check_options[:force]
assert_equal Dir.pwd, check_options[:install_dir]
@@ -2,8 +2,8 @@ require 'rubygems/test_case'
require 'rubygems/commands/cert_command'
require 'rubygems/fix_openssl_warnings' if RUBY_VERSION < "1.9"
-unless defined? OpenSSL then
- warn "`gem cert` tests are being skipped, module OpenSSL not found"
end
class TestGemCommandsCertCommand < Gem::TestCase
@@ -98,14 +98,22 @@ Added '/CN=alternate/DC=example'
end
def test_execute_build
@cmd.handle_options %W[--build [email protected]]
- use_ui @ui do
@cmd.execute
end
- output = @ui.output.split "\n"
assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}",
output.shift
assert_equal "Private Key: #{File.join @tempdir, 'gem-private_key.pem'}",
@@ -115,12 +123,43 @@ Added '/CN=alternate/DC=example'
output.shift
assert_empty output
- assert_empty @ui.error
assert_path_exists File.join(@tempdir, 'gem-private_key.pem')
assert_path_exists File.join(@tempdir, 'gem-public_cert.pem')
end
def test_execute_build_key
@cmd.handle_options %W[
@@ -135,21 +174,32 @@ Added '/CN=alternate/DC=example'
assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}",
output.shift
- assert_equal "Private Key: #{File.join @tempdir, 'gem-private_key.pem'}",
- output.shift
-
- assert_equal "Don't forget to move the key file to somewhere private!",
- output.shift
assert_empty output
assert_empty @ui.error
assert_path_exists File.join(@tempdir, 'gem-public_cert.pem')
- private_key_file = File.join @tempdir, 'gem-private_key.pem'
- assert_path_exists private_key_file
- assert_equal PRIVATE_KEY.to_pem, File.read(private_key_file)
end
def test_execute_certificate
@@ -203,6 +253,17 @@ Added '/CN=alternate/DC=example'
assert_equal PRIVATE_KEY.to_pem, @cmd.options[:key].to_pem
end
def test_execute_remove
@trust_dir.trust_cert PUBLIC_CERT
@@ -307,6 +368,35 @@ Removed '/CN=alternate/DC=example'
assert_equal mask, File.stat(path).mode unless win_platform?
end
def test_execute_sign_default
FileUtils.mkdir_p File.join Gem.user_home, '.gem'
@@ -339,6 +429,38 @@ Removed '/CN=alternate/DC=example'
assert_equal mask, File.stat(path).mode unless win_platform?
end
def test_execute_sign_no_cert
FileUtils.mkdir_p File.join Gem.user_home, '.gem'
@@ -509,6 +631,24 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
assert_equal [ALTERNATE_CERT_FILE, CHILD_CERT_FILE], @cmd.options[:sign]
end
def test_handle_options_sign_nonexistent
nonexistent = File.join @tempdir, 'nonexistent'
e = assert_raises OptionParser::InvalidArgument do
@@ -525,5 +665,5 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
e.message
end
-end if defined? OpenSSL
@@ -15,6 +15,21 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
install_gem @a_2
end
def test_execute
@cmd.options[:args] = %w[a]
@@ -91,6 +91,34 @@ class TestGemCommandsContentsCommand < Gem::TestCase
assert_equal "", @ui.error
end
def test_execute_multiple
@cmd.options[:args] = %w[foo bar]
@@ -140,10 +168,10 @@ lib/foo.rb
@cmd.execute
end
- expected = %W[
- #{Gem::ConfigMap[:bindir]}/default_command
- #{Gem::ConfigMap[:rubylibdir]}/default/gem.rb
- #{Gem::ConfigMap[:archdir]}/default_gem.so
].sort.join "\n"
assert_equal expected, @ui.output.chomp
@@ -11,6 +11,7 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
def test_execute
orig_sources = Gem.sources.dup
Gem.sources.replace %w[http://gems.example.com]
Gem.configuration['gemcutter_key'] = 'blah'
@@ -36,10 +37,17 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase
assert_match %r|"gemcutter_key" => "\*\*\*\*"|, @ui.output
assert_match %r|:verbose => |, @ui.output
assert_match %r|REMOTE SOURCES:|, @ui.output
- assert_equal '', @ui.error
ensure
Gem.sources.replace orig_sources
end
def test_execute_gemdir
@@ -34,6 +34,32 @@ class TestGemCommandsFetchCommand < Gem::TestCase
'gem repository directories must not be created'
end
def test_execute_prerelease
util_setup_fake_fetcher true
util_clear_gems
@@ -53,8 +79,8 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- assert_path_exists(File.join(@tempdir, @a2_pre.file_name),
- "#{@a2_pre.full_name} not fetched")
end
def test_execute_specific_prerelease
@@ -18,7 +18,7 @@ class TestGemCommandsHelpCommand < Gem::TestCase
def test_gem_help_bad
util_gem 'bad' do |out, err|
assert_equal('', out)
- assert_match(/Unknown command bad. Try gem help commands\n/, err)
end
end
@@ -36,9 +36,12 @@ class TestGemCommandsHelpCommand < Gem::TestCase
mgr.command_names.each do |cmd|
assert_match(/\s+#{cmd}\s+\S+/, out)
end
- assert_equal '', err
- refute_match 'No command found for ', out
end
end
@@ -6,6 +6,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase
def setup
super
@cmd = Gem::Commands::InstallCommand.new
@cmd.options[:document] = []
@@ -168,8 +169,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase
# This is needed because we need to exercise the cache path
# within SpecFetcher
- path = File.join Gem.user_home, '.gem', 'specs', "not-there.nothing%80",
- "latest_specs.4.8"
FileUtils.mkdir_p File.dirname(path)
@@ -633,67 +633,6 @@ ERROR: Possible alternatives: non_existent_with_hint
assert_equal x, e
end
- def test_execute_installs_dependencies
- r, r_gem = util_gem 'r', '1', 'q' => '= 1'
- q, q_gem = util_gem 'q', '1'
-
- util_setup_fake_fetcher
- util_setup_spec_fetcher r, q
-
- Gem::Specification.reset
-
- @fetcher.data["#{@gem_repo}gems/#{q.file_name}"] = read_binary(q_gem)
- @fetcher.data["#{@gem_repo}gems/#{r.file_name}"] = read_binary(r_gem)
-
- @cmd.options[:args] = ["r"]
-
- e = nil
- use_ui @ui do
- e = assert_raises Gem::SystemExitException do
- capture_io do
- @cmd.execute
- end
- end
- end
-
- out = @ui.output.split "\n"
- assert_equal "2 gems installed", out.shift
- assert out.empty?, out.inspect
-
- assert_equal %w[q-1 r-1], @cmd.installed_specs.map { |spec| spec.full_name }
-
- assert_equal 0, e.exit_code
- end
-
- def test_execute_satisfy_deps_of_local_from_sources
- r, r_gem = util_gem 'r', '1', 'q' => '= 1'
- q, q_gem = util_gem 'q', '1'
-
- util_setup_fake_fetcher
- util_setup_spec_fetcher r, q
-
- Gem::Specification.reset
-
- @fetcher.data["#{@gem_repo}gems/#{q.file_name}"] = read_binary(q_gem)
-
- @cmd.options[:args] = [r_gem]
-
- use_ui @ui do
- e = assert_raises Gem::SystemExitException do
- capture_io do
- @cmd.execute
- end
- end
- assert_equal 0, e.exit_code
- end
-
- assert_equal %w[q-1 r-1], @cmd.installed_specs.map { |spec| spec.full_name }
-
- out = @ui.output.split "\n"
- assert_equal "2 gems installed", out.shift
- assert out.empty?, out.inspect
- end
-
def test_execute_uses_from_a_gemdeps
util_setup_fake_fetcher
util_setup_spec_fetcher
@@ -951,4 +890,3 @@ ERROR: Possible alternatives: non_existent_with_hint
end
-
@@ -6,6 +6,7 @@ class TestGemCommandsOwnerCommand < Gem::TestCase
def setup
super
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
Gem.configuration.rubygems_api_key = "ed244fbf2b1a52e012da8616c512fa47f9aa5250"
@@ -34,6 +35,36 @@ EOF
assert_match %r{- [email protected]}, @ui.output
end
def test_show_owners_denied
response = "You don't have permission to push to this gem"
@fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 403, 'Forbidden']
@@ -87,6 +118,24 @@ EOF
assert_match response, @ui.output
end
def test_add_owners_key
response = "Owner added successfully."
@fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
@@ -80,6 +80,36 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_empty out, out.inspect
end
def test_execute_no_extension
a = quick_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end
@@ -194,7 +194,7 @@ beta-gems.example.com is not a URI
assert_equal expected, @ui.output
assert_equal '', @ui.error
- dir = File.join Gem.user_home, '.gem', 'specs'
refute File.exist?(dir), 'cache dir removed'
end
@@ -16,6 +16,20 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
@executable = File.join(@gemhome, 'bin', 'executable')
end
def test_execute_dependency_order
c = quick_gem 'c' do |spec|
spec.add_dependency 'a'
@@ -43,6 +57,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
def test_execute_removes_executable
ui = Gem::MockGemUi.new
util_setup_gem ui
build_rake_in do
@@ -175,5 +190,32 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
assert Gem::Specification.find_all_by_name('x').length == 0
end
end
@@ -11,6 +11,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def setup
super
@cmd = Gem::Commands::UpdateCommand.new
@@ -253,7 +254,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
out = @ui.output.split "\n"
assert_equal "Updating installed gems", out.shift
assert_equal "Updating #{@a2.name}", out.shift
- assert_equal "Gems updated: #{@c2.name} #{@b2.name} #{@a2.name}",
out.shift
assert_empty out
@@ -201,6 +201,10 @@ ERROR: Your gem push credentials file located at:
has file permissions of 0644 but 0600 is required.
You should reset your credentials at:
\thttps://rubygems.org/profile/edit
@@ -428,6 +432,14 @@ if you believe they were disclosed to a third party.
assert_equal('/home/me/certs', @cfg.ssl_ca_cert)
end
def util_config_file(args = @cfg_args)
@cfg = Gem::ConfigFile.new args
end
@@ -6,6 +6,7 @@ class TestGemDependencyInstaller < Gem::TestCase
def setup
super
@gems_dir = File.join @tempdir, 'gems'
@cache_dir = File.join @gemhome, 'cache'
@@ -172,7 +173,8 @@ class TestGemDependencyInstaller < Gem::TestCase
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
- FileUtils.mv e1_gem, @tempdir
inst = nil
Dir.chdir @tempdir do
@@ -180,40 +182,15 @@ class TestGemDependencyInstaller < Gem::TestCase
inst.install 'b'
end
- Dir.chdir @tempdir do
- inst = Gem::DependencyInstaller.new
- inst.install 'e'
- end
-
- assert_equal %w[e-1 a-1], inst.installed_gems.map { |s| s.full_name }
- end
-
- def test_install_ignore_satified_deps
- util_setup_gems
-
- _, e1_gem = util_gem 'e', '1' do |s|
- s.add_dependency 'b'
- end
-
- util_clear_gems
-
- FileUtils.mv @a1_gem, @tempdir
- FileUtils.mv @b1_gem, @tempdir
- FileUtils.mv e1_gem, @tempdir
-
- Dir.chdir @tempdir do
- i = Gem::DependencyInstaller.new :ignore_dependencies => true
- i.install 'b'
- end
-
- inst = nil
Dir.chdir @tempdir do
- inst = Gem::DependencyInstaller.new :minimal_deps => true
inst.install 'e'
end
- assert_equal %w[e-1], inst.installed_gems.map { |s| s.full_name }
end
def test_install_cache_dir
@@ -246,15 +223,18 @@ class TestGemDependencyInstaller < Gem::TestCase
Gem::Specification.reset
FileUtils.mv @a1_gem, @tempdir
- FileUtils.mv a2_gem, @tempdir # not in index
FileUtils.mv @b1_gem, @tempdir
inst = nil
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
- inst.install 'a', Gem::Requirement.create("= 2")
end
FileUtils.rm File.join(@tempdir, a2.file_name)
Dir.chdir @tempdir do
@@ -282,19 +262,18 @@ class TestGemDependencyInstaller < Gem::TestCase
Gem::Specification.reset
FileUtils.mv @a1_gem, @tempdir
- FileUtils.mv a2_gem, @tempdir # not in index
FileUtils.mv @b1_gem, @tempdir
- FileUtils.mv a3_gem, @tempdir
-
- inst = nil
Dir.chdir @tempdir do
- inst = Gem::DependencyInstaller.new
- inst.install 'a', Gem::Requirement.create("= 2")
end
FileUtils.rm File.join(@tempdir, a2.file_name)
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
inst.install 'b'
@@ -488,6 +467,42 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
end
def test_install_env_shebang
util_setup_gems
@@ -627,12 +642,12 @@ class TestGemDependencyInstaller < Gem::TestCase
inst = nil
Dir.chdir @tempdir do
- e = assert_raises Gem::DependencyError do
inst = Gem::DependencyInstaller.new :domain => :local
inst.install 'b'
end
- expected = "Unable to resolve dependencies: b requires a (>= 0)"
assert_equal expected, e.message
end
@@ -910,12 +925,13 @@ class TestGemDependencyInstaller < Gem::TestCase
gems = set.sorted
assert_equal 2, gems.length
- local = gems.first
assert_equal 'a-1', local.spec.full_name, 'local spec'
assert_equal File.join(@tempdir, @a1.file_name),
local.source.download(local.spec), 'local path'
- remote = gems.last
assert_equal 'a-1', remote.spec.full_name, 'remote spec'
assert_equal Gem::Source.new(@gem_repo), remote.source, 'remote path'
@@ -15,7 +15,9 @@ class TestGemDependencyResolver < Gem::TestCase
exp = expected.sort_by { |s| s.full_name }
act = actual.map { |a| a.spec }.sort_by { |s| s.full_name }
- assert_equal exp, act
end
def test_no_overlap_specificly
@@ -64,6 +66,32 @@ class TestGemDependencyResolver < Gem::TestCase
assert_set [a2], res.resolve
end
def test_only_returns_spec_once
a1 = util_spec "a", "1", "c" => "= 1"
b1 = util_spec "b", "1", "c" => "= 1"
@@ -177,7 +205,8 @@ class TestGemDependencyResolver < Gem::TestCase
r.resolve
end
- assert_equal "unable to find any gem matching dependency 'a (>= 0)'", e.message
assert_equal "a (>= 0)", e.dependency.to_s
end
@@ -215,7 +244,7 @@ class TestGemDependencyResolver < Gem::TestCase
r.resolve
end
- assert_equal "detected 1 conflict with dependency 'c (>= 2)'", e.message
assert_equal "c (>= 2)", e.dependency.to_s
@@ -324,4 +353,18 @@ class TestGemDependencyResolver < Gem::TestCase
assert_set [b1, c1, d2], r.resolve
end
end
@@ -1,5 +1,6 @@
require 'rubygems/test_case'
require 'rubygems/ext'
class TestGemExtBuilder < Gem::TestCase
@@ -13,6 +14,10 @@ class TestGemExtBuilder < Gem::TestCase
FileUtils.mkdir_p @dest_path
@orig_DESTDIR = ENV['DESTDIR']
end
def teardown
@@ -56,5 +61,93 @@ install:
end
end
end
@@ -120,8 +120,13 @@ checking for main\(\) in .*?nonexistent/m, error.message)
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
@@ -7,6 +7,7 @@ class TestGemGemRunner < Gem::TestCase
super
@orig_args = Gem::Command.build_args
end
def teardown
@@ -41,23 +42,26 @@ class TestGemGemRunner < Gem::TestCase
assert_equal %w[--commands], Gem::Command.extra_args
end
- def test_build_args_are_handled
- Gem.clear_paths
-
- cls = Class.new(Gem::Command) do
- def execute
- end
- end
- test_obj = cls.new :ba_test
- cmds = Gem::CommandManager.new
- cmds.register_command :ba_test, test_obj
- runner = Gem::GemRunner.new :command_manager => cmds
- runner.run(%W[ba_test -- --build_arg1 --build_arg2])
- assert_equal %w[--build_arg1 --build_arg2], test_obj.options[:build_args]
end
end
@@ -101,7 +101,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
def test_sign_in_with_host
api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
- util_sign_in [api_key, 200, 'OK'], 'http://example.com', :param
assert_match "Enter your http://example.com credentials.",
@sign_in_ui.output
@@ -112,6 +112,20 @@ class TestGemGemcutterUtilities < Gem::TestCase
assert_equal api_key, credentials[:rubygems_api_key]
end
def test_sign_in_with_host_ENV
api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
util_sign_in [api_key, 200, 'OK'], 'http://example.com'
@@ -163,14 +177,14 @@ class TestGemGemcutterUtilities < Gem::TestCase
assert_match %r{Access Denied.}, @sign_in_ui.output
end
- def util_sign_in response, host = nil, style = :ENV
skip 'Always uses $stdin on windows' if Gem.win_platform?
password = 'secret'
if host
- ENV['RUBYGEMS_HOST'] = host if style == :ENV
else
host = Gem.host
end
@@ -182,8 +196,8 @@ class TestGemGemcutterUtilities < Gem::TestCase
@sign_in_ui = Gem::MockGemUi.new "#{email}\n#{password}\n"
use_ui @sign_in_ui do
- if style == :param then
- @cmd.sign_in host
else
@cmd.sign_in
end
@@ -209,4 +223,3 @@ class TestGemGemcutterUtilities < Gem::TestCase
end
end
-
@@ -22,12 +22,13 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
--rdoc
--ri
-E
- -P HighSecurity
-f
-i /install_to
-w
]
assert @cmd.handles?(args)
end
@@ -100,6 +101,8 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
end
def test_security_policy
@cmd.handle_options %w[-P HighSecurity]
assert_equal Gem::Security::HighSecurity, @cmd.options[:security_policy]
@@ -4,6 +4,7 @@ class TestGemInstaller < Gem::InstallerTestCase
def setup
super
if __name__ =~ /^test_install(_|$)/ then
FileUtils.rm_r @spec.gem_dir
@@ -14,6 +15,8 @@ class TestGemInstaller < Gem::InstallerTestCase
end
def teardown
super
Gem.configuration = @config
@@ -52,95 +55,6 @@ load Gem.bin_path('a', 'executable', version)
assert_equal expected, wrapper
end
- def test_build_extensions_none
- use_ui @ui do
- @installer.build_extensions
- end
-
- assert_equal '', @ui.output
- assert_equal '', @ui.error
-
- refute File.exist?('gem_make.out')
- end
-
- def test_build_extensions_extconf_bad
- @installer.spec = @spec
- @spec.extensions << 'extconf.rb'
-
- e = assert_raises Gem::Installer::ExtensionBuildError do
- use_ui @ui do
- @installer.build_extensions
- end
- end
-
- assert_match(/\AERROR: Failed to build gem native extension.$/, e.message)
-
- assert_equal "Building native extensions. This could take a while...\n",
- @ui.output
- assert_equal '', @ui.error
-
- gem_make_out = File.join @gemhome, 'gems', @spec.full_name, '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
- @installer.spec = @spec
- FileUtils.mkdir_p @spec.gem_dir
- gem_make_out = File.join @spec.gem_dir, 'gem_make.out'
- @spec.extensions << nil
-
- e = assert_raises Gem::Installer::ExtensionBuildError do
- use_ui @ui do
- @installer.build_extensions
- end
- end
-
- assert_match(/^\s*No builder for extension ''$/, e.message)
-
- assert_equal "Building native extensions. This could take a while...\n",
- @ui.output
- assert_equal '', @ui.error
-
- assert_equal "No builder for extension ''\n", File.read(gem_make_out)
- ensure
- FileUtils.rm_f gem_make_out
- end
-
- def test_build_extensions_with_build_args
- args = ["--aa", "--bb"]
- @installer.build_args = args
- @installer.spec = @spec
- @spec.extensions << 'extconf.rb'
-
- File.open File.join(@spec.gem_dir, "extconf.rb"), "w" do |f|
- f.write <<-'RUBY'
- puts "IN EXTCONF"
- extconf_args = File.join File.dirname(__FILE__), 'extconf_args'
- File.open extconf_args, 'w' do |f|
- f.puts ARGV.inspect
- end
-
- File.open 'Makefile', 'w' do |f|
- f.puts "default:\n\techo built"
- f.puts "install:\n\techo installed"
- end
- RUBY
- end
-
- use_ui @ui do
- @installer.build_extensions
- end
-
- path = File.join @spec.gem_dir, "extconf_args"
-
- assert_equal args.inspect, File.read(path).strip
- assert File.directory? File.join(@spec.gem_dir, 'lib')
- end
-
def test_check_executable_overwrite
@installer.generate_bin
@@ -159,7 +73,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.generate_bin
installed_exec = File.join util_inst_bindir, 'executable'
- assert File.exist? installed_exec
wrapper = File.read installed_exec
assert_match %r|generated by RubyGems|, wrapper
@@ -222,7 +136,7 @@ gem 'other', version
@installer.generate_bin # should not raise
installed_exec = File.join util_inst_bindir, 'foo-executable-bar'
- assert File.exist? installed_exec
wrapper = File.read installed_exec
assert_match %r|generated by RubyGems|, wrapper
@@ -251,7 +165,7 @@ gem 'other', version
@installer.generate_bin
installed_exec = File.join util_inst_bindir, 'executable'
- assert File.exist? installed_exec
wrapper = File.read installed_exec
assert_match %r|generated by RubyGems|, wrapper
@@ -264,7 +178,7 @@ gem 'other', version
@installer.generate_bin
installed_exec = File.join util_inst_bindir, 'executable'
- assert File.exist? installed_exec
wrapper = File.read installed_exec
assert_match %r|generated by RubyGems|, wrapper
@@ -300,6 +214,8 @@ gem 'other', version
end
def test_ensure_loadable_spec_security_policy
_, a_gem = util_gem 'a', 2 do |s|
s.add_dependency 'garbage ~> 5'
end
@@ -336,7 +252,7 @@ gem 'other', version
assert_equal true, File.directory?(util_inst_bindir)
installed_exec = File.join(util_inst_bindir, 'executable')
- assert_equal true, File.exist?(installed_exec)
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
wrapper = File.read installed_exec
@@ -371,7 +287,7 @@ gem 'other', version
@installer.generate_bin
assert File.directory? util_inst_bindir
installed_exec = File.join util_inst_bindir, 'executable'
- assert File.exist? installed_exec
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
wrapper = File.read installed_exec
@@ -388,7 +304,7 @@ gem 'other', version
@installer.generate_bin
assert_equal true, File.directory?(util_inst_bindir)
installed_exec = File.join util_inst_bindir, 'foo-executable-bar'
- assert_equal true, File.exist?(installed_exec)
ensure
Gem::Installer.exec_format = nil
end
@@ -402,7 +318,7 @@ gem 'other', version
@installer.generate_bin
assert_equal true, File.directory?(util_inst_bindir)
installed_exec = File.join util_inst_bindir, 'executable'
- assert_equal true, File.exist?(installed_exec)
ensure
Gem::Installer.exec_format = nil
end
@@ -424,7 +340,7 @@ gem 'other', version
@installer.generate_bin
installed_exec = File.join("#{@gemhome}2", "bin", 'executable')
- assert File.exist? installed_exec
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
wrapper = File.read installed_exec
@@ -437,7 +353,7 @@ gem 'other', version
@installer.wrappers = true
@installer.generate_bin
- refute File.exist?(util_inst_bindir), 'bin dir was created when not needed'
end
def test_generate_bin_script_no_perms
@@ -473,7 +389,7 @@ gem 'other', version
@installer.generate_bin
installed_exec = File.join @gemhome, 'bin', 'executable'
- assert_equal true, File.exist?(installed_exec)
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
wrapper = File.read installed_exec
@@ -498,7 +414,7 @@ gem 'other', version
@installer.generate_bin
assert_equal true, File.directory?(util_inst_bindir)
- assert_equal true, File.exist?(installed_exec)
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
assert_match %r|generated by RubyGems|, File.read(installed_exec)
@@ -528,7 +444,7 @@ gem 'other', version
@installer.wrappers = false
@installer.generate_bin
- refute File.exist?(util_inst_bindir)
end
def test_generate_bin_symlink_no_perms
@@ -627,7 +543,7 @@ gem 'other', version
@installer.generate_bin
installed_exec = File.join util_inst_bindir, 'executable'
- assert File.exist? installed_exec
@spec = Gem::Specification.new do |s|
s.files = ['lib/code.rb']
@@ -664,7 +580,7 @@ gem 'other', version
assert_equal true, File.directory?(util_inst_bindir)
installed_exec = File.join(util_inst_bindir, 'executable')
- assert_equal true, File.exist?(installed_exec)
assert_match(/Unable to use symlinks on Windows, installing wrapper/i,
@ui.error)
@@ -731,19 +647,19 @@ gem 'other', version
rakefile = File.join gemdir, 'ext', 'a', 'Rakefile'
Gem.pre_install do |installer|
- refute File.exist?(cache_file), 'cache file must not exist yet'
true
end
Gem.post_build do |installer|
- assert File.exist?(gemdir), 'gem install dir must exist'
- assert File.exist?(rakefile), 'gem executable must exist'
- refute File.exist?(stub_exe), 'gem executable must not exist'
true
end
Gem.post_install do |installer|
- assert File.exist?(cache_file), 'cache file must exist'
end
@newspec = nil
@@ -754,23 +670,23 @@ gem 'other', version
end
assert_equal @spec, @newspec
- assert File.exist? gemdir
- assert File.exist?(stub_exe), 'gem executable must exist'
exe = File.join gemdir, 'bin', 'executable'
- assert File.exist? exe
exe_mode = File.stat(exe).mode & 0111
assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform?
- assert File.exist?(File.join(gemdir, 'lib', 'code.rb'))
- assert File.exist? rakefile
spec_file = File.join(@gemhome, 'specifications', @spec.spec_name)
assert_equal spec_file, @newspec.loaded_from
- assert File.exist?(spec_file)
assert_same @installer, @post_build_hook_arg
assert_same @installer, @post_install_hook_arg
@@ -879,7 +795,7 @@ gem 'other', version
end
gemdir = File.join(@gemhome, 'gems', @spec.full_name)
- assert File.exist?(File.join(gemdir, 'lib', 'code.rb'))
util_setup_gem
# Morph spec to have lib/other.rb instead of code.rb and recreate
@@ -898,9 +814,9 @@ gem 'other', version
end
end
- assert File.exist?(File.join(gemdir, 'lib', 'other.rb'))
- refute(File.exist?(File.join(gemdir, 'lib', 'code.rb')),
- "code.rb from prior install of same gem shouldn't remain here")
end
def test_install_force
@@ -910,7 +826,7 @@ gem 'other', version
end
gem_dir = File.join(@gemhome, 'gems', 'old_ruby_required-1')
- assert File.exist?(gem_dir)
end
def test_install_missing_dirs
@@ -926,8 +842,8 @@ gem 'other', version
File.directory? File.join(Gem.dir, 'docs')
File.directory? File.join(Gem.dir, 'specifications')
- assert File.exist?(File.join(@gemhome, 'cache', @spec.file_name))
- assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name))
end
def test_install_post_build_false
@@ -948,10 +864,10 @@ gem 'other', version
end
spec_file = File.join @gemhome, 'specifications', @spec.spec_name
- refute File.exist? spec_file
gem_dir = File.join @gemhome, 'gems', @spec.full_name
- refute File.exist? gem_dir
end
def test_install_post_build_nil
@@ -966,10 +882,10 @@ gem 'other', version
end
spec_file = File.join @gemhome, 'specifications', @spec.spec_name
- assert File.exist? spec_file
gem_dir = File.join @gemhome, 'gems', @spec.full_name
- assert File.exist? gem_dir
end
def test_install_pre_install_false
@@ -990,7 +906,7 @@ gem 'other', version
end
spec_file = File.join @gemhome, 'specifications', @spec.spec_name
- refute File.exist? spec_file
end
def test_install_pre_install_nil
@@ -1005,7 +921,7 @@ gem 'other', version
end
spec_file = File.join @gemhome, 'specifications', @spec.spec_name
- assert File.exist? spec_file
end
def test_install_with_message
@@ -1021,6 +937,31 @@ gem 'other', version
assert_match %r|I am a shiny gem!|, @ui.output
end
def test_install_extension_and_script
@spec.extensions << "extconf.rb"
write_file File.join(@tempdir, "extconf.rb") do |io|
@@ -1047,16 +988,16 @@ gem 'other', version
RUBY
end
- assert !File.exist?(File.join(@spec.gem_dir, rb))
- assert !File.exist?(File.join(@spec.gem_dir, rb2))
use_ui @ui do
path = Gem::Package.build @spec
@installer = Gem::Installer.new path
@installer.install
end
- assert File.exist?(File.join(@spec.gem_dir, rb))
- assert File.exist?(File.join(@spec.gem_dir, rb2))
end
def test_install_extension_flat
@@ -1085,14 +1026,14 @@ gem 'other', version
}
so = File.join(@spec.gem_dir, "#{@spec.name}.#{RbConfig::CONFIG["DLEXT"]}")
- assert !File.exist?(so)
use_ui @ui do
path = Gem::Package.build @spec
@installer = Gem::Installer.new path
@installer.install
end
- assert File.exist?(so)
rescue
puts '-' * 78
puts File.read File.join(@gemhome, 'gems', 'a-2', 'Makefile')
@@ -1337,11 +1278,11 @@ gem 'other', version
@installer.unpack dest
- assert File.exist?(File.join(dest, 'lib', 'code.rb'))
- assert File.exist?(File.join(dest, 'bin', 'executable'))
end
- def test_write_build_args
refute_path_exists @spec.build_info_file
@installer.build_args = %w[
@@ -1357,7 +1298,7 @@ gem 'other', version
assert_equal expected, File.read(@spec.build_info_file)
end
- def test_write_build_args_empty
refute_path_exists @spec.build_info_file
@installer.write_build_info_file
@@ -1397,20 +1338,20 @@ gem 'other', version
def test_write_spec
FileUtils.rm @spec.spec_file
- refute File.exist?(@spec.spec_file)
@installer.spec = @spec
@installer.gem_home = @gemhome
@installer.write_spec
- assert File.exist?(@spec.spec_file)
assert_equal @spec, eval(File.read(@spec.spec_file))
end
def test_write_spec_writes_cached_spec
FileUtils.rm @spec.spec_file
- refute File.exist?(@spec.spec_file)
@spec.files = %w[a.rb b.rb c.rb]
@@ -1429,6 +1370,30 @@ gem 'other', version
assert_match %r!/gemhome/gems/a-2$!, @installer.dir
end
def old_ruby_required
spec = quick_spec 'old_ruby_required', '1' do |s|
s.required_ruby_version = '= 1.4.6'
@@ -2,6 +2,21 @@ require 'rubygems/test_case'
require 'rubygems/name_tuple'
class TestGemNameTuple < Gem::TestCase
def test_platform_normalization
n = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby"
assert_equal "ruby", n.platform
@@ -12,4 +27,11 @@ class TestGemNameTuple < Gem::TestCase
n = Gem::NameTuple.new "a", Gem::Version.new(0), ""
assert_equal "ruby", n.platform
end
end
@@ -87,16 +87,19 @@ class TestGemPackage < Gem::Package::TarTestCase
metadata_sha512 = Digest::SHA512.hexdigest s.string
expected = {
- 'SHA1' => {
- 'metadata.gz' => metadata_sha1,
- 'data.tar.gz' => Digest::SHA1.hexdigest(tar),
- },
'SHA512' => {
'metadata.gz' => metadata_sha512,
'data.tar.gz' => Digest::SHA512.hexdigest(tar),
}
}
assert_equal expected, YAML.load(checksums)
end
@@ -160,12 +163,57 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_build_auto_signed
FileUtils.mkdir_p File.join(Gem.user_home, '.gem')
private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem'
Gem::Security.write PRIVATE_KEY, private_key_path
public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem'
Gem::Security.write PUBLIC_CERT, public_cert_path
spec = Gem::Specification.new 'build', '1'
@@ -214,6 +262,8 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_build_signed
spec = Gem::Specification.new 'build', '1'
spec.summary = 'build'
spec.authors = 'build'
@@ -248,6 +298,43 @@ class TestGemPackage < Gem::Package::TarTestCase
assert_equal %w[lib/code.rb], reader.contents
end
def test_contents
package = Gem::Package.new @gem
@@ -309,6 +396,19 @@ class TestGemPackage < Gem::Package::TarTestCase
"#{@destination} is not allowed", e.message)
end
def test_install_location
package = Gem::Package.new @gem
@@ -444,7 +544,7 @@ class TestGemPackage < Gem::Package::TarTestCase
io.write metadata_gz
end
- digest = OpenSSL::Digest::SHA1.new
digest << metadata_gz
checksums = {
@@ -476,7 +576,8 @@ class TestGemPackage < Gem::Package::TarTestCase
def test_verify_corrupt
Tempfile.open 'corrupt' do |io|
data = Gem.gzip 'a' * 10
- io.write tar_file_header('metadata.gz', "\000x", 0644, data.length)
io.write data
io.rewind
@@ -515,6 +616,8 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_verify_security_policy
package = Gem::Package.new @gem
package.security_policy = Gem::Security::HighSecurity
@@ -530,6 +633,8 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_verify_security_policy_low_security
@spec.cert_chain = [PUBLIC_CERT.to_pem]
@spec.signing_key = PRIVATE_KEY
@@ -548,6 +653,8 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_verify_security_policy_checksum_missing
@spec.cert_chain = [PUBLIC_CERT.to_pem]
@spec.signing_key = PRIVATE_KEY
@@ -603,6 +710,21 @@ class TestGemPackage < Gem::Package::TarTestCase
e.message
end
def test_spec
package = Gem::Package.new @gem
@@ -21,6 +21,8 @@ class TestGemPackageOld < Gem::TestCase
end
def test_contents_security_policy
@package.security_policy = Gem::Security::AlmostNoSecurity
assert_raises Gem::Security::Exception do
@@ -40,6 +42,8 @@ class TestGemPackageOld < Gem::TestCase
end
def test_extract_files_security_policy
@package.security_policy = Gem::Security::AlmostNoSecurity
assert_raises Gem::Security::Exception do
@@ -52,6 +56,8 @@ class TestGemPackageOld < Gem::TestCase
end
def test_spec_security_policy
@package.security_policy = Gem::Security::AlmostNoSecurity
assert_raises Gem::Security::Exception do
@@ -60,6 +66,8 @@ class TestGemPackageOld < Gem::TestCase
end
def test_verify
assert @package.verify
@package.security_policy = Gem::Security::NoSecurity
@@ -4,8 +4,8 @@ require 'rubygems/package'
class TestGemPackageTarReader < Gem::Package::TarTestCase
def test_each_entry
- tar = tar_dir_header "foo", "bar", 0
- tar << tar_file_header("bar", "baz", 0, 0)
io = TempIO.new tar
@@ -25,8 +25,9 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase
def test_rewind
content = ('a'..'z').to_a.join(" ")
- str = tar_file_header("lib/foo", "", 010644, content.size) + content +
- "\0" * (512 - content.size)
str << "\0" * 1024
Gem::Package::TarReader.new(TempIO.new(str)) do |tar_reader|
@@ -43,8 +44,8 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase
end
def test_seek
- tar = tar_dir_header "foo", "bar", 0
- tar << tar_file_header("bar", "baz", 0, 0)
io = TempIO.new tar
@@ -60,8 +61,8 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase
end
def test_seek_missing
- tar = tar_dir_header "foo", "bar", 0
- tar << tar_file_header("bar", "baz", 0, 0)
io = TempIO.new tar
@@ -9,7 +9,7 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase
@contents = ('a'..'z').to_a.join * 100
@tar = ''
- @tar << tar_file_header("lib/foo", "", 0, @contents.size)
@tar << @contents
@tar << "\0" * (512 - (@tar.size % 512))
@@ -1,5 +1,6 @@
require 'rubygems/package/tar_test_case'
require 'rubygems/package/tar_writer'
class TestGemPackageTarWriter < Gem::Package::TarTestCase
@@ -18,112 +19,130 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
end
def test_add_file
- @tar_writer.add_file 'x', 0644 do |f| f.write 'a' * 10 end
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
@io.string[0, 512])
assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
assert_equal 1024, @io.pos
end
def test_add_file_digest
- digest_algorithms = OpenSSL::Digest::SHA1, OpenSSL::Digest::SHA512
- digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io|
- io.write 'a' * 10
- end
- assert_equal '3495ff69d34671d1e15b33a63c1379fdedd3a32a',
- digests['SHA1'].hexdigest
- assert_equal '4714870aff6c97ca09d135834fdb58a6389a50c1' \
- '1fef8ec4afef466fb60a23ac6b7a9c92658f14df' \
- '4993d6b40a4e4d8424196afc347e97640d68de61' \
- 'e1cf14b0',
- digests['SHA512'].hexdigest
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
@io.string[0, 512])
assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
assert_equal 1024, @io.pos
end
def test_add_file_digest_multiple
- digest_algorithms = [OpenSSL::Digest::SHA1, OpenSSL::Digest::SHA512]
- digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io|
- io.write 'a' * 10
- end
- assert_equal '3495ff69d34671d1e15b33a63c1379fdedd3a32a',
- digests['SHA1'].hexdigest
- assert_equal '4714870aff6c97ca09d135834fdb58a6389a50c1' \
- '1fef8ec4afef466fb60a23ac6b7a9c92658f14df' \
- '4993d6b40a4e4d8424196afc347e97640d68de61' \
- 'e1cf14b0',
- digests['SHA512'].hexdigest
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
- @io.string[0, 512])
assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
assert_equal 1024, @io.pos
end
def test_add_file_signer
signer = Gem::Security::Signer.new PRIVATE_KEY, [PUBLIC_CERT]
- @tar_writer.add_file_signed 'x', 0644, signer do |io|
- io.write 'a' * 10
- end
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
- @io.string[0, 512])
- assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
- digest = signer.digest_algorithm.new
- digest.update 'a' * 10
- signature = signer.sign digest.digest
- assert_headers_equal(tar_file_header('x.sig', '', 0444, signature.length),
- @io.string[1024, 512])
- assert_equal "#{signature}#{"\0" * (512 - signature.length)}",
- @io.string[1536, 512]
- assert_equal 2048, @io.pos
end
def test_add_file_signer_empty
signer = Gem::Security::Signer.new nil, nil
- @tar_writer.add_file_signed 'x', 0644, signer do |io|
- io.write 'a' * 10
- end
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
@io.string[0, 512])
assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
- digest = signer.digest_algorithm.new
- digest.update 'a' * 10
-
assert_equal 1024, @io.pos
end
def test_add_file_simple
- @tar_writer.add_file_simple 'x', 0644, 10 do |io| io.write "a" * 10 end
- assert_headers_equal(tar_file_header('x', '', 0644, 10),
@io.string[0, 512])
assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
assert_equal 1024, @io.pos
end
def test_add_file_simple_padding
- @tar_writer.add_file_simple 'x', 0, 100
- assert_headers_equal tar_file_header('x', '', 0, 100),
@io.string[0, 512]
assert_equal "\0" * 512, @io.string[512, 512]
end
@@ -182,11 +201,14 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
end
def test_mkdir
- @tar_writer.mkdir 'foo', 0644
- assert_headers_equal tar_dir_header('foo', '', 0644),
- @io.string[0, 512]
- assert_equal 512, @io.pos
end
def test_split_name
@@ -64,4 +64,21 @@ class TestGemPathSupport < Gem::TestCase
def util_path
ENV["GEM_PATH"].split(File::PATH_SEPARATOR)
end
end
@@ -186,6 +186,24 @@ class TestGemPlatform < Gem::TestCase
assert((x86_darwin8 === Gem::Platform.local), 'universal =~ x86')
end
def test_equals3_version
util_set_arch 'i686-darwin8'
@@ -1,7 +1,13 @@
require 'rubygems/test_case'
-require 'ostruct'
require 'webrick'
-require 'webrick/https'
require 'rubygems/remote_fetcher'
require 'rubygems/package'
require 'minitest/mock'
@@ -128,19 +134,7 @@ gems:
refute_nil fetcher
assert_kind_of Gem::RemoteFetcher, fetcher
- assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy_uri).to_s
- end
-
- def test_self_fetcher_with_proxy_URI
- proxy_uri = URI.parse 'http://proxy.example.com'
- Gem.configuration[:http_proxy] = proxy_uri
- Gem::RemoteFetcher.fetcher = nil
-
- fetcher = Gem::RemoteFetcher.fetcher
- refute_nil fetcher
-
- assert_kind_of Gem::RemoteFetcher, fetcher
- assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy_uri)
end
def test_fetch_size_bad_uri
@@ -155,7 +149,7 @@ gems:
def test_fetch_size_socket_error
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.connection_for(uri)
raise SocketError, "tarded"
end
@@ -414,70 +408,6 @@ gems:
assert_equal @a2.file_name, File.basename(gem)
end
- def test_explicit_proxy
- use_ui @ui do
- fetcher = Gem::RemoteFetcher.new @proxy_uri
- assert_equal PROXY_DATA.size, fetcher.fetch_size(@server_uri)
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
- end
- end
-
- def test_explicit_proxy_with_user_auth
- use_ui @ui do
- uri = URI.parse @proxy_uri
- uri.user, uri.password = 'foo', 'bar'
- fetcher = Gem::RemoteFetcher.new uri.to_s
- proxy = fetcher.instance_variable_get("@proxy_uri")
- assert_equal 'foo', proxy.user
- assert_equal 'bar', proxy.password
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
- end
-
- use_ui @ui do
- uri = URI.parse @proxy_uri
- uri.user, uri.password = 'domain%5Cuser', 'bar'
- fetcher = Gem::RemoteFetcher.new uri.to_s
- proxy = fetcher.instance_variable_get("@proxy_uri")
- assert_equal 'domain\user', fetcher.unescape(proxy.user)
- assert_equal 'bar', proxy.password
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
- end
-
- use_ui @ui do
- uri = URI.parse @proxy_uri
- uri.user, uri.password = 'user', 'my%20pass'
- fetcher = Gem::RemoteFetcher.new uri.to_s
- proxy = fetcher.instance_variable_get("@proxy_uri")
- assert_equal 'user', proxy.user
- assert_equal 'my pass', fetcher.unescape(proxy.password)
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
- end
- end
-
- def test_explicit_proxy_with_user_auth_in_env
- use_ui @ui do
- ENV['http_proxy'] = @proxy_uri
- ENV['http_proxy_user'] = 'foo'
- ENV['http_proxy_pass'] = 'bar'
- fetcher = Gem::RemoteFetcher.new nil
- proxy = fetcher.instance_variable_get("@proxy_uri")
- assert_equal 'foo', proxy.user
- assert_equal 'bar', proxy.password
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
- end
-
- use_ui @ui do
- ENV['http_proxy'] = @proxy_uri
- ENV['http_proxy_user'] = 'foo\user'
- ENV['http_proxy_pass'] = 'my bar'
- fetcher = Gem::RemoteFetcher.new nil
- proxy = fetcher.instance_variable_get("@proxy_uri")
- assert_equal 'foo\user', fetcher.unescape(proxy.user)
- assert_equal 'my bar', fetcher.unescape(proxy.password)
- assert_data_from_proxy fetcher.fetch_path(@server_uri)
- end
- end
-
def test_fetch_path_gzip
fetcher = Gem::RemoteFetcher.new nil
@@ -560,22 +490,6 @@ gems:
assert_equal nil, fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0))
end
- def test_get_proxy_from_env_auto_normalizes
- fetcher = Gem::RemoteFetcher.new(nil)
- ENV['HTTP_PROXY'] = 'fakeurl:12345'
-
- assert_equal('http://fakeurl:12345', fetcher.get_proxy_from_env.to_s)
- end
-
- def test_get_proxy_from_env_empty
- ENV['HTTP_PROXY'] = ''
- ENV.delete 'http_proxy'
-
- fetcher = Gem::RemoteFetcher.new nil
-
- assert_equal nil, fetcher.send(:get_proxy_from_env)
- end
-
def test_implicit_no_proxy
use_ui @ui do
ENV['http_proxy'] = 'http://fakeurl:12345'
@@ -611,9 +525,7 @@ gems:
fetcher = Gem::RemoteFetcher.new nil
url = 'http://gems.example.com/redirect'
- conn = Object.new
- def conn.started?() true end
- def conn.request(req)
url = 'http://gems.example.com/redirect'
unless defined? @requested then
@requested = true
@@ -627,9 +539,6 @@ gems:
end
end
- conn = { "#{Thread.current.object_id}:gems.example.com:80" => conn }
- fetcher.instance_variable_set :@connections, conn
-
data = fetcher.fetch_http URI.parse(url)
assert_equal 'real_path', data
@@ -639,18 +548,13 @@ gems:
fetcher = Gem::RemoteFetcher.new nil
url = 'http://gems.example.com/redirect'
- conn = Object.new
- def conn.started?() true end
- def conn.request(req)
url = 'http://gems.example.com/redirect'
res = Net::HTTPMovedPermanently.new nil, 301, nil
res.add_field 'Location', url
res
end
- conn = { "#{Thread.current.object_id}:gems.example.com:80" => conn }
- fetcher.instance_variable_set :@connections, conn
-
e = assert_raises Gem::RemoteFetcher::FetchError do
fetcher.fetch_http URI.parse(url)
end
@@ -658,14 +562,6 @@ gems:
assert_equal "too many redirects (#{url})", e.message
end
- def test_normalize_uri
- assert_equal 'FILE://example/', @fetcher.normalize_uri('FILE://example/')
- assert_equal 'FTP://example/', @fetcher.normalize_uri('FTP://example/')
- assert_equal 'HTTP://example/', @fetcher.normalize_uri('HTTP://example/')
- assert_equal 'HTTPS://example/', @fetcher.normalize_uri('HTTPS://example/')
- assert_equal 'http://example/', @fetcher.normalize_uri('example/')
- end
-
def test_observe_no_proxy_env_single_host
use_ui @ui do
ENV["http_proxy"] = @proxy_uri
@@ -684,115 +580,15 @@ gems:
end
end
- def test_request
- uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
- util_stub_connection_for :body => :junk, :code => 200
-
- response = @fetcher.request uri, Net::HTTP::Get
-
- assert_equal 200, response.code
- assert_equal :junk, response.body
- end
-
- def test_request_head
- uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
- util_stub_connection_for :body => '', :code => 200
- response = @fetcher.request uri, Net::HTTP::Head
-
- assert_equal 200, response.code
- assert_equal '', response.body
- end
-
- def test_request_unmodified
- uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
- conn = util_stub_connection_for :body => '', :code => 304
-
- t = Time.now
- response = @fetcher.request uri, Net::HTTP::Head, t
-
- assert_equal 304, response.code
- assert_equal '', response.body
-
- assert_equal t.rfc2822, conn.payload['if-modified-since']
- end
-
- def test_user_agent
- ua = @fetcher.user_agent
-
- assert_match %r%^RubyGems/\S+ \S+ Ruby/\S+ \(.*?\)%, ua
- assert_match %r%RubyGems/#{Regexp.escape Gem::VERSION}%, ua
- assert_match %r% #{Regexp.escape Gem::Platform.local.to_s} %, ua
- assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}%, ua
- assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE} %, ua
- end
-
- def test_user_agent_engine
- util_save_version
-
- Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
- Object.send :const_set, :RUBY_ENGINE, 'vroom'
-
- ua = @fetcher.user_agent
-
- assert_match %r%\) vroom%, ua
- ensure
- util_restore_version
- end
-
- def test_user_agent_engine_ruby
- util_save_version
-
- Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
- Object.send :const_set, :RUBY_ENGINE, 'ruby'
-
- ua = @fetcher.user_agent
-
- assert_match %r%\)%, ua
- ensure
- util_restore_version
- end
-
- def test_user_agent_level
- util_save_version
-
- Object.send :remove_const, :RUBY_LEVEL
- Object.send :const_set, :RUBY_LEVEL, 5
-
- ua = @fetcher.user_agent
-
- assert_match %r% level 5\)%, ua
- ensure
- util_restore_version
- end
-
- def test_user_agent_revision
- util_save_version
-
- Object.send :remove_const, :RUBY_LEVEL
- Object.send :const_set, :RUBY_LEVEL, -1
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
- Object.send :const_set, :RUBY_REVISION, 6
-
- ua = @fetcher.user_agent
-
- assert_match %r% revision 6\)%, ua
- assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}dev%, ua
- ensure
- util_restore_version
- end
-
- def test_user_agent_revision_missing
- util_save_version
-
- Object.send :remove_const, :RUBY_LEVEL
- Object.send :const_set, :RUBY_LEVEL, -1
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
-
- ua = @fetcher.user_agent
- assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE}\)%, ua
- ensure
- util_restore_version
end
def test_yaml_error_on_size
@@ -811,6 +607,42 @@ gems:
end
end
def test_do_not_allow_insecure_ssl_connection_by_default
ssl_server = self.class.start_ssl_server
with_configured_fetcher do |fetcher|
@@ -850,18 +682,6 @@ gems:
Gem.configuration = nil
end
- def util_stub_connection_for hash
- def @fetcher.connection= conn
- @conn = conn
- end
-
- def @fetcher.connection_for uri
- @conn
- end
-
- @fetcher.connection = Conn.new OpenStruct.new(hash)
- end
-
def assert_error(exception_class=Exception)
got_exception = false
@@ -882,20 +702,6 @@ gems:
assert_match(/0\.4\.2/, data, "Data is not from proxy")
end
- class Conn
- attr_accessor :payload
-
- def initialize(response)
- @response = response
- self.payload = nil
- end
-
- def request(req)
- self.payload = req
- @response
- end
- end
-
class NilLog < WEBrick::Log
def log(level, data) #Do nothing
end
@@ -913,9 +719,11 @@ gems:
end
DIR = File.expand_path(File.dirname(__FILE__))
- DH_PARAM = OpenSSL::PKey::DH.new(128)
def start_ssl_server(config = {})
null_logger = NilLog.new
server = WEBrick::HTTPServer.new({
:Port => 0,
@@ -934,7 +742,7 @@ gems:
server.mount_proc("/insecure_redirect") { |req, res|
res.set_redirect(WEBrick::HTTPStatus::MovedPermanently, req.query['to'])
}
- server.ssl_context.tmp_dh_callback = proc { DH_PARAM }
t = Thread.new do
begin
server.start
@@ -953,8 +761,6 @@ gems:
server
end
-
-
private
def start_server(port, data)
@@ -1015,24 +821,5 @@ gems:
assert_equal "/home/skillet", @fetcher.correct_for_windows_path(path)
end
- def util_save_version
- @orig_RUBY_ENGINE = RUBY_ENGINE if defined? RUBY_ENGINE
- @orig_RUBY_LEVEL = RUBY_LEVEL
- @orig_RUBY_REVISION = RUBY_REVISION if defined? RUBY_REVISION
- end
-
- def util_restore_version
- Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
- Object.send :const_set, :RUBY_ENGINE, @orig_RUBY_ENGINE if
- defined?(@orig_RUBY_ENGINE)
-
- Object.send :remove_const, :RUBY_LEVEL
- Object.send :const_set, :RUBY_LEVEL, @orig_RUBY_LEVEL
-
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
- Object.send :const_set, :RUBY_REVISION, @orig_RUBY_REVISION if
- defined?(@orig_RUBY_REVISION)
- end
-
end
@@ -2,6 +2,10 @@ require 'rubygems/test_case'
require 'rubygems/security'
require 'rubygems/fix_openssl_warnings' if RUBY_VERSION < "1.9"
class TestGemSecurity < Gem::TestCase
CHILD_KEY = load_key 'child'
@@ -95,7 +99,7 @@ class TestGemSecurity < Gem::TestCase
end
def test_class_create_key
- key = @SEC.create_key 256
assert_kind_of OpenSSL::PKey::RSA, key
end
@@ -246,5 +250,57 @@ class TestGemSecurity < Gem::TestCase
assert_equal expected, trust_dir.dir
end
-end
@@ -2,6 +2,10 @@
require 'rubygems/test_case'
class TestGemSecurityPolicy < Gem::TestCase
ALTERNATE_KEY = load_key 'alternate'
@@ -11,6 +15,7 @@ class TestGemSecurityPolicy < Gem::TestCase
INVALIDCHILD_KEY = load_key 'invalidchild'
ALTERNATE_CERT = load_cert 'alternate'
CHILD_CERT = load_cert 'child'
EXPIRED_CERT = load_cert 'expired'
FUTURE_CERT = load_cert 'future'
@@ -285,6 +290,11 @@ class TestGemSecurityPolicy < Gem::TestCase
"(root of signing cert #{CHILD_CERT.subject})", e.message
end
def test_verify
Gem::Security.trust_dir.trust_cert PUBLIC_CERT
@@ -325,6 +335,33 @@ class TestGemSecurityPolicy < Gem::TestCase
assert_equal 'missing digest for 0', e.message
end
def test_verify_not_enough_signatures
Gem::Security.trust_dir.trust_cert PUBLIC_CERT
@@ -341,6 +378,21 @@ class TestGemSecurityPolicy < Gem::TestCase
assert_equal 'missing digest for 1', e.message
end
def test_verify_wrong_digest_type
Gem::Security.trust_dir.trust_cert PUBLIC_CERT
@@ -484,5 +536,5 @@ class TestGemSecurityPolicy < Gem::TestCase
return digests, signatures
end
-end
@@ -1,5 +1,9 @@
require 'rubygems/test_case'
class TestGemSecuritySigner < Gem::TestCase
ALTERNATE_KEY = load_key 'alternate'
@@ -72,6 +76,20 @@ class TestGemSecuritySigner < Gem::TestCase
assert_equal PRIVATE_KEY.to_s, signer.key.to_s
end
def test_load_cert_chain
Gem::Security.trust_dir.trust_cert PUBLIC_CERT
@@ -186,5 +204,5 @@ c7NM7KZZjj7G++SXjYTEI1PHSA7aFQ/i/+qSUvx+Pg==
end
end
-end
@@ -1,5 +1,9 @@
require 'rubygems/test_case'
class TestGemSecurityTrustDir < Gem::TestCase
CHILD_CERT = load_cert 'child'
@@ -90,5 +94,5 @@ class TestGemSecurityTrustDir < Gem::TestCase
assert_equal mask, File.stat(@dest_dir).mode unless win_platform?
end
-end
@@ -63,7 +63,7 @@ class TestGemSource < Gem::TestCase
def test_cache_dir_escapes_windows_paths
uri = URI.parse("file:///C:/WINDOWS/Temp/gem_repo")
- root = File.join Gem.user_home, '.gem', 'specs'
cache_dir = @source.cache_dir(uri).gsub(root, '')
assert cache_dir !~ /:/, "#{cache_dir} should not contain a :"
end
@@ -123,7 +123,7 @@ class TestGemSource < Gem::TestCase
expected = @released
assert_equal expected, @source.load_specs(:released)
- cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
assert File.exist?(cache_dir), "#{cache_dir} does not exist"
cache_file = File.join cache_dir, "specs.#{Gem.marshal_version}"
@@ -138,7 +138,7 @@ class TestGemSource < Gem::TestCase
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
' ' * Marshal.dump(@latest_specs).length
- cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
FileUtils.mkdir_p cache_dir
@@ -160,7 +160,7 @@ class TestGemSource < Gem::TestCase
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
util_gzip(Marshal.dump(@latest_specs))
- cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
FileUtils.mkdir_p cache_dir
@@ -184,5 +184,28 @@ class TestGemSource < Gem::TestCase
end
end
end
@@ -1,5 +1,5 @@
require 'rubygems/test_case'
-require 'rubygems/source_local'
require 'fileutils'
@@ -66,18 +66,41 @@ class TestGemSourceLocal < Gem::TestCase
assert_equal s, @a
end
def test_download
path = @sl.download @a
assert_equal File.expand_path(@a.file_name), path
end
- def test_compare
- uri = URI.parse "http://gems.example/foo"
- s = Gem::Source.new uri
- assert_equal(-1, (@sl <=> s))
- assert_equal 1, (s <=> @sl)
- assert_equal 0, (@sl <=> @sl)
end
end
@@ -1,5 +1,5 @@
require 'rubygems/test_case'
-require 'rubygems/source_specific_file'
class TestGemSourceSpecificFile < Gem::TestCase
def setup
@@ -30,4 +30,42 @@ class TestGemSourceSpecificFile < Gem::TestCase
def test_download
assert_equal @a_gem, @sf.download(@a)
end
end
@@ -168,7 +168,7 @@ class TestGemSpecFetcher < Gem::TestCase
specs, _ = @sf.available_specs(:latest)
assert_equal [@source], specs.keys
- assert_equal @latest_specs, specs[@source].sort
end
def test_available_specs_released
@@ -176,7 +176,7 @@ class TestGemSpecFetcher < Gem::TestCase
assert_equal [@source], specs.keys
- assert_equal @released, specs[@source].sort
end
def test_available_specs_complete
@@ -184,9 +184,9 @@ class TestGemSpecFetcher < Gem::TestCase
assert_equal [@source], specs.keys
- comp = @prerelease_specs + @released
- assert_equal comp.sort, specs[@source].sort
end
def test_available_specs_complete_handles_no_prerelease
@@ -197,12 +197,9 @@ class TestGemSpecFetcher < Gem::TestCase
assert_equal [@source], specs.keys
- comp = @released
-
- assert_equal comp.sort, specs[@source].sort
end
-
def test_available_specs_cache
specs, _ = @sf.available_specs(:latest)
@@ -230,7 +227,7 @@ class TestGemSpecFetcher < Gem::TestCase
def test_available_specs_prerelease
specs, _ = @sf.available_specs(:prerelease)
- assert_equal @prerelease_specs, specs[@source].sort
end
def test_available_specs_with_bad_source
@@ -38,10 +38,8 @@ Gem::Specification.new do |s|
end
EOF
- def setup
- super
-
- @a1 = quick_spec 'a', '1' do |s|
s.executable = 'exec'
s.extensions << 'ext/a/extconf.rb'
s.test_file = 'test/suite.rb'
@@ -56,6 +54,22 @@ end
s.mark_version
s.files = %w[lib/code.rb]
end
@a2 = quick_spec 'a', '2' do |s|
s.files = %w[lib/code.rb]
@@ -66,6 +80,379 @@ end
load 'rubygems/syck_hack.rb'
end
def test_self_attribute_names
expected_value = %w[
authors
@@ -449,6 +836,25 @@ dependencies: []
assert_equal %w[a], Gem::Specification.outdated
end
DATA_PATH = File.expand_path "../data", __FILE__
def test_handles_private_null_type
@@ -1022,19 +1428,60 @@ dependencies: []
assert_equal %w[lib], @a1.require_paths
end
def test_requirements
assert_equal ['A working computer'], @a1.requirements
end
def test_runtime_dependencies_legacy
# legacy gems don't have a type
- @a1.runtime_dependencies.each do |dep|
dep.instance_variable_set :@type, nil
end
expected = %w[rake jabber4r pqa]
- assert_equal expected, @a1.runtime_dependencies.map { |d| d.name }
end
def test_spaceship_name
@@ -1088,11 +1535,13 @@ dependencies: []
@a2.add_runtime_dependency 'b', '1'
@a2.dependencies.first.instance_variable_set :@type, nil
@a2.required_rubygems_version = Gem::Requirement.new '> 0'
ruby_code = @a2.to_ruby
expected = <<-SPEC
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "a"
@@ -1105,7 +1554,7 @@ Gem::Specification.new do |s|
s.email = "[email protected]"
s.files = ["lib/code.rb"]
s.homepage = "http://example.com"
- s.require_paths = ["lib"]
s.rubygems_version = "#{Gem::VERSION}"
s.summary = "this is a summary"
@@ -1140,6 +1589,7 @@ end
expected = <<-SPEC
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "a"
@@ -1179,14 +1629,17 @@ end
end
def test_to_ruby_fancy
- @a1.platform = Gem::Platform.local
- ruby_code = @a1.to_ruby
local = Gem::Platform.local
expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]"
expected = <<-SPEC
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "a"
@@ -1234,7 +1687,7 @@ end
same_spec = eval ruby_code
- assert_equal @a1, same_spec
end
def test_to_ruby_legacy
@@ -1886,6 +2339,7 @@ end
def test_metadata_specs
valid_ruby_spec = <<-EOF
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "m"
@@ -5,6 +5,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
def setup
super
build_rake_in do
use_ui ui do
@@ -375,6 +376,19 @@ class TestGemUninstaller < Gem::InstallerTestCase
assert_equal "Successfully uninstalled q-1.0", lines.shift
end
def test_uninstall_prompt_includes_dep_type
quick_gem 'r', '1' do |s|
@@ -122,6 +122,15 @@ class TestGemVersion < Gem::TestCase
assert_equal "5.2.4", v("5.2.4").to_s
end
# Asserts that +version+ is a prerelease.
def assert_prerelease version
@@ -161,6 +170,12 @@ class TestGemVersion < Gem::TestCase
assert second.eql?(first), "#{second} is eql? #{first}"
end
# Refute the assumption that +version+ is a prerelease.
def refute_prerelease version
@@ -80,7 +80,69 @@ class TestGemVersionOption < Gem::TestCase
@cmd.handle_options %w[--version >1]
- expected = { :version => Gem::Requirement.new('> 1'), :args => [] }
assert_equal expected, @cmd.options
end