bundler 1.10.6 → 1.11.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +105 -0
  3. data/.rubocop_todo.yml +120 -0
  4. data/.travis.yml +8 -23
  5. data/CHANGELOG.md +69 -0
  6. data/CODE_OF_CONDUCT.md +6 -4
  7. data/DEVELOPMENT.md +4 -5
  8. data/README.md +2 -2
  9. data/Rakefile +70 -87
  10. data/bin/rake +14 -0
  11. data/bin/rspec +10 -0
  12. data/bin/rubocop +11 -0
  13. data/bundler.gemspec +17 -15
  14. data/exe/bundle +20 -0
  15. data/{bin → exe}/bundle_ruby +6 -4
  16. data/exe/bundler +20 -0
  17. data/lib/bundler.rb +98 -119
  18. data/lib/bundler/capistrano.rb +2 -2
  19. data/lib/bundler/cli.rb +85 -74
  20. data/lib/bundler/cli/binstubs.rb +1 -2
  21. data/lib/bundler/cli/cache.rb +0 -1
  22. data/lib/bundler/cli/check.rb +7 -5
  23. data/lib/bundler/cli/clean.rb +0 -1
  24. data/lib/bundler/cli/common.rb +6 -7
  25. data/lib/bundler/cli/config.rb +69 -56
  26. data/lib/bundler/cli/console.rb +8 -8
  27. data/lib/bundler/cli/exec.rb +4 -3
  28. data/lib/bundler/cli/gem.rb +50 -39
  29. data/lib/bundler/cli/init.rb +5 -6
  30. data/lib/bundler/cli/inject.rb +1 -2
  31. data/lib/bundler/cli/install.rb +18 -21
  32. data/lib/bundler/cli/lock.rb +8 -3
  33. data/lib/bundler/cli/open.rb +4 -5
  34. data/lib/bundler/cli/outdated.rb +7 -8
  35. data/lib/bundler/cli/package.rb +1 -1
  36. data/lib/bundler/cli/platform.rb +2 -3
  37. data/lib/bundler/cli/show.rb +9 -9
  38. data/lib/bundler/cli/update.rb +2 -3
  39. data/lib/bundler/cli/viz.rb +1 -2
  40. data/lib/bundler/constants.rb +1 -1
  41. data/lib/bundler/current_ruby.rb +38 -3
  42. data/lib/bundler/definition.rb +83 -88
  43. data/lib/bundler/dep_proxy.rb +11 -9
  44. data/lib/bundler/dependency.rb +26 -11
  45. data/lib/bundler/deployment.rb +2 -2
  46. data/lib/bundler/deprecate.rb +3 -3
  47. data/lib/bundler/dsl.rb +63 -44
  48. data/lib/bundler/env.rb +19 -12
  49. data/lib/bundler/environment.rb +1 -2
  50. data/lib/bundler/errors.rb +82 -0
  51. data/lib/bundler/fetcher.rb +45 -39
  52. data/lib/bundler/fetcher/base.rb +20 -7
  53. data/lib/bundler/fetcher/dependency.rb +5 -5
  54. data/lib/bundler/fetcher/downloader.rb +1 -2
  55. data/lib/bundler/fetcher/index.rb +4 -7
  56. data/lib/bundler/friendly_errors.rb +15 -8
  57. data/lib/bundler/gem_helper.rb +44 -35
  58. data/lib/bundler/gem_helpers.rb +7 -8
  59. data/lib/bundler/gem_remote_fetcher.rb +41 -0
  60. data/lib/bundler/gem_tasks.rb +4 -1
  61. data/lib/bundler/graph.rb +25 -24
  62. data/lib/bundler/index.rb +21 -18
  63. data/lib/bundler/injector.rb +2 -4
  64. data/lib/bundler/inline.rb +3 -3
  65. data/lib/bundler/installer.rb +57 -144
  66. data/lib/bundler/installer/gem_installer.rb +76 -0
  67. data/lib/bundler/installer/parallel_installer.rb +22 -13
  68. data/lib/bundler/installer/standalone.rb +48 -0
  69. data/lib/bundler/lazy_specification.rb +3 -4
  70. data/lib/bundler/lockfile_parser.rb +21 -19
  71. data/lib/bundler/match_platform.rb +4 -4
  72. data/lib/bundler/psyched_yaml.rb +3 -3
  73. data/lib/bundler/remote_specification.rb +1 -1
  74. data/lib/bundler/resolver.rb +93 -88
  75. data/lib/bundler/retry.rb +9 -10
  76. data/lib/bundler/ruby_dsl.rb +1 -1
  77. data/lib/bundler/ruby_version.rb +7 -10
  78. data/lib/bundler/rubygems_ext.rb +32 -27
  79. data/lib/bundler/{gem_installer.rb → rubygems_gem_installer.rb} +2 -2
  80. data/lib/bundler/rubygems_integration.rb +85 -70
  81. data/lib/bundler/runtime.rb +57 -61
  82. data/lib/bundler/settings.rb +27 -26
  83. data/lib/bundler/setup.rb +3 -3
  84. data/lib/bundler/shared_helpers.rb +45 -20
  85. data/lib/bundler/similarity_detector.rb +19 -21
  86. data/lib/bundler/source.rb +4 -5
  87. data/lib/bundler/source/git.rb +29 -31
  88. data/lib/bundler/source/git/git_proxy.rb +52 -26
  89. data/lib/bundler/source/path.rb +25 -28
  90. data/lib/bundler/source/path/installer.rb +4 -4
  91. data/lib/bundler/source/rubygems.rb +62 -48
  92. data/lib/bundler/source/rubygems/remote.rb +3 -3
  93. data/lib/bundler/source_list.rb +4 -4
  94. data/lib/bundler/spec_set.rb +17 -15
  95. data/lib/bundler/ssl_certs/certificate_manager.rb +5 -6
  96. data/lib/bundler/stub_specification.rb +2 -2
  97. data/lib/bundler/templates/Executable +5 -5
  98. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +42 -6
  99. data/lib/bundler/templates/newgem/README.md.tt +1 -1
  100. data/lib/bundler/templates/newgem/Rakefile.tt +4 -2
  101. data/lib/bundler/templates/newgem/bin/setup.tt +2 -1
  102. data/lib/bundler/templates/newgem/newgem.gemspec.tt +2 -2
  103. data/lib/bundler/ui.rb +3 -3
  104. data/lib/bundler/ui/rg_proxy.rb +2 -2
  105. data/lib/bundler/ui/shell.rb +10 -6
  106. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +82 -71
  107. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +1 -1
  108. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +9 -0
  109. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +40 -21
  110. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +8 -0
  111. data/lib/bundler/vendored_molinillo.rb +1 -1
  112. data/lib/bundler/vendored_persistent.rb +3 -3
  113. data/lib/bundler/vendored_thor.rb +2 -2
  114. data/lib/bundler/version.rb +1 -1
  115. data/lib/bundler/vlad.rb +1 -1
  116. data/lib/bundler/worker.rb +4 -5
  117. data/man/bundle-config.ronn +4 -2
  118. data/man/bundle-gem.ronn +77 -0
  119. data/man/bundle-install.ronn +13 -6
  120. data/man/bundle-lock.ronn +47 -0
  121. data/man/bundle.ronn +1 -1
  122. data/man/gemfile.5.ronn +8 -0
  123. data/man/index.txt +1 -0
  124. metadata +37 -8
  125. data/bin/bundle +0 -21
  126. data/bin/bundler +0 -21
