bundler 1.0.22 → 1.1.pre

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 (114) hide show
  1. data/CHANGELOG.md +15 -181
  2. data/ISSUES.md +11 -26
  3. data/LICENSE +0 -2
  4. data/Rakefile +67 -116
  5. data/UPGRADING.md +4 -4
  6. data/bin/bundle +10 -10
  7. data/bundler.gemspec +5 -5
  8. data/lib/bundler.rb +15 -25
  9. data/lib/bundler/capistrano.rb +2 -2
  10. data/lib/bundler/cli.rb +41 -72
  11. data/lib/bundler/definition.rb +11 -37
  12. data/lib/bundler/dependency.rb +9 -13
  13. data/lib/bundler/deployment.rb +3 -8
  14. data/lib/bundler/dsl.rb +10 -24
  15. data/lib/bundler/fetcher.rb +101 -0
  16. data/lib/bundler/gem_helper.rb +6 -11
  17. data/lib/bundler/index.rb +8 -15
  18. data/lib/bundler/installer.rb +55 -35
  19. data/lib/bundler/lazy_specification.rb +7 -10
  20. data/lib/bundler/remote_specification.rb +6 -8
  21. data/lib/bundler/resolver.rb +18 -12
  22. data/lib/bundler/rubygems_ext.rb +3 -20
  23. data/lib/bundler/runtime.rb +57 -8
  24. data/lib/bundler/settings.rb +6 -4
  25. data/lib/bundler/setup.rb +5 -12
  26. data/lib/bundler/shared_helpers.rb +100 -4
  27. data/lib/bundler/source.rb +61 -106
  28. data/lib/bundler/spec_set.rb +8 -9
  29. data/lib/bundler/templates/newgem/Rakefile.tt +2 -1
  30. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +0 -2
  31. data/lib/bundler/templates/newgem/newgem.gemspec.tt +3 -6
  32. data/lib/bundler/ui.rb +1 -4
  33. data/lib/bundler/vendor/net/http/faster.rb +27 -0
  34. data/lib/bundler/vendor/net/http/persistent.rb +464 -0
  35. data/lib/bundler/vendor/thor.rb +4 -43
  36. data/lib/bundler/vendor/thor/actions.rb +11 -28
  37. data/lib/bundler/vendor/thor/actions/create_file.rb +2 -2
  38. data/lib/bundler/vendor/thor/actions/directory.rb +2 -2
  39. data/lib/bundler/vendor/thor/actions/empty_directory.rb +0 -0
  40. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +15 -56
  41. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +10 -15
  42. data/lib/bundler/vendor/thor/base.rb +4 -24
  43. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +0 -0
  44. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +0 -0
  45. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +0 -0
  46. data/lib/bundler/vendor/thor/error.rb +0 -0
  47. data/lib/bundler/vendor/thor/invocation.rb +0 -0
  48. data/lib/bundler/vendor/thor/parser.rb +0 -0
  49. data/lib/bundler/vendor/thor/parser/argument.rb +0 -0
  50. data/lib/bundler/vendor/thor/parser/arguments.rb +2 -2
  51. data/lib/bundler/vendor/thor/parser/option.rb +1 -1
  52. data/lib/bundler/vendor/thor/parser/options.rb +16 -17
  53. data/lib/bundler/vendor/thor/shell.rb +0 -0
  54. data/lib/bundler/vendor/thor/shell/basic.rb +13 -40
  55. data/lib/bundler/vendor/thor/shell/color.rb +0 -0
  56. data/lib/bundler/vendor/thor/task.rb +4 -3
  57. data/lib/bundler/vendor/thor/util.rb +2 -2
  58. data/lib/bundler/vendor/thor/version.rb +1 -1
  59. data/lib/bundler/version.rb +1 -1
  60. data/lib/bundler/vlad.rb +0 -2
  61. data/man/bundle-install.ronn +3 -6
  62. data/man/gemfile.5.ronn +2 -7
  63. data/spec/cache/gems_spec.rb +0 -11
  64. data/spec/cache/git_spec.rb +2 -5
  65. data/spec/install/deploy_spec.rb +8 -8
  66. data/spec/install/gems/dependency_api_spec.rb +85 -0
  67. data/spec/install/gems/flex_spec.rb +4 -4
  68. data/spec/install/gems/groups_spec.rb +3 -17
  69. data/spec/install/gems/platform_spec.rb +16 -0
  70. data/spec/install/gems/simple_case_spec.rb +24 -88
  71. data/spec/install/gems/standalone_spec.rb +162 -0
  72. data/spec/install/gems/sudo_spec.rb +2 -3
  73. data/spec/install/gemspec_spec.rb +0 -38
  74. data/spec/install/git_spec.rb +4 -3
  75. data/spec/install/invalid_spec.rb +0 -18
  76. data/spec/install/path_spec.rb +1 -53
  77. data/spec/lock/git_spec.rb +1 -1
  78. data/spec/lock/lockfile_spec.rb +16 -72
  79. data/spec/other/check_spec.rb +6 -6
  80. data/spec/other/clean_spec.rb +202 -0
  81. data/spec/other/exec_spec.rb +7 -14
  82. data/spec/other/ext_spec.rb +0 -21
  83. data/spec/{bundler → other}/gem_helper_spec.rb +1 -16
  84. data/spec/other/help_spec.rb +1 -2
  85. data/spec/other/init_spec.rb +3 -3
  86. data/spec/other/newgem_spec.rb +1 -23
  87. data/spec/pack/gems_spec.rb +22 -0
  88. data/spec/quality_spec.rb +2 -6
  89. data/spec/runtime/require_spec.rb +10 -10
  90. data/spec/runtime/setup_spec.rb +12 -54
  91. data/spec/spec_helper.rb +7 -14
  92. data/spec/support/artifice/endpoint.rb +50 -0
  93. data/spec/support/artifice/endpoint_fallback.rb +22 -0
  94. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  95. data/spec/support/artifice/endpoint_redirect.rb +11 -0
  96. data/spec/support/builders.rb +2 -25
  97. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  98. data/spec/support/fakeweb/windows.rb +23 -0
  99. data/spec/support/helpers.rb +12 -5
  100. data/spec/support/matchers.rb +16 -4
  101. data/spec/support/path.rb +2 -0
  102. data/spec/support/rubygems_ext.rb +2 -6
  103. data/spec/update/gems_spec.rb +2 -3
  104. data/spec/update/git_spec.rb +2 -2
  105. metadata +41 -24
  106. data/.travis.yml +0 -31
  107. data/lib/bundler/gem_installer.rb +0 -9
  108. data/lib/bundler/gem_tasks.rb +0 -2
  109. data/lib/bundler/rubygems_integration.rb +0 -344
  110. data/lib/bundler/vendor/thor/actions/create_link.rb +0 -57
  111. data/lib/bundler/vendor/thor/group.rb +0 -273
  112. data/lib/bundler/vendor/thor/rake_compat.rb +0 -66
  113. data/lib/bundler/vendor/thor/runner.rb +0 -309
  114. data/lib/bundler/vendored_thor.rb +0 -7
