lib/bundler/definition.rb in bundler-1.6.9 vs lib/bundler/definition.rb in bundler-1.7.0

- old
+ new

@@ -3,12 +3,11 @@ module Bundler class Definition include GemHelpers - attr_reader :dependencies, :platforms, :sources, :ruby_version, - :locked_deps + attr_reader :dependencies, :platforms, :ruby_version, :locked_deps # Given a gemfile and lockfile creates a Bundler definition # # @param gemfile [Pathname] Path to Gemfile # @param lockfile [Pathname,nil] Path to Gemfile.lock @@ -38,11 +37,11 @@ # * If all fresh dependencies are satisfied by the locked # specs, then we can try to resolve locally. # # @param lockfile [Pathname] Path to Gemfile.lock # @param dependencies [Array(Bundler::Dependency)] array of dependencies from Gemfile - # @param sources [Array(Bundler::Source::Rubygems)] + # @param sources [Bundler::SourceList] # @param unlock [Hash, Boolean, nil] Gems that have been requested # to be updated or true if all gems should be updated # @param ruby_version [Bundler::RubyVersion, nil] Requested Ruby Version def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil) @unlocking = unlock == true || !unlock.empty? @@ -109,18 +108,18 @@ end end def resolve_with_cache! raise "Specs already loaded" if @specs - @sources.each { |s| s.cached! } + sources.cached! specs end def resolve_remotely! raise "Specs already loaded" if @specs @remote = true - @sources.each { |s| s.remote! } + sources.remote! specs end # For given dependency list returns a SpecSet with Gemspec of all the required # dependencies. @@ -208,11 +207,11 @@ def index @index ||= Index.build do |idx| dependency_names = @dependencies.dup || [] dependency_names.map! {|d| d.name } - @sources.each do |s| + sources.all_sources.each do |s| if s.is_a?(Bundler::Source::Rubygems) s.dependency_names = dependency_names.uniq idx.add_source s.specs else source_index = s.specs @@ -225,19 +224,28 @@ # used when frozen is enabled so we can find the bundler # spec, even if (say) a git gem is not checked out. def rubygems_index @rubygems_index ||= Index.build do |idx| - rubygems = @sources.find{|s| s.is_a?(Source::Rubygems) } - idx.add_source rubygems.specs + sources.rubygems_sources.each do |rubygems| + idx.add_source rubygems.specs + end end end - def rubygems_remotes - @sources.select{|s| s.is_a?(Source::Rubygems) }.map{|s| s.remotes }.flatten + def has_rubygems_remotes? + sources.rubygems_sources.any? {|s| s.remotes.any? } end + def has_local_dependencies? + !sources.path_sources.empty? || !sources.git_sources.empty? + end + + def spec_git_paths + sources.git_sources.map {|s| s.path.to_s } + end + def groups dependencies.map { |d| d.groups }.flatten.uniq end def lock(file) @@ -263,16 +271,16 @@ end def to_lock out = "" - sorted_sources.each do |source| + sources.lock_sources.each do |source| # Add the source header out << source.to_lock # Find all specs for this source resolve. - select { |s| s.source == source }. + select { |s| source.can_lock?(s) }. # This needs to be sorted by full name so that # gems with the same name, but different platform # are ordered consistently sort_by { |s| s.full_name }. each do |spec| @@ -317,13 +325,14 @@ added = [] deleted = [] changed = [] - if @locked_sources != @sources - new_sources = @sources - @locked_sources - deleted_sources = @locked_sources - @sources + gemfile_sources = sources.all_sources + if @locked_sources != gemfile_sources + new_sources = gemfile_sources - @locked_sources + deleted_sources = @locked_sources - gemfile_sources if new_sources.any? added.concat new_sources.map { |source| "* source: #{source}" } end @@ -391,10 +400,12 @@ end end private + attr_reader :sources + def nothing_changed? !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes end def pretty_dep(dep, source = false) @@ -439,42 +450,31 @@ changed || specs_changed?(source) { |o| source.class == o.class && source.uri == o.uri } end end def converge_paths - @sources.any? do |source| - next unless source.instance_of?(Source::Path) + sources.path_sources.any? do |source| specs_changed?(source) do |ls| ls.class == source.class && ls.path == source.path end end end def converge_sources changes = false # Get the Rubygems source from the Gemfile.lock - locked_gem = @locked_sources.find { |s| s.kind_of?(Source::Rubygems) } + locked_gem = @locked_sources.select { |s| s.kind_of?(Source::Rubygems) } - # Get the Rubygems source from the Gemfile - actual_gem = @sources.find { |s| s.kind_of?(Source::Rubygems) } - - # If there is a Rubygems source in both - if locked_gem && actual_gem - # Merge the remotes from the Gemfile into the Gemfile.lock - changes = changes | locked_gem.replace_remotes(actual_gem) - end - # Replace the sources from the Gemfile with the sources from the Gemfile.lock, # if they exist in the Gemfile.lock and are `==`. If you can't find an equivalent # source in the Gemfile.lock, use the one from the Gemfile. - @sources.map! do |source| - @locked_sources.find { |s| s == source } || source - end - changes = changes | (Set.new(@sources) != Set.new(@locked_sources)) + sources.replace_sources!(@locked_sources) + gemfile_sources = sources.all_sources + changes = changes | (Set.new(gemfile_sources) != Set.new(@locked_sources)) - @sources.each do |source| + gemfile_sources.each do |source| # If the source is unlockable and the current command allows an unlock of # the source (for example, you are doing a `bundle update <foo>` of a git-pinned # gem), unlock it. For git sources, this means to unlock the revision, which # will cause the `ref` used to be the most recent for the branch (or master) if # an explicit `ref` is not used. @@ -488,11 +488,11 @@ end def converge_dependencies (@dependencies + @locked_deps).each do |dep| if dep.source - dep.source = @sources.find { |s| dep.source == s } + dep.source = sources.get(dep.source) end end Set.new(@dependencies) != Set.new(@locked_deps) end @@ -522,11 +522,11 @@ end end converged = [] @locked_specs.each do |s| - s.source = @sources.find { |src| s.source == src } + s.source = sources.get(s.source) # Don't add a spec to the list if its source is expired. For example, # if you change a Git gem to Rubygems. next if s.source.nil? || @unlock[:sources].include?(s.name) # If the spec is from a path source and it doesn't exist anymore @@ -551,11 +551,11 @@ resolve = SpecSet.new(converged) resolve = resolve.for(expand_dependencies(deps, true), @unlock[:gems]) diff = @locked_specs.to_a - resolve.to_a # Now, we unlock any sources that do not have anymore gems pinned to it - @sources.each do |source| + sources.all_sources.each do |source| next unless source.respond_to?(:unlock!) unless resolve.any? { |s| s.source == source } source.unlock! if !diff.empty? && diff.any? { |s| s.source == source } end @@ -584,16 +584,9 @@ dep.gem_platforms(@platforms).each do |p| deps << DepProxy.new(dep, p) if remote || p == generic(Gem::Platform.local) end end deps - end - - def sorted_sources - @sources.sort_by do |s| - # Place GEM at the top - [ s.is_a?(Source::Rubygems) ? 1 : 0, s.to_s ] - end end def requested_dependencies groups = self.groups - Bundler.settings.without groups.map! { |g| g.to_sym }