@@ -15,35 +15,34 @@ module Bundler
15
15
  end
16
16
 
17
17
  def initialize(name, exceptions = nil, retries = self.class.default_retries)
18
- @name = name
19
- @retries = retries
18
+ @name = name
19
+ @retries = retries
20
20
  @exceptions = Array(exceptions) || []
21
- @total_runs = @retries + 1 # will run once, then upto attempts.times
21
+ @total_runs = @retries + 1 # will run once, then upto attempts.times
22
22
  end
23
23
 
24
24
  def attempt(&block)
25
25
  @current_run = 0
26
26
  @failed = false
27
27
  @error = nil
28
- while keep_trying? do
29
- run(&block)
30
- end
28
+ run(&block) while keep_trying?
31
29
  @result
32
30
  end
33
- alias :attempts :attempt
31
+ alias_method :attempts, :attempt
34
32
 
35
33
  private
34
+
36
35
  def run(&block)
37
36
  @failed = false
38
37
  @current_run += 1
39
38
  @result = block.call
40
39
  rescue => e
41
- fail(e)
40
+ fail_attempt(e)
42
41
  end
43
42
 
44
- def fail(e)
43
+ def fail_attempt(e)
45
44
  @failed = true
46
- raise e if last_attempt? || @exceptions.any?{ |k| e.is_a?(k) }
45
+ raise e if last_attempt? || @exceptions.any? {|k| e.is_a?(k) }
47
46
  return true unless name
48
47
  Bundler.ui.warn "Retrying#{" #{name}" if name} due to error (#{current_run.next}/#{total_runs}): #{e.class} #{e.message}"