@@ -36,7 +36,7 @@ module Bundler
36
36
  out = " #{name} (#{version}-#{platform})\n"
37
37
  end
38
38
 
39
- dependencies.sort_by {|d| d.to_s }.each do |dep|
39
+ dependencies.sort_by {|d| d.name }.each do |dep|
40
40
  next if dep.type == :development
41
41
  out << " #{dep.to_lock}\n"
42
42
  end
@@ -58,16 +58,13 @@ module Bundler
58
58
 
59
59
  private
60
60
 
61
- def to_ary
62
- nil
63
- end
64
-
65
61
  def method_missing(method, *args, &blk)
66
- raise "LazySpecification has not been materialized yet (calling :#{method} #{args.inspect})" unless @specification
67
-
68
- return super unless respond_to?(method)
69
-
70
- @specification.send(method, *args, &blk)
62
+ if Gem::Specification.new.respond_to?(method)
63
+ raise "LazySpecification has not been materialized yet (calling :#{method} #{args.inspect})" unless @specification
64
+ @specification.send(method, *args, &blk)
65
+ else
66
+ super
67
+ end
71
68
  end
72
69
 
73
70
  end
@@ -12,11 +12,11 @@ module Bundler
12
12
  attr_reader :name, :version, :platform
13
13
  attr_accessor :source
14
14
 
