diff options
58 files changed, 317 insertions, 556 deletions
diff --git a/lib/bundler/bundler.gemspec b/lib/bundler/bundler.gemspec index a9c9fac462..da50b46225 100644 --- a/lib/bundler/bundler.gemspec +++ b/lib/bundler/bundler.gemspec @@ -29,8 +29,8 @@ Gem::Specification.new do |s| "source_code_uri" => "https://github.com/rubygems/rubygems/tree/master/bundler", } - s.required_ruby_version = ">= 2.3.0" - s.required_rubygems_version = ">= 2.5.2" + s.required_ruby_version = ">= 2.6.0" + s.required_rubygems_version = ">= 3.0.1" s.files = Dir.glob("lib/bundler{.rb,/**/*}", File::FNM_DOTMATCH).reject {|f| File.directory?(f) } diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb index 5bcf30d82d..08fa6547fb 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -40,7 +40,7 @@ module Bundler raise InvalidOption, "Please specify gems to add." if gems.empty? version.to_a.each do |v| - raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN =~ v.to_s + raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN.match?(v.to_s) end end end diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb index 74444ad0ce..e299a5a8c2 100644 --- a/lib/bundler/cli/doctor.rb +++ b/lib/bundler/cli/doctor.rb @@ -73,12 +73,10 @@ module Bundler definition.specs.each do |spec| bundles_for_gem(spec).each do |bundle| bad_paths = dylibs(bundle).select do |f| - begin - Fiddle.dlopen(f) - false - rescue Fiddle::DLError - true - end + Fiddle.dlopen(f) + false + rescue Fiddle::DLError + true end if bad_paths.any? broken_links[spec] ||= [] diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index 8c8ebe8ff3..135bfde038 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -270,7 +270,7 @@ module Bundler Bundler.ui.info hint_text("test") result = Bundler.ui.ask "Enter a test framework. rspec/minitest/test-unit/(none):" - if result =~ /rspec|minitest|test-unit/ + if /rspec|minitest|test-unit/.match?(result) test_framework = result else test_framework = false @@ -311,7 +311,7 @@ module Bundler Bundler.ui.info hint_text("ci") result = Bundler.ui.ask "Enter a CI service. github/travis/gitlab/circle/(none):" - if result =~ /github|travis|gitlab|circle/ + if /github|travis|gitlab|circle/.match?(result) ci_template = result else ci_template = false @@ -342,7 +342,7 @@ module Bundler Bundler.ui.info hint_text("linter") result = Bundler.ui.ask "Enter a linter. rubocop/standard/(none):" - if result =~ /rubocop|standard/ + if /rubocop|standard/.match?(result) linter_template = result else linter_template = false @@ -389,7 +389,7 @@ module Bundler end def ensure_safe_gem_name(name, constant_array) - if name =~ /^\d/ + if /^\d/.match?(name) Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers." exit 1 end @@ -416,28 +416,15 @@ module Bundler end def required_ruby_version - if Gem.ruby_version < Gem::Version.new("2.4.a") then "2.3.0" - elsif Gem.ruby_version < Gem::Version.new("2.5.a") then "2.4.0" - elsif Gem.ruby_version < Gem::Version.new("2.6.a") then "2.5.0" - else - "2.6.0" - end + "2.6.0" end def rubocop_version - if Gem.ruby_version < Gem::Version.new("2.4.a") then "0.81.0" - elsif Gem.ruby_version < Gem::Version.new("2.5.a") then "1.12" - else - "1.21" - end + "1.21" end def standard_version - if Gem.ruby_version < Gem::Version.new("2.4.a") then "0.2.5" - elsif Gem.ruby_version < Gem::Version.new("2.5.a") then "1.0" - else - "1.3" - end + "1.3" end end end diff --git a/lib/bundler/compact_index_client/cache.rb b/lib/bundler/compact_index_client/cache.rb index 2d83777139..0b43581c11 100644 --- a/lib/bundler/compact_index_client/cache.rb +++ b/lib/bundler/compact_index_client/cache.rb @@ -68,7 +68,7 @@ module Bundler def info_path(name) name = name.to_s - if name =~ /[^a-z0-9_-]/ + if /[^a-z0-9_-]/.match?(name) name += "-#{SharedHelpers.digest(:MD5).hexdigest(name).downcase}" info_roots.last.join(name) else diff --git a/lib/bundler/compact_index_client/updater.rb b/lib/bundler/compact_index_client/updater.rb index 5b430dfbe2..0f7bf9bb50 100644 --- a/lib/bundler/compact_index_client/updater.rb +++ b/lib/bundler/compact_index_client/updater.rb @@ -20,63 +20,64 @@ module Bundler def initialize(fetcher) @fetcher = fetcher - require_relative "../vendored_tmpdir" end def update(local_path, remote_path, retrying = nil) headers = {} - Bundler::Dir.mktmpdir("bundler-compact-index-") do |local_temp_dir| - local_temp_path = Pathname.new(local_temp_dir).join(local_path.basename) - - # first try to fetch any new bytes on the existing file - if retrying.nil? && local_path.file? - copy_file local_path, local_temp_path - - headers["If-None-Match"] = etag_for(local_temp_path) - headers["Range"] = - if local_temp_path.size.nonzero? - # Subtract a byte to ensure the range won't be empty. - # Avoids 416 (Range Not Satisfiable) responses. - "bytes=#{local_temp_path.size - 1}-" - else - "bytes=#{local_temp_path.size}-" - end - end + local_temp_path = local_path.sub(/$/, ".#{$$}") + local_temp_path = local_temp_path.sub(/$/, ".retrying") if retrying + local_temp_path = local_temp_path.sub(/$/, ".tmp") - response = @fetcher.call(remote_path, headers) - return nil if response.is_a?(Net::HTTPNotModified) + # first try to fetch any new bytes on the existing file + if retrying.nil? && local_path.file? + copy_file local_path, local_temp_path - content = response.body + headers["If-None-Match"] = etag_for(local_temp_path) + headers["Range"] = + if local_temp_path.size.nonzero? + # Subtract a byte to ensure the range won't be empty. + # Avoids 416 (Range Not Satisfiable) responses. + "bytes=#{local_temp_path.size - 1}-" + else + "bytes=#{local_temp_path.size}-" + end + end - etag = (response["ETag"] || "").gsub(%r{\AW/}, "") - correct_response = SharedHelpers.filesystem_access(local_temp_path) do - if response.is_a?(Net::HTTPPartialContent) && local_temp_path.size.nonzero? - local_temp_path.open("a") {|f| f << slice_body(content, 1..-1) } + response = @fetcher.call(remote_path, headers) + return nil if response.is_a?(Net::HTTPNotModified) - etag_for(local_temp_path) == etag - else - local_temp_path.open("wb") {|f| f << content } + content = response.body - etag.length.zero? || etag_for(local_temp_path) == etag - end - end + etag = (response["ETag"] || "").gsub(%r{\AW/}, "") + correct_response = SharedHelpers.filesystem_access(local_temp_path) do + if response.is_a?(Net::HTTPPartialContent) && local_temp_path.size.nonzero? + local_temp_path.open("a") {|f| f << slice_body(content, 1..-1) } - if correct_response - SharedHelpers.filesystem_access(local_path) do - FileUtils.mv(local_temp_path, local_path) - end - return nil + etag_for(local_temp_path) == etag + else + local_temp_path.open("wb") {|f| f << content } + + etag.length.zero? || etag_for(local_temp_path) == etag end + end - if retrying - raise MisMatchedChecksumError.new(remote_path, etag, etag_for(local_temp_path)) + if correct_response + SharedHelpers.filesystem_access(local_path) do + FileUtils.mv(local_temp_path, local_path) end + return nil + end - update(local_path, remote_path, :retrying) + if retrying + raise MisMatchedChecksumError.new(remote_path, etag, etag_for(local_temp_path)) end + + update(local_path, remote_path, :retrying) rescue Zlib::GzipFile::Error raise Bundler::HTTPError + ensure + FileUtils.remove_file(local_temp_path) if File.exist?(local_temp_path) end def etag_for(path) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index fe807605e0..f4dcd605c2 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -295,7 +295,7 @@ module Bundler # Convert to \r\n if the existing lock has them # i.e., Windows with `git config core.autocrlf=true` - contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match("\r\n") + contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match?("\r\n") if @locked_bundler_version locked_major = @locked_bundler_version.segments.first diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 547db16190..179fea4dfd 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -324,7 +324,7 @@ module Bundler if name.is_a?(Symbol) raise GemfileError, %(You need to specify gem names as Strings. Use 'gem "#{name}"' instead) end - if name =~ /\s/ + if /\s/.match?(name) raise GemfileError, %('#{name}' is not a valid gem name because it contains whitespace) end raise GemfileError, %(an empty gem name is not valid) if name.empty? diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb index b23176588f..77838f0361 100644 --- a/lib/bundler/fetcher/compact_index.rb +++ b/lib/bundler/fetcher/compact_index.rb @@ -12,17 +12,15 @@ module Bundler method = instance_method(method_name) undef_method(method_name) define_method(method_name) do |*args, &blk| - begin - method.bind(self).call(*args, &blk) - rescue NetworkDownError, CompactIndexClient::Updater::MisMatchedChecksumError => e - raise HTTPError, e.message - rescue AuthenticationRequiredError - # Fail since we got a 401 from the server. - raise - rescue HTTPError => e - Bundler.ui.trace(e) - nil - end + method.bind(self).call(*args, &blk) + rescue NetworkDownError, CompactIndexClient::Updater::MisMatchedChecksumError => e + raise HTTPError, e.message + rescue AuthenticationRequiredError + # Fail since we got a 401 from the server. + raise + rescue HTTPError => e + Bundler.ui.trace(e) + nil end end diff --git a/lib/bundler/fetcher/downloader.rb b/lib/bundler/fetcher/downloader.rb index 0a668eb17c..2f691886ad 100644 --- a/lib/bundler/fetcher/downloader.rb +++ b/lib/bundler/fetcher/downloader.rb @@ -80,7 +80,7 @@ module Bundler private def validate_uri_scheme!(uri) - return if uri.scheme =~ /\Ahttps?\z/ + return if /\Ahttps?\z/.match?(uri.scheme) raise InvalidOption, "The request uri `#{uri}` has an invalid scheme (`#{uri.scheme}`). " \ "Did you mean `http` or `https`?" diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index d0d2a6679a..8277784a6a 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -37,7 +37,7 @@ module Bundler when Thor::Error Bundler.ui.error error.message when LoadError - raise error unless error.message =~ /cannot load such file -- openssl|openssl.so|libcrypto.so/ + raise error unless /cannot load such file -- openssl|openssl.so|libcrypto.so/.match?(error.message) Bundler.ui.error "\nCould not load OpenSSL. #{error.class}: #{error}\n#{error.backtrace.join("\n ")}" when Interrupt Bundler.ui.error "\nQuitting..." diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index 81465cec19..c2edc9b43a 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -235,7 +235,7 @@ module Bundler gemfile.each_with_index do |line, index| next unless !line.nil? && line.strip.start_with?(block_name) - if gemfile[index + 1] =~ /^\s*end\s*$/ + if /^\s*end\s*$/.match?(gemfile[index + 1]) gemfile[index] = nil gemfile[index + 1] = nil end diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 1b17de5d4e..04d7dc6f23 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -136,11 +136,7 @@ module Bundler mode = Gem.win_platform? ? "wb:UTF-8" : "w" require "erb" - content = if RUBY_VERSION >= "2.6" - ERB.new(template, :trim_mode => "-").result(binding) - else - ERB.new(template, nil, "-").result(binding) - end + content = ERB.new(template, :trim_mode => "-").result(binding) File.write(binstub_path, content, :mode => mode, :perm => 0o777 & ~File.umask) if Gem.win_platform? || options[:all_platforms] @@ -183,11 +179,7 @@ module Bundler mode = Gem.win_platform? ? "wb:UTF-8" : "w" require "erb" - content = if RUBY_VERSION >= "2.6" - ERB.new(template, :trim_mode => "-").result(binding) - else - ERB.new(template, nil, "-").result(binding) - end + content = ERB.new(template, :trim_mode => "-").result(binding) File.write("#{bin_path}/#{executable}", content, :mode => mode, :perm => 0o755) if Gem.win_platform? || options[:all_platforms] @@ -226,12 +218,10 @@ module Bundler requested_path_gems = @definition.requested_specs.select {|s| s.source.is_a?(Source::Path) } path_plugin_files = requested_path_gems.map do |spec| - begin - Bundler.rubygems.spec_matches_for_glob(spec, "rubygems_plugin#{Bundler.rubygems.suffix_pattern}") - rescue TypeError - error_message = "#{spec.name} #{spec.version} has an invalid gemspec" - raise Gem::InvalidSpecificationException, error_message - end + Bundler.rubygems.spec_matches_for_glob(spec, "rubygems_plugin#{Bundler.rubygems.suffix_pattern}") + rescue TypeError + error_message = "#{spec.name} #{spec.version} has an invalid gemspec" + raise Gem::InvalidSpecificationException, error_message end.flatten Bundler.rubygems.load_plugin_files(path_plugin_files) Bundler.rubygems.load_env_plugins diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 871f53663c..0ec5b7de8a 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -63,7 +63,7 @@ module Bundler @state = nil @specs = {} - if lockfile.match(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/) + if lockfile.match?(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/) raise LockfileError, "Your #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} contains merge conflicts.\n" \ "Run `git checkout HEAD -- #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}` first to get a clean lock." end @@ -80,7 +80,7 @@ module Bundler @state = :ruby elsif line == BUNDLED @state = :bundled_with - elsif line =~ /^[^\s]/ + elsif /^[^\s]/.match?(line) @state = nil elsif @state send("parse_#{@state}", line) diff --git a/lib/bundler/mirror.rb b/lib/bundler/mirror.rb index a63b45b47d..9d437a0951 100644 --- a/lib/bundler/mirror.rb +++ b/lib/bundler/mirror.rb @@ -148,13 +148,11 @@ module Bundler class TCPSocketProbe def replies?(mirror) MirrorSockets.new(mirror).any? do |socket, address, timeout| - begin - socket.connect_nonblock(address) - rescue Errno::EINPROGRESS - wait_for_writtable_socket(socket, address, timeout) - rescue RuntimeError # Connection failed somehow, again - false - end + socket.connect_nonblock(address) + rescue Errno::EINPROGRESS + wait_for_writtable_socket(socket, address, timeout) + rescue RuntimeError # Connection failed somehow, again + false end end diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 12d6789065..705c4c8458 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -338,11 +338,7 @@ module Gem end def glob_files_in_dir(glob, base_path) - if RUBY_VERSION >= "2.5" - Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) } - else - Dir.glob(File.join(base_path.to_s.gsub(/[\[\]]/, '\\\\\\&'), glob)).map! {|f| File.expand_path(f) } - end + Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) } end end end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 745ae05c5c..dc89dedeb2 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -64,7 +64,7 @@ module Bundler at = if local? path elsif user_ref = options["ref"] - if ref =~ /\A[a-z0-9]{4,}\z/i + if /\A[a-z0-9]{4,}\z/i.match?(ref) shortref_for_display(user_ref) else user_ref @@ -295,7 +295,7 @@ module Bundler end def uri_hash - if uri =~ %r{^\w+://(\w+@)?} + if %r{^\w+://(\w+@)?}.match?(uri) # Downcase the domain component of the URI # and strip off a trailing slash, if one is present input = Bundler::URI.parse(uri).normalize.to_s.sub(%r{/$}, "") diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index 5468536f86..e379c84741 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -250,7 +250,7 @@ module Bundler # Adds credentials to the URI def configured_uri - if /https?:/ =~ uri + if /https?:/.match?(uri) remote = Bundler::URI(uri) config_auth = Bundler.settings[remote.to_s] || Bundler.settings[remote.host] remote.userinfo ||= config_auth diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 672ecfd13b..20975e20ca 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -224,13 +224,13 @@ module Bundler # Some gem authors put absolute paths in their gemspec # and we have to save them from themselves - spec.files = spec.files.map do |p| - next p unless p =~ /\A#{Pathname::SEPARATOR_PAT}/ - next if File.directory?(p) + spec.files = spec.files.map do |path| + next path unless /\A#{Pathname::SEPARATOR_PAT}/.match?(path) + next if File.directory?(path) begin - Pathname.new(p).relative_path_from(gem_dir).to_s + Pathname.new(path).relative_path_from(gem_dir).to_s rescue ArgumentError - p + path end end.compact diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 3b640b55a9..7eefd291a2 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -145,7 +145,7 @@ module Bundler end if installed?(spec) && !force - print_using_message "Using #{version_message(spec)}" + print_using_message "Using #{version_message(spec, options[:previous_spec])}" return nil # no post-install message end @@ -163,8 +163,6 @@ module Bundler install_path = rubygems_dir bin_path = Bundler.system_bindir - Bundler.mkdir_p bin_path unless spec.executables.empty? || Bundler.rubygems.provides?(">= 2.7.5") - require_relative "../rubygems_gem_installer" installer = Bundler::RubyGemsGemInstaller.at( @@ -340,7 +338,7 @@ module Bundler def normalize_uri(uri) uri = uri.to_s - uri = "#{uri}/" unless uri =~ %r{/$} + uri = "#{uri}/" unless %r{/$}.match?(uri) require_relative "../vendored_uri" uri = Bundler::URI(uri) raise ArgumentError, "The source must be an absolute URI. For example:\n" \ @@ -383,7 +381,7 @@ module Bundler idx = @allow_local ? installed_specs.dup : Index.new Dir["#{cache_path}/*.gem"].each do |gemfile| - next if gemfile =~ /^bundler\-[\d\.]+?\.gem/ + next if /^bundler\-[\d\.]+?\.gem/.match?(gemfile) s ||= Bundler.rubygems.spec_from_gem(gemfile) s.source = self idx << s diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index 6ea2910d18..ab05e1334a 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -206,7 +206,7 @@ module Bundler def warn_on_git_protocol(source) return if Bundler.settings["git.allow_insecure"] - if source.uri =~ /^git\:/ + if /^git\:/.match?(source.uri) Bundler.ui.warn "The git source `#{source.uri}` uses the `git` protocol, " \ "which transmits data without encryption. Disable this warning with " \ "`bundle config set --local git.allow_insecure true`, or switch to the `https` " \ diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler index 77f90e735c..6dab1688f7 100644 --- a/lib/bundler/templates/Executable.bundler +++ b/lib/bundler/templates/Executable.bundler @@ -72,13 +72,7 @@ m = Module.new do bundler_gem_version = Gem::Version.new(version) - requirement = bundler_gem_version.approximate_recommendation - - return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0") - - requirement += ".a" if bundler_gem_version.prerelease? - - requirement + bundler_gem_version.approximate_recommendation end def load_bundler! diff --git a/lib/bundler/vendor/tmpdir/lib/tmpdir.rb b/lib/bundler/vendor/tmpdir/lib/tmpdir.rb deleted file mode 100644 index 70d43e0c6b..0000000000 --- a/lib/bundler/vendor/tmpdir/lib/tmpdir.rb +++ /dev/null @@ -1,154 +0,0 @@ -# frozen_string_literal: true -# -# tmpdir - retrieve temporary directory path -# -# $Id$ -# - -require_relative '../../fileutils/lib/fileutils' -begin - require 'etc.so' -rescue LoadError # rescue LoadError for miniruby -end - -class Bundler::Dir < Dir - - @systmpdir ||= defined?(Etc.systmpdir) ? Etc.systmpdir : '/tmp' - - ## - # Returns the operating system's temporary file path. - - def self.tmpdir - tmp = nil - ['TMPDIR', 'TMP', 'TEMP', ['system temporary path', @systmpdir], ['/tmp']*2, ['.']*2].each do |name, dir = ENV[name]| - next if !dir - dir = File.expand_path(dir) - stat = File.stat(dir) rescue next - case - when !stat.directory? - warn "#{name} is not a directory: #{dir}" - when !stat.writable? - warn "#{name} is not writable: #{dir}" - when stat.world_writable? && !stat.sticky? - warn "#{name} is world-writable: #{dir}" - else - tmp = dir - break - end - end - raise ArgumentError, "could not find a temporary directory" unless tmp - tmp - end - - # Bundler::Dir.mktmpdir creates a temporary directory. - # - # The directory is created with 0700 permission. - # Application should not change the permission to make the temporary directory accessible from other users. - # - # The prefix and suffix of the name of the directory is specified by - # the optional first argument, <i>prefix_suffix</i>. - # - If it is not specified or nil, "d" is used as the prefix and no suffix is used. - # - If it is a string, it is used as the prefix and no suffix is used. - # - If it is an array, first element is used as the prefix and second element is used as a suffix. - # - # Bundler::Dir.mktmpdir {|dir| dir is ".../d..." } - # Bundler::Dir.mktmpdir("foo") {|dir| dir is ".../foo..." } - # Bundler::Dir.mktmpdir(["foo", "bar"]) {|dir| dir is ".../foo...bar" } - # - # The directory is created under Bundler::Dir.tmpdir or - # the optional second argument <i>tmpdir</i> if non-nil value is given. - # - # Bundler::Dir.mktmpdir {|dir| dir is "#{Bundler::Dir.tmpdir}/d..." } - # Bundler::Dir.mktmpdir(nil, "/var/tmp") {|dir| dir is "/var/tmp/d..." } - # - # If a block is given, - # it is yielded with the path of the directory. - # The directory and its contents are removed - # using Bundler::FileUtils.remove_entry before Bundler::Dir.mktmpdir returns. - # The value of the block is returned. - # - # Bundler::Dir.mktmpdir {|dir| - # # use the directory... - # open("#{dir}/foo", "w") { ... } - # } - # - # If a block is not given, - # The path of the directory is returned. - # In this case, Bundler::Dir.mktmpdir doesn't remove the directory. - # - # dir = Bundler::Dir.mktmpdir - # begin - # # use the directory... - # open("#{dir}/foo", "w") { ... } - # ensure - # # remove the directory. - # Bundler::FileUtils.remove_entry dir - # end - # - def self.mktmpdir(prefix_suffix=nil, *rest, **options) - base = nil - path = Tmpname.create(prefix_suffix || "d", *rest, **options) {|p, _, _, d| - base = d - mkdir(p, 0700) - } - if block_given? - begin - yield path.dup - ensure - unless base - stat = File.stat(File.dirname(path)) - if stat.world_writable? and !stat.sticky? - raise ArgumentError, "parent directory is world writable but not sticky" - end - end - Bundler::FileUtils.remove_entry path - end - else - path - end - end - - module Tmpname # :nodoc: - module_function - - def tmpdir - Bundler::Dir.tmpdir - end - - UNUSABLE_CHARS = "^,-.0-9A-Z_a-z~" - - class << (RANDOM = Random.new) - MAX = 36**6 # < 0x100000000 - def next - rand(MAX).to_s(36) - end - end - private_constant :RANDOM - - def create(basename, tmpdir=nil, max_try: nil, **opts) - origdir = tmpdir - tmpdir ||= tmpdir() - n = nil - prefix, suffix = basename - prefix = (String.try_convert(prefix) or - raise ArgumentError, "unexpected prefix: #{prefix.inspect}") - prefix = prefix.delete(UNUSABLE_CHARS) - suffix &&= (String.try_convert(suffix) or - raise ArgumentError, "unexpected suffix: #{suffix.inspect}") - suffix &&= suffix.delete(UNUSABLE_CHARS) - begin - t = Time.now.strftime("%Y%m%d") - path = "#{prefix}#{t}-#{$$}-#{RANDOM.next}"\ - "#{n ? %[-#{n}] : ''}#{suffix||''}" - path = File.join(tmpdir, path) - yield(path, n, opts, origdir) - rescue Errno::EEXIST - n ||= 0 - n += 1 - retry if !max_try or n < max_try - raise "cannot generate temporary name using `#{basename}' under `#{tmpdir}'" - end - path - end - end -end diff --git a/lib/bundler/vendored_tmpdir.rb b/lib/bundler/vendored_tmpdir.rb deleted file mode 100644 index 43b4fa75fe..0000000000 --- a/lib/bundler/vendored_tmpdir.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -module Bundler; end -require_relative "vendor/tmpdir/lib/tmpdir" diff --git a/lib/bundler/worker.rb b/lib/bundler/worker.rb index 5e4ee21c51..3ebd6f01db 100644 --- a/lib/bundler/worker.rb +++ b/lib/bundler/worker.rb @@ -87,14 +87,12 @@ module Bundler creation_errors = [] @threads = Array.new(@size) do |i| - begin - Thread.start { process_queue(i) }.tap do |thread| - thread.name = "#{name} Worker ##{i}" if thread.respond_to?(:name=) - end - rescue ThreadError => e - creation_errors << e - nil + Thread.start { process_queue(i) }.tap do |thread| + thread.name = "#{name} Worker ##{i}" if thread.respond_to?(:name=) end + rescue ThreadError => e + creation_errors << e + nil end.compact add_interrupt_handler unless @threads.empty? diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 37c9b4ada1..c779b7c244 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -107,7 +107,7 @@ class Gem::Commands::SetupCommand < Gem::Command end def check_ruby_version - required_version = Gem::Requirement.new ">= 2.3.0" + required_version = Gem::Requirement.new ">= 2.6.0" unless required_version.satisfied_by? Gem.ruby_version alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}" diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 7c24fedcde..5c90981645 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -329,14 +329,8 @@ command to remove old versions. Gem::Version.new("3.2.3") elsif Gem.ruby_version > Gem::Version.new("2.7.a") Gem::Version.new("3.1.2") - elsif Gem.ruby_version > Gem::Version.new("2.6.a") - Gem::Version.new("3.0.1") - elsif Gem.ruby_version > Gem::Version.new("2.5.a") - Gem::Version.new("2.7.3") - elsif Gem.ruby_version > Gem::Version.new("2.4.a") - Gem::Version.new("2.6.8") else - Gem::Version.new("2.5.2") + Gem::Version.new("3.0.1") end end end diff --git a/lib/rubygems/core_ext/kernel_warn.rb b/lib/rubygems/core_ext/kernel_warn.rb index 14a69938ca..f0f173c0b1 100644 --- a/lib/rubygems/core_ext/kernel_warn.rb +++ b/lib/rubygems/core_ext/kernel_warn.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -# `uplevel` keyword argument of Kernel#warn is available since ruby 2.5. -if RUBY_VERSION >= "2.5" && !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES +if !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES module Kernel rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path. diff --git a/lib/rubygems/security.rb b/lib/rubygems/security.rb index 2ba9562fd4..3ba8c6957c 100644 --- a/lib/rubygems/security.rb +++ b/lib/rubygems/security.rb @@ -434,13 +434,6 @@ module Gem::Security end ## - # In Ruby 2.3 EC doesn't implement the private_key? but not the private? method - - if defined?(OpenSSL::PKey::EC) && Gem::Version.new(String.new(RUBY_VERSION)) < Gem::Version.new("2.4.0") - OpenSSL::PKey::EC.send(:alias_method, :private?, :private_key?) - end - - ## # Creates a self-signed certificate with an issuer and subject from +email+, # a subject alternative name of +email+ and the given +extensions+ for the # +key+. @@ -492,13 +485,7 @@ module Gem::Security 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 - domain_key = OpenSSL::PKey::EC.new(EC_NAME) - domain_key.generate_key - domain_key - end + OpenSSL::PKey::EC.generate(EC_NAME) else raise Gem::Security::Exception, "#{algorithm} algorithm not found. RSA, DSA, and EC algorithms are supported." diff --git a/lib/rubygems/util.rb b/lib/rubygems/util.rb index 356c46a5a1..05e5788932 100644 --- a/lib/rubygems/util.rb +++ b/lib/rubygems/util.rb @@ -97,11 +97,7 @@ module Gem::Util # returning absolute paths to the matching files. def self.glob_files_in_dir(glob, base_path) - if RUBY_VERSION >= "2.5" - Dir.glob(glob, base: base_path).map! {|f| File.expand_path(f, base_path) } - else - Dir.glob(File.expand_path(glob, base_path)) - end + Dir.glob(glob, base: base_path).map! {|f| File.expand_path(f, base_path) } end ## diff --git a/libexec/bundle b/libexec/bundle index 73a6397e77..77b77d8ef8 100755 --- a/libexec/bundle +++ b/libexec/bundle @@ -15,10 +15,7 @@ else require "bundler" end -# Workaround for non-activated bundler spec due to missing https://github.com/rubygems/rubygems/commit/4e306d7bcdee924b8d80ca9db6125aa59ee4e5a3 -gem "bundler", Bundler::VERSION if Gem.rubygems_version < Gem::Version.new("2.6.2") - -if Gem.rubygems_version < Gem::Version.new("3.2.3") && Gem.ruby_version < Gem::Version.new("2.6.a") && !ENV["BUNDLER_NO_OLD_RUBYGEMS_WARNING"] +if Gem.rubygems_version < Gem::Version.new("3.2.3") && Gem.ruby_version < Gem::Version.new("3.0.a") && !ENV["BUNDLER_NO_OLD_RUBYGEMS_WARNING"] Bundler.ui.warn \ "Your RubyGems version (#{Gem::VERSION}) has a bug that prevents " \ "`required_ruby_version` from working for Bundler. Any scripts that use " \ diff --git a/spec/bundler/bundler/env_spec.rb b/spec/bundler/bundler/env_spec.rb index fb950c3c60..186b207b9f 100644 --- a/spec/bundler/bundler/env_spec.rb +++ b/spec/bundler/bundler/env_spec.rb @@ -34,8 +34,6 @@ RSpec.describe Bundler::Env do end it "prints user home" do - skip "needs to use a valid HOME" if Gem.win_platform? && RUBY_VERSION < "2.6.0" - with_clear_paths("HOME", "/a/b/c") do out = described_class.report expect(out).to include("User Home /a/b/c") @@ -43,8 +41,6 @@ RSpec.describe Bundler::Env do end it "prints user path" do - skip "needs to use a valid HOME" if Gem.win_platform? && RUBY_VERSION < "2.6.0" - with_clear_paths("HOME", "/a/b/c") do allow(File).to receive(:exist?) allow(File).to receive(:exist?).with("/a/b/c/.gem").and_return(true) diff --git a/spec/bundler/commands/config_spec.rb b/spec/bundler/commands/config_spec.rb index 6148b1c7ce..ede93f99eb 100644 --- a/spec/bundler/commands/config_spec.rb +++ b/spec/bundler/commands/config_spec.rb @@ -143,17 +143,15 @@ RSpec.describe ".bundle/config" do end it "has lower precedence than env" do - begin - ENV["BUNDLE_FOO"] = "env" + ENV["BUNDLE_FOO"] = "env" - bundle "config set --global foo global" - expect(out).to match(/You have a bundler environment variable for foo set to "env"/) + bundle "config set --global foo global" + expect(out).to match(/You have a bundler environment variable for foo set to "env"/) - run "puts Bundler.settings[:foo]" - expect(out).to eq("env") - ensure - ENV.delete("BUNDLE_FOO") - end + run "puts Bundler.settings[:foo]" + expect(out).to eq("env") + ensure + ENV.delete("BUNDLE_FOO") end it "can be deleted" do @@ -221,15 +219,13 @@ RSpec.describe ".bundle/config" do end it "has higher precedence than env" do - begin - ENV["BUNDLE_FOO"] = "env" - bundle "config set --local foo local" - - run "puts Bundler.settings[:foo]" - expect(out).to eq("local") - ensure - ENV.delete("BUNDLE_FOO") - end + ENV["BUNDLE_FOO"] = "env" + bundle "config set --local foo local" + + run "puts Bundler.settings[:foo]" + expect(out).to eq("local") + ensure + ENV.delete("BUNDLE_FOO") end it "can be deleted" do diff --git a/spec/bundler/commands/viz_spec.rb b/spec/bundler/commands/viz_spec.rb index 0efb24b504..811fc255ef 100644 --- a/spec/bundler/commands/viz_spec.rb +++ b/spec/bundler/commands/viz_spec.rb @@ -2,9 +2,7 @@ RSpec.describe "bundle viz", :bundler => "< 3", :if => Bundler.which("dot") do before do - graphviz_version = RUBY_VERSION >= "2.4" ? "1.2.5" : "1.2.4" - - realworld_system_gems "ruby-graphviz --version #{graphviz_version}" + realworld_system_gems "ruby-graphviz --version 1.2.5" end it "graphs gems from the Gemfile" do diff --git a/spec/bundler/install/bundler_spec.rb b/spec/bundler/install/bundler_spec.rb index ae7c94c31f..e7ec3bc7e7 100644 --- a/spec/bundler/install/bundler_spec.rb +++ b/spec/bundler/install/bundler_spec.rb @@ -210,6 +210,33 @@ RSpec.describe "bundle install" do expect(err).to be_empty end + it "prints the previous version when switching to a previously downloaded gem" do + build_repo4 do + build_gem "rails", "7.0.3" + build_gem "rails", "7.0.4" + end + + bundle "config set path.system true" + + install_gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem 'rails', "7.0.4" + G + + install_gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem 'rails', "7.0.3" + G + + install_gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem 'rails', "7.0.4" + G + + expect(out).to include("Using rails 7.0.4 (was 7.0.3)") + expect(err).to be_empty + end + it "can install dependencies with newer bundler version with system gems" do bundle "config set path.system true" diff --git a/spec/bundler/install/gemfile/git_spec.rb b/spec/bundler/install/gemfile/git_spec.rb index 4ac9f186ec..7d263a2fe5 100644 --- a/spec/bundler/install/gemfile/git_spec.rb +++ b/spec/bundler/install/gemfile/git_spec.rb @@ -1237,7 +1237,7 @@ RSpec.describe "bundle install with git sources" do s.extensions = ["ext/extconf.rb"] s.write "ext/extconf.rb", <<-RUBY require "mkmf" - $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] unless RUBY_VERSION < "2.4" + $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] create_makefile("foo") RUBY s.write "ext/foo.c", "void Init_foo() {}" diff --git a/spec/bundler/install/gems/native_extensions_spec.rb b/spec/bundler/install/gems/native_extensions_spec.rb index c3e05586bd..5c18d2cc51 100644 --- a/spec/bundler/install/gems/native_extensions_spec.rb +++ b/spec/bundler/install/gems/native_extensions_spec.rb @@ -7,7 +7,7 @@ RSpec.describe "installing a gem with native extensions" do s.extensions = ["ext/extconf.rb"] s.write "ext/extconf.rb", <<-E require "mkmf" - $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] unless RUBY_VERSION < "2.4" + $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] name = "c_extension_bundle" dir_config(name) raise "OMG" unless with_config("c_extension") == "hello" @@ -52,7 +52,7 @@ RSpec.describe "installing a gem with native extensions" do s.extensions = ["ext/extconf.rb"] s.write "ext/extconf.rb", <<-E require "mkmf" - $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] unless RUBY_VERSION < "2.4" + $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] name = "c_extension_bundle" dir_config(name) raise "OMG" unless with_config("c_extension") == "hello" @@ -97,7 +97,7 @@ RSpec.describe "installing a gem with native extensions" do s.extensions = ["ext/extconf.rb"] s.write "ext/extconf.rb", <<-E require "mkmf" - $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] unless RUBY_VERSION < "2.4" + $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] name = "c_extension_bundle_#{n}" dir_config(name) raise "OMG" unless with_config("c_extension_#{n}") == "#{n}" @@ -150,7 +150,7 @@ RSpec.describe "installing a gem with native extensions" do s.extensions = ["ext/extconf.rb"] s.write "ext/extconf.rb", <<-E require "mkmf" - $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] unless RUBY_VERSION < "2.4" + $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] name = "c_extension_bundle" dir_config(name) raise "OMG" unless with_config("c_extension") == "hello" && with_config("c_extension_bundle-dir") == "hola" diff --git a/spec/bundler/other/major_deprecation_spec.rb b/spec/bundler/other/major_deprecation_spec.rb index e14b5ff003..6465bea0d2 100644 --- a/spec/bundler/other/major_deprecation_spec.rb +++ b/spec/bundler/other/major_deprecation_spec.rb @@ -589,8 +589,7 @@ RSpec.describe "major deprecations" do context "bundle viz" do before do - graphviz_version = RUBY_VERSION >= "2.4" ? "1.2.5" : "1.2.4" - realworld_system_gems "ruby-graphviz --version #{graphviz_version}" + realworld_system_gems "ruby-graphviz --version 1.2.5" create_file "gems.rb", "source \"#{file_uri_for(gem_repo1)}\"" bundle "viz" end diff --git a/spec/bundler/quality_es_spec.rb b/spec/bundler/quality_es_spec.rb index 90968e6270..0dbd77e451 100644 --- a/spec/bundler/quality_es_spec.rb +++ b/spec/bundler/quality_es_spec.rb @@ -41,7 +41,7 @@ RSpec.describe "La biblioteca si misma" do included = /ronn/ error_messages = [] man_tracked_files.each do |filename| - next unless filename =~ included + next unless filename&.match?(included) error_messages << check_for_expendable_words(filename) error_messages << check_for_specific_pronouns(filename) end @@ -52,7 +52,7 @@ RSpec.describe "La biblioteca si misma" do error_messages = [] exempt = /vendor/ lib_tracked_files.each do |filename| - next if filename =~ exempt + next if filename&.match?(exempt) error_messages << check_for_expendable_words(filename) error_messages << check_for_specific_pronouns(filename) end diff --git a/spec/bundler/quality_spec.rb b/spec/bundler/quality_spec.rb index 86a927c361..86e5a51f7f 100644 --- a/spec/bundler/quality_spec.rb +++ b/spec/bundler/quality_spec.rb @@ -12,7 +12,7 @@ RSpec.describe "The library itself" do failing_lines = [] each_line(filename) do |line, number| - failing_lines << number + 1 if line =~ merge_conflicts_regex + failing_lines << number + 1 if line&.match?(merge_conflicts_regex) end return if failing_lines.empty? @@ -32,8 +32,8 @@ RSpec.describe "The library itself" do def check_for_extra_spaces(filename) failing_lines = [] each_line(filename) do |line, number| - next if line =~ /^\s+#.*\s+\n$/ - failing_lines << number + 1 if line =~ /\s+\n$/ + next if /^\s+#.*\s+\n$/.match?(line) + failing_lines << number + 1 if /\s+\n$/.match?(line) end return if failing_lines.empty? @@ -45,7 +45,7 @@ RSpec.describe "The library itself" do failing_lines = [] each_line(filename) do |line, number| - failing_lines << number + 1 if line =~ /’/ + failing_lines << number + 1 if /’/.match?(line) end return if failing_lines.empty? @@ -89,7 +89,7 @@ RSpec.describe "The library itself" do exempt = /\.gitmodules|fixtures|vendor|LICENSE|vcr_cassettes|rbreadline\.diff|index\.txt$/ error_messages = [] tracked_files.each do |filename| - next if filename =~ exempt + next if filename&.match?(exempt) error_messages << check_for_tab_characters(filename) error_messages << check_for_extra_spaces(filename) end @@ -100,7 +100,7 @@ RSpec.describe "The library itself" do exempt = /vendor|vcr_cassettes|LICENSE|rbreadline\.diff/ error_messages = [] tracked_files.each do |filename| - next if filename =~ exempt + next if filename&.match?(exempt) error_messages << check_for_straneous_quotes(filename) end expect(error_messages.compact).to be_well_formed @@ -110,7 +110,7 @@ RSpec.describe "The library itself" do error_messages = [] exempt = %r{lock/lockfile_spec|quality_spec|vcr_cassettes|\.ronn|lockfile_parser\.rb} tracked_files.each do |filename| - next if filename =~ exempt + next if filename&.match?(exempt) error_messages << check_for_git_merge_conflicts(filename) end expect(error_messages.compact).to be_well_formed @@ -120,7 +120,7 @@ RSpec.describe "The library itself" do included = /ronn/ error_messages = [] man_tracked_files.each do |filename| - next unless filename =~ included + next unless filename&.match?(included) error_messages << check_for_expendable_words(filename) error_messages << check_for_specific_pronouns(filename) end @@ -131,7 +131,7 @@ RSpec.describe "The library itself" do error_messages = [] exempt = /vendor|vcr_cassettes|CODE_OF_CONDUCT/ lib_tracked_files.each do |filename| - next if filename =~ exempt + next if filename&.match?(exempt) error_messages << check_for_expendable_words(filename) error_messages << check_for_specific_pronouns(filename) end @@ -229,7 +229,7 @@ RSpec.describe "The library itself" do exempt = %r{templates/|\.5|\.1|vendor/} all_bad_requires = [] lib_tracked_files.each do |filename| - next if filename =~ exempt + next if filename&.match?(exempt) each_line(filename) do |line, number| line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" } end diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index 044be570b0..f244289c88 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -1304,11 +1304,7 @@ end describe "default gem activation" do let(:exemptions) do - exempts = if Gem.rubygems_version >= Gem::Version.new("2.7") - %w[did_you_mean] - else - %w[io-console openssl] - end << "bundler" + exempts = %w[did_you_mean bundler] exempts << "uri" if Gem.ruby_version >= Gem::Version.new("2.7") exempts << "pathname" if Gem.ruby_version >= Gem::Version.new("3.0") exempts << "set" unless Gem.rubygems_version >= Gem::Version.new("3.2.6") diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb index 2f4a1d45e4..6a7e2891a6 100644 --- a/spec/bundler/spec_helper.rb +++ b/spec/bundler/spec_helper.rb @@ -96,23 +96,21 @@ RSpec.configure do |config| end config.around :each do |example| - begin - FileUtils.cp_r pristine_system_gem_path, system_gem_path - - with_gem_path_as(system_gem_path) do - Bundler.ui.silence { example.run } - - all_output = all_commands_output - if example.exception && !all_output.empty? - message = all_output + "\n" + example.exception.message - (class << example.exception; self; end).send(:define_method, :message) do - message - end + FileUtils.cp_r pristine_system_gem_path, system_gem_path + + with_gem_path_as(system_gem_path) do + Bundler.ui.silence { example.run } + + all_output = all_commands_output + if example.exception && !all_output.empty? + message = all_output + "\n" + example.exception.message + (class << example.exception; self; end).send(:define_method, :message) do + message end end - ensure - reset! end + ensure + reset! end config.after :suite do diff --git a/spec/bundler/support/builders.rb b/spec/bundler/support/builders.rb index 2af11e9874..b4d4976379 100644 --- a/spec/bundler/support/builders.rb +++ b/spec/bundler/support/builders.rb @@ -456,7 +456,7 @@ module Spec write "ext/extconf.rb", <<-RUBY require "mkmf" - $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] unless RUBY_VERSION < "2.4" + $extout = "$(topdir)/" + RbConfig::CONFIG["EXTOUT"] extension_name = "#{name}_c" if extra_lib_dir = with_config("ext-lib") diff --git a/spec/bundler/support/bundle.rb b/spec/bundler/support/bundle.rb index bb21526d35..5f808531ff 100644 --- a/spec/bundler/support/bundle.rb +++ b/spec/bundler/support/bundle.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true require "rubygems" +Gem.instance_variable_set(:@ruby, ENV["RUBY"]) if ENV["RUBY"] + require_relative "path" bundler_gemspec = Spec::Path.loaded_gemspec bundler_gemspec.instance_variable_set(:@full_gem_path, Spec::Path.source_root) diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb index 76e3b05ee1..ad7a6e0de9 100644 --- a/spec/bundler/support/hax.rb +++ b/spec/bundler/support/hax.rb @@ -33,11 +33,4 @@ module Gem if ENV["BUNDLER_SPEC_GEM_SOURCES"] self.sources = [ENV["BUNDLER_SPEC_GEM_SOURCES"]] end - - # We only need this hack for rubygems versions without the BundlerVersionFinder - if Gem.rubygems_version < Gem::Version.new("2.7.0") - @path_to_default_spec_map.delete_if do |_path, spec| - spec.name == "bundler" - end - end end diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index 1541f903c7..703c98eca3 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -290,7 +290,7 @@ module Spec if gem_name.start_with?("bundler") version = gem_name.match(/\Abundler-(?<version>.*)\z/)[:version] if gem_name != "bundler" with_built_bundler(version) {|gem_path| install_gem(gem_path, default) } - elsif gem_name =~ %r{\A(?:[a-zA-Z]:)?/.*\.gem\z} + elsif %r{\A(?:[a-zA-Z]:)?/.*\.gem\z}.match?(gem_name) install_gem(gem_name, default) else install_gem("#{gem_repo}/gems/#{gem_name}.gem", default) @@ -486,10 +486,10 @@ module Spec Gem.ruby_version.segments[0..1].map.with_index {|s, i| i == 1 ? s + 1 : s }.join(".") end - # versions providing a bundler version finder but not including + # versions not including # https://github.com/rubygems/rubygems/commit/929e92d752baad3a08f3ac92eaec162cb96aedd1 def rubygems_version_failing_to_activate_bundler_prereleases - Gem.rubygems_version < Gem::Version.new("3.1.0.pre.1") && Gem.rubygems_version >= Gem::Version.new("2.7.0") + Gem.rubygems_version < Gem::Version.new("3.1.0.pre.1") end def revision_for(path) diff --git a/spec/bundler/support/indexes.rb b/spec/bundler/support/indexes.rb index 744dd6e233..670f3b0230 100644 --- a/spec/bundler/support/indexes.rb +++ b/spec/bundler/support/indexes.rb @@ -126,7 +126,7 @@ module Spec next if version == v("1.4.2.1") && platform != pl("x86-mswin32") next if version == v("1.4.2") && platform == pl("x86-mswin32") gem "nokogiri", version, platform do - dep "weakling", ">= 0.0.3" if platform =~ pl("java") + dep "weakling", ">= 0.0.3" if platform =~ pl("java") # rubocop:disable Performance/RegexpMatch end end end diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb index c9538f6b36..de03b2746e 100644 --- a/spec/bundler/support/path.rb +++ b/spec/bundler/support/path.rb @@ -295,25 +295,11 @@ module Spec end def rubocop_gemfile_basename - filename = if RUBY_VERSION.start_with?("2.3") - "rubocop23_gems" - elsif RUBY_VERSION.start_with?("2.4") - "rubocop24_gems" - else - "rubocop_gems" - end - tool_dir.join("#{filename}.rb") + source_root.join("tool/bundler/rubocop_gems.rb") end def standard_gemfile_basename - filename = if RUBY_VERSION.start_with?("2.3") - "standard23_gems" - elsif RUBY_VERSION.start_with?("2.4") - "standard24_gems" - else - "standard_gems" - end - tool_dir.join("#{filename}.rb") + source_root.join("tool/bundler/standard_gems.rb") end def tool_dir diff --git a/spec/bundler/support/rubygems_version_manager.rb b/spec/bundler/support/rubygems_version_manager.rb index d1b1f8dd03..5653601ae8 100644 --- a/spec/bundler/support/rubygems_version_manager.rb +++ b/spec/bundler/support/rubygems_version_manager.rb @@ -113,7 +113,7 @@ class RubygemsVersionManager end def resolve_target_tag - return "v#{@source}" if @source.match(/^\d/) + return "v#{@source}" if @source.match?(/^\d/) @source end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index dd2440b068..ea8aebb785 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -2061,13 +2061,8 @@ You may need to `bundle install` to install missing gems end def redefine_method(base, method, new_result) - if RUBY_VERSION >= "2.5" - base.alias_method(method, method) - base.define_method(method) { new_result } - else - base.send(:alias_method, method, method) - base.send(:define_method, method) { new_result } - end + base.alias_method(method, method) + base.define_method(method) { new_result } end def with_plugin(path) diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index b8f35192ae..0b533329a9 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -76,7 +76,7 @@ class TestGemCommandManager < Gem::TestCase message = "Unknown command pish".dup - if RUBY_VERSION >= "2.4" && defined?(DidYouMean::SPELL_CHECKERS) && defined?(DidYouMean::Correctable) + if defined?(DidYouMean::SPELL_CHECKERS) && defined?(DidYouMean::Correctable) message << "\nDid you mean? \"push\"" end diff --git a/test/rubygems/test_gem_requirement.rb b/test/rubygems/test_gem_requirement.rb index 29bb264454..130ea6297d 100644 --- a/test/rubygems/test_gem_requirement.rb +++ b/test/rubygems/test_gem_requirement.rb @@ -83,7 +83,7 @@ class TestGemRequirement < Gem::TestCase Gem::Requirement.parse(Gem::Version.new("2")) end - if RUBY_VERSION >= "2.5" && !(Gem.java_platform? && ENV["JRUBY_OPTS"].to_s.include?("--debug")) + if !(Gem.java_platform? && ENV["JRUBY_OPTS"].to_s.include?("--debug")) def test_parse_deduplication assert_same "~>", Gem::Requirement.parse("~> 1").first end diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index 222bdcfb28..dff945f625 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -596,76 +596,73 @@ class TestGemRequire < Gem::TestCase assert_empty unresolved_names end - # uplevel is 2.5+ only - if RUBY_VERSION >= "2.5" - ["", "Kernel."].each do |prefix| - define_method "test_no_kernel_require_in_#{prefix.tr(".", "_")}warn_with_uplevel" do - Dir.mktmpdir("warn_test") do |dir| - File.write(dir + "/sub.rb", "#{prefix}warn 'uplevel', 'test', uplevel: 1\n") - File.write(dir + "/main.rb", "require 'sub'\n") - _, err = capture_subprocess_io do - system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "-I", dir, "main.rb") - end - assert_match(/main\.rb:1: warning: uplevel\ntest\n$/, err) - _, err = capture_subprocess_io do - system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "-I", dir, "main.rb") - end - assert_match(/main\.rb:1: warning: uplevel\ntest\n$/, err) + ["", "Kernel."].each do |prefix| + define_method "test_no_kernel_require_in_#{prefix.tr(".", "_")}warn_with_uplevel" do + Dir.mktmpdir("warn_test") do |dir| + File.write(dir + "/sub.rb", "#{prefix}warn 'uplevel', 'test', uplevel: 1\n") + File.write(dir + "/main.rb", "require 'sub'\n") + _, err = capture_subprocess_io do + system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "-I", dir, "main.rb") end - end - - define_method "test_no_other_behavioral_changes_with_#{prefix.tr(".", "_")}warn" do - Dir.mktmpdir("warn_test") do |dir| - File.write(dir + "/main.rb", "#{prefix}warn({x:1}, {y:2}, [])\n") - _, err = capture_subprocess_io do - system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "main.rb") - end - assert_match(/{:x=>1}\n{:y=>2}\n$/, err) - _, err = capture_subprocess_io do - system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "main.rb") - end - assert_match(/{:x=>1}\n{:y=>2}\n$/, err) + assert_match(/main\.rb:1: warning: uplevel\ntest\n$/, err) + _, err = capture_subprocess_io do + system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "-I", dir, "main.rb") end + assert_match(/main\.rb:1: warning: uplevel\ntest\n$/, err) end end - def test_no_crash_when_overriding_warn_with_warning_module + define_method "test_no_other_behavioral_changes_with_#{prefix.tr(".", "_")}warn" do Dir.mktmpdir("warn_test") do |dir| - File.write(dir + "/main.rb", "module Warning; def warn(str); super; end; end; warn 'Foo Bar'") + File.write(dir + "/main.rb", "#{prefix}warn({x:1}, {y:2}, [])\n") _, err = capture_subprocess_io do system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "main.rb") end - assert_match(/Foo Bar\n$/, err) + assert_match(/{:x=>1}\n{:y=>2}\n$/, err) _, err = capture_subprocess_io do system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "main.rb") end - assert_match(/Foo Bar\n$/, err) + assert_match(/{:x=>1}\n{:y=>2}\n$/, err) end end + end - def test_expected_backtrace_location_when_inheriting_from_basic_object_and_including_kernel - Dir.mktmpdir("warn_test") do |dir| - File.write(dir + "/main.rb", "\nrequire 'sub'\n") - File.write(dir + "/sub.rb", <<-'RUBY') - require 'rubygems' - class C < BasicObject - include ::Kernel - def deprecated - warn "This is a deprecated method", uplevel: 2 - end - end - C.new.deprecated - RUBY + def test_no_crash_when_overriding_warn_with_warning_module + Dir.mktmpdir("warn_test") do |dir| + File.write(dir + "/main.rb", "module Warning; def warn(str); super; end; end; warn 'Foo Bar'") + _, err = capture_subprocess_io do + system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "main.rb") + end + assert_match(/Foo Bar\n$/, err) + _, err = capture_subprocess_io do + system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "main.rb") + end + assert_match(/Foo Bar\n$/, err) + end + end - _, err = capture_subprocess_io do - system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "-I", dir, "main.rb") - end - assert_match(/main\.rb:2: warning: This is a deprecated method$/, err) - _, err = capture_subprocess_io do - system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "-I", dir, "main.rb") + def test_expected_backtrace_location_when_inheriting_from_basic_object_and_including_kernel + Dir.mktmpdir("warn_test") do |dir| + File.write(dir + "/main.rb", "\nrequire 'sub'\n") + File.write(dir + "/sub.rb", <<-'RUBY') + require 'rubygems' + class C < BasicObject + include ::Kernel + def deprecated + warn "This is a deprecated method", uplevel: 2 + end end - assert_match(/main\.rb:2: warning: This is a deprecated method$/, err) + C.new.deprecated + RUBY + + _, err = capture_subprocess_io do + system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "-I", dir, "main.rb") + end + assert_match(/main\.rb:2: warning: This is a deprecated method$/, err) + _, err = capture_subprocess_io do + system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "-I", dir, "main.rb") end + assert_match(/main\.rb:2: warning: This is a deprecated method$/, err) end end diff --git a/tool/bundler/dev_gems.rb b/tool/bundler/dev_gems.rb index abeb25821b..1603d5f8bc 100644 --- a/tool/bundler/dev_gems.rb +++ b/tool/bundler/dev_gems.rb @@ -2,17 +2,16 @@ source "https://rubygems.org" -gem "rdoc", "6.2.0" # 6.2.1 is required > Ruby 2.3 gem "test-unit", "~> 3.0" gem "rake", "~> 13.0" gem "webrick", "~> 1.6" gem "parallel_tests", "~> 2.29" -gem "parallel", "1.19.2" # 1.20+ is required > Ruby 2.3 +gem "parallel", "~> 1.19" gem "rspec-core", "~> 3.12" gem "rspec-expectations", "~> 3.12" gem "rspec-mocks", "~> 3.12" -gem "uri", "~> 0.10.1" +gem "uri", "~> 0.12.0" group :doc do gem "ronn", "~> 0.7.3", :platform => :ruby diff --git a/tool/bundler/dev_gems.rb.lock b/tool/bundler/dev_gems.rb.lock index 526d7d3d86..41e2128bb8 100644 --- a/tool/bundler/dev_gems.rb.lock +++ b/tool/bundler/dev_gems.rb.lock @@ -5,13 +5,12 @@ GEM hpricot (0.8.6) hpricot (0.8.6-java) mustache (1.1.1) - parallel (1.19.2) + parallel (1.22.1) parallel_tests (2.32.0) parallel - power_assert (2.0.1) + power_assert (2.0.2) rake (13.0.6) - rdiscount (2.2.0.2) - rdoc (6.2.0) + rdiscount (2.2.7) ronn (0.7.3) hpricot (>= 0.8.2) mustache (>= 0.7.0) @@ -21,13 +20,13 @@ GEM rspec-expectations (3.12.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-mocks (3.12.0) + rspec-mocks (3.12.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.0) - test-unit (3.5.3) + test-unit (3.5.5) power_assert - uri (0.10.1) + uri (0.12.0) webrick (1.7.0) PLATFORMS @@ -41,16 +40,15 @@ PLATFORMS x86_64-linux DEPENDENCIES - parallel (= 1.19.2) + parallel (~> 1.19) parallel_tests (~> 2.29) rake (~> 13.0) - rdoc (= 6.2.0) ronn (~> 0.7.3) rspec-core (~> 3.12) rspec-expectations (~> 3.12) rspec-mocks (~> 3.12) test-unit (~> 3.0) - uri (~> 0.10.1) + uri (~> 0.12.0) webrick (~> 1.6) BUNDLED WITH diff --git a/tool/bundler/rubocop_gems.rb.lock b/tool/bundler/rubocop_gems.rb.lock index d706d0ce62..dbb7601a11 100644 --- a/tool/bundler/rubocop_gems.rb.lock +++ b/tool/bundler/rubocop_gems.rb.lock @@ -3,45 +3,48 @@ GEM specs: ast (2.4.2) diff-lcs (1.5.0) - minitest (5.15.0) - parallel (1.21.0) - parser (3.1.0.0) + json (2.6.3) + json (2.6.3-java) + minitest (5.16.3) + parallel (1.22.1) + parser (3.1.3.0) ast (~> 2.4.1) - power_assert (2.0.1) + power_assert (2.0.2) rainbow (3.1.1) rake (13.0.6) - rake-compiler (1.1.7) + rake-compiler (1.2.0) rake - regexp_parser (2.2.0) + regexp_parser (2.6.1) rexml (3.2.5) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.2) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.2) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.3) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.3) - rubocop (1.24.1) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) + rubocop (1.40.0) + json (~> 2.3) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.1.2.1) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.15.1, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.23.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.15.1) - parser (>= 3.0.1.1) + rubocop-ast (1.24.0) + parser (>= 3.1.1.0) ruby-progressbar (1.11.0) - test-unit (3.5.3) + test-unit (3.5.5) power_assert - unicode-display_width (2.1.0) + unicode-display_width (2.3.0) PLATFORMS aarch64-linux diff --git a/tool/bundler/standard_gems.rb.lock b/tool/bundler/standard_gems.rb.lock index fcac98fe27..198aada23b 100644 --- a/tool/bundler/standard_gems.rb.lock +++ b/tool/bundler/standard_gems.rb.lock @@ -3,51 +3,56 @@ GEM specs: ast (2.4.2) diff-lcs (1.5.0) - minitest (5.15.0) - parallel (1.21.0) - parser (3.1.0.0) + json (2.6.3) + json (2.6.3-java) + language_server-protocol (3.17.0.2) + minitest (5.16.3) + parallel (1.22.1) + parser (3.1.3.0) ast (~> 2.4.1) - power_assert (2.0.1) + power_assert (2.0.2) rainbow (3.1.1) rake (13.0.6) - rake-compiler (1.1.7) + rake-compiler (1.2.0) rake - regexp_parser (2.2.0) + regexp_parser (2.6.1) rexml (3.2.5) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.2) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.2) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.3) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.3) - rubocop (1.24.1) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) + rubocop (1.39.0) + json (~> 2.3) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.1.2.1) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.15.1, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.23.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.15.1) - parser (>= 3.0.1.1) - rubocop-performance (1.13.1) + rubocop-ast (1.24.0) + parser (>= 3.1.1.0) + rubocop-performance (1.15.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) ruby-progressbar (1.11.0) - standard (1.6.0) - rubocop (= 1.24.1) - rubocop-performance (= 1.13.1) - test-unit (3.5.3) + standard (1.19.1) + language_server-protocol (~> 3.17.0.2) + rubocop (= 1.39.0) + rubocop-performance (= 1.15.1) + test-unit (3.5.5) power_assert - unicode-display_width (2.1.0) + unicode-display_width (2.3.0) PLATFORMS aarch64-linux diff --git a/tool/bundler/test_gems.rb.lock b/tool/bundler/test_gems.rb.lock index 8e2f0768a6..62b65c007f 100644 --- a/tool/bundler/test_gems.rb.lock +++ b/tool/bundler/test_gems.rb.lock @@ -5,7 +5,7 @@ GEM rack-test builder (3.2.4) compact_index (0.13.0) - mustermann (1.1.1) + mustermann (1.1.2) ruby2_keywords (~> 0.0.1) rack (2.0.8) rack-protection (2.0.8.1) @@ -19,7 +19,7 @@ GEM rack (~> 2.0) rack-protection (= 2.0.8.1) tilt (~> 2.0) - tilt (2.0.10) + tilt (2.0.11) webrick (1.7.0) PLATFORMS |