From 600a715c9bde99fe2e9a669465d78833445273e8 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Sat, 1 Feb 2020 11:14:04 +0900 Subject: Merge the current master branch of rubygems/rubygems. Just started to develop RubyGems 3.2.0. --- lib/rubygems/basic_specification.rb | 8 +- lib/rubygems/command.rb | 6 +- lib/rubygems/command_manager.rb | 1 + lib/rubygems/commands/help_command.rb | 2 +- lib/rubygems/commands/info_command.rb | 13 +- lib/rubygems/commands/install_command.rb | 6 +- lib/rubygems/commands/list_command.rb | 15 +- lib/rubygems/commands/pristine_command.rb | 12 +- lib/rubygems/commands/search_command.rb | 14 +- lib/rubygems/commands/setup_command.rb | 19 +- lib/rubygems/commands/sources_command.rb | 6 +- lib/rubygems/commands/update_command.rb | 37 ++- lib/rubygems/deprecate.rb | 18 +- lib/rubygems/doctor.rb | 2 + lib/rubygems/exceptions.rb | 13 +- lib/rubygems/gem_runner.rb | 10 +- lib/rubygems/installer.rb | 38 ++- lib/rubygems/installer_test_case.rb | 4 +- lib/rubygems/installer_uninstaller_utils.rb | 24 ++ lib/rubygems/package.rb | 3 +- lib/rubygems/query_utils.rb | 362 +++++++++++++++++++++++++ lib/rubygems/remote_fetcher.rb | 14 - lib/rubygems/request_set/gem_dependency_api.rb | 2 +- lib/rubygems/resolver/api_set.rb | 2 +- lib/rubygems/resolver/api_specification.rb | 2 +- lib/rubygems/security.rb | 8 +- lib/rubygems/security/signer.rb | 2 +- lib/rubygems/server.rb | 2 +- lib/rubygems/specification.rb | 33 ++- lib/rubygems/specification_policy.rb | 3 +- lib/rubygems/test_case.rb | 58 ++-- lib/rubygems/uninstaller.rb | 36 ++- lib/rubygems/user_interaction.rb | 8 - lib/rubygems/version.rb | 2 +- 34 files changed, 629 insertions(+), 156 deletions(-) create mode 100644 lib/rubygems/installer_uninstaller_utils.rb create mode 100644 lib/rubygems/query_utils.rb (limited to 'lib/rubygems') diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index c6d63ac473..a4bd11cae3 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -274,12 +274,18 @@ class Gem::BasicSpecification # Return all files in this gem that match for +glob+. def matches_for_glob(glob) # TODO: rename? - # TODO: do we need these?? Kill it glob = File.join(self.lib_dirs_glob, glob) Dir[glob].map { |f| f.tap(&Gem::UNTAINT) } # FIX our tests are broken, run w/ SAFE=1 end + ## + # Returns the list of plugins in this spec. + + def plugins + matches_for_glob("rubygems#{Gem.plugin_suffix_pattern}") + end + ## # Returns a string usable in Dir.glob to match all requirable paths # for this spec. diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index c1e5e13c5a..d9a0700b95 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -466,6 +466,10 @@ class Gem::Command result end + def deprecated? + false + end + private def option_is_deprecated?(option) @@ -646,7 +650,7 @@ basic help message containing pointers to more information. http://localhost:8808/ with info about installed gems Further information: - http://guides.rubygems.org + https://guides.rubygems.org HELP # :startdoc: diff --git a/lib/rubygems/command_manager.rb b/lib/rubygems/command_manager.rb index 8ad723be55..03b859e501 100644 --- a/lib/rubygems/command_manager.rb +++ b/lib/rubygems/command_manager.rb @@ -176,6 +176,7 @@ class Gem::CommandManager cmd_name = args.shift.downcase cmd = find_command cmd_name cmd.invoke_with_build_args args, build_args + cmd.deprecation_warning if cmd.deprecated? end end diff --git a/lib/rubygems/commands/help_command.rb b/lib/rubygems/commands/help_command.rb index 9f14e22f90..259e8b5622 100644 --- a/lib/rubygems/commands/help_command.rb +++ b/lib/rubygems/commands/help_command.rb @@ -38,7 +38,7 @@ Some examples of 'gem' usage. * Create a gem: - See http://guides.rubygems.org/make-your-own-gem/ + See https://guides.rubygems.org/make-your-own-gem/ * See information about RubyGems: diff --git a/lib/rubygems/commands/info_command.rb b/lib/rubygems/commands/info_command.rb index 6a737b178b..a64843405e 100644 --- a/lib/rubygems/commands/info_command.rb +++ b/lib/rubygems/commands/info_command.rb @@ -1,14 +1,19 @@ # frozen_string_literal: true require 'rubygems/command' -require 'rubygems/commands/query_command' +require 'rubygems/query_utils' -class Gem::Commands::InfoCommand < Gem::Commands::QueryCommand +class Gem::Commands::InfoCommand < Gem::Command + + include Gem::QueryUtils def initialize - super "info", "Show information for the given gem" + super "info", "Show information for the given gem", + :name => //, :domain => :local, :details => false, :versions => true, + :installed => nil, :version => Gem::Requirement.default + + add_query_options - remove_option('--name-matches') remove_option('-d') defaults[:details] = true diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb index 753ff33eb5..6f9a8d2a08 100644 --- a/lib/rubygems/commands/install_command.rb +++ b/lib/rubygems/commands/install_command.rb @@ -218,7 +218,7 @@ You can use `i` command instead of `install`. gem_version ||= options[:version] domain = options[:domain] domain = :local unless options[:suggest_alternate] - supress_suggestions = (domain == :local) + suppress_suggestions = (domain == :local) begin install_gem gem_name, gem_version @@ -226,11 +226,11 @@ You can use `i` command instead of `install`. alert_error "Error installing #{gem_name}:\n\t#{e.message}" exit_code |= 1 rescue Gem::GemNotFoundException => e - show_lookup_failure e.name, e.version, e.errors, supress_suggestions + show_lookup_failure e.name, e.version, e.errors, suppress_suggestions exit_code |= 2 rescue Gem::UnsatisfiableDependencyError => e - show_lookup_failure e.name, e.version, e.errors, supress_suggestions, + show_lookup_failure e.name, e.version, e.errors, suppress_suggestions, "'#{gem_name}' (#{gem_version})" exit_code |= 2 diff --git a/lib/rubygems/commands/list_command.rb b/lib/rubygems/commands/list_command.rb index cd21543537..f94038920f 100644 --- a/lib/rubygems/commands/list_command.rb +++ b/lib/rubygems/commands/list_command.rb @@ -1,17 +1,20 @@ # frozen_string_literal: true require 'rubygems/command' -require 'rubygems/commands/query_command' +require 'rubygems/query_utils' ## -# An alternate to Gem::Commands::QueryCommand that searches for gems starting -# with the supplied argument. +# Searches for gems starting with the supplied argument. -class Gem::Commands::ListCommand < Gem::Commands::QueryCommand +class Gem::Commands::ListCommand < Gem::Command + + include Gem::QueryUtils def initialize - super 'list', 'Display local gems whose name matches REGEXP' + super 'list', 'Display local gems whose name matches REGEXP', + :name => //, :domain => :local, :details => false, :versions => true, + :installed => nil, :version => Gem::Requirement.default - remove_option('--name-matches') + add_query_options end def arguments # :nodoc: diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index 2248a821c8..d10060923f 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -40,6 +40,11 @@ class Gem::Commands::PristineCommand < Gem::Command options[:only_executables] = value end + add_option('--only-plugins', + 'Only restore plugins') do |value, options| + options[:only_plugins] = value + end + add_option('-E', '--[no-]env-shebang', 'Rewrite executables with a shebang', 'of /usr/bin/env') do |value, options| @@ -126,14 +131,14 @@ extensions will be restored. end end - unless spec.extensions.empty? or options[:extensions] or options[:only_executables] + unless spec.extensions.empty? or options[:extensions] or options[:only_executables] or options[:only_plugins] say "Skipped #{spec.full_name}, it needs to compile an extension" next end gem = spec.cache_file - unless File.exist? gem or options[:only_executables] + unless File.exist? gem or options[:only_executables] or options[:only_plugins] require 'rubygems/remote_fetcher' say "Cached gem for #{spec.full_name} not found, attempting to fetch..." @@ -172,6 +177,9 @@ extensions will be restored. if options[:only_executables] installer = Gem::Installer.for_spec(spec, installer_options) installer.generate_bin + elsif options[:only_plugins] + installer = Gem::Installer.for_spec(spec) + installer.generate_plugins else installer = Gem::Installer.at(gem, installer_options) installer.install diff --git a/lib/rubygems/commands/search_command.rb b/lib/rubygems/commands/search_command.rb index c9cb1f2d43..65ee25167c 100644 --- a/lib/rubygems/commands/search_command.rb +++ b/lib/rubygems/commands/search_command.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true require 'rubygems/command' -require 'rubygems/commands/query_command' +require 'rubygems/query_utils' -class Gem::Commands::SearchCommand < Gem::Commands::QueryCommand +class Gem::Commands::SearchCommand < Gem::Command - def initialize - super 'search', 'Display remote gems whose name matches REGEXP' + include Gem::QueryUtils - remove_option '--name-matches' + def initialize + super 'search', 'Display remote gems whose name matches REGEXP', + :name => //, :domain => :remote, :details => false, :versions => true, + :installed => nil, :version => Gem::Requirement.default - defaults[:domain] = :remote + add_query_options end def arguments # :nodoc: diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 579776df7e..d67caca91c 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -20,7 +20,8 @@ class Gem::Commands::SetupCommand < Gem::Command :force => true, :site_or_vendor => 'sitelibdir', :destdir => '', :prefix => '', :previous_version => '', - :regenerate_binstubs => true + :regenerate_binstubs => true, + :regenerate_plugins => true add_option '--previous-version=VERSION', 'Previous version of RubyGems', @@ -89,6 +90,11 @@ class Gem::Commands::SetupCommand < Gem::Command options[:regenerate_binstubs] = value end + add_option '--[no-]regenerate-plugins', + 'Regenerate gem plugins' do |value, options| + options[:regenerate_plugins] = value + end + add_option '-f', '--[no-]force', 'Forcefully overwrite binstubs' do |value, options| options[:force] = value @@ -181,6 +187,7 @@ By default, this RubyGems will install gem as: say "RubyGems #{Gem::VERSION} installed" regenerate_binstubs if options[:regenerate_binstubs] + regenerate_plugins if options[:regenerate_plugins] uninstall_old_gemcutter @@ -626,6 +633,16 @@ abort "#{deprecation_message}" command.invoke(*args) end + def regenerate_plugins + require "rubygems/commands/pristine_command" + say "Regenerating plugins" + + args = %w[--all --only-plugins --silent] + + command = Gem::Commands::PristineCommand.new + command.invoke(*args) + end + private def target_bin_path(bin_dir, bin_file) diff --git a/lib/rubygems/commands/sources_command.rb b/lib/rubygems/commands/sources_command.rb index feab23237d..ca9d425232 100644 --- a/lib/rubygems/commands/sources_command.rb +++ b/lib/rubygems/commands/sources_command.rb @@ -136,7 +136,7 @@ RubyGems has been configured to serve gems via the following URLs through its history: * http://gems.rubyforge.org (RubyGems 1.3.6 and earlier) -* http://rubygems.org (RubyGems 1.3.7 through 1.8.25) +* https://rubygems.org/ (RubyGems 1.3.7 through 1.8.25) * https://rubygems.org (RubyGems 2.0.1 and newer) Since all of these sources point to the same set of gems you only need one @@ -153,8 +153,8 @@ before it is added. To remove a source use the --remove argument: - $ gem sources --remove http://rubygems.org - http://rubygems.org removed from sources + $ gem sources --remove https://rubygems.org/ + https://rubygems.org/ removed from sources EOF end diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index e8031a259d..7031ac0dd0 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -73,8 +73,6 @@ command to remove old versions. say "Latest version already installed. Done." terminate_interaction end - - options[:user_install] = false end def check_update_arguments # :nodoc: @@ -90,9 +88,10 @@ command to remove old versions. return end - hig = highest_installed_gems - - gems_to_update = which_to_update hig, options[:args].uniq + gems_to_update = which_to_update( + highest_installed_gems, + options[:args].uniq + ) if options[:explain] say "Gems to update:" @@ -137,6 +136,9 @@ command to remove old versions. def highest_installed_gems # :nodoc: hig = {} # highest installed gems + # Get only gem specifications installed as --user-install + Gem::Specification.dirs = Gem.user_dir if options[:user_install] + Gem::Specification.each do |spec| if hig[spec.name].nil? or hig[spec.name].version < spec.version hig[spec.name] = spec @@ -168,11 +170,34 @@ command to remove old versions. Dir.chdir update_dir do say "Installing RubyGems #{version}" - installed = system Gem.ruby, '--disable-gems', 'setup.rb', *args + installed = preparing_gem_layout_for(version) do + system Gem.ruby, '--disable-gems', 'setup.rb', *args + end + say "RubyGems system software updated" if installed end end + def preparing_gem_layout_for(version) + if Gem::Version.new(version) >= Gem::Version.new("3.2.a") + yield + else + require "tmpdir" + tmpdir = Dir.mktmpdir + FileUtils.mv Gem.plugins_dir, tmpdir + + status = yield + + if status + FileUtils.rm_rf tmpdir + else + FileUtils.mv File.join(tmpdir, "plugins"), Gem.plugins_dir + end + + status + end + end + def rubygems_target_version version = options[:system] update_latest = version == true diff --git a/lib/rubygems/deprecate.rb b/lib/rubygems/deprecate.rb index 8accfb6174..19c0aa0752 100644 --- a/lib/rubygems/deprecate.rb +++ b/lib/rubygems/deprecate.rb @@ -65,6 +65,22 @@ module Gem::Deprecate end end - module_function :deprecate, :skip_during + # Deprecation method to deprecate Rubygems commands + def deprecate_command(year, month) + class_eval do + define_method "deprecated?" do + true + end + + define_method "deprecation_warning" do + msg = [ "#{self.command} command is deprecated", + ". It will be removed on or after %4d-%02d-01.\n" % [year, month], + ] + + alert_warning "#{msg.join}" unless Gem::Deprecate.skip + end + end + end + module_function :deprecate, :deprecate_command, :skip_during end diff --git a/lib/rubygems/doctor.rb b/lib/rubygems/doctor.rb index 661ae5a4e1..cb800f11ec 100644 --- a/lib/rubygems/doctor.rb +++ b/lib/rubygems/doctor.rb @@ -26,6 +26,7 @@ class Gem::Doctor ['doc', ''], ['extensions', ''], ['gems', ''], + ['plugins', ''], ].freeze missing = @@ -112,6 +113,7 @@ class Gem::Doctor next if installed_specs.include? basename next if /^rubygems-\d/ =~ basename next if 'specifications' == sub_directory and 'default' == basename + next if 'plugins' == sub_directory and Gem.plugin_suffix_regexp =~ basename type = File.directory?(child) ? 'directory' : 'file' diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb index 3924f9dde6..ac1e8b49cf 100644 --- a/lib/rubygems/exceptions.rb +++ b/lib/rubygems/exceptions.rb @@ -5,18 +5,7 @@ require 'rubygems/deprecate' ## # Base exception class for RubyGems. All exception raised by RubyGems are a # subclass of this one. -class Gem::Exception < RuntimeError - - ## - #-- - # TODO: remove in RubyGems 4, nobody sets this - - attr_accessor :source_exception # :nodoc: - - extend Gem::Deprecate - deprecate :source_exception, :none, 2018, 12 - -end +class Gem::Exception < RuntimeError; end class Gem::CommandLineError < Gem::Exception; end diff --git a/lib/rubygems/gem_runner.rb b/lib/rubygems/gem_runner.rb index 4159d81389..80aebd579a 100644 --- a/lib/rubygems/gem_runner.rb +++ b/lib/rubygems/gem_runner.rb @@ -26,13 +26,9 @@ Gem.load_env_plugins rescue nil class Gem::GemRunner - def initialize(options={}) - if !options.empty? && !Gem::Deprecate.skip - Kernel.warn "NOTE: passing options to Gem::GemRunner.new is deprecated with no replacement. It will be removed on or after 2016-10-01." - end - - @command_manager_class = options[:command_manager] || Gem::CommandManager - @config_file_class = options[:config_file] || Gem::ConfigFile + def initialize + @command_manager_class = Gem::CommandManager + @config_file_class = Gem::ConfigFile end ## diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index ad39ec81bf..2ba92482cc 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -6,6 +6,7 @@ #++ require 'rubygems/command' +require 'rubygems/installer_uninstaller_utils' require 'rubygems/exceptions' require 'rubygems/deprecate' require 'rubygems/package' @@ -43,6 +44,8 @@ class Gem::Installer include Gem::UserInteraction + include Gem::InstallerUninstallerUtils + ## # Filename of the gem being installed. @@ -180,15 +183,7 @@ class Gem::Installer require 'fileutils' @options = options - if package.is_a? String - security_policy = options[:security_policy] - @package = Gem::Package.new package, security_policy - if $VERBOSE - warn "constructing an Installer object with a string is deprecated. Please use Gem::Installer.at (called from: #{caller.first})" - end - else - @package = package - end + @package = package process_options @@ -330,6 +325,7 @@ class Gem::Installer end generate_bin + generate_plugins unless @options[:install_as_default] write_spec @@ -520,7 +516,17 @@ class Gem::Installer else generate_bin_symlink filename, @bin_dir end + end + end + def generate_plugins # :nodoc: + latest = Gem::Specification.latest_spec_for(spec.name) + return if latest && latest.version > spec.version + + if spec.plugins.empty? + remove_plugins_for(spec) + else + regenerate_plugins_for(spec) end end @@ -810,7 +816,7 @@ TEXT ruby_exe = "ruby.exe" if ruby_exe.empty? if File.exist?(File.join bindir, ruby_exe) - # stub & ruby.exe withing same folder. Portable + # stub & ruby.exe within same folder. Portable <<-TEXT @ECHO OFF @"%~dp0#{ruby_exe}" "%~dpn0" %* @@ -844,18 +850,6 @@ TEXT builder.build_extensions end - ## - # Logs the build +output+ in +build_dir+, then raises Gem::Ext::BuildError. - # - # TODO: Delete this for RubyGems 4. It remains for API compatibility - - def extension_build_error(build_dir, output, backtrace = nil) # :nodoc: - builder = Gem::Ext::Builder.new spec, @build_args - - builder.build_error build_dir, output, backtrace - end - deprecate :extension_build_error, :none, 2018, 12 - ## # Reads the file index and extracts each file into the gem directory. # diff --git a/lib/rubygems/installer_test_case.rb b/lib/rubygems/installer_test_case.rb index f48466d3ea..5a3ce75c26 100644 --- a/lib/rubygems/installer_test_case.rb +++ b/lib/rubygems/installer_test_case.rb @@ -171,10 +171,10 @@ class Gem::InstallerTestCase < Gem::TestCase ## # Sets up the base @gem, builds it and returns an installer for it. # - def util_setup_installer + def util_setup_installer(&block) @gem = setup_base_gem - util_setup_gem + util_setup_gem(&block) end ## diff --git a/lib/rubygems/installer_uninstaller_utils.rb b/lib/rubygems/installer_uninstaller_utils.rb new file mode 100644 index 0000000000..b8436f4f0a --- /dev/null +++ b/lib/rubygems/installer_uninstaller_utils.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +## +# Helper methods for both Gem::Installer and Gem::Uninstaller + +module Gem::InstallerUninstallerUtils + + def regenerate_plugins_for(spec) + spec.plugins.each do |plugin| + plugin_script_path = File.join Gem.plugins_dir, "#{spec.name}_plugin#{File.extname(plugin)}" + + File.open plugin_script_path, 'wb' do |file| + file.puts "require '#{plugin}'" + end + + verbose plugin_script_path + end + end + + def remove_plugins_for(spec) + FileUtils.rm_f Gem::Util.glob_files_in_dir("#{spec.name}#{Gem.plugin_suffix_pattern}", Gem.plugins_dir) + end + +end diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 813ab9da33..b944a050a3 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -8,7 +8,8 @@ # Example using a Gem::Package # # Builds a .gem file given a Gem::Specification. A .gem file is a tarball -# which contains a data.tar.gz and metadata.gz, and possibly signatures. +# which contains a data.tar.gz, metadata.gz, checksums.yaml.gz and possibly +# signatures. # # require 'rubygems' # require 'rubygems/package' diff --git a/lib/rubygems/query_utils.rb b/lib/rubygems/query_utils.rb new file mode 100644 index 0000000000..3bc5ccfaa2 --- /dev/null +++ b/lib/rubygems/query_utils.rb @@ -0,0 +1,362 @@ +# frozen_string_literal: true + +require 'rubygems/local_remote_options' +require 'rubygems/spec_fetcher' +require 'rubygems/version_option' +require 'rubygems/text' + +module Gem::QueryUtils + + include Gem::Text + include Gem::LocalRemoteOptions + include Gem::VersionOption + + def add_query_options + add_option('-i', '--[no-]installed', + 'Check for installed gem') do |value, options| + options[:installed] = value + end + + add_option('-I', 'Equivalent to --no-installed') do |value, options| + options[:installed] = false + end + + add_version_option command, "for use with --installed" + + add_option('-d', '--[no-]details', + 'Display detailed information of gem(s)') do |value, options| + options[:details] = value + end + + add_option('--[no-]versions', + 'Display only gem names') do |value, options| + options[:versions] = value + options[:details] = false unless value + end + + add_option('-a', '--all', + 'Display all gem versions') do |value, options| + options[:all] = value + end + + add_option('-e', '--exact', + 'Name of gem(s) to query on matches the', + 'provided STRING') do |value, options| + options[:exact] = value + end + + add_option('--[no-]prerelease', + 'Display prerelease versions') do |value, options| + options[:prerelease] = value + end + + add_local_remote_options + end + + def defaults_str # :nodoc: + "--local --name-matches // --no-details --versions --no-installed" + end + + def description # :nodoc: + <<-EOF +The query command is the basis for the list and search commands. + +You should really use the list and search commands instead. This command +is too hard to use. + EOF + end + + def execute + gem_names = Array(options[:name]) + + if !args.empty? + gem_names = options[:exact] ? args.map{|arg| /\A#{Regexp.escape(arg)}\Z/ } : args.map{|arg| /#{arg}/i } + end + + terminate_interaction(check_installed_gems(gem_names)) if check_installed_gems? + + gem_names.each { |n| show_gems(n) } + end + + private + + def check_installed_gems(gem_names) + exit_code = 0 + + if args.empty? && !gem_name? + alert_error "You must specify a gem name" + exit_code = 4 + elsif gem_names.count > 1 + alert_error "You must specify only ONE gem!" + exit_code = 4 + else + installed = installed?(gem_names.first, options[:version]) + installed = !installed unless options[:installed] + + say(installed) + exit_code = 1 if !installed + end + + exit_code + end + + def check_installed_gems? + !options[:installed].nil? + end + + def gem_name? + !options[:name].source.empty? + end + + def prerelease + options[:prerelease] + end + + def show_prereleases? + prerelease.nil? || prerelease + end + + def args + options[:args].to_a + end + + def display_header(type) + if (ui.outs.tty? and Gem.configuration.verbose) or both? + say + say "*** #{type} GEMS ***" + say + end + end + + #Guts of original execute + def show_gems(name) + show_local_gems(name) if local? + show_remote_gems(name) if remote? + end + + def show_local_gems(name, req = Gem::Requirement.default) + display_header("LOCAL") + + specs = Gem::Specification.find_all do |s| + s.name =~ name and req =~ s.version + end + + dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req } + specs.select! do |s| + dep.match?(s.name, s.version, show_prereleases?) + end + + spec_tuples = specs.map do |spec| + [spec.name_tuple, spec] + end + + output_query_results(spec_tuples) + end + + def show_remote_gems(name) + display_header("REMOTE") + + fetcher = Gem::SpecFetcher.fetcher + + spec_tuples = if name.respond_to?(:source) && name.source.empty? + fetcher.detect(specs_type) { true } + else + fetcher.detect(specs_type) do |name_tuple| + name === name_tuple.name + end + end + + output_query_results(spec_tuples) + end + + def specs_type + if options[:all] + if options[:prerelease] + :complete + else + :released + end + elsif options[:prerelease] + :prerelease + else + :latest + end + end + + ## + # Check if gem +name+ version +version+ is installed. + + def installed?(name, req = Gem::Requirement.default) + Gem::Specification.any? { |s| s.name =~ name and req =~ s.version } + end + + def output_query_results(spec_tuples) + output = [] + versions = Hash.new { |h,name| h[name] = [] } + + spec_tuples.each do |spec_tuple, source| + versions[spec_tuple.name] << [spec_tuple, source] + end + + versions = versions.sort_by do |(n,_),_| + n.downcase + end + + output_versions output, versions + + say output.join(options[:details] ? "\n\n" : "\n") + end + + def output_versions(output, versions) + versions.each do |gem_name, matching_tuples| + matching_tuples = matching_tuples.sort_by { |n,_| n.version }.reverse + + platforms = Hash.new { |h,version| h[version] = [] } + + matching_tuples.each do |n, _| + platforms[n.version] << n.platform if n.platform + end + + seen = {} + + matching_tuples.delete_if do |n,_| + if seen[n.version] + true + else + seen[n.version] = true + false + end + end + + output << clean_text(make_entry(matching_tuples, platforms)) + end + end + + def entry_details(entry, detail_tuple, specs, platforms) + return unless options[:details] + + name_tuple, spec = detail_tuple + + spec = spec.fetch_spec(name_tuple)if spec.respond_to?(:fetch_spec) + + entry << "\n" + + spec_platforms entry, platforms + spec_authors entry, spec + spec_homepage entry, spec + spec_license entry, spec + spec_loaded_from entry, spec, specs + spec_summary entry, spec + end + + def entry_versions(entry, name_tuples, platforms, specs) + return unless options[:versions] + + list = + if platforms.empty? or options[:details] + name_tuples.map { |n| n.version }.uniq + else + platforms.sort.reverse.map do |version, pls| + out = version.to_s + + if options[:domain] == :local + default = specs.any? do |s| + !s.is_a?(Gem::Source) && s.version == version && s.default_gem? + end + out = "default: #{out}" if default + end + + if pls != [Gem::Platform::RUBY] + platform_list = [pls.delete(Gem::Platform::RUBY), *pls.sort].compact + out = platform_list.unshift(out).join(' ') + end + + out + end + end + + entry << " (#{list.join ', '})" + end + + def make_entry(entry_tuples, platforms) + detail_tuple = entry_tuples.first + + name_tuples, specs = entry_tuples.flatten.partition do |item| + Gem::NameTuple === item + end + + entry = [name_tuples.first.name] + + entry_versions(entry, name_tuples, platforms, specs) + entry_details(entry, detail_tuple, specs, platforms) + + entry.join + end + + def spec_authors(entry, spec) + authors = "Author#{spec.authors.length > 1 ? 's' : ''}: ".dup + authors << spec.authors.join(', ') + entry << format_text(authors, 68, 4) + end + + def spec_homepage(entry, spec) + return if spec.homepage.nil? or spec.homepage.empty? + + entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4) + end + + def spec_license(entry, spec) + return if spec.license.nil? or spec.license.empty? + + licenses = "License#{spec.licenses.length > 1 ? 's' : ''}: ".dup + licenses << spec.licenses.join(', ') + entry << "\n" << format_text(licenses, 68, 4) + end + + def spec_loaded_from(entry, spec, specs) + return unless spec.loaded_from + + if specs.length == 1 + default = spec.default_gem? ? ' (default)' : nil + entry << "\n" << " Installed at#{default}: #{spec.base_dir}" + else + label = 'Installed at' + specs.each do |s| + version = s.version.to_s + version << ', default' if s.default_gem? + entry << "\n" << " #{label} (#{version}): #{s.base_dir}" + label = ' ' * label.length + end + end + end + + def spec_platforms(entry, platforms) + non_ruby = platforms.any? do |_, pls| + pls.any? { |pl| pl != Gem::Platform::RUBY } + end + + return unless non_ruby + + if platforms.length == 1 + title = platforms.values.length == 1 ? 'Platform' : 'Platforms' + entry << " #{title}: #{platforms.values.sort.join(', ')}\n" + else + entry << " Platforms:\n" + + sorted_platforms = platforms.sort_by { |version,| version } + + sorted_platforms.each do |version, pls| + label = " #{version}: " + data = format_text pls.sort.join(', '), 68, label.length + data[0, label.length] = label + entry << data << "\n" + end + end + end + + def spec_summary(entry, spec) + summary = truncate_text(spec.summary, "the summary for #{spec.full_name}") + entry << "\n\n" << format_text(summary, 68, 4) + end + +end diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index 2ed619f1bc..b37ebc15fd 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -7,7 +7,6 @@ require 'rubygems/uri_formatter' require 'rubygems/uri_parsing' require 'rubygems/user_interaction' require 'resolv' -require 'rubygems/deprecate' ## # RemoteFetcher handles the details of fetching gems and gem information from @@ -16,8 +15,6 @@ require 'rubygems/deprecate' class Gem::RemoteFetcher include Gem::UserInteraction - extend Gem::Deprecate - include Gem::UriParsing ## @@ -309,17 +306,6 @@ class Gem::RemoteFetcher data end - ## - # Returns the size of +uri+ in bytes. - - def fetch_size(uri) - response = fetch_path(uri, nil, true) - - response['content-length'].to_i - end - - deprecate :fetch_size, :none, 2019, 12 - ## # Performs a Net::HTTP request of type +request_class+ on +uri+ returning # a Net::HTTP response object. request maintains a table of persistent diff --git a/lib/rubygems/request_set/gem_dependency_api.rb b/lib/rubygems/request_set/gem_dependency_api.rb index b7a8ee6f4f..ef3f302ea8 100644 --- a/lib/rubygems/request_set/gem_dependency_api.rb +++ b/lib/rubygems/request_set/gem_dependency_api.rb @@ -235,7 +235,7 @@ class Gem::RequestSet::GemDependencyAPI return unless (groups & @without_groups).empty? dependencies.each do |dep| - @set.gem dep.name, *dep.requirement + @set.gem dep.name, *dep.requirement.as_list end end diff --git a/lib/rubygems/resolver/api_set.rb b/lib/rubygems/resolver/api_set.rb index 6fd91e3b73..135f1b08aa 100644 --- a/lib/rubygems/resolver/api_set.rb +++ b/lib/rubygems/resolver/api_set.rb @@ -23,7 +23,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set ## # Creates a new APISet that will retrieve gems from +uri+ using the RubyGems # API URL +dep_uri+ which is described at - # http://guides.rubygems.org/rubygems-org-api + # https://guides.rubygems.org/rubygems-org-api def initialize(dep_uri = 'https://rubygems.org/api/v1/dependencies') super() diff --git a/lib/rubygems/resolver/api_specification.rb b/lib/rubygems/resolver/api_specification.rb index 9bbc095788..4052846e99 100644 --- a/lib/rubygems/resolver/api_specification.rb +++ b/lib/rubygems/resolver/api_specification.rb @@ -11,7 +11,7 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification # Creates an APISpecification for the given +set+ from the rubygems.org # +api_data+. # - # See http://guides.rubygems.org/rubygems-org-api/#misc_methods for the + # See https://guides.rubygems.org/rubygems-org-api/#misc_methods for the # format of the +api_data+. def initialize(set, api_data) diff --git a/lib/rubygems/security.rb b/lib/rubygems/security.rb index 7b0a0b3c6a..4529c08772 100644 --- a/lib/rubygems/security.rb +++ b/lib/rubygems/security.rb @@ -62,11 +62,11 @@ end # # $ tar tf your-gem-1.0.gem # metadata.gz -# metadata.gz.sum # metadata.gz.sig # metadata signature # data.tar.gz -# data.tar.gz.sum # data.tar.gz.sig # data signature +# checksums.yaml.gz +# checksums.yaml.gz.sig # checksums signature # # === Manually signing gems # @@ -161,6 +161,8 @@ end # -K, --private-key KEY Key for --sign or --build # -s, --sign CERT Signs CERT with the key from -K # and the certificate from -C +# -d, --days NUMBER_OF_DAYS Days before the certificate expires +# -R, --re-sign Re-signs the certificate from -C with the key from -K # # We've already covered the --build option, and the # --add, --list, and --remove commands @@ -265,7 +267,7 @@ end # 2. Grab the public key from the gemspec # # gem spec some_signed_gem-1.0.gem cert_chain | \ -# ruby -ryaml -e 'puts YAML.load_documents($stdin)' > public_key.crt +# ruby -ryaml -e 'puts YAML.load($stdin)' > public_key.crt # # 3. Generate a SHA1 hash of the data.tar.gz # diff --git a/lib/rubygems/security/signer.rb b/lib/rubygems/security/signer.rb index 5e4ba6ebba..8fb1b1ddc1 100644 --- a/lib/rubygems/security/signer.rb +++ b/lib/rubygems/security/signer.rb @@ -39,7 +39,7 @@ class Gem::Security::Signer }.freeze ## - # Attemps to re-sign an expired cert with a given private key + # Attempts to re-sign an expired cert with a given private key def self.re_sign_cert(expired_cert, expired_cert_path, private_key) return unless expired_cert.not_after < Time.now diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb index 97923ef698..83d7cf5abc 100644 --- a/lib/rubygems/server.rb +++ b/lib/rubygems/server.rb @@ -661,7 +661,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } "only_one_executable" => true, "full_name" => "rubygems-#{Gem::VERSION}", "has_deps" => false, - "homepage" => "http://guides.rubygems.org/", + "homepage" => "https://guides.rubygems.org/", "name" => 'rubygems', "ri_installed" => true, "summary" => "RubyGems itself", diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 5321edfcc3..ad43a63e80 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -384,6 +384,7 @@ class Gem::Specification < Gem::BasicSpecification # "mailing_list_uri" => "https://groups.example.com/bestgemever", # "source_code_uri" => "https://example.com/user/bestgemever", # "wiki_uri" => "https://example.com/user/bestgemever/wiki" + # "funding_uri" => "https://example.com/donate" # } # # These links will be used on your gem's page on rubygems.org and must pass @@ -1086,6 +1087,13 @@ class Gem::Specification < Gem::BasicSpecification _latest_specs Gem::Specification._all, prerelease end + ## + # Return the latest installed spec for gem +name+. + + def self.latest_spec_for(name) + latest_specs(true).find { |installed_spec| installed_spec.name == name } + end + def self._latest_specs(specs, prerelease = false) # :nodoc: result = Hash.new { |h,k| h[k] = {} } native = {} @@ -1752,10 +1760,11 @@ class Gem::Specification < Gem::BasicSpecification # # [depending_gem, dependency, [list_of_gems_that_satisfy_dependency]] - def dependent_gems + def dependent_gems(check_dev=true) out = [] Gem::Specification.each do |spec| - spec.dependencies.each do |dep| + deps = check_dev ? spec.dependencies : spec.runtime_dependencies + deps.each do |dep| if self.satisfies_requirement?(dep) sats = [] find_all_satisfiers(dep) do |sat| @@ -1847,29 +1856,23 @@ class Gem::Specification < Gem::BasicSpecification end ## - # Sets executables to +value+, ensuring it is an array. Don't - # use this, push onto the array instead. + # Sets executables to +value+, ensuring it is an array. def executables=(value) - # TODO: warn about setting instead of pushing @executables = Array(value) end ## - # Sets extensions to +extensions+, ensuring it is an array. Don't - # use this, push onto the array instead. + # Sets extensions to +extensions+, ensuring it is an array. def extensions=(extensions) - # TODO: warn about setting instead of pushing @extensions = Array extensions end ## - # Sets extra_rdoc_files to +files+, ensuring it is an array. Don't - # use this, push onto the array instead. + # Sets extra_rdoc_files to +files+, ensuring it is an array. def extra_rdoc_files=(files) - # TODO: warn about setting instead of pushing @extra_rdoc_files = Array files end @@ -2245,11 +2248,9 @@ class Gem::Specification < Gem::BasicSpecification end ## - # Sets rdoc_options to +value+, ensuring it is an array. Don't - # use this, push onto the array instead. + # Sets rdoc_options to +value+, ensuring it is an array. def rdoc_options=(options) - # TODO: warn about setting instead of pushing @rdoc_options = Array options end @@ -2268,11 +2269,9 @@ class Gem::Specification < Gem::BasicSpecification end ## - # Set requirements to +req+, ensuring it is an array. Don't - # use this, push onto the array instead. + # Set requirements to +req+, ensuring it is an array. def requirements=(req) - # TODO: warn about setting instead of pushing @requirements = Array req end diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index c3c496db9b..a50fafbc82 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -18,6 +18,7 @@ class Gem::SpecificationPolicy mailing_list_uri source_code_uri wiki_uri + funding_uri ].freeze # :nodoc: def initialize(specification) @@ -421,7 +422,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li end def help_text # :nodoc: - "See http://guides.rubygems.org/specification-reference/ for help" + "See https://guides.rubygems.org/specification-reference/ for help" end end diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 206497c651..691985dcd2 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -169,20 +169,24 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # original value when the block ends # def bindir(value) - bindir = RbConfig::CONFIG['bindir'] + with_clean_path_to_ruby do + bindir = RbConfig::CONFIG['bindir'] - if value - RbConfig::CONFIG['bindir'] = value - else - RbConfig::CONFIG.delete 'bindir' - end + if value + RbConfig::CONFIG['bindir'] = value + else + RbConfig::CONFIG.delete 'bindir' + end - yield - ensure - if bindir - RbConfig::CONFIG['bindir'] = bindir - else - RbConfig::CONFIG.delete 'bindir' + begin + yield + ensure + if bindir + RbConfig::CONFIG['bindir'] = bindir + else + RbConfig::CONFIG.delete 'bindir' + end + end end end @@ -321,6 +325,11 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni @tempdir.tap(&Gem::UNTAINT) end + @orig_SYSTEM_WIDE_CONFIG_FILE = Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE + Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE + Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE, + File.join(@tempdir, 'system-gemrc') + @gemhome = File.join @tempdir, 'gemhome' @userhome = File.join @tempdir, 'userhome' ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache' @@ -331,7 +340,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni ruby end - @git = ENV['GIT'] || 'git' + @git = ENV['GIT'] || (win_platform? ? 'git.exe' : 'git') Gem.ensure_gem_subdirectories @gemhome @@ -442,6 +451,10 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni ENV.replace(@orig_env) + Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE + Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE, + @orig_SYSTEM_WIDE_CONFIG_FILE + Gem.ruby = @orig_ruby if @orig_ruby if Gem.java_platform? @@ -562,7 +575,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni def install_gem(spec, options = {}) require 'rubygems/installer' - gem = File.join @tempdir, "gems", "#{spec.full_name}.gem" + gem = spec.cache_file unless File.exist? gem use_ui Gem::MockGemUi.new do @@ -571,7 +584,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end end - gem = File.join(@tempdir, File.basename(spec.cache_file)).tap(&Gem::UNTAINT) + gem = File.join(@tempdir, File.basename(gem)).tap(&Gem::UNTAINT) end Gem::Installer.at(gem, options.merge({:wrappers => true})).install @@ -667,8 +680,6 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni yield(s) if block_given? end - Gem::Specification.map # HACK: force specs to (re-)load before we write - written_path = write_file spec.spec_file do |io| io.write spec.to_ruby_for_cache end @@ -833,9 +844,6 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni util_build_gem spec - cache_file = File.join @tempdir, 'gems', "#{spec.full_name}.gem" - FileUtils.mkdir_p File.dirname cache_file - FileUtils.mv spec.cache_file, cache_file FileUtils.rm spec.spec_file end @@ -1247,6 +1255,16 @@ Also, a list: end end + def with_clean_path_to_ruby + orig_ruby = Gem.ruby + + Gem.instance_variable_set :@ruby, nil + + yield + ensure + Gem.instance_variable_set :@ruby, orig_ruby + end + class << self # :nodoc: diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index 20b437d472..1766423429 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -7,6 +7,7 @@ require 'fileutils' require 'rubygems' +require 'rubygems/installer_uninstaller_utils' require 'rubygems/dependency_list' require 'rubygems/rdoc' require 'rubygems/user_interaction' @@ -23,6 +24,8 @@ class Gem::Uninstaller include Gem::UserInteraction + include Gem::InstallerUninstallerUtils + ## # The directory a gem's executables will be installed into @@ -158,8 +161,11 @@ class Gem::Uninstaller end remove_executables @spec + remove_plugins @spec remove @spec + regenerate_plugins + Gem.post_uninstall_hooks.each do |hook| hook.call self end @@ -168,11 +174,10 @@ class Gem::Uninstaller end ## - # Removes installed executables and batch files (windows only) for - # +gemspec+. + # Removes installed executables and batch files (windows only) for +spec+. def remove_executables(spec) - return if spec.nil? or spec.executables.empty? + return if spec.executables.empty? executables = spec.executables.clone @@ -231,10 +236,6 @@ class Gem::Uninstaller ## # spec:: the spec of the gem to be uninstalled - # list:: the list of all such gems - # - # Warning: this method modifies the +list+ parameter. Once it has - # uninstalled a gem, it is removed from that list. def remove(spec) unless path_ok?(@gem_home, spec) or @@ -274,6 +275,25 @@ class Gem::Uninstaller Gem::Specification.reset end + ## + # Remove any plugin wrappers for +spec+. + + def remove_plugins(spec) # :nodoc: + return if spec.plugins.empty? + + remove_plugins_for(spec) + end + + ## + # Regenerates plugin wrappers after removal. + + def regenerate_plugins + latest = Gem::Specification.latest_spec_for(@spec.name) + return if latest.nil? + + regenerate_plugins_for(latest) + end + ## # Is +spec+ in +gem_dir+? @@ -317,7 +337,7 @@ class Gem::Uninstaller s.name == spec.name && s.full_name != spec.full_name end - spec.dependent_gems.each do |dep_spec, dep, satlist| + spec.dependent_gems(@check_dev).each do |dep_spec, dep, satlist| unless siblings.any? { |s| s.satisfies_requirement? dep } msg << "#{dep_spec.name}-#{dep_spec.version} depends on #{dep}" end diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 93f528a763..f5bdd84150 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -358,14 +358,6 @@ class Gem::StreamUI ask(question) if question end - ## - # Display a debug message on the same location as error messages. - - def debug(statement) - @errs.puts statement - end - deprecate :debug, :none, 2018, 12 - ## # Terminate the application with exit code +status+, running any exit # handlers that might have been defined. diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index 6524faf5c8..b1faedcda2 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -151,7 +151,7 @@ class Gem::Version - autoload :Requirement, 'rubygems/requirement' + autoload :Requirement, File.expand_path('requirement', __dir__) include Comparable -- cgit v1.2.3