15
- def initialize(name, version, platform, source_uri)
16
- @name = name
17
- @version = version
18
- @platform = platform
19
- @source_uri = source_uri
15
+ def initialize(name, version, platform, spec_fetcher)
16
+ @name = name
17
+ @version = version
18
+ @platform = platform
19
+ @spec_fetcher = spec_fetcher
20
20
  end
21
21
 
22
22
  # Needed before installs, since the arch matters then and quick
@@ -43,9 +43,7 @@ module Bundler
43
43
  private
44
44
 
45
45
  def _remote_specification
46
- @specification ||= begin
47
- Gem::SpecFetcher.new.fetch_spec([@name, @version, @platform], URI(@source_uri.to_s))
48
- end
46
+ @specification ||= @spec_fetcher.fetch_spec([@name, @version, @platform])
49
47
  end
50
48
 
51
49
  def method_missing(method, *args, &blk)
@@ -145,7 +145,7 @@ module Bundler
145
145
  def debug
146
146
  if ENV['DEBUG_RESOLVER']
147
147
  debug_info = yield
148
- debug_info = debug_info.inspect unless debug_info.is_a?(String)
148
+ debug_info = debug_info.inpsect unless debug_info.is_a?(String)
149
149
  $stderr.puts debug_info
150
150
  end
151
151
  end
@@ -179,15 +179,15 @@ module Bundler
179
179
  activated[a.name] ? 0 : gems_size(a) ]
180
180
  end
181
181
 
182
- debug { "Activated:\n" + activated.values.map {|a| " #{a}" }.join("\n") }
183
- debug { "Requirements:\n" + reqs.map {|r| " #{r}"}.join("\n") }
182
+ debug { "Activated:\n" + activated.values.map { |a| " #{a.name} (#{a.version})" }.join("\n") }
183
+ debug { "Requirements:\n" + reqs.map { |r| " #{r.name} (#{r.requirement})"}.join("\n") }
184
184
 
185
185
  activated = activated.dup
186
186
 
187
187
  # Pull off the first requirement so that we can resolve it
188
188
  current = reqs.shift
189
189
 
190
- debug { "Attempting:\n #{current}"}
190
+ debug { "Attempting:\n #{current.name} (#{current.requirement})"}
191
191
 
192
192
  # Check if the gem has already been activated, if it has, we will make sure
193
193
  # that the currently activated gem satisfies the requirement.
@@ -279,6 +279,14 @@ module Bundler
279
279
  end
280
280
  raise GemNotFound, message
281
281
  else
282
+ if @missing_gems[current] >= 5
283
+ message = "Bundler could not find find gem #{current.required_by.last},"
284
+ message << "which is required by gem #{current}."
285
+ raise GemNotFound, message
286
+ end
287
+ @missing_gems[current] += 1
288
+
289
+ debug { " Could not find #{current} by #{current.required_by.last}" }
282
290
  @errors[current.name] = [nil, current]
283
291
  end
284
292
  end
@@ -348,8 +356,7 @@ module Bundler
348
356
 
349
357
  def search(dep)
350
358
  if base = @base[dep.name] and base.any?
351
- reqs = [dep.requirement.as_list, base.first.version.to_s].flatten.compact
352
- d = Gem::Dependency.new(base.first.name, *reqs)
359
+ d = Gem::Dependency.new(base.first.name, *[dep.requirement.as_list, base.first.version].flatten)
353
360
  else
354
361
  d = dep.dep
355
362
  end
@@ -413,7 +420,7 @@ module Bundler
413
420
  # If the origin is "bundler", the conflict is us
414
421
  if origin.name == "bundler"
415
422
  o << " Current Bundler version:\n"
416
- other_bundler_required = !requirement.requirement.satisfied_by?(origin.version)
423
+ newer_bundler_required = requirement.requirement > Gem::Requirement.new(origin.version)
417
424
  # If the origin is a LockfileParser, it does not respond_to :required_by
418
425
  elsif !origin.respond_to?(:required_by) || !(origin.required_by.first)
419
426
  o << " In snapshot (Gemfile.lock):\n"
@@ -422,9 +429,9 @@ module Bundler
422
429
  o << gem_message(origin)
423
430
 
424
431
  # If the bundle wants a newer bundler than the running bundler, explain
