# File lib/librarian/spec_change_set.rb, line 14 def initialize(environment, spec, lock) self.environment = environment raise TypeError, "can't convert #{spec.class} into #{Spec}" unless Spec === spec raise TypeError, "can't convert #{lock.class} into #{Resolution}" unless Resolution === lock @spec, @lock = spec, lock end
# File lib/librarian/spec_change_set.rb, line 75 def added_dependency_names @added_dependency_names ||= spec_dependency_names - lock_dependency_names end
Returns an array of those manifests from the previous spec which should be kept,
based on inspecting the new spec against the locked resolution from the previous spec.
# File lib/librarian/spec_change_set.rb, line 142 def analyze @analyze ||= begin debug { "Analyzing spec and lock:" } if same? debug { " Same!" } return lock.manifests end debug { " Removed:" } ; removed_dependency_names.each { |name| debug { " #{name}" } } debug { " ExplicitRemoved:" } ; explicit_removed_dependency_names.each { |name| debug { " #{name}" } } debug { " Added:" } ; added_dependency_names.each { |name| debug { " #{name}" } } debug { " NonMatchingAdded:" } ; nonmatching_added_dependency_names.each { |name| debug { " #{name}" } } debug { " Changed:" } ; changed_dependency_names.each { |name| debug { " #{name}" } } debug { " DeepKeep:" } ; deep_keep_manifest_names.each { |name| debug { " #{name}" } } debug { " ShallowStrip:" } ; shallow_strip_manifest_names.each { |name| debug { " #{name}" } } manifests = ManifestSet.new(lock_manifests) manifests.deep_keep!(deep_keep_manifest_names) manifests.shallow_strip!(shallow_strip_manifest_names) manifests.to_a end end
# File lib/librarian/spec_change_set.rb, line 25 def changed? !same? end
# File lib/librarian/spec_change_set.rb, line 98 def changed_dependency_names @changed_dependency_names ||= common_dependency_names.reject do |name| spec_dependency = spec_dependency_index[name] lock_dependency = lock_dependency_index[name] lock_manifest = lock_manifests_index[name] same = true same &&= spec_dependency.satisfied_by?(lock_manifest) same &&= spec_dependency.source == lock_dependency.source same end.to_set end
# File lib/librarian/spec_change_set.rb, line 94 def common_dependency_names @common_dependency_names ||= lock_dependency_names & spec_dependency_names end
# File lib/librarian/spec_change_set.rb, line 110 def deep_keep_manifest_names @deep_keep_manifest_names ||= begin lock_dependency_names - ( removed_dependency_names + changed_dependency_names + nonmatching_added_dependency_names ) end end
A dependency which is deleted from the specfile will, in the general case,
be removed conservatively. This means it might not actually be removed. But if the dependency originally declared a source which is now non- default, it must be removed, even if another dependency has a transitive dependency on the one that was removed (which is the scenario in which a conservative removal would not remove it). In this case, we must also remove it explicitly so that it can be re-resolved from the default source.
# File lib/librarian/spec_change_set.rb, line 68 def explicit_removed_dependency_names @explicit_removed_dependency_names ||= removed_dependency_names.reject do |name| lock_manifest = lock_manifests_index[name] spec.sources.include?(lock_manifest.source) end.to_set end
# File lib/librarian/spec_change_set.rb, line 126 def inspect Helpers.strip_heredoc(" <##{self.class.name}: Removed: #{removed_dependency_names.to_a.join(", ")} ExplicitRemoved: #{explicit_removed_dependency_names.to_a.join(", ")} Added: #{added_dependency_names.to_a.join(", ")} NonMatchingAdded: #{nonmatching_added_dependency_names.to_a.join(", ")} Changed: #{changed_dependency_names.to_a.join(", ")} DeepKeep: #{deep_keep_manifest_names.to_a.join(", ")} ShallowStrip: #{shallow_strip_manifest_names.to_a.join(", ")} > ") end
# File lib/librarian/spec_change_set.rb, line 39 def lock_dependencies @lock_dependencies ||= lock.dependencies end
# File lib/librarian/spec_change_set.rb, line 45 def lock_dependency_index @lock_dependency_index ||= Hash[lock_dependencies.map{|d| [d.name, d]}] end
# File lib/librarian/spec_change_set.rb, line 42 def lock_dependency_names @lock_dependency_names ||= Set.new(lock_dependencies.map{|d| d.name}) end
# File lib/librarian/spec_change_set.rb, line 49 def lock_manifests @lock_manifests ||= lock.manifests end
# File lib/librarian/spec_change_set.rb, line 52 def lock_manifests_index @lock_manifests_index ||= ManifestSet.new(lock_manifests).to_hash end
# File lib/librarian/spec_change_set.rb, line 79 def nonmatching_added_dependency_names @nonmatching_added_dependency_names ||= added_dependency_names.reject do |name| spec_dependency = spec_dependency_index[name] lock_manifest = lock_manifests_index[name] if lock_manifest matching = true matching &&= spec_dependency.satisfied_by?(lock_manifest) matching &&= spec_dependency.source == lock_manifest.source matching else false end end.to_set end
# File lib/librarian/spec_change_set.rb, line 56 def removed_dependency_names @removed_dependency_names ||= lock_dependency_names - spec_dependency_names end
# File lib/librarian/spec_change_set.rb, line 21 def same? @same ||= spec.dependencies.sort_by{|d| d.name} == lock.dependencies.sort_by{|d| d.name} end
# File lib/librarian/spec_change_set.rb, line 120 def shallow_strip_manifest_names @shallow_strip_manifest_names ||= begin explicit_removed_dependency_names + changed_dependency_names end end
# File lib/librarian/spec_change_set.rb, line 29 def spec_dependencies @spec_dependencies ||= spec.dependencies end
# File lib/librarian/spec_change_set.rb, line 35 def spec_dependency_index @spec_dependency_index ||= Hash[spec_dependencies.map{|d| [d.name, d]}] end
# File lib/librarian/spec_change_set.rb, line 32 def spec_dependency_names @spec_dependency_names ||= Set.new(spec_dependencies.map{|d| d.name}) end
# File lib/librarian/spec_change_set.rb, line 168 def debug(*args, &block) environment.logger.debug(*args, &block) end