diff options
author | Hiroshi SHIBATA <[email protected]> | 2020-05-08 14:19:04 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2020-05-13 07:54:37 +0900 |
commit | 0e60b59d5884edb8f9aea023efd9b24f1ff02049 () | |
tree | e52935ce510440872ca5ce6b0e092cbc94f18bc9 /lib/bundler | |
parent | 68224651a4d4dc3ce0cea666f5423dd8b6ba6cfc (diff) |
Update the bundler version with master branch
Notes: Merged: https://.com/ruby/ruby/pull/3086
51 files changed, 686 insertions, 568 deletions
@@ -24,21 +24,24 @@ Gem::Specification.new do |s| if s.respond_to?(:metadata=) s.metadata = { - "bug_tracker_uri" => "https://.com/bundler/bundler/issues", - "changelog_uri" => "https://.com/bundler/bundler/blob/master/CHANGELOG.md", "homepage_uri" => "https://bundler.io/", - "source_code_uri" => "https://.com/bundler/bundler/", } end s.required_ruby_version = ">= 2.3.0" s.required_rubygems_version = ">= 2.5.2" - s.files = (Dir.glob("lib/bundler/**/*", File::FNM_DOTMATCH) + Dir.glob("man/bundler*") + Dir.glob("libexec/bundle*")).reject {|f| File.directory?(f) } - s.files += ["lib/bundler.rb"] - s.bindir = "libexec" s.executables = %w[bundle bundler] s.require_paths = ["lib"] end @@ -345,8 +345,8 @@ module Bundler desc "list", "List all gems in the bundle" method_option "name-only", :type => :boolean, :banner => "print only the gem names" - method_option "only-group", :type => :string, :banner => "print gems from a particular group" - method_option "without-group", :type => :string, :banner => "print all gems except from a group" method_option "paths", :type => :boolean, :banner => "print the path to each gem in the bundle" def list require_relative "cli/list" @@ -570,8 +570,9 @@ module Bundler method_option :ext, :type => :boolean, :default => false, :desc => "Generate the boilerplate for C extension code" method_option :git, :type => :boolean, :default => true, :desc => "Initialize a git repo inside your library." method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set gem.mit true`." method_option :test, :type => :string, :lazy_default => "rspec", :aliases => "-t", :banner => "rspec", - :desc => "Generate a test directory for your library, either rspec or minitest. Set a default with `bundle config set gem.test rspec`." def gem(name) end @@ -815,7 +816,7 @@ module Bundler option = current_command.options[name] flag_name = option.switch_name - name_index = ARGV.find {|arg| flag_name == arg } return unless name_index value = options[name] @@ -12,7 +12,7 @@ module Bundler Bundler::SharedHelpers.major_deprecation 2, "bundle console will be replaced " \ "by `bin/console` generated by `bundle gem <name>`" - group ? Bundler.require(:default, *group.split(' ').map!(&:to_sym)) : Bundler.require ARGV.clear console = get_console(Bundler.settings[:console] || "irb") @@ -12,6 +12,7 @@ module Bundler TEST_FRAMEWORK_VERSIONS = { "rspec" => "3.0", "minitest" => "5.0", }.freeze attr_reader :options, :gem_name, :thor, :name, :target @@ -62,7 +63,7 @@ module Bundler ensure_safe_gem_name(name, constant_array) templates = { - "Gemfile.tt" => "Gemfile", "lib/newgem.rb.tt" => "lib/#{namespaced_path}.rb", "lib/newgem/version.rb.tt" => "lib/#{namespaced_path}/version.rb", "newgem.gemspec.tt" => "#{name}.gemspec", @@ -92,16 +93,22 @@ module Bundler "spec/spec_helper.rb.tt" => "spec/spec_helper.rb", "spec/newgem_spec.rb.tt" => "spec/#{namespaced_path}_spec.rb" ) when "minitest" templates.merge!( - "test/test_helper.rb.tt" => "test/test_helper.rb", - "test/newgem_test.rb.tt" => "test/#{namespaced_path}_test.rb" ) end end - config[:test_task] = config[:test] == "minitest" ? "test" : "spec" - if ask_and_set(:mit, "Do you want to license your code permissively under the MIT license?", "This means that any other developer or company will be legally allowed to use your code " \ "for free as long as they admit you created it. You can read more about the MIT license " \ @@ -124,6 +131,15 @@ module Bundler templates.merge!("CODE_OF_CONDUCT.md.tt" => "CODE_OF_CONDUCT.md") end templates.merge!("exe/newgem.tt" => "exe/#{name}") if config[:exe] if options[:ext] @@ -199,9 +215,9 @@ module Bundler if test_framework.nil? Bundler.ui.confirm "Do you want to generate tests with your gem?" - result = Bundler.ui.ask "Type 'rspec' or 'minitest' to generate those test files now and " \ - "in the future. rspec/minitest/(none):" - if result =~ /rspec|minitest/ test_framework = result else test_framework = false @@ -50,10 +50,17 @@ module Bundler end def print_gem_info(spec) gem_info = String.new gem_info << " * #{spec.name} (#{spec.version}#{spec.git_version})\n" gem_info << "\tSummary: #{spec.summary}\n" if spec.summary gem_info << "\tHomepage: #{spec.homepage}\n" if spec.homepage gem_info << "\tPath: #{spec.full_gem_path}\n" gem_info << "\tDefault Gem: yes" if spec.respond_to?(:default_gem?) && spec.default_gem? Bundler.ui.info gem_info @@ -41,7 +41,7 @@ module Bundler private def gemfile - @gemfile ||= Bundler.settings[:init_gems_rb] ? "gems.rb" : "Gemfile" end end end @@ -10,7 +10,7 @@ module Bundler be sure to check out these resources: 1. Check out our troubleshooting guide for quick fixes to common issues: - https://.com/bundler/bundler/blob/master/doc/TROUBLESHOOTING.md 2. Instructions for common Bundler uses can be found on the documentation site: https://bundler.io/ @@ -22,7 +22,7 @@ module Bundler still aren't working the way you expect them to, please let us know so that we can diagnose and help fix the problem you're having. Please view the Filing Issues guide for more information: - https://.com/bundler/bundler/blob/master/doc/contributing/ISSUES.md EOS @@ -4,14 +4,16 @@ module Bundler class CLI::List def initialize(options) @options = options end def run - raise InvalidOption, "The `--only-group` and `--without-group` options cannot be used together" if @options["only-group"] && @options["without-group"] raise InvalidOption, "The `--name-only` and `--paths` options cannot be used together" if @options["name-only"] && @options[:paths] - specs = if @options["only-group"] || @options["without-group"] filtered_specs_by_groups else Bundler.load.specs @@ -32,9 +34,9 @@ module Bundler private def verify_group_exists(groups) - raise InvalidOption, "`#{@options["without-group"]}` group could not be found." if @options["without-group"] && !groups.include?(@options["without-group"].to_sym) - - raise InvalidOption, "`#{@options["only-group"]}` group could not be found." if @options["only-group"] && !groups.include?(@options["only-group"].to_sym) end def filtered_specs_by_groups @@ -44,10 +46,10 @@ module Bundler verify_group_exists(groups) show_groups = - if @options["without-group"] - groups.reject {|g| g == @options["without-group"].to_sym } - elsif @options["only-group"] - groups.select {|g| g == @options["only-group"].to_sym } else groups end.map(&:to_sym) @@ -3,18 +3,16 @@ module Bundler class CLI::Outdated attr_reader :options, :gems, :options_include_groups, :filter_options_, :sources, :strict - attr_accessor :outdated_gems_by_groups, :outdated_gems_list def initialize(options, gems) @options = options @gems = gems @sources = Array(options[:source]) - @filter_options_ = options.keys & - %w[filter-major filter-minor filter-] - @outdated_gems_by_groups = {} - @outdated_gems_list = [] @options_include_groups = [:group, :groups].any? do |v| options.keys.include?(v.to_s) @@ -22,8 +20,7 @@ module Bundler # the level options imply strict is also true. It wouldn't make # sense otherwise. - @strict = options["filter-strict"] || - Bundler::CLI::Common._level_options(options).any? end def run @@ -76,58 +73,54 @@ module Bundler end specs.sort_by(&:name).each do |current_spec| - next if !gems.empty? && !gems.include?(current_spec.name) - dependency = current_dependencies[current_spec.name] active_spec = retrieve_active_spec(definition, current_spec) - next if active_spec.nil? - next if filter_options_.any? && - !update_present_via_semver_portions(current_spec, active_spec, options) gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version) next unless gem_outdated || (current_spec.git_version != active_spec.git_version) - groups = nil if dependency && !options[:parseable] groups = dependency.groups.join(", ") end - outdated_gems_list << { :active_spec => active_spec, - :current_spec => current_spec, - :dependency => dependency, - :groups => groups } - - outdated_gems_by_groups[groups] ||= [] - outdated_gems_by_groups[groups] << outdated_gems_list[-1] end - if outdated_gems_list.empty? - display_nothing_outdated_message - else unless options[:parseable] - Bundler.ui.info(header_outdated_message) end - if options_include_groups - ordered_groups = outdated_gems_by_groups.keys.compact.sort - ordered_groups.insert(0, nil).each do |groups| - gems = outdated_gems_by_groups[groups] - contains_group = if groups - groups.split(", ").include?(options[:group]) - else - options[:group] == "group" - end - next if (!options[:groups] && !contains_group) || gems.nil? - unless options[:parseable] - Bundler.ui.info(header_group_message(groups)) end - - print_gems(gems) end else - print_gems(outdated_gems_list) end exit 1 @@ -140,22 +133,6 @@ module Bundler "#{group_text}#{groups.split(",").size > 1 ? "s" : ""} \"#{groups}\"" end - def header_outdated_message - if options[:pre] - "Outdated gems included in the bundle (including s):" - else - "Outdated gems included in the bundle:" - end - end - - def header_group_message(groups) - if groups - "===== #{groups_text("Group", groups)} =====" - else - "===== Without group =====" - end - end - def nothing_outdated_message if filter_options_.any? display = filter_options_.map do |o| @@ -169,6 +146,8 @@ module Bundler end def retrieve_active_spec(definition, current_spec) if strict active_spec = definition.find_resolved_spec(current_spec) else @@ -182,12 +161,6 @@ module Bundler active_spec end - def display_nothing_outdated_message - unless options[:parseable] - Bundler.ui.info(nothing_outdated_message) - end - end - def print_gems(gems_list) gems_list.each do |gem| print_gem( @@ -199,6 +172,19 @@ module Bundler end end def print_gem(current_spec, active_spec, dependency, groups) spec_version = "#{active_spec.version}#{active_spec.git_version}" spec_version += " (from #{active_spec.loaded_from})" if Bundler.ui.debug? && active_spec.loaded_from @@ -213,7 +199,7 @@ module Bundler output_message = if options[:parseable] spec_outdated_info.to_s - elsif options_include_groups || !groups " * #{spec_outdated_info}" else " * #{spec_outdated_info} in #{groups_text("group", groups)}" @@ -222,6 +208,16 @@ module Bundler Bundler.ui.info output_message.rstrip end def check_for_deployment_mode! return unless Bundler.frozen_bundle? suggested_command = if Bundler.settings.locations("frozen")[:global] @@ -266,5 +262,34 @@ module Bundler version_section = spec.version.segments[version_portion_index, 1] version_section.to_a[0].to_i end end end @@ -23,6 +23,16 @@ module Bundler Bundler::Plugin.install(plugins, options) end desc "list", "List the installed plugins and available commands" def list Bundler::Plugin.list @@ -29,6 +29,11 @@ module Bundler FileUtils.rm_rf spec.full_gem_path when Source::Git source.remote! if extension_cache_path = source.extension_cache_path(spec) FileUtils.rm_rf extension_cache_path @@ -1,5 +1,7 @@ # frozen_string_literal: true module Bundler class CompactIndexClient class Cache @@ -92,19 +94,9 @@ module Bundler header ? lines[header + 1..-1] : lines end - def parse_gem(string) - version_and_platform, rest = string.split(" ", 2) - version, platform = version_and_platform.split("-", 2) - dependencies, requirements = rest.split("|", 2).map {|s| s.split(",") } if rest - dependencies = dependencies ? dependencies.map {|d| parse_dependency(d) } : [] - requirements = requirements ? requirements.map {|r| parse_dependency(r) } : [] - [version, platform, dependencies, requirements] - end - - def parse_dependency(string) - dependency = string.split(":") - dependency[-1] = dependency[-1].split("&") if dependency.size > 1 - dependency end def info_roots @@ -0,0 +1,66 @@ @@ -77,12 +77,17 @@ module Bundler @locked_bundler_version = nil @locked_ruby_version = nil @locked_specs_incomplete_for_platform = false if lockfile && File.exist?(lockfile) @lockfile_contents = Bundler.read_file(lockfile) @locked_gems = LockfileParser.new(@lockfile_contents) @locked_platforms = @locked_gems.platforms - @platforms = @locked_platforms.dup @locked_bundler_version = @locked_gems.bundler_version @locked_ruby_version = @locked_gems.ruby_version @@ -113,7 +118,7 @@ module Bundler end @unlocking ||= @unlock[:ruby] ||= (!@locked_ruby_version ^ !@ruby_version) - add_current_platform unless Bundler.frozen_bundle? converge_path_sources_to_gemspec_sources @path_changes = converge_paths @@ -228,12 +233,13 @@ module Bundler end def current_dependencies - dependencies.select(&:should_include?) end def specs_for(groups) - deps = dependencies.select {|d| (d.groups & groups).any? } - deps.delete_if {|d| !d.should_include? } specs.for(expand_dependencies(deps)) end @@ -450,9 +456,9 @@ module Bundler @locked_deps.each {|name, d| both_sources[name][1] = d.source } both_sources.each do |name, (dep, lock_source)| - next unless (dep.nil? && !lock_source.nil?) || (!dep.nil? && !lock_source.nil? && !lock_source.can_lock?(dep)) gemfile_source_name = (dep && dep.source) || "no specified source" - lockfile_source_name = lock_source || "no specified source" changed << "* #{name} from `#{gemfile_source_name}` to `#{lockfile_source_name}`" end @@ -518,10 +524,6 @@ module Bundler raise InvalidOption, "Unable to remove the platform `#{platform}` since the only platforms are #{@platforms.join ", "}" end - def add_current_platform - current_platforms.each {|platform| add_platform(platform) } - end - def find_resolved_spec(current_spec) specs.find_by_name_and_platform(current_spec.name, current_spec.platform) end @@ -543,6 +545,12 @@ module Bundler private def current_platforms current_platform = Bundler.local_platform [].tap do |platforms| @@ -706,9 +714,6 @@ module Bundler elsif dep.source dep.source = sources.get(dep.source) end - if dep.source.is_a?(Source::Gemspec) - dep.platforms.concat(@platforms.map {|p| Dependency::REVERSE_PLATFORM_MAP[p] }.flatten(1)).uniq! - end end changes = false @@ -858,8 +863,8 @@ module Bundler @metadata_dependencies ||= begin ruby_versions = concat_ruby_version_requirements(@ruby_version) if ruby_versions.empty? || !@ruby_version.exact? - concat_ruby_version_requirements(RubyVersion.system) - concat_ruby_version_requirements(locked_ruby_version_object) unless @unlock[:ruby] end [ Dependency.new("Ruby\0", ruby_versions), @@ -890,27 +895,23 @@ module Bundler dependencies.each do |dep| dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name) next if !remote && !dep.current_platform? - platforms = dep.gem_platforms(sorted_platforms) - if platforms.empty? && !Bundler.settings[:disable_platform_warnings] - mapped_platforms = dep.expanded_platforms - Bundler.ui.warn \ - "The dependency #{dep} will be unused by any of the platforms Bundler is installing for. " \ - "Bundler is installing for #{@platforms.join ", "} but the dependency " \ - "is only for #{mapped_platforms.join ", "}. " \ - "To add those platforms to the bundle, " \ - "run `bundle lock --add-platform #{mapped_platforms.join " "}`." - end - platforms.each do |p| deps << DepProxy.new(dep, p) if remote || p == generic_local_platform end end deps end def requested_dependencies groups = requested_groups groups.map!(&:to_sym) - dependencies.reject {|d| !d.should_include? || (d.groups & groups).empty? } end def source_requirements @@ -74,15 +74,6 @@ module Bundler :x64_mingw_26 => Gem::Platform::X64_MINGW, }.freeze - REVERSE_PLATFORM_MAP = {}.tap do |reverse_platform_map| - PLATFORM_MAP.each do |key, value| - reverse_platform_map[value] ||= [] - reverse_platform_map[value] << key - end - - reverse_platform_map.each {|_, platforms| platforms.freeze } - end.freeze - def initialize(name, version, options = {}, &blk) type = options["type"] || :runtime super(name, version, type) @@ -75,8 +75,7 @@ module Bundler @gemspecs << spec - gem_platforms = Bundler::Dependency::REVERSE_PLATFORM_MAP[Bundler::GemHelpers.generic_local_platform] - gem spec.name, :name => spec.name, :path => path, :glob => glob, :platforms => gem_platforms group(development_group) do spec.development_dependencies.each do |dep| @@ -17,14 +17,38 @@ module Bundler ].map(&:freeze).freeze BUNDLER_PREFIX = "BUNDLER_ORIG_".freeze - # @param env [ENV] # @param keys [Array<String>] def initialize(env, keys) - @original = env.to_hash @keys = keys @prefix = BUNDLER_PREFIX end # @return [Hash] def backup env = @original.clone @@ -56,6 +56,7 @@ module Bundler class SudoNotPermittedError < BundlerError; status_code(30); end class ThreadCreationError < BundlerError; status_code(33); end class APIResponseMismatchError < BundlerError; status_code(34); end class GemfileEvalError < GemfileError; end class MarshalError < StandardError; end @@ -30,7 +30,6 @@ module Bundler settings_flag(:allow_bundler_dependency_conflicts) { bundler_3_mode? } settings_flag(:allow_offline_install) { bundler_3_mode? } settings_flag(:auto_clean_without_path) { bundler_3_mode? } - settings_flag(:auto_config_jobs) { bundler_3_mode? } settings_flag(:cache_all) { bundler_3_mode? } settings_flag(:default_install_uses_path) { bundler_3_mode? } settings_flag(:deployment_means_frozen) { bundler_3_mode? } @@ -229,6 +229,7 @@ module Bundler "BUILDBOX" => "buildbox", "GO_SERVER_URL" => "go", "SNAP_CI" => "snap", "CI_NAME" => ENV["CI_NAME"], "CI" => "ci", } @@ -23,13 +23,7 @@ module Bundler Bundler.ui.error error.message when LoadError raise error unless error.message =~ /cannot load such file -- openssl|openssl.so|libcrypto.so/ - Bundler.ui.error "\nCould not load OpenSSL." - Bundler.ui.warn <<-WARN, :wrap => true - You must recompile Ruby with OpenSSL support or change the sources in your \ - Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL \ - using RVM are available at https://rvm.io/packages/openssl. - WARN - Bundler.ui.trace error when Interrupt Bundler.ui.error "\nQuitting..." Bundler.ui.trace error @@ -82,7 +76,7 @@ module Bundler I tried... - - **Have you read our issues document, https://.com/bundler/bundler/blob/master/doc/contributing/ISSUES.md?** ... @@ -106,7 +100,7 @@ module Bundler #{issues_url(e)} If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at: - https://.com/bundler/bundler/issues/new EOS end @@ -114,7 +108,7 @@ module Bundler message = exception.message.lines.first.tr(":", " ").chomp message = message.split("-").first if exception.is_a?(Errno) require "cgi" - "https://.com/bundler/bundler/search?q=" \ "#{CGI.escape(message)}&type=Issues" end end @@ -25,8 +25,8 @@ module Bundler attr_reader :spec_path, :base, :gemspec def initialize(base = nil, name = nil) - @base = (base ||= SharedHelpers.pwd) - gemspecs = name ? [File.join(base, "#{name}.gemspec")] : Dir[File.join(base, "{,*}.gemspec")] raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1 @spec_path = gemspecs.first @gemspec = Bundler.load_gemspec(@spec_path) @@ -73,7 +73,7 @@ module Bundler def build_gem file_name = nil - sh("#{gem_command} build -V #{spec_path.shellescape}".shellsplit) do file_name = File.basename(built_gem_path) SharedHelpers.filesystem_access(File.join(base, "pkg")) {|p| FileUtils.mkdir_p(p) } FileUtils.mv(built_gem_path, "pkg") @@ -84,9 +84,9 @@ module Bundler def install_gem(built_gem_path = nil, local = false) built_gem_path ||= build_gem - cmd = "#{gem_command} install #{built_gem_path}" - cmd += " --local" if local - _, status = sh_with_status(cmd.shellsplit) unless status.success? raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" end @@ -96,11 +96,11 @@ module Bundler protected def rubygem_push(path) - cmd = %W[#{gem_command} push #{path}] cmd << "--key" << gem_key if gem_key cmd << "--host" << allowed_push_host if allowed_push_host unless allowed_push_host || Bundler.user_home.join(".gem/credentials").file? - raise "Your rubygems.org credentials aren't set. Run `gem push` to set them." end sh_with_input(cmd) Bundler.ui.confirm "Pushed #{name} #{version} to #{gem_push_host}" @@ -210,7 +210,7 @@ module Bundler end def gem_command - ENV["GEM_COMMAND"] ? ENV["GEM_COMMAND"] : "gem" end end end @@ -7,7 +7,7 @@ module Bundler # available dependency versions as found in its index, before returning it to # to the resolution engine to select the best version. class GemVersionPromoter - DEBUG = ENV["DEBUG_RESOLVER"] attr_reader :level, :locked_specs, :unlock_gems @@ -58,7 +58,7 @@ def gemfile(install = false, options = {}, &gemfile) Bundler.ui = install ? ui : Bundler::UI::Silent.new if install || definition.missing_specs? - Bundler.settings.temporary(:inline => true, :disable_platform_warnings => true) do installer = Bundler::Installer.install(Bundler.root, definition, :system => true) installer.post_install_messages.each do |name, message| Bundler.ui.info "Post-install message from #{name}:\n#{message}" @@ -204,18 +204,7 @@ module Bundler return 1 unless can_install_in_parallel? - auto_config_jobs = Bundler.feature_flag.auto_config_jobs? - if jobs = Bundler.settings[:jobs] - if auto_config_jobs - jobs - else - [jobs.pred, 1].max - end - elsif auto_config_jobs - processor_count - else - 1 - end end def processor_count @@ -19,11 +19,11 @@ module Bundler Bundler.ui.debug "#{worker}: #{spec.name} (#{spec.version}) from #{spec.loaded_from}" generate_executable_stubs return true, post_install_message - rescue Bundler::InstallHookError, Bundler::SecurityError, APIResponseMismatchError raise rescue Errno::ENOSPC return false, out_of_space_message - rescue StandardError => e return false, specific_failure_message(e) end @@ -99,7 +99,7 @@ module Bundler install_serially end - handle_error if @specs.any?(&:failed?) @specs ensure worker_pool && worker_pool.stop @@ -132,6 +132,10 @@ module Bundler private def install_with_worker enqueue_specs process_specs until finished_installing? @@ -156,11 +160,7 @@ module Bundler gem_installer = Bundler::GemInstaller.new( spec_install.spec, @installer, @standalone, worker_num, @force ) - success, message = begin - gem_installer.install_from_spec - rescue RuntimeError => e - raise e, "#{e}\n\n#{require_tree_for_spec(spec_install.spec)}" - end if success spec_install.state = :installed spec_install.post_install_message = message unless message.nil? @@ -190,11 +190,11 @@ module Bundler end def handle_error - errors = @specs.select(&:failed?).map(&:error) if exception = errors.find {|e| e.is_a?(Bundler::BundlerError) } raise exception end - raise Bundler::InstallError, errors.map(&:to_s).join("\n\n") end def require_tree_for_spec(spec) @@ -46,6 +46,14 @@ module Bundler identifier == other.identifier end def satisfies?(dependency) @name == dependency.name && dependency.requirement.satisfied_by?(Gem::Version.new(@version)) end @@ -72,8 +80,13 @@ module Bundler @specification = if source.is_a?(Source::Gemspec) && source.gemspec.name == name source.gemspec.tap {|s| s.source = source } else - search = source.specs.search(search_object).last - if search && Gem::Platform.new(search.platform) != Gem::Platform.new(platform) && !search.runtime_dependencies.-(dependencies.reject {|d| d.type == :development }).empty? Bundler.ui.warn "Unable to use the platform-specific (#{search.platform}) version of #{name} (#{version}) " \ "because it has different dependencies from the #{platform} version. " \ "To use the platform-specific version of the gem, run `bundle config set specific_platform true` and install again." @@ -47,6 +47,32 @@ module Bundler Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace.join("\n ")}" end # List installed plugins and commands # def list @@ -71,6 +71,15 @@ module Bundler raise end # Path of default index file def index_file Plugin.root.join("index") @@ -26,12 +26,3 @@ module Bundler YamlLibrarySyntaxError = ::ArgumentError end end - -require_relative "deprecate" -begin - Bundler::Deprecate.skip_during do - require "rubygems/safe_yaml" - end -rescue LoadError - # it's OK if the file isn't there -end @@ -50,6 +50,8 @@ module Bundler # once the remote gem is downloaded, the backend specification will # be swapped out. def __swap__(spec) SharedHelpers.ensure_same_dependencies(self, dependencies, spec.dependencies) @_remote_specification = spec end @@ -76,7 +78,8 @@ module Bundler deps = method_missing(:dependencies) # allow us to handle when the specs dependencies are an array of array of string - # see https://.com/bundler/bundler/issues/5797 deps = deps.map {|d| d.is_a?(Gem::Dependency) ? d : Gem::Dependency.new(*d) } deps @@ -75,12 +75,17 @@ module Bundler return unless debug? debug_info = yield debug_info = debug_info.inspect unless debug_info.is_a?(String) - warn debug_info.split("\n").map {|s| " " * depth + s } end def debug? return @debug_mode if defined?(@debug_mode) - @debug_mode = ENV["DEBUG_RESOLVER"] || ENV["DEBUG_RESOLVER_TREE"] || false end def before_resolution @@ -146,7 +151,26 @@ module Bundler @gem_version_promoter.sort_versions(dependency, spec_groups) end end - search.select {|sg| sg.for?(platform) }.each {|sg| sg.activate_platform!(platform) } end def index_for(dependency) @@ -183,9 +207,7 @@ module Bundler end def requirement_satisfied_by?(requirement, activated, spec) - return false unless requirement.matches_spec?(spec) || spec.source.is_a?(Source::Gemspec) - spec.activate_platform!(requirement.__platform) if !@platforms || @platforms.include?(requirement.__platform) - true end def relevant_sources_for_vertex(vertex) @@ -223,8 +245,9 @@ module Bundler end def self.platform_sort_key(platform) - return ["", "", ""] if Gem::Platform::RUBY == platform - platform.to_a.map {|part| part || "" } end private @@ -9,6 +9,7 @@ module Bundler attr_accessor :ignores_bundler_dependencies def initialize(all_specs) raise ArgumentError, "cannot initialize with an empty value" unless exemplary_spec = all_specs.first @name = exemplary_spec.name @version = exemplary_spec.version @@ -28,7 +29,7 @@ module Bundler lazy_spec = LazySpecification.new(name, version, s.platform, source) lazy_spec.dependencies.replace s.dependencies lazy_spec - end.compact end def activate_platform!(platform) @@ -37,13 +38,25 @@ module Bundler @activated_platforms << platform end def for?(platform) - spec = @specs[platform] - !spec.nil? end def to_s - @to_s ||= "#{name} (#{version})" end def dependencies_for_activated_platforms @@ -58,6 +71,7 @@ module Bundler return unless other.is_a?(SpecGroup) name == other.name && version == other.version && source == other.source end @@ -65,11 +79,18 @@ module Bundler return unless other.is_a?(SpecGroup) name.eql?(other.name) && version.eql?(other.version) && source.eql?(other.source) end def hash - to_s.hash ^ source.hash end private @@ -51,7 +51,8 @@ module Gem alias_method :rg_extension_dir, :extension_dir def extension_dir @bundler_extension_dir ||= if source.respond_to?(:extension_dir_name) - File.expand_path(File.join(extensions_dir, source.extension_dir_name)) else rg_extension_dir end @@ -346,7 +346,7 @@ module Bundler raise e end - # backwards compatibility shim, see https://.com/bundler/bundler/issues/5102 kernel_class.send(:public, :gem) if Bundler.feature_flag.setup_makes_kernel_gem_public? end end @@ -443,35 +443,6 @@ module Bundler Gem.clear_paths end - # This backports base_dir which replaces installation path - # RubyGems 1.8+ - def backport_base_dir - redefine_method(Gem::Specification, :base_dir) do - return Gem.dir unless loaded_from - File.dirname File.dirname loaded_from - end - end - - def backport_cache_file - redefine_method(Gem::Specification, :cache_dir) do - @cache_dir ||= File.join base_dir, "cache" - end - - redefine_method(Gem::Specification, :cache_file) do - @cache_file ||= File.join cache_dir, "#{full_name}.gem" - end - end - - def backport_spec_file - redefine_method(Gem::Specification, :spec_dir) do - @spec_dir ||= File.join base_dir, "specifications" - end - - redefine_method(Gem::Specification, :spec_file) do - @spec_file ||= File.join spec_dir, "#{full_name}.gemspec" - end - end - def undo_replacements @replaced_methods.each do |(sym, klass), method| redefine_method(klass, sym, method) @@ -602,10 +573,10 @@ module Bundler def backport_ext_builder_monitor # So we can avoid requiring "rubygems/ext" in its entirety - Gem.module_eval <<-RB, __FILE__, __LINE__ + 1 module Ext end - RB require "rubygems/ext/builder" @@ -12,7 +12,6 @@ module Bundler allow_offline_install auto_clean_without_path auto_install - auto_config_jobs cache_all cache_all_platforms default_install_uses_path @@ -22,7 +21,6 @@ module Bundler disable_exec_load disable_local_branch_check disable_multisource - disable_platform_warnings disable_shared_gems disable_version_check force_ruby_platform @@ -230,6 +230,10 @@ module Bundler @allow_remote || @allow_cached end private def serialize_gemspecs_in(destination) @@ -256,10 +260,6 @@ module Bundler cached_revision && super end - def local? - @local - end - def requires_checkout? allow_git_ops? && !local? && !cached_revision_checked_out? end @@ -18,7 +18,7 @@ module Bundler def initialize(command) msg = String.new msg << "Bundler is trying to run a `git #{command}` at runtime. You probably need to run `bundle install`. However, " - msg << "this error message could probably be more useful. Please submit a ticket at https://.com/bundler/bundler/issues " msg << "with steps to reproduce as well as the following\n\nCALLER: #{caller.join("\n")}" super msg end @@ -27,21 +27,21 @@ module Bundler class GitCommandError < GitError attr_reader :command - def initialize(command, path = nil, extra_info = nil) @command = command msg = String.new - msg << "Git error: command `git #{command}` in directory #{SharedHelpers.pwd} has failed." msg << "\n#{extra_info}" if extra_info - msg << "\nIf this error persists you could try removing the cache directory '#{path}'" if path && path.exist? super msg end end class MissingGitRevisionError < GitCommandError - def initialize(command, path, ref, repo) msg = "Revision #{ref} does not exist in the repository #{repo}. Maybe you misspelled it?" - super command, path, msg end end @@ -62,26 +62,18 @@ module Bundler end def revision - return @revision if @revision - - begin - @revision ||= find_local_revision - rescue GitCommandError => e - raise MissingGitRevisionError.new(e.command, path, ref, URICredentialsFilter.credential_filtered_uri(uri)) - end - - @revision end def branch - @branch ||= allowed_in_path do - git("rev-parse --abbrev-ref HEAD").strip end end def contains?(commit) - allowed_in_path do - result, status = git_null("branch --contains #{commit}") status.success? && result =~ /^\* (.*)$/ end end @@ -108,8 +100,8 @@ module Bundler return unless extra_ref end - in_path do - git_retry %(fetch --force --quiet --tags #{uri_escaped_with_configured_credentials} "refs/heads/*:refs/heads/*" #{extra_ref}) end end @@ -133,58 +125,54 @@ module Bundler end end # method 2 - SharedHelpers.chdir(destination) do - git_retry %(fetch --force --quiet --tags "#{path}") - begin - git "reset --hard #{@revision}" - rescue GitCommandError => e - raise MissingGitRevisionError.new(e.command, path, @revision, URICredentialsFilter.credential_filtered_uri(uri)) - end - if submodules - git_retry "submodule update --init --recursive" - elsif Gem::Version.create(version) >= Gem::Version.create("2.9.0") - git_retry "submodule deinit --all --force" - end end end private - def git_null(command) - command_with_no_credentials = URICredentialsFilter.credential_filtered_string(command, uri) - raise GitNotAllowedError.new(command_with_no_credentials) unless allow? out, status = SharedHelpers.with_clean_git_env do - capture_and_ignore_stderr("git #{command}") end [URICredentialsFilter.credential_filtered_string(out, uri), status] end - def git_retry(command) Bundler::Retry.new("`git #{URICredentialsFilter.credential_filtered_string(command, uri)}`", GitNotAllowedError).attempts do - git(command) end end - def git(command, check_errors = true, error_msg = nil) - command_with_no_credentials = URICredentialsFilter.credential_filtered_string(command, uri) - raise GitNotAllowedError.new(command_with_no_credentials) unless allow? out, status = SharedHelpers.with_clean_git_env do - capture_and_filter_stderr(uri, "git #{command}") end - stdout_with_no_credentials = URICredentialsFilter.credential_filtered_string(out, uri) - raise GitCommandError.new(command_with_no_credentials, path, error_msg) if check_errors && !status.success? - stdout_with_no_credentials end def has_revision_cached? return unless @revision - in_path { git("cat-file -e #{@revision}") } true rescue GitError false @@ -195,9 +183,11 @@ module Bundler end def find_local_revision - allowed_in_path do - git("rev-parse --verify #{Shellwords.shellescape(ref)}", true).strip end end # Escape the URI for git commands @@ -230,27 +220,32 @@ module Bundler @git ? @git.allow_git_ops? : true end - def in_path(&blk) checkout unless path.exist? - _ = URICredentialsFilter # load it before we chdir - SharedHelpers.chdir(path, &blk) end - def allowed_in_path - return in_path { yield } if allow? raise GitError, "The git source #{uri} is not yet checked out. Please run `bundle install` before trying to start your application" end - def capture_and_filter_stderr(uri, cmd) require "open3" - return_value, captured_err, status = Open3.capture3(cmd) Bundler.ui.warn URICredentialsFilter.credential_filtered_string(captured_err, uri) if uri && !captured_err.empty? [return_value, status] end - def capture_and_ignore_stderr(cmd) require "open3" - return_value, _, status = Open3.capture3(cmd) [return_value, status] end end @@ -132,7 +132,11 @@ module Bundler end def expand(somepath) - somepath.expand_path(root_path) rescue ArgumentError => e Bundler.ui.debug(e) raise PathError, "There was an error while trying to use the path " \ @@ -26,18 +26,16 @@ module Bundler end def post_install - SharedHelpers.chdir(@gem_dir) do - run_hooks(:pre_install) - unless @disable_extensions - build_extensions - run_hooks(:post_build) - end - generate_bin unless spec.executables.nil? || spec.executables.empty? - run_hooks(:post_install) - end ensure Bundler.rm_rf(@tmp_dir) if Bundler.requires_sudo? end @@ -2,73 +2,83 @@ ## Our Pledge -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. ## Our Standards -Examples of behavior that contributes to creating a positive environment -include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members -Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or -advances -* Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting -## Our Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. ## Scope -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at <%= config[:email] %>. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain ity with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [https://contributor-covenant.org/version/1/4][version] -[homepage]: https://contributor-covenant.org -[version]: https://contributor-covenant.org/version/1/4/ @@ -3,10 +3,13 @@ source "https://rubygems.org" # Specify your gem's dependencies in <%= config[:name] %>.gemspec gemspec -gem "rake", "~> 12.0" <%- if config[:ext] -%> gem "rake-compiler" <%- end -%> <%- if config[:test] -%> gem "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>" <%- end -%> @@ -1,5 +1,7 @@ require "bundler/gem_tasks" -<% if config[:test] == "minitest" -%> require "rake/testtask" Rake::TestTask.new(:test) do |t| @@ -8,13 +10,21 @@ Rake::TestTask.new(:test) do |t| t.test_files = FileList["test/**/*_test.rb"] end -<% elsif config[:test] == "rspec" -%> require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) <% end -%> <% if config[:ext] -%> require "rake/extensiontask" task :build => :compile @@ -23,7 +33,5 @@ Rake::ExtensionTask.new("<%= config[:underscored_name] %>") do |ext| ext.lib_dir = "lib/<%= config[:namespaced_path] %>" end -task :default => [:clobber, :compile, :<%= config[:test_task] %>] -<% else -%> -task :default => :<%= config[:test_task] %> <% end -%> @@ -1,4 +1,4 @@ -require_relative 'lib/<%=config[:namespaced_path]%>/version' Gem::Specification.new do |spec| spec.name = <%= config[:name].inspect %> @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end spec.bindir = "exe" @@ -0,0 +1,11 @@ @@ -0,0 +1,4 @@ @@ -0,0 +1,13 @@ @@ -0,0 +1,4 @@ @@ -12,15 +12,11 @@ autoload :OpenSSL, 'openssl' # servers you wish to talk to. For each host:port you communicate with a # single persistent connection is created. # -# Multiple Bundler::Persistent::Net::HTTP::Persistent objects will share the same set of -# connections. # -# For each thread you start a new connection will be created. A -# Bundler::Persistent::Net::HTTP::Persistent connection will not be shared across threads. -# -# You can shut down the HTTP connections when done by calling #shutdown. You -# should name your Bundler::Persistent::Net::HTTP::Persistent object if you intend to call this -# method. # # Example: # @@ -28,7 +24,7 @@ autoload :OpenSSL, 'openssl' # # uri = Bundler::URI 'http://example.com/awesome/web/service' # -# http = Bundler::Persistent::Net::HTTP::Persistent.new name: 'my_app_name' # # # perform a GET # response = http.request uri @@ -50,14 +46,14 @@ autoload :OpenSSL, 'openssl' # to use Bundler::URI#request_uri not Bundler::URI#path. The request_uri contains the query # params which are sent in the body for other requests. # -# == SSL # -# SSL connections are automatically created depending upon the scheme of the -# Bundler::URI. SSL connections are automatically verified against the default # certificate store for your computer. You can override this by changing # verify_mode or by specifying an alternate cert_store. # -# Here are the SSL settings, see the individual methods for documentation: # # #certificate :: This client's certificate # #ca_file :: The certificate-authorities @@ -67,7 +63,7 @@ autoload :OpenSSL, 'openssl' # #private_key :: The client's SSL private key # #reuse_ssl_sessions :: Reuse a previously opened SSL session for a new # connection -# #ssl_timeout :: SSL session lifetime # #ssl_version :: Which specific SSL version to use # #verify_callback :: For server certificate verification # #verify_depth :: Depth of certificate verification @@ -96,14 +92,15 @@ autoload :OpenSSL, 'openssl' # # === Segregation # -# By providing an application name to ::new you can separate your connections -# from the connections of other applications. # # === Idle Timeout # -# If a connection hasn't been used for this number of seconds it will automatically be -# reset upon the next use to avoid attempting to send to a closed connection. -# The default value is 5 seconds. nil means no timeout. Set through #idle_timeout. # # Reducing this value may help avoid the "too many connection resets" error # when sending non-idempotent requests while increasing this value will cause @@ -118,8 +115,9 @@ autoload :OpenSSL, 'openssl' # # The number of requests that should be made before opening a new connection. # Typically many keep-alive capable servers tune this to 100 or less, so the -# 101st request will fail with ECONNRESET. If unset (default), this value has no -# effect, if set, connections will be reset on the request after max_requests. # # === Open Timeout # @@ -131,45 +129,6 @@ autoload :OpenSSL, 'openssl' # Socket options may be set on newly-created connections. See #socket_options # for details. # -# === Non-Idempotent Requests -# -# By default non-idempotent requests will not be retried per RFC 2616. By -# setting retry_change_requests to true requests will automatically be retried -# once. -# -# Only do this when you know that retrying a POST or other non-idempotent -# request is safe for your application and will not create duplicate -# resources. -# -# The recommended way to handle non-idempotent requests is the following: -# -# require 'bundler/vendor/net-http-persistent/lib/net/http/persistent' -# -# uri = Bundler::URI 'http://example.com/awesome/web/service' -# post_uri = uri + 'create' -# -# http = Bundler::Persistent::Net::HTTP::Persistent.new name: 'my_app_name' -# -# post = Net::HTTP::Post.new post_uri.path -# # ... fill in POST request -# -# begin -# response = http.request post_uri, post -# rescue Bundler::Persistent::Net::HTTP::Persistent::Error -# -# # POST failed, make a new request to verify the server did not process -# # the request -# exists_uri = uri + '...' -# response = http.get exists_uri -# -# # Retry if it failed -# retry if response.code == '404' -# end -# -# The method of determining if the resource was created or not is unique to -# the particular service you are using. Of course, you will want to add -# protection from infinite looping. -# # === Connection Termination # # If you are done using the Bundler::Persistent::Net::HTTP::Persistent instance you may shut down @@ -195,33 +154,20 @@ class Bundler::Persistent::Net::HTTP::Persistent HAVE_OPENSSL = defined? OpenSSL::SSL # :nodoc: ## - # The default connection pool size is 1/4 the allowed open files. - if Gem.win_platform? then - DEFAULT_POOL_SIZE = 256 - else DEFAULT_POOL_SIZE = Process.getrlimit(Process::RLIMIT_NOFILE).first / 4 end ## # The version of Bundler::Persistent::Net::HTTP::Persistent you are using - VERSION = '3.1.0' - - ## - # Exceptions rescued for automatic retry on ruby 2.0.0. This overlaps with - # the exception list for ruby 1.x. - - RETRIED_EXCEPTIONS = [ # :nodoc: - (Net::ReadTimeout if Net.const_defined? :ReadTimeout), - IOError, - EOFError, - Errno::ECONNRESET, - Errno::ECONNABORTED, - Errno::EPIPE, - (OpenSSL::SSL::SSLError if HAVE_OPENSSL), - Timeout::Error, - ].compact ## # Error class for errors raised by Bundler::Persistent::Net::HTTP::Persistent. Various @@ -349,6 +295,13 @@ class Bundler::Persistent::Net::HTTP::Persistent attr_accessor :max_requests ## # The value sent in the Keep-Alive header. Defaults to 30. Not needed for # HTTP/1.1 servers. # @@ -360,8 +313,7 @@ class Bundler::Persistent::Net::HTTP::Persistent attr_accessor :keep_alive ## - # A name for this connection. Allows you to keep your connections apart - # from everybody else's. attr_reader :name @@ -491,22 +443,10 @@ class Bundler::Persistent::Net::HTTP::Persistent attr_reader :verify_mode ## - # Enable retries of non-idempotent requests that change data (e.g. POST - # requests) when the server has disconnected. - # - # This will in the worst case lead to multiple requests with the same data, - # but it may be useful for some applications. Take care when enabling - # this option to ensure it is safe to POST or perform other non-idempotent - # requests to the server. - - attr_accessor :retry_change_requests - - ## # Creates a new Bundler::Persistent::Net::HTTP::Persistent. # - # Set +name+ to keep your connections apart from everybody else's. Not - # required currently, but highly recommended. Your library name should be - # good enough. This parameter will be required in a future version. # # +proxy+ may be set to a Bundler::URI::HTTP or :ENV to pick up proxy options from # the environment. See proxy_from_env for details. @@ -519,8 +459,9 @@ class Bundler::Persistent::Net::HTTP::Persistent # proxy.password = 'hunter2' # # Set +pool_size+ to limit the maximum number of connections allowed. - # Defaults to 1/4 the number of allowed file handles. You can have no more - # than this many threads with active HTTP transactions. def initialize name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE @name = name @@ -537,6 +478,7 @@ class Bundler::Persistent::Net::HTTP::Persistent @write_timeout = nil @idle_timeout = 5 @max_requests = nil @socket_options = [] @ssl_generation = 0 # incremented when SSL session variables change @@ -568,8 +510,6 @@ class Bundler::Persistent::Net::HTTP::Persistent @reuse_ssl_sessions = OpenSSL::SSL.const_defined? :Session end - @retry_change_requests = false - self.proxy = proxy if proxy end @@ -630,7 +570,9 @@ class Bundler::Persistent::Net::HTTP::Persistent net_http_args = [uri.hostname, uri.port] - if @proxy_uri and not proxy_bypass? uri.hostname, uri.port then net_http_args.concat @proxy_args else net_http_args.concat [nil, nil, nil, nil] @@ -650,9 +592,11 @@ class Bundler::Persistent::Net::HTTP::Persistent reset connection end - http.read_timeout = @read_timeout if @read_timeout - http.write_timeout = @write_timeout if @write_timeout && http.respond_to?(:write_timeout=) - http.keep_alive_timeout = @idle_timeout if @idle_timeout return yield connection rescue Errno::ECONNREFUSED @@ -670,27 +614,14 @@ class Bundler::Persistent::Net::HTTP::Persistent end ## - # Returns an error message containing the number of requests performed on - # this connection - - def error_message connection - connection.requests -= 1 # fixup - - age = Time.now - connection.last_use - - "after #{connection.requests} requests on #{connection.http.object_id}, " \ - "last used #{age} seconds ago" - end - - ## - # Bundler::URI::escape wrapper def escape str CGI.escape str if str end ## - # Bundler::URI::unescape wrapper def unescape str CGI.unescape str if str @@ -733,6 +664,7 @@ class Bundler::Persistent::Net::HTTP::Persistent def finish connection connection.finish connection.http.instance_variable_set :@ssl_session, nil unless @reuse_ssl_sessions end @@ -741,31 +673,31 @@ class Bundler::Persistent::Net::HTTP::Persistent # Returns the HTTP protocol version for +uri+ def http_version uri - @http_versions["#{uri.host}:#{uri.port}"] end ## - # Is +req+ idempotent according to RFC 2616? - def idempotent? req - case req.method - when 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE' then - true - end end ## - # Is the request +req+ idempotent or is retry_change_requests allowed. - def can_retry? req - @retry_change_requests && !idempotent?(req) - end - ## - # Adds "http://" to the String +uri+ if it is missing. - def normalize_uri uri - (uri =~ /^https?:/) ? uri : "http://#{uri}" end ## @@ -806,7 +738,7 @@ class Bundler::Persistent::Net::HTTP::Persistent if @proxy_uri then @proxy_args = [ - @proxy_uri.host, @proxy_uri.port, unescape(@proxy_uri.user), unescape(@proxy_uri.password), @@ -881,14 +813,15 @@ class Bundler::Persistent::Net::HTTP::Persistent end ## - # Forces reconnection of HTTP connections. def reconnect @generation += 1 end ## - # Forces reconnection of SSL connections. def reconnect_ssl @ssl_generation += 1 @@ -921,14 +854,8 @@ class Bundler::Persistent::Net::HTTP::Persistent # the response will not have been read). # # +req+ must be a Net::HTTPGenericRequest subclass (see Net::HTTP for a list). - # - # If there is an error and the request is idempotent according to RFC 2616 - # it will be retried automatically. def request uri, req = nil, &block - retried = false - bad_response = false - uri = Bundler::URI uri req = request_setup req || uri response = nil @@ -942,37 +869,12 @@ class Bundler::Persistent::Net::HTTP::Persistent response = http.request req, &block if req.connection_close? or - (response.http_version <= '1.0' and not response.connection_keep_alive?) or - response.connection_close? then finish connection end - rescue Net::HTTPBadResponse => e - message = error_message connection - - finish connection - - raise Error, "too many bad responses #{message}" if - bad_response or not can_retry? req - - bad_response = true - retry - rescue *RETRIED_EXCEPTIONS => e - request_failed e, req, connection if - retried or not can_retry? req - - reset connection - - retried = true - retry - rescue Errno::EINVAL, Errno::ETIMEDOUT => e # not retried on ruby 2 - request_failed e, req, connection if retried or not can_retry? req - - reset connection - - retried = true - retry - rescue Exception => e finish connection raise @@ -981,34 +883,19 @@ class Bundler::Persistent::Net::HTTP::Persistent end end - @http_versions["#{uri.host}:#{uri.port}"] ||= response.http_version response end ## - # Raises an Error for +exception+ which resulted from attempting the request - # +req+ on the +connection+. - # - # Finishes the +connection+. - - def request_failed exception, req, connection # :nodoc: - due_to = "(due to #{exception.message} - #{exception.class})" - message = "too many connection resets #{due_to} #{error_message connection}" - - finish connection - - raise Error, message, exception.backtrace - end - - ## # Creates a GET request if +req_or_uri+ is a Bundler::URI and adds headers to the # request. # # Returns the request. def request_setup req_or_uri # :nodoc: - req = if Bundler::URI === req_or_uri then Net::HTTP::Get.new req_or_uri.request_uri else req_or_uri @@ -1172,7 +1059,6 @@ application: reconnect_ssl end - end require_relative 'persistent/connection' @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.1.4".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i |