425
- if origin.name == "bundler" && other_bundler_required
426
- o << "This Gemfile requires a different version of Bundler.\n"
427
- o << "Perhaps you need to update Bundler by running `gem install bundler`?"
432
+ if origin.name == "bundler" && newer_bundler_required
433
+ o << "Your version of Bundler is older than the one requested by the Gemfile.\n"
434
+ o << "Perhaps you need to update Bundler by running `gem install bundler`."
428
435
  end
429
436
 
430
437
  # origin is nil if the required gem and version cannot be found in any of
@@ -449,8 +456,7 @@ module Bundler
449
456
  # the rest of the time, the gem cannot be found because it does not exist in the known sources
450
457
  else
451
458
  if requirement.required_by.first
452
- o << "Could not find gem '#{clean_req(requirement)}', which is required by "
453
- o << "gem '#{clean_req(requirement.required_by.first)}', in any of the sources."
459
+ o << "Could not find gem '#{clean_req(requirement)}', required by '#{clean_req(requirement.required_by.first)}', in any of the sources\n"
454
460
  else
455
461
  o << "Could not find gem '#{clean_req(requirement)} in any of the sources\n"
456
462
  end
@@ -19,7 +19,7 @@ module Gem
19
19
 
20
20
  def full_gem_path
21
21
  source.respond_to?(:path) ?
22
- Pathname.new(loaded_from).dirname.expand_path(Bundler.root).to_s :
22
+ Pathname.new(loaded_from).dirname.expand_path.to_s :
23
23
  rg_full_gem_path
24
24
  end
25
25
 
@@ -39,12 +39,6 @@ module Gem
39
39
  end
40
40
  end
41
41
 
42
- # RubyGems 1.8+ used only.
43
- remove_method :gem_dir if method_defined? :gem_dir
44
- def gem_dir
45
- full_gem_path
46
- end
47
-
48
42
  def groups
49
43
  @groups ||= []
50
44
  end
@@ -111,12 +105,6 @@ module Gem
111
105
 
112
106
  alias eql? ==
113
107
 
114
- def encode_with(coder)
115
- to_yaml_properties.each do |ivar|
116
- coder[ivar.to_s.sub(/^@/, '')] = instance_variable_get(ivar)
117
- end
118
- end
119
-
120
108
  def to_yaml_properties
121
109
  instance_variables.reject { |p| ["@source", "@groups"].include?(p.to_s) }
122
110
  end
@@ -124,13 +112,11 @@ module Gem
124
112
  def to_lock
125
113
  out = " #{name}"
126
114
  unless requirement == Gem::Requirement.default
127
- reqs = requirement.requirements.map{|o,v| "#{o} #{v}" }.sort.reverse
128
- out << " (#{reqs.join(', ')})"
115
+ out << " (#{requirement.to_s})"
129
116
  end
130
117
  out
131
118
  end
132
119
 
133
- # Backport of performance enhancement added to Rubygems 1.4
134
120
  def matches_spec?(spec)
135
121
  # name can be a Regexp, so use ===
136
122
  return false unless name === spec.name
@@ -141,7 +127,6 @@ module Gem
141
127
  end
142
128
 
143
129
  class Requirement
144
- # Backport of performance enhancement added to Rubygems 1.4
145
130
  def none?
146
131
  @none ||= (to_s == ">= 0")
147
132
  end unless allocate.respond_to?(:none?)
@@ -152,14 +137,12 @@ module Gem
152
137
  MSWIN = Gem::Platform.new('mswin32')
153
138
  MINGW = Gem::Platform.new('x86-mingw32')
154
139
 
155
- undef_method :hash if method_defined? :hash
156
140
  def hash
157
141
  @cpu.hash ^ @os.hash ^ @version.hash
158
142
  end
159
143
 
160
144
  alias eql? ==
161
145
  end
162
-
163
146
  end
164
147
 
165
148
  module Bundler
@@ -186,7 +169,7 @@ module Bundler
186
169
  end
187
170
 
188
171
  def to_s
189
- "#{name} (#{requirement}) #{__platform}"
172
+ @dep.to_s
190
173
  end
191
174
 
192
175
  private
@@ -11,7 +11,7 @@ module Bundler
11
11
  specs = groups.any? ? @definition.specs_for(groups) : requested_specs
12
12
 
13
13
  setup_environment