49
48
  end
@@ -4,7 +4,7 @@ module Bundler
4
4
  raise GemfileError, "Please define :engine_version" if options[:engine] && options[:engine_version].nil?
5
5
  raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil?
6
6
 
7
- raise GemfileError, "ruby_version must match the :engine_version for MRI" if options[:engine] == "ruby" && options[:engine_version] && ruby_version != options[:engine_version]
7
+ raise GemfileEvalError, "ruby_version must match the :engine_version for MRI" if options[:engine] == "ruby" && options[:engine_version] && ruby_version != options[:engine_version]
8
8
  @ruby_version = RubyVersion.new(ruby_version, options[:patchlevel], options[:engine], options[:engine_version])
9
9
  end
10
10
  end
@@ -32,10 +32,10 @@ module Bundler
32
32
  end
33
33
 
34
34
  def ==(other)
35
- version == other.version &&
36
- engine == other.engine &&
35
+ version == other.version &&
36
+ engine == other.engine &&
37
37
  engine_version == other.engine_version &&
38
- patchlevel == other.patchlevel
38
+ patchlevel == other.patchlevel
39
39
  end
40
40
 
41
41
  # Returns a tuple of these things:
@@ -46,15 +46,13 @@ module Bundler
46
46
  # 3. engine_version
47
47
  def diff(other)
48
48
  if engine != other.engine && @input_engine
49
- [ :engine, engine, other.engine ]
49
+ [:engine, engine, other.engine]
50
50
  elsif version != other.version
51
- [ :version, version, other.version ]
51
+ [:version, version, other.version]
52
52
  elsif engine_version != other.engine_version && @input_engine
53
- [ :engine_version, engine_version, other.engine_version ]
53
+ [:engine_version, engine_version, other.engine_version]
54
54
  elsif patchlevel != other.patchlevel && @patchlevel
55
- [ :patchlevel, patchlevel, other.patchlevel ]
56
- else
57
- nil
55
+ [:patchlevel, patchlevel, other.patchlevel]
58
56
  end
59
57
  end
60
58
 
@@ -106,7 +104,6 @@ module Bundler
106
104
  JRUBY_VERSION.dup
107
105
  else
108
106
  raise BundlerError, "RUBY_ENGINE value #{RUBY_ENGINE} is not recognized"
109
- nil
110
107
  end
111
108
  end
112
109
 
@@ -1,16 +1,16 @@
1
- require 'pathname'
1
+ require "pathname"
2
2
 
3
3
  if defined?(Gem::QuickLoader)
4
4
  # Gem Prelude makes me a sad panda :'(
5
5
  Gem::QuickLoader.load_full_rubygems_library
6
6
  end
7
7
 
8
- require 'rubygems'
9
- require 'rubygems/specification'
10
- require 'bundler/match_platform'
8
+ require "rubygems"
9
+ require "rubygems/specification"
10
+ require "bundler/match_platform"
11
11
 
12
12
  module Gem
13
- @loaded_stacks = Hash.new { |h,k| h[k] = [] }
13
+ @loaded_stacks = Hash.new {|h, k| h[k] = [] }
14
14
 
15
15
  class Specification
16
16
  attr_accessor :remote, :location, :relative_loaded_from
@@ -22,15 +22,19 @@ module Gem
22
22
  alias_method :rg_loaded_from, :loaded_from
23
23
 
24
24
  def full_gem_path
25
- source.respond_to?(:path) ?
26
- Pathname.new(loaded_from).dirname.expand_path(Bundler.root).to_s.untaint :
25
+ if source.respond_to?(:path)
26
+ Pathname.new(loaded_from).dirname.expand_path(Bundler.root).to_s.untaint
27
+ else
27
28
  rg_full_gem_path
29
+ end
28
30
  end
29
31
 
30
32
  def loaded_from
31
- relative_loaded_from ?
32
- source.path.join(relative_loaded_from).to_s :
33
+ if relative_loaded_from
34
+ source.path.join(relative_loaded_from).to_s
35
+ else
33
36
  rg_loaded_from
37
+ end
34
38
  end
35
39
 
36
40
  def load_paths
@@ -48,9 +52,11 @@ module Gem
48
52
  if method_defined?(:extension_dir)
49
53
  alias_method :rg_extension_dir, :extension_dir
50
54
  def extension_dir
