bundler 2.0.2

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 (303) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3111 -0
  3. data/LICENSE.md +23 -0
  4. data/README.md +63 -0
  5. data/bundler.gemspec +65 -0
  6. data/exe/bundle +31 -0
  7. data/exe/bundle_ruby +60 -0
  8. data/exe/bundler +4 -0
  9. data/lib/bundler.rb +567 -0
  10. data/lib/bundler/build_metadata.rb +53 -0
  11. data/lib/bundler/capistrano.rb +22 -0
  12. data/lib/bundler/cli.rb +792 -0
  13. data/lib/bundler/cli/add.rb +35 -0
  14. data/lib/bundler/cli/binstubs.rb +49 -0
  15. data/lib/bundler/cli/cache.rb +36 -0
  16. data/lib/bundler/cli/check.rb +38 -0
  17. data/lib/bundler/cli/clean.rb +25 -0
  18. data/lib/bundler/cli/common.rb +102 -0
  19. data/lib/bundler/cli/config.rb +119 -0
  20. data/lib/bundler/cli/console.rb +43 -0
  21. data/lib/bundler/cli/doctor.rb +140 -0
  22. data/lib/bundler/cli/exec.rb +105 -0
  23. data/lib/bundler/cli/gem.rb +252 -0
  24. data/lib/bundler/cli/info.rb +50 -0
  25. data/lib/bundler/cli/init.rb +47 -0
  26. data/lib/bundler/cli/inject.rb +60 -0
  27. data/lib/bundler/cli/install.rb +218 -0
  28. data/lib/bundler/cli/issue.rb +40 -0
  29. data/lib/bundler/cli/list.rb +58 -0
  30. data/lib/bundler/cli/lock.rb +63 -0
  31. data/lib/bundler/cli/open.rb +26 -0
  32. data/lib/bundler/cli/outdated.rb +266 -0
  33. data/lib/bundler/cli/package.rb +49 -0
  34. data/lib/bundler/cli/platform.rb +46 -0
  35. data/lib/bundler/cli/plugin.rb +24 -0
  36. data/lib/bundler/cli/pristine.rb +47 -0
  37. data/lib/bundler/cli/remove.rb +18 -0
  38. data/lib/bundler/cli/show.rb +75 -0
  39. data/lib/bundler/cli/update.rb +91 -0
  40. data/lib/bundler/cli/viz.rb +31 -0
  41. data/lib/bundler/compact_index_client.rb +109 -0
  42. data/lib/bundler/compact_index_client/cache.rb +118 -0
  43. data/lib/bundler/compact_index_client/updater.rb +116 -0
  44. data/lib/bundler/compatibility_guard.rb +13 -0
  45. data/lib/bundler/constants.rb +7 -0
  46. data/lib/bundler/current_ruby.rb +94 -0
  47. data/lib/bundler/definition.rb +995 -0
  48. data/lib/bundler/dep_proxy.rb +48 -0
  49. data/lib/bundler/dependency.rb +139 -0
  50. data/lib/bundler/deployment.rb +69 -0
  51. data/lib/bundler/deprecate.rb +44 -0
  52. data/lib/bundler/dsl.rb +615 -0
  53. data/lib/bundler/endpoint_specification.rb +141 -0
  54. data/lib/bundler/env.rb +149 -0
  55. data/lib/bundler/environment_preserver.rb +59 -0
  56. data/lib/bundler/errors.rb +158 -0
  57. data/lib/bundler/feature_flag.rb +75 -0
  58. data/lib/bundler/fetcher.rb +312 -0
  59. data/lib/bundler/fetcher/base.rb +52 -0
  60. data/lib/bundler/fetcher/compact_index.rb +126 -0
  61. data/lib/bundler/fetcher/dependency.rb +82 -0
  62. data/lib/bundler/fetcher/downloader.rb +84 -0
  63. data/lib/bundler/fetcher/index.rb +52 -0
  64. data/lib/bundler/friendly_errors.rb +131 -0
  65. data/lib/bundler/gem_helper.rb +217 -0
  66. data/lib/bundler/gem_helpers.rb +101 -0
  67. data/lib/bundler/gem_remote_fetcher.rb +43 -0
  68. data/lib/bundler/gem_tasks.rb +7 -0
  69. data/lib/bundler/gem_version_promoter.rb +190 -0
  70. data/lib/bundler/gemdeps.rb +29 -0
  71. data/lib/bundler/graph.rb +152 -0
  72. data/lib/bundler/index.rb +213 -0
  73. data/lib/bundler/injector.rb +253 -0
  74. data/lib/bundler/inline.rb +74 -0
  75. data/lib/bundler/installer.rb +318 -0
  76. data/lib/bundler/installer/gem_installer.rb +85 -0
  77. data/lib/bundler/installer/parallel_installer.rb +229 -0
  78. data/lib/bundler/installer/standalone.rb +53 -0
  79. data/lib/bundler/lazy_specification.rb +123 -0
  80. data/lib/bundler/lockfile_generator.rb +95 -0
  81. data/lib/bundler/lockfile_parser.rb +256 -0
  82. data/lib/bundler/match_platform.rb +24 -0
  83. data/lib/bundler/mirror.rb +223 -0
  84. data/lib/bundler/plugin.rb +294 -0
  85. data/lib/bundler/plugin/api.rb +81 -0
  86. data/lib/bundler/plugin/api/source.rb +306 -0
  87. data/lib/bundler/plugin/dsl.rb +53 -0
  88. data/lib/bundler/plugin/events.rb +61 -0
  89. data/lib/bundler/plugin/index.rb +165 -0
  90. data/lib/bundler/plugin/installer.rb +96 -0
  91. data/lib/bundler/plugin/installer/git.rb +38 -0
  92. data/lib/bundler/plugin/installer/rubygems.rb +27 -0
  93. data/lib/bundler/plugin/source_list.rb +27 -0
  94. data/lib/bundler/process_lock.rb +24 -0
  95. data/lib/bundler/psyched_yaml.rb +37 -0
  96. data/lib/bundler/remote_specification.rb +114 -0
  97. data/lib/bundler/resolver.rb +373 -0
  98. data/lib/bundler/resolver/spec_group.rb +106 -0
  99. data/lib/bundler/retry.rb +66 -0
  100. data/lib/bundler/ruby_dsl.rb +18 -0
  101. data/lib/bundler/ruby_version.rb +152 -0
  102. data/lib/bundler/rubygems_ext.rb +209 -0
  103. data/lib/bundler/rubygems_gem_installer.rb +99 -0
  104. data/lib/bundler/rubygems_integration.rb +915 -0
  105. data/lib/bundler/runtime.rb +322 -0
  106. data/lib/bundler/settings.rb +464 -0
  107. data/lib/bundler/settings/validator.rb +102 -0
  108. data/lib/bundler/setup.rb +28 -0
  109. data/lib/bundler/shared_helpers.rb +386 -0
  110. data/lib/bundler/similarity_detector.rb +63 -0
  111. data/lib/bundler/source.rb +94 -0
  112. data/lib/bundler/source/gemspec.rb +18 -0
  113. data/lib/bundler/source/git.rb +329 -0
  114. data/lib/bundler/source/git/git_proxy.rb +262 -0
  115. data/lib/bundler/source/metadata.rb +62 -0
  116. data/lib/bundler/source/path.rb +249 -0
  117. data/lib/bundler/source/path/installer.rb +74 -0
  118. data/lib/bundler/source/rubygems.rb +539 -0
  119. data/lib/bundler/source/rubygems/remote.rb +69 -0
  120. data/lib/bundler/source_list.rb +186 -0
  121. data/lib/bundler/spec_set.rb +208 -0
  122. data/lib/bundler/ssl_certs/.document +1 -0
  123. data/lib/bundler/ssl_certs/certificate_manager.rb +66 -0
  124. data/lib/bundler/ssl_certs/index.rubygems.org/GlobalSignRootCA.pem +21 -0
  125. data/lib/bundler/ssl_certs/rubygems.global.ssl.fastly.net/DigiCertHighAssuranceEVRootCA.pem +23 -0
  126. data/lib/bundler/ssl_certs/rubygems.org/AddTrustExternalCARoot.pem +25 -0
  127. data/lib/bundler/stub_specification.rb +108 -0
  128. data/lib/bundler/templates/.document +1 -0
  129. data/lib/bundler/templates/Executable +29 -0
  130. data/lib/bundler/templates/Executable.bundler +105 -0
  131. data/lib/bundler/templates/Executable.standalone +14 -0
  132. data/lib/bundler/templates/Gemfile +7 -0
  133. data/lib/bundler/templates/gems.rb +8 -0
  134. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +74 -0
  135. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  136. data/lib/bundler/templates/newgem/LICENSE.txt.tt +21 -0
  137. data/lib/bundler/templates/newgem/README.md.tt +47 -0
  138. data/lib/bundler/templates/newgem/Rakefile.tt +29 -0
  139. data/lib/bundler/templates/newgem/bin/console.tt +14 -0
  140. data/lib/bundler/templates/newgem/bin/setup.tt +8 -0
  141. data/lib/bundler/templates/newgem/exe/newgem.tt +3 -0
  142. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +3 -0
  143. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  144. data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  145. data/lib/bundler/templates/newgem/gitignore.tt +20 -0
  146. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +13 -0
  147. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  148. data/lib/bundler/templates/newgem/newgem.gemspec.tt +50 -0
  149. data/lib/bundler/templates/newgem/rspec.tt +3 -0
  150. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +9 -0
  151. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +14 -0
  152. data/lib/bundler/templates/newgem/test/newgem_test.rb.tt +11 -0
  153. data/lib/bundler/templates/newgem/test/test_helper.rb.tt +8 -0
  154. data/lib/bundler/templates/newgem/travis.yml.tt +7 -0
  155. data/lib/bundler/ui.rb +9 -0
  156. data/lib/bundler/ui/rg_proxy.rb +19 -0
  157. data/lib/bundler/ui/shell.rb +146 -0
  158. data/lib/bundler/ui/silent.rb +69 -0
  159. data/lib/bundler/uri_credentials_filter.rb +37 -0
  160. data/lib/bundler/vendor/fileutils/lib/fileutils.rb +1741 -0
  161. data/lib/bundler/vendor/fileutils/lib/fileutils/version.rb +5 -0
  162. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +12 -0
  163. data/lib/bundler/vendor/molinillo/lib/molinillo/compatibility.rb +26 -0
  164. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +57 -0
  165. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +81 -0
  166. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +223 -0
  167. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +36 -0
  168. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +66 -0
  169. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +62 -0
  170. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +63 -0
  171. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +61 -0
  172. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +126 -0
  173. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +46 -0
  174. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +36 -0
  175. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +136 -0
  176. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +143 -0
  177. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +6 -0
  178. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +101 -0
  179. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +67 -0
  180. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +837 -0
  181. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +46 -0
  182. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +58 -0
  183. data/lib/bundler/vendor/net-http-persistent/lib/net/http/faster.rb +27 -0
  184. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1233 -0
  185. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/ssl_reuse.rb +129 -0
  186. data/lib/bundler/vendor/thor/lib/thor.rb +509 -0
  187. data/lib/bundler/vendor/thor/lib/thor/actions.rb +331 -0
  188. data/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +104 -0
  189. data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +60 -0
  190. data/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +118 -0
  191. data/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +143 -0
  192. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +373 -0
  193. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
  194. data/lib/bundler/vendor/thor/lib/thor/base.rb +678 -0
  195. data/lib/bundler/vendor/thor/lib/thor/command.rb +135 -0
  196. data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +97 -0
  197. data/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  198. data/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb +129 -0
  199. data/lib/bundler/vendor/thor/lib/thor/error.rb +114 -0
  200. data/lib/bundler/vendor/thor/lib/thor/group.rb +281 -0
  201. data/lib/bundler/vendor/thor/lib/thor/invocation.rb +177 -0
  202. data/lib/bundler/vendor/thor/lib/thor/line_editor.rb +17 -0
  203. data/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +37 -0
  204. data/lib/bundler/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  205. data/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -0
  206. data/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +70 -0
  207. data/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +175 -0
  208. data/lib/bundler/vendor/thor/lib/thor/parser/option.rb +146 -0
  209. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +226 -0
  210. data/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +71 -0
  211. data/lib/bundler/vendor/thor/lib/thor/runner.rb +324 -0
  212. data/lib/bundler/vendor/thor/lib/thor/shell.rb +81 -0
  213. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +482 -0
  214. data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +149 -0
  215. data/lib/bundler/vendor/thor/lib/thor/shell/html.rb +126 -0
  216. data/lib/bundler/vendor/thor/lib/thor/util.rb +268 -0
  217. data/lib/bundler/vendor/thor/lib/thor/version.rb +3 -0
  218. data/lib/bundler/vendored_fileutils.rb +9 -0
  219. data/lib/bundler/vendored_molinillo.rb +4 -0
  220. data/lib/bundler/vendored_persistent.rb +52 -0
  221. data/lib/bundler/vendored_thor.rb +8 -0
  222. data/lib/bundler/version.rb +28 -0
  223. data/lib/bundler/version_ranges.rb +76 -0
  224. data/lib/bundler/vlad.rb +17 -0
  225. data/lib/bundler/worker.rb +106 -0
  226. data/lib/bundler/yaml_serializer.rb +90 -0
  227. data/man/bundle-add.1 +58 -0
  228. data/man/bundle-add.1.txt +52 -0
  229. data/man/bundle-add.ronn +40 -0
  230. data/man/bundle-binstubs.1 +40 -0
  231. data/man/bundle-binstubs.1.txt +48 -0
  232. data/man/bundle-binstubs.ronn +43 -0
  233. data/man/bundle-check.1 +31 -0
  234. data/man/bundle-check.1.txt +33 -0
  235. data/man/bundle-check.ronn +26 -0
  236. data/man/bundle-clean.1 +24 -0
  237. data/man/bundle-clean.1.txt +26 -0
  238. data/man/bundle-clean.ronn +18 -0
  239. data/man/bundle-config.1 +497 -0
  240. data/man/bundle-config.1.txt +529 -0
  241. data/man/bundle-config.ronn +397 -0
  242. data/man/bundle-doctor.1 +44 -0
  243. data/man/bundle-doctor.1.txt +44 -0
  244. data/man/bundle-doctor.ronn +33 -0
  245. data/man/bundle-exec.1 +165 -0
  246. data/man/bundle-exec.1.txt +178 -0
  247. data/man/bundle-exec.ronn +152 -0
  248. data/man/bundle-gem.1 +80 -0
  249. data/man/bundle-gem.1.txt +91 -0
  250. data/man/bundle-gem.ronn +78 -0
  251. data/man/bundle-info.1 +20 -0
  252. data/man/bundle-info.1.txt +21 -0
  253. data/man/bundle-info.ronn +17 -0
  254. data/man/bundle-init.1 +25 -0
  255. data/man/bundle-init.1.txt +34 -0
  256. data/man/bundle-init.ronn +29 -0
  257. data/man/bundle-inject.1 +33 -0
  258. data/man/bundle-inject.1.txt +32 -0
  259. data/man/bundle-inject.ronn +22 -0
  260. data/man/bundle-install.1 +308 -0
  261. data/man/bundle-install.1.txt +396 -0
  262. data/man/bundle-install.ronn +378 -0
  263. data/man/bundle-list.1 +50 -0
  264. data/man/bundle-list.1.txt +43 -0
  265. data/man/bundle-list.ronn +33 -0
  266. data/man/bundle-lock.1 +84 -0
  267. data/man/bundle-lock.1.txt +93 -0
  268. data/man/bundle-lock.ronn +94 -0
  269. data/man/bundle-open.1 +32 -0
  270. data/man/bundle-open.1.txt +29 -0
  271. data/man/bundle-open.ronn +19 -0
  272. data/man/bundle-outdated.1 +155 -0
  273. data/man/bundle-outdated.1.txt +131 -0
  274. data/man/bundle-outdated.ronn +111 -0
  275. data/man/bundle-package.1 +55 -0
  276. data/man/bundle-package.1.txt +79 -0
  277. data/man/bundle-package.ronn +72 -0
  278. data/man/bundle-platform.1 +61 -0
  279. data/man/bundle-platform.1.txt +57 -0
  280. data/man/bundle-platform.ronn +42 -0
  281. data/man/bundle-pristine.1 +34 -0
  282. data/man/bundle-pristine.1.txt +44 -0
  283. data/man/bundle-pristine.ronn +34 -0
  284. data/man/bundle-remove.1 +31 -0
  285. data/man/bundle-remove.1.txt +34 -0
  286. data/man/bundle-remove.ronn +23 -0
  287. data/man/bundle-show.1 +23 -0
  288. data/man/bundle-show.1.txt +27 -0
  289. data/man/bundle-show.ronn +21 -0
  290. data/man/bundle-update.1 +394 -0
  291. data/man/bundle-update.1.txt +391 -0
  292. data/man/bundle-update.ronn +350 -0
  293. data/man/bundle-viz.1 +39 -0
  294. data/man/bundle-viz.1.txt +39 -0
  295. data/man/bundle-viz.ronn +30 -0
  296. data/man/bundle.1 +136 -0
  297. data/man/bundle.1.txt +116 -0
  298. data/man/bundle.ronn +111 -0
  299. data/man/gemfile.5 +689 -0
  300. data/man/gemfile.5.ronn +521 -0
  301. data/man/gemfile.5.txt +653 -0
  302. data/man/index.txt +25 -0
  303. metadata +463 -0