14
- Bundler.rubygems.replace_entrypoints(specs)
14
+ cripple_rubygems(specs)
15
15
 
16
16
  # Activate the specs
17
17
  specs.each do |spec|
@@ -19,9 +19,9 @@ module Bundler
19
19
  raise GemNotFound, "#{spec.full_name} is missing. Run `bundle` to get it."
20
20
  end
21
21
 
22
- if activated_spec = Bundler.rubygems.loaded_specs(spec.name) and activated_spec.version != spec.version
22
+ if activated_spec = Gem.loaded_specs[spec.name] and activated_spec.version != spec.version
23
23
  e = Gem::LoadError.new "You have already activated #{activated_spec.name} #{activated_spec.version}, " \
24
- "but your Gemfile requires #{spec.name} #{spec.version}. Using bundle exec may solve this."
24
+ "but your Gemfile requires #{spec.name} #{spec.version}. Consider using bundle exec."
25
25
  e.name = spec.name
26
26
  if e.respond_to?(:requirement=)
27
27
  e.requirement = Gem::Requirement.new(spec.version.to_s)
@@ -31,7 +31,7 @@ module Bundler
31
31
  raise e
32
32
  end
33
33
 
34
- Bundler.rubygems.mark_loaded(spec)
34
+ Gem.loaded_specs[spec.name] = spec
35
35
  load_paths = spec.load_paths.reject {|path| $LOAD_PATH.include?(path)}
36
36
  $LOAD_PATH.unshift(*load_paths)
37
37
  end
@@ -85,7 +85,7 @@ module Bundler
85
85
  alias gems specs
86
86
 
87
87
  def cache
88
- FileUtils.mkdir_p(cache_path) unless File.exists?(cache_path)
88
+ FileUtils.mkdir_p(cache_path)
89
89
 
90
90
  Bundler.ui.info "Updating .gem files in vendor/cache"
91
91
  specs.each do |spec|
@@ -96,13 +96,13 @@ module Bundler
96
96
  end
97
97
 
98
98
  def prune_cache
99
- FileUtils.mkdir_p(cache_path) unless File.exists?(cache_path)
99
+ FileUtils.mkdir_p(cache_path)
100
100
 
101
101
  resolve = @definition.resolve
102
102
  cached = Dir["#{cache_path}/*.gem"]
103
103
 
104
104
  cached = cached.delete_if do |path|
105
- spec = Bundler.rubygems.spec_from_gem path
105
+ spec = Gem::Format.from_file_by_path(path).spec
106
106
 
107
107
  resolve.any? do |s|
108
108
  s.name == spec.name && s.version == spec.version && !s.source.is_a?(Bundler::Source::Git)
@@ -119,6 +119,55 @@ module Bundler
119
119
  end
120
120
  end
121
121
 
122
+ def clean
123
+ return false if Bundler.settings[:path] == nil
124
+
125
+ gem_bins = Dir["#{Gem.dir}/bin/*"]
126
+ git_dirs = Dir["#{Gem.dir}/bundler/gems/*"]
127
+ gem_dirs = Dir["#{Gem.dir}/gems/*"]
128
+ spec_gem_paths = specs.collect {|spec| spec.full_gem_path }
129
+ spec_gem_executables = specs.collect do |spec|
130
+ spec.executables.collect do |executable|
131
+ "#{Gem.dir}/#{spec.bindir}/#{executable}"
132
+ end
133
+ end.flatten
134
+ stale_gem_bins = gem_bins - spec_gem_executables
135
+ stale_git_dirs = git_dirs - spec_gem_paths
136
+ stale_gem_dirs = gem_dirs - spec_gem_paths
137
+
138
+ stale_gem_bins.each {|bin| FileUtils.rm(bin) }
139
+ stale_gem_dirs.collect do |gem_dir|
140
+ full_name = Pathname.new(gem_dir).basename.to_s
141
+
142
+ FileUtils.rm_rf(gem_dir)
143
+ specification_file = "#{Gem.dir}/specifications/#{full_name}.gemspec"
144
+ FileUtils.rm(specification_file) if File.exists?(specification_file)
145
+
146
+ parts = full_name.split('-')
147
+ name = parts[0..-2].join('-')
148
+ version = parts.last
149
+ output = "#{name} (#{version})"
150
+
151
+ Bundler.ui.info "Removing #{output}"
152
+
153
+ output
154
+ end + stale_git_dirs.collect do |gem_dir|
155
+ full_name = Pathname.new(gem_dir).basename.to_s
156
+
157
+ FileUtils.rm_rf(gem_dir)
158
+
159
+ parts = full_name.split('-')
160
+ name = parts[0..-3].join('-')
161
+ revision = parts[-1]
162
+ version = parts[-2]
163
+ output = "#{name} (#{version} #{revision})"
164
+
165
+ Bundler.ui.info "Removing #{output}"
166
+
167
+ output
168
+ end
169
+ end
170
+
122
171
  private