51
- @extension_dir ||= source.respond_to?(:extension_dir_name) ?
52
- File.expand_path(File.join(extensions_dir, source.extension_dir_name)) :
55
+ @extension_dir ||= if source.respond_to?(:extension_dir_name)
56
+ File.expand_path(File.join(extensions_dir, source.extension_dir_name))
57
+ else
53
58
  rg_extension_dir
59
+ end
54
60
  end
55
61
  end
56
62
 
@@ -88,43 +94,42 @@ module Gem
88
94
  private
89
95
 
90
96
  def dependencies_to_gemfile(dependencies, group = nil)
91
- gemfile = ''
97
+ gemfile = ""
92
98
  if dependencies.any?
93
99
  gemfile << "group :#{group} do\n" if group
94
100
  dependencies.each do |dependency|
95
- gemfile << ' ' if group
96
- gemfile << %|gem "#{dependency.name}"|
101
+ gemfile << " " if group
102
+ gemfile << %(gem "#{dependency.name}")
97
103
  req = dependency.requirements_list.first
98
- gemfile << %|, "#{req}"| if req
104
+ gemfile << %(, "#{req}") if req
99
105
  gemfile << "\n"
100
106
  end
101
107
  gemfile << "end\n" if group
102
108
  end
103
109
  gemfile
104
110
  end
105
-
106
111
  end
107
112
 
108
113
  class Dependency
109
114
  attr_accessor :source, :groups
110
115
 
111
- alias eql? ==
116
+ alias_method :eql?, :==
112
117
 
113
118
  def encode_with(coder)
114
119
  to_yaml_properties.each do |ivar|
115
- coder[ivar.to_s.sub(/^@/, '')] = instance_variable_get(ivar)
120
+ coder[ivar.to_s.sub(/^@/, "")] = instance_variable_get(ivar)
116
121
  end
117
122
  end
118
123
 
119
124
  def to_yaml_properties
120
- instance_variables.reject { |p| ["@source", "@groups"].include?(p.to_s) }
125
+ instance_variables.reject {|p| ["@source", "@groups"].include?(p.to_s) }
121
126
  end
122
127
 
123
128
  def to_lock
124
129
  out = " #{name}"
125
130
  unless requirement == Gem::Requirement.default
126
- reqs = requirement.requirements.map{|o,v| "#{o} #{v}" }.sort.reverse
127
- out << " (#{reqs.join(', ')})"
131
+ reqs = requirement.requirements.map {|o, v| "#{o} #{v}" }.sort.reverse
132
+ out << " (#{reqs.join(", ")})"
128
133
  end
129
134
  out
130
135
  end
@@ -147,11 +152,11 @@ module Gem
147
152
  end
148
153
 
149
154
  class Platform
150
- JAVA = Gem::Platform.new('java') unless defined?(JAVA)
151
- MSWIN = Gem::Platform.new('mswin32') unless defined?(MSWIN)
152
- MSWIN64 = Gem::Platform.new('mswin64') unless defined?(MSWIN64)
153
- MINGW = Gem::Platform.new('x86-mingw32') unless defined?(MINGW)
154
- X64_MINGW = Gem::Platform.new('x64-mingw32') unless defined?(X64_MINGW)
155
+ JAVA = Gem::Platform.new("java") unless defined?(JAVA)
156
+ MSWIN = Gem::Platform.new("mswin32") unless defined?(MSWIN)
157
+ MSWIN64 = Gem::Platform.new("mswin64") unless defined?(MSWIN64)
158
+ MINGW = Gem::Platform.new("x86-mingw32") unless defined?(MINGW)
159
+ X64_MINGW = Gem::Platform.new("x64-mingw32") unless defined?(X64_MINGW)
155
160
 
156
161
  undef_method :hash if method_defined? :hash
157
162
  def hash
@@ -159,7 +164,7 @@ module Gem
159
164
  end
160
165
 
161
166
  undef_method :eql? if method_defined? :eql?
162
- alias eql? ==
167
+ alias_method :eql?, :==
163
168
  end
164
169
  end
165
170
 
@@ -1,7 +1,7 @@
1
- require 'rubygems/installer'
1
+ require "rubygems/installer"
2
2
 
3
3
  module Bundler
4
- class GemInstaller < Gem::Installer
4
+ class RubyGemsGemInstaller < Gem::Installer
5
5
  def check_executable_overwrite(filename)
6
6
  # Bundler needs to install gems regardless of binstub overwriting
7
7
  end
@@ -1,6 +1,7 @@
1
- require 'monitor'
2
- require 'rubygems'
3
- require 'rubygems/config_file'
1
+ require "monitor"
2
+ require "rubygems"
3
+ require "rubygems/config_file"
4
+ require "bundler/psyched_yaml"
4
5
 
