rubygems-update 2.6.4 → 2.6.5

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

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (288) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +18 -24
  3. data/CODE_OF_CONDUCT.md +2 -2
  4. data/CONTRIBUTING.rdoc +1 -1
  5. data/History.txt +30 -1
  6. data/Manifest.txt +233 -3
  7. data/Rakefile +30 -1
  8. data/appveyor.yml +0 -2
  9. data/bundler/CHANGELOG.md +2407 -0
  10. data/bundler/CODE_OF_CONDUCT.md +42 -0
  11. data/bundler/CONTRIBUTING.md +36 -0
  12. data/bundler/DEVELOPMENT.md +148 -0
  13. data/bundler/ISSUES.md +100 -0
  14. data/bundler/LICENSE.md +23 -0
  15. data/bundler/README.md +40 -0
  16. data/bundler/exe/bundle +35 -0
  17. data/bundler/exe/bundle_ruby +61 -0
  18. data/bundler/exe/bundler +22 -0
  19. data/bundler/lib/bundler.rb +455 -0
  20. data/bundler/lib/bundler/capistrano.rb +17 -0
  21. data/bundler/lib/bundler/cli.rb +497 -0
  22. data/bundler/lib/bundler/cli/binstubs.rb +40 -0
  23. data/bundler/lib/bundler/cli/cache.rb +35 -0
  24. data/bundler/lib/bundler/cli/check.rb +40 -0
  25. data/bundler/lib/bundler/cli/clean.rb +26 -0
  26. data/bundler/lib/bundler/cli/common.rb +56 -0
  27. data/bundler/lib/bundler/cli/config.rb +100 -0
  28. data/bundler/lib/bundler/cli/console.rb +39 -0
  29. data/bundler/lib/bundler/cli/exec.rb +82 -0
  30. data/bundler/lib/bundler/cli/gem.rb +214 -0
  31. data/bundler/lib/bundler/cli/init.rb +33 -0
  32. data/bundler/lib/bundler/cli/inject.rb +33 -0
  33. data/bundler/lib/bundler/cli/install.rb +225 -0
  34. data/bundler/lib/bundler/cli/lock.rb +48 -0
  35. data/bundler/lib/bundler/cli/open.rb +25 -0
  36. data/bundler/lib/bundler/cli/outdated.rb +151 -0
  37. data/bundler/lib/bundler/cli/package.rb +46 -0
  38. data/bundler/lib/bundler/cli/platform.rb +45 -0
  39. data/bundler/lib/bundler/cli/plugin.rb +23 -0
  40. data/bundler/lib/bundler/cli/show.rb +75 -0
  41. data/bundler/lib/bundler/cli/update.rb +72 -0
  42. data/bundler/lib/bundler/cli/viz.rb +27 -0
  43. data/bundler/lib/bundler/constants.rb +6 -0
  44. data/bundler/lib/bundler/current_ruby.rb +84 -0
  45. data/bundler/lib/bundler/definition.rb +744 -0
  46. data/bundler/lib/bundler/dep_proxy.rb +46 -0
  47. data/bundler/lib/bundler/dependency.rb +127 -0
  48. data/bundler/lib/bundler/deployment.rb +63 -0
  49. data/bundler/lib/bundler/deprecate.rb +16 -0
  50. data/bundler/lib/bundler/dsl.rb +512 -0
  51. data/bundler/lib/bundler/endpoint_specification.rb +129 -0
  52. data/bundler/lib/bundler/env.rb +83 -0
  53. data/bundler/lib/bundler/environment.rb +42 -0
  54. data/bundler/lib/bundler/environment_preserver.rb +38 -0
  55. data/bundler/lib/bundler/errors.rb +124 -0
  56. data/bundler/lib/bundler/fetcher.rb +304 -0
  57. data/bundler/lib/bundler/fetcher/base.rb +41 -0
  58. data/bundler/lib/bundler/fetcher/compact_index.rb +103 -0
  59. data/bundler/lib/bundler/fetcher/dependency.rb +92 -0
  60. data/bundler/lib/bundler/fetcher/downloader.rb +66 -0
  61. data/bundler/lib/bundler/fetcher/index.rb +51 -0
  62. data/bundler/lib/bundler/friendly_errors.rb +103 -0
  63. data/bundler/lib/bundler/gem_helper.rb +188 -0
  64. data/bundler/lib/bundler/gem_helpers.rb +32 -0
  65. data/bundler/lib/bundler/gem_remote_fetcher.rb +42 -0
  66. data/bundler/lib/bundler/gem_tasks.rb +6 -0
  67. data/bundler/lib/bundler/graph.rb +172 -0
  68. data/bundler/lib/bundler/index.rb +191 -0
  69. data/bundler/lib/bundler/injector.rb +63 -0
  70. data/bundler/lib/bundler/inline.rb +74 -0
  71. data/bundler/lib/bundler/installer.rb +217 -0
  72. data/bundler/lib/bundler/installer/gem_installer.rb +77 -0
  73. data/bundler/lib/bundler/installer/parallel_installer.rb +126 -0
  74. data/bundler/lib/bundler/installer/standalone.rb +52 -0
  75. data/bundler/lib/bundler/lazy_specification.rb +85 -0
  76. data/bundler/lib/bundler/lockfile_parser.rb +233 -0
  77. data/bundler/lib/bundler/match_platform.rb +14 -0
  78. data/bundler/lib/bundler/mirror.rb +218 -0
  79. data/bundler/lib/bundler/plugin.rb +156 -0
  80. data/bundler/lib/bundler/plugin/api.rb +56 -0
  81. data/bundler/lib/bundler/plugin/dsl.rb +29 -0
  82. data/bundler/lib/bundler/plugin/index.rb +88 -0
  83. data/bundler/lib/bundler/plugin/installer.rb +99 -0
  84. data/bundler/lib/bundler/plugin/installer/git.rb +38 -0
  85. data/bundler/lib/bundler/plugin/installer/rubygems.rb +27 -0
  86. data/bundler/lib/bundler/plugin/source_list.rb +24 -0
  87. data/bundler/lib/bundler/postit_trampoline.rb +57 -0
  88. data/bundler/lib/bundler/psyched_yaml.rb +27 -0
  89. data/bundler/lib/bundler/remote_specification.rb +85 -0
  90. data/bundler/lib/bundler/resolver.rb +368 -0
  91. data/bundler/lib/bundler/retry.rb +61 -0
  92. data/bundler/lib/bundler/ruby_dsl.rb +17 -0
  93. data/bundler/lib/bundler/ruby_version.rb +140 -0
  94. data/bundler/lib/bundler/rubygems_ext.rb +178 -0
  95. data/bundler/lib/bundler/rubygems_gem_installer.rb +10 -0
  96. data/bundler/lib/bundler/rubygems_integration.rb +710 -0
  97. data/bundler/lib/bundler/runtime.rb +282 -0
  98. data/bundler/lib/bundler/settings.rb +259 -0
  99. data/bundler/lib/bundler/setup.rb +28 -0
  100. data/bundler/lib/bundler/shared_helpers.rb +212 -0
  101. data/bundler/lib/bundler/similarity_detector.rb +62 -0
  102. data/bundler/lib/bundler/source.rb +37 -0
  103. data/bundler/lib/bundler/source/gemspec.rb +13 -0
  104. data/bundler/lib/bundler/source/git.rb +297 -0
  105. data/bundler/lib/bundler/source/git/git_proxy.rb +218 -0
  106. data/bundler/lib/bundler/source/path.rb +245 -0
  107. data/bundler/lib/bundler/source/path/installer.rb +44 -0
  108. data/bundler/lib/bundler/source/rubygems.rb +450 -0
  109. data/bundler/lib/bundler/source/rubygems/remote.rb +59 -0
  110. data/bundler/lib/bundler/source_list.rb +106 -0
  111. data/bundler/lib/bundler/spec_set.rb +157 -0
  112. data/bundler/lib/bundler/ssl_certs/.document +1 -0
  113. data/bundler/lib/bundler/ssl_certs/certificate_manager.rb +65 -0
  114. data/bundler/lib/bundler/ssl_certs/index.rubygems.org/GlobalSignRootCA.pem +21 -0
  115. data/bundler/lib/bundler/ssl_certs/rubygems.global.ssl.fastly.net/DigiCertHighAssuranceEVRootCA.pem +23 -0
  116. data/{lib/rubygems/ssl_certs/rubygems.org/AddTrustExternalCARoot-2048.pem → bundler/lib/bundler/ssl_certs/rubygems.org/AddTrustExternalCARoot.pem} +0 -0
  117. data/bundler/lib/bundler/stub_specification.rb +24 -0
  118. data/bundler/lib/bundler/templates/Executable +17 -0
  119. data/bundler/lib/bundler/templates/Executable.standalone +12 -0
  120. data/bundler/lib/bundler/templates/Gemfile +5 -0
  121. data/bundler/lib/bundler/templates/newgem/.travis.yml.tt +5 -0
  122. data/bundler/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +74 -0
  123. data/bundler/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  124. data/bundler/lib/bundler/templates/newgem/LICENSE.txt.tt +21 -0
  125. data/bundler/lib/bundler/templates/newgem/README.md.tt +41 -0
  126. data/bundler/lib/bundler/templates/newgem/Rakefile.tt +29 -0
  127. data/bundler/lib/bundler/templates/newgem/bin/console.tt +14 -0
  128. data/bundler/lib/bundler/templates/newgem/bin/setup.tt +8 -0
  129. data/bundler/lib/bundler/templates/newgem/exe/newgem.tt +3 -0
  130. data/bundler/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +3 -0
  131. data/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  132. data/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  133. data/bundler/lib/bundler/templates/newgem/gitignore.tt +16 -0
  134. data/bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt +12 -0
  135. data/bundler/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  136. data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +46 -0
  137. data/bundler/lib/bundler/templates/newgem/rspec.tt +2 -0
  138. data/bundler/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +11 -0
  139. data/bundler/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +2 -0
  140. data/bundler/lib/bundler/templates/newgem/test/newgem_test.rb.tt +11 -0
  141. data/bundler/lib/bundler/templates/newgem/test/test_helper.rb.tt +4 -0
  142. data/bundler/lib/bundler/ui.rb +8 -0
  143. data/bundler/lib/bundler/ui/rg_proxy.rb +18 -0
  144. data/bundler/lib/bundler/ui/shell.rb +114 -0
  145. data/bundler/lib/bundler/ui/silent.rb +48 -0
  146. data/bundler/lib/bundler/uri_credentials_filter.rb +36 -0
  147. data/bundler/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb +79 -0
  148. data/bundler/lib/bundler/vendor/compact_index_client/lib/compact_index_client/cache.rb +98 -0
  149. data/bundler/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb +80 -0
  150. data/bundler/lib/bundler/vendor/compact_index_client/lib/compact_index_client/version.rb +4 -0
  151. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo.rb +10 -0
  152. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +50 -0
  153. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +80 -0
  154. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +203 -0
  155. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +35 -0
  156. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +58 -0
  157. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +61 -0
  158. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +53 -0
  159. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +114 -0
  160. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +45 -0
  161. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +35 -0
  162. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +123 -0
  163. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +75 -0
  164. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +5 -0
  165. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +100 -0
  166. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +65 -0
  167. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +460 -0
  168. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +45 -0
  169. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +54 -0
  170. data/bundler/lib/bundler/vendor/net/http/faster.rb +26 -0
  171. data/bundler/lib/bundler/vendor/net/http/persistent.rb +1230 -0
  172. data/bundler/lib/bundler/vendor/net/http/persistent/ssl_reuse.rb +128 -0
  173. data/bundler/lib/bundler/vendor/postit/lib/postit.rb +15 -0
  174. data/bundler/lib/bundler/vendor/postit/lib/postit/environment.rb +44 -0
  175. data/bundler/lib/bundler/vendor/postit/lib/postit/installer.rb +28 -0
  176. data/bundler/lib/bundler/vendor/postit/lib/postit/parser.rb +21 -0
  177. data/bundler/lib/bundler/vendor/postit/lib/postit/setup.rb +12 -0
  178. data/bundler/lib/bundler/vendor/postit/lib/postit/version.rb +3 -0
  179. data/bundler/lib/bundler/vendor/thor/lib/thor.rb +484 -0
  180. data/bundler/lib/bundler/vendor/thor/lib/thor/actions.rb +319 -0
  181. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  182. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +59 -0
  183. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +118 -0
  184. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
  185. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +316 -0
  186. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +107 -0
  187. data/bundler/lib/bundler/vendor/thor/lib/thor/base.rb +656 -0
  188. data/bundler/lib/bundler/vendor/thor/lib/thor/command.rb +133 -0
  189. data/bundler/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  190. data/bundler/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb +10 -0
  191. data/bundler/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb +98 -0
  192. data/bundler/lib/bundler/vendor/thor/lib/thor/error.rb +32 -0
  193. data/bundler/lib/bundler/vendor/thor/lib/thor/group.rb +281 -0
  194. data/bundler/lib/bundler/vendor/thor/lib/thor/invocation.rb +178 -0
  195. data/bundler/lib/bundler/vendor/thor/lib/thor/line_editor.rb +17 -0
  196. data/bundler/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
  197. data/bundler/lib/bundler/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  198. data/bundler/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -0
  199. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +73 -0
  200. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +175 -0
  201. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/option.rb +125 -0
  202. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/options.rb +218 -0
  203. data/bundler/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +71 -0
  204. data/bundler/lib/bundler/vendor/thor/lib/thor/runner.rb +322 -0
  205. data/bundler/lib/bundler/vendor/thor/lib/thor/shell.rb +81 -0
  206. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +421 -0
  207. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/color.rb +149 -0
  208. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/html.rb +126 -0
  209. data/bundler/lib/bundler/vendor/thor/lib/thor/util.rb +267 -0
  210. data/bundler/lib/bundler/vendor/thor/lib/thor/version.rb +3 -0
  211. data/bundler/lib/bundler/vendored_molinillo.rb +3 -0
  212. data/bundler/lib/bundler/vendored_persistent.rb +12 -0
  213. data/bundler/lib/bundler/vendored_thor.rb +4 -0
  214. data/bundler/lib/bundler/version.rb +11 -0
  215. data/bundler/lib/bundler/vlad.rb +12 -0
  216. data/bundler/lib/bundler/worker.rb +82 -0
  217. data/bundler/lib/bundler/yaml_serializer.rb +67 -0
  218. data/bundler/man/bundle-config.ronn +193 -0
  219. data/bundler/man/bundle-exec.ronn +136 -0
  220. data/bundler/man/bundle-gem.ronn +77 -0
  221. data/bundler/man/bundle-install.ronn +404 -0
  222. data/bundler/man/bundle-lock.ronn +47 -0
  223. data/bundler/man/bundle-package.ronn +67 -0
  224. data/bundler/man/bundle-platform.ronn +42 -0
  225. data/bundler/man/bundle-update.ronn +194 -0
  226. data/bundler/man/bundle.ronn +98 -0
  227. data/bundler/man/gemfile.5.ronn +499 -0
  228. data/bundler/man/index.txt +8 -0
  229. data/lib/rubygems.rb +42 -2
  230. data/lib/rubygems/config_file.rb +1 -1
  231. data/lib/rubygems/defaults.rb +18 -0
  232. data/lib/rubygems/installer.rb +1 -0
  233. data/lib/rubygems/package.rb +3 -1
  234. data/lib/rubygems/package/tar_writer.rb +10 -16
  235. data/lib/rubygems/remote_fetcher.rb +1 -15
  236. data/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/resolution_state.rb +50 -0
  237. data/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb +80 -0
  238. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb +57 -145
  239. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action.rb +35 -0
  240. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +58 -0
  241. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +61 -0
  242. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +53 -0
  243. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb +114 -0
  244. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/set_payload.rb +45 -0
  245. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/tag.rb +35 -0
  246. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb +123 -0
  247. data/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb +1 -1
  248. data/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb +1 -1
  249. data/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb +55 -54
  250. data/lib/rubygems/resolver/molinillo/lib/molinillo/state.rb +4 -2
  251. data/lib/rubygems/security/signer.rb +2 -0
  252. data/lib/rubygems/specification.rb +4 -4
  253. data/lib/rubygems/ssl_certs/index.rubygems.org/GlobalSignRootCA.pem +21 -0
  254. data/lib/rubygems/ssl_certs/rubygems.org/AddTrustExternalCARoot.pem +25 -0
  255. data/test/rubygems/alternate_cert.pem +10 -9
  256. data/test/rubygems/alternate_cert_32.pem +10 -9
  257. data/test/rubygems/child_cert.pem +11 -9
  258. data/test/rubygems/child_cert_32.pem +11 -9
  259. data/test/rubygems/encrypted_private_key.pem +26 -26
  260. data/test/rubygems/expired_cert.pem +9 -8
  261. data/test/rubygems/future_cert.pem +9 -8
  262. data/test/rubygems/future_cert_32.pem +9 -8
  263. data/test/rubygems/grandchild_cert.pem +11 -9
  264. data/test/rubygems/grandchild_cert_32.pem +11 -9
  265. data/test/rubygems/invalid_issuer_cert.pem +11 -9
  266. data/test/rubygems/invalid_issuer_cert_32.pem +11 -9
  267. data/test/rubygems/invalid_signer_cert.pem +10 -9
  268. data/test/rubygems/invalid_signer_cert_32.pem +10 -9
  269. data/test/rubygems/invalidchild_cert.pem +11 -9
  270. data/test/rubygems/invalidchild_cert_32.pem +11 -9
  271. data/test/rubygems/public_cert.pem +11 -9
  272. data/test/rubygems/public_cert_32.pem +10 -9
  273. data/test/rubygems/test_bundled_ca.rb +1 -1
  274. data/test/rubygems/test_gem.rb +7 -0
  275. data/test/rubygems/test_gem_installer.rb +119 -0
  276. data/test/rubygems/test_gem_package.rb +9 -3
  277. data/test/rubygems/test_gem_package_tar_writer.rb +24 -0
  278. data/test/rubygems/test_gem_remote_fetcher.rb +0 -12
  279. data/test/rubygems/test_gem_security_signer.rb +8 -0
  280. data/test/rubygems/test_gem_specification.rb +1 -1
  281. data/test/rubygems/wrong_key_cert.pem +10 -9
  282. data/test/rubygems/wrong_key_cert_32.pem +10 -9
  283. data/util/ci +73 -0
  284. data/util/create_certs.rb +64 -49
  285. data/util/update_bundled_ca_certificates.rb +23 -2
  286. metadata +257 -19
  287. data/lib/gauntlet_rubygems.rb +0 -51
  288. data/lib/rubygems/ssl_certs/index.rubygems.org/GlobalSignRoot.pem +0 -18
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ module Bundler
3
+ # General purpose class for retrying code that may fail
4
+ class Retry
5
+ attr_accessor :name, :total_runs, :current_run
6
+
7
+ class << self
8
+ def default_attempts
9
+ default_retries + 1
10
+ end
11
+ alias_method :attempts, :default_attempts
12
+
13
+ def default_retries
14
+ Bundler.settings[:retry]
15
+ end
16
+ end
17
+
18
+ def initialize(name, exceptions = nil, retries = self.class.default_retries)
19
+ @name = name
20
+ @retries = retries
21
+ @exceptions = Array(exceptions) || []
22
+ @total_runs = @retries + 1 # will run once, then upto attempts.times
23
+ end
24
+
25
+ def attempt(&block)
26
+ @current_run = 0
27
+ @failed = false
28
+ @error = nil
29
+ run(&block) while keep_trying?
30
+ @result
31
+ end
32
+ alias_method :attempts, :attempt
33
+
34
+ private
35
+
36
+ def run(&block)
37
+ @failed = false
38
+ @current_run += 1
39
+ @result = block.call
40
+ rescue => e
41
+ fail_attempt(e)
42
+ end
43
+
44
+ def fail_attempt(e)
45
+ @failed = true
46
+ raise e if last_attempt? || @exceptions.any? {|k| e.is_a?(k) }
47
+ return true unless name
48
+ Bundler.ui.warn "Retrying#{" #{name}" if name} due to error (#{current_run.next}/#{total_runs}): #{e.class} #{e.message}"
49
+ end
50
+
51
+ def keep_trying?
52
+ return true if current_run.zero?
53
+ return false if last_attempt?
54
+ return true if @failed
55
+ end
56
+
57
+ def last_attempt?
58
+ current_run >= total_runs
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module Bundler
3
+ module RubyDsl
4
+ def ruby(*ruby_version)
5
+ options = ruby_version.last.is_a?(Hash) ? ruby_version.pop : {}
6
+ ruby_version.flatten!
7
+ raise GemfileError, "Please define :engine_version" if options[:engine] && options[:engine_version].nil?
8
+ raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil?
9
+
10
+ if options[:engine] == "ruby" && options[:engine_version] &&
11
+ ruby_version != Array(options[:engine_version])
12
+ raise GemfileEvalError, "ruby_version must match the :engine_version for MRI"
13
+ end
14
+ @ruby_version = RubyVersion.new(ruby_version, options[:patchlevel], options[:engine], options[:engine_version])
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+ module Bundler
3
+ class RubyVersion
4
+ attr_reader :versions,
5
+ :patchlevel,
6
+ :engine,
7
+ :engine_versions,
8
+ :gem_version,
9
+ :engine_gem_version
10
+
11
+ def initialize(versions, patchlevel, engine, engine_version)
12
+ # The parameters to this method must satisfy the
13
+ # following constraints, which are verified in
14
+ # the DSL:
15
+ #
16
+ # * If an engine is specified, an engine version
17
+ # must also be specified
18
+ # * If an engine version is specified, an engine
19
+ # must also be specified
20
+ # * If the engine is "ruby", the engine version
21
+ # must not be specified, or the engine version
22
+ # specified must match the version.
23
+
24
+ @versions = Array(versions)
25
+ @gem_version = Gem::Requirement.create(@versions.first).requirements.first.last
26
+ @input_engine = engine
27
+ @engine = engine || "ruby"
28
+ @engine_versions = (engine_version && Array(engine_version)) || @versions
29
+ @engine_gem_version = Gem::Requirement.create(@engine_versions.first).requirements.first.last
30
+ @patchlevel = patchlevel
31
+ end
32
+
33
+ def to_s(versions = self.versions)
34
+ output = String.new("ruby #{versions_string(versions)}")
35
+ output << "p#{patchlevel}" if patchlevel
36
+ output << " (#{engine} #{versions_string(engine_versions)})" unless engine == "ruby"
37
+
38
+ output
39
+ end
40
+
41
+ # @private
42
+ PATTERN = /
43
+ ruby\s
44
+ ([\d.]+) # ruby version
45
+ (?:p(\d+))? # optional patchlevel
46
+ (?:\s\((\S+)\s(.+)\))? # optional engine info
47
+ /xo
48
+
49
+ # Returns a RubyVersion from the given string.
50
+ # @param [String] the version string to match.
51
+ # @return [RubyVersion,Nil] The version if the string is a valid RubyVersion
52
+ # description, and nil otherwise.
53
+ def self.from_string(string)
54
+ new($1, $2, $3, $4) if string =~ PATTERN
55
+ end
56
+
57
+ def single_version_string
58
+ to_s(gem_version)
59
+ end
60
+
61
+ def ==(other)
62
+ versions == other.versions &&
63
+ engine == other.engine &&
64
+ engine_versions == other.engine_versions &&
65
+ patchlevel == other.patchlevel
66
+ end
67
+
68
+ def host
69
+ @host ||= [
70
+ RbConfig::CONFIG["host_cpu"],
71
+ RbConfig::CONFIG["host_vendor"],
72
+ RbConfig::CONFIG["host_os"]
73
+ ].join("-")
74
+ end
75
+
76
+ # Returns a tuple of these things:
77
+ # [diff, this, other]
78
+ # The priority of attributes are
79
+ # 1. engine
80
+ # 2. ruby_version
81
+ # 3. engine_version
82
+ def diff(other)
83
+ raise ArgumentError, "Can only diff with a RubyVersion, not a #{other.class}" unless other.is_a?(RubyVersion)
84
+ if engine != other.engine && @input_engine
85
+ [:engine, engine, other.engine]
86
+ elsif versions.empty? || !matches?(versions, other.gem_version)
87
+ [:version, versions_string(versions), versions_string(other.versions)]
88
+ elsif @input_engine && !matches?(engine_versions, other.engine_gem_version)
89
+ [:engine_version, versions_string(engine_versions), versions_string(other.engine_versions)]
90
+ elsif patchlevel && (!patchlevel.is_a?(String) || !other.patchlevel.is_a?(String) || !matches?(patchlevel, other.patchlevel))
91
+ [:patchlevel, patchlevel, other.patchlevel]
92
+ end
93
+ end
94
+
95
+ def versions_string(versions)
96
+ Array(versions).join(", ")
97
+ end
98
+
99
+ def self.system
100
+ ruby_engine = if defined?(RUBY_ENGINE) && !RUBY_ENGINE.nil?
101
+ RUBY_ENGINE.dup
102
+ else
103
+ # not defined in ruby 1.8.7
104
+ "ruby"
105
+ end
106
+ # :sob: mocking RUBY_VERSION breaks stuff on 1.8.7
107
+ ruby_version = ENV.fetch("BUNDLER_SPEC_RUBY_VERSION") { RUBY_VERSION }.dup
108
+ ruby_engine_version = case ruby_engine
109
+ when "ruby"
110
+ ruby_version
111
+ when "rbx"
112
+ Rubinius::VERSION.dup
113
+ when "jruby"
114
+ JRUBY_VERSION.dup
115
+ else
116
+ raise BundlerError, "RUBY_ENGINE value #{RUBY_ENGINE} is not recognized"
117
+ end
118
+ @ruby_version ||= RubyVersion.new(ruby_version, RUBY_PATCHLEVEL.to_s, ruby_engine, ruby_engine_version)
119
+ end
120
+
121
+ def to_gem_version_with_patchlevel
122
+ @gem_version_with_patch ||= begin
123
+ Gem::Version.create("#{@gem_version}.#{@patchlevel}")
124
+ rescue ArgumentError
125
+ @gem_version
126
+ end
127
+ end
128
+
129
+ private
130
+
131
+ def matches?(requirements, version)
132
+ # Handles RUBY_PATCHLEVEL of -1 for instances like ruby-head
133
+ return requirements == version if requirements.to_s == "-1" || version.to_s == "-1"
134
+
135
+ Array(requirements).all? do |requirement|
136
+ Gem::Requirement.create(requirement).satisfied_by?(Gem::Version.create(version))
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+ require "pathname"
3
+
4
+ if defined?(Gem::QuickLoader)
5
+ # Gem Prelude makes me a sad panda :'(
6
+ Gem::QuickLoader.load_full_rubygems_library
7
+ end
8
+
9
+ require "rubygems"
10
+ require "rubygems/specification"
11
+ require "bundler/match_platform"
12
+
13
+ module Gem
14
+ @loaded_stacks = Hash.new {|h, k| h[k] = [] }
15
+
16
+ class Specification
17
+ attr_accessor :remote, :location, :relative_loaded_from
18
+
19
+ remove_method :source if instance_methods(false).include?(:source)
20
+ attr_accessor :source
21
+
22
+ alias_method :rg_full_gem_path, :full_gem_path
23
+ alias_method :rg_loaded_from, :loaded_from
24
+
25
+ attr_writer :full_gem_path unless instance_methods.include?(:full_gem_path=)
26
+
27
+ def full_gem_path
28
+ if source.respond_to?(:path)
29
+ Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.untaint
30
+ else
31
+ rg_full_gem_path
32
+ end
33
+ end
34
+
35
+ def loaded_from
36
+ if relative_loaded_from
37
+ source.path.join(relative_loaded_from).to_s
38
+ else
39
+ rg_loaded_from
40
+ end
41
+ end
42
+
43
+ def load_paths
44
+ return full_require_paths if respond_to?(:full_require_paths)
45
+
46
+ require_paths.map do |require_path|
47
+ if require_path.include?(full_gem_path)
48
+ require_path
49
+ else
50
+ File.join(full_gem_path, require_path)
51
+ end
52
+ end
53
+ end
54
+
55
+ if method_defined?(:extension_dir)
56
+ alias_method :rg_extension_dir, :extension_dir
57
+ def extension_dir
58
+ @bundler_extension_dir ||= if source.respond_to?(:extension_dir_name)
59
+ File.expand_path(File.join(extensions_dir, source.extension_dir_name))
60
+ else
61
+ rg_extension_dir
62
+ end
63
+ end
64
+ end
65
+
66
+ # RubyGems 1.8+ used only.
67
+ methods = instance_methods(false)
68
+ gem_dir = methods.first.is_a?(String) ? "gem_dir" : :gem_dir
69
+ remove_method :gem_dir if methods.include?(gem_dir)
70
+ def gem_dir
71
+ full_gem_path
72
+ end
73
+
74
+ def groups
75
+ @groups ||= []
76
+ end
77
+
78
+ def git_version
79
+ return unless loaded_from && source.is_a?(Bundler::Source::Git)
80
+ " #{source.revision[0..6]}"
81
+ end
82
+
83
+ def to_gemfile(path = nil)
84
+ gemfile = String.new("source 'https://rubygems.org'\n")
85
+ gemfile << dependencies_to_gemfile(nondevelopment_dependencies)
86
+ unless development_dependencies.empty?
87
+ gemfile << "\n"
88
+ gemfile << dependencies_to_gemfile(development_dependencies, :development)
89
+ end
90
+ gemfile
91
+ end
92
+
93
+ def nondevelopment_dependencies
94
+ dependencies - development_dependencies
95
+ end
96
+
97
+ private
98
+
99
+ def dependencies_to_gemfile(dependencies, group = nil)
100
+ gemfile = String.new
101
+ if dependencies.any?
102
+ gemfile << "group :#{group} do\n" if group
103
+ dependencies.each do |dependency|
104
+ gemfile << " " if group
105
+ gemfile << %(gem "#{dependency.name}")
106
+ req = dependency.requirements_list.first
107
+ gemfile << %(, "#{req}") if req
108
+ gemfile << "\n"
109
+ end
110
+ gemfile << "end\n" if group
111
+ end
112
+ gemfile
113
+ end
114
+ end
115
+
116
+ class Dependency
117
+ attr_accessor :source, :groups
118
+
119
+ alias_method :eql?, :==
120
+
121
+ def encode_with(coder)
122
+ to_yaml_properties.each do |ivar|
123
+ coder[ivar.to_s.sub(/^@/, "")] = instance_variable_get(ivar)
124
+ end
125
+ end
126
+
127
+ def to_yaml_properties
128
+ instance_variables.reject {|p| ["@source", "@groups"].include?(p.to_s) }
129
+ end
130
+
131
+ def to_lock
132
+ out = String.new(" #{name}")
133
+ unless requirement == Gem::Requirement.default
134
+ reqs = requirement.requirements.map {|o, v| "#{o} #{v}" }.sort.reverse
135
+ out << " (#{reqs.join(", ")})"
136
+ end
137
+ out
138
+ end
139
+
140
+ # Backport of performance enhancement added to Rubygems 1.4
141
+ def matches_spec?(spec)
142
+ # name can be a Regexp, so use ===
143
+ return false unless name === spec.name
144
+ return true if requirement.none?
145
+
146
+ requirement.satisfied_by?(spec.version)
147
+ end unless allocate.respond_to?(:matches_spec?)
148
+ end
149
+
150
+ class Requirement
151
+ # Backport of performance enhancement added to Rubygems 1.4
152
+ def none?
153
+ @none ||= (to_s == ">= 0")
154
+ end unless allocate.respond_to?(:none?)
155
+ end
156
+
157
+ class Platform
158
+ JAVA = Gem::Platform.new("java") unless defined?(JAVA)
159
+ MSWIN = Gem::Platform.new("mswin32") unless defined?(MSWIN)
160
+ MSWIN64 = Gem::Platform.new("mswin64") unless defined?(MSWIN64)
161
+ MINGW = Gem::Platform.new("x86-mingw32") unless defined?(MINGW)
162
+ X64_MINGW = Gem::Platform.new("x64-mingw32") unless defined?(X64_MINGW)
163
+
164
+ undef_method :hash if method_defined? :hash
165
+ def hash
166
+ @cpu.hash ^ @os.hash ^ @version.hash
167
+ end
168
+
169
+ undef_method :eql? if method_defined? :eql?
170
+ alias_method :eql?, :==
171
+ end
172
+ end
173
+
174
+ module Gem
175
+ class Specification
176
+ include ::Bundler::MatchPlatform
177
+ end
178
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ require "rubygems/installer"
3
+
4
+ module Bundler
5
+ class RubyGemsGemInstaller < Gem::Installer
6
+ def check_executable_overwrite(filename)
7
+ # Bundler needs to install gems regardless of binstub overwriting
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,710 @@
1
+ # frozen_string_literal: true
2
+ require "monitor"
3
+ require "rubygems"
4
+ require "rubygems/config_file"
5
+
6
+ module Bundler
7
+ class RubygemsIntegration
8
+ if defined?(Gem::Ext::Builder::CHDIR_MONITOR)
9
+ EXT_LOCK = Gem::Ext::Builder::CHDIR_MONITOR
10
+ else
11
+ EXT_LOCK = Monitor.new
12
+ end
13
+
14
+ def self.version
15
+ @version ||= Gem::Version.new(Gem::VERSION)
16
+ end
17
+
18
+ def self.provides?(req_str)
19
+ Gem::Requirement.new(req_str).satisfied_by?(version)
20
+ end
21
+
22
+ def version
23
+ self.class.version
24
+ end
25
+
26
+ def provides?(req_str)
27
+ self.class.provides?(req_str)
28
+ end
29
+
30
+ def build_args
31
+ Gem::Command.build_args
32
+ end
33
+
34
+ def build_args=(args)
35
+ Gem::Command.build_args = args
36
+ end
37
+
38
+ def load_path_insert_index
39
+ Gem.load_path_insert_index
40
+ end
41
+
42
+ def loaded_specs(name)
43
+ Gem.loaded_specs[name]
44
+ end
45
+
46
+ def mark_loaded(spec)
47
+ if spec.respond_to?(:activated=)
48
+ current = Gem.loaded_specs[spec.name]
49
+ current.activated = false if current
50
+ spec.activated = true
51
+ end
52
+ Gem.loaded_specs[spec.name] = spec
53
+ end
54
+
55
+ def validate(spec)
56
+ Bundler.ui.silence { spec.validate(false) }
57
+ rescue Gem::InvalidSpecificationException => e
58
+ error_message = "The gemspec at #{spec.loaded_from} is not valid. Please fix this gemspec.\n" \
59
+ "The validation error was '#{e.message}'\n"
60
+ raise Gem::InvalidSpecificationException.new(error_message)
61
+ rescue Errno::ENOENT
62
+ nil
63
+ end
64
+
65
+ def set_installed_by_version(spec, installed_by_version = Gem::VERSION)
66
+ return unless spec.respond_to?(:installed_by_version=)
67
+ spec.installed_by_version = Gem::Version.create(installed_by_version)
68
+ end
69
+
70
+ def spec_missing_extensions?(spec)
71
+ !spec.respond_to?(:missing_extensions?) || spec.missing_extensions?
72
+ end
73
+
74
+ def path(obj)
75
+ obj.to_s
76
+ end
77
+
78
+ def platforms
79
+ Gem.platforms
80
+ end
81
+
82
+ def configuration
83
+ require "bundler/psyched_yaml"
84
+ Gem.configuration
85
+ rescue Gem::SystemExitException, LoadError => e
86
+ Bundler.ui.error "#{e.class}: #{e.message}"
87
+ Bundler.ui.trace e
88
+ raise
89
+ rescue YamlLibrarySyntaxError => e
90
+ raise YamlSyntaxError.new(e, "Your RubyGems configuration, which is " \
91
+ "usually located in ~/.gemrc, contains invalid YAML syntax.")
92
+ end
93
+
94
+ def ruby_engine
95
+ Gem.ruby_engine
96
+ end
97
+
98
+ def read_binary(path)
99
+ Gem.read_binary(path)
100
+ end
101
+
102
+ def inflate(obj)
103
+ Gem.inflate(obj)
104
+ end
105
+
106
+ def sources=(val)
107
+ # Gem.configuration creates a new Gem::ConfigFile, which by default will read ~/.gemrc
108
+ # If that file exists, its settings (including sources) will overwrite the values we
109
+ # are about to set here. In order to avoid that, we force memoizing the config file now.
110
+ configuration
111
+
112
+ Gem.sources = val
113
+ end
114
+
115
+ def sources
116
+ Gem.sources
117
+ end
118
+
119
+ def gem_dir
120
+ Gem.dir
121
+ end
122
+
123
+ def gem_bindir
124
+ Gem.bindir
125
+ end
126
+
127
+ def user_home
128
+ Gem.user_home
129
+ end
130
+
131
+ def gem_path
132
+ Gem.path
133
+ end
134
+
135
+ def gem_cache
136
+ gem_path.map {|p| File.expand_path("cache", p) }
137
+ end
138
+
139
+ def spec_cache_dirs
140
+ @spec_cache_dirs ||= begin
141
+ dirs = gem_path.map {|dir| File.join(dir, "specifications") }
142
+ dirs << Gem.spec_cache_dir if Gem.respond_to?(:spec_cache_dir) # Not in Rubygems 2.0.3 or earlier
143
+ dirs.uniq.select {|dir| File.directory? dir }
144
+ end
145
+ end
146
+
147
+ def marshal_spec_dir
148
+ Gem::MARSHAL_SPEC_DIR
149
+ end
150
+
151
+ def config_map
152
+ Gem::ConfigMap
153
+ end
154
+
155
+ def repository_subdirectories
156
+ %w(cache doc gems specifications)
157
+ end
158
+
159
+ def clear_paths
160
+ Gem.clear_paths
161
+ end
162
+
163
+ def bin_path(gem, bin, ver)
164
+ Gem.bin_path(gem, bin, ver)
165
+ end
166
+
167
+ def preserve_paths
168
+ # this is a no-op outside of Rubygems 1.8
169
+ yield
170
+ end
171
+
172
+ def loaded_gem_paths
173
+ # RubyGems 2.2+ can put binary extension into dedicated folders,
174
+ # therefore use RubyGems facilities to obtain their load paths.
175
+ if Gem::Specification.method_defined? :full_require_paths
176
+ loaded_gem_paths = Gem.loaded_specs.map {|_, s| s.full_require_paths }
177
+ loaded_gem_paths.flatten
178
+ else
179
+ $LOAD_PATH.select do |p|
180
+ Bundler.rubygems.gem_path.any? {|gp| p =~ /^#{Regexp.escape(gp)}/ }
181
+ end
182
+ end
183
+ end
184
+
185
+ def ui=(obj)
186
+ Gem::DefaultUserInteraction.ui = obj
187
+ end
188
+
189
+ def ext_lock
190
+ EXT_LOCK
191
+ end
192
+
193
+ def fetch_specs(all, pre, &blk)
194
+ specs = Gem::SpecFetcher.new.list(all, pre)
195
+ specs.each { yield } if block_given?
196
+ specs
197
+ end
198
+
199
+ def fetch_prerelease_specs
200
+ fetch_specs(false, true)
201
+ rescue Gem::RemoteFetcher::FetchError
202
+ {} # if we can't download them, there aren't any
203
+ end
204
+
205
+ # TODO: This is for older versions of Rubygems... should we support the
206
+ # X-Gemfile-Source header on these old versions?
207
+ # Maybe the newer implementation will work on older Rubygems?
208
+ # It seems difficult to keep this implementation and still send the header.
209
+ def fetch_all_remote_specs(remote)
210
+ old_sources = Bundler.rubygems.sources
211
+ Bundler.rubygems.sources = [remote.uri.to_s]
212
+ # Fetch all specs, minus prerelease specs
213
+ spec_list = fetch_specs(true, false)
214
+ # Then fetch the prerelease specs
215
+ fetch_prerelease_specs.each {|k, v| spec_list[k].concat(v) }
216
+
217
+ spec_list.values.first
218
+ ensure
219
+ Bundler.rubygems.sources = old_sources
220
+ end
221
+
222
+ def with_build_args(args)
223
+ ext_lock.synchronize do
224
+ old_args = build_args
225
+ begin
226
+ self.build_args = args
227
+ yield
228
+ ensure
229
+ self.build_args = old_args
230
+ end
231
+ end
232
+ end
233
+
234
+ def gem_from_path(path, policy = nil)
235
+ require "rubygems/format"
236
+ Gem::Format.from_file_by_path(path, policy)
237
+ end
238
+
239
+ def spec_from_gem(path, policy = nil)
240
+ require "rubygems/security"
241
+ gem_from_path(path, security_policies[policy]).spec
242
+ rescue Gem::Package::FormatError
243
+ raise GemspecError, "Could not read gem at #{path}. It may be corrupted."
244
+ rescue Exception, Gem::Exception, Gem::Security::Exception => e
245
+ if e.is_a?(Gem::Security::Exception) ||
246
+ e.message =~ /unknown trust policy|unsigned gem/i ||
247
+ e.message =~ /couldn't verify (meta)?data signature/i
248
+ raise SecurityError,
249
+ "The gem #{File.basename(path, ".gem")} can't be installed because " \
250
+ "the security policy didn't allow it, with the message: #{e.message}"
251
+ else
252
+ raise e
253
+ end
254
+ end
255
+
256
+ def build(spec, skip_validation = false)
257
+ require "rubygems/builder"
258
+ Gem::Builder.new(spec).build
259
+ end
260
+
261
+ def build_gem(gem_dir, spec)
262
+ build(spec)
263
+ end
264
+
265
+ def download_gem(spec, uri, path)
266
+ uri = Bundler.settings.mirror_for(uri)
267
+ fetcher = Gem::RemoteFetcher.new(configuration[:http_proxy])
268
+ fetcher.download(spec, uri, path)
269
+ end
270
+
271
+ def security_policy_keys
272
+ %w(High Medium Low AlmostNo No).map {|level| "#{level}Security" }
273
+ end
274
+
275
+ def security_policies
276
+ @security_policies ||= begin
277
+ require "rubygems/security"
278
+ Gem::Security::Policies
279
+ rescue LoadError, NameError
280
+ {}
281
+ end
282
+ end
283
+
284
+ def reverse_rubygems_kernel_mixin
285
+ # Disable rubygems' gem activation system
286
+ ::Kernel.class_eval do
287
+ if private_method_defined?(:gem_original_require)
288
+ alias_method :rubygems_require, :require
289
+ alias_method :require, :gem_original_require
290
+ end
291
+
292
+ undef gem
293
+ end
294
+ end
295
+
296
+ def replace_gem(specs)
297
+ reverse_rubygems_kernel_mixin
298
+
299
+ executables = specs.map(&:executables).flatten
300
+
301
+ ::Kernel.send(:define_method, :gem) do |dep, *reqs|
302
+ if executables.include? File.basename(caller.first.split(":").first)
303
+ break
304
+ end
305
+ reqs.pop if reqs.last.is_a?(Hash)
306
+
307
+ unless dep.respond_to?(:name) && dep.respond_to?(:requirement)
308
+ dep = Gem::Dependency.new(dep, reqs)
309
+ end
310
+
311
+ spec = specs.find {|s| s.name == dep.name }
312
+
313
+ if spec.nil?
314
+
315
+ e = Gem::LoadError.new "#{dep.name} is not part of the bundle. Add it to Gemfile."
316
+ e.name = dep.name
317
+ if e.respond_to?(:requirement=)
318
+ e.requirement = dep.requirement
319
+ else
320
+ e.version_requirement = dep.requirement
321
+ end
322
+ raise e
323
+ elsif dep !~ spec
324
+ e = Gem::LoadError.new "can't activate #{dep}, already activated #{spec.full_name}. " \
325
+ "Make sure all dependencies are added to Gemfile."
326
+ e.name = dep.name
327
+ if e.respond_to?(:requirement=)
328
+ e.requirement = dep.requirement
329
+ else
330
+ e.version_requirement = dep.requirement
331
+ end
332
+ raise e
333
+ end
334
+
335
+ true
336
+ end
337
+ end
338
+
339
+ def stub_source_index(specs)
340
+ Gem::SourceIndex.send(:alias_method, :old_initialize, :initialize)
341
+ redefine_method(Gem::SourceIndex, :initialize) do |*args|
342
+ @gems = {}
343
+ # You're looking at this thinking: Oh! This is how I make those
344
+ # rubygems deprecations go away!
345
+ #
346
+ # You'd be correct BUT using of this method in production code
347
+ # must be approved by the rubygems team itself!
348
+ #
349
+ # This is your warning. If you use this and don't have approval
350
+ # we can't protect you.
351
+ #
352
+ Deprecate.skip_during do
353
+ self.spec_dirs = *args
354
+ add_specs(*specs)
355
+ end
356
+ end
357
+ end
358
+
359
+ # Used to make bin stubs that are not created by bundler work
360
+ # under bundler. The new Gem.bin_path only considers gems in
361
+ # +specs+
362
+ def replace_bin_path(specs)
363
+ gem_class = (class << Gem; self; end)
364
+
365
+ redefine_method(gem_class, :find_spec_for_exe) do |name, *args|
366
+ exec_name = args.first
367
+
368
+ spec = if exec_name
369
+ specs.find {|s| s.executables.include?(exec_name) }
370
+ else
371
+ specs.find {|s| s.name == name }
372
+ end
373
+ raise(Gem::Exception, "can't find executable #{exec_name}") unless spec
374
+ raise Gem::Exception, "no default executable for #{spec.full_name}" unless exec_name ||= spec.default_executable
375
+ unless spec.name == name
376
+ warn "Bundler is using a binstub that was created for a different gem.\n" \
377
+ "This is deprecated, in future versions you may need to `bundle binstub #{name}` " \
378
+ "to work around a system/bundle conflict."
379
+ end
380
+ spec
381
+ end
382
+
383
+ redefine_method(gem_class, :bin_path) do |name, *args|
384
+ exec_name = args.first
385
+ return ENV["BUNDLE_BIN_PATH"] if exec_name == "bundle"
386
+
387
+ spec = find_spec_for_exe(name, *args)
388
+ exec_name ||= spec.default_executable
389
+
390
+ gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name)
391
+ gem_from_path_bin = File.join(File.dirname(spec.loaded_from), spec.bindir, exec_name)
392
+ File.exist?(gem_bin) ? gem_bin : gem_from_path_bin
393
+ end
394
+ end
395
+
396
+ # Because Bundler has a static view of what specs are available,
397
+ # we don't #refresh, so stub it out.
398
+ def replace_refresh
399
+ gem_class = (class << Gem; self; end)
400
+ redefine_method(gem_class, :refresh) {}
401
+ end
402
+
403
+ # Replace or hook into Rubygems to provide a bundlerized view
404
+ # of the world.
405
+ def replace_entrypoints(specs)
406
+ replace_gem(specs)
407
+
408
+ stub_rubygems(specs)
409
+
410
+ replace_bin_path(specs)
411
+ replace_refresh
412
+
413
+ Gem.clear_paths
414
+ end
415
+
416
+ # This backports the correct segment generation code from Rubygems 1.4+
417
+ # by monkeypatching it into the method in Rubygems 1.3.6 and 1.3.7.
418
+ def backport_segment_generation
419
+ redefine_method(Gem::Version, :segments) do
420
+ @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s|
421
+ /^\d+$/ =~ s ? s.to_i : s
422
+ end
423
+ end
424
+ end
425
+
426
+ # This backport fixes the marshaling of @segments.
427
+ def backport_yaml_initialize
428
+ redefine_method(Gem::Version, :yaml_initialize) do |_, map|
429
+ @version = map["version"]
430
+ @segments = nil
431
+ @hash = nil
432
+ end
433
+ end
434
+
435
+ # This backports base_dir which replaces installation path
436
+ # Rubygems 1.8+
437
+ def backport_base_dir
438
+ redefine_method(Gem::Specification, :base_dir) do
439
+ return Gem.dir unless loaded_from
440
+ File.dirname File.dirname loaded_from
441
+ end
442
+ end
443
+
444
+ def backport_cache_file
445
+ redefine_method(Gem::Specification, :cache_dir) do
446
+ @cache_dir ||= File.join base_dir, "cache"
447
+ end
448
+
449
+ redefine_method(Gem::Specification, :cache_file) do
450
+ @cache_file ||= File.join cache_dir, "#{full_name}.gem"
451
+ end
452
+ end
453
+
454
+ def backport_spec_file
455
+ redefine_method(Gem::Specification, :spec_dir) do
456
+ @spec_dir ||= File.join base_dir, "specifications"
457
+ end
458
+
459
+ redefine_method(Gem::Specification, :spec_file) do
460
+ @spec_file ||= File.join spec_dir, "#{full_name}.gemspec"
461
+ end
462
+ end
463
+
464
+ def redefine_method(klass, method, &block)
465
+ begin
466
+ if klass.instance_method(method) && method != :initialize
467
+ # doing this to ensure we also get private methods
468
+ klass.send(:remove_method, method)
469
+ end
470
+ rescue NameError
471
+ # method isn't defined
472
+ nil
473
+ end
474
+ klass.send(:define_method, method, &block)
475
+ end
476
+
477
+ # Rubygems 1.4 through 1.6
478
+ class Legacy < RubygemsIntegration
479
+ def initialize
480
+ super
481
+ backport_base_dir
482
+ backport_cache_file
483
+ backport_spec_file
484
+ backport_yaml_initialize
485
+ end
486
+
487
+ def stub_rubygems(specs)
488
+ # Rubygems versions lower than 1.7 use SourceIndex#from_gems_in
489
+ source_index_class = (class << Gem::SourceIndex; self; end)
490
+ source_index_class.send(:define_method, :from_gems_in) do |*args|
491
+ source_index = Gem::SourceIndex.new
492
+ source_index.spec_dirs = *args
493
+ source_index.add_specs(*specs)
494
+ source_index
495
+ end
496
+ end
497
+
498
+ def all_specs
499
+ Gem.source_index.gems.values
500
+ end
501
+
502
+ def find_name(name)
503
+ Gem.source_index.find_name(name)
504
+ end
505
+
506
+ def validate(spec)
507
+ # These versions of RubyGems always validate in "packaging" mode,
508
+ # which is too strict for the kinds of checks we care about. As a
509
+ # result, validation is disabled on versions of RubyGems below 1.7.
510
+ end
511
+ end
512
+
513
+ # Rubygems versions 1.3.6 and 1.3.7
514
+ class Ancient < Legacy
515
+ def initialize
516
+ super
517
+ backport_segment_generation
518
+ end
519
+ end
520
+
521
+ # Rubygems 1.7
522
+ class Transitional < Legacy
523
+ def stub_rubygems(specs)
524
+ stub_source_index(specs)
525
+ end
526
+
527
+ def validate(spec)
528
+ # Missing summary is downgraded to a warning in later versions,
529
+ # so we set it to an empty string to prevent an exception here.
530
+ spec.summary ||= ""
531
+ RubygemsIntegration.instance_method(:validate).bind(self).call(spec)
532
+ end
533
+ end
534
+
535
+ # Rubygems 1.8.5-1.8.19
536
+ class Modern < RubygemsIntegration
537
+ def stub_rubygems(specs)
538
+ Gem::Specification.all = specs
539
+
540
+ Gem.post_reset do
541
+ Gem::Specification.all = specs
542
+ end
543
+
544
+ stub_source_index(specs)
545
+ end
546
+
547
+ def all_specs
548
+ Gem::Specification.to_a
549
+ end
550
+
551
+ def find_name(name)
552
+ Gem::Specification.find_all_by_name name
553
+ end
554
+ end
555
+
556
+ # Rubygems 1.8.0 to 1.8.4
557
+ class AlmostModern < Modern
558
+ # Rubygems [>= 1.8.0, < 1.8.5] has a bug that changes Gem.dir whenever
559
+ # you call Gem::Installer#install with an :install_dir set. We have to
560
+ # change it back for our sudo mode to work.
561
+ def preserve_paths
562
+ old_dir = gem_dir
563
+ old_path = gem_path
564
+ yield
565
+ Gem.use_paths(old_dir, old_path)
566
+ end
567
+ end
568
+
569
+ # Rubygems 1.8.20+
570
+ class MoreModern < Modern
571
+ # Rubygems 1.8.20 and adds the skip_validation parameter, so that's
572
+ # when we start passing it through.
573
+ def build(spec, skip_validation = false)
574
+ require "rubygems/builder"
575
+ Gem::Builder.new(spec).build(skip_validation)
576
+ end
577
+ end
578
+
579
+ # Rubygems 2.0
580
+ class Future < RubygemsIntegration
581
+ def stub_rubygems(specs)
582
+ Gem::Specification.all = specs
583
+
584
+ Gem.post_reset do
585
+ Gem::Specification.all = specs
586
+ end
587
+ end
588
+
589
+ def all_specs
590
+ Gem::Specification.to_a
591
+ end
592
+
593
+ def find_name(name)
594
+ Gem::Specification.find_all_by_name name
595
+ end
596
+
597
+ def fetch_specs(source, remote, name)
598
+ path = source + "#{name}.#{Gem.marshal_version}.gz"
599
+ fetcher = gem_remote_fetcher
600
+ fetcher.headers = { "X-Gemfile-Source" => remote.original_uri.to_s } if remote.original_uri
601
+ string = fetcher.fetch_path(path)
602
+ Bundler.load_marshal(string)
603
+ rescue Gem::RemoteFetcher::FetchError => e
604
+ # it's okay for prerelease to fail
605
+ raise e unless name == "prerelease_specs"
606
+ end
607
+
608
+ def fetch_all_remote_specs(remote)
609
+ source = remote.uri.is_a?(URI) ? remote.uri : URI.parse(source.to_s)
610
+
611
+ specs = fetch_specs(source, remote, "specs")
612
+ pres = fetch_specs(source, remote, "prerelease_specs") || []
613
+
614
+ specs.concat(pres)
615
+ end
616
+
617
+ def download_gem(spec, uri, path)
618
+ uri = Bundler.settings.mirror_for(uri)
619
+ fetcher = gem_remote_fetcher
620
+ fetcher.headers = { "X-Gemfile-Source" => spec.remote.original_uri.to_s } if spec.remote.original_uri
621
+ fetcher.download(spec, uri, path)
622
+ end
623
+
624
+ def gem_remote_fetcher
625
+ require "resolv"
626
+ proxy = configuration[:http_proxy]
627
+ dns = Resolv::DNS.new
628
+ Bundler::GemRemoteFetcher.new(proxy, dns)
629
+ end
630
+
631
+ def gem_from_path(path, policy = nil)
632
+ require "rubygems/package"
633
+ p = Gem::Package.new(path)
634
+ p.security_policy = policy if policy
635
+ p
636
+ end
637
+
638
+ def build(spec, skip_validation = false)
639
+ require "rubygems/package"
640
+ Gem::Package.build(spec, skip_validation)
641
+ end
642
+
643
+ def repository_subdirectories
644
+ Gem::REPOSITORY_SUBDIRECTORIES
645
+ end
646
+ end
647
+
648
+ # RubyGems 2.1.0
649
+ class MoreFuture < Future
650
+ def initialize
651
+ super
652
+ backport_ext_builder_monitor
653
+ end
654
+
655
+ def all_specs
656
+ require "bundler/remote_specification"
657
+ Gem::Specification.stubs.map do |stub|
658
+ StubSpecification.from_stub(stub)
659
+ end
660
+ end
661
+
662
+ def backport_ext_builder_monitor
663
+ require "rubygems/ext"
664
+
665
+ Gem::Ext::Builder.class_eval do
666
+ unless const_defined?(:CHDIR_MONITOR)
667
+ const_set(:CHDIR_MONITOR, EXT_LOCK)
668
+ end
669
+
670
+ remove_const(:CHDIR_MUTEX) if const_defined?(:CHDIR_MUTEX)
671
+ const_set(:CHDIR_MUTEX, const_get(:CHDIR_MONITOR))
672
+ end
673
+ end
674
+
675
+ if Gem::Specification.respond_to?(:stubs_for)
676
+ def find_name(name)
677
+ Gem::Specification.stubs_for(name).map(&:to_spec)
678
+ end
679
+ else
680
+ def find_name(name)
681
+ Gem::Specification.stubs.find_all do |spec|
682
+ spec.name == name
683
+ end.map(&:to_spec)
684
+ end
685
+ end
686
+ end
687
+ end
688
+
689
+ if RubygemsIntegration.provides?(">= 2.1.0")
690
+ @rubygems = RubygemsIntegration::MoreFuture.new
691
+ elsif RubygemsIntegration.provides?(">= 1.99.99")
692
+ @rubygems = RubygemsIntegration::Future.new
693
+ elsif RubygemsIntegration.provides?(">= 1.8.20")
694
+ @rubygems = RubygemsIntegration::MoreModern.new
695
+ elsif RubygemsIntegration.provides?(">= 1.8.5")
696
+ @rubygems = RubygemsIntegration::Modern.new
697
+ elsif RubygemsIntegration.provides?(">= 1.8.0")
698
+ @rubygems = RubygemsIntegration::AlmostModern.new
699
+ elsif RubygemsIntegration.provides?(">= 1.7.0")
700
+ @rubygems = RubygemsIntegration::Transitional.new
701
+ elsif RubygemsIntegration.provides?(">= 1.4.0")
702
+ @rubygems = RubygemsIntegration::Legacy.new
703
+ else # Rubygems 1.3.6 and 1.3.7
704
+ @rubygems = RubygemsIntegration::Ancient.new
705
+ end
706
+
707
+ class << self
708
+ attr_reader :rubygems
709
+ end
710
+ end