# frozen_string_literal: truemoduleBundlerclassSourceListattr_reader:path_sources,:git_sources,:plugin_sources,:global_path_source,:metadata_sourcedefglobal_rubygems_source@global_rubygems_source||=rubygems_aggregate_class.new("allow_local"=>true)enddefinitialize@path_sources=[]@git_sources=[]@plugin_sources=[]@global_rubygems_source=nil@global_path_source=nil@rubygems_sources=[]@metadata_source=Source::Metadata.new@merged_gem_lockfile_sections=false@local_mode=trueenddefmerged_gem_lockfile_sections?@merged_gem_lockfile_sectionsenddefmerged_gem_lockfile_sections!(replacement_source)@merged_gem_lockfile_sections=true@global_rubygems_source=replacement_sourceenddefaggregate_global_source?global_rubygems_source.multiple_remotes?enddefimplicit_global_source?global_rubygems_source.no_remotes?enddefadd_path_source(options={})ifoptions["gemspec"]add_source_to_listSource::Gemspec.new(options),path_sourceselsepath_source=add_source_to_listSource::Path.new(options),path_sources@global_path_source||=path_sourceifoptions["global"]path_sourceendenddefadd_git_source(options={})add_source_to_list(Source::Git.new(options),git_sources).tapdo|source|warn_on_git_protocol(source)endenddefadd_rubygems_source(options={})new_source=Source::Rubygems.new(options)return@global_rubygems_sourceif@global_rubygems_source==new_sourceadd_source_to_listnew_source,@rubygems_sourcesenddefadd_plugin_source(source,options={})add_source_to_listPlugin.source(source).new(options),@plugin_sourcesenddefadd_global_rubygems_remote(uri)global_rubygems_source.add_remote(uri)global_rubygems_sourceenddeflocal_mode?@local_modeenddefdefault_sourceglobal_path_source||global_rubygems_sourceenddefrubygems_sourcesnon_global_rubygems_sources+[global_rubygems_source]enddefnon_global_rubygems_sources@rubygems_sourcesenddefrubygems_remotesrubygems_sources.flat_map(&:remotes).uniqenddefall_sourcespath_sources+git_sources+plugin_sources+rubygems_sources+[metadata_source]enddefnon_default_explicit_sourcesall_sources-[default_source,metadata_source]enddefget(source)source_list_for(source).find{|s|equivalent_source?(source,s)}enddeflock_sourceslock_other_sources+lock_rubygems_sourcesenddeflock_other_sources(path_sources+git_sources+plugin_sources).sort_by(&:identifier)enddeflock_rubygems_sourcesifmerged_gem_lockfile_sections?[combine_rubygems_sources]elserubygems_sources.sort_by(&:identifier)endend# Returns true if there are changesdefreplace_sources!(replacement_sources)returnfalseifreplacement_sources.empty?@rubygems_sources,@path_sources,@git_sources,@plugin_sources=map_sources(replacement_sources)@global_rubygems_source=global_replacement_source(replacement_sources)different_sources?(lock_sources,replacement_sources)end# Returns true if there are changesdefexpired_sources?(replacement_sources)returnfalseifreplacement_sources.empty?lock_sources=dup_with_replaced_sources(replacement_sources).lock_sourcesdifferent_sources?(lock_sources,replacement_sources)enddefprefer_local!all_sources.each(&:prefer_local!)enddeflocal_only!all_sources.each(&:local_only!)enddeflocal!all_sources.each(&:local!)enddefcached!all_sources.each(&:cached!)enddefremote!@local_mode=falseall_sources.each(&:remote!)endprivatedefdup_with_replaced_sources(replacement_sources)new_source_list=dupnew_source_list.replace_sources!(replacement_sources)new_source_listenddefmap_sources(replacement_sources)rubygems=@rubygems_sources.mapdo|source|replace_rubygems_source(replacement_sources,source)endgit,plugin=[@git_sources,@plugin_sources].mapdo|sources|sources.mapdo|source|replace_source(replacement_sources,source)endendpath=@path_sources.mapdo|source|replace_path_source(replacement_sources,source)end[rubygems,path,git,plugin]enddefglobal_replacement_source(replacement_sources)replace_rubygems_source(replacement_sources,global_rubygems_source,&:local!)enddefreplace_rubygems_source(replacement_sources,gemfile_source)replace_source(replacement_sources,gemfile_source)do|replacement_source|# locked sources never include credentials so always prefer remotes from the gemfilereplacement_source.remotes=gemfile_source.remotesyieldreplacement_sourceifblock_given?replacement_sourceendenddefreplace_source(replacement_sources,gemfile_source)replacement_source=replacement_sources.find{|s|s==gemfile_source}returngemfile_sourceunlessreplacement_sourcereplacement_source=yield(replacement_source)ifblock_given?replacement_sourceenddefreplace_path_source(replacement_sources,gemfile_source)replace_source(replacement_sources,gemfile_source)do|replacement_source|ifgemfile_source.is_a?(Source::Gemspec)gemfile_source.checksum_store=replacement_source.checksum_storegemfile_sourceelsereplacement_sourceendendenddefdifferent_sources?(lock_sources,replacement_sources)!equivalent_sources?(lock_sources,replacement_sources)enddefrubygems_aggregate_classSource::Rubygemsenddefadd_source_to_list(source,list)list.unshift(source).uniq!sourceenddefsource_list_for(source)casesourcewhenSource::Gitthengit_sourceswhenSource::Paththenpath_sourceswhenSource::Rubygemsthenrubygems_sourceswhenPlugin::API::Sourcethenplugin_sourceselseraiseArgumentError,"Invalid source: #{source.inspect}"endenddefcombine_rubygems_sourcesSource::Rubygems.new("remotes"=>rubygems_remotes)enddefwarn_on_git_protocol(source)returnifBundler.settings["git.allow_insecure"]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` "\"protocol to keep your data secure."endenddefequivalent_sources?(lock_sources,replacement_sources)lock_sources.sort_by(&:identifier)==replacement_sources.sort_by(&:identifier)enddefequivalent_source?(source,other_source)source==other_sourceendendend