5
6
  module Bundler
6
7
  class RubygemsIntegration
@@ -66,7 +67,10 @@ module Bundler
66
67
  rescue Gem::SystemExitException => e
67
68
  Bundler.ui.error "#{e.class}: #{e.message}"
68
69
  Bundler.ui.trace e
69
- raise Gem::SystemExitException
70
+ raise
71
+ rescue YamlSyntaxError => e
72
+ raise YAMLSyntaxError.new(e, "Your RubyGems configuration, which is " \
73
+ "usually located in ~/.gemrc, contains invalid YAML syntax.")
70
74
  end
71
75
 
72
76
  def ruby_engine
@@ -111,14 +115,14 @@ module Bundler
111
115
  end
112
116
 
113
117
  def gem_cache
114
- gem_path.map{|p| File.expand_path("cache", p) }
118
+ gem_path.map {|p| File.expand_path("cache", p) }
115
119
  end
116
120
 
117
121
  def spec_cache_dirs
118
122
  @spec_cache_dirs ||= begin
119
- dirs = gem_path.map {|dir| File.join(dir, 'specifications')}
123
+ dirs = gem_path.map {|dir| File.join(dir, "specifications") }
120
124
  dirs << Gem.spec_cache_dir if Gem.respond_to?(:spec_cache_dir) # Not in Rubygems 2.0.3 or earlier
121
- dirs.uniq.select {|dir| File.directory? dir}
125
+ dirs.uniq.select {|dir| File.directory? dir }
122
126
  end
123
127
  end
124
128
 
@@ -131,7 +135,7 @@ module Bundler
131
135
  end
132
136
 
133
137
  def repository_subdirectories
134
- %w[cache doc gems specifications]
138
+ %w(cache doc gems specifications)
135
139
  end
136
140
 
137
141
  def clear_paths
@@ -151,11 +155,11 @@ module Bundler
151
155
  # RubyGems 2.2+ can put binary extension into dedicated folders,
152
156
  # therefore use RubyGems facilities to obtain their load paths.
153
157
  if Gem::Specification.method_defined? :full_require_paths
154
- loaded_gem_paths = Gem.loaded_specs.map {|n, s| s.full_require_paths}
158
+ loaded_gem_paths = Gem.loaded_specs.map {|_, s| s.full_require_paths }
155
159
  loaded_gem_paths.flatten
156
160
  else
157
161
  $LOAD_PATH.select do |p|
