summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-18 08:37:18 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-18 08:37:18 +0000
commitec6c07570237b209d47b7690a5b5a6774301242b ()
tree70902f2e19499bb3bd26f014aa12bb43b96e9b22
parent3367daf716bda6e73f3418dd601bd1713d557c07 (diff)
Merge upstream revision of rubygems/rubygems.
This commits includes tiny bugfix and new features listed here: * Add --re-sign flag to cert command by bronzdoc: https://.com/rubygems/rubygems/pull/2391 * Download gems with threads. by indirect: https://.com/rubygems/rubygems/pull/1898 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--lib/rubygems/commands/cert_command.rb34
-rw-r--r--lib/rubygems/config_file.rb12
-rw-r--r--lib/rubygems/installer.rb18
-rw-r--r--lib/rubygems/request_set.rb27
-rw-r--r--lib/rubygems/resolver/specification.rb14
-rw-r--r--lib/rubygems/security/signer.rb18
-rw-r--r--lib/rubygems/user_interaction.rb67
-rw-r--r--test/rubygems/test_gem_commands_cert_command.rb39
-rw-r--r--test/rubygems/test_gem_stream_ui.rb16
9 files changed, 165 insertions, 80 deletions
@@ -14,15 +14,16 @@ class Gem::Commands::CertCommand < Gem::Command
super 'cert', 'Manage RubyGems certificates and signing settings',
:add => [], :remove => [], :list => [], :build => [], :sign => []
- OptionParser.accept OpenSSL::X509::Certificate do |certificate|
begin
- OpenSSL::X509::Certificate.new File.read certificate
rescue Errno::ENOENT
- raise OptionParser::InvalidArgument, "#{certificate}: does not exist"
rescue OpenSSL::X509::CertificateError
raise OptionParser::InvalidArgument,
- "#{certificate}: invalid X509 certificate"
end
end
OptionParser.accept OpenSSL::PKey::RSA do |key_file|
@@ -42,7 +43,7 @@ class Gem::Commands::CertCommand < Gem::Command
end
add_option('-a', '--add CERT', OpenSSL::X509::Certificate,
- 'Add a trusted certificate.') do |cert, options|
options[:add] << cert
end
@@ -67,8 +68,9 @@ class Gem::Commands::CertCommand < Gem::Command
end
add_option('-C', '--certificate CERT', OpenSSL::X509::Certificate,
- 'Signing certificate for --sign') do |cert, options|
options[:issuer_cert] = cert
end
add_option('-K', '--private-key KEY', OpenSSL::PKey::RSA,
@@ -89,6 +91,11 @@ class Gem::Commands::CertCommand < Gem::Command
'Days before the certificate expires') do |days, options|
options[:expiration_length_days] = days.to_i
end
end
def add_certificate certificate # :nodoc:
@@ -114,6 +121,14 @@ class Gem::Commands::CertCommand < Gem::Command
build email
end
sign_certificates unless options[:sign].empty?
end
@@ -290,6 +305,13 @@ For further reading on signing gems see `ri Gem::Security`.
end
end
private
def valid_email? email
@@ -27,6 +27,7 @@ require 'rbconfig'
# +:backtrace+:: See #backtrace
# +:sources+:: Sets Gem::sources
# +:verbose+:: See #verbose
#
# gemrc files may exist in various locations and are read and merged in
# the following order:
@@ -43,6 +44,7 @@ class Gem::ConfigFile
DEFAULT_BULK_THRESHOLD = 1000
DEFAULT_VERBOSITY = true
DEFAULT_UPDATE_SOURCES = true
##
# For Ruby packagers to set configuration defaults. Set in
@@ -105,6 +107,11 @@ class Gem::ConfigFile
attr_accessor :verbose
##
# True if we want to update the SourceInfoCache every time, false otherwise
attr_accessor :update_sources
@@ -177,6 +184,7 @@ class Gem::ConfigFile
@bulk_threshold = DEFAULT_BULK_THRESHOLD
@verbose = DEFAULT_VERBOSITY
@update_sources = DEFAULT_UPDATE_SOURCES
operating_system_config = Marshal.load Marshal.dump(OPERATING_SYSTEM_DEFAULTS)
platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS)
@@ -200,6 +208,7 @@ class Gem::ConfigFile
@path = @hash[:gempath] if @hash.key? :gempath
@update_sources = @hash[:update_sources] if @hash.key? :update_sources
@verbose = @hash[:verbose] if @hash.key? :verbose
@disable_default_gem_server = @hash[:disable_default_gem_server] if @hash.key? :disable_default_gem_server
@sources = @hash[:sources] if @hash.key? :sources
@@ -415,6 +424,9 @@ if you believe they were disclosed to a third party.
yaml_hash[:update_sources] = @hash.fetch(:update_sources, DEFAULT_UPDATE_SOURCES)
yaml_hash[:verbose] = @hash.fetch(:verbose, DEFAULT_VERBOSITY)
yaml_hash[:ssl_verify_mode] =
@hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode
@@ -771,30 +771,26 @@ TEXT
# return the stub script text used to launch the true Ruby script
def windows_stub_script(bindir, bin_file_name)
- rb_config = RbConfig::CONFIG
- rb_topdir = RbConfig::TOPDIR || File.dirname(rb_config["bindir"])
- # get ruby executable file name from RbConfig
- ruby_exe = "#{rb_config['RUBY_INSTALL_NAME']}#{rb_config['EXEEXT']}"
-
- if File.exist?(File.join bindir, ruby_exe)
# stub & ruby.exe withing same folder. Portable
<<-TEXT
@ECHO OFF
@"%~dp0ruby.exe" "%~dpn0" %*
TEXT
- elsif bindir.downcase.start_with? rb_topdir.downcase
- # stub within ruby folder, but not standard bin. Portable
require 'pathname'
from = Pathname.new bindir
- to = Pathname.new "#{rb_topdir}/bin"
rel = to.relative_path_from from
<<-TEXT
@ECHO OFF
@"%~dp0#{rel}/ruby.exe" "%~dpn0" %*
TEXT
else
- # outside ruby folder, maybe -user-install or bundler. Portable, but ruby
- # is dependent on PATH
<<-TEXT
@ECHO OFF
@ruby.exe "%~dpn0" %*
@@ -152,7 +152,34 @@ class Gem::RequestSet
@prerelease = options[:prerelease]
requests = []
sorted_requests.each do |req|
if req.installed? then
req.spec.spec.build_extensions
@@ -84,11 +84,7 @@ class Gem::Resolver::Specification
def install options = {}
require 'rubygems/installer'
- destination = options[:install_dir] || Gem.dir
-
- Gem.ensure_gem_subdirectories destination
-
- gem = source.download spec, destination
installer = Gem::Installer.at gem, options
@@ -97,6 +93,14 @@ class Gem::Resolver::Specification
@spec = installer.install
end
##
# Returns true if this specification is installable on this platform.
@@ -30,6 +30,24 @@ class Gem::Security::Signer
attr_reader :digest_name # :nodoc:
##
# Creates a new signer with an RSA +key+ or path to a key, and a certificate
# +chain+ containing X509 certificates, encoding certificates or paths to
# certificates.
@@ -512,11 +512,10 @@ class Gem::StreamUI
# Return a download reporter object chosen from the current verbosity
def download_reporter(*args)
- case Gem.configuration.verbose
- when nil, false
SilentDownloadReporter.new(@outs, *args)
else
- VerboseDownloadReporter.new(@outs, *args)
end
end
@@ -553,9 +552,11 @@ class Gem::StreamUI
end
##
- # A progress reporter that prints out messages about the current progress.
- class VerboseDownloadReporter
##
# The current file name being displayed
@@ -563,71 +564,43 @@ class Gem::StreamUI
attr_reader :file_name
##
- # The total bytes in the file
-
- attr_reader :total_bytes
-
- ##
- # The current progress (0 to 100)
-
- attr_reader :progress
-
- ##
- # Creates a new verbose download reporter that will display on
# +out_stream+. The other arguments are ignored.
def initialize(out_stream, *args)
@out = out_stream
- @progress = 0
end
##
- # Tells the download reporter that the +file_name+ is being fetched and
- # contains +total_bytes+.
- def fetch(file_name, total_bytes)
- @file_name = file_name
- @total_bytes = total_bytes.to_i
- @units = @total_bytes.zero? ? 'B' : '%'
-
- update_display(false)
end
##
- # Updates the verbose download reporter for the given number of +bytes+.
def update(bytes)
- new_progress = if @units == 'B' then
- bytes
- else
- ((bytes.to_f * 100) / total_bytes.to_f).ceil
- end
-
- return if new_progress == @progress
-
- @progress = new_progress
- update_display
end
##
# Indicates the download is complete.
def done
- @progress = 100 if @units == '%'
- update_display(true, true)
end
private
-
- def update_display(show_progress = true, new_line = false) # :nodoc:
- return unless @out.tty?
-
- if show_progress then
- @out.print "\rFetching: %s (%3d%s)" % [@file_name, @progress, @units]
- else
- @out.print "Fetching: %s" % @file_name
end
- @out.puts if new_line
end
end
end
@@ -9,14 +9,16 @@ end
class TestGemCommandsCertCommand < Gem::TestCase
ALTERNATE_CERT = load_cert 'alternate'
ALTERNATE_KEY_FILE = key_path 'alternate'
PRIVATE_KEY_FILE = key_path 'private'
PUBLIC_KEY_FILE = key_path 'public'
- ALTERNATE_CERT_FILE = cert_path 'alternate'
- CHILD_CERT_FILE = cert_path 'child'
- PUBLIC_CERT_FILE = cert_path 'public'
def setup
super
@@ -582,6 +584,37 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
assert_equal expected, @ui.error
end
def test_handle_options
@cmd.handle_options %W[
--add #{PUBLIC_CERT_FILE}
@@ -156,14 +156,14 @@ class TestGemStreamUI < Gem::TestCase
def test_download_reporter_anything
@cfg.verbose = 0
reporter = @sui.download_reporter
- assert_kind_of Gem::StreamUI::VerboseDownloadReporter, reporter
end
- def test_verbose_download_reporter
@cfg.verbose = true
reporter = @sui.download_reporter
reporter.fetch 'a.gem', 1024
- assert_equal "Fetching: a.gem", @out.string
end
def test_verbose_download_reporter_progress
@@ -171,7 +171,7 @@ class TestGemStreamUI < Gem::TestCase
reporter = @sui.download_reporter
reporter.fetch 'a.gem', 1024
reporter.update 512
- assert_equal "Fetching: a.gem\rFetching: a.gem ( 50%)", @out.string
end
def test_verbose_download_reporter_progress_once
@@ -180,7 +180,7 @@ class TestGemStreamUI < Gem::TestCase
reporter.fetch 'a.gem', 1024
reporter.update 510
reporter.update 512
- assert_equal "Fetching: a.gem\rFetching: a.gem ( 50%)", @out.string
end
def test_verbose_download_reporter_progress_complete
@@ -189,7 +189,7 @@ class TestGemStreamUI < Gem::TestCase
reporter.fetch 'a.gem', 1024
reporter.update 510
reporter.done
- assert_equal "Fetching: a.gem\rFetching: a.gem ( 50%)\rFetching: a.gem (100%)\n", @out.string
end
def test_verbose_download_reporter_progress_nil_length
@@ -198,7 +198,7 @@ class TestGemStreamUI < Gem::TestCase
reporter.fetch 'a.gem', nil
reporter.update 1024
reporter.done
- assert_equal "Fetching: a.gem\rFetching: a.gem (1024B)\rFetching: a.gem (1024B)\n", @out.string
end
def test_verbose_download_reporter_progress_zero_length
@@ -207,7 +207,7 @@ class TestGemStreamUI < Gem::TestCase
reporter.fetch 'a.gem', 0
reporter.update 1024
reporter.done
- assert_equal "Fetching: a.gem\rFetching: a.gem (1024B)\rFetching: a.gem (1024B)\n", @out.string
end
def test_verbose_download_reporter_no_tty