Permalink
Browse files

Alphabetize Gem::DependencyInstaller

  • Loading branch information...
1 parent 37c5dde commit 4cee7aba52d51a986cdd1ef310ddf6031cbfe51c @drbrain drbrain committed Apr 4, 2013
Showing with 112 additions and 111 deletions.
  1. +112 −111 lib/rubygems/dependency_installer.rb
@@ -16,14 +16,6 @@ class Gem::DependencyInstaller
include Gem::UserInteraction
- attr_reader :gems_to_install
- attr_reader :installed_gems
-
- ##
- # Documentation types. For use by the Gem.done_installing hook
-
- attr_reader :document
-
DEFAULT_OPTIONS = {
:env_shebang => false,
:document => %w[ri],
@@ -39,6 +31,17 @@ class Gem::DependencyInstaller
}.freeze
##
+ # Documentation types. For use by the Gem.done_installing hook
+
+ attr_reader :document
+
+ attr_reader :errors
+
+ attr_reader :gems_to_install
+
+ attr_reader :installed_gems
+
+ ##
# Creates a new installer instance.
#
# Options are:
@@ -57,7 +60,7 @@ class Gem::DependencyInstaller
# :wrappers:: See Gem::Installer::new
# :build_args:: See Gem::Installer::new
- def initialize(options = {})
+ def initialize options = {}
@only_install_dir = !!options[:install_dir]
@install_dir = options[:install_dir] || Gem.dir
@@ -100,8 +103,55 @@ def initialize(options = {})
@errors = nil
end
- attr_reader :errors
+ def add_found_dependencies to_do, dependency_list
+ seen = {}
+ dependencies = Hash.new { |h, name| h[name] = Gem::Dependency.new name }
+
+ until to_do.empty? do
+ spec = to_do.shift
+
+ # HACK why is spec nil?
+ next if spec.nil? or seen[spec.name]
+ seen[spec.name] = true
+
+ deps = spec.runtime_dependencies
+
+ if @development
+ if @dev_shallow
+ if @toplevel_specs.include? spec.full_name
+ deps |= spec.development_dependencies
+ end
+ else
+ deps |= spec.development_dependencies
+ end
+ end
+
+ deps.each do |dep|
+ dependencies[dep.name] = dependencies[dep.name].merge dep
+
+ if @minimal_deps
+ next if Gem::Specification.any? do |installed_spec|
+ dep.name == installed_spec.name and
+ dep.requirement.satisfied_by? installed_spec.version
+ end
+ end
+
+ results = find_gems_with_sources(dep)
+
+ results.sorted.each do |t|
+ to_do.push t.spec
+ end
+
+ results.remove_installed! dep
+
+ @available << results
+ results.inject_into_list dependency_list
+ end
+ end
+
+ dependency_list.remove_specs_unsatisfied_by dependencies
+ end
##
# Creates an AvailableSet to install from based on +dep_or_name+ and
# +version+
@@ -140,7 +190,7 @@ def consider_remote?
# sources. Gems are sorted with newer gems preferred over older gems, and
# local gems preferred over remote gems.
- def find_gems_with_sources(dep)
+ def find_gems_with_sources dep
set = Gem::AvailableSet.new
if consider_local?
@@ -181,6 +231,46 @@ def find_gems_with_sources(dep)
end
##
+ # Finds a spec and the source_uri it came from for gem +gem_name+ and
+ # +version+. Returns an Array of specs and sources required for
+ # installation of the gem.
+
+ def find_spec_by_name_and_version gem_name,
+ version = Gem::Requirement.default,
+ prerelease = false
+
+ set = Gem::AvailableSet.new
+
+ if consider_local?
+ if gem_name =~ /\.gem$/ and File.file? gem_name then
+ src = Gem::Source::SpecificFile.new(gem_name)
+ set.add src.spec, src
+ else
+ local = Gem::Source::Local.new
+
+ if s = local.find_gem(gem_name, version)
+ set.add s, local
+ end
+ end
+ end
+
+ if set.empty?
+ dep = Gem::Dependency.new gem_name, version
+ # HACK Dependency objects should be immutable
+ dep.prerelease = true if prerelease
+
+ set = find_gems_with_sources(dep)
+ set.match_platform!
+ end
+
+ if set.empty?
+ raise Gem::SpecificGemNotFoundException.new(gem_name, version, @errors)
+ end
+
+ @available = set
+ end
+
+ ##
# Gathers all dependencies necessary for the installation from local and
# remote sources unless the ignore_dependencies was given.
@@ -216,93 +306,19 @@ def gather_dependencies
@gems_to_install = dependency_list.dependency_order.reverse
end
- def add_found_dependencies to_do, dependency_list
- seen = {}
- dependencies = Hash.new { |h, name| h[name] = Gem::Dependency.new name }
-
- until to_do.empty? do
- spec = to_do.shift
-
- # HACK why is spec nil?
- next if spec.nil? or seen[spec.name]
- seen[spec.name] = true
-
- deps = spec.runtime_dependencies
-
- if @development
- if @dev_shallow
- if @toplevel_specs.include? spec.full_name
- deps |= spec.development_dependencies
- end
- else
- deps |= spec.development_dependencies
- end
- end
-
- deps.each do |dep|
- dependencies[dep.name] = dependencies[dep.name].merge dep
-
- if @minimal_deps
- next if Gem::Specification.any? do |installed_spec|
- dep.name == installed_spec.name and
- dep.requirement.satisfied_by? installed_spec.version
- end
- end
-
- results = find_gems_with_sources(dep)
-
- results.sorted.each do |t|
- to_do.push t.spec
- end
-
- results.remove_installed! dep
-
- @available << results
- results.inject_into_list dependency_list
- end
- end
-
- dependency_list.remove_specs_unsatisfied_by dependencies
- end
-
- ##
- # Finds a spec and the source_uri it came from for gem +gem_name+ and
- # +version+. Returns an Array of specs and sources required for
- # installation of the gem.
-
- def find_spec_by_name_and_version(gem_name,
- version = Gem::Requirement.default,
- prerelease = false)
-
- set = Gem::AvailableSet.new
-
- if consider_local?
- if gem_name =~ /\.gem$/ and File.file? gem_name then
- src = Gem::Source::SpecificFile.new(gem_name)
- set.add src.spec, src
- else
- local = Gem::Source::Local.new
-
- if s = local.find_gem(gem_name, version)
- set.add s, local
+ def in_background what
+ fork_happened = false
+ if @build_docs_in_background and Process.respond_to?(:fork)
+ begin
+ Process.fork do
+ yield
end
+ fork_happened = true
+ say "#{what} in a background process."
+ rescue NotImplementedError
end
end
-
- if set.empty?
- dep = Gem::Dependency.new gem_name, version
- # HACK Dependency objects should be immutable
- dep.prerelease = true if prerelease
-
- set = find_gems_with_sources(dep)
- set.match_platform!
- end
-
- if set.empty?
- raise Gem::SpecificGemNotFoundException.new(gem_name, version, @errors)
- end
-
- @available = set
+ yield unless fork_happened
end
##
@@ -365,22 +381,7 @@ def install_development_deps
end
end
- def in_background what
- fork_happened = false
- if @build_docs_in_background and Process.respond_to?(:fork)
- begin
- Process.fork do
- yield
- end
- fork_happened = true
- say "#{what} in a background process."
- rescue NotImplementedError
- end
- end
- yield unless fork_happened
- end
-
- def resolve_dependencies dep_or_name, version
+ def resolve_dependencies dep_or_name, version # :nodoc:
as = available_set_for dep_or_name, version
request_set = as.to_request_set install_development_deps

0 comments on commit 4cee7ab

Please sign in to comment.