158
- Bundler.rubygems.gem_path.any?{|gp| p =~ /^#{Regexp.escape(gp)}/ }
162
+ Bundler.rubygems.gem_path.any? {|gp| p =~ /^#{Regexp.escape(gp)}/ }
159
163
  end
160
164
  end
161
165
  end
@@ -180,18 +184,26 @@ module Bundler
180
184
  [] # if we can't download them, there aren't any
181
185
  end
182
186
 
183
- def fetch_all_remote_specs
187
+ # TODO: This is for older versions of Rubygems... should we support the
188
+ # X-Gemfile-Source header on these old versions?
189
+ # Maybe the newer implementation will work on older Rubygems?
190
+ # It seems difficult to keep this implementation and still send the header.
191
+ def fetch_all_remote_specs(remote)
192
+ old_sources = Bundler.rubygems.sources
193
+ Bundler.rubygems.sources = [remote.uri.to_s]
184
194
  # Fetch all specs, minus prerelease specs
185
195
  spec_list = fetch_specs(true, false)
186
196
  # Then fetch the prerelease specs
187
197
  fetch_prerelease_specs.each {|k, v| spec_list[k] += v }
188
198
 
189
- return spec_list
199
+ spec_list
200
+ ensure
201
+ Bundler.rubygems.sources = old_sources
190
202
  end
191
203
 
192
204
  def with_build_args(args)
193
205
  ext_lock.synchronize do
194
- old_args = self.build_args
206
+ old_args = build_args
195
207
  begin
196
208
  self.build_args = args
197
209
  yield
@@ -202,12 +214,12 @@ module Bundler
202
214
  end
203
215
 
204
216
  def gem_from_path(path, policy = nil)
205
- require 'rubygems/format'
217
+ require "rubygems/format"
206
218
  Gem::Format.from_file_by_path(path, policy)
207
219
  end
208
220
 
209
221
  def spec_from_gem(path, policy = nil)
210
- require 'rubygems/security'
222
+ require "rubygems/security"
211
223
  gem_from_path(path, security_policies[policy]).spec
212
224
  rescue Gem::Package::FormatError
213
225
  raise GemspecError, "Could not read gem at #{path}. It may be corrupted."
@@ -216,7 +228,7 @@ module Bundler
216
228
  e.message =~ /unknown trust policy|unsigned gem/i ||
217
229
  e.message =~ /couldn't verify (meta)?data signature/i
218
230
  raise SecurityError,
219
- "The gem #{File.basename(path, '.gem')} can't be installed because " \
231
+ "The gem #{File.basename(path, ".gem")} can't be installed because " \
220
232
  "the security policy didn't allow it, with the message: #{e.message}"
221
233
  else
222
234
  raise e
@@ -224,12 +236,12 @@ module Bundler
224
236
  end
225
237
 
226
238
  def build(spec, skip_validation = false)
227
- require 'rubygems/builder'
239
+ require "rubygems/builder"
228
240
  Gem::Builder.new(spec).build
229
241
  end
230
242
 
231
243
  def build_gem(gem_dir, spec)
232
- build(spec)
244
+ build(spec)
233
245
  end
234
246
 
235
247
  def download_gem(spec, uri, path)
@@ -239,12 +251,12 @@ module Bundler
239
251
  end
240
252
 
241
253
  def security_policy_keys
242
- %w{High Medium Low AlmostNo No}.map { |level| "#{level}Security" }
254
+ %w(High Medium Low AlmostNo No).map {|level| "#{level}Security" }
243
255
  end
244
256
 
245
257
  def security_policies
246
258
  @security_policies ||= begin
247
- require 'rubygems/security'
259
+ require "rubygems/security"
248
260
  Gem::Security::Policies
249
261
  rescue LoadError, NameError
250
262
  {}
@@ -255,8 +267,8 @@ module Bundler
255
267
  # Disable rubygems' gem activation system
256
268
  ::Kernel.class_eval do
257
269
  if private_method_defined?(:gem_original_require)
258
- alias rubygems_require require
259
- alias require gem_original_require
270
+ alias_method :rubygems_require, :require
271
+ alias_method :require, :gem_original_require
260
272
  end
261
273
 
262
274
  undef gem
@@ -266,11 +278,11 @@ module Bundler
266
278
  def replace_gem(specs)
267
279
  reverse_rubygems_kernel_mixin
268
280
 
269
- executables = specs.map { |s| s.executables }.flatten
281
+ executables = specs.map(&:executables).flatten
270
282
 
271
283
  ::Kernel.send(:define_method, :gem) do |dep, *reqs|
272
- if executables.include? File.basename(caller.first.split(':').first)
273
- return
284
+ if executables.include? File.basename(caller.first.split(":").first)
285
+ break
274
286
  end
275
287
  reqs.pop if reqs.last.is_a?(Hash)
276
288
 
@@ -278,7 +290,7 @@ module Bundler
278
290
  dep = Gem::Dependency.new(dep, reqs)
279
291
  end
280
292
 
281
- spec = specs.find { |s| s.name == dep.name }
293
+ spec = specs.find {|s| s.name == dep.name }
282
294
 
283
295
  if spec.nil?
284
296
 
@@ -330,27 +342,25 @@ module Bundler
330
342
  # under bundler. The new Gem.bin_path only considers gems in
331
343
  # +specs+
332
344
  def replace_bin_path(specs)
333
- gem_class = (class << Gem ; self ; end)
345
+ gem_class = (class << Gem; self; end)
334
346
  redefine_method(gem_class, :bin_path) do |name, *args|
335
347
  exec_name = args.first
336
348
 
337
- if exec_name == 'bundle'
338
- return ENV['BUNDLE_BIN_PATH']
339
- end
349
+ return ENV["BUNDLE_BIN_PATH"] if exec_name == "bundle"
340
350
 
341
351
  spec = nil
342
352
 
343
353
  if exec_name
344
- spec = specs.find { |s| s.executables.include?(exec_name) }
345
- spec or raise Gem::Exception, "can't find executable #{exec_name}"
354
+ spec = specs.find {|s| s.executables.include?(exec_name) }
355
+ raise(Gem::Exception, "can't find executable #{exec_name}") unless spec
346
356
  unless spec.name == name
347
357
  warn "Bundler is using a binstub that was created for a different gem.\n" \
348
358
  "This is deprecated, in future versions you may need to `bundle binstub #{name}` " \
349
359
  "to work around a system/bundle conflict."
350
360
  end
351
361
  else
352
- spec = specs.find { |s| s.name == name }
353
- exec_name = spec.default_executable or raise Gem::Exception, "no default executable for #{spec.full_name}"
362
+ spec = specs.find {|s| s.name == name }
363
+ raise Gem::Exception, "no default executable for #{spec.full_name}" unless exec_name = spec.default_executable
354
364
  end
355
365
 
356
366
  gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name)
@@ -362,8 +372,8 @@ module Bundler
362
372
  # Because Bundler has a static view of what specs are available,
363
373
  # we don't #refresh, so stub it out.
364
374
  def replace_refresh
365
- gem_class = (class << Gem ; self ; end)
366
- redefine_method(gem_class, :refresh) { }
375
+ gem_class = (class << Gem; self; end)
376
+ redefine_method(gem_class, :refresh) {}
367
377
  end
368
378
 
369
379
  # Replace or hook into Rubygems to provide a bundlerized view
@@ -391,8 +401,8 @@ module Bundler
391
401
 
392
402
  # This backport fixes the marshaling of @segments.
393
403
  def backport_yaml_initialize
394
- redefine_method(Gem::Version, :yaml_initialize) do |tag, map|
395
- @version = map['version']
404
+ redefine_method(Gem::Version, :yaml_initialize) do |_, map|
405
+ @version = map["version"]
396
406
  @segments = nil
397
407
  @hash = nil
398
408
  end
@@ -446,7 +456,7 @@ module Bundler
446
456
 
447
457
  def stub_rubygems(specs)
448
458
  # Rubygems versions lower than 1.7 use SourceIndex#from_gems_in
449
- source_index_class = (class << Gem::SourceIndex ; self ; end)
459
+ source_index_class = (class << Gem::SourceIndex; self; end)
450
460
  source_index_class.send(:define_method, :from_gems_in) do |*args|
451
461
  source_index = Gem::SourceIndex.new
452
462
  source_index.spec_dirs = *args
@@ -499,9 +509,9 @@ module Bundler
499
509
  def stub_rubygems(specs)
500
510
  Gem::Specification.all = specs
501
511
 
502
- Gem.post_reset {
512
+ Gem.post_reset do
503
513
  Gem::Specification.all = specs
504
- }
514
+ end
505
515
 
506
516
  stub_source_index(specs)
507
517
  end
@@ -521,7 +531,8 @@ module Bundler
521
531
  # you call Gem::Installer#install with an :install_dir set. We have to
522
532
  # change it back for our sudo mode to work.
523
533
  def preserve_paths
524
- old_dir, old_path = gem_dir, gem_path
534
+ old_dir = gem_dir
535
+ old_path = gem_path
525
536
  yield
526
537
  Gem.use_paths(old_dir, old_path)
527
538
  end
@@ -532,7 +543,7 @@ module Bundler
532
543
  # Rubygems 1.8.20 and adds the skip_validation parameter, so that's
533
544
  # when we start passing it through.
534
545
  def build(spec, skip_validation = false)
535
- require 'rubygems/builder'
546
+ require "rubygems/builder"
536
547
  Gem::Builder.new(spec).build(skip_validation)
537
548
  end
538
549
  end
@@ -555,48 +566,55 @@ module Bundler
555
566
  Gem::Specification.find_all_by_name name
556
567
  end
557
568
 
558
- def fetch_specs(source, name)
569
+ def fetch_specs(source, remote, name)
559
570
  path = source + "#{name}.#{Gem.marshal_version}.gz"
560
- string = Gem::RemoteFetcher.fetcher.fetch_path(path)
571
+ fetcher = gem_remote_fetcher
572
+ fetcher.headers = { "X-Gemfile-Source" => remote.original_uri.to_s } if remote.original_uri
573
+ string = fetcher.fetch_path(path)
561
574
  Bundler.load_marshal(string)
562
575
  rescue Gem::RemoteFetcher::FetchError => e
563
576
  # it's okay for prerelease to fail
564
577
  raise e unless name == "prerelease_specs"
565
578
  end
566
579
 
567
- def fetch_all_remote_specs
580
+ def fetch_all_remote_specs(remote)
568
581
  # Since SpecFetcher now returns NameTuples, we just fetch directly
569
582
  # and unmarshal the array ourselves.
570
583
  hash = {}
571
584
 
572
- Gem.sources.each do |source|
573
- source = URI.parse(source.to_s) unless source.is_a?(URI)
574
- hash[source] = fetch_specs(source, "specs")
585
+ source = remote.uri
586
+ source = URI.parse(source.to_s) unless source.is_a?(URI)
587
+ hash[source] = fetch_specs(source, remote, "specs")
575
588
 
576
- pres = fetch_specs(source, "prerelease_specs")
577
- hash[source].push(*pres) if pres && !pres.empty?
578
- end
589
+ pres = fetch_specs(source, remote, "prerelease_specs")
590
+ hash[source].push(*pres) if pres && !pres.empty?
579
591
 
580
592
  hash
581
593
  end
582
594
 
583
595
  def download_gem(spec, uri, path)
584
- require 'resolv'
585
596
  uri = Bundler.settings.mirror_for(uri)
586
- proxy, dns = configuration[:http_proxy], Resolv::DNS.new
587
- fetcher = Gem::RemoteFetcher.new(proxy, dns)
597
+ fetcher = gem_remote_fetcher
598
+ fetcher.headers = { "X-Gemfile-Source" => spec.remote.original_uri.to_s } if spec.remote.original_uri
588
599
  fetcher.download(spec, uri, path)
589
600
  end
590
601
 
602
+ def gem_remote_fetcher
603
+ require "resolv"
604
+ proxy = configuration[:http_proxy]
605
+ dns = Resolv::DNS.new
606
+ Bundler::GemRemoteFetcher.new(proxy, dns)
607
+ end
608
+
591
609
  def gem_from_path(path, policy = nil)
592
- require 'rubygems/package'
610
+ require "rubygems/package"
593
611
  p = Gem::Package.new(path)
594
612
  p.security_policy = policy if policy
595
- return p
613
+ p
596
614
  end
597
615
 
598
616
  def build(spec, skip_validation = false)
599
- require 'rubygems/package'
617
+ require "rubygems/package"
600
618
  Gem::Package.build(spec, skip_validation)
601
619
  end
602
620
 
@@ -613,23 +631,21 @@ module Bundler
613
631
  end
614
632
 
615
633
  def all_specs
616
- require 'bundler/remote_specification'
634
+ require "bundler/remote_specification"
617
635
  Gem::Specification.stubs.map do |stub|
618
636
  StubSpecification.from_stub(stub)
619
637
  end
620
638
  end
621
639
 
622
640
  def backport_ext_builder_monitor
623
- require 'rubygems/ext'
641
+ require "rubygems/ext"
624
642
 
625
643
  Gem::Ext::Builder.class_eval do
626
- if !const_defined?(:CHDIR_MONITOR)
644
+ unless const_defined?(:CHDIR_MONITOR)
627
645
  const_set(:CHDIR_MONITOR, EXT_LOCK)
628
646
  end
629
647
 
630
- if const_defined?(:CHDIR_MUTEX)
631
- remove_const(:CHDIR_MUTEX)
632
- end
648
+ remove_const(:CHDIR_MUTEX) if const_defined?(:CHDIR_MUTEX)
633
649
  const_set(:CHDIR_MUTEX, const_get(:CHDIR_MONITOR))
634
650
  end
635
651
  end
@@ -646,22 +662,21 @@ module Bundler
646
662
  end
647
663
  end
648
664
  end
649
-
650
665
  end
651
666
 
652
667
  if RubygemsIntegration.provides?(">= 2.1.0")
653
668
  @rubygems = RubygemsIntegration::MoreFuture.new
654
669
  elsif RubygemsIntegration.provides?(">= 1.99.99")
655
670
  @rubygems = RubygemsIntegration::Future.new
656
- elsif RubygemsIntegration.provides?('>= 1.8.20')
671
+ elsif RubygemsIntegration.provides?(">= 1.8.20")
657
672
  @rubygems = RubygemsIntegration::MoreModern.new
658
- elsif RubygemsIntegration.provides?('>= 1.8.5')
673
+ elsif RubygemsIntegration.provides?(">= 1.8.5")
659
674
  @rubygems = RubygemsIntegration::Modern.new
660
- elsif RubygemsIntegration.provides?('>= 1.8.0')
675
+ elsif RubygemsIntegration.provides?(">= 1.8.0")
661
676
  @rubygems = RubygemsIntegration::AlmostModern.new
662
- elsif RubygemsIntegration.provides?('>= 1.7.0')
677
+ elsif RubygemsIntegration.provides?(">= 1.7.0")
663
678
  @rubygems = RubygemsIntegration::Transitional.new
664
- elsif RubygemsIntegration.provides?('>= 1.4.0')
679
+ elsif RubygemsIntegration.provides?(">= 1.4.0")
665
680
  @rubygems = RubygemsIntegration::Legacy.new
666
681
  else # Rubygems 1.3.6 and 1.3.7
667
682
  @rubygems = RubygemsIntegration::Ancient.new