@@ -0,0 +1,322 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bundler
4
+ class Runtime
5
+ include SharedHelpers
6
+
7
+ def initialize(root, definition)
8
+ @root = root
9
+ @definition = definition
10
+ end
11
+
12
+ def setup(*groups)
13
+ @definition.ensure_equivalent_gemfile_and_lockfile if Bundler.frozen_bundle?
14
+
15
+ groups.map!(&:to_sym)
16
+
17
+ # Has to happen first
18
+ clean_load_path
19
+
20
+ specs = groups.any? ? @definition.specs_for(groups) : requested_specs
21
+
22
+ SharedHelpers.set_bundle_environment
23
+ Bundler.rubygems.replace_entrypoints(specs)
24
+
25
+ # Activate the specs
26
+ load_paths = specs.map do |spec|
27
+ unless spec.loaded_from
28
+ raise GemNotFound, "#{spec.full_name} is missing. Run `bundle install` to get it."
29
+ end
30
+
31
+ check_for_activated_spec!(spec)
32
+
33
+ Bundler.rubygems.mark_loaded(spec)
34
+ spec.load_paths.reject {|path| $LOAD_PATH.include?(path) }
35
+ end.reverse.flatten
36
+
37
+ # See Gem::Specification#add_self_to_load_path (since RubyGems 1.8)
38
+ if insert_index = Bundler.rubygems.load_path_insert_index
39
+ # Gem directories must come after -I and ENV['RUBYLIB']
40
+ $LOAD_PATH.insert(insert_index, *load_paths)
41
+ else
42
+ # We are probably testing in core, -I and RUBYLIB don't apply
43
+ $LOAD_PATH.unshift(*load_paths)
44
+ end
45
+
46
+ setup_manpath
47
+
48
+ lock(:preserve_unknown_sections => true)
49
+
50
+ self
51
+ end
52
+
53
+ REQUIRE_ERRORS = [
54
+ /^no such file to load -- (.+)$/i,
55
+ /^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
56
+ /^Missing API definition file in (.+)$/i,
57
+ /^cannot load such file -- (.+)$/i,
58
+ /^dlopen\([^)]*\): Library not loaded: (.+)$/i,
59
+ ].freeze
60
+
61
+ def require(*groups)
62
+ groups.map!(&:to_sym)
63
+ groups = [:default] if groups.empty?
64
+
65
+ @definition.dependencies.each do |dep|
66
+ # Skip the dependency if it is not in any of the requested groups, or
67
+ # not for the current platform, or doesn't match the gem constraints.
68
+ next unless (dep.groups & groups).any? && dep.should_include?
69
+
70
+ required_file = nil
71
+
72
+ begin
73
+ # Loop through all the specified autorequires for the
74
+ # dependency. If there are none, use the dependency's name
75
+ # as the autorequire.
76
+ Array(dep.autorequire || dep.name).each do |file|
77
+ # Allow `require: true` as an alias for `require: <name>`
78
+ file = dep.name if file == true
79
+ required_file = file
80
+ begin
81
+ Kernel.require file
82
+ rescue RuntimeError => e
83
+ raise e if e.is_a?(LoadError) # we handle this a little later
84
+ raise Bundler::GemRequireError.new e,
85
+ "There was an error while trying to load the gem '#{file}'."
86
+ end
87
+ end
88
+ rescue LoadError => e
89
+ REQUIRE_ERRORS.find {|r| r =~ e.message }
90
+ raise if dep.autorequire || $1 != required_file
91
+
92
+ if dep.autorequire.nil? && dep.name.include?("-")
93
+ begin
94
+ namespaced_file = dep.name.tr("-", "/")
95
+ Kernel.require namespaced_file
96
+ rescue LoadError => e
97
+ REQUIRE_ERRORS.find {|r| r =~ e.message }
98
+ raise if $1 != namespaced_file
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ def self.definition_method(meth)
106
+ define_method(meth) do
107
+ raise ArgumentError, "no definition when calling Runtime##{meth}" unless @definition
108
+ @definition.send(meth)
109
+ end
110
+ end
111
+ private_class_method :definition_method
112
+
113
+ definition_method :requested_specs
114
+ definition_method :specs
115
+ definition_method :dependencies
116
+ definition_method :current_dependencies
117
+ definition_method :requires
118
+
119
+ def lock(opts = {})
120
+ return if @definition.nothing_changed? && !@definition.unlocking?
121
+ @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections])
122
+ end
123
+
124
+ alias_method :gems, :specs
125
+
126
+ def cache(custom_path = nil)
127
+ cache_path = Bundler.app_cache(custom_path)
128
+ SharedHelpers.filesystem_access(cache_path) do |p|
129
+ FileUtils.mkdir_p(p)
130
+ end unless File.exist?(cache_path)
131
+
132
+ Bundler.ui.info "Updating files in #{Bundler.settings.app_cache_path}"
133
+
134
+ specs_to_cache = Bundler.settings[:cache_all_platforms] ? @definition.resolve.materialized_for_all_platforms : specs
135
+ specs_to_cache.each do |spec|
136
+ next if spec.name == "bundler"
137
+ next if spec.source.is_a?(Source::Gemspec)
138
+ spec.source.send(:fetch_gem, spec) if Bundler.settings[:cache_all_platforms] && spec.source.respond_to?(:fetch_gem, true)
139
+ spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache)
140
+ end
141
+
142
+ Dir[cache_path.join("*/.git")].each do |git_dir|
143
+ FileUtils.rm_rf(git_dir)
144
+ FileUtils.touch(File.expand_path("../.bundlecache", git_dir))
145
+ end
146
+
147
+ prune_cache(cache_path) unless Bundler.settings[:no_prune]
148
+ end
149
+
150
+ def prune_cache(cache_path)
151
+ SharedHelpers.filesystem_access(cache_path) do |p|
152
+ FileUtils.mkdir_p(p)
153
+ end unless File.exist?(cache_path)
154
+ resolve = @definition.resolve
155
+ prune_gem_cache(resolve, cache_path)
156
+ prune_git_and_path_cache(resolve, cache_path)
157
+ end
158
+
159
+ def clean(dry_run = false)
160
+ gem_bins = Dir["#{Gem.dir}/bin/*"]
161
+ git_dirs = Dir["#{Gem.dir}/bundler/gems/*"]
162
+ git_cache_dirs = Dir["#{Gem.dir}/cache/bundler/git/*"]
163
+ gem_dirs = Dir["#{Gem.dir}/gems/*"]
164
+ gem_files = Dir["#{Gem.dir}/cache/*.gem"]
165
+ gemspec_files = Dir["#{Gem.dir}/specifications/*.gemspec"]
166
+ extension_dirs = Dir["#{Gem.dir}/extensions/*/*/*"]
167
+ spec_gem_paths = []
168
+ # need to keep git sources around
169
+ spec_git_paths = @definition.spec_git_paths
170
+ spec_git_cache_dirs = []
171
+ spec_gem_executables = []
172
+ spec_cache_paths = []
173
+ spec_gemspec_paths = []
174
+ spec_extension_paths = []
175
+ specs.each do |spec|
176
+ spec_gem_paths << spec.full_gem_path
177
+ # need to check here in case gems are nested like for the rails git repo
178
+ md = %r{(.+bundler/gems/.+-[a-f0-9]{7,12})}.match(spec.full_gem_path)
179
+ spec_git_paths << md[1] if md
180
+ spec_gem_executables << spec.executables.collect do |executable|
181
+ e = "#{Bundler.rubygems.gem_bindir}/#{executable}"
182
+ [e, "#{e}.bat"]
183
+ end
184
+ spec_cache_paths << spec.cache_file
185
+ spec_gemspec_paths << spec.spec_file
186
+ spec_extension_paths << spec.extension_dir if spec.respond_to?(:extension_dir)
187
+ spec_git_cache_dirs << spec.source.cache_path.to_s if spec.source.is_a?(Bundler::Source::Git)
188
+ end
189
+ spec_gem_paths.uniq!
190
+ spec_gem_executables.flatten!
191
+
192
+ stale_gem_bins = gem_bins - spec_gem_executables
193
+ stale_git_dirs = git_dirs - spec_git_paths - ["#{Gem.dir}/bundler/gems/extensions"]
194
+ stale_git_cache_dirs = git_cache_dirs - spec_git_cache_dirs
195
+ stale_gem_dirs = gem_dirs - spec_gem_paths
196
+ stale_gem_files = gem_files - spec_cache_paths
197
+ stale_gemspec_files = gemspec_files - spec_gemspec_paths
198
+ stale_extension_dirs = extension_dirs - spec_extension_paths
199
+
200
+ removed_stale_gem_dirs = stale_gem_dirs.collect {|dir| remove_dir(dir, dry_run) }
201
+ removed_stale_git_dirs = stale_git_dirs.collect {|dir| remove_dir(dir, dry_run) }
202
+ output = removed_stale_gem_dirs + removed_stale_git_dirs
203
+
204
+ unless dry_run
205
+ stale_files = stale_gem_bins + stale_gem_files + stale_gemspec_files
206
+ stale_files.each do |file|
207
+ SharedHelpers.filesystem_access(File.dirname(file)) do |_p|
208
+ FileUtils.rm(file) if File.exist?(file)
209
+ end
210
+ end
211
+
212
+ stale_dirs = stale_git_cache_dirs + stale_extension_dirs
213
+ stale_dirs.each do |stale_dir|
214
+ SharedHelpers.filesystem_access(stale_dir) do |dir|
215
+ FileUtils.rm_rf(dir) if File.exist?(dir)
216
+ end
217
+ end
218
+ end
219
+
220
+ output
221
+ end
222
+
223
+ private
224
+
225
+ def prune_gem_cache(resolve, cache_path)
226
+ cached = Dir["#{cache_path}/*.gem"]
227
+
228
+ cached = cached.delete_if do |path|
229
+ spec = Bundler.rubygems.spec_from_gem path
230
+
231
+ resolve.any? do |s|
232
+ s.name == spec.name && s.version == spec.version && !s.source.is_a?(Bundler::Source::Git)
233
+ end
234
+ end
235
+
236
+ if cached.any?
237
+ Bundler.ui.info "Removing outdated .gem files from #{Bundler.settings.app_cache_path}"
238
+
239
+ cached.each do |path|
240
+ Bundler.ui.info " * #{File.basename(path)}"
241
+ File.delete(path)
242
+ end
243
+ end
244
+ end
245
+
246
+ def prune_git_and_path_cache(resolve, cache_path)
247
+ cached = Dir["#{cache_path}/*/.bundlecache"]
248
+
249
+ cached = cached.delete_if do |path|
250
+ name = File.basename(File.dirname(path))
251
+
252
+ resolve.any? do |s|
253
+ source = s.source
254
+ source.respond_to?(:app_cache_dirname) && source.app_cache_dirname == name
255
+ end
256
+ end
257
+
258
+ if cached.any?
259
+ Bundler.ui.info "Removing outdated git and path gems from #{Bundler.settings.app_cache_path}"
260
+
261
+ cached.each do |path|
262
+ path = File.dirname(path)
263
+ Bundler.ui.info " * #{File.basename(path)}"
264
+ FileUtils.rm_rf(path)
265
+ end
266
+ end
267
+ end
268
+
269
+ def setup_manpath
270
+ # Add man/ subdirectories from activated bundles to MANPATH for man(1)
271
+ manuals = $LOAD_PATH.map do |path|
272
+ man_subdir = path.sub(/lib$/, "man")
273
+ man_subdir unless Dir[man_subdir + "/man?/"].empty?
274
+ end.compact
275
+
276
+ return if manuals.empty?
277
+ Bundler::SharedHelpers.set_env "MANPATH", manuals.concat(
278
+ ENV["MANPATH"].to_s.split(File::PATH_SEPARATOR)
279
+ ).uniq.join(File::PATH_SEPARATOR)
280
+ end
281
+
282
+ def remove_dir(dir, dry_run)
283
+ full_name = Pathname.new(dir).basename.to_s
284
+
285
+ parts = full_name.split("-")
286
+ name = parts[0..-2].join("-")
287
+ version = parts.last
288
+ output = "#{name} (#{version})"
289
+
290
+ if dry_run
291
+ Bundler.ui.info "Would have removed #{output}"
292
+ else
293
+ Bundler.ui.info "Removing #{output}"
294
+ FileUtils.rm_rf(dir)
295
+ end
296
+
297
+ output
298
+ end
299
+
300
+ def check_for_activated_spec!(spec)
301
+ return unless activated_spec = Bundler.rubygems.loaded_specs(spec.name)
302
+ return if activated_spec.version == spec.version
303
+
304
+ suggestion = if Bundler.rubygems.spec_default_gem?(activated_spec)
305
+ "Since #{spec.name} is a default gem, you can either remove your dependency on it" \
306
+ " or try updating to a newer version of bundler that supports #{spec.name} as a default gem."
307
+ else
308
+ "Prepending `bundle exec` to your command may solve this."
309
+ end
310
+
311
+ e = Gem::LoadError.new "You have already activated #{activated_spec.name} #{activated_spec.version}, " \
312
+ "but your Gemfile requires #{spec.name} #{spec.version}. #{suggestion}"
313
+ e.name = spec.name
314
+ if e.respond_to?(:requirement=)
315
+ e.requirement = Gem::Requirement.new(spec.version.to_s)
316
+ else
317
+ e.version_requirement = Gem::Requirement.new(spec.version.to_s)
318
+ end
319
+ raise e
320
+ end
321
+ end
322
+ end
@@ -0,0 +1,464 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ module Bundler
6
+ class Settings
7
+ autoload :Mirror, "bundler/mirror"
8
+ autoload :Mirrors, "bundler/mirror"
9
+ autoload :Validator, "bundler/settings/validator"
10
+
11
+ BOOL_KEYS = %w[
12
+ allow_bundler_dependency_conflicts
13
+ allow_deployment_source_credential_changes
14
+ allow_offline_install
15
+ auto_clean_without_path
16
+ auto_install
17
+ auto_config_jobs
18
+ cache_all
19
+ cache_all_platforms
20
+ cache_command_is_package
21
+ console_command
22
+ default_install_uses_path
23
+ deployment
24
+ deployment_means_frozen
25
+ disable_checksum_validation
26
+ disable_exec_load
27
+ disable_local_branch_check
28
+ disable_multisource
29
+ disable_platform_warnings
30
+ disable_shared_gems
31
+ disable_version_check
32
+ error_on_stderr
33
+ force_ruby_platform
34
+ forget_cli_options
35
+ frozen
36
+ gem.coc
37
+ gem.mit
38
+ global_path_appends_ruby_scope
39
+ global_gem_cache
40
+ ignore_messages
41
+ init_gems_rb
42
+ list_command
43
+ lockfile_upgrade_warning
44
+ lockfile_uses_separate_rubygems_sources
45
+ major_deprecations
46
+ no_install
47
+ no_prune
48
+ only_update_to_newer_versions
49
+ path_relative_to_cwd
50
+ path.system
51
+ plugins
52
+ prefer_gems_rb
53
+ print_only_version_number
54
+ setup_makes_kernel_gem_public
55
+ silence_root_warning
56
+ skip_default_git_sources
57
+ specific_platform
58
+ suppress_install_using_messages
59
+ unlock_source_unlocks_spec
60
+ update_requires_all_flag
61
+ use_gem_version_promoter_for_major_updates
62
+ viz_command
63
+ ].freeze
64
+
65
+ NUMBER_KEYS = %w[
66
+ jobs
67
+ redirect
68
+ retry
69
+ ssl_verify_mode
70
+ timeout
71
+ ].freeze
72
+
73
+ ARRAY_KEYS = %w[
74
+ with
75
+ without
76
+ ].freeze
77
+
78
+ DEFAULT_CONFIG = {
79
+ :disable_version_check => true,
80
+ :redirect => 5,
81
+ :retry => 3,
82
+ :timeout => 10,
83
+ }.freeze
84
+
85
+ def initialize(root = nil)
86
+ @root = root
87
+ @local_config = load_config(local_config_file)
88
+ @global_config = load_config(global_config_file)
89
+ @temporary = {}
90
+ end
91
+
92
+ def [](name)
93
+ key = key_for(name)
94
+ value = @temporary.fetch(key) do
95
+ @local_config.fetch(key) do
96
+ ENV.fetch(key) do
97
+ @global_config.fetch(key) do
98
+ DEFAULT_CONFIG.fetch(name) do
99
+ nil
100
+ end end end end end
101
+
102
+ converted_value(value, name)
103
+ end
104
+
105
+ def set_command_option(key, value)
106
+ if Bundler.feature_flag.forget_cli_options?
107
+ temporary(key => value)
108
+ value
109
+ else
110
+ command = if value.nil?
111
+ "bundle config --delete #{key}"
112
+ else
113
+ "bundle config #{key} #{Array(value).join(":")}"
114
+ end
115
+
116
+ Bundler::SharedHelpers.major_deprecation 3,\
117
+ "flags passed to commands " \
118
+ "will no longer be automatically remembered. Instead please set flags " \
119
+ "you want remembered between commands using `bundle config " \
120
+ "<setting name> <setting value>`, i.e. `#{command}`"
121
+
122
+ set_local(key, value)
123
+ end
124
+ end
125
+
126
+ def set_command_option_if_given(key, value)
127
+ return if value.nil?
128
+ set_command_option(key, value)
129
+ end
130
+
131
+ def set_local(key, value)
132
+ local_config_file || raise(GemfileNotFound, "Could not locate Gemfile")
133
+
134
+ set_key(key, value, @local_config, local_config_file)
135
+ end
136
+
137
+ def temporary(update)
138
+ existing = Hash[update.map {|k, _| [k, @temporary[key_for(k)]] }]
139
+ update.each do |k, v|
140
+ set_key(k, v, @temporary, nil)
141
+ end
142
+ return unless block_given?
143
+ begin
144
+ yield
145
+ ensure
146
+ existing.each {|k, v| set_key(k, v, @temporary, nil) }
147
+ end
148
+ end
149
+
150
+ def set_global(key, value)
151
+ set_key(key, value, @global_config, global_config_file)
152
+ end
153
+
154
+ def all
155
+ env_keys = ENV.keys.grep(/\ABUNDLE_.+/)
156
+
157
+ keys = @temporary.keys | @global_config.keys | @local_config.keys | env_keys
158
+
159
+ keys.map do |key|
160
+ key.sub(/^BUNDLE_/, "").gsub(/__/, ".").downcase
161
+ end
162
+ end
163
+
164
+ def local_overrides
165
+ repos = {}
166
+ all.each do |k|
167
+ repos[$'] = self[k] if k =~ /^local\./
168
+ end
169
+ repos
170
+ end
171
+
172
+ def mirror_for(uri)
173
+ uri = URI(uri.to_s) unless uri.is_a?(URI)
174
+ gem_mirrors.for(uri.to_s).uri
175
+ end
176
+
177
+ def credentials_for(uri)
178
+ self[uri.to_s] || self[uri.host]
179
+ end
180
+
181
+ def gem_mirrors
182
+ all.inject(Mirrors.new) do |mirrors, k|
183
+ mirrors.parse(k, self[k]) if k.start_with?("mirror.")
184
+ mirrors
185
+ end
186
+ end
187
+
188
+ def locations(key)
189
+ key = key_for(key)
190
+ locations = {}
191
+ locations[:temporary] = @temporary[key] if @temporary.key?(key)
192
+ locations[:local] = @local_config[key] if @local_config.key?(key)
193
+ locations[:env] = ENV[key] if ENV[key]
194
+ locations[:global] = @global_config[key] if @global_config.key?(key)
195
+ locations[:default] = DEFAULT_CONFIG[key] if DEFAULT_CONFIG.key?(key)
196
+ locations
197
+ end
198
+
199
+ def pretty_values_for(exposed_key)
200
+ key = key_for(exposed_key)
201
+
202
+ locations = []
203
+
204
+ if @temporary.key?(key)
205
+ locations << "Set for the current command: #{converted_value(@temporary[key], exposed_key).inspect}"
206
+ end
207
+
208
+ if @local_config.key?(key)
209
+ locations << "Set for your local app (#{local_config_file}): #{converted_value(@local_config[key], exposed_key).inspect}"
210
+ end
211
+
212
+ if value = ENV[key]
213
+ locations << "Set via #{key}: #{converted_value(value, exposed_key).inspect}"
214
+ end
215
+
216
+ if @global_config.key?(key)
217
+ locations << "Set for the current user (#{global_config_file}): #{converted_value(@global_config[key], exposed_key).inspect}"
218
+ end
219
+
220
+ return ["You have not configured a value for `#{exposed_key}`"] if locations.empty?
221
+ locations
222
+ end
223
+
224
+ # for legacy reasons, in Bundler 1, the ruby scope isnt appended when the setting comes from ENV or the global config,
225
+ # nor do we respect :disable_shared_gems
226
+ def path
227
+ key = key_for(:path)
228
+ path = ENV[key] || @global_config[key]
229
+ if path && !@temporary.key?(key) && !@local_config.key?(key)
230
+ return Path.new(path, Bundler.feature_flag.global_path_appends_ruby_scope?, false, false)
231
+ end
232
+
233
+ system_path = self["path.system"] || (self[:disable_shared_gems] == false)
234
+ Path.new(self[:path], true, system_path, Bundler.feature_flag.default_install_uses_path?)
235
+ end
236
+
237
+ Path = Struct.new(:explicit_path, :append_ruby_scope, :system_path, :default_install_uses_path) do
238
+ def path
239
+ path = base_path
240
+ path = File.join(path, Bundler.ruby_scope) if append_ruby_scope && !use_system_gems?
241
+ path
242
+ end
243
+
244
+ def use_system_gems?
245
+ return true if system_path
246
+ return false if explicit_path
247
+ !default_install_uses_path
248
+ end
249
+
250
+ def base_path
251
+ path = explicit_path
252
+ path ||= ".bundle" unless use_system_gems?
253
+ path ||= Bundler.rubygems.gem_dir
254
+ path
255
+ end
256
+
257
+ def base_path_relative_to_pwd
258
+ base_path = Pathname.new(self.base_path)
259
+ expanded_base_path = base_path.expand_path(Bundler.root)
260
+ relative_path = expanded_base_path.relative_path_from(Pathname.pwd)
261
+ if relative_path.to_s.start_with?("..")
262
+ relative_path = base_path if base_path.absolute?
263
+ else
264
+ relative_path = Pathname.new(File.join(".", relative_path))
265
+ end
266
+ relative_path
267
+ rescue ArgumentError
268
+ expanded_base_path
269
+ end
270
+
271
+ def validate!
272
+ return unless explicit_path && system_path
273
+ path = Bundler.settings.pretty_values_for(:path)
274
+ path.unshift(nil, "path:") unless path.empty?
275
+ system_path = Bundler.settings.pretty_values_for("path.system")
276
+ system_path.unshift(nil, "path.system:") unless system_path.empty?
277
+ disable_shared_gems = Bundler.settings.pretty_values_for(:disable_shared_gems)
278
+ disable_shared_gems.unshift(nil, "disable_shared_gems:") unless disable_shared_gems.empty?
279
+ raise InvalidOption,
280
+ "Using a custom path while using system gems is unsupported.\n#{path.join("\n")}\n#{system_path.join("\n")}\n#{disable_shared_gems.join("\n")}"
281
+ end
282
+ end
283
+
284
+ def allow_sudo?
285
+ key = key_for(:path)
286
+ path_configured = @temporary.key?(key) || @local_config.key?(key)
287
+ !path_configured
288
+ end
289
+
290
+ def ignore_config?
291
+ ENV["BUNDLE_IGNORE_CONFIG"]
292
+ end
293
+
294
+ def app_cache_path
295
+ @app_cache_path ||= self[:cache_path] || "vendor/cache"
296
+ end
297
+
298
+ def validate!
299
+ all.each do |raw_key|
300
+ [@local_config, ENV, @global_config].each do |settings|
301
+ value = converted_value(settings[key_for(raw_key)], raw_key)
302
+ Validator.validate!(raw_key, value, settings.to_hash.dup)
303
+ end
304
+ end
305
+ end
306
+
307
+ def key_for(key)
308
+ key = Settings.normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key
309
+ key = key.to_s.gsub(".", "__").upcase
310
+ "BUNDLE_#{key}"
311
+ end
312
+
313
+ private
314
+
315
+ def parent_setting_for(name)
316
+ split_specific_setting_for(name)[0]
317
+ end
318
+
319
+ def specific_gem_for(name)
320
+ split_specific_setting_for(name)[1]
321
+ end
322
+
323
+ def split_specific_setting_for(name)
324
+ name.split(".")
325
+ end
326
+
327
+ def is_bool(name)
328
+ BOOL_KEYS.include?(name.to_s) || BOOL_KEYS.include?(parent_setting_for(name.to_s))
329
+ end
330
+
331
+ def to_bool(value)
332
+ case value
333
+ when nil, /\A(false|f|no|n|0|)\z/i, false
334
+ false
335
+ else
336
+ true
337
+ end
338
+ end
339
+
340
+ def is_num(key)
341
+ NUMBER_KEYS.include?(key.to_s)
342
+ end
343
+
344
+ def is_array(key)
345
+ ARRAY_KEYS.include?(key.to_s)
346
+ end
347
+
348
+ def to_array(value)
349
+ return [] unless value
350
+ value.split(":").map(&:to_sym)
351
+ end
352
+
353
+ def array_to_s(array)
354
+ array = Array(array)
355
+ return nil if array.empty?
356
+ array.join(":").tr(" ", ":")
357
+ end
358
+
359
+ def set_key(raw_key, value, hash, file)
360
+ raw_key = raw_key.to_s
361
+ value = array_to_s(value) if is_array(raw_key)
362
+
363
+ key = key_for(raw_key)
364
+
365
+ return if hash[key] == value
366
+
367
+ hash[key] = value
368
+ hash.delete(key) if value.nil?
369
+
370
+ Validator.validate!(raw_key, converted_value(value, raw_key), hash)
371
+
372
+ return unless file
373
+ SharedHelpers.filesystem_access(file) do |p|
374
+ FileUtils.mkdir_p(p.dirname)
375
+ require "bundler/yaml_serializer"
376
+ p.open("w") {|f| f.write(YAMLSerializer.dump(hash)) }
377
+ end
378
+ end
379
+
380
+ def converted_value(value, key)
381
+ if is_array(key)
382
+ to_array(value)
383
+ elsif value.nil?
384
+ nil
385
+ elsif is_bool(key) || value == "false"
386
+ to_bool(value)
387
+ elsif is_num(key)
388
+ value.to_i
389
+ else
390
+ value.to_s
391
+ end
392
+ end
393
+
394
+ def global_config_file
395
+ if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty?
396
+ Pathname.new(ENV["BUNDLE_CONFIG"])
397
+ else
398
+ begin
399
+ Bundler.user_bundle_path("config")
400
+ rescue PermissionError, GenericSystemCallError
401
+ nil
402
+ end
403
+ end
404
+ end
405
+
406
+ def local_config_file
407
+ Pathname.new(@root).join("config") if @root
408
+ end
409
+
410
+ CONFIG_REGEX = %r{ # rubocop:disable Style/RegexpLiteral
411
+ ^
412
+ (BUNDLE_.+):\s # the key
413
+ (?: !\s)? # optional exclamation mark found with ruby 1.9.3
414
+ (['"]?) # optional opening quote
415
+ (.* # contents of the value
416
+ (?: # optionally, up until the next key
417
+ (\n(?!BUNDLE).+)*
418
+ )
419
+ )
420
+ \2 # matching closing quote
421
+ $
422
+ }xo
423
+
424
+ def load_config(config_file)
425
+ return {} if !config_file || ignore_config?
426
+ SharedHelpers.filesystem_access(config_file, :read) do |file|
427
+ valid_file = file.exist? && !file.size.zero?
428
+ return {} unless valid_file
429
+ require "bundler/yaml_serializer"
430
+ YAMLSerializer.load file.read
431
+ end
432
+ end
433
+
434
+ PER_URI_OPTIONS = %w[
435
+ fallback_timeout
436
+ ].freeze
437
+
438
+ NORMALIZE_URI_OPTIONS_PATTERN =
439
+ /
440
+ \A
441
+ (\w+\.)? # optional prefix key
442
+ (https?.*?) # URI
443
+ (\.#{Regexp.union(PER_URI_OPTIONS)})? # optional suffix key
444
+ \z
445
+ /ix
446
+
447
+ # TODO: duplicates Rubygems#normalize_uri
448
+ # TODO: is this the correct place to validate mirror URIs?
449
+ def self.normalize_uri(uri)
450
+ uri = uri.to_s
451
+ if uri =~ NORMALIZE_URI_OPTIONS_PATTERN
452
+ prefix = $1
453
+ uri = $2
454
+ suffix = $3
455
+ end
456
+ uri = "#{uri}/" unless uri.end_with?("/")
457
+ uri = URI(uri)
458
+ unless uri.absolute?
459
+ raise ArgumentError, format("Gem sources must be absolute. You provided '%s'.", uri)
460
+ end
461
+ "#{prefix}#{uri}#{suffix}"
462
+ end
463
+ end
464
+ end