rkh-bundler 1.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/.gitignore +22 -0
  2. data/.travis.yml +42 -0
  3. data/CHANGELOG.md +1105 -0
  4. data/ISSUES.md +67 -0
  5. data/LICENSE +23 -0
  6. data/README.md +31 -0
  7. data/Rakefile +208 -0
  8. data/UPGRADING.md +103 -0
  9. data/bin/bundle +31 -0
  10. data/bundler.gemspec +31 -0
  11. data/lib/bundler.rb +353 -0
  12. data/lib/bundler/capistrano.rb +11 -0
  13. data/lib/bundler/cli.rb +693 -0
  14. data/lib/bundler/definition.rb +568 -0
  15. data/lib/bundler/dep_proxy.rb +43 -0
  16. data/lib/bundler/dependency.rb +134 -0
  17. data/lib/bundler/deployment.rb +58 -0
  18. data/lib/bundler/dsl.rb +256 -0
  19. data/lib/bundler/endpoint_specification.rb +78 -0
  20. data/lib/bundler/environment.rb +47 -0
  21. data/lib/bundler/fetcher.rb +225 -0
  22. data/lib/bundler/gem_helper.rb +162 -0
  23. data/lib/bundler/gem_helpers.rb +23 -0
  24. data/lib/bundler/gem_installer.rb +9 -0
  25. data/lib/bundler/gem_tasks.rb +2 -0
  26. data/lib/bundler/graph.rb +148 -0
  27. data/lib/bundler/index.rb +187 -0
  28. data/lib/bundler/installer.rb +190 -0
  29. data/lib/bundler/lazy_specification.rb +79 -0
  30. data/lib/bundler/lockfile_parser.rb +127 -0
  31. data/lib/bundler/match_platform.rb +13 -0
  32. data/lib/bundler/psyched_yaml.rb +15 -0
  33. data/lib/bundler/remote_specification.rb +57 -0
  34. data/lib/bundler/resolver.rb +486 -0
  35. data/lib/bundler/ruby_version.rb +94 -0
  36. data/lib/bundler/rubygems_ext.rb +153 -0
  37. data/lib/bundler/rubygems_integration.rb +394 -0
  38. data/lib/bundler/runtime.rb +233 -0
  39. data/lib/bundler/settings.rb +128 -0
  40. data/lib/bundler/setup.rb +23 -0
  41. data/lib/bundler/shared_helpers.rb +71 -0
  42. data/lib/bundler/source.rb +869 -0
  43. data/lib/bundler/spec_set.rb +137 -0
  44. data/lib/bundler/templates/Executable +16 -0
  45. data/lib/bundler/templates/Executable.standalone +12 -0
  46. data/lib/bundler/templates/Gemfile +4 -0
  47. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  48. data/lib/bundler/templates/newgem/LICENSE.tt +22 -0
  49. data/lib/bundler/templates/newgem/README.md.tt +29 -0
  50. data/lib/bundler/templates/newgem/Rakefile.tt +2 -0
  51. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  52. data/lib/bundler/templates/newgem/gitignore.tt +17 -0
  53. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +9 -0
  54. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  55. data/lib/bundler/templates/newgem/newgem.gemspec.tt +17 -0
  56. data/lib/bundler/ui.rb +88 -0
  57. data/lib/bundler/vendor/net/http/faster.rb +27 -0
  58. data/lib/bundler/vendor/net/http/persistent.rb +468 -0
  59. data/lib/bundler/vendor/thor.rb +358 -0
  60. data/lib/bundler/vendor/thor/actions.rb +314 -0
  61. data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
  62. data/lib/bundler/vendor/thor/actions/create_link.rb +57 -0
  63. data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
  64. data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
  65. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +270 -0
  66. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +109 -0
  67. data/lib/bundler/vendor/thor/base.rb +576 -0
  68. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
  69. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  70. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
  71. data/lib/bundler/vendor/thor/error.rb +30 -0
  72. data/lib/bundler/vendor/thor/group.rb +273 -0
  73. data/lib/bundler/vendor/thor/invocation.rb +168 -0
  74. data/lib/bundler/vendor/thor/parser.rb +4 -0
  75. data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
  76. data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
  77. data/lib/bundler/vendor/thor/parser/option.rb +120 -0
  78. data/lib/bundler/vendor/thor/parser/options.rb +172 -0
  79. data/lib/bundler/vendor/thor/rake_compat.rb +66 -0
  80. data/lib/bundler/vendor/thor/runner.rb +309 -0
  81. data/lib/bundler/vendor/thor/shell.rb +88 -0
  82. data/lib/bundler/vendor/thor/shell/basic.rb +302 -0
  83. data/lib/bundler/vendor/thor/shell/color.rb +108 -0
  84. data/lib/bundler/vendor/thor/shell/html.rb +121 -0
  85. data/lib/bundler/vendor/thor/task.rb +113 -0
  86. data/lib/bundler/vendor/thor/util.rb +229 -0
  87. data/lib/bundler/vendor/thor/version.rb +3 -0
  88. data/lib/bundler/vendored_thor.rb +7 -0
  89. data/lib/bundler/version.rb +6 -0
  90. data/lib/bundler/vlad.rb +11 -0
  91. data/man/bundle-config.ronn +130 -0
  92. data/man/bundle-exec.ronn +111 -0
  93. data/man/bundle-install.ronn +335 -0
  94. data/man/bundle-package.ronn +59 -0
  95. data/man/bundle-update.ronn +176 -0
  96. data/man/bundle.ronn +83 -0
  97. data/man/gemfile.5.ronn +324 -0
  98. data/man/index.txt +6 -0
  99. data/spec/bundler/dsl_spec.rb +48 -0
  100. data/spec/bundler/gem_helper_spec.rb +174 -0
  101. data/spec/bundler/source_spec.rb +25 -0
  102. data/spec/cache/gems_spec.rb +239 -0
  103. data/spec/cache/git_spec.rb +124 -0
  104. data/spec/cache/path_spec.rb +103 -0
  105. data/spec/cache/platform_spec.rb +57 -0
  106. data/spec/install/deploy_spec.rb +211 -0
  107. data/spec/install/gems/c_ext_spec.rb +48 -0
  108. data/spec/install/gems/dependency_api_spec.rb +402 -0
  109. data/spec/install/gems/env_spec.rb +107 -0
  110. data/spec/install/gems/flex_spec.rb +313 -0
  111. data/spec/install/gems/groups_spec.rb +268 -0
  112. data/spec/install/gems/packed_spec.rb +84 -0
  113. data/spec/install/gems/platform_spec.rb +208 -0
  114. data/spec/install/gems/post_install_spec.rb +47 -0
  115. data/spec/install/gems/resolving_spec.rb +72 -0
  116. data/spec/install/gems/simple_case_spec.rb +814 -0
  117. data/spec/install/gems/standalone_spec.rb +260 -0
  118. data/spec/install/gems/sudo_spec.rb +74 -0
  119. data/spec/install/gems/win32_spec.rb +26 -0
  120. data/spec/install/gemspec_spec.rb +170 -0
  121. data/spec/install/git_spec.rb +796 -0
  122. data/spec/install/invalid_spec.rb +35 -0
  123. data/spec/install/path_spec.rb +405 -0
  124. data/spec/install/upgrade_spec.rb +26 -0
  125. data/spec/lock/git_spec.rb +35 -0
  126. data/spec/lock/lockfile_spec.rb +809 -0
  127. data/spec/other/check_spec.rb +265 -0
  128. data/spec/other/clean_spec.rb +492 -0
  129. data/spec/other/config_spec.rb +138 -0
  130. data/spec/other/console_spec.rb +54 -0
  131. data/spec/other/exec_spec.rb +229 -0
  132. data/spec/other/ext_spec.rb +37 -0
  133. data/spec/other/help_spec.rb +39 -0
  134. data/spec/other/init_spec.rb +40 -0
  135. data/spec/other/newgem_spec.rb +87 -0
  136. data/spec/other/open_spec.rb +35 -0
  137. data/spec/other/outdated_spec.rb +93 -0
  138. data/spec/other/platform_spec.rb +881 -0
  139. data/spec/other/show_spec.rb +88 -0
  140. data/spec/quality_spec.rb +62 -0
  141. data/spec/realworld/edgecases_spec.rb +177 -0
  142. data/spec/resolver/basic_spec.rb +20 -0
  143. data/spec/resolver/platform_spec.rb +82 -0
  144. data/spec/runtime/executable_spec.rb +120 -0
  145. data/spec/runtime/load_spec.rb +107 -0
  146. data/spec/runtime/platform_spec.rb +90 -0
  147. data/spec/runtime/require_spec.rb +261 -0
  148. data/spec/runtime/setup_spec.rb +755 -0
  149. data/spec/runtime/with_clean_env_spec.rb +80 -0
  150. data/spec/spec_helper.rb +98 -0
  151. data/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb +13 -0
  152. data/spec/support/artifice/endpoint.rb +54 -0
  153. data/spec/support/artifice/endpoint_500.rb +37 -0
  154. data/spec/support/artifice/endpoint_api_missing.rb +16 -0
  155. data/spec/support/artifice/endpoint_basic_authentication.rb +13 -0
  156. data/spec/support/artifice/endpoint_extra.rb +27 -0
  157. data/spec/support/artifice/endpoint_extra_missing.rb +15 -0
  158. data/spec/support/artifice/endpoint_fallback.rb +18 -0
  159. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  160. data/spec/support/artifice/endpoint_redirect.rb +15 -0
  161. data/spec/support/builders.rb +604 -0
  162. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  163. data/spec/support/fakeweb/windows.rb +23 -0
  164. data/spec/support/helpers.rb +317 -0
  165. data/spec/support/indexes.rb +112 -0
  166. data/spec/support/matchers.rb +77 -0
  167. data/spec/support/path.rb +73 -0
  168. data/spec/support/platforms.rb +86 -0
  169. data/spec/support/ruby_ext.rb +20 -0
  170. data/spec/support/rubygems_ext.rb +37 -0
  171. data/spec/support/rubygems_hax/platform.rb +22 -0
  172. data/spec/support/sudo.rb +21 -0
  173. data/spec/update/gems_spec.rb +134 -0
  174. data/spec/update/git_spec.rb +196 -0
  175. data/spec/update/source_spec.rb +51 -0
  176. metadata +338 -0
