diff options
author | Takuya Noguchi <[email protected]> | 2022-07-17 08:08:51 +0000 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2022-07-22 12:07:23 +0900 |
commit | d7ffd3fea402239b16833cc434404a7af82d44f3 () | |
tree | 9794942135111c36e6b6bce69e070ca556b89028 /lib | |
parent | 388c4e1076ac5a58d5008abc8e0a8d017698875a (diff) |
RubyGems: Enable Style/StringLiterals cop
Signed-off-by: Takuya Noguchi <[email protected]>
138 files changed, 1380 insertions, 1380 deletions
@@ -5,18 +5,18 @@ # See LICENSE.txt for permissions. #++ -require 'rbconfig' module Gem VERSION = "3.4.0.dev".freeze end # Must be first since it unloads the prelude from 1.9.2 -require_relative 'rubygems/compatibility' -require_relative 'rubygems/defaults' -require_relative 'rubygems/deprecate' -require_relative 'rubygems/errors' ## # RubyGems is the Ruby standard for publishing and managing third party @@ -117,11 +117,11 @@ module Gem # Taint support is deprecated in Ruby 2.7. # This allows switching ".untaint" to ".tap(&Gem::UNTAINT)", # to avoid deprecation warnings in Ruby 2.7. - UNTAINT = RUBY_VERSION < '2.7' ? :untaint.to_sym : proc {} # When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn KERNEL_WARN_IGNORES_INTERNAL_ENTRIES = RUBY_ENGINE == "truffleruby" || - (RUBY_ENGINE == "ruby" && RUBY_VERSION >= '3.0') ## # An Array of Regexps that match windows Ruby platforms. @@ -293,14 +293,14 @@ module Gem # The mode needed to read a file as straight binary. def self.binary_mode - 'rb' end ## # The path where gem executables are to be installed. def self.bindir(install_dir=Gem.dir) - return File.join install_dir, 'bin' unless install_dir.to_s == Gem.default_dir.to_s Gem.default_bindir end @@ -309,7 +309,7 @@ module Gem # The path were rubygems plugins are to be installed. def self.plugindir(install_dir=Gem.dir) - File.join install_dir, 'plugins' end ## @@ -353,7 +353,7 @@ module Gem # A Zlib::Deflate.deflate wrapper def self.deflate(data) - require 'zlib' Zlib::Deflate.deflate data end @@ -375,7 +375,7 @@ module Gem target = {} env.each_pair do |k,v| case k - when 'GEM_HOME', 'GEM_PATH', 'GEM_SPEC_CACHE' case v when nil, String target[k] = v @@ -450,7 +450,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} subdir = File.join dir, name next if File.exist? subdir - require 'fileutils' begin FileUtils.mkdir_p subdir, **options @@ -466,7 +466,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # distinction as extensions cannot be shared between the two. def self.extension_api_version # :nodoc: - if 'no' == RbConfig::CONFIG['ENABLE_SHARED'] "#{ruby_api_version}-static" else ruby_api_version @@ -576,7 +576,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} return i if path.instance_variable_defined?(:@gem_prelude_index) end - index = $LOAD_PATH.index RbConfig::CONFIG['sitelibdir'] index || 0 end @@ -607,10 +607,10 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} def self.load_yaml return if @yaml_loaded - require 'psych' - require_relative 'rubygems/psych_tree' - require_relative 'rubygems/safe_yaml' @yaml_loaded = true end @@ -741,9 +741,9 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} def self.prefix prefix = File.dirname RUBYGEMS_DIR - if prefix != File.expand_path(RbConfig::CONFIG['sitelibdir']) and - prefix != File.expand_path(RbConfig::CONFIG['libdir']) and - 'lib' == File.basename(RUBYGEMS_DIR) prefix end end @@ -759,11 +759,11 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # Safely read a file in binary mode on all platforms. def self.read_binary(path) - open_file(path, 'rb+') do |io| io.read end rescue Errno::EACCES, Errno::EROFS - open_file(path, 'rb') do |io| io.read end end @@ -771,7 +771,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} ## # Safely write a file in binary mode on all platforms. def self.write_binary(path, data) - open_file(path, 'wb') do |io| io.write data end end @@ -816,13 +816,13 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # Returns a String containing the API compatibility version of Ruby def self.ruby_api_version - @ruby_api_version ||= RbConfig::CONFIG['ruby_version'].dup end def self.env_requirement(gem_name) @env_requirements_by_name ||= {} @env_requirements_by_name[gem_name] ||= begin - req = ENV["GEM_REQUIREMENT_#{gem_name.upcase}"] || '>= 0'.freeze Gem::Requirement.create(req) end end @@ -845,7 +845,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # Returns the latest release version of RubyGems. def self.latest_rubygems_version - latest_version_for('rubygems-update') or raise "Can't find 'rubygems-update' in any repo. Check `gem source list`." end @@ -940,8 +940,8 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # Suffixes for require-able paths. def self.suffixes - @suffixes ||= ['', - '.rb', *%w[DLEXT DLEXT2].map do |key| val = RbConfig::CONFIG[key] next unless val and not val.empty? @@ -970,7 +970,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # Lazily loads DefaultUserInteraction and returns the default UI. def self.ui - require_relative 'rubygems/user_interaction' Gem::DefaultUserInteraction.ui end @@ -992,7 +992,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} def self.win_platform? if @@win_platform.nil? - ruby_platform = RbConfig::CONFIG['host_os'] @@win_platform = !!WIN_PATTERNS.find {|r| ruby_platform =~ r } end @@ -1071,7 +1071,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} def self.use_gemdeps(path = nil) raise_exception = path - path ||= ENV['RUBYGEMS_GEMDEPS'] return unless path path = path.dup @@ -1096,7 +1096,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end ENV["BUNDLE_GEMFILE"] ||= File.expand_path(path) - require_relative 'rubygems/user_interaction' require "bundler" begin Gem::DefaultUserInteraction.use_ui(ui) do @@ -1293,34 +1293,34 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/".freeze - autoload :BundlerVersionFinder, File.expand_path('rubygems/bundler_version_finder', __dir__) - autoload :ConfigFile, File.expand_path('rubygems/config_file', __dir__) - autoload :Dependency, File.expand_path('rubygems/dependency', __dir__) - autoload :DependencyList, File.expand_path('rubygems/dependency_list', __dir__) - autoload :Installer, File.expand_path('rubygems/installer', __dir__) - autoload :Licenses, File.expand_path('rubygems/util/licenses', __dir__) - autoload :NameTuple, File.expand_path('rubygems/name_tuple', __dir__) - autoload :PathSupport, File.expand_path('rubygems/path_support', __dir__) - autoload :RequestSet, File.expand_path('rubygems/request_set', __dir__) - autoload :Requirement, File.expand_path('rubygems/requirement', __dir__) - autoload :Resolver, File.expand_path('rubygems/resolver', __dir__) - autoload :Source, File.expand_path('rubygems/source', __dir__) - autoload :SourceList, File.expand_path('rubygems/source_list', __dir__) - autoload :SpecFetcher, File.expand_path('rubygems/spec_fetcher', __dir__) - autoload :SpecificationPolicy, File.expand_path('rubygems/specification_policy', __dir__) - autoload :Util, File.expand_path('rubygems/util', __dir__) - autoload :Version, File.expand_path('rubygems/version', __dir__) end -require_relative 'rubygems/exceptions' -require_relative 'rubygems/specification' # REFACTOR: This should be pulled out into some kind of hacks file. begin ## # Defaults the operating system (or packager) wants to provide for RubyGems. - require 'rubygems/defaults/operating_system' rescue LoadError # Ignored rescue StandardError => e @@ -1345,6 +1345,6 @@ end # Loads the default specs. Gem::Specification.load_defaults -require_relative 'rubygems/core_ext/kernel_gem' -require_relative 'rubygems/core_ext/kernel_require' -require_relative 'rubygems/core_ext/kernel_warn' @@ -47,7 +47,7 @@ class Gem::BasicSpecification # directory. def gem_build_complete_path # :nodoc: - File.join extension_dir, 'gem.build_complete' end ## @@ -103,7 +103,7 @@ class Gem::BasicSpecification def extensions_dir Gem.default_ext_dir_for(base_dir) || - File.join(base_dir, 'extensions', Gem::Platform.local.to_s, Gem.extension_api_version) end @@ -5,9 +5,9 @@ # See LICENSE.txt for permissions. #++ -require_relative 'optparse' -require_relative 'requirement' -require_relative 'user_interaction' ## # Base class for all Gem commands. When creating a new gem command, define @@ -76,7 +76,7 @@ class Gem::Command when Array @extra_args = value when String - @extra_args = value.split(' ') end end @@ -556,7 +556,7 @@ class Gem::Command def configure_options(header, option_list) return if option_list.nil? or option_list.empty? - header = header.to_s.empty? ? '' : "#{header} " @parser.separator " #{header}Options:" option_list.each do |args, handler| @@ -565,7 +565,7 @@ class Gem::Command end end - @parser.separator '' end ## @@ -578,13 +578,13 @@ class Gem::Command # ---------------------------------------------------------------- # Add the options common to all commands. - add_common_option('-h', '--help', - 'Get help on this command') do |value, options| options[:help] = true end - add_common_option('-V', '--[no-]verbose', - 'Set the verbose level of output') do |value, options| # Set us to "really verbose" so the progress meter works if Gem.configuration.verbose and value Gem.configuration.verbose = 1 @@ -593,7 +593,7 @@ class Gem::Command end end - add_common_option('-q', '--quiet', 'Silence command progress meter') do |value, options| Gem.configuration.verbose = false end @@ -606,20 +606,20 @@ class Gem::Command # commands. Both options are actually handled before the other # options get parsed. - add_common_option('--config-file FILE', - 'Use this config file instead of default') do end - add_common_option('--backtrace', - 'Show stack backtrace on errors') do end - add_common_option('--debug', - 'Turn on Ruby debugging') do end - add_common_option('--norc', - 'Avoid loading any .gemrc file') do end # :stopdoc: @@ -5,9 +5,9 @@ # See LICENSE.txt for permissions. #++ -require_relative 'command' -require_relative 'user_interaction' -require_relative 'text' ## # The command manager registers and installs all the individual sub-commands @@ -73,9 +73,9 @@ class Gem::CommandManager ].freeze ALIAS_COMMANDS = { - 'i' => 'install', - 'login' => 'signin', - 'logout' => 'signout', }.freeze ## @@ -104,7 +104,7 @@ class Gem::CommandManager # Register all the subcommands supported by the gem command. def initialize - require 'timeout' @commands = {} BUILTIN_COMMANDS.each do |name| @@ -169,10 +169,10 @@ class Gem::CommandManager end case args.first - when '-h', '--help' then say Gem::Command::HELP terminate_interaction 0 - when '-v', '--version' then say Gem::VERSION terminate_interaction 0 when /^-/ then @@ -1,29 +1,29 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../package' -require_relative '../version_option' class Gem::Commands::BuildCommand < Gem::Command include Gem::VersionOption def initialize - super 'build', 'Build a gem from a gemspec' add_platform_option - add_option '--force', 'skip validation of the spec' do |value, options| options[:force] = true end - add_option '--strict', 'consider warnings as errors when validating the spec' do |value, options| options[:strict] = true end - add_option '-o', '--output FILE', 'output gem with the given filename' do |value, options| options[:output] = value end - add_option '-C PATH', 'Run as if gem build was started in <PATH> instead of the current working directory.' do |value, options| options[:build_path] = value end end @@ -1,69 +1,69 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../security' class Gem::Commands::CertCommand < Gem::Command def initialize - super 'cert', 'Manage RubyGems certificates and signing settings', :add => [], :remove => [], :list => [], :build => [], :sign => [] - add_option('-a', '--add CERT', - 'Add a trusted certificate.') do |cert_file, options| options[:add] << open_cert(cert_file) end - add_option('-l', '--list [FILTER]', - 'List trusted certificates where the', - 'subject contains FILTER') do |filter, options| - filter ||= '' options[:list] << filter end - add_option('-r', '--remove FILTER', - 'Remove trusted certificates where the', - 'subject contains FILTER') do |filter, options| options[:remove] << filter end - add_option('-b', '--build EMAIL_ADDR', - 'Build private key and self-signed', - 'certificate for EMAIL_ADDR') do |email_address, options| options[:build] << email_address end - add_option('-C', '--certificate CERT', - 'Signing certificate for --sign') do |cert_file, options| options[:issuer_cert] = open_cert(cert_file) options[:issuer_cert_file] = cert_file end - add_option('-K', '--private-key KEY', - 'Key for --sign or --build') do |key_file, options| options[:key] = open_private_key(key_file) end - add_option('-A', '--key-algorithm ALGORITHM', - 'Select which key algorithm to use for --build') do |algorithm, options| options[:key_algorithm] = algorithm end - add_option('-s', '--sign CERT', - 'Signs CERT with the key from -K', - 'and the certificate from -C') do |cert_file, options| raise Gem::OptionParser::InvalidArgument, "#{cert_file}: does not exist" unless File.file? cert_file options[:sign] << cert_file end - add_option('-d', '--days NUMBER_OF_DAYS', - 'Days before the certificate expires') do |days, options| options[:expiration_length_days] = days.to_i end - add_option('-R', '--re-sign', - 'Re-signs the certificate from -C with the key from -K') do |resign, options| options[:resign] = resign end end @@ -93,7 +93,7 @@ class Gem::Commands::CertCommand < Gem::Command def open_private_key(key_file) check_openssl - passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE'] key = OpenSSL::PKey.read File.read(key_file), passphrase raise Gem::OptionParser::InvalidArgument, "#{key_file}: private key not found" unless key.private? @@ -166,10 +166,10 @@ class Gem::Commands::CertCommand < Gem::Command def build_key # :nodoc: return options[:key] if options[:key] - passphrase = ask_for_password 'Passphrase for your Private Key:' say "\n" - passphrase_confirmation = ask_for_password 'Please repeat the passphrase for your Private Key:' say "\n" raise Gem::CommandLineError, @@ -260,7 +260,7 @@ 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 - passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE'] options[:key] = OpenSSL::PKey.read key, passphrase rescue Errno::ENOENT @@ -1,44 +1,44 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../version_option' -require_relative '../validator' -require_relative '../doctor' class Gem::Commands::CheckCommand < Gem::Command include Gem::VersionOption def initialize - super 'check', 'Check a gem repository for added or missing files', :alien => true, :doctor => false, :dry_run => false, :gems => true - add_option('-a', '--[no-]alien', 'Report "unmanaged" or rogue files in the', - 'gem repository') do |value, options| options[:alien] = value end - add_option('--[no-]doctor', - 'Clean up uninstalled gems and broken', - 'specifications') do |value, options| options[:doctor] = value end - add_option('--[no-]dry-run', - 'Do not remove files, only report what', - 'would be removed') do |value, options| options[:dry_run] = value end - add_option('--[no-]gems', - 'Check installed gems for problems') do |value, options| options[:gems] = value end - add_version_option 'check' end def check_gems - say 'Checking gems...' say gems = get_all_gem_names rescue [] @@ -57,7 +57,7 @@ class Gem::Commands::CheckCommand < Gem::Command end def doctor - say 'Checking for files from uninstalled gems...' say Gem.path.each do |gem_repo| @@ -72,11 +72,11 @@ class Gem::Commands::CheckCommand < Gem::Command end def arguments # :nodoc: - 'GEMNAME name of gem to check' end def defaults_str # :nodoc: - '--gems --alien' end def description # :nodoc: @@ -1,35 +1,35 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../dependency_list' -require_relative '../uninstaller' class Gem::Commands::CleanupCommand < Gem::Command def initialize - super 'cleanup', - 'Clean up old versions of installed gems', :force => false, :install_dir => Gem.dir, :check_dev => true - add_option('-n', '-d', '--dry-run', - 'Do not uninstall gems') do |value, options| options[:dryrun] = true end - add_option(:Deprecated, '--dryrun', - 'Do not uninstall gems') do |value, options| options[:dryrun] = true end - deprecate_option('--dryrun', extra_msg: 'Use --dry-run instead') - add_option('-D', '--[no-]check-development', - 'Check development dependencies while uninstalling', - '(default: true)') do |value, options| options[:check_dev] = value end - add_option('--[no-]user-install', - 'Cleanup in user\'s home directory instead', - 'of GEM_HOME.') do |value, options| options[:user_install] = value end @@ -1,39 +1,39 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../version_option' class Gem::Commands::ContentsCommand < Gem::Command include Gem::VersionOption def initialize - super 'contents', 'Display the contents of the installed gems', :specdirs => [], :lib_only => false, :prefix => true, :show_install_dir => false add_version_option - add_option('--all', "Contents for all gems") do |all, options| options[:all] = all end - add_option('-s', '--spec-dir a,b,c', Array, "Search for gems under specific paths") do |spec_dirs, options| options[:specdirs] = spec_dirs end - add_option('-l', '--[no-]lib-only', "Only return files in the Gem's lib_dirs") do |lib_only, options| options[:lib_only] = lib_only end - add_option('--[no-]prefix', "Don't include installed path prefix") do |prefix, options| options[:prefix] = prefix end - add_option('--[no-]show-install-dir', - 'Show only the gem install dir') do |show, options| options[:show_install_dir] = show end @@ -105,11 +105,11 @@ prefix or only the files that are requireable. case file when /\A#{spec.bindir}\// # $' is POSTMATCH - [RbConfig::CONFIG['bindir'], $'] when /\.so\z/ - [RbConfig::CONFIG['archdir'], file] else - [RbConfig::CONFIG['rubylibdir'], file] end end end @@ -1,28 +1,28 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../local_remote_options' -require_relative '../version_option' class Gem::Commands::DependencyCommand < Gem::Command include Gem::LocalRemoteOptions include Gem::VersionOption def initialize - super 'dependency', - 'Show the dependencies of an installed gem', :version => Gem::Requirement.default, :domain => :local add_version_option add_platform_option add_prerelease_option - add_option('-R', '--[no-]reverse-dependencies', - 'Include reverse dependencies in the output') do |value, options| options[:reverse_dependencies] = value end - add_option('-p', '--pipe', "Pipe Format (name --version ver)") do |value, options| options[:pipe_format] = value end @@ -134,7 +134,7 @@ use with other commands. def ensure_local_only_reverse_dependencies # :nodoc: if options[:reverse_dependencies] and remote? and not local? - alert_error 'Only reverse dependencies for local gems are supported.' terminate_interaction 1 end end @@ -142,7 +142,7 @@ use with other commands. def ensure_specs(specs) # :nodoc: return unless specs.empty? - patterns = options[:args].join ',' say "No gems found matching #{patterns} (#{options[:version]})" if Gem.configuration.verbose @@ -151,10 +151,10 @@ use with other commands. def print_dependencies(spec, level = 0) # :nodoc: response = String.new - response << ' ' * level + "Gem #{spec.full_name}\n" unless spec.dependencies.empty? spec.dependencies.sort_by {|dep| dep.name }.each do |dep| - response << ' ' * level + " #{dep}\n" end end response @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative '../command' class Gem::Commands::EnvironmentCommand < Gem::Command def initialize - super 'environment', 'Display information about the RubyGems environment' end def arguments # :nodoc: @@ -16,7 +16,7 @@ class Gem::Commands::EnvironmentCommand < Gem::Command platform display the supported gem platforms <omitted> display everything EOF - return args.gsub(/^\s+/, '') end def description # :nodoc: @@ -141,7 +141,7 @@ lib/rubygems/defaults/operating_system.rb out << " - GEM CONFIGURATION:\n" Gem.configuration.each do |name, value| - value = value.gsub(/./, '*') if name == 'gemcutter_key' out << " - #{name.inspect} => #{value.inspect}\n" end @@ -152,7 +152,7 @@ lib/rubygems/defaults/operating_system.rb out << " - SHELL PATH:\n" - shell_path = ENV['PATH'].split(File::PATH_SEPARATOR) add_path out, shell_path out @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../local_remote_options' -require_relative '../version_option' class Gem::Commands::FetchCommand < Gem::Command include Gem::LocalRemoteOptions @@ -13,7 +13,7 @@ class Gem::Commands::FetchCommand < Gem::Command :version => Gem::Requirement.default, } - super 'fetch', 'Download a gem and place it in the current directory', defaults add_bulk_threshold_option add_proxy_option @@ -24,13 +24,13 @@ class Gem::Commands::FetchCommand < Gem::Command add_platform_option add_prerelease_option - add_option '--[no-]suggestions', 'Suggest alternates when gems are not found' do |value, options| options[:suggest_alternate] = value end end def arguments # :nodoc: - 'GEMNAME name of gem to download' end def defaults_str # :nodoc: @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../indexer' ## # Generates a index files for use as a gem server. @@ -9,27 +9,27 @@ require_relative '../indexer' class Gem::Commands::GenerateIndexCommand < Gem::Command def initialize - super 'generate_index', - 'Generates the index files for a gem server directory', - :directory => '.', :build_modern => true - add_option '-d', '--directory=DIRNAME', - 'repository base dir containing gems subdir' do |dir, options| options[:directory] = File.expand_path dir end - add_option '--[no-]modern', - 'Generate indexes for RubyGems', - '(always true)' do |value, options| options[:build_modern] = value end - deprecate_option('--modern', version: '4.0', extra_msg: 'Modern indexes (specs, latest_specs, and prerelease_specs) are always generated, so this option is not needed.') - deprecate_option('--no-modern', version: '4.0', extra_msg: 'The `--no-modern` option is currently ignored. Modern indexes (specs, latest_specs, and prerelease_specs) are always generated.') - add_option '--update', - 'Update modern indexes with gems added', - 'since the last update' do |value, options| options[:update] = value end end @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative '../command' class Gem::Commands::HelpCommand < Gem::Command # :stopdoc: @@ -280,7 +280,7 @@ platform. # :startdoc: def initialize - super 'help', "Provide help on the 'gem' command" @command_manager = Gem::CommandManager.instance end @@ -326,7 +326,7 @@ platform. 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| @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../query_utils' class Gem::Commands::InfoCommand < Gem::Command include Gem::QueryUtils @@ -13,7 +13,7 @@ class Gem::Commands::InfoCommand < Gem::Command add_query_options - remove_option('-d') defaults[:details] = true defaults[:exact] = true @@ -1,10 +1,10 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../install_update_options' -require_relative '../dependency_installer' -require_relative '../local_remote_options' -require_relative '../validator' -require_relative '../version_option' ## # Gem installer command line tool @@ -29,7 +29,7 @@ class Gem::Commands::InstallCommand < Gem::Command defaults.merge!(install_update_options) - super 'install', 'Install a gem into the local repository', defaults add_install_update_options add_local_remote_options @@ -157,7 +157,7 @@ You can use `i` command instead of `install`. @installed_specs = [] - ENV.delete 'GEM_PATH' if options[:install_dir].nil? check_install_dir check_version @@ -172,7 +172,7 @@ You can use `i` command instead of `install`. end def install_from_gemdeps # :nodoc: - require_relative '../request_set' rs = Gem::RequestSet.new specs = rs.install_from_gemdeps options do |req, inst| @@ -247,11 +247,11 @@ You can use `i` command instead of `install`. def load_hooks # :nodoc: if options[:install_as_default] - require_relative '../install_default_message' else - require_relative '../install_message' end - require_relative '../rdoc' end def show_install_errors(errors) # :nodoc: @@ -270,7 +270,7 @@ You can use `i` command instead of `install`. def show_installed # :nodoc: return if @installed_specs.empty? - gems = @installed_specs.length == 1 ? 'gem' : 'gems' say "#{@installed_specs.length} #{gems} installed" end end @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../query_utils' ## # Searches for gems starting with the supplied argument. @@ -9,7 +9,7 @@ class Gem::Commands::ListCommand < Gem::Command include Gem::QueryUtils def initialize - super 'list', 'Display local gems whose name matches REGEXP', :domain => :local, :details => false, :versions => true, :installed => nil, :version => Gem::Requirement.default @@ -1,13 +1,13 @@ # frozen_string_literal: true -require_relative '../command' class Gem::Commands::LockCommand < Gem::Command def initialize - super 'lock', 'Generate a lockdown list of gems', :strict => false - add_option '-s', '--[no-]strict', - 'fail if unable to satisfy a dependency' do |strict, options| options[:strict] = strict end end @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative '../command' unless defined? Gem::Commands::MirrorCommand class Gem::Commands::MirrorCommand < Gem::Command def initialize - super('mirror', 'Mirror all gem files (requires rubygems-mirror)') begin - Gem::Specification.find_by_name('rubygems-mirror').activate rescue Gem::LoadError # no-op end @@ -1,18 +1,18 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../version_option' class Gem::Commands::OpenCommand < Gem::Command include Gem::VersionOption def initialize - super 'open', 'Open gem sources in editor' - add_option('-e', '--editor COMMAND', String, "Prepends COMMAND to gem path. Could be used to specify editor.") do |command, options| options[:editor] = command || get_env_editor end - add_option('-v', '--version VERSION', String, "Opens specific gem version") do |version| options[:version] = version end @@ -40,10 +40,10 @@ class Gem::Commands::OpenCommand < Gem::Command end def get_env_editor - ENV['GEM_EDITOR'] || - ENV['VISUAL'] || - ENV['EDITOR'] || - 'vi' end def execute @@ -1,15 +1,15 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../local_remote_options' -require_relative '../spec_fetcher' -require_relative '../version_option' class Gem::Commands::OutdatedCommand < Gem::Command include Gem::LocalRemoteOptions include Gem::VersionOption def initialize - super 'outdated', 'Display all gems that need updates' add_local_remote_options add_platform_option @@ -1,8 +1,8 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../local_remote_options' -require_relative '../gemcutter_utilities' -require_relative '../text' class Gem::Commands::OwnerCommand < Gem::Command include Gem::Text @@ -34,23 +34,23 @@ permission to. end def initialize - super 'owner', 'Manage gem owners of a gem on the push server' add_proxy_option add_key_option add_otp_option defaults.merge! :add => [], :remove => [] - add_option '-a', '--add NEW_OWNER', 'Add an owner by user identifier' do |value, options| options[:add] << value end - add_option '-r', '--remove OLD_OWNER', 'Remove an owner by user identifier' do |value, options| options[:remove] << value end - add_option '-h', '--host HOST', - 'Use another gemcutter-compatible host', - ' (e.g. https://rubygems.org)' do |value, options| options[:host] = value end end @@ -108,7 +108,7 @@ permission to. def send_owner_request(method, name, owner) rubygems_api_request method, "api/v1/gems/#{name}/owners", scope: get_owner_scope(method: method) do |request| - request.set_form_data 'email' => owner request.add_field "Authorization", api_key end end @@ -1,67 +1,67 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../package' -require_relative '../installer' -require_relative '../version_option' class Gem::Commands::PristineCommand < Gem::Command include Gem::VersionOption def initialize - super 'pristine', - 'Restores installed gems to pristine condition from files located in the gem cache', :version => Gem::Requirement.default, :extensions => true, :extensions_set => false, :all => false - add_option('--all', - 'Restore all installed gems to pristine', - 'condition') do |value, options| options[:all] = value end - add_option('--skip=gem_name', - 'used on --all, skip if name == gem_name') do |value, options| options[:skip] ||= [] options[:skip] << value end - add_option('--[no-]extensions', - 'Restore gems with extensions', - 'in addition to regular gems') do |value, options| options[:extensions_set] = true options[:extensions] = value end - add_option('--only-executables', - 'Only restore executables') do |value, options| 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| options[:env_shebang] = value end - add_option('-i', '--install-dir DIR', - 'Gem repository to get binstubs and plugins installed') do |value, options| options[:install_dir] = File.expand_path(value) end - add_option('-n', '--bindir DIR', - 'Directory where executables are', - 'located') do |value, options| options[:bin_dir] = File.expand_path(value) end - add_version_option('restore to', 'pristine condition') end def arguments # :nodoc: @@ -69,7 +69,7 @@ class Gem::Commands::PristineCommand < Gem::Command end def defaults_str # :nodoc: - '--extensions' end def description # :nodoc: @@ -143,7 +143,7 @@ extensions will be restored. gem = spec.cache_file unless File.exist? gem or options[:only_executables] or options[:only_plugins] - require_relative '../remote_fetcher' say "Cached gem for #{spec.full_name} not found, attempting to fetch..." @@ -163,8 +163,8 @@ extensions will be restored. if options.include? :env_shebang options[:env_shebang] else - install_defaults = Gem::ConfigFile::PLATFORM_DEFAULTS['install'] - install_defaults.to_s['--env-shebang'] end bin_dir = options[:bin_dir] if options[:bin_dir] @@ -1,8 +1,8 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../local_remote_options' -require_relative '../gemcutter_utilities' -require_relative '../package' class Gem::Commands::PushCommand < Gem::Command include Gem::LocalRemoteOptions @@ -29,7 +29,7 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo end def initialize - super 'push', 'Push a gem up to the gem server', :host => self.host @user_defined_host = false @@ -37,9 +37,9 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo add_key_option add_otp_option - add_option('--host HOST', - 'Push to another gemcutter-compatible host', - ' (e.g. https://rubygems.org)') do |value, options| options[:host] = value @user_defined_host = true end @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../query_utils' -require_relative '../deprecate' class Gem::Commands::QueryCommand < Gem::Command extend Gem::Deprecate @@ -17,15 +17,15 @@ class Gem::Commands::QueryCommand < Gem::Command alert_warning message unless Gem::Deprecate.skip end - def initialize(name = 'query', - summary = 'Query gem information in local or remote repositories') super name, summary, :domain => :local, :details => false, :versions => true, :installed => nil, :version => Gem::Requirement.default - add_option('-n', '--name-matches REGEXP', - 'Name of gem(s) to query on matches the', - 'provided REGEXP') do |value, options| options[:name] = /#{value}/i end @@ -1,35 +1,35 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../version_option' -require_relative '../rdoc' -require 'fileutils' class Gem::Commands::RdocCommand < Gem::Command include Gem::VersionOption def initialize - super 'rdoc', 'Generates RDoc for pre-installed gems', :version => Gem::Requirement.default, :include_rdoc => false, :include_ri => true, :overwrite => false - add_option('--all', - 'Generate RDoc/RI documentation for all', - 'installed gems') do |value, options| options[:all] = value end - add_option('--[no-]rdoc', - 'Generate RDoc HTML') do |value, options| options[:include_rdoc] = value end - add_option('--[no-]ri', - 'Generate RI data') do |value, options| options[:include_ri] = value end - add_option('--[no-]overwrite', - 'Overwrite installed documents') do |value, options| options[:overwrite] = value end @@ -69,7 +69,7 @@ Use --overwrite to force rebuilding of documentation. end if specs.empty? - alert_error 'No matching gems found' terminate_interaction 1 end @@ -79,8 +79,8 @@ Use --overwrite to force rebuilding of documentation. doc.force = options[:overwrite] if options[:overwrite] - FileUtils.rm_rf File.join(spec.doc_dir, 'ri') - FileUtils.rm_rf File.join(spec.doc_dir, 'rdoc') end begin @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../query_utils' class Gem::Commands::SearchCommand < Gem::Command include Gem::QueryUtils def initialize - super 'search', 'Display remote gems whose name matches REGEXP', :domain => :remote, :details => false, :versions => true, :installed => nil, :version => Gem::Requirement.default @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative '../command' unless defined? Gem::Commands::ServerCommand class Gem::Commands::ServerCommand < Gem::Command def initialize - super('server', 'Starts up a web server that hosts the RDoc (requires rubygems-server)') begin - Gem::Specification.find_by_name('rubygems-server').activate rescue Gem::LoadError # no-op end @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative '../command' ## # Installs RubyGems itself. This command is ordinarily only available from a @@ -12,47 +12,47 @@ class Gem::Commands::SetupCommand < Gem::Command ENV_PATHS = %w[/usr/bin/env /bin/env].freeze def initialize - super 'setup', 'Install RubyGems', :format_executable => false, :document => %w[ri], :force => true, - :site_or_vendor => 'sitelibdir', - :destdir => '', :prefix => '', :previous_version => '', :regenerate_binstubs => true, :regenerate_plugins => true - add_option '--previous-version=VERSION', - 'Previous version of RubyGems', - 'Used for changelog processing' do |version, options| options[:previous_version] = version end - add_option '--prefix=PREFIX', - 'Prefix path for installing RubyGems', - 'Will not affect gem repository location' do |prefix, options| options[:prefix] = File.expand_path prefix end - add_option '--destdir=DESTDIR', - 'Root directory to install RubyGems into', - 'Mainly used for packaging RubyGems' do |destdir, options| options[:destdir] = File.expand_path destdir end - add_option '--[no-]vendor', - 'Install into vendorlibdir not sitelibdir' do |vendor, options| - options[:site_or_vendor] = vendor ? 'vendorlibdir' : 'sitelibdir' end - add_option '--[no-]format-executable', - 'Makes `gem` match ruby', - 'If Ruby is ruby18, gem will be gem18' do |value, options| options[:format_executable] = value end - add_option '--[no-]document [TYPES]', Array, - 'Generate documentation for RubyGems', - 'List the documentation types you wish to', - 'generate. For example: rdoc,ri' do |value, options| options[:document] = case value when nil then %w[rdoc ri] when false then [] @@ -60,46 +60,46 @@ class Gem::Commands::SetupCommand < Gem::Command end end - add_option '--[no-]rdoc', - 'Generate RDoc documentation for RubyGems' do |value, options| if value - options[:document] << 'rdoc' else - options[:document].delete 'rdoc' end options[:document].uniq! end - add_option '--[no-]ri', - 'Generate RI documentation for RubyGems' do |value, options| if value - options[:document] << 'ri' else - options[:document].delete 'ri' end options[:document].uniq! end - add_option '--[no-]regenerate-binstubs', - 'Regenerate gem binstubs' do |value, options| 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 end - add_option('-E', '--[no-]env-shebang', - 'Rewrite executables with a shebang', - 'of /usr/bin/env') do |value, options| options[:env_shebang] = value end @@ -107,7 +107,7 @@ class Gem::Commands::SetupCommand < Gem::Command end def check_ruby_version - required_version = Gem::Requirement.new '>= 2.3.0' unless required_version.satisfied_by? Gem.ruby_version alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}" @@ -149,7 +149,7 @@ By default, this RubyGems will install gem as: check_ruby_version - require 'fileutils' if Gem.configuration.really_verbose extend FileUtils::Verbose else @@ -194,7 +194,7 @@ By default, this RubyGems will install gem as: end if options[:previous_version].empty? - options[:previous_version] = Gem::VERSION.sub(/[0-9]+$/, '0') end options[:previous_version] = Gem::Version.new(options[:previous_version]) @@ -216,7 +216,7 @@ By default, this RubyGems will install gem as: end if documentation_success - if options[:document].include? 'rdoc' say "Rdoc documentation was installed. You may now invoke:" say " gem server" say "and then peruse beautifully formatted documentation for your gems" @@ -227,7 +227,7 @@ By default, this RubyGems will install gem as: say end - if options[:document].include? 'ri' say "Ruby Interactive (ri) documentation was installed. ri is kind of like man " say "pages for Ruby libraries. You may access it like this:" say " ri Classname" @@ -244,14 +244,14 @@ By default, this RubyGems will install gem as: def install_executables(bin_dir) prog_mode = options[:prog_mode] || 0755 - executables = { 'gem' => 'bin' } executables.each do |tool, path| say "Installing #{tool} executable" if @verbose Dir.chdir path do bin_file = "gem" - require 'tmpdir' dest_file = target_bin_path(bin_dir, bin_file) bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}" @@ -260,7 +260,7 @@ By default, this RubyGems will install gem as: bin = File.readlines bin_file bin[0] = shebang - File.open bin_tmp_file, 'w' do |fp| fp.puts bin.join end @@ -275,7 +275,7 @@ By default, this RubyGems will install gem as: begin bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat" - File.open bin_cmd_file, 'w' do |file| file.puts <<-TEXT @ECHO OFF IF NOT "%~f0" == "~f0" GOTO :WinNT @@ -296,7 +296,7 @@ By default, this RubyGems will install gem as: def shebang if options[:env_shebang] - ruby_name = RbConfig::CONFIG['ruby_install_name'] @env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path } "#!#{@env_path} #{ruby_name}\n" else @@ -305,8 +305,8 @@ By default, this RubyGems will install gem as: end def install_lib(lib_dir) - libs = { 'RubyGems' => 'lib' } - libs['Bundler'] = 'bundler/lib' libs.each do |tool, path| say "Installing #{tool}" if @verbose @@ -319,7 +319,7 @@ By default, this RubyGems will install gem as: end def install_rdoc - gem_doc_dir = File.join Gem.dir, 'doc' rubygems_name = "rubygems-#{Gem::VERSION}" rubygems_doc_dir = File.join gem_doc_dir, rubygems_name @@ -333,19 +333,19 @@ By default, this RubyGems will install gem as: (not File.exist? rubygems_doc_dir or File.writable? rubygems_doc_dir) say "Removing old RubyGems RDoc and ri" if @verbose - Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir| rm_rf dir end - require_relative '../rdoc' - fake_spec = Gem::Specification.new 'rubygems', Gem::VERSION def fake_spec.full_gem_path - File.expand_path '../../..', __dir__ end - generate_ri = options[:document].include? 'ri' - generate_rdoc = options[:document].include? 'rdoc' rdoc = Gem::RDoc.new fake_spec, generate_rdoc, generate_ri rdoc.generate @@ -397,7 +397,7 @@ By default, this RubyGems will install gem as: cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e) end - require_relative '../installer' Dir.chdir("bundler") do built_gem = Gem::Package.build(bundler_spec) @@ -439,10 +439,10 @@ By default, this RubyGems will install gem as: prefix = options[:prefix] if prefix.empty? - man_dir = RbConfig::CONFIG['mandir'] return unless man_dir else - man_dir = File.join prefix, 'man' end prepend_destdir_if_present(man_dir) @@ -454,10 +454,10 @@ By default, this RubyGems will install gem as: if prefix.empty? lib_dir = RbConfig::CONFIG[site_or_vendor] - bin_dir = RbConfig::CONFIG['bindir'] else - lib_dir = File.join prefix, 'lib' - bin_dir = File.join prefix, 'bin' end [prepend_destdir_if_present(lib_dir), prepend_destdir_if_present(bin_dir)] @@ -465,19 +465,19 @@ By default, this RubyGems will install gem as: def files_in(dir) Dir.chdir dir do - Dir.glob(File.join('**', '*'), File::FNM_DOTMATCH). select {|f| !File.directory?(f) } end end def remove_old_bin_files(bin_dir) old_bin_files = { - 'gem_mirror' => 'gem mirror', - 'gem_server' => 'gem server', - 'gemlock' => 'gem lock', - 'gemri' => 'ri', - 'gemwhich' => 'gem which', - 'index_gem_repository.rb' => 'gem generate_index', } old_bin_files.each do |old_bin_file, new_name| @@ -486,7 +486,7 @@ By default, this RubyGems will install gem as: deprecation_message = "`#{old_bin_file}` has been deprecated. Use `#{new_name}` instead." - File.open old_bin_path, 'w' do |fp| fp.write <<-EOF #!#{Gem.ruby} @@ -496,15 +496,15 @@ abort "#{deprecation_message}" next unless Gem.win_platform? - File.open "#{old_bin_path}.bat", 'w' do |fp| fp.puts %(@ECHO.#{deprecation_message}) end end end def remove_old_lib_files(lib_dir) - lib_dirs = { File.join(lib_dir, 'rubygems') => 'lib/rubygems' } - lib_dirs[File.join(lib_dir, 'bundler')] = 'bundler/lib/bundler' lib_dirs.each do |old_lib_dir, new_lib_dir| lib_files = files_in(new_lib_dir) @@ -512,11 +512,11 @@ abort "#{deprecation_message}" to_remove = old_lib_files - lib_files - gauntlet_rubygems = File.join(lib_dir, 'gauntlet_rubygems.rb') to_remove << gauntlet_rubygems if File.exist? gauntlet_rubygems to_remove.delete_if do |file| - file.start_with? 'defaults' end remove_file_list(to_remove, old_lib_dir) @@ -542,7 +542,7 @@ abort "#{deprecation_message}" end def show_release_notes - release_notes = File.join Dir.pwd, 'CHANGELOG.md' release_notes = if File.exist? release_notes @@ -573,10 +573,10 @@ abort "#{deprecation_message}" end def uninstall_old_gemcutter - require_relative '../uninstaller' - ui = Gem::Uninstaller.new('gemcutter', :all => true, :ignore => true, - :version => '< 0.4') ui.uninstall rescue Gem::InstallError end @@ -625,7 +625,7 @@ abort "#{deprecation_message}" destdir = options[:destdir] return path if destdir.empty? - File.join(options[:destdir], path.gsub(/^[a-zA-Z]:/, '')) end def install_file_list(files, dest_dir) @@ -1,15 +1,15 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../gemcutter_utilities' class Gem::Commands::SigninCommand < Gem::Command include Gem::GemcutterUtilities def initialize - super 'signin', 'Sign in to any gemcutter-compatible host. '\ - 'It defaults to https://rubygems.org' - add_option('--host HOST', 'Push to another gemcutter-compatible host') do |value, options| options[:host] = value end @@ -17,10 +17,10 @@ class Gem::Commands::SigninCommand < Gem::Command end def description # :nodoc: - 'The signin command executes host sign in for a push server (the default is'\ - ' https://rubygems.org). The host can be provided with the host flag or can'\ - ' be inferred from the provided gem. Host resolution matches the resolution'\ - ' strategy for the push command.' end def usage # :nodoc: @@ -1,14 +1,14 @@ # frozen_string_literal: true -require_relative '../command' class Gem::Commands::SignoutCommand < Gem::Command def initialize - super 'signout', 'Sign out from all the current sessions.' end def description # :nodoc: - 'The `signout` command is used to sign out from all current sessions,'\ - ' allowing you to sign in using a different set of credentials.' end def usage # :nodoc: @@ -19,13 +19,13 @@ class Gem::Commands::SignoutCommand < Gem::Command credentials_path = Gem.configuration.credentials_path if !File.exist?(credentials_path) - alert_error 'You are not currently signed in.' elsif !File.writable?(credentials_path) alert_error "File '#{Gem.configuration.credentials_path}' is read-only."\ - ' Please make sure it is writable.' else Gem.configuration.unset_api_key! - say 'You have successfully signed out from all sessions.' end end end @@ -1,40 +1,40 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../remote_fetcher' -require_relative '../spec_fetcher' -require_relative '../local_remote_options' class Gem::Commands::SourcesCommand < Gem::Command include Gem::LocalRemoteOptions def initialize - require 'fileutils' - super 'sources', - 'Manage the sources and cache file RubyGems uses to search for gems' - add_option '-a', '--add SOURCE_URI', 'Add source' do |value, options| options[:add] = value end - add_option '-l', '--list', 'List sources' do |value, options| options[:list] = value end - add_option '-r', '--remove SOURCE_URI', 'Remove source' do |value, options| options[:remove] = value end - add_option '-c', '--clear-all', - 'Remove all sources (clear the cache)' do |value, options| options[:clear_all] = value end - add_option '-u', '--update', 'Update source cache' do |value, options| options[:update] = value end - add_option '-f', '--[no-]force', "Do not show any confirmation prompts and behave as if 'yes' was always answered" do |value, options| options[:force] = value end @@ -82,8 +82,8 @@ Do you want to add this source? def check_rubygems_https(source_uri) # :nodoc: uri = URI source_uri - if uri.scheme and uri.scheme.downcase == 'http' and - uri.host.downcase == 'rubygems.org' question = <<-QUESTION.chomp https://rubygems.org is recommended for security over #{uri} @@ -112,7 +112,7 @@ Do you want to add this insecure source? end def defaults_str # :nodoc: - '--list' end def description # :nodoc: @@ -1,8 +1,8 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../local_remote_options' -require_relative '../version_option' -require_relative '../package' class Gem::Commands::SpecificationCommand < Gem::Command include Gem::LocalRemoteOptions @@ -11,28 +11,28 @@ class Gem::Commands::SpecificationCommand < Gem::Command def initialize Gem.load_yaml - super 'specification', 'Display gem specification (in yaml)', :domain => :local, :version => Gem::Requirement.default, :format => :yaml - add_version_option('examine') add_platform_option add_prerelease_option - add_option('--all', 'Output specifications for all versions of', - 'the gem') do |value, options| options[:all] = true end - add_option('--ruby', 'Output ruby format') do |value, options| options[:format] = :ruby end - add_option('--yaml', 'Output YAML format') do |value, options| options[:format] = :yaml end - add_option('--marshal', 'Output Marshal format') do |value, options| options[:format] = :marshal end @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative '../command' class Gem::Commands::StaleCommand < Gem::Command def initialize - super('stale', 'List gems along with access times') end def description # :nodoc: @@ -1,8 +1,8 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../version_option' -require_relative '../uninstaller' -require 'fileutils' ## # Gem uninstaller command line tool @@ -13,78 +13,78 @@ class Gem::Commands::UninstallCommand < Gem::Command include Gem::VersionOption def initialize - super 'uninstall', 'Uninstall gems from the local repository', :version => Gem::Requirement.default, :user_install => true, :check_dev => false, :vendor => false - add_option('-a', '--[no-]all', - 'Uninstall all matching versions' ) do |value, options| options[:all] = value end - add_option('-I', '--[no-]ignore-dependencies', - 'Ignore dependency requirements while', - 'uninstalling') do |value, options| options[:ignore] = value end - add_option('-D', '--[no-]check-development', - 'Check development dependencies while uninstalling', - '(default: false)') do |value, options| options[:check_dev] = value end - add_option('-x', '--[no-]executables', - 'Uninstall applicable executables without', - 'confirmation') do |value, options| options[:executables] = value end - add_option('-i', '--install-dir DIR', - 'Directory to uninstall gem from') do |value, options| options[:install_dir] = File.expand_path(value) end - add_option('-n', '--bindir DIR', - 'Directory to remove executables from') do |value, options| options[:bin_dir] = File.expand_path(value) end - add_option('--[no-]user-install', - 'Uninstall from user\'s home directory', - 'in addition to GEM_HOME.') do |value, options| options[:user_install] = value end - add_option('--[no-]format-executable', - 'Assume executable names match Ruby\'s prefix and suffix.') do |value, options| options[:format_executable] = value end - add_option('--[no-]force', - 'Uninstall all versions of the named gems', - 'ignoring dependencies') do |value, options| options[:force] = value end - add_option('--[no-]abort-on-dependent', - 'Prevent uninstalling gems that are', - 'depended on by other gems.') do |value, options| options[:abort_on_dependent] = value end add_version_option add_platform_option - add_option('--vendor', - 'Uninstall gem from the vendor directory.', - 'Only for use by gem repackagers.') do |value, options| unless Gem.vendor_dir - raise Gem::OptionParser::InvalidOption.new 'your platform is not supported' end - alert_warning 'Use your OS package manager to uninstall vendor gems' options[:vendor] = true options[:install_dir] = Gem.vendor_dir end @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../version_option' -require_relative '../security_option' -require_relative '../remote_fetcher' -require_relative '../package' # forward-declare @@ -17,18 +17,18 @@ class Gem::Commands::UnpackCommand < Gem::Command include Gem::SecurityOption def initialize - require 'fileutils' - super 'unpack', 'Unpack an installed gem to the current directory', :version => Gem::Requirement.default, :target => Dir.pwd - add_option('--target=DIR', - 'target directory for unpacking') do |value, options| options[:target] = value end - add_option('--spec', 'unpack the gem specification') do |value, options| options[:spec] = true end @@ -103,11 +103,11 @@ command help for an example. end end - File.open destination, 'w' do |io| io.write metadata end else - basename = File.basename path, '.gem' target_dir = File.expand_path basename, options[:target] package = Gem::Package.new path, security_policy @@ -1,13 +1,13 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../command_manager' -require_relative '../dependency_installer' -require_relative '../install_update_options' -require_relative '../local_remote_options' -require_relative '../spec_fetcher' -require_relative '../version_option' -require_relative '../install_message' # must come before rdoc for messaging -require_relative '../rdoc' class Gem::Commands::UpdateCommand < Gem::Command include Gem::InstallUpdateOptions @@ -25,7 +25,7 @@ class Gem::Commands::UpdateCommand < Gem::Command options.merge!(install_update_options) - super 'update', 'Update installed gems to the latest version', options add_install_update_options @@ -35,8 +35,8 @@ class Gem::Commands::UpdateCommand < Gem::Command value end - add_option('--system [VERSION]', Gem::Version, - 'Update the RubyGems system software') do |value, options| value = true unless value options[:system] = value @@ -176,13 +176,13 @@ command to remove old versions. args = update_rubygems_arguments version = spec.version - update_dir = File.join spec.base_dir, 'gems', "rubygems-update-#{version}" Dir.chdir update_dir do say "Installing RubyGems #{version}" unless options[:silent] installed = preparing_gem_layout_for(version) do - system Gem.ruby, '--disable-gems', 'setup.rb', *args end say "RubyGems system software updated" if installed unless options[:silent] @@ -224,7 +224,7 @@ command to remove old versions. requirement = Gem::Requirement.new ">= #{Gem::VERSION}" rubygems_update = Gem::Specification.new - rubygems_update.name = 'rubygems-update' rubygems_update.version = version highest_remote_tup = highest_remote_name_tuple(rubygems_update) @@ -278,8 +278,8 @@ command to remove old versions. check_oldest_rubygems version - installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement - installed_gems = update_gem('rubygems-update', version) if installed_gems.empty? || installed_gems.first.version != version return if installed_gems.empty? install_rubygems installed_gems.first @@ -287,11 +287,11 @@ command to remove old versions. def update_rubygems_arguments # :nodoc: args = [] - args << '--silent' if options[:silent] - args << '--prefix' << Gem.prefix if Gem.prefix - args << '--no-document' unless options[:document].include?('rdoc') || options[:document].include?('ri') - args << '--no-format-executable' if options[:no_format_executable] - args << '--previous-version' << Gem::VERSION if options[:system] == true or Gem::Version.new(options[:system]) >= Gem::Version.new(2) args @@ -1,17 +1,17 @@ # frozen_string_literal: true -require_relative '../command' class Gem::Commands::WhichCommand < Gem::Command def initialize - super 'which', 'Find the location of a library file you can require', :search_gems_first => false, :show_all => false - add_option '-a', '--[no-]all', 'show all matching files' do |show_all, options| options[:show_all] = show_all end - add_option '-g', '--[no-]gems-first', - 'search gems before non-gems' do |gems_first, options| options[:search_gems_first] = gems_first end end @@ -39,7 +39,7 @@ requiring to see why it does not behave as you expect. found = true options[:args].each do |arg| - arg = arg.sub(/#{Regexp.union(*Gem.suffixes)}$/, '') dirs = $LOAD_PATH spec = Gem::Specification.find_by_path arg @@ -1,8 +1,8 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../local_remote_options' -require_relative '../version_option' -require_relative '../gemcutter_utilities' class Gem::Commands::YankCommand < Gem::Command include Gem::LocalRemoteOptions @@ -28,15 +28,15 @@ data you will need to change them immediately and yank your gem. end def initialize - super 'yank', 'Remove a pushed gem from the index' add_version_option("remove") add_platform_option("remove") add_otp_option - add_option('--host HOST', - 'Yank from another gemcutter-compatible host', - ' (e.g. https://rubygems.org)') do |value, options| options[:host] = value end @@ -76,10 +76,10 @@ data you will need to change them immediately and yank your gem. request.add_field("Authorization", api_key) data = { - 'gem_name' => name, - 'version' => version, } - data['platform'] = platform if platform request.set_form_data data end @@ -5,8 +5,8 @@ # See LICENSE.txt for permissions. #++ -require_relative 'user_interaction' -require 'rbconfig' ## # Gem::ConfigFile RubyGems options and gem command options from gemrc. @@ -71,7 +71,7 @@ class Gem::ConfigFile # :startdoc: - SYSTEM_WIDE_CONFIG_FILE = File.join SYSTEM_CONFIG_PATH, 'gemrc' ## # List of arguments supplied to the config file object. @@ -182,20 +182,20 @@ class Gem::ConfigFile @update_sources = DEFAULT_UPDATE_SOURCES @concurrent_downloads = DEFAULT_CONCURRENT_DOWNLOADS @cert_expiration_length_days = DEFAULT_CERT_EXPIRATION_LENGTH_DAYS - @ipv4_fallback_enabled = ENV['IPV4_FALLBACK_ENABLED'] == 'true' || DEFAULT_IPV4_FALLBACK_ENABLED operating_system_config = Marshal.load Marshal.dump(OPERATING_SYSTEM_DEFAULTS) platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS) system_config = load_file SYSTEM_WIDE_CONFIG_FILE user_config = load_file config_file_name.dup.tap(&Gem::UNTAINT) - environment_config = (ENV['GEMRC'] || '') .split(File::PATH_SEPARATOR).inject({}) do |result, file| result.merge load_file file end @hash = operating_system_config.merge platform_config - unless args.index '--norc' @hash = @hash.merge system_config @hash = @hash.merge user_config @hash = @hash.merge environment_config @@ -269,7 +269,7 @@ if you believe they were disclosed to a third party. # Location of RubyGems.org credentials def credentials_path - credentials = File.join Gem.user_home, '.gem', 'credentials' if File.exist? credentials credentials else @@ -320,13 +320,13 @@ if you believe they were disclosed to a third party. config = load_file(credentials_path).merge(host => api_key) dirname = File.dirname credentials_path - require 'fileutils' FileUtils.mkdir_p(dirname) Gem.load_yaml permissions = 0600 & (~File.umask) - File.open(credentials_path, 'w', permissions) do |f| f.write config.to_yaml end @@ -389,7 +389,7 @@ if you believe they were disclosed to a third party. yield :backtrace, @backtrace yield :bulk_threshold, @bulk_threshold - yield 'config_file_name', @config_file_name if @config_file_name hash.each(&block) end @@ -405,7 +405,7 @@ if you believe they were disclosed to a third party. when /^--debug$/ then $DEBUG = true - warn 'NOTE: Debugging mode prints all exceptions even when rescued' else @args << arg end @@ -444,7 +444,7 @@ if you believe they were disclosed to a third party. @hash[:ssl_client_cert] if @hash.key? :ssl_client_cert keys = yaml_hash.keys.map {|key| key.to_s } - keys << 'debug' re = Regexp.union(*keys) @hash.each do |key, value| @@ -458,10 +458,10 @@ if you believe they were disclosed to a third party. # Writes out this config file, replacing its source. def write - require 'fileutils' FileUtils.mkdir_p File.dirname(config_file_name) - File.open config_file_name, 'w' do |io| io.write to_yaml end end @@ -39,7 +39,7 @@ module Kernel # GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb def gem(gem_name, *requirements) # :doc: - skip_list = (ENV['GEM_SKIP'] || "").split(/:/) raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name if gem_name.kind_of? Gem::Dependency @@ -5,7 +5,7 @@ # See LICENSE.txt for permissions. #++ -require 'monitor' module Kernel @@ -39,7 +39,7 @@ if RUBY_VERSION >= "2.5" && !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES start += 1 if path = loc.path - unless path.start_with?(rubygems_path) or path.start_with?('<internal:') # Non-rubygems frames uplevel -= 1 end @@ -1,4 +1,4 @@ -require 'socket' module CoreExtensions module TCPSocketExt @@ -20,10 +20,10 @@ module Gem # specified in the environment def self.default_spec_cache_dir - default_spec_cache_dir = File.join Gem.user_home, '.gem', 'specs' unless File.exist?(default_spec_cache_dir) - default_spec_cache_dir = File.join Gem.data_home, 'gem', 'specs' end default_spec_cache_dir @@ -34,7 +34,7 @@ module Gem # specified in the environment def self.default_dir - @default_dir ||= File.join(RbConfig::CONFIG['rubylibprefix'], 'gems', RbConfig::CONFIG['ruby_version']) end ## @@ -81,7 +81,7 @@ module Gem Dir.home.dup rescue if Gem.win_platform? - File.expand_path File.join(ENV['HOMEDRIVE'] || ENV['SystemDrive'], '/') else File.expand_path "/" end @@ -103,7 +103,7 @@ module Gem gem_dir = File.join(Gem.user_home, ".gem") gem_dir = File.join(Gem.data_home, "gem") unless File.exist?(gem_dir) parts = [gem_dir, ruby_engine] - parts << RbConfig::CONFIG['ruby_version'] unless RbConfig::CONFIG['ruby_version'].empty? File.join parts end @@ -111,14 +111,14 @@ module Gem # The path to standard location of the user's configuration directory. def self.config_home - @config_home ||= (ENV["XDG_CONFIG_HOME"] || File.join(Gem.user_home, '.config')) end ## # Finds the user's config file def self.find_config_file - gemrc = File.join Gem.user_home, '.gemrc' if File.exist? gemrc gemrc else @@ -137,14 +137,14 @@ module Gem # The path to standard location of the user's cache directory. def self.cache_home - @cache_home ||= (ENV["XDG_CACHE_HOME"] || File.join(Gem.user_home, '.cache')) end ## # The path to standard location of the user's data directory. def self.data_home - @data_home ||= (ENV["XDG_DATA_HOME"] || File.join(Gem.user_home, '.local', 'share')) end ## @@ -169,7 +169,7 @@ module Gem # Deduce Ruby's --program-prefix and --program-suffix from its install name def self.default_exec_format - exec_format = RbConfig::CONFIG['ruby_install_name'].sub('ruby', '%s') rescue '%s' unless exec_format =~ /%s/ raise Gem::Exception, @@ -183,7 +183,7 @@ module Gem # The default directory for binaries def self.default_bindir - RbConfig::CONFIG['bindir'] end def self.ruby_engine @@ -227,14 +227,14 @@ module Gem # Directory where vendor gems are installed. def self.vendor_dir # :nodoc: - if vendor_dir = ENV['GEM_VENDOR'] return vendor_dir.dup end - return nil unless RbConfig::CONFIG.key? 'vendordir' - File.join RbConfig::CONFIG['vendordir'], 'gems', - RbConfig::CONFIG['ruby_version'] end ## @@ -97,14 +97,14 @@ class Gem::Dependency end def pretty_print(q) # :nodoc: - q.group 1, 'Gem::Dependency.new(', ')' do q.pp name - q.text ',' q.breakable q.pp requirement - q.text ',' q.breakable q.pp type @@ -197,7 +197,7 @@ class Gem::Dependency reqs = other.requirement.requirements return false unless reqs.length == 1 - return false unless reqs.first.first == '=' version = reqs.first.last @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative '../rubygems' -require_relative 'dependency_list' -require_relative 'package' -require_relative 'installer' -require_relative 'spec_fetcher' -require_relative 'user_interaction' -require_relative 'available_set' -require_relative 'deprecate' ## # Installs a gem along with all its dependencies from local and remote gems. @@ -5,8 +5,8 @@ # See LICENSE.txt for permissions. #++ -require_relative 'tsort' -require_relative 'deprecate' ## # Gem::DependencyList is used for installing and uninstalling gems in the @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../rubygems' -require_relative 'user_interaction' ## # Cleans up after a partially-failed uninstall or for an invalid @@ -19,13 +19,13 @@ class Gem::Doctor # subdirectory. REPOSITORY_EXTENSION_MAP = [ # :nodoc: - ['specifications', '.gemspec'], - ['build_info', '.info'], - ['cache', '.gem'], - ['doc', ''], - ['extensions', ''], - ['gems', ''], - ['plugins', ''], ].freeze missing = @@ -74,8 +74,8 @@ class Gem::Doctor Gem.use_paths @gem_repository.to_s unless gem_repository? - say 'This directory does not appear to be a RubyGems repository, ' + - 'skipping' say return end @@ -111,16 +111,16 @@ class Gem::Doctor basename = File.basename(child, extension) 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' action = if @dry_run - 'Extra' else FileUtils.rm_r(child) - 'Removed' end say "#{action} #{type} #{sub_directory}/#{File.basename(child)}" @@ -136,8 +136,8 @@ module Gem "Found %s (%s), but was for platform%s %s" % [@name, @version, - @platforms.size == 1 ? '' : 's', - @platforms.join(' ,')] end end @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative 'deprecate' -require_relative 'unknown_command_spell_checker' ## # Base exception class for RubyGems. All exception raised by RubyGems are a @@ -27,7 +27,7 @@ class Gem::UnknownCommandError < Gem::Exception if DidYouMean.respond_to?(:correct_error) DidYouMean.correct_error(Gem::UnknownCommandError, Gem::UnknownCommandSpellChecker) else - DidYouMean::SPELL_CHECKERS['Gem::UnknownCommandError'] = Gem::UnknownCommandSpellChecker prepend DidYouMean::Correctable @@ -154,7 +154,7 @@ class Gem::ImpossibleDependenciesError < Gem::Exception def build_message # :nodoc: requester = @request.requester - requester = requester ? requester.spec.full_name : 'The user' dependency = @request.dependency message = "#{requester} requires #{dependency} but it conflicted:\n".dup @@ -10,10 +10,10 @@ module Gem::Ext; end -require_relative 'ext/build_error' -require_relative 'ext/builder' -require_relative 'ext/configure_builder' -require_relative 'ext/ext_conf_builder' -require_relative 'ext/rake_builder' -require_relative 'ext/cmake_builder' -require_relative 'ext/cargo_builder' @@ -2,7 +2,7 @@ ## # Raised when there is an error while building extensions. -require_relative '../exceptions' class Gem::Ext::BuildError < Gem::InstallError end @@ -5,7 +5,7 @@ # See LICENSE.txt for permissions. #++ -require_relative '../user_interaction' class Gem::Ext::Builder include Gem::UserInteraction @@ -18,29 +18,29 @@ class Gem::Ext::Builder end def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil) - unless File.exist? File.join(make_dir, 'Makefile') - raise Gem::InstallError, 'Makefile not found' end # try to find make program from Ruby configure arguments first - RbConfig::CONFIG['configure_args'] =~ /with-make-prog\=(\w+)/ - make_program_name = ENV['MAKE'] || ENV['make'] || $1 unless make_program_name - make_program_name = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make' end make_program = Shellwords.split(make_program_name) # The installation of the bundled gems is failed when DESTDIR is empty in mswin platform. - destdir = (/\bnmake/i !~ make_program_name || ENV['DESTDIR'] && ENV['DESTDIR'] != "") ? 'DESTDIR=%s' % ENV['DESTDIR'] : '' env = [destdir] if sitedir - env << 'sitearchdir=%s' % sitedir - env << 'sitelibdir=%s' % sitedir end - ['clean', '', 'install'].each do |target| # Pass DESTDIR via command line to override what's in MAKEFLAGS cmd = [ *make_program, @@ -50,7 +50,7 @@ class Gem::Ext::Builder begin run(cmd, results, "make #{target}".rstrip, make_dir) rescue Gem::InstallError - raise unless target == 'clean' # ignore clean failure end end end @@ -59,7 +59,7 @@ class Gem::Ext::Builder verbose = Gem.configuration.really_verbose begin - rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil if verbose puts("current directory: #{dir}") p(command) @@ -70,7 +70,7 @@ class Gem::Ext::Builder require "open3" # Set $SOURCE_DATE_EPOCH for the subprocess. - build_env = { 'SOURCE_DATE_EPOCH' => Gem.source_date_epoch_string }.merge(env) output, status = begin Open3.capture2e(build_env, *command, :chdir => dir) rescue => error @@ -82,7 +82,7 @@ class Gem::Ext::Builder results << output end ensure - ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps end unless status.success? @@ -212,11 +212,11 @@ EOF # Writes +output+ to gem_make.out in the extension install directory. def write_gem_make_out(output) # :nodoc: - destination = File.join @spec.extension_dir, 'gem_make.out' FileUtils.mkdir_p @spec.extension_dir - File.open destination, 'wb' do |io| io.puts output end @@ -29,14 +29,14 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder def build_crate(dest_path, results, args, cargo_dir) env = build_env cmd = cargo_command(cargo_dir, dest_path, args) - runner.call cmd, results, 'cargo', cargo_dir, env results end def build_env build_env = rb_config_env - build_env["RUBY_STATIC"] = "true" if ruby_static? && ENV.key?('RUBY_STATIC') build_env end @@ -46,7 +46,7 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder cmd = [] cmd += [cargo, "rustc"] - cmd += ["--target", ENV['CARGO_BUILD_TARGET']] if ENV['CARGO_BUILD_TARGET'] cmd += ["--target-dir", dest_path] cmd += ["--manifest-path", manifest] cmd += ["--lib"] @@ -144,13 +144,13 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder def cargo_dylib_path(dest_path) prefix = so_ext == "dll" ? "" : "lib" path_parts = [dest_path] - path_parts << ENV['CARGO_BUILD_TARGET'] if ENV['CARGO_BUILD_TARGET'] path_parts += [profile_target_directory, "#{prefix}#{cargo_crate_name}.#{so_ext}"] File.join(*path_parts) end def cargo_crate_name - spec.metadata.fetch('cargo_crate_name', spec.name).tr('-', '_') end def rustc_dynamic_linker_flags(dest_dir) @@ -297,8 +297,8 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder def profile_target_directory case profile - when :release then 'release' - when :dev then 'debug' else raise "unknown target directory for profile: #{profile}" end end @@ -2,8 +2,8 @@ class Gem::Ext::CmakeBuilder < Gem::Ext::Builder def self.build(extension, dest_path, results, args=[], lib_dir=nil, cmake_dir=Dir.pwd) - unless File.exist?(File.join(cmake_dir, 'Makefile')) - require_relative '../command' cmd = ["cmake", ".", "-DCMAKE_INSTALL_PREFIX=#{dest_path}", *Gem::Command.build_args] run cmd, results, class_name, cmake_dir @@ -7,7 +7,7 @@ class Gem::Ext::ConfigureBuilder < Gem::Ext::Builder def self.build(extension, dest_path, results, args=[], lib_dir=nil, configure_dir=Dir.pwd) - unless File.exist?(File.join(configure_dir, 'Makefile')) cmd = ["sh", "./configure", "--prefix=#{dest_path}", *args] run cmd, results, class_name, configure_dir @@ -7,8 +7,8 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_dir=Dir.pwd) - require 'fileutils' - require 'tempfile' tmp_dest = Dir.mktmpdir(".gem.", extension_dir) @@ -22,16 +22,16 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder begin require "shellwords" - cmd = Gem.ruby.shellsplit << "-I" << File.expand_path('../..', __dir__) << File.basename(extension) cmd.push(*args) run(cmd, results, class_name, extension_dir) do |s, r| - mkmf_log = File.join(extension_dir, 'mkmf.log') if File.exist? mkmf_log unless s.success? r << "To see why this extension failed to compile, please check" \ " the mkmf.log which can be found here:\n" - r << " " + File.join(dest_path, 'mkmf.log') + "\n" end FileUtils.mv mkmf_log, dest_path end @@ -67,7 +67,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder private def self.get_relative_path(path, base) - path[0..base.length - 1] = '.' if path.start_with?(base) path end end @@ -11,16 +11,16 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder run([Gem.ruby, File.basename(extension), *args], results, class_name, extension_dir) end - rake = ENV['rake'] if rake require "shellwords" rake = rake.shellsplit else begin - rake = [Gem.ruby, "-I#{File.expand_path("../..", __dir__)}", "-rrubygems", Gem.bin_path('rake', 'rake')] rescue Gem::Exception - rake = [Gem.default_exec_format % 'rake'] end end @@ -5,9 +5,9 @@ # See LICENSE.txt for permissions. #++ -require_relative '../rubygems' -require_relative 'command_manager' -require_relative 'deprecate' ## # Run an instance of the gem program. @@ -41,7 +41,7 @@ class Gem::GemRunner config_args = Gem.configuration[command_name] config_args = case config_args when String - config_args.split ' ' else Array(config_args) end @@ -56,7 +56,7 @@ class Gem::GemRunner # other arguments in the list. def extract_build_args(args) # :nodoc: - return [] unless offset = args.index('--') build_args = args.slice!(offset...args.length) @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'remote_fetcher' -require_relative 'text' ## # Utility methods for using the RubyGems API. @@ -19,8 +19,8 @@ module Gem::GemcutterUtilities # Add the --key option def add_key_option - add_option('-k', '--key KEYNAME', Symbol, - 'Use the given API key', "from #{Gem.configuration.credentials_path}") do |value,options| options[:key] = value end @@ -30,9 +30,9 @@ module Gem::GemcutterUtilities # Add the --otp option def add_otp_option - add_option('--otp CODE', - 'Digit code for multifactor authentication', - 'You can also use the environment variable GEM_HOST_OTP_CODE') do |value, options| options[:otp] = value end end @@ -69,7 +69,7 @@ module Gem::GemcutterUtilities @host ||= begin - env_rubygems_host = ENV['RUBYGEMS_HOST'] env_rubygems_host = nil if env_rubygems_host and env_rubygems_host.empty? @@ -83,7 +83,7 @@ module Gem::GemcutterUtilities # If +allowed_push_host+ metadata is present, then it will only allow that host. def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, scope: nil, &block) - require 'net/http' self.host = host if host unless self.host @@ -118,7 +118,7 @@ module Gem::GemcutterUtilities end def mfa_unauthorized?(response) - response.kind_of?(Net::HTTPUnauthorized) && response.body.start_with?('You have enabled multifactor authentication') end def update_scope(scope) @@ -240,13 +240,13 @@ module Gem::GemcutterUtilities end def ask_otp - say 'You have enabled multi-factor authentication. Please enter OTP code.' - options[:otp] = ask 'Code: ' end def pretty_host(host) if default_host? - 'RubyGems.org' else host end @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative '../rubygems' -require_relative 'package' -require 'tmpdir' ## # Top level class for building the gem repository index. @@ -43,28 +43,28 @@ class Gem::Indexer # Create an indexer that will index the gems in +directory+. def initialize(directory, options = {}) - require 'fileutils' - require 'tmpdir' - require 'zlib' options = { :build_modern => true }.merge options @build_modern = options[:build_modern] @dest_directory = directory - @directory = Dir.mktmpdir 'gem_generate_index' marshal_name = "Marshal.#{Gem.marshal_version}" - @master_index = File.join @directory, 'yaml' @marshal_index = File.join @directory, marshal_name - @quick_dir = File.join @directory, 'quick' @quick_marshal_dir = File.join @quick_dir, marshal_name @quick_marshal_dir_base = File.join "quick", marshal_name # FIX: UGH - @quick_index = File.join @quick_dir, 'index' - @latest_index = File.join @quick_dir, 'latest_index' @specs_index = File.join @directory, "specs.#{Gem.marshal_version}" @latest_specs_index = @@ -104,7 +104,7 @@ class Gem::Indexer files = [] - Gem.time 'Generated Marshal quick index gemspecs' do specs.each do |spec| next if spec.default_gem? spec_file_name = "#{spec.original_name}.gemspec.rz" @@ -112,7 +112,7 @@ class Gem::Indexer marshal_zipped = Gem.deflate Marshal.dump(spec) - File.open marshal_name, 'wb' do |io| io.write marshal_zipped end @@ -136,7 +136,7 @@ class Gem::Indexer say "Generating #{name} index" Gem.time "Generated #{name} index" do - File.open(file, 'wb') do |io| specs = index.map do |*spec| # We have to splat here because latest_specs is an array, while the # others are hashes. @@ -169,10 +169,10 @@ class Gem::Indexer latest_specs = Gem::Specification._latest_specs specs - build_modern_index(released.sort, @specs_index, 'specs') - build_modern_index(latest_specs.sort, @latest_specs_index, 'latest specs') build_modern_index(prerelease.sort, @prerelease_specs_index, - 'prerelease specs') @files += [@specs_index, "#{@specs_index}.gz", @@ -217,7 +217,7 @@ class Gem::Indexer def compress_indices say "Compressing indices" - Gem.time 'Compressed indices' do if @build_modern gzip @specs_index gzip @latest_specs_index @@ -252,7 +252,7 @@ class Gem::Indexer zipped = Gem.deflate data - File.open "#{filename}.#{extension}", 'wb' do |io| io.write zipped end end @@ -308,7 +308,7 @@ class Gem::Indexer end files = files.map do |path| - path.sub(/^#{Regexp.escape @directory}\/?/, '') # HACK? end files.each do |file| @@ -358,7 +358,7 @@ class Gem::Indexer end if updated_gems.empty? - say 'No new gems' terminate_interaction 0 end @@ -367,7 +367,7 @@ class Gem::Indexer files = build_marshal_gemspecs specs - Gem.time 'Updated indexes' do update_specs_index released, @dest_specs_index, @specs_index update_specs_index released, @dest_latest_specs_index, @latest_specs_index update_specs_index(prerelease, @@ -389,7 +389,7 @@ class Gem::Indexer files << "#{@prerelease_specs_index}.gz" files = files.map do |path| - path.sub(/^#{Regexp.escape @directory}\/?/, '') # HACK? end files.each do |file| @@ -420,7 +420,7 @@ class Gem::Indexer specs_index = compact_specs specs_index.uniq.sort - File.open dest, 'wb' do |io| Marshal.dump specs_index, io end end @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../rubygems' -require_relative 'user_interaction' ## # A post-install hook that displays "Successfully installed @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../rubygems' -require_relative 'user_interaction' ## # A default post-install hook that displays "Successfully installed @@ -5,8 +5,8 @@ # See LICENSE.txt for permissions. #++ -require_relative '../rubygems' -require_relative 'security_option' ## # Mixin methods for install and update options for Gem::Commands @@ -18,22 +18,22 @@ module Gem::InstallUpdateOptions # Add the install/update options to the option parser. def add_install_update_options - add_option(:"Install/Update", '-i', '--install-dir DIR', - 'Gem repository directory to get installed', - 'gems') do |value, options| options[:install_dir] = File.expand_path(value) end - add_option(:"Install/Update", '-n', '--bindir DIR', - 'Directory where executables will be', - 'placed when the gem is installed') do |value, options| options[:bin_dir] = File.expand_path(value) end - add_option(:"Install/Update", '--document [TYPES]', Array, - 'Generate documentation for installed gems', - 'List the documentation types you wish to', - 'generate. For example: rdoc,ri') do |value, options| options[:document] = case value when nil then %w[ri] when false then [] @@ -41,63 +41,63 @@ module Gem::InstallUpdateOptions end end - add_option(:"Install/Update", '--build-root DIR', - 'Temporary installation root. Useful for building', - 'packages. Do not use this when installing remote gems.') do |value, options| options[:build_root] = File.expand_path(value) end - add_option(:"Install/Update", '--vendor', - 'Install gem into the vendor directory.', - 'Only for use by gem repackagers.') do |value, options| unless Gem.vendor_dir - raise Gem::OptionParser::InvalidOption.new 'your platform is not supported' end options[:vendor] = true options[:install_dir] = Gem.vendor_dir end - add_option(:"Install/Update", '-N', '--no-document', - 'Disable documentation generation') do |value, options| options[:document] = [] end - add_option(:"Install/Update", '-E', '--[no-]env-shebang', "Rewrite the shebang line on installed", "scripts to use /usr/bin/env") do |value, options| options[:env_shebang] = value end - add_option(:"Install/Update", '-f', '--[no-]force', - 'Force gem to install, bypassing dependency', - 'checks') do |value, options| options[:force] = value end - add_option(:"Install/Update", '-w', '--[no-]wrappers', - 'Use bin wrappers for executables', - 'Not available on dosish platforms') do |value, options| options[:wrappers] = value end add_security_option - add_option(:"Install/Update", '--ignore-dependencies', - 'Do not install any required dependent gems') do |value, options| options[:ignore_dependencies] = value end - add_option(:"Install/Update", '--[no-]format-executable', - 'Make installed executable names match Ruby.', - 'If Ruby is ruby18, foo_exec will be', - 'foo_exec18') do |value, options| options[:format_executable] = value end - add_option(:"Install/Update", '--[no-]user-install', - 'Install in user\'s home directory instead', - 'of GEM_HOME.') do |value, options| options[:user_install] = value end @@ -133,9 +133,9 @@ module Gem::InstallUpdateOptions options[:post_install_message] = value end - add_option(:"Install/Update", '-g', '--file [FILE]', - 'Read from a gem dependencies API file and', - 'install the listed gems') do |v,o| v = Gem::GEM_DEP_FILES.find do |file| File.exist? file end unless v @@ -150,32 +150,32 @@ module Gem::InstallUpdateOptions options[:gemdeps] = v end - add_option(:"Install/Update", '--without GROUPS', Array, - 'Omit the named groups (comma separated)', - 'when installing from a gem dependencies', - 'file') do |v,o| options[:without_groups].concat v.map {|without| without.intern } end - add_option(:"Install/Update", '--default', - 'Add the gem\'s full specification to', - 'specifications/default and extract only its bin') do |v,o| options[:install_as_default] = v end - add_option(:"Install/Update", '--explain', - 'Rather than install the gems, indicate which would', - 'be installed') do |v,o| options[:explain] = v end - add_option(:"Install/Update", '--[no-]lock', - 'Create a lock file (when used with -g/--file)') do |v,o| options[:lock] = v end - add_option(:"Install/Update", '--[no-]suggestions', - 'Suggest alternates when gems are not found') do |v,o| options[:suggest_alternate] = v end end @@ -193,7 +193,7 @@ module Gem::InstallUpdateOptions # Default description for the gem install and update commands. def install_update_defaults_str - '--document=ri' end end @@ -5,12 +5,12 @@ # See LICENSE.txt for permissions. #++ -require_relative 'installer_uninstaller_utils' -require_relative 'exceptions' -require_relative 'deprecate' -require_relative 'package' -require_relative 'ext' -require_relative 'user_interaction' ## # The installer installs the files contained in the .gem into the Gem.home. @@ -125,14 +125,14 @@ class Gem::Installer @spec = spec end - def extract_files(destination_dir, pattern = '*') FileUtils.mkdir_p destination_dir spec.files.each do |file| file = File.join destination_dir, file next if File.exist? file FileUtils.mkdir_p File.dirname(file) - File.open file, 'w' do |fp| fp.puts "# #{file}" end end @@ -177,7 +177,7 @@ class Gem::Installer # :post_install_message:: Print gem post install message if true def initialize(package, options={}) - require 'fileutils' @options = options @package = package @@ -219,7 +219,7 @@ class Gem::Installer ruby_executable = false existing = nil - File.open generated_bin, 'rb' do |io| line = io.gets shebang = /^#!.*ruby/ @@ -256,7 +256,7 @@ class Gem::Installer question = "#{spec.name}'s executable \"#{filename}\" conflicts with ".dup if ruby_executable - question << (existing || 'an unknown executable') return if ask_yes_no "#{question}\nOverwrite the executable?", false @@ -474,7 +474,7 @@ class Gem::Installer if Gem.win_platform? script_name = formatted_program_filename(filename) + ".bat" script_path = File.join bindir, File.basename(script_name) - File.open script_path, 'w' do |file| file.puts windows_stub_script(bindir, filename) end @@ -504,7 +504,7 @@ class Gem::Installer dir_mode = options[:prog_mode] || (mode | 0111) unless dir_mode == mode - require 'fileutils' FileUtils.chmod dir_mode, bin_path end @@ -541,10 +541,10 @@ class Gem::Installer def generate_bin_script(filename, bindir) bin_script_path = File.join bindir, formatted_program_filename(filename) - require 'fileutils' FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers - File.open bin_script_path, 'wb', 0755 do |file| file.print app_script_text(filename) file.chmod(options[:prog_mode] || 0755) end @@ -565,7 +565,7 @@ class Gem::Installer if File.exist? dst if File.symlink? dst link = File.readlink(dst).split File::SEPARATOR - cur_version = Gem::Version.create(link[-3].sub(/^.*-/, '')) return if spec.version < cur_version end File.unlink dst @@ -684,9 +684,9 @@ class Gem::Installer @build_args = options[:build_args] unless @build_root.nil? - @bin_dir = File.join(@build_root, @bin_dir.gsub(/^[a-zA-Z]:/, '')) - @gem_home = File.join(@build_root, @gem_home.gsub(/^[a-zA-Z]:/, '')) - @plugins_dir = File.join(@build_root, @plugins_dir.gsub(/^[a-zA-Z]:/, '')) alert_warning "You build with buildroot.\n Build root: #{@build_root}\n Bin dir: #{@bin_dir}\n Gem home: #{@gem_home}\n Plugins dir: #{@plugins_dir}" end end @@ -697,7 +697,7 @@ class Gem::Installer user_bin_dir = @bin_dir || Gem.bindir(gem_home) user_bin_dir = user_bin_dir.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR - path = ENV['PATH'] path = path.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR if Gem.win_platform? @@ -708,7 +708,7 @@ class Gem::Installer path = path.split(File::PATH_SEPARATOR) unless path.include? user_bin_dir - unless !Gem.win_platform? && (path.include? user_bin_dir.sub(ENV['HOME'], '~')) alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run." self.class.path_warning = true end @@ -788,7 +788,7 @@ TEXT end def gemdeps_load(name) - return '' if name == "bundler" <<-TEXT @@ -824,7 +824,7 @@ TEXT 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 @@ -935,14 +935,14 @@ TEXT def write_build_info_file return if build_args.empty? - build_info_dir = File.join gem_home, 'build_info' dir_mode = options[:dir_mode] FileUtils.mkdir_p build_info_dir, :mode => dir_mode && 0755 build_info_file = File.join build_info_dir, "#{spec.full_name}.info" - File.open build_info_file, 'w' do |io| build_args.each do |arg| io.puts arg end @@ -955,7 +955,7 @@ TEXT # Writes the .gem file to the cache directory def write_cache_file - cache_file = File.join gem_home, 'cache', spec.file_name @package.copy_to cache_file end @@ -987,7 +987,7 @@ TEXT end def load_relative_enabled? - rb_config["LIBRUBY_RELATIVE"] == 'yes' end def bash_prolog_script @@ -9,12 +9,12 @@ module Gem::InstallerUninstallerUtils plugins = spec.plugins return if plugins.empty? - require 'pathname' spec.plugins.each do |plugin| plugin_script_path = File.join plugins_dir, "#{spec.name}_plugin#{File.extname(plugin)}" - File.open plugin_script_path, 'wb' do |file| file.puts "require_relative '#{Pathname.new(plugin).relative_path_from(Pathname.new(plugins_dir))}'" end @@ -5,8 +5,8 @@ # See LICENSE.txt for permissions. #++ -require 'uri' -require_relative '../rubygems' ## # Mixin methods for local and remote Gem::Command options. @@ -38,18 +38,18 @@ module Gem::LocalRemoteOptions # Add local/remote options to the command line parser. def add_local_remote_options - add_option(:"Local/Remote", '-l', '--local', - 'Restrict operations to the LOCAL domain') do |value, options| options[:domain] = :local end - add_option(:"Local/Remote", '-r', '--remote', - 'Restrict operations to the REMOTE domain') do |value, options| options[:domain] = :remote end - add_option(:"Local/Remote", '-b', '--both', - 'Allow LOCAL and REMOTE operations') do |value, options| options[:domain] = :both end @@ -64,7 +64,7 @@ module Gem::LocalRemoteOptions # Add the --bulk-threshold option def add_bulk_threshold_option - add_option(:"Local/Remote", '-B', '--bulk-threshold COUNT', "Threshold for switching to bulk", "synchronization (default #{Gem.configuration.bulk_threshold})") do |value, options| @@ -76,8 +76,8 @@ module Gem::LocalRemoteOptions # Add the --clear-sources option def add_clear_sources_option - add_option(:"Local/Remote", '--clear-sources', - 'Clear the gem sources') do |value, options| Gem.sources = nil options[:sources_cleared] = true end @@ -89,8 +89,8 @@ module Gem::LocalRemoteOptions def add_proxy_option accept_uri_http - add_option(:"Local/Remote", '-p', '--[no-]http-proxy [URL]', URI::HTTP, - 'Use HTTP proxy for remote operations') do |value, options| options[:http_proxy] = (value == false) ? :no_proxy : value Gem.configuration[:http_proxy] = options[:http_proxy] end @@ -102,9 +102,9 @@ module Gem::LocalRemoteOptions def add_source_option accept_uri_http - add_option(:"Local/Remote", '-s', '--source URL', URI::HTTP, - 'Append URL to list of remote gem sources') do |source, options| - source << '/' if source !~ /\/\z/ if options.delete :sources_cleared Gem.sources = [source] @@ -118,8 +118,8 @@ module Gem::LocalRemoteOptions # Add the --update-sources option def add_update_sources_option - add_option(:Deprecated, '-u', '--[no-]update-sources', - 'Update local source cache') do |value, options| Gem.configuration.update_sources = value end end @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative 'user_interaction' ## # This Gem::StreamUI subclass records input and output to StringIO for @@ -40,7 +40,7 @@ class Gem::MockGemUi < Gem::StreamUI end def initialize(input = "") - require 'stringio' ins = StringIO.new input outs = StringIO.new errs = StringIO.new @@ -48,7 +48,7 @@ class Gem::NameTuple def full_name case @platform - when nil, 'ruby', '' "#{@name}-#{@version}" else "#{@name}-#{@version}-#{@platform}" @@ -1,3 +1,3 @@ # frozen_string_literal: true -require_relative 'optparse/lib/optparse' @@ -5,8 +5,8 @@ #++ require_relative "../rubygems" -require_relative 'security' -require_relative 'user_interaction' ## # Example using a Gem::Package @@ -158,7 +158,7 @@ class Gem::Package return super unless gem.present? return super unless gem.start - return super unless gem.start.include? 'MD5SUM =' Gem::Package::Old.new gem end @@ -178,9 +178,9 @@ class Gem::Package tar = Gem::Package::TarReader.new io tar.each_entry do |entry| case entry.full_name - when 'metadata' then metadata = entry.read - when 'metadata.gz' then metadata = Gem::Util.gunzip entry.read end end @@ -193,7 +193,7 @@ class Gem::Package # Creates a new package that will read or write to the file +gem+. def initialize(gem, security_policy) # :notnew: - require 'zlib' @gem = gem @@ -229,7 +229,7 @@ class Gem::Package end end - tar.add_file_signed 'checksums.yaml.gz', 0444, @signer do |io| gzip_to io do |gz_io| Psych.dump checksums_by_algorithm, gz_io end @@ -241,7 +241,7 @@ class Gem::Package # and adds this file to the +tar+. def add_contents(tar) # :nodoc: - digests = tar.add_file_signed 'data.tar.gz', 0444, @signer do |io| gzip_to io do |gz_io| Gem::Package::TarWriter.new gz_io do |data_tar| add_files data_tar @@ -249,7 +249,7 @@ class Gem::Package end end - @checksums['data.tar.gz'] = digests end ## @@ -266,7 +266,7 @@ class Gem::Package next unless stat.file? tar.add_file_simple file, stat.mode, stat.size do |dst_io| - File.open file, 'rb' do |src_io| dst_io.write src_io.read 16384 until src_io.eof? end end @@ -277,13 +277,13 @@ class Gem::Package # Adds the package's Gem::Specification to the +tar+ file def add_metadata(tar) # :nodoc: - digests = tar.add_file_signed 'metadata.gz', 0444, @signer do |io| gzip_to io do |gz_io| gz_io.write @spec.to_yaml end end - @checksums['metadata.gz'] = digests end ## @@ -335,7 +335,7 @@ EOM gem_tar = Gem::Package::TarReader.new io gem_tar.each do |entry| - next unless entry.full_name == 'data.tar.gz' open_tar_gz entry do |pkg_tar| pkg_tar.each do |contents_entry| @@ -387,7 +387,7 @@ EOM reader = Gem::Package::TarReader.new io reader.each do |entry| - next unless entry.full_name == 'data.tar.gz' extract_tar_gz entry, destination_dir, pattern @@ -420,7 +420,7 @@ EOM real_destination = link_target.start_with?("/") ? link_target : File.expand_path(link_target, File.dirname(destination)) raise Gem::Package::SymlinkError.new(entry.full_name, real_destination, destination_dir) unless - normalize_path(real_destination).start_with? normalize_path(destination_dir + '/') end FileUtils.rm_rf destination @@ -439,7 +439,7 @@ EOM directories << mkdir end - File.open destination, 'wb' do |out| out.write entry.read FileUtils.chmod file_mode(entry.header.mode), destination end if entry.file? @@ -481,13 +481,13 @@ EOM def install_location(filename, destination_dir) # :nodoc: raise Gem::Package::PathError.new(filename, destination_dir) if - filename.start_with? '/' destination_dir = File.realpath(destination_dir) destination = File.expand_path(filename, destination_dir) raise Gem::Package::PathError.new(destination, destination_dir) unless - normalize_path(destination).start_with? normalize_path(destination_dir + '/') destination.tap(&Gem::UNTAINT) destination @@ -506,9 +506,9 @@ EOM def load_spec(entry) # :nodoc: case entry.full_name - when 'metadata' then @spec = Gem::Specification.from_yaml entry.read - when 'metadata.gz' then Zlib::GzipReader.wrap(entry, external_encoding: Encoding::UTF_8) do |gzio| @spec = Gem::Specification.from_yaml gzio.read end @@ -532,7 +532,7 @@ EOM def read_checksums(gem) Gem.load_yaml - @checksums = gem.seek 'checksums.yaml.gz' do |entry| Zlib::GzipReader.wrap entry do |gz_io| Gem::SafeYAML.safe_load gz_io.read end @@ -544,7 +544,7 @@ EOM # certificate and key are not present only checksum generation is set up. def setup_signer(signer_options: {}) - passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE'] if @spec.signing_key @signer = Gem::Security::Signer.new( @@ -651,7 +651,7 @@ EOM case file_name when "metadata", "metadata.gz" then load_spec entry - when 'data.tar.gz' then verify_gz entry end rescue @@ -668,12 +668,12 @@ EOM end unless @spec - raise Gem::Package::FormatError.new 'package metadata is missing', @gem end - unless @files.include? 'data.tar.gz' raise Gem::Package::FormatError.new \ - 'package content (data.tar.gz) is missing', @gem end if duplicates = @files.group_by {|f| f }.select {|k,v| v.size > 1 }.map(&:first) and duplicates.any? @@ -693,12 +693,12 @@ EOM end end -require_relative 'package/digest_io' -require_relative 'package/source' -require_relative 'package/file_source' -require_relative 'package/io_source' -require_relative 'package/old' -require_relative 'package/tar_header' -require_relative 'package/tar_reader' -require_relative 'package/tar_reader/entry' -require_relative 'package/tar_writer' @@ -22,10 +22,10 @@ class Gem::Package::FileSource < Gem::Package::Source # :nodoc: all end def with_write_io(&block) - File.open path, 'wb', &block end def with_read_io(&block) - File.open path, 'rb', &block end end @@ -19,8 +19,8 @@ class Gem::Package::Old < Gem::Package # cannot be written. def initialize(gem, security_policy) - require 'fileutils' - require 'zlib' Gem.load_yaml @contents = nil @@ -41,7 +41,7 @@ class Gem::Package::Old < Gem::Package read_until_dashes io # spec header = file_list io - @contents = header.map {|file| file['path'] } end end @@ -59,7 +59,7 @@ class Gem::Package::Old < Gem::Package raise Gem::Exception, errstr unless header header.each do |entry| - full_name = entry['path'] destination = install_location full_name, destination_dir @@ -73,13 +73,13 @@ class Gem::Package::Old < Gem::Package file_data = Zlib::Inflate.inflate file_data raise Gem::Package::FormatError, "#{full_name} in #{@gem} is corrupt" if - file_data.length != entry['size'].to_i FileUtils.rm_rf destination FileUtils.mkdir_p File.dirname(destination), :mode => dir_mode && 0755 - File.open destination, 'wb', file_mode(entry['mode']) do |out| out.write file_data end @@ -119,7 +119,7 @@ class Gem::Package::Old < Gem::Package loop do line = io.gets - return if line.chomp == '__END__' break unless line end @@ -160,7 +160,7 @@ class Gem::Package::Old < Gem::Package return true unless @security_policy raise Gem::Security::Exception, - 'old format gems do not contain signatures and cannot be verified' if @security_policy.verify_data true @@ -53,42 +53,42 @@ class Gem::Package::TarHeader ## # Pack format for a tar header - PACK_FORMAT = 'a100' + # name - 'a8' + # mode - 'a8' + # uid - 'a8' + # gid - 'a12' + # size - 'a12' + # mtime - 'a7a' + # chksum - 'a' + # typeflag - 'a100' + # linkname - 'a6' + # magic - 'a2' + # version - 'a32' + # uname - 'a32' + # gname - 'a8' + # devmajor - 'a8' + # devminor - 'a155' # prefix ## # Unpack format for a tar header - UNPACK_FORMAT = 'A100' + # name - 'A8' + # mode - 'A8' + # uid - 'A8' + # gid - 'A12' + # size - 'A12' + # mtime - 'A8' + # checksum - 'A' + # typeflag - 'A100' + # linkname - 'A6' + # magic - 'A2' + # version - 'A32' + # uname - 'A32' + # gname - 'A8' + # devmajor - 'A8' + # devminor - 'A155' # prefix attr_reader(*FIELDS) @@ -134,7 +134,7 @@ class Gem::Package::TarHeader # \ff flags a negative 256-based number # In case we have a match, parse it as a signed binary value # in big-endian order, except that the high-order bit is ignored. - return str.unpack('N2').last if str =~ /\A[\x80\xff]/n strict_oct(str) end @@ -121,4 +121,4 @@ class Gem::Package::TarReader end end -require_relative 'tar_reader/entry' @@ -68,9 +68,9 @@ class Gem::Package::TarReader::Entry @header.name end rescue ArgumentError => e - raise unless e.message == 'string contains null byte' raise Gem::Package::TarInvalidError, - 'tar is corrupt, name contains null byte' end ## @@ -166,7 +166,7 @@ class Gem::Package::TarWriter def add_file_signed(name, mode, signer) digest_algorithms = [ signer.digest_algorithm, - Gem::Security.create_digest('SHA512'), ].compact.uniq digests = add_file_digest name, mode, digest_algorithms do |io| @@ -304,14 +304,14 @@ class Gem::Package::TarWriter raise Gem::Package::TooLongFileName.new("File \"#{name}\" has a too long path (should be 256 or less)") end - prefix = '' if name.bytesize > 100 - parts = name.split('/', -1) # parts are never empty here name = parts.pop # initially empty for names with a trailing slash ("foo/.../bar/") - prefix = parts.join('/') # if empty, then it's impossible to split (parts is empty too) while !parts.empty? && (prefix.bytesize > 155 || name.empty?) - name = parts.pop + '/' + name - prefix = parts.join('/') end if name.bytesize > 100 or prefix.empty? @@ -20,9 +20,9 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require_relative '../rubygems' -require_relative 'package' -require 'rake/packagetask' ## # Create a package based upon a Gem::Specification. Gem packages, as well as @@ -113,7 +113,7 @@ class Gem::PackageTask < Rake::PackageTask Gem::Package.build gem_spec verbose trace do - mv gem_file, '..' end end end @@ -12,7 +12,7 @@ class Gem::Platform attr_accessor :cpu, :os, :version def self.local - arch = RbConfig::CONFIG['arch'] arch = "#{arch}_60" if arch =~ /mswin(?:32|64)$/ @local ||= new(arch) end @@ -56,7 +56,7 @@ class Gem::Platform case arch when Gem::Platform::CURRENT then Gem::Platform.local - when Gem::Platform::RUBY, nil, '' then Gem::Platform::RUBY else super @@ -68,7 +68,7 @@ class Gem::Platform when Array then @cpu, @os, @version = arch when String then - arch = arch.split '-' if arch.length > 2 and arch.last !~ /\d/ # reassemble x86-linux-gnu extra = arch.pop @@ -78,7 +78,7 @@ class Gem::Platform cpu = arch.shift @cpu = case cpu - when /i\d86/ then 'x86' else cpu end @@ -91,31 +91,31 @@ class Gem::Platform @cpu, os = nil, cpu if os.nil? # legacy jruby @os, @version = case os - when /aix(\d+)?/ then [ 'aix', $1 ] - when /cygwin/ then [ 'cygwin', nil ] - when /darwin(\d+)?/ then [ 'darwin', $1 ] - when /^macruby$/ then [ 'macruby', nil ] - when /freebsd(\d+)?/ then [ 'freebsd', $1 ] - when /hpux(\d+)?/ then [ 'hpux', $1 ] - when /^java$/, /^jruby$/ then [ 'java', nil ] - when /^java([\d.]*)/ then [ 'java', $1 ] - when /^dalvik(\d+)?$/ then [ 'dalvik', $1 ] - when /^dotnet$/ then [ 'dotnet', nil ] - when /^dotnet([\d.]*)/ then [ 'dotnet', $1 ] - when /linux-?((?!gnu)\w+)?/ then [ 'linux', $1 ] - when /mingw32/ then [ 'mingw32', nil ] - when /mingw-?(\w+)?/ then [ 'mingw', $1 ] when /(mswin\d+)(\_(\d+))?/ then os, version = $1, $3 - @cpu = 'x86' if @cpu.nil? and os =~ /32$/ [os, version] - when /netbsdelf/ then [ 'netbsdelf', nil ] - when /openbsd(\d+\.\d+)?/ then [ 'openbsd', $1 ] - when /bitrig(\d+\.\d+)?/ then [ 'bitrig', $1 ] - when /solaris(\d+\.\d+)?/ then [ 'solaris', $1 ] # test when /^(\w+_platform)(\d+)?/ then [ $1, $2 ] - else [ 'unknown', nil ] end when Gem::Platform then @cpu = arch.cpu @@ -131,7 +131,7 @@ class Gem::Platform end def to_s - to_a.compact.join '-' end ## @@ -160,12 +160,12 @@ class Gem::Platform return nil unless Gem::Platform === other # universal-mingw32 matches x64-mingw-ucrt - return true if (@cpu == 'universal' or other.cpu == 'universal') and - @os.start_with?('mingw') and other.os.start_with?('mingw') # cpu - ([nil,'universal'].include?(@cpu) or [nil, 'universal'].include?(other.cpu) or @cpu == other.cpu or - (@cpu == 'arm' and other.cpu.start_with?("arm"))) and # os @os == other.os and @@ -184,17 +184,17 @@ class Gem::Platform when String then # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007 other = case other - when /^i686-darwin(\d)/ then ['x86', 'darwin', $1 ] - when /^i\d86-linux/ then ['x86', 'linux', nil ] - when 'java', 'jruby' then [nil, 'java', nil ] - when /^dalvik(\d+)?$/ then [nil, 'dalvik', $1 ] - when /dotnet(\-(\d+\.\d+))?/ then ['universal','dotnet', $2 ] - when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2 ] - when /mswin64(\_(\d+))?/ then ['x64', 'mswin64', $2 ] - when 'powerpc-darwin' then ['powerpc', 'darwin', nil ] - when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1 ] - when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8' ] - when /universal-darwin(\d)/ then ['universal', 'darwin', $1 ] else other end @@ -210,11 +210,11 @@ class Gem::Platform # A pure-Ruby gem that may use Gem::Specification#extensions to build # binary files. - RUBY = 'ruby'.freeze ## # A platform-specific gem that is built for the packaging Ruby's platform. # This will be replaced with Gem::Platform::local. - CURRENT = 'current'.freeze end @@ -7,7 +7,7 @@ module Gem end unless respond_to? :create def visit_String(str) - return super unless str == '=' # or whatever you want quote = Psych::Nodes::Scalar::SINGLE_QUOTED @emitter.scalar str, nil, nil, false, true, quote @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative 'local_remote_options' -require_relative 'spec_fetcher' -require_relative 'version_option' -require_relative 'text' module Gem::QueryUtils @@ -12,41 +12,41 @@ module Gem::QueryUtils 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 @@ -257,7 +257,7 @@ module Gem::QueryUtils if pls != [Gem::Platform::RUBY] platform_list = [pls.delete(Gem::Platform::RUBY), *pls.sort].compact - out = platform_list.unshift(out).join(' ') end out @@ -284,7 +284,7 @@ module Gem::QueryUtils def spec_authors(entry, spec) authors = "Author#{spec.authors.length > 1 ? 's' : ''}: ".dup - authors << spec.authors.join(', ') entry << format_text(authors, 68, 4) end @@ -298,7 +298,7 @@ module Gem::QueryUtils 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 @@ -306,15 +306,15 @@ module Gem::QueryUtils 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 @@ -327,7 +327,7 @@ module Gem::QueryUtils 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" @@ -336,7 +336,7 @@ module Gem::QueryUtils 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 @@ -1,8 +1,8 @@ # frozen_string_literal: true -require_relative '../rubygems' begin - require 'rdoc/rubygems_hook' module Gem RDoc = ::RDoc::RubygemsHook end @@ -1,11 +1,11 @@ # frozen_string_literal: true -require_relative '../rubygems' -require_relative 'request' -require_relative 'request/connection_pools' -require_relative 's3_uri_signer' -require_relative 'uri_formatter' -require_relative 'uri' -require_relative 'user_interaction' ## # RemoteFetcher handles the details of fetching gems and gem information from @@ -72,10 +72,10 @@ class Gem::RemoteFetcher # fetching the gem. def initialize(proxy=nil, dns=nil, headers={}) - require_relative 'core_ext/tcpsocket_init' if Gem.configuration.ipv4_fallback_enabled - require 'net/http' - require 'stringio' - require 'uri' Socket.do_not_reverse_lookup = true @@ -136,7 +136,7 @@ class Gem::RemoteFetcher # REFACTOR: split this up and dis on scheme (eg download_http) # REFACTOR: be sure to clean up fake fetcher when you do this... cleaner case scheme - when 'http', 'https', 's3' then unless File.exist? local_gem_path begin verbose "Downloading gem #{gem_file_name}" @@ -156,12 +156,12 @@ class Gem::RemoteFetcher self.cache_update_path remote_gem_path, local_gem_path end end - when 'file' then begin path = source_uri.path - path = File.dirname(path) if File.extname(path) == '.gem' - remote_gem_path = Gem::Util.correct_for_windows_path(File.join(path, 'gems', gem_file_name)) FileUtils.cp(remote_gem_path, local_gem_path) rescue Errno::EACCES @@ -171,7 +171,7 @@ class Gem::RemoteFetcher verbose "Using local gem #{local_gem_path}" when nil then # TODO test for local overriding cache source_path = if Gem.win_platform? && source_uri.scheme && - !source_uri.path.include?(':') "#{source_uri.scheme}:#{source_uri.path}" else source_uri.path @@ -216,9 +216,9 @@ class Gem::RemoteFetcher head ? response : response.body when Net::HTTPMovedPermanently, Net::HTTPFound, Net::HTTPSeeOther, Net::HTTPTemporaryRedirect then - raise FetchError.new('too many redirects', uri) if depth > 10 - unless location = response['Location'] raise FetchError.new("redirecting but no redirect location was given", uri) end location = Gem::Uri.new location @@ -312,7 +312,7 @@ class Gem::RemoteFetcher end def https?(uri) - uri.scheme.downcase == 'https' end def close_all @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'net/http' -require_relative 'user_interaction' class Gem::Request extend Gem::UserInteraction @@ -44,7 +44,7 @@ class Gem::Request end def self.configure_connection_for_https(connection, cert_files) - raise Gem::Exception.new('OpenSSL is not available. Install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources') unless Gem::HAVE_OPENSSL connection.use_ssl = true connection.verify_mode = @@ -96,10 +96,10 @@ class Gem::Request return unless cert case error_number when OpenSSL::X509::V_ERR_CERT_HAS_EXPIRED then - require 'time' "Certificate #{cert.subject} expired at #{cert.not_after.iso8601}" when OpenSSL::X509::V_ERR_CERT_NOT_YET_VALID then - require 'time' "Certificate #{cert.subject} not valid until #{cert.not_before.iso8601}" when OpenSSL::X509::V_ERR_CERT_REJECTED then "Certificate #{cert.subject} is rejected" @@ -140,13 +140,13 @@ class Gem::Request Gem::UriFormatter.new(@uri.password).unescape end - request.add_field 'User-Agent', @user_agent - request.add_field 'Connection', 'keep-alive' - request.add_field 'Keep-Alive', '30' if @last_modified - require 'time' - request.add_field 'If-Modified-Since', @last_modified.httpdate end yield request if block_given? @@ -158,7 +158,7 @@ class Gem::Request # Returns a proxy URI for the given +scheme+ if one is set in the # environment variables. - def self.get_proxy_from_env(scheme = 'http') _scheme = scheme.downcase _SCHEME = scheme.upcase env_proxy = ENV["#{_scheme}_proxy"] || ENV["#{_SCHEME}_PROXY"] @@ -166,8 +166,8 @@ class Gem::Request no_env_proxy = env_proxy.nil? || env_proxy.empty? if no_env_proxy - return (_scheme == 'https' || _scheme == 'http') ? - :no_proxy : get_proxy_from_env('http') end require "uri" @@ -229,14 +229,14 @@ class Gem::Request reset connection - raise Gem::RemoteFetcher::FetchError.new('too many bad responses', @uri) if bad_response bad_response = true retry rescue Net::HTTPFatalError verbose "fatal error" - raise Gem::RemoteFetcher::FetchError.new('fatal error', @uri) # HACK work around EOFError bug in Net::HTTP # NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible # to install gems. @@ -246,7 +246,7 @@ class Gem::Request requests = @requests[connection.object_id] verbose "connection reset after #{requests} requests, retrying" - raise Gem::RemoteFetcher::FetchError.new('too many connection resets', @uri) if retried reset connection @@ -273,7 +273,7 @@ class Gem::Request ua = "RubyGems/#{Gem::VERSION} #{Gem::Platform.local}".dup ruby_version = RUBY_VERSION - ruby_version += 'dev' if RUBY_LEVEL == -1 ua << " Ruby/#{ruby_version} (#{RUBY_RELEASE_DATE}" if RUBY_LEVEL >= 0 @@ -283,12 +283,12 @@ class Gem::Request end ua << ")" - ua << " #{RUBY_ENGINE}" if RUBY_ENGINE != 'ruby' ua end end -require_relative 'request/http_pool' -require_relative 'request/https_pool' -require_relative 'request/connection_pools' @@ -37,7 +37,7 @@ class Gem::Request::ConnectionPools # :nodoc: # 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? @@ -45,7 +45,7 @@ class Gem::Request::ConnectionPools # :nodoc: end def https?(uri) - uri.scheme.downcase == 'https' end def no_proxy?(host, env_no_proxy) @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative 'tsort' ## # A RequestSet groups a request to activate a set of dependencies. @@ -254,7 +254,7 @@ class Gem::RequestSet end def install_into(dir, force = true, options = {}) - gem_home, ENV['GEM_HOME'] = ENV['GEM_HOME'], dir existing = force ? [] : specs_in(dir) existing.delete_if {|s| @always_install.include? s } @@ -287,7 +287,7 @@ class Gem::RequestSet installed ensure - ENV['GEM_HOME'] = gem_home end ## @@ -337,32 +337,32 @@ class Gem::RequestSet end def pretty_print(q) # :nodoc: - q.group 2, '[RequestSet:', ']' do q.breakable if @remote - q.text 'remote' q.breakable end if @prerelease - q.text 'prerelease' q.breakable end if @development_shallow - q.text 'shallow development' q.breakable elsif @development - q.text 'development' q.breakable end if @soft_missing - q.text 'soft missing' end - q.group 2, '[dependencies:', ']' do q.breakable @dependencies.map do |dep| q.text dep.to_s @@ -371,7 +371,7 @@ class Gem::RequestSet end q.breakable - q.text 'sets:' q.breakable q.pp @sets.map {|set| set.class } @@ -461,6 +461,6 @@ class Gem::RequestSet end end -require_relative 'request_set/gem_dependency_api' -require_relative 'request_set/lockfile' -require_relative 'request_set/lockfile/tokenizer' @@ -50,10 +50,10 @@ class Gem::RequestSet::GemDependencyAPI :ruby_21 => %w[ruby rbx maglev truffleruby], }.freeze - mswin = Gem::Platform.new 'x86-mswin32' - mswin64 = Gem::Platform.new 'x64-mswin64' - x86_mingw = Gem::Platform.new 'x86-mingw32' - x64_mingw = Gem::Platform.new 'x64-mingw32' PLATFORM_MAP = { # :nodoc: :jruby => Gem::Platform::RUBY, @@ -91,11 +91,11 @@ class Gem::RequestSet::GemDependencyAPI :x64_mingw_21 => x64_mingw, }.freeze - gt_eq_0 = Gem::Requirement.new '>= 0' - tilde_gt_1_8_0 = Gem::Requirement.new '~> 1.8.0' - tilde_gt_1_9_0 = Gem::Requirement.new '~> 1.9.0' - tilde_gt_2_0_0 = Gem::Requirement.new '~> 2.0.0' - tilde_gt_2_1_0 = Gem::Requirement.new '~> 2.1.0' VERSION_MAP = { # :nodoc: :jruby => gt_eq_0, @@ -435,7 +435,7 @@ Gem dependencies file #{@path} requires #{name} more than once. reference ||= ref reference ||= branch reference ||= tag - reference ||= 'master' if ref && branch warn <<-WARNING @@ -637,8 +637,8 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # :development. Only one group may be specified. def gemspec(options = {}) - name = options.delete(:name) || '{,*}' - path = options.delete(:path) || '.' development_group = options.delete(:development_group) || :development spec = find_gemspec name, path @@ -697,11 +697,11 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta def pin_gem_source(name, type = :default, source = nil) source_description = case type - when :default then '(default)' when :path then "path: #{source}" when :git then "git: #{source}" when :source then "source: #{source}" - else '(unknown)' end raise ArgumentError, @@ -788,7 +788,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta engine_version = options[:engine_version] raise ArgumentError, - 'You must specify engine_version along with the Ruby engine' if engine and not engine_version return true if @installing @@ -76,7 +76,7 @@ class Gem::RequestSet::Lockfile @gem_deps_file = File.expand_path(gem_deps_file) @gem_deps_dir = File.dirname(@gem_deps_file) - if RUBY_VERSION < '2.7' @gem_deps_file.untaint unless gem_deps_file.tainted? end @@ -106,7 +106,7 @@ class Gem::RequestSet::Lockfile out << " specs:" requests.sort_by {|request| request.name }.each do |request| - next if request.spec.name == 'bundler' platform = "-#{request.spec.platform}" unless Gem::Platform::RUBY == request.spec.platform @@ -156,7 +156,7 @@ class Gem::RequestSet::Lockfile if dest.index(base) == 0 offset = dest[base.size + 1..-1] - return '.' unless offset offset else @@ -224,7 +224,7 @@ class Gem::RequestSet::Lockfile def write content = to_s - File.open "#{@gem_deps_file}.lock", 'w' do |io| io.write content end end @@ -236,4 +236,4 @@ class Gem::RequestSet::Lockfile end end -require_relative 'lockfile/tokenizer' @@ -19,15 +19,15 @@ class Gem::RequestSet::Lockfile::Parser @tokens.skip :newline case token.value - when 'DEPENDENCIES' then parse_DEPENDENCIES - when 'GIT' then parse_GIT - when 'GEM' then parse_GEM - when 'PATH' then parse_PATH - when 'PLATFORMS' then parse_PLATFORMS else token = get until @tokens.empty? or peek.first == :section @@ -110,8 +110,8 @@ class Gem::RequestSet::Lockfile::Parser def parse_GEM # :nodoc: sources = [] - while [:entry, 'remote'] == peek.first(2) do - get :entry, 'remote' data = get(:text).value skip :newline @@ -120,7 +120,7 @@ class Gem::RequestSet::Lockfile::Parser sources << Gem::Source.new(Gem::DEFAULT_HOST) if sources.empty? - get :entry, 'specs' skip :newline @@ -145,7 +145,7 @@ class Gem::RequestSet::Lockfile::Parser data = token.value if type == :text and column == 4 - version, platform = data.split '-', 2 platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY @@ -171,12 +171,12 @@ class Gem::RequestSet::Lockfile::Parser end def parse_GIT # :nodoc: - get :entry, 'remote' repository = get(:text).value skip :newline - get :entry, 'revision' revision = get(:text).value skip :newline @@ -190,7 +190,7 @@ class Gem::RequestSet::Lockfile::Parser skip :newline end - get :entry, 'specs' skip :newline @@ -234,12 +234,12 @@ class Gem::RequestSet::Lockfile::Parser end def parse_PATH # :nodoc: - get :entry, 'remote' directory = get(:text).value skip :newline - get :entry, 'specs' skip :newline @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative 'parser' class Gem::RequestSet::Lockfile::Tokenizer Token = Struct.new :type, :value, :column, :line @@ -57,7 +57,7 @@ class Gem::RequestSet::Lockfile::Tokenizer private def tokenize(input) - require 'strscan' s = StringScanner.new input until s.eos? do @@ -61,7 +61,7 @@ class Gem::Requirement input when Gem::Version, Array then new input - when '!' then source_set else if input.respond_to? :to_str @@ -73,11 +73,11 @@ class Gem::Requirement end def self.default - new '>= 0' end def self.default_prerelease - new '>= 0.a' end ### @@ -218,7 +218,7 @@ class Gem::Requirement end def encode_with(coder) # :nodoc: - coder.add 'requirements', @requirements end ## @@ -230,7 +230,7 @@ class Gem::Requirement end def pretty_print(q) # :nodoc: - q.group 1, 'Gem::Requirement.new(', ')' do q.pp as_list end end @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative 'dependency' -require_relative 'exceptions' -require_relative 'util/list' ## # Given a set of Gem::Dependency objects as +needed+ and a way to query the @@ -10,14 +10,14 @@ require_relative 'util/list' # all the requirements. class Gem::Resolver - require_relative 'resolver/molinillo' ## # If the DEBUG_RESOLVER environment variable is set then debugging mode is # enabled for the resolver. This will display information about the state # of the resolver while a set of dependencies is being resolved. - DEBUG_RESOLVER = !ENV['DEBUG_RESOLVER'].nil? ## # Set to true if all development dependencies should be considered. @@ -74,7 +74,7 @@ class Gem::Resolver case sets.length when 0 then - raise ArgumentError, 'one set in the composition must be non-nil' when 1 then sets.first else @@ -124,7 +124,7 @@ class Gem::Resolver data = yield $stderr.printf "%10s (%d entries)\n", stage.to_s.upcase, data.size unless data.empty? - require 'pp' PP.pp data, $stderr end end @@ -173,7 +173,7 @@ class Gem::Resolver include Molinillo::UI def output - @output ||= debug? ? $stdout : File.open(IO::NULL, 'w') end def debug? @@ -318,30 +318,30 @@ class Gem::Resolver private :amount_constrained end -require_relative 'resolver/activation_request' -require_relative 'resolver/conflict' -require_relative 'resolver/dependency_request' -require_relative 'resolver/requirement_list' -require_relative 'resolver/stats' - -require_relative 'resolver/set' -require_relative 'resolver/api_set' -require_relative 'resolver/composed_set' -require_relative 'resolver/best_set' -require_relative 'resolver/current_set' -require_relative 'resolver/git_set' -require_relative 'resolver/index_set' -require_relative 'resolver/installer_set' -require_relative 'resolver/lock_set' -require_relative 'resolver/vendor_set' -require_relative 'resolver/source_set' - -require_relative 'resolver/specification' -require_relative 'resolver/spec_specification' -require_relative 'resolver/api_specification' -require_relative 'resolver/git_specification' -require_relative 'resolver/index_specification' -require_relative 'resolver/installed_specification' -require_relative 'resolver/local_specification' -require_relative 'resolver/lock_specification' -require_relative 'resolver/vendor_specification' @@ -93,7 +93,7 @@ class Gem::Resolver::ActivationRequest end def inspect # :nodoc: - '#<%s for %p from %s>' % [ self.class, @spec, @request ] end @@ -130,12 +130,12 @@ class Gem::Resolver::ActivationRequest end def pretty_print(q) # :nodoc: - q.group 2, '[Activation request', ']' do q.breakable q.pp @spec q.breakable - q.text ' for ' q.pp @request end end @@ -26,13 +26,13 @@ class Gem::Resolver::APISet < Gem::Resolver::Set # API URL +dep_uri+ which is described at # https://guides.rubygems.org/rubygems-org-api - def initialize(dep_uri = 'https://index.rubygems.org/info/') super() dep_uri = URI dep_uri unless URI === dep_uri @dep_uri = dep_uri - @uri = dep_uri + '..' @data = Hash.new {|h,k| h[k] = [] } @source = Gem::Source.new @uri @@ -83,12 +83,12 @@ class Gem::Resolver::APISet < Gem::Resolver::Set end def pretty_print(q) # :nodoc: - q.group 2, '[APISet', ']' do q.breakable q.text "URI: #{@dep_uri}" q.breakable - q.text 'gem names:' q.pp @data.keys end end @@ -62,7 +62,7 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification end def pretty_print(q) # :nodoc: - q.group 2, '[APISpecification', ']' do q.breakable q.text "name: #{name}" @@ -73,7 +73,7 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification q.text "platform: #{platform}" q.breakable - q.text 'dependencies:' q.breakable q.pp @dependencies @@ -41,9 +41,9 @@ class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet end def pretty_print(q) # :nodoc: - q.group 2, '[BestSet', ']' do q.breakable - q.text 'sets:' q.breakable q.pp @sets @@ -65,7 +65,7 @@ class Gem::Resolver::Conflict matching = matching % [ dependency, - alternates.join(', '), ] end @@ -97,21 +97,21 @@ class Gem::Resolver::Conflict end def pretty_print(q) # :nodoc: - q.group 2, '[Dependency conflict: ', ']' do q.breakable - q.text 'activated ' q.pp @activated q.breakable - q.text ' dependency ' q.pp @dependency q.breakable if @dependency == @failed_dep - q.text ' failed' else - q.text ' failed dependency ' q.pp @failed_dep end end @@ -139,7 +139,7 @@ class Gem::Resolver::Conflict end end - path = ['user request (gem command or Gemfile)'] if path.empty? path end @@ -95,12 +95,12 @@ class Gem::Resolver::DependencyRequest end def pretty_print(q) # :nodoc: - q.group 2, '[Dependency request ', ']' do q.breakable q.text @dependency.to_s q.breakable - q.text ' requested by ' q.pp @requester end end @@ -35,7 +35,7 @@ class Gem::Resolver::GitSet < Gem::Resolver::Set def initialize # :nodoc: super() - @git = ENV['git'] || 'git' @need_submodules = {} @repositories = {} @root_dir = Gem.dir @@ -104,7 +104,7 @@ class Gem::Resolver::GitSet < Gem::Resolver::Set end def pretty_print(q) # :nodoc: - q.group 2, '[GitSet', ']' do next if @repositories.empty? q.breakable @@ -21,7 +21,7 @@ class Gem::Resolver::GitSpecification < Gem::Resolver::SpecSpecification # the executables. def install(options = {}) - require_relative '../installer' installer = Gem::Installer.for_spec spec, options @@ -35,7 +35,7 @@ class Gem::Resolver::GitSpecification < Gem::Resolver::SpecSpecification end def pretty_print(q) # :nodoc: - q.group 2, '[GitSpecification', ']' do q.breakable q.text "name: #{name}" @@ -43,7 +43,7 @@ class Gem::Resolver::GitSpecification < Gem::Resolver::SpecSpecification q.text "version: #{version}" q.breakable - q.text 'dependencies:' q.breakable q.pp dependencies @@ -53,14 +53,14 @@ class Gem::Resolver::IndexSet < Gem::Resolver::Set end def pretty_print(q) # :nodoc: - q.group 2, '[IndexSet', ']' do q.breakable - q.text 'sources:' q.breakable q.pp @f.sources q.breakable - q.text 'specs:' q.breakable @@ -66,11 +66,11 @@ class Gem::Resolver::IndexSpecification < Gem::Resolver::Specification end def inspect # :nodoc: - '#<%s %s source %s>' % [self.class, full_name, @source] end def pretty_print(q) # :nodoc: - q.group 2, '[Index specification', ']' do q.breakable q.text full_name @@ -80,7 +80,7 @@ class Gem::Resolver::IndexSpecification < Gem::Resolver::Specification end q.breakable - q.text 'source ' q.pp @source end end @@ -30,7 +30,7 @@ class Gem::Resolver::InstalledSpecification < Gem::Resolver::SpecSpecification end def pretty_print(q) # :nodoc: - q.group 2, '[InstalledSpecification', ']' do q.breakable q.text "name: #{name}" @@ -41,7 +41,7 @@ class Gem::Resolver::InstalledSpecification < Gem::Resolver::SpecSpecification q.text "platform: #{platform}" q.breakable - q.text 'dependencies:' q.breakable q.pp spec.dependencies end @@ -190,7 +190,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set def inspect # :nodoc: always_install = @always_install.map {|s| s.full_name } - '#<%s domain: %s specs: %p always install: %p>' % [ self.class, @domain, @specs.keys, always_install ] end @@ -219,16 +219,16 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set end def pretty_print(q) # :nodoc: - q.group 2, '[InstallerSet', ']' do q.breakable q.text "domain: #{@domain}" q.breakable - q.text 'specs: ' q.pp @specs.keys q.breakable - q.text 'always install: ' q.pp @always_install end end @@ -17,7 +17,7 @@ class Gem::Resolver::LocalSpecification < Gem::Resolver::SpecSpecification end def pretty_print(q) # :nodoc: - q.group 2, '[LocalSpecification', ']' do q.breakable q.text "name: #{name}" @@ -28,7 +28,7 @@ class Gem::Resolver::LocalSpecification < Gem::Resolver::SpecSpecification q.text "platform: #{platform}" q.breakable - q.text 'dependencies:' q.breakable q.pp dependencies @@ -63,15 +63,15 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set end def pretty_print(q) # :nodoc: - q.group 2, '[LockSet', ']' do q.breakable - q.text 'source:' q.breakable q.pp @source q.breakable - q.text 'specs:' q.breakable q.pp @specs.map {|spec| spec.full_name } @@ -29,7 +29,7 @@ class Gem::Resolver::LockSpecification < Gem::Resolver::Specification def install(options = {}) destination = options[:install_dir] || Gem.dir - if File.exist? File.join(destination, 'specifications', spec.spec_name) yield nil return end @@ -45,7 +45,7 @@ class Gem::Resolver::LockSpecification < Gem::Resolver::Specification end def pretty_print(q) # :nodoc: - q.group 2, '[LockSpecification', ']' do q.breakable q.text "name: #{@name}" @@ -59,7 +59,7 @@ class Gem::Resolver::LockSpecification < Gem::Resolver::Specification unless @dependencies.empty? q.breakable - q.text 'dependencies:' q.breakable q.pp @dependencies end @@ -1,2 +1,2 @@ # frozen_string_literal: true -require_relative 'molinillo/lib/molinillo' @@ -93,7 +93,7 @@ class Gem::Resolver::Specification # specification. def install(options = {}) - require_relative '../installer' gem = download options @@ -69,7 +69,7 @@ class Gem::Resolver::VendorSet < Gem::Resolver::Set end def pretty_print(q) # :nodoc: - q.group 2, '[VendorSet', ']' do next if @directories.empty? q.breakable @@ -1,4 +1,4 @@ -require_relative 'openssl' ## # S3URISigner implements AWS SigV4 for S3 Source to avoid a dependency on the aws-sdk-* gems @@ -138,14 +138,14 @@ class Gem::S3URISigner end def ec2_metadata_credentials_json - require 'net/http' - require_relative 'request' - require_relative 'request/connection_pools' - require 'json' iam_info = ec2_metadata_request(EC2_IAM_INFO) # Expected format: arn:aws:iam::<id>:instance-profile/<role_name> - role_name = iam_info['InstanceProfileArn'].split('/').last ec2_metadata_request(EC2_IAM_SECURITY_CREDENTIALS + role_name) end @@ -26,7 +26,7 @@ module Gem if ::Psych.respond_to? :safe_load def self.safe_load(input) - if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1') ::Psych.safe_load(input, permitted_classes: PERMITTED_CLASSES, permitted_symbols: PERMITTED_SYMBOLS, aliases: true) else ::Psych.safe_load(input, PERMITTED_CLASSES, PERMITTED_SYMBOLS, true) @@ -34,7 +34,7 @@ module Gem end def self.load(input) - if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1') ::Psych.safe_load(input, permitted_classes: [::Symbol]) else ::Psych.safe_load(input, [::Symbol]) @@ -5,8 +5,8 @@ # See LICENSE.txt for permissions. #++ -require_relative 'exceptions' -require_relative 'openssl' ## # = Signing gems @@ -334,7 +334,7 @@ module Gem::Security ## # Used internally to select the signing digest from all computed digests - DIGEST_NAME = 'SHA256' # :nodoc: ## # Length of keys created by RSA and DSA keys @@ -344,18 +344,18 @@ module Gem::Security ## # Default algorithm to use when building a key pair - DEFAULT_KEY_ALGORITHM = 'RSA' ## # Named curve used for Elliptic Curve - EC_NAME = 'secp384r1' ## # Cipher used to encrypt the key pair used to sign gems. # Must be in the list returned by OpenSSL::Cipher.ciphers - KEY_CIPHER = OpenSSL::Cipher.new('AES-256-CBC') if defined?(OpenSSL::Cipher) ## # One day in seconds @@ -376,10 +376,10 @@ module Gem::Security # * The certificate contains a subject key identifier EXTENSIONS = { - 'basicConstraints' => 'CA:FALSE', - 'keyUsage' => - 'keyEncipherment,dataEncipherment,digitalSignature', - 'subjectKeyIdentifier' => 'hash', }.freeze def self.alt_name_or_x509_entry(certificate, x509_entry) @@ -473,7 +473,7 @@ module Gem::Security OpenSSL::Digest.new(algorithm) end else - require 'digest' def self.create_digest(algorithm = DIGEST_NAME) Digest.const_get(algorithm).new @@ -487,11 +487,11 @@ module Gem::Security def self.create_key(algorithm) if defined?(OpenSSL::PKey) case algorithm.downcase - when 'dsa' OpenSSL::PKey::DSA.new(RSA_DSA_KEY_LENGTH) - when 'rsa' OpenSSL::PKey::RSA.new(RSA_DSA_KEY_LENGTH) - when 'ec' if RUBY_VERSION >= "2.4.0" OpenSSL::PKey::EC.generate(EC_NAME) else @@ -510,11 +510,11 @@ module Gem::Security # Turns +email_address+ into an OpenSSL::X509::Name def self.email_to_name(email_address) - email_address = email_address.gsub(/[^\[email protected]]+/i, '_') - cn, dcs = email_address.split '@' - dcs = dcs.split '.' OpenSSL::X509::Name.new([ ["CN", cn], @@ -571,17 +571,17 @@ module Gem::Security signee_key = certificate.public_key alt_name = certificate.extensions.find do |extension| - extension.oid == 'subjectAltName' end - extensions = extensions.merge 'subjectAltName' => alt_name.value if alt_name issuer_alt_name = signing_cert.extensions.find do |extension| - extension.oid == 'subjectAltName' end - extensions = extensions.merge 'issuerAltName' => issuer_alt_name.value if issuer_alt_name signed = create_cert signee_subject, signee_key, age, extensions, serial @@ -597,7 +597,7 @@ module Gem::Security def self.trust_dir return @trust_dir if @trust_dir - dir = File.join Gem.user_home, '.gem', 'trust' @trust_dir ||= Gem::Security::TrustDir.new dir end @@ -617,7 +617,7 @@ module Gem::Security def self.write(pemmable, path, permissions = 0600, passphrase = nil, cipher = KEY_CIPHER) path = File.expand_path path - File.open path, 'wb', permissions do |io| if passphrase and cipher io.write pemmable.to_pem cipher, passphrase else @@ -633,9 +633,9 @@ module Gem::Security end if Gem::HAVE_OPENSSL - require_relative 'security/policy' - require_relative 'security/policies' - require_relative 'security/trust_dir' end -require_relative 'security/signer' @@ -5,7 +5,7 @@ module Gem::Security # No security policy: all package signature checks are disabled. NoSecurity = Policy.new( - 'No Security', :verify_data => false, :verify_signer => false, :verify_chain => false, @@ -23,7 +23,7 @@ module Gem::Security # easily spoofed, and is not recommended. AlmostNoSecurity = Policy.new( - 'Almost No Security', :verify_data => true, :verify_signer => false, :verify_chain => false, @@ -40,7 +40,7 @@ module Gem::Security # is not recommended. LowSecurity = Policy.new( - 'Low Security', :verify_data => true, :verify_signer => true, :verify_chain => false, @@ -59,7 +59,7 @@ module Gem::Security # gem off as unsigned. MediumSecurity = Policy.new( - 'Medium Security', :verify_data => true, :verify_signer => true, :verify_chain => true, @@ -78,7 +78,7 @@ module Gem::Security # a reasonable guarantee that the contents of the gem have not been altered. HighSecurity = Policy.new( - 'High Security', :verify_data => true, :verify_signer => true, :verify_chain => true, @@ -91,7 +91,7 @@ module Gem::Security # Policy used to verify a certificate and key when signing a gem SigningPolicy = Policy.new( - 'Signing Policy', :verify_data => false, :verify_signer => true, :verify_chain => true, @@ -104,11 +104,11 @@ module Gem::Security # Hash of configured security policies Policies = { - 'NoSecurity' => NoSecurity, - 'AlmostNoSecurity' => AlmostNoSecurity, - 'LowSecurity' => LowSecurity, - 'MediumSecurity' => MediumSecurity, - 'HighSecurity' => HighSecurity, # SigningPolicy is not intended for use by `gem -P` so do not list it }.freeze @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative '../user_interaction' ## # A Gem::Security::Policy object encapsulates the settings for verifying @@ -53,8 +53,8 @@ class Gem::Security::Policy # and is valid for the given +time+. def check_chain(chain, time) - raise Gem::Security::Exception, 'missing signing chain' unless chain - raise Gem::Security::Exception, 'empty signing chain' if chain.empty? begin chain.each_cons 2 do |issuer, cert| @@ -83,7 +83,7 @@ class Gem::Security::Policy # If the +issuer+ is +nil+ no verification is performed. def check_cert(signer, issuer, time) - raise Gem::Security::Exception, 'missing signing certificate' unless signer message = "certificate #{signer.subject}" @@ -112,7 +112,7 @@ class Gem::Security::Policy unless signer and key return true unless @only_signed - raise Gem::Security::Exception, 'missing key or signature' end raise Gem::Security::Exception, @@ -127,11 +127,11 @@ class Gem::Security::Policy # +time+. def check_root(chain, time) - raise Gem::Security::Exception, 'missing signing chain' unless chain root = chain.first - raise Gem::Security::Exception, 'missing root certificate' unless root raise Gem::Security::Exception, "root certificate #{root.subject} is not self-signed " + @@ -146,11 +146,11 @@ class Gem::Security::Policy # the digests of the two certificates match according to +digester+ def check_trust(chain, digester, trust_dir) - raise Gem::Security::Exception, 'missing signing chain' unless chain root = chain.first - raise Gem::Security::Exception, 'missing root certificate' unless root path = Gem::Security.trust_dir.cert_path root @@ -182,7 +182,7 @@ class Gem::Security::Policy def subject(certificate) # :nodoc: certificate.extensions.each do |extension| - next unless extension.oid == 'subjectAltName' return extension.value end @@ -206,7 +206,7 @@ class Gem::Security::Policy # If +key+ is given it is used to validate the signing certificate. def verify(chain, key = nil, digests = {}, signatures = {}, - full_name = '(unknown)') if signatures.empty? if @only_signed raise Gem::Security::Exception, @@ -230,7 +230,7 @@ class Gem::Security::Policy end if @verify_data - raise Gem::Security::Exception, 'no digests provided (probable bug)' if signer_digests.nil? or signer_digests.empty? else signer_digests = {} @@ -42,7 +42,7 @@ class Gem::Security::Signer def self.re_sign_cert(expired_cert, expired_cert_path, private_key) return unless expired_cert.not_after < Time.now - expiry = expired_cert.not_after.strftime('%Y%m%d%H%M%S') expired_cert_file = "#{File.basename(expired_cert_path)}.expired.#{expiry}" new_expired_cert_path = File.join(Gem.user_home, ".gem", expired_cert_file) @@ -105,7 +105,7 @@ class Gem::Security::Signer # this value is preferred, otherwise the subject is used. def extract_name(cert) # :nodoc: - subject_alt_name = cert.extensions.find {|e| 'subjectAltName' == e.oid } if subject_alt_name /\Aemail:/ =~ subject_alt_name.value # rubocop:disable Performance/StartWith @@ -139,7 +139,7 @@ class Gem::Security::Signer def sign(data) return unless @key - raise Gem::Security::Exception, 'no certs provided' if @cert_chain.empty? if @cert_chain.length == 1 and @cert_chain.last.not_after < Time.now alert("Your certificate has expired, trying to re-sign it...") @@ -182,7 +182,7 @@ class Gem::Security::Signer return unless disk_key if disk_key.to_pem == @key.to_pem && disk_cert == old_cert.to_pem - expiry = old_cert.not_after.strftime('%Y%m%d%H%M%S') old_cert_file = "gem-public_cert.pem.expired.#{expiry}" old_cert_path = File.join(Gem.user_home, ".gem", old_cert_file) @@ -41,7 +41,7 @@ class Gem::Security::TrustDir def each_certificate return enum_for __method__ unless block_given? - glob = File.join @dir, '*.pem' Dir[glob].each do |certificate_file| begin @@ -92,7 +92,7 @@ class Gem::Security::TrustDir destination = cert_path certificate - File.open destination, 'wb', 0600 do |io| io.write certificate.to_pem io.chmod(@permissions[:trusted_cert]) end @@ -104,7 +104,7 @@ class Gem::Security::TrustDir # permissions. def verify - require 'fileutils' if File.exist? @dir raise Gem::Security::Exception, "trust directory #{@dir} is not a directory" unless @@ -5,7 +5,7 @@ # See LICENSE.txt for permissions. #++ -require_relative '../rubygems' # forward-declare @@ -20,9 +20,9 @@ end module Gem::SecurityOption def add_security_option Gem::OptionParser.accept Gem::Security::Policy do |value| - require_relative 'security' - raise Gem::OptionParser::InvalidArgument, 'OpenSSL not installed' unless defined?(Gem::Security::HighSecurity) policy = Gem::Security::Policies[value] @@ -33,9 +33,9 @@ module Gem::SecurityOption policy end - add_option(:"Install/Update", '-P', '--trust-policy POLICY', Gem::Security::Policy, - 'Specify gem trust policy') do |value, options| options[:security_policy] = value end end @@ -12,9 +12,9 @@ class Gem::Source include Gem::Text FILES = { # :nodoc: - :released => 'specs', - :latest => 'latest_specs', - :prerelease => 'prerelease_specs', }.freeze ## @@ -71,7 +71,7 @@ class Gem::Source # Returns a Set that can fetch specifications from this source. def dependency_resolver_set # :nodoc: - return Gem::Resolver::IndexSet.new self if 'file' == uri.scheme fetch_uri = if uri.host == "rubygems.org" index_uri = uri.dup @@ -141,7 +141,7 @@ class Gem::Source return spec if spec end - source_uri.path << '.rz' spec = fetcher.fetch_path source_uri spec = Gem::Util.inflate spec @@ -150,7 +150,7 @@ class Gem::Source require "fileutils" FileUtils.mkdir_p cache_dir - File.open local_spec, 'wb' do |io| io.write spec end end @@ -209,13 +209,13 @@ class Gem::Source end def pretty_print(q) # :nodoc: - q.group 2, '[Remote:', ']' do q.breakable q.text @uri.to_s if api = uri q.breakable - q.text 'API URI: ' q.text api.to_s end end @@ -229,13 +229,13 @@ class Gem::Source private def enforce_trailing_slash(uri) - uri.merge(uri.path.gsub(/\/+$/, '') + '/') end end -require_relative 'source/git' -require_relative 'source/installed' -require_relative 'source/specific_file' -require_relative 'source/local' -require_relative 'source/lock' -require_relative 'source/vendor' @@ -58,7 +58,7 @@ class Gem::Source::Git < Gem::Source @remote = true @root_dir = Gem.dir - @git = ENV['git'] || 'git' end def <=>(other) @@ -92,18 +92,18 @@ class Gem::Source::Git < Gem::Source return false unless File.exist? repo_cache_dir unless File.exist? install_dir - system @git, 'clone', '--quiet', '--no-checkout', repo_cache_dir, install_dir end Dir.chdir install_dir do - system @git, 'fetch', '--quiet', '--force', '--tags', install_dir - success = system @git, 'reset', '--quiet', '--hard', rev_parse if @need_submodules require "open3" - _, status = Open3.capture2e(@git, 'submodule', 'update', '--quiet', '--init', '--recursive') success &&= status.success? end @@ -120,11 +120,11 @@ class Gem::Source::Git < Gem::Source if File.exist? repo_cache_dir Dir.chdir repo_cache_dir do - system @git, 'fetch', '--quiet', '--force', '--tags', - @repository, 'refs/heads/*:refs/heads/*' end else - system @git, 'clone', '--quiet', '--bare', '--no-hardlinks', @repository, repo_cache_dir end end @@ -133,7 +133,7 @@ class Gem::Source::Git < Gem::Source # Directory where git gems get unpacked and so-forth. def base_dir # :nodoc: - File.join @root_dir, 'bundler' end ## @@ -155,11 +155,11 @@ class Gem::Source::Git < Gem::Source def install_dir # :nodoc: return unless File.exist? repo_cache_dir - File.join base_dir, 'gems', "#{@name}-#{dir_shortref}" end def pretty_print(q) # :nodoc: - q.group 2, '[Git: ', ']' do q.breakable q.text @repository @@ -172,7 +172,7 @@ class Gem::Source::Git < Gem::Source # The directory where the git gem's repository will be cached. def repo_cache_dir # :nodoc: - File.join @root_dir, 'cache', 'bundler', 'git', "#{@name}-#{uri_hash}" end ## @@ -182,7 +182,7 @@ class Gem::Source::Git < Gem::Source hash = nil Dir.chdir repo_cache_dir do - hash = Gem::Util.popen(@git, 'rev-parse', @reference).strip end raise Gem::Exception, @@ -201,7 +201,7 @@ class Gem::Source::Git < Gem::Source return [] unless install_dir Dir.chdir install_dir do - Dir['{,*,*/*}.gemspec'].map do |spec_file| directory = File.dirname spec_file file = File.basename spec_file @@ -211,7 +211,7 @@ class Gem::Source::Git < Gem::Source spec.base_dir = base_dir spec.extension_dir = - File.join base_dir, 'extensions', Gem::Platform.local.to_s, Gem.extension_api_version, "#{name}-#{dir_shortref}" spec.full_gem_path = File.dirname spec.loaded_from if spec @@ -226,11 +226,11 @@ class Gem::Source::Git < Gem::Source # A hash for the git gem based on the git repository URI. def uri_hash # :nodoc: - require_relative '../openssl' normalized = if @repository =~ %r{^\w+://(\w+@)?} - uri = URI(@repository).normalize.to_s.sub %r{/$},'' uri.sub(/\A(\w+)/) { $1.downcase } else @repository @@ -33,6 +33,6 @@ class Gem::Source::Installed < Gem::Source end def pretty_print(q) # :nodoc: - q.text '[Installed]' end end @@ -29,7 +29,7 @@ class Gem::Source::Local < Gem::Source end def inspect # :nodoc: - keys = @specs ? @specs.keys.sort : 'NOT LOADED' "#<%s specs: %p>" % [self.class, keys] end @@ -121,7 +121,7 @@ class Gem::Source::Local < Gem::Source end def pretty_print(q) # :nodoc: - q.group 2, '[Local gems:', ']' do q.breakable q.seplist @specs.keys do |v| q.text v.full_name @@ -42,7 +42,7 @@ class Gem::Source::SpecificFile < Gem::Source end def pretty_print(q) # :nodoc: - q.group 2, '[SpecificFile:', ']' do q.breakable q.text @path end @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative 'remote_fetcher' -require_relative 'user_interaction' -require_relative 'errors' -require_relative 'text' -require_relative 'name_tuple' ## # SpecFetcher handles metadata updates from remote gem repositories. @@ -171,19 +171,19 @@ class Gem::SpecFetcher # alternative gem names. def suggest_gems_from_name(gem_name, type = :latest, num_results = 5) - gem_name = gem_name.downcase.tr('_-', '') max = gem_name.size / 2 names = available_specs(type).first.values.flatten(1) matches = names.map do |n| next unless n.match_platform? - [n.name, 0] if n.name.downcase.tr('_-', '').include?(gem_name) end.compact if matches.length < num_results matches += names.map do |n| next unless n.match_platform? - distance = levenshtein_distance gem_name, n.name.downcase.tr('_-', '') next if distance >= max return [n.name] if distance == 0 [n.name, distance] @@ -6,11 +6,11 @@ # See LICENSE.txt for permissions. #++ -require_relative 'deprecate' -require_relative 'basic_specification' -require_relative 'stub_specification' -require_relative 'platform' -require_relative 'util/list' ## # The Specification class contains the information for a gem. Typically @@ -74,20 +74,20 @@ class Gem::Specification < Gem::BasicSpecification # key should be equal to the CURRENT_SPECIFICATION_VERSION. SPECIFICATION_VERSION_HISTORY = { # :nodoc: - -1 => ['(RubyGems versions up to and including 0.7 did not have versioned specifications)'], 1 => [ 'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"', '"test_file=x" is a shortcut for "test_files=[x]"', ], 2 => [ 'Added "required_rubygems_version"', - 'Now forward-compatible with future versions', ], 3 => [ - 'Added Fixnum validation to the specification_version', ], 4 => [ - 'Added sandboxed freeform metadata to the specification version.', ], }.freeze @@ -126,7 +126,7 @@ class Gem::Specification < Gem::BasicSpecification @@default_value = { :authors => [], :autorequire => nil, - :bindir => 'bin', :cert_chain => [], :date => nil, :dependencies => [], @@ -143,7 +143,7 @@ class Gem::Specification < Gem::BasicSpecification :platform => Gem::Platform::RUBY, :post_install_message => nil, :rdoc_options => [], - :require_paths => ['lib'], :required_ruby_version => Gem::Requirement.default, :required_rubygems_version => Gem::Requirement.default, :requirements => [], @@ -489,12 +489,12 @@ class Gem::Specification < Gem::BasicSpecification # legacy constants when nil, Gem::Platform::RUBY then @new_platform = Gem::Platform::RUBY - when 'mswin32' then # was Gem::Platform::WIN32 - @new_platform = Gem::Platform.new 'x86-mswin32' - when 'i586-linux' then # was Gem::Platform::LINUX_586 - @new_platform = Gem::Platform.new 'x86-linux' - when 'powerpc-darwin' then # was Gem::Platform::DARWIN - @new_platform = Gem::Platform.new 'ppc-darwin' else @new_platform = Gem::Platform.new platform end @@ -1149,7 +1149,7 @@ class Gem::Specification < Gem::BasicSpecification file = file.dup.tap(&Gem::UNTAINT) return unless File.file?(file) - code = Gem.open_file(file, 'r:UTF-8:-', &:read) code.tap(&Gem::UNTAINT) @@ -1390,7 +1390,7 @@ class Gem::Specification < Gem::BasicSpecification @required_rubygems_version, @original_platform, @dependencies, - '', # rubyforge_project @email, @authors, @description, @@ -1608,7 +1608,7 @@ class Gem::Specification < Gem::BasicSpecification return if default_gem? return if File.exist? gem_build_complete_path return if !File.writable?(base_dir) - return if !File.exist?(File.join(base_dir, 'extensions')) begin # We need to require things in $LOAD_PATH without looking for the @@ -1616,9 +1616,9 @@ class Gem::Specification < Gem::BasicSpecification unresolved_deps = Gem::Specification.unresolved_deps.dup Gem::Specification.unresolved_deps.clear - require_relative 'config_file' - require_relative 'ext' - require_relative 'user_interaction' ui = Gem::SilentUI.new Gem::DefaultUserInteraction.use_ui ui do @@ -1837,7 +1837,7 @@ class Gem::Specification < Gem::BasicSpecification # spec.doc_dir 'ri' # => "/path/to/gem_repo/doc/a-1/ri" def doc_dir(type = nil) - @doc_dir ||= File.join base_dir, 'doc', full_name if type File.join @doc_dir, type @@ -1849,17 +1849,17 @@ class Gem::Specification < Gem::BasicSpecification def encode_with(coder) # :nodoc: mark_version - coder.add 'name', @name - coder.add 'version', @version platform = case @original_platform - when nil, '' then - 'ruby' when String then @original_platform else @original_platform.to_s end - coder.add 'platform', platform attributes = @@attributes.map(&:to_s) - %w[name version platform] attributes.each do |name| @@ -2229,7 +2229,7 @@ class Gem::Specification < Gem::BasicSpecification end def pretty_print(q) # :nodoc: - q.group 2, 'Gem::Specification.new do |s|', 'end' do q.breakable attributes = @@attributes - [:name, :version] @@ -2324,7 +2324,7 @@ class Gem::Specification < Gem::BasicSpecification # Returns the full path to this spec's ri directory. def ri_dir - @ri_dir ||= File.join base_dir, 'ri', full_name end ## @@ -2334,13 +2334,13 @@ class Gem::Specification < Gem::BasicSpecification def ruby_code(obj) case obj when String then obj.dump + ".freeze" - when Array then '[' + obj.map {|x| ruby_code x }.join(", ") + ']' when Hash then seg = obj.keys.sort.map {|k| "#{k.to_s.dump} => #{obj[k].to_s.dump}" } "{ #{seg.join(', ')} }" when Gem::Version then obj.to_s.dump - when DateLike then obj.strftime('%Y-%m-%d').dump - when Time then obj.strftime('%Y-%m-%d').dump when Numeric then obj.inspect when true, false, nil then obj.inspect when Gem::Platform then "Gem::Platform.new(#{obj.to_a.inspect})" @@ -2562,14 +2562,14 @@ class Gem::Specification < Gem::BasicSpecification # back, we have to check again here to make sure that our # psych code was properly loaded, and load it if not. unless Gem.const_defined?(:NoAliasYAMLTree) - require_relative 'psych_tree' end builder = Gem::NoAliasYAMLTree.create builder << self ast = builder.tree - require 'stringio' io = StringIO.new io.set_encoding Encoding::UTF_8 @@ -2656,7 +2656,7 @@ class Gem::Specification < Gem::BasicSpecification # skip to set required_ruby_version when d rubygems. # It caused to raise CircularDependencyError if @version.prerelease? && (@name.nil? || @name.strip != "rubygems") - self.required_rubygems_version = '> 1.3.1' end invalidate_memoized_attributes @@ -1,4 +1,4 @@ -require_relative 'user_interaction' class Gem::SpecificationPolicy include Gem::UserInteraction @@ -120,7 +120,7 @@ class Gem::SpecificationPolicy metadata = @specification.metadata unless Hash === metadata - error 'metadata must be a hash' end metadata.each do |key, value| @@ -188,7 +188,7 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: prerelease_dep && [email protected]? open_ended = dep.requirement.requirements.all? do |op, version| - not version.prerelease? and (op == '>' or op == '>=') end if open_ended @@ -198,12 +198,12 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: base = segments.first 2 - recommendation = if (op == '>' || op == '>=') && segments == [0] " use a bounded requirement, such as '~> x.y'" else - bugfix = if op == '>' ", '> #{dep_version}'" - elsif op == '>=' and base != segments ", '>= #{dep_version}'" end @@ -286,7 +286,7 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: def validate_require_paths return unless @specification.raw_require_paths.empty? - error 'specification must have at least one require_path' end def validate_non_files @@ -310,7 +310,7 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: def validate_specification_version return if @specification.specification_version.is_a?(Integer) - error 'specification_version must be an Integer (did you mean version?)' end def validate_platform @@ -380,7 +380,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li WARNING end - LAZY = '"FIxxxXME" or "TOxxxDO"'.gsub(/xxx/, '') LAZY_PATTERN = /\AFI XME|\ATO DO/x.freeze HOMEPAGE_URI_PATTERN = /\A[a-z][a-z\d+.-]*:/i.freeze @@ -405,7 +405,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li # Make sure a homepage is valid HTTP/HTTPS URI if homepage and not homepage.empty? - require 'uri' begin homepage_uri = URI.parse(homepage) unless [URI::HTTP, URI::HTTPS].member? homepage_uri.class @@ -445,7 +445,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li def validate_shebang_line_in(executable) executable_path = File.join(@specification.bindir, executable) - return if File.read(executable_path, 2) == '#!' warning "#{executable_path} is missing #! line" end @@ -457,11 +457,11 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li end def validate_extensions # :nodoc: - require_relative 'ext' builder = Gem::Ext::Builder.new(@specification) rake_extension = @specification.extensions.any? {|s| builder.builder_for(s) == Gem::Ext::RakeBuilder } - rake_dependency = @specification.dependencies.any? {|d| d.name == 'rake' } warning <<-WARNING if rake_extension && !rake_dependency You have specified rake based extension, but rake is not added as dependency. It is recommended to add rake as a dependency in gemspec since there's no guarantee rake will be already installed. @@ -9,7 +9,7 @@ class Gem::StubSpecification < Gem::BasicSpecification PREFIX = "# stub: ".freeze # :nodoc: - OPEN_MODE = 'r:UTF-8:-'.freeze class StubLine # :nodoc: all attr_reader :name, :version, :platform, :require_paths, :extensions, @@ -19,9 +19,9 @@ class Gem::StubSpecification < Gem::BasicSpecification # These are common require paths. REQUIRE_PATHS = { # :nodoc: - 'lib' => 'lib'.freeze, - 'test' => 'test'.freeze, - 'ext' => 'ext'.freeze, }.freeze # These are common require path lists. This hash is used to optimize @@ -29,7 +29,7 @@ class Gem::StubSpecification < Gem::BasicSpecification # in their require paths, so lets take advantage of that by pre-allocating # a require path list for that case. REQUIRE_PATH_LIST = { # :nodoc: - 'lib' => ['lib'].freeze, }.freeze def initialize(data, extensions) @@ -1,3 +1,3 @@ # frozen_string_literal: true -require_relative 'tsort/lib/tsort' @@ -5,12 +5,12 @@ # See LICENSE.txt for permissions. #++ -require 'fileutils' -require_relative '../rubygems' -require_relative 'installer_uninstaller_utils' -require_relative 'dependency_list' -require_relative 'rdoc' -require_relative 'user_interaction' ## # An Uninstaller. @@ -302,8 +302,8 @@ class Gem::Uninstaller # Is +spec+ in +gem_dir+? def path_ok?(gem_dir, spec) - full_path = File.join gem_dir, 'gems', spec.full_name - original_path = File.join gem_dir, 'gems', spec.original_name full_path == spec.full_gem_path || original_path == spec.full_gem_path end @@ -332,10 +332,10 @@ class Gem::Uninstaller # Asks if it is OK to remove +spec+. Returns true if it is OK. def ask_if_ok(spec) # :nodoc: - msg = [''] - msg << 'You have requested to uninstall the gem:' msg << "\t#{spec.full_name}" - msg << '' siblings = Gem::Specification.select do |s| s.name == spec.name && s.full_name != spec.full_name @@ -347,8 +347,8 @@ class Gem::Uninstaller end end - msg << 'If you remove this gem, these dependencies will not be met.' - msg << 'Continue with Uninstall?' return ask_yes_no(msg.join("\n"), false) end @@ -360,7 +360,7 @@ class Gem::Uninstaller # of what it did for us to find rather than trying to recreate # it again. if @format_executable - require_relative 'installer' Gem::Installer.exec_format % File.basename(filename) else filename @@ -66,7 +66,7 @@ class Gem::Uri def redact_credentials_from(text) return text unless valid_uri? && password? && text.include?(to_s) - text.sub(password, 'REDACTED') end def method_missing(method_name, *args, &blk) @@ -97,11 +97,11 @@ class Gem::Uri end def with_redacted_user - clone.tap {|uri| uri.user = 'REDACTED' } end def with_redacted_password - clone.tap {|uri| uri.password = 'REDACTED' } end def valid_uri? @@ -113,7 +113,7 @@ class Gem::Uri end def oauth_basic? - password == 'x-oauth-basic' end def token? @@ -17,7 +17,7 @@ class Gem::UriFormatter # Creates a new URI formatter for +uri+. def initialize(uri) - require 'cgi' @uri = uri end @@ -5,8 +5,8 @@ # See LICENSE.txt for permissions. #++ -require_relative 'deprecate' -require_relative 'text' ## # Module that defines the default UserInteraction. Any class including this @@ -148,7 +148,7 @@ module Gem::UserInteraction ## # Displays the given +statement+ on the standard output (or equivalent). - def say(statement = '') ui.say statement end @@ -259,11 +259,11 @@ class Gem::StreamUI default_answer = case default when nil - 'yn' when true - 'Yn' else - 'yN' end result = nil @@ -312,7 +312,7 @@ class Gem::StreamUI def require_io_console @require_io_console ||= begin begin - require 'io/console' rescue LoadError end true @@ -472,7 +472,7 @@ class Gem::StreamUI # and the +terminal_message+ when it is complete. def initialize(out_stream, size, initial_message, - terminal_message = 'complete') @out = out_stream @total = size @count = 0 @@ -1,5 +1,5 @@ # frozen_string_literal: true -require_relative 'deprecate' ## # This module contains various utility methods as module methods. @@ -10,9 +10,9 @@ module Gem::Util # Zlib::GzipReader wrapper that unzips +data+. def self.gunzip(data) - require 'zlib' - require 'stringio' - data = StringIO.new(data, 'r') gzip_reader = begin Zlib::GzipReader.new(data) @@ -29,9 +29,9 @@ module Gem::Util # Zlib::GzipWriter wrapper that zips +data+. def self.gzip(data) - require 'zlib' - require 'stringio' - zipped = StringIO.new(String.new, 'w') zipped.set_encoding Encoding::BINARY Zlib::GzipWriter.wrap zipped do |io| @@ -45,7 +45,7 @@ module Gem::Util # A Zlib::Inflate#inflate wrapper def self.inflate(data) - require 'zlib' Zlib::Inflate.inflate data end @@ -86,7 +86,7 @@ module Gem::Util loop do Dir.chdir here, &block rescue Errno::EACCES - new_here = File.expand_path('..', here) return if new_here == here # toplevel here = new_here end @@ -109,7 +109,7 @@ module Gem::Util # comes with a leading slash. def self.correct_for_windows_path(path) - if path[0].chr == '/' && path[1].chr =~ /[a-z]/i && path[2].chr == ':' path[1..-1] else path @@ -1,11 +1,11 @@ # frozen_string_literal: true -require_relative '../text' class Gem::Licenses extend Gem::Text - NONSTANDARD = 'Nonstandard'.freeze - LICENSE_REF = 'LicenseRef-.+'.freeze # Software Package Data Exchange (SPDX) standard open-source software # license identifiers @@ -5,8 +5,8 @@ # See LICENSE.txt for permissions. #++ -require_relative 'package' -require_relative 'installer' ## # Validator performs various gem file and gem database validation @@ -15,7 +15,7 @@ class Gem::Validator include Gem::UserInteraction def initialize # :nodoc: - require 'find' end private @@ -110,11 +110,11 @@ class Gem::Validator begin next unless data # HACK `gem check -a mkrf` - source = File.join gem_directory, entry['path'] File.open source, Gem.binary_mode do |f| unless f.read == data - errors[gem_name][entry['path']] = "Modified from original" end end end @@ -276,7 +276,7 @@ class Gem::Version end def yaml_initialize(tag, map) # :nodoc: - @version = map['version'] @segments = nil @hash = nil end @@ -286,7 +286,7 @@ class Gem::Version end def encode_with(coder) # :nodoc: - coder.add 'version', @version end ## @@ -311,7 +311,7 @@ class Gem::Version @@release[self] ||= if prerelease? segments = self.segments segments.pop while segments.any? {|s| String === s } - self.class.new segments.join('.') else self end @@ -5,7 +5,7 @@ # See LICENSE.txt for permissions. #++ -require_relative '../rubygems' ## # Mixin methods for --version and --platform Gem::Command options. @@ -24,7 +24,7 @@ module Gem::VersionOption end end - add_option('--platform PLATFORM', Gem::Platform, "Specify the platform of gem to #{task}", *wrap) do |value, options| unless options[:added_platform] @@ -55,7 +55,7 @@ module Gem::VersionOption Gem::Requirement.new(*value.split(/\s*,\s*/)) end - add_option('-v', '--version VERSION', Gem::Requirement, "Specify version of gem to #{task}", *wrap) do |value, options| # Allow handling for multiple --version operators |