123
172
 
124
173
  def cache_path
@@ -127,7 +176,7 @@ module Bundler
127
176
 
128
177
  def setup_environment
129
178
  begin
130
- ENV["BUNDLE_BIN_PATH"] = Bundler.rubygems.bin_path("bundler", "bundle", VERSION)
179
+ ENV["BUNDLE_BIN_PATH"] = Gem.bin_path("bundler", "bundle", VERSION)
131
180
  rescue Gem::GemNotFoundException
132
181
  ENV["BUNDLE_BIN_PATH"] = File.expand_path("../../../bin/bundle", __FILE__)
133
182
  end
@@ -16,7 +16,7 @@ module Bundler
16
16
  end
17
17
 
18
18
  def delete(key)
19
- @local_config.delete(key_for(key))
19
+ @local_config
20
20
  end
21
21
 
22
22
  def set_global(key, value)
@@ -62,7 +62,9 @@ module Bundler
62
62
  end
63
63
 
64
64
  def without=(array)
65
- self[:without] = (array.empty? ? nil : array.join(":")) if array
65
+ unless array.empty?
66
+ self[:without] = array.join(":")
67
+ end
66
68
  end
67
69
 
68
70
  def without
@@ -77,7 +79,7 @@ module Bundler
77
79
  if path = self[:path]
78
80
  "#{path}/#{Bundler.ruby_scope}"
79
81
  else
80
- Bundler.rubygems.gem_dir
82
+ Gem.dir
81
83
  end
82
84
  end
83
85
 
@@ -104,7 +106,7 @@ module Bundler
104
106
  end
105
107
 
106
108
  def global_config_file
107
- file = ENV["BUNDLE_CONFIG"] || File.join(Bundler.rubygems.user_home, ".bundle/config")
109
+ file = ENV["BUNDLE_CONFIG"] || File.join(Gem.user_home, ".bundle/config")
108
110
  Pathname.new(file)
109
111
  end
110
112
 
@@ -2,19 +2,12 @@ require 'bundler/shared_helpers'
2
2
 
3
3
  if Bundler::SharedHelpers.in_bundle?
4
4
  require 'bundler'
5
- if STDOUT.tty?
6
- begin
7
- Bundler.setup
8
- rescue Bundler::BundlerError => e
9
- puts "\e[31m#{e.message}\e[0m"
10
- puts e.backtrace.join("\n") if ENV["DEBUG"]
11
- if Bundler::GemNotFound === e
12
- puts "\e[33mRun `bundle install` to install missing gems.\e[0m"
13
- end
14
- exit e.status_code
15
- end
16
- else
5
+ begin
17
6
  Bundler.setup
7
+ rescue Bundler::BundlerError => e
8
+ puts "\e[31m#{e.message}\e[0m"
9
+ puts e.backtrace.join("\n") if ENV["DEBUG"]
10
+ exit e.status_code
18
11
  end
19
12
 
20
13
  # Add bundler to the load path after disabling system gems
@@ -1,7 +1,6 @@
1
1
  require 'pathname'
2
2
  require 'rubygems'
3
-
4
- require 'bundler/rubygems_integration'
3
+ Gem.source_index # ensure Rubygems is fully loaded in Ruby 1.9
5
4
 
6
5
  module Gem
7
6
  class Dependency
@@ -58,14 +57,111 @@ module Bundler
58
57
  if defined?(::Gem)
59
58
  me = File.expand_path("../../", __FILE__)
60
59
  $LOAD_PATH.reject! do |p|
61
- next if File.expand_path(p) =~ /^#{Regexp.escape(me)}/
60
+ next if File.expand_path(p) =~ /^#{me}/
62
61
  p != File.dirname(__FILE__) &&
