summaryrefslogtreecommitdiff
path: root/lib/bundler/installer.rb
blob: b3d62c226543a3bd35c59d4bc5e9d29fe7492a43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require 'rubygems/dependency_installer'

module Bundler
  class Installer < Environment
    def self.install(root, definition, options)
      new(root, definition).run(options)
    end

    def run(options)
      if actual_dependencies.empty?
        Bundler.ui.warn "The Gemfile specifies no dependencies"
        return
      end

      # Ensure that BUNDLE_PATH exists
      FileUtils.mkdir_p(Bundler.bundle_path)

      # Must install gems in the order that the resolver provides
      # as dependencies might actually affect the installation of
      # the gem.
      specs.each do |spec|
        spec.source.fetch(spec) if spec.source.respond_to?(:fetch)

        unless requested_specs.include?(spec)
          Bundler.ui.debug "  * Not in requested group; skipping."
          next
        end

        Bundler.ui.info "Installing #{spec.name} (#{spec.version}) from #{spec.source} "

        spec.source.install(spec)

        Bundler.ui.info ""
      end

      if locked?
        write_rb_lock
      end

      Bundler.ui.confirm "Your bundle is complete!"
    end

    def dependencies
      @definition.dependencies
    end

    def actual_dependencies
      @definition.actual_dependencies
    end

  private

    def sources
      @definition.sources
    end

    def resolve_locally
      # Return unless all the dependencies have = version requirements
      return if actual_dependencies.any? { |d| ambiguous?(d) }

      specs = super

      # Simple logic for now. Can improve later.
      specs.length == actual_dependencies.length && specs
    rescue GemNotFound, PathError => e
      nil
    end

    def resolve_remotely
      resolve(:specs, remote_index)
    end

    def ambiguous?(dep)
      dep.requirement.requirements.any? { |op,_| op != '=' }
    end

    def remote_index
      @remote_index ||= Index.build do |idx|
        rubygems, other = sources.partition { |s| Source::Rubygems === s }

        other.each do |source|
          Bundler.ui.debug "Source: Processing index"
          idx.use source.specs
        end

        idx.use Index.installed_gems
        idx.use Index.cached_gems

        rubygems.each do |source|
          Bundler.ui.debug "Source: Processing index"
          idx.use source.specs
        end
      end
    end
  end
end