aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/dependency_list.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/dependency_list.rb')
-rw-r--r--lib/rubygems/dependency_list.rb38
1 files changed, 35 insertions, 3 deletions
diff --git a/lib/rubygems/dependency_list.rb b/lib/rubygems/dependency_list.rb
index 647bb91ae2..91c7c5ade4 100644
--- a/lib/rubygems/dependency_list.rb
+++ b/lib/rubygems/dependency_list.rb
@@ -17,6 +17,7 @@ require 'tsort'
# correct order to avoid conflicts.
class Gem::DependencyList
+ attr_reader :specs
include Enumerable
include TSort
@@ -56,6 +57,10 @@ class Gem::DependencyList
@specs.push(*gemspecs)
end
+ def clear
+ @specs.clear
+ end
+
##
# Return a list of the gem specifications in the dependency list, sorted in
# order so that no gemspec in the list depends on a gemspec earlier in the
@@ -110,11 +115,26 @@ class Gem::DependencyList
# Are all the dependencies in the list satisfied?
def ok?
- @specs.all? do |spec|
- spec.runtime_dependencies.all? do |dep|
- @specs.find { |s| s.satisfies_requirement? dep }
+ why_not_ok?(:quick).empty?
+ end
+
+ def why_not_ok? quick = false
+ unsatisfied = Hash.new { |h,k| h[k] = [] }
+ source_index = Gem.source_index
+ @specs.each do |spec|
+ spec.runtime_dependencies.each do |dep|
+ inst = source_index.any? { |_, installed_spec|
+ dep.name == installed_spec.name and
+ dep.requirement.satisfied_by? installed_spec.version
+ }
+
+ unless inst or @specs.find { |s| s.satisfies_requirement? dep } then
+ unsatisfied[spec.name] << dep
+ return unsatisfied if quick
+ end
end
end
+ unsatisfied
end
##
@@ -147,6 +167,18 @@ class Gem::DependencyList
end
##
+ # Remove everything in the DependencyList that matches but doesn't
+ # satisfy items in +dependencies+ (a hash of gem names to arrays of
+ # dependencies).
+
+ def remove_specs_unsatisfied_by dependencies
+ specs.reject! { |spec|
+ dep = dependencies[spec.name]
+ dep and not dep.requirement.satisfied_by? spec.version
+ }
+ end
+
+ ##
# Removes the gemspec matching +full_name+ from the dependency list
def remove_by_name(full_name)