lib/rubygems/dependency_installer.rb in rubygems-update-2.1.11 vs lib/rubygems/dependency_installer.rb in rubygems-update-2.2.0.rc.1

- old
+ new

@@ -1,8 +1,7 @@ require 'rubygems' require 'rubygems/dependency_list' -require 'rubygems/dependency_resolver' require 'rubygems/package' require 'rubygems/installer' require 'rubygems/spec_fetcher' require 'rubygems/user_interaction' require 'rubygems/source' @@ -194,11 +193,11 @@ # Returns a list of pairs of gemspecs and source_uris that match # Gem::Dependency +dep+ from both local (Dir.pwd) and remote (Gem.sources) # sources. Gems are sorted with newer gems preferred over older gems, and # local gems preferred over remote gems. - def find_gems_with_sources dep # :nodoc: + def find_gems_with_sources dep, best_only=false # :nodoc: set = Gem::AvailableSet.new if consider_local? sl = Gem::Source::Local.new @@ -209,19 +208,38 @@ end end if consider_remote? begin - found, errors = Gem::SpecFetcher.fetcher.spec_for_dependency dep + # TODO this is pulled from #spec_for_dependency to allow + # us to filter tuples before fetching specs. + # + tuples, errors = Gem::SpecFetcher.fetcher.search_for_dependency dep + if best_only && !tuples.empty? + tuples.sort! { |a,b| b[0].version <=> a[0].version } + tuples = [tuples.first] + end + + specs = [] + tuples.each do |tup, source| + begin + spec = source.fetch_spec(tup) + rescue Gem::RemoteFetcher::FetchError => e + errors << Gem::SourceFetchProblem.new(source, e) + else + specs << [spec, source] + end + end + if @errors @errors += errors else @errors = errors end - set << found + set << specs rescue Gem::RemoteFetcher::FetchError => e # FIX if there is a problem talking to the network, we either need to always tell # the user (no really_verbose) or fail hard, not silently tell them that we just # couldn't find their requested gem. @@ -269,11 +287,11 @@ if set.empty? dep = Gem::Dependency.new gem_name, version dep.prerelease = true if prerelease - set = find_gems_with_sources(dep) + set = find_gems_with_sources(dep, true) set.match_platform! end if set.empty? raise Gem::SpecificGemNotFoundException.new(gem_name, version, @errors) @@ -284,11 +302,11 @@ ## # Gathers all dependencies necessary for the installation from local and # remote sources unless the ignore_dependencies was given. #-- - # TODO remove, no longer used + # TODO remove at RubyGems 3 def gather_dependencies # :nodoc: specs = @available.all_specs # these gems were listed by the user, always install them @@ -400,19 +418,20 @@ as = available_set_for dep_or_name, version request_set = as.to_request_set install_development_deps request_set.soft_missing = @force - installer_set = Gem::DependencyResolver::InstallerSet.new @domain + installer_set = Gem::Resolver::InstallerSet.new @domain installer_set.always_install.concat request_set.always_install installer_set.ignore_installed = @only_install_dir if @ignore_dependencies then installer_set.ignore_dependencies = true - request_set.soft_missing = true + request_set.ignore_dependencies = true + request_set.soft_missing = true end - composed_set = Gem::DependencyResolver.compose_sets as, installer_set + composed_set = Gem::Resolver.compose_sets as, installer_set request_set.resolve composed_set request_set end