63
- Bundler.rubygems.gem_path.any?{|gp| p =~ /^#{Regexp.escape(gp)}/ }
62
+ Gem.path.any?{|gp| p =~ /^#{gp}/ }
64
63
  end
65
64
  $LOAD_PATH.uniq!
66
65
  end
67
66
  end
68
67
 
68
+ def reverse_rubygems_kernel_mixin
69
+ # Disable rubygems' gem activation system
70
+ ::Kernel.class_eval do
71
+ if private_method_defined?(:gem_original_require)
72
+ alias rubygems_require require
73
+ alias require gem_original_require
74
+ end
75
+
76
+ undef gem
77
+ end
78
+ end
79
+
80
+ def cripple_rubygems(specs)
81
+ reverse_rubygems_kernel_mixin
82
+
83
+ executables = specs.map { |s| s.executables }.flatten
84
+ Gem.source_index # ensure RubyGems is fully loaded
85
+
86
+ ::Kernel.send(:define_method, :gem) do |dep, *reqs|
87
+ if executables.include? File.basename(caller.first.split(':').first)
88
+ return
89
+ end
90
+ opts = reqs.last.is_a?(Hash) ? reqs.pop : {}
91
+
92
+ unless dep.respond_to?(:name) && dep.respond_to?(:requirement)
93
+ dep = Gem::Dependency.new(dep, reqs)
94
+ end
95
+
96
+ spec = specs.find { |s| s.name == dep.name }
97
+
98
+ if spec.nil?
99
+
100
+ e = Gem::LoadError.new "#{dep.name} is not part of the bundle. Add it to Gemfile."
101
+ e.name = dep.name
102
+ if e.respond_to?(:requirement=)
103
+ e.requirement = dep.requirement
104
+ else
105
+ e.version_requirement = dep.requirement
106
+ end
107
+ raise e
108
+ elsif dep !~ spec
109
+ e = Gem::LoadError.new "can't activate #{dep}, already activated #{spec.full_name}. " \
110
+ "Make sure all dependencies are added to Gemfile."
111
+ e.name = dep.name
112
+ if e.respond_to?(:requirement=)
113
+ e.requirement = dep.requirement
114
+ else
115
+ e.version_requirement = dep.requirement
116
+ end
117
+ raise e
118
+ end
119
+
120
+ true
121
+ end
122
+
123
+ # === Following hacks are to improve on the generated bin wrappers ===
124
+
125
+ # Yeah, talk about a hack
126
+ source_index_class = (class << Gem::SourceIndex ; self ; end)
127
+ source_index_class.send(:remove_method, :from_gems_in)
128
+ source_index_class.send(:define_method, :from_gems_in) do |*args|
129
+ source_index = Gem::SourceIndex.new
130
+ source_index.spec_dirs = *args
131
+ source_index.add_specs(*specs)
132
+ source_index
133
+ end
134
+
135
+ # OMG more hacks
136
+ gem_class = (class << Gem ; self ; end)
137
+ gem_class.send(:remove_method, :refresh)
138
+ gem_class.send(:define_method, :refresh) { }
139
+ gem_class.send(:remove_method, :bin_path)
140
+ gem_class.send(:define_method, :bin_path) do |name, *args|
141
+ exec_name, *reqs = args
142
+
143
+ if exec_name == 'bundle'
144
+ return ENV['BUNDLE_BIN_PATH']
145
+ end
146
+
147
+ spec = nil
148
+
149
+ if exec_name
150
+ spec = specs.find { |s| s.executables.include?(exec_name) }
151
+ spec or raise Gem::Exception, "can't find executable #{exec_name}"
152
+ else
153
+ spec = specs.find { |s| s.name == name }
154
+ exec_name = spec.default_executable or raise Gem::Exception, "no default executable for #{spec.full_name}"
155
+ end
156
+
157
+ gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name)
158
+ gem_from_path_bin = File.join(File.dirname(spec.loaded_from), spec.bindir, exec_name)
159
+ File.exist?(gem_bin) ? gem_bin : gem_from_path_bin
160
+ end
161
+
162
+ Gem.clear_paths
163
+ end
164
+
69
165
  extend self
70
166
  end
71
167
  end