@@ -0,0 +1,94 @@
1
+ module Bundler
2
+ class RubyVersion
3
+ attr_reader :version, :engine, :engine_version
4
+
5
+ def initialize(version, engine, engine_version)
6
+ # The parameters to this method must satisfy the
7
+ # following constraints, which are verified in
8
+ # the DSL:
9
+ #
10
+ # * If an engine is specified, an engine version
11
+ # must also be specified
12
+ # * If an engine version is specified, an engine
13
+ # must also be specified
14
+ # * If the engine is "ruby", the engine version
15
+ # must not be specified, or the engine version
16
+ # specified must match the version.
17
+
18
+ @version = version
19
+ @engine = engine || "ruby"
20
+ @engine_version = engine_version || version
21
+ end
22
+
23
+ def to_s
24
+ output = "ruby #{version}"
25
+ output << " (#{engine} #{engine_version})" unless engine == "ruby"
26
+
27
+ output
28
+ end
29
+
30
+ def ==(other)
31
+ version == other.version &&
32
+ engine == other.engine &&
33
+ engine_version == other.engine_version
34
+ end
35
+
36
+ # Returns a tuple of thsee things:
37
+ # [diff, this, other]
38
+ # The priority of attributes are
39
+ # 1. engine
40
+ # 2. ruby_version
41
+ # 3. engine_version
42
+ def diff(other)
43
+ if engine != other.engine
44
+ [ :engine, engine, other.engine ]
45
+ elsif version != other.version
46
+ [ :version, version, other.version ]
47
+ elsif engine_version != other.engine_version
48
+ [ :engine_version, engine_version, other.engine_version ]
49
+ else
50
+ nil
51
+ end
52
+ end
53
+ end
54
+
55
+ # A subclass of RubyVersion that implements version,
56
+ # engine and engine_version based upon the current
57
+ # information in the system. It can be used anywhere
58
+ # a RubyVersion object is expected, and can be
59
+ # compared with a RubyVersion object.
60
+ class SystemRubyVersion < RubyVersion
61
+ def initialize(*)
62
+ # override the default initialize, because
63
+ # we will implement version, engine and
64
+ # engine_version dynamically
65
+ end
66
+
67
+ def version
68
+ RUBY_VERSION
69
+ end
70
+
71
+ def engine
72
+ if defined?(RUBY_ENGINE)
73
+ RUBY_ENGINE
74
+ else
75
+ # not defined in ruby 1.8.7
76
+ "ruby"
77
+ end
78
+ end
79
+
80
+ def engine_version
81
+ case engine
82
+ when "ruby"
83
+ RUBY_VERSION
84
+ when "rbx"
85
+ Rubinius::VERSION
86
+ when "jruby"
87
+ JRUBY_VERSION
88
+ else
89
+ raise BundlerError, "That RUBY_ENGINE is not recognized"
90
+ nil
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,153 @@
1
+ require 'pathname'
2
+
3
+ if defined?(Gem::QuickLoader)
4
+ # Gem Prelude makes me a sad panda :'(
5
+ Gem::QuickLoader.load_full_rubygems_library
6
+ end
7
+
8
+ require 'rubygems'
9
+ require 'rubygems/specification'
10
+ require 'bundler/match_platform'
11
+
12
+ module Gem
13
+ @loaded_stacks = Hash.new { |h,k| h[k] = [] }
14
+
15
+ class Specification
16
+ attr_accessor :source, :location, :relative_loaded_from
17
+
18
+ alias_method :rg_full_gem_path, :full_gem_path
19
+ alias_method :rg_loaded_from, :loaded_from
20
+
21
+ def full_gem_path
22
+ source.respond_to?(:path) ?
23
+ Pathname.new(loaded_from).dirname.expand_path(Bundler.root).to_s :
24
+ rg_full_gem_path
25
+ end
26
+
27
+ def loaded_from
28
+ relative_loaded_from ?
29
+ source.path.join(relative_loaded_from).to_s :
30
+ rg_loaded_from
31
+ end
32
+
33
+ def load_paths
34
+ require_paths.map do |require_path|
35
+ if require_path.include?(full_gem_path)
36
+ require_path
37
+ else
38
+ File.join(full_gem_path, require_path)
39
+ end
40
+ end
41
+ end
42
+
43
+ # RubyGems 1.8+ used only.
44
+ remove_method :gem_dir if method_defined? :gem_dir
45
+ def gem_dir
46
+ full_gem_path
47
+ end
48
+
49
+ def groups
50
+ @groups ||= []
51
+ end
52
+
53
+ def git_version
54
+ if @loaded_from && File.exist?(File.join(full_gem_path, ".git"))
55
+ sha = Dir.chdir(full_gem_path){ `git rev-parse HEAD`.strip }
56
+ " #{sha[0..6]}"
57
+ end
58
+ end
59
+
60
+ def to_gemfile(path = nil)
61
+ gemfile = "source :gemcutter\n"
62
+ gemfile << dependencies_to_gemfile(nondevelopment_dependencies)
63
+ unless development_dependencies.empty?
64
+ gemfile << "\n"
65
+ gemfile << dependencies_to_gemfile(development_dependencies, :development)
66
+ end
67
+ gemfile
68
+ end
69
+
70
+ def nondevelopment_dependencies
71
+ dependencies - development_dependencies
72
+ end
73
+
74
+ private
75
+
76
+ def dependencies_to_gemfile(dependencies, group = nil)
77
+ gemfile = ''
78
+ if dependencies.any?
79
+ gemfile << "group :#{group} do\n" if group
80
+ dependencies.each do |dependency|
81
+ gemfile << ' ' if group
82
+ gemfile << %|gem "#{dependency.name}"|
83
+ req = dependency.requirements_list.first
84
+ gemfile << %|, "#{req}"| if req
85
+ gemfile << "\n"
86
+ end
87
+ gemfile << "end\n" if group
88
+ end
89
+ gemfile
90
+ end
91
+
92
+ end
93
+
94
+ class Dependency
95
+ attr_accessor :source, :groups
96
+
97
+ alias eql? ==
98
+
99
+ def encode_with(coder)
100
+ to_yaml_properties.each do |ivar|
101
+ coder[ivar.to_s.sub(/^@/, '')] = instance_variable_get(ivar)
102
+ end
103
+ end
104
+
105
+ def to_yaml_properties
106
+ instance_variables.reject { |p| ["@source", "@groups"].include?(p.to_s) }
107
+ end
108
+
109
+ def to_lock
110
+ out = " #{name}"
111
+ unless requirement == Gem::Requirement.default
112
+ reqs = requirement.requirements.map{|o,v| "#{o} #{v}" }.sort.reverse
113
+ out << " (#{reqs.join(', ')})"
114
+ end
115
+ out
116
+ end
117
+
118
+ # Backport of performance enhancement added to Rubygems 1.4
119
+ def matches_spec?(spec)
120
+ # name can be a Regexp, so use ===
121
+ return false unless name === spec.name
122
+ return true if requirement.none?
123
+
124
+ requirement.satisfied_by?(spec.version)
125
+ end unless allocate.respond_to?(:matches_spec?)
126
+ end
127
+
128
+ class Requirement
129
+ # Backport of performance enhancement added to Rubygems 1.4
130
+ def none?
131
+ @none ||= (to_s == ">= 0")
132
+ end unless allocate.respond_to?(:none?)
133
+ end
134
+
135
+ class Platform
136
+ JAVA = Gem::Platform.new('java')
137
+ MSWIN = Gem::Platform.new('mswin32')
138
+ MINGW = Gem::Platform.new('x86-mingw32')
139
+
140
+ undef_method :hash if method_defined? :hash
141
+ def hash
142
+ @cpu.hash ^ @os.hash ^ @version.hash
143
+ end
144
+
145
+ alias eql? ==
146
+ end
147
+ end
148
+
149
+ module Gem
150
+ class Specification
151
+ include ::Bundler::MatchPlatform
152
+ end
153
+ end
@@ -0,0 +1,394 @@
1
+ module Bundler
2
+ class RubygemsIntegration
3
+ def initialize
4
+ # Work around a RubyGems bug
5
+ configuration
6
+ end
7
+
8
+ def loaded_specs(name)
9
+ Gem.loaded_specs[name]
10
+ end
11
+
12
+ def mark_loaded(spec)
13
+ Gem.loaded_specs[spec.name] = spec
14
+ end
15
+
16
+ def path(obj)
17
+ obj.to_s
18
+ end
19
+
20
+ def platforms
21
+ Gem.platforms
22
+ end
23
+
24
+ def configuration
25
+ Gem.configuration
26
+ end
27
+
28
+ def ruby_engine
29
+ Gem.ruby_engine
30
+ end
31
+
32
+ def read_binary(path)
33
+ Gem.read_binary(path)
34
+ end
35
+
36
+ def inflate(obj)
37
+ Gem.inflate(obj)
38
+ end
39
+
40
+ def sources=(val)
41
+ Gem.sources = val
42
+ end
43
+
44
+ def sources
45
+ Gem.sources
46
+ end
47
+
48
+ def gem_dir
49
+ Gem.dir
50
+ end
51
+
52
+ def gem_bindir
53
+ Gem.bindir
54
+ end
55
+
56
+ def user_home
57
+ Gem.user_home
58
+ end
59
+
60
+ def gem_path
61
+ Gem.path
62
+ end
63
+
64
+ def marshal_spec_dir
65
+ Gem::MARSHAL_SPEC_DIR
66
+ end
67
+
68
+ def clear_paths
69
+ Gem.clear_paths
70
+ end
71
+
72
+ def bin_path(gem, bin, ver)
73
+ Gem.bin_path(gem, bin, ver)
74
+ end
75
+
76
+ def refresh
77
+ Gem.refresh
78
+ end
79
+
80
+ def preserve_paths
81
+ # this is a no-op outside of Rubygems 1.8
82
+ yield
83
+ end
84
+
85
+ def ui=(obj)
86
+ Gem::DefaultUserInteraction.ui = obj
87
+ end
88
+
89
+ def fetch_specs(all, pre, &blk)
90
+ Gem::SpecFetcher.new.list(all, pre).each(&blk)
91
+ end
92
+
93
+ def with_build_args(args)
94
+ old_args = Gem::Command.build_args
95
+ begin
96
+ Gem::Command.build_args = args
97
+ yield
98
+ ensure
99
+ Gem::Command.build_args = old_args
100
+ end
101
+ end
102
+
103
+ def spec_from_gem(path)
104
+ Gem::Format.from_file_by_path(path).spec
105
+ end
106
+
107
+ def download_gem(spec, uri, path)
108
+ Gem::RemoteFetcher.fetcher.download(spec, uri, path)
109
+ end
110
+
111
+ def reverse_rubygems_kernel_mixin
112
+ # Disable rubygems' gem activation system
113
+ ::Kernel.class_eval do
114
+ if private_method_defined?(:gem_original_require)
115
+ alias rubygems_require require
116
+ alias require gem_original_require
117
+ end
118
+
119
+ undef gem
120
+ end
121
+ end
122
+
123
+ def replace_gem(specs)
124
+ executables = specs.map { |s| s.executables }.flatten
125
+
126
+ ::Kernel.send(:define_method, :gem) do |dep, *reqs|
127
+ if executables.include? File.basename(caller.first.split(':').first)
128
+ return
129
+ end
130
+ reqs.pop if reqs.last.is_a?(Hash)
131
+
132
+ unless dep.respond_to?(:name) && dep.respond_to?(:requirement)
133
+ dep = Gem::Dependency.new(dep, reqs)
134
+ end
135
+
136
+ spec = specs.find { |s| s.name == dep.name }
137
+
138
+ if spec.nil?
139
+
140
+ e = Gem::LoadError.new "#{dep.name} is not part of the bundle. Add it to Gemfile."
141
+ e.name = dep.name
142
+ if e.respond_to?(:requirement=)
143
+ e.requirement = dep.requirement
144
+ else
145
+ e.version_requirement = dep.requirement
146
+ end
147
+ raise e
148
+ elsif dep !~ spec
149
+ e = Gem::LoadError.new "can't activate #{dep}, already activated #{spec.full_name}. " \
150
+ "Make sure all dependencies are added to Gemfile."
151
+ e.name = dep.name
152
+ if e.respond_to?(:requirement=)
153
+ e.requirement = dep.requirement
154
+ else
155
+ e.version_requirement = dep.requirement
156
+ end
157
+ raise e
158
+ end
159
+
160
+ true
161
+ end
162
+ end
163
+
164
+ if defined? ::Deprecate
165
+ Deprecate = ::Deprecate
166
+ elsif defined? Gem::Deprecate
167
+ Deprecate = Gem::Deprecate
168
+ else
169
+ class Deprecate
170
+ def skip_during; yield; end
171
+ end
172
+ end
173
+
174
+ def stub_source_index137(specs)
175
+ # Rubygems versions lower than 1.7 use SourceIndex#from_gems_in
176
+ source_index_class = (class << Gem::SourceIndex ; self ; end)
177
+ source_index_class.send(:remove_method, :from_gems_in)
178
+ source_index_class.send(:define_method, :from_gems_in) do |*args|
179
+ source_index = Gem::SourceIndex.new
180
+ source_index.spec_dirs = *args
181
+ source_index.add_specs(*specs)
182
+ source_index
183
+ end
184
+ end
185
+
186
+ def stub_source_index170(specs)
187
+ Gem::SourceIndex.send(:alias_method, :old_initialize, :initialize)
188
+ Gem::SourceIndex.send(:define_method, :initialize) do |*args|
189
+ @gems = {}
190
+ # You're looking at this thinking: Oh! This is how I make those
191
+ # rubygems deprecations go away!
192
+ #
193
+ # You'd be correct BUT using of this method in production code
194
+ # must be approved by the rubygems team itself!
195
+ #
196
+ # This is your warning. If you use this and don't have approval
197
+ # we can't protect you.
198
+ #
199
+ Deprecate.skip_during do
200
+ self.spec_dirs = *args
201
+ add_specs(*specs)
202
+ end
203
+ end
204
+ end
205
+
206
+ # Used to make bin stubs that are not created by bundler work
207
+ # under bundler. The new Gem.bin_path only considers gems in
208
+ # +specs+
209
+ def replace_bin_path(specs)
210
+ gem_class = (class << Gem ; self ; end)
211
+ gem_class.send(:remove_method, :bin_path)
212
+ gem_class.send(:define_method, :bin_path) do |name, *args|
213
+ exec_name = args.first
214
+
215
+ if exec_name == 'bundle'
216
+ return ENV['BUNDLE_BIN_PATH']
217
+ end
218
+
219
+ spec = nil
220
+
221
+ if exec_name
222
+ spec = specs.find { |s| s.executables.include?(exec_name) }
223
+ spec or raise Gem::Exception, "can't find executable #{exec_name}"
224
+ else
225
+ spec = specs.find { |s| s.name == name }
226
+ exec_name = spec.default_executable or raise Gem::Exception, "no default executable for #{spec.full_name}"
227
+ end
228
+
229
+ gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name)
230
+ gem_from_path_bin = File.join(File.dirname(spec.loaded_from), spec.bindir, exec_name)
231
+ File.exist?(gem_bin) ? gem_bin : gem_from_path_bin
232
+ end
233
+ end
234
+
235
+ # Because Bundler has a static view of what specs are available,
236
+ # we don't #refresh, so stub it out.
237
+ def replace_refresh
238
+ gem_class = (class << Gem ; self ; end)
239
+ gem_class.send(:remove_method, :refresh)
240
+ gem_class.send(:define_method, :refresh) { }
241
+ end
242
+
243
+ # Replace or hook into Rubygems to provide a bundlerized view
244
+ # of the world.
245
+ def replace_entrypoints(specs)
246
+ reverse_rubygems_kernel_mixin
247
+
248
+ replace_gem(specs)
249
+
250
+ stub_rubygems(specs)
251
+
252
+ replace_bin_path(specs)
253
+ replace_refresh
254
+
255
+ Gem.clear_paths
256
+ end
257
+
258
+ # This backports the correct segment generation code from Rubygems 1.4+
259
+ # by monkeypatching it into the method in Rubygems 1.3.6 and 1.3.7.
260
+ def backport_segment_generation
261
+ Gem::Version.send(:define_method, :segments) do
262
+ @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s|
263
+ /^\d+$/ =~ s ? s.to_i : s
264
+ end
265
+ end
266
+ end
267
+
268
+ # This backport fixes the marshaling of @segments.
269
+ def backport_yaml_initialize
270
+ Gem::Version.send(:define_method, :yaml_initialize) do |tag, map|
271
+ @version = map['version']
272
+ @segments = nil
273
+ @hash = nil
274
+ end
275
+ end
276
+
277
+ # This backports base_dir which replaces installation path
278
+ # Rubygems 1.8+
279
+ def backport_base_dir
280
+ Gem::Specification.send(:define_method, :base_dir) do
281
+ return Gem.dir unless loaded_from
282
+ File.dirname File.dirname loaded_from
283
+ end
284
+ end
285
+
286
+ def backport_cache_file
287
+ Gem::Specification.send(:define_method, :cache_dir) do
288
+ @cache_dir ||= File.join base_dir, "cache"
289
+ end
290
+
291
+ Gem::Specification.send(:define_method, :cache_file) do
292
+ @cache_file ||= File.join cache_dir, "#{full_name}.gem"
293
+ end
294
+ end
295
+
296
+ def backport_spec_file
297
+ Gem::Specification.send(:define_method, :spec_dir) do
298
+ @spec_dir ||= File.join base_dir, "specifications"
299
+ end
300
+
301
+ Gem::Specification.send(:define_method, :spec_file) do
302
+ @spec_file ||= File.join spec_dir, "#{full_name}.gemspec"
303
+ end
304
+ end
305
+
306
+ # Rubygems 1.4 through 1.6
307
+ class Legacy < RubygemsIntegration
308
+ def initialize
309
+ super
310
+ backport_base_dir
311
+ backport_cache_file
312
+ backport_spec_file
313
+ backport_yaml_initialize
314
+ end
315
+
316
+ def stub_rubygems(specs)
317
+ stub_source_index137(specs)
318
+ end
319
+
320
+ def all_specs
321
+ Gem.source_index.gems.values
322
+ end
323
+
324
+ def find_name(name)
325
+ Gem.source_index.find_name(name)
326
+ end
327
+ end
328
+
329
+ # Rubygems versions 1.3.6 and 1.3.7
330
+ class Ancient < Legacy
331
+ def initialize
332
+ super
333
+ backport_segment_generation
334
+ end
335
+ end
336
+
337
+ # Rubygems 1.7
338
+ class Transitional < Legacy
339
+ def stub_rubygems(specs)
340
+ stub_source_index170(specs)
341
+ end
342
+ end
343
+
344
+ # Rubygems 1.8.5
345
+ class Modern < RubygemsIntegration
346
+ def stub_rubygems(specs)
347
+ Gem::Specification.all = specs
348
+
349
+ Gem.post_reset {
350
+ Gem::Specification.all = specs
351
+ }
352
+
353
+ stub_source_index170(specs)
354
+ end
355
+
356
+ def all_specs
357
+ Gem::Specification.to_a
358
+ end
359
+
360
+ def find_name(name)
361
+ Gem::Specification.find_all_by_name name
362
+ end
363
+ end
364
+
365
+ # Rubygems 1.8.0 to 1.8.4
366
+ class AlmostModern < Modern
367
+ # Rubygems [>= 1.8.0, < 1.8.5] has a bug that changes Gem.dir whenever
368
+ # you call Gem::Installer#install with an :install_dir set. We have to
369
+ # change it back for our sudo mode to work.
370
+ def preserve_paths
371
+ old_dir, old_path = gem_dir, gem_path
372
+ yield
373
+ Gem.use_paths(old_dir, old_path)
374
+ end
375
+ end
376
+
377
+ end
378
+
379
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.5')
380
+ @rubygems = RubygemsIntegration::Modern.new
381
+ elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0')
382
+ @rubygems = RubygemsIntegration::AlmostModern.new
383
+ elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.7.0')
384
+ @rubygems = RubygemsIntegration::Transitional.new
385
+ elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.4.0')
386
+ @rubygems = RubygemsIntegration::Legacy.new
387
+ else # Rubygems 1.3.6 and 1.3.7
388
+ @rubygems = RubygemsIntegration::Ancient.new
389
+ end
390
+
391
+ class << self
392
+ attr_reader :rubygems
393
+ end
394
+ end