bundler-prehistoric 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +100 -0
  5. data/CHANGELOG.md +1640 -0
  6. data/CONTRIBUTING.md +32 -0
  7. data/DEVELOPMENT.md +117 -0
  8. data/Gemfile +3 -0
  9. data/ISSUES.md +96 -0
  10. data/LICENSE.md +23 -0
  11. data/README.md +46 -0
  12. data/Rakefile +256 -0
  13. data/UPGRADING.md +103 -0
  14. data/bin/bundle +21 -0
  15. data/bin/bundle_ruby +56 -0
  16. data/bin/bundler +21 -0
  17. data/bundler.gemspec +33 -0
  18. data/lib/bundler.rb +442 -0
  19. data/lib/bundler/backports/time.rb +7 -0
  20. data/lib/bundler/capistrano.rb +16 -0
  21. data/lib/bundler/cli.rb +395 -0
  22. data/lib/bundler/cli/binstubs.rb +38 -0
  23. data/lib/bundler/cli/cache.rb +34 -0
  24. data/lib/bundler/cli/check.rb +35 -0
  25. data/lib/bundler/cli/clean.rb +19 -0
  26. data/lib/bundler/cli/common.rb +54 -0
  27. data/lib/bundler/cli/config.rb +84 -0
  28. data/lib/bundler/cli/console.rb +39 -0
  29. data/lib/bundler/cli/exec.rb +37 -0
  30. data/lib/bundler/cli/gem.rb +101 -0
  31. data/lib/bundler/cli/init.rb +33 -0
  32. data/lib/bundler/cli/inject.rb +33 -0
  33. data/lib/bundler/cli/install.rb +133 -0
  34. data/lib/bundler/cli/open.rb +23 -0
  35. data/lib/bundler/cli/outdated.rb +80 -0
  36. data/lib/bundler/cli/package.rb +36 -0
  37. data/lib/bundler/cli/platform.rb +43 -0
  38. data/lib/bundler/cli/show.rb +48 -0
  39. data/lib/bundler/cli/update.rb +73 -0
  40. data/lib/bundler/cli/viz.rb +27 -0
  41. data/lib/bundler/constants.rb +5 -0
  42. data/lib/bundler/current_ruby.rb +155 -0
  43. data/lib/bundler/definition.rb +604 -0
  44. data/lib/bundler/dep_proxy.rb +43 -0
  45. data/lib/bundler/dependency.rb +106 -0
  46. data/lib/bundler/deployment.rb +59 -0
  47. data/lib/bundler/deprecate.rb +15 -0
  48. data/lib/bundler/dsl.rb +305 -0
  49. data/lib/bundler/endpoint_specification.rb +76 -0
  50. data/lib/bundler/env.rb +56 -0
  51. data/lib/bundler/environment.rb +42 -0
  52. data/lib/bundler/fetcher.rb +396 -0
  53. data/lib/bundler/friendly_errors.rb +42 -0
  54. data/lib/bundler/gem_helper.rb +169 -0
  55. data/lib/bundler/gem_helpers.rb +25 -0
  56. data/lib/bundler/gem_installer.rb +9 -0
  57. data/lib/bundler/gem_path_manipulation.rb +8 -0
  58. data/lib/bundler/gem_tasks.rb +2 -0
  59. data/lib/bundler/graph.rb +169 -0
  60. data/lib/bundler/index.rb +184 -0
  61. data/lib/bundler/injector.rb +64 -0
  62. data/lib/bundler/installer.rb +332 -0
  63. data/lib/bundler/lazy_specification.rb +83 -0
  64. data/lib/bundler/lockfile_parser.rb +146 -0
  65. data/lib/bundler/match_platform.rb +13 -0
  66. data/lib/bundler/parallel_workers.rb +18 -0
  67. data/lib/bundler/parallel_workers/thread_worker.rb +30 -0
  68. data/lib/bundler/parallel_workers/unix_worker.rb +101 -0
  69. data/lib/bundler/parallel_workers/worker.rb +69 -0
  70. data/lib/bundler/psyched_yaml.rb +26 -0
  71. data/lib/bundler/remote_specification.rb +57 -0
  72. data/lib/bundler/resolver.rb +534 -0
  73. data/lib/bundler/retry.rb +60 -0
  74. data/lib/bundler/ruby_dsl.rb +11 -0
  75. data/lib/bundler/ruby_version.rb +117 -0
  76. data/lib/bundler/rubygems_ext.rb +171 -0
  77. data/lib/bundler/rubygems_integration.rb +578 -0
  78. data/lib/bundler/runtime.rb +310 -0
  79. data/lib/bundler/settings.rb +176 -0
  80. data/lib/bundler/setup.rb +23 -0
  81. data/lib/bundler/shared_helpers.rb +110 -0
  82. data/lib/bundler/similarity_detector.rb +63 -0
  83. data/lib/bundler/source.rb +29 -0
  84. data/lib/bundler/source/git.rb +289 -0
  85. data/lib/bundler/source/git/git_proxy.rb +158 -0
  86. data/lib/bundler/source/path.rb +225 -0
  87. data/lib/bundler/source/path/installer.rb +38 -0
  88. data/lib/bundler/source/rubygems.rb +334 -0
  89. data/lib/bundler/source/svn.rb +260 -0
  90. data/lib/bundler/source/svn/svn_proxy.rb +110 -0
  91. data/lib/bundler/spec_set.rb +154 -0
  92. data/lib/bundler/ssl_certs/.document +1 -0
  93. data/lib/bundler/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +14 -0
  94. data/lib/bundler/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +23 -0
  95. data/lib/bundler/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +28 -0
  96. data/lib/bundler/ssl_certs/GeoTrustGlobalCA.pem +20 -0
  97. data/lib/bundler/ssl_certs/certificate_manager.rb +41 -0
  98. data/lib/bundler/templates/Executable +16 -0
  99. data/lib/bundler/templates/Executable.standalone +12 -0
  100. data/lib/bundler/templates/Gemfile +4 -0
  101. data/lib/bundler/templates/newgem/.travis.yml.tt +3 -0
  102. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  103. data/lib/bundler/templates/newgem/LICENSE.txt.tt +22 -0
  104. data/lib/bundler/templates/newgem/README.md.tt +31 -0
  105. data/lib/bundler/templates/newgem/Rakefile.tt +26 -0
  106. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  107. data/lib/bundler/templates/newgem/consolerc.tt +3 -0
  108. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +3 -0
  109. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  110. data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  111. data/lib/bundler/templates/newgem/gitignore.tt +16 -0
  112. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +12 -0
  113. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  114. data/lib/bundler/templates/newgem/newgem.gemspec.tt +38 -0
  115. data/lib/bundler/templates/newgem/rspec.tt +2 -0
  116. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +11 -0
  117. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +2 -0
  118. data/lib/bundler/templates/newgem/test/minitest_helper.rb.tt +4 -0
  119. data/lib/bundler/templates/newgem/test/test_newgem.rb.tt +11 -0
  120. data/lib/bundler/ui.rb +7 -0
  121. data/lib/bundler/ui/rg_proxy.rb +21 -0
  122. data/lib/bundler/ui/shell.rb +98 -0
  123. data/lib/bundler/ui/silent.rb +44 -0
  124. data/lib/bundler/vendor/.document +0 -0
  125. data/lib/bundler/vendor/net/http/faster.rb +26 -0
  126. data/lib/bundler/vendor/net/http/persistent.rb +1230 -0
  127. data/lib/bundler/vendor/net/http/persistent/ssl_reuse.rb +128 -0
  128. data/lib/bundler/vendor/thor.rb +480 -0
  129. data/lib/bundler/vendor/thor/actions.rb +319 -0
  130. data/lib/bundler/vendor/thor/actions/create_file.rb +103 -0
  131. data/lib/bundler/vendor/thor/actions/create_link.rb +59 -0
  132. data/lib/bundler/vendor/thor/actions/directory.rb +118 -0
  133. data/lib/bundler/vendor/thor/actions/empty_directory.rb +135 -0
  134. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +316 -0
  135. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +107 -0
  136. data/lib/bundler/vendor/thor/base.rb +656 -0
  137. data/lib/bundler/vendor/thor/command.rb +133 -0
  138. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  139. data/lib/bundler/vendor/thor/core_ext/io_binary_read.rb +10 -0
  140. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +98 -0
  141. data/lib/bundler/vendor/thor/error.rb +32 -0
  142. data/lib/bundler/vendor/thor/group.rb +281 -0
  143. data/lib/bundler/vendor/thor/invocation.rb +173 -0
  144. data/lib/bundler/vendor/thor/line_editor.rb +17 -0
  145. data/lib/bundler/vendor/thor/line_editor/basic.rb +35 -0
  146. data/lib/bundler/vendor/thor/line_editor/readline.rb +88 -0
  147. data/lib/bundler/vendor/thor/parser.rb +4 -0
  148. data/lib/bundler/vendor/thor/parser/argument.rb +73 -0
  149. data/lib/bundler/vendor/thor/parser/arguments.rb +175 -0
  150. data/lib/bundler/vendor/thor/parser/option.rb +121 -0
  151. data/lib/bundler/vendor/thor/parser/options.rb +218 -0
  152. data/lib/bundler/vendor/thor/rake_compat.rb +71 -0
  153. data/lib/bundler/vendor/thor/runner.rb +322 -0
  154. data/lib/bundler/vendor/thor/shell.rb +81 -0
  155. data/lib/bundler/vendor/thor/shell/basic.rb +420 -0
  156. data/lib/bundler/vendor/thor/shell/color.rb +149 -0
  157. data/lib/bundler/vendor/thor/shell/html.rb +126 -0
  158. data/lib/bundler/vendor/thor/util.rb +267 -0
  159. data/lib/bundler/vendor/thor/version.rb +3 -0
  160. data/lib/bundler/vendored_persistent.rb +3 -0
  161. data/lib/bundler/vendored_thor.rb +8 -0
  162. data/lib/bundler/version.rb +6 -0
  163. data/lib/bundler/vlad.rb +11 -0
  164. data/man/bundle-config.ronn +155 -0
  165. data/man/bundle-exec.ronn +136 -0
  166. data/man/bundle-install.ronn +372 -0
  167. data/man/bundle-package.ronn +59 -0
  168. data/man/bundle-platform.ronn +42 -0
  169. data/man/bundle-update.ronn +179 -0
  170. data/man/bundle.ronn +92 -0
  171. data/man/gemfile.5.ronn +369 -0
  172. data/man/index.txt +7 -0
  173. data/spec/bundler/bundler_spec.rb +74 -0
  174. data/spec/bundler/cli_spec.rb +16 -0
  175. data/spec/bundler/definition_spec.rb +21 -0
  176. data/spec/bundler/dsl_spec.rb +108 -0
  177. data/spec/bundler/friendly_errors_spec.rb +13 -0
  178. data/spec/bundler/gem_helper_spec.rb +225 -0
  179. data/spec/bundler/psyched_yaml_spec.rb +8 -0
  180. data/spec/bundler/retry_spec.rb +59 -0
  181. data/spec/bundler/settings_spec.rb +13 -0
  182. data/spec/bundler/source_spec.rb +25 -0
  183. data/spec/cache/gems_spec.rb +316 -0
  184. data/spec/cache/git_spec.rb +188 -0
  185. data/spec/cache/path_spec.rb +121 -0
  186. data/spec/cache/platform_spec.rb +53 -0
  187. data/spec/cache/svn_spec.rb +82 -0
  188. data/spec/commands/binstubs_spec.rb +246 -0
  189. data/spec/commands/check_spec.rb +278 -0
  190. data/spec/commands/clean_spec.rb +652 -0
  191. data/spec/commands/config_spec.rb +227 -0
  192. data/spec/commands/console_spec.rb +102 -0
  193. data/spec/commands/exec_spec.rb +367 -0
  194. data/spec/commands/help_spec.rb +39 -0
  195. data/spec/commands/init_spec.rb +39 -0
  196. data/spec/commands/inject_spec.rb +78 -0
  197. data/spec/commands/licenses_spec.rb +31 -0
  198. data/spec/commands/newgem_spec.rb +451 -0
  199. data/spec/commands/open_spec.rb +80 -0
  200. data/spec/commands/outdated_spec.rb +168 -0
  201. data/spec/commands/package_spec.rb +128 -0
  202. data/spec/commands/show_spec.rb +152 -0
  203. data/spec/install/binstubs_spec.rb +24 -0
  204. data/spec/install/bundler_spec.rb +146 -0
  205. data/spec/install/deploy_spec.rb +237 -0
  206. data/spec/install/gemfile/gemspec_spec.rb +170 -0
  207. data/spec/install/gemfile/git_spec.rb +967 -0
  208. data/spec/install/gemfile/path_spec.rb +480 -0
  209. data/spec/install/gemfile/svn_spec.rb +582 -0
  210. data/spec/install/gemfile_spec.rb +44 -0
  211. data/spec/install/gems/c_ext_spec.rb +48 -0
  212. data/spec/install/gems/dependency_api_spec.rb +580 -0
  213. data/spec/install/gems/env_spec.rb +107 -0
  214. data/spec/install/gems/flex_spec.rb +314 -0
  215. data/spec/install/gems/groups_spec.rb +308 -0
  216. data/spec/install/gems/mirror_spec.rb +39 -0
  217. data/spec/install/gems/platform_spec.rb +221 -0
  218. data/spec/install/gems/post_install_spec.rb +121 -0
  219. data/spec/install/gems/resolving_spec.rb +124 -0
  220. data/spec/install/gems/simple_case_spec.rb +386 -0
  221. data/spec/install/gems/standalone_spec.rb +260 -0
  222. data/spec/install/gems/sudo_spec.rb +136 -0
  223. data/spec/install/gems/win32_spec.rb +26 -0
  224. data/spec/install/gemspecs_spec.rb +50 -0
  225. data/spec/install/path_spec.rb +150 -0
  226. data/spec/install/post_bundle_message_spec.rb +142 -0
  227. data/spec/install/prereleases_spec.rb +43 -0
  228. data/spec/install/security_policy_spec.rb +77 -0
  229. data/spec/install/upgrade_spec.rb +26 -0
  230. data/spec/lock/git_spec.rb +34 -0
  231. data/spec/lock/lockfile_spec.rb +912 -0
  232. data/spec/lock/svn_spec.rb +35 -0
  233. data/spec/other/bundle_ruby_spec.rb +142 -0
  234. data/spec/other/cli_dispatch_spec.rb +21 -0
  235. data/spec/other/ext_spec.rb +60 -0
  236. data/spec/other/platform_spec.rb +1285 -0
  237. data/spec/other/ssl_cert_spec.rb +10 -0
  238. data/spec/quality_spec.rb +88 -0
  239. data/spec/realworld/dependency_api_spec.rb +60 -0
  240. data/spec/realworld/edgecases_spec.rb +177 -0
  241. data/spec/realworld/parallel_spec.rb +69 -0
  242. data/spec/resolver/basic_spec.rb +66 -0
  243. data/spec/resolver/platform_spec.rb +88 -0
  244. data/spec/runtime/executable_spec.rb +149 -0
  245. data/spec/runtime/load_spec.rb +107 -0
  246. data/spec/runtime/platform_spec.rb +90 -0
  247. data/spec/runtime/require_spec.rb +332 -0
  248. data/spec/runtime/setup_spec.rb +856 -0
  249. data/spec/runtime/with_clean_env_spec.rb +91 -0
  250. data/spec/spec_helper.rb +114 -0
  251. data/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb +13 -0
  252. data/spec/support/artifice/endpoint.rb +71 -0
  253. data/spec/support/artifice/endpoint_500.rb +37 -0
  254. data/spec/support/artifice/endpoint_api_missing.rb +16 -0
  255. data/spec/support/artifice/endpoint_basic_authentication.rb +13 -0
  256. data/spec/support/artifice/endpoint_creds_diff_host.rb +38 -0
  257. data/spec/support/artifice/endpoint_extra.rb +31 -0
  258. data/spec/support/artifice/endpoint_extra_missing.rb +15 -0
  259. data/spec/support/artifice/endpoint_fallback.rb +17 -0
  260. data/spec/support/artifice/endpoint_host_redirect.rb +15 -0
  261. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  262. data/spec/support/artifice/endpoint_redirect.rb +15 -0
  263. data/spec/support/artifice/endpoint_strict_basic_authentication.rb +18 -0
  264. data/spec/support/artifice/endpoint_timeout.rb +13 -0
  265. data/spec/support/builders.rb +748 -0
  266. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  267. data/spec/support/fakeweb/windows.rb +23 -0
  268. data/spec/support/hax.rb +22 -0
  269. data/spec/support/helpers.rb +348 -0
  270. data/spec/support/indexes.rb +280 -0
  271. data/spec/support/less_than_proc.rb +14 -0
  272. data/spec/support/matchers.rb +77 -0
  273. data/spec/support/path.rb +81 -0
  274. data/spec/support/permissions.rb +10 -0
  275. data/spec/support/platforms.rb +94 -0
  276. data/spec/support/ruby_ext.rb +20 -0
  277. data/spec/support/rubygems_ext.rb +39 -0
  278. data/spec/support/streams.rb +13 -0
  279. data/spec/support/sudo.rb +16 -0
  280. data/spec/update/gems_spec.rb +201 -0
  281. data/spec/update/git_spec.rb +236 -0
  282. data/spec/update/source_spec.rb +63 -0
  283. data/spec/update/svn_spec.rb +100 -0
  284. metadata +486 -0
@@ -0,0 +1,27 @@
1
+ module Bundler
2
+ class CLI::Viz
3
+ attr_reader :options, :gem_name
4
+ def initialize(options)
5
+ @options = options
6
+ end
7
+
8
+ def run
9
+ require 'graphviz'
10
+ output_file = File.expand_path(options[:file])
11
+ graph = Graph.new(Bundler.load, output_file, options[:version], options[:requirements], options[:format], options[:without])
12
+ graph.viz
13
+ rescue LoadError => e
14
+ Bundler.ui.error e.inspect
15
+ Bundler.ui.warn "Make sure you have the graphviz ruby gem. You can install it with:"
16
+ Bundler.ui.warn "`gem install ruby-graphviz`"
17
+ rescue StandardError => e
18
+ if e.message =~ /GraphViz not installed or dot not in PATH/
19
+ Bundler.ui.error e.message
20
+ Bundler.ui.warn "Please install GraphViz. On a Mac with homebrew, you can run `brew install graphviz`."
21
+ else
22
+ raise
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Bundler
2
+ WINDOWS = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
3
+ FREEBSD = RbConfig::CONFIG["host_os"] =~ /bsd/
4
+ NULL = WINDOWS ? "NUL" : "/dev/null"
5
+ end
@@ -0,0 +1,155 @@
1
+ module Bundler
2
+ # Returns current version of Ruby
3
+ #
4
+ # @return [CurrentRuby] Current version of Ruby
5
+ def self.current_ruby
6
+ @current_ruby ||= CurrentRuby.new
7
+ end
8
+
9
+ class CurrentRuby
10
+ def on_18?
11
+ RUBY_VERSION =~ /^1\.8/
12
+ end
13
+
14
+ def on_19?
15
+ RUBY_VERSION =~ /^1\.9/
16
+ end
17
+
18
+ def on_20?
19
+ RUBY_VERSION =~ /^2\.0/
20
+ end
21
+
22
+ def on_21?
23
+ RUBY_VERSION =~ /^2\.1/
24
+ end
25
+
26
+ def ruby?
27
+ !mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "rbx" || RUBY_ENGINE == "maglev")
28
+ end
29
+
30
+ def ruby_18?
31
+ ruby? && on_18?
32
+ end
33
+
34
+ def ruby_19?
35
+ ruby? && on_19?
36
+ end
37
+
38
+ def ruby_20?
39
+ ruby? && on_20?
40
+ end
41
+
42
+ def ruby_21?
43
+ ruby? && on_21?
44
+ end
45
+
46
+ def mri?
47
+ !mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby")
48
+ end
49
+
50
+ def mri_18?
51
+ mri? && on_18?
52
+ end
53
+
54
+ def mri_19?
55
+ mri? && on_19?
56
+ end
57
+
58
+ def mri_20?
59
+ mri? && on_20?
60
+ end
61
+
62
+ def mri_21?
63
+ mri? && on_21?
64
+ end
65
+
66
+ def rbx?
67
+ ruby? && defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
68
+ end
69
+
70
+ def jruby?
71
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
72
+ end
73
+
74
+ def jruby_18?
75
+ jruby? && on_18?
76
+ end
77
+
78
+ def jruby_19?
79
+ jruby? && on_19?
80
+ end
81
+
82
+ def maglev?
83
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "maglev"
84
+ end
85
+
86
+ def mswin?
87
+ Bundler::WINDOWS
88
+ end
89
+
90
+ def mswin_18?
91
+ mswin? && on_18?
92
+ end
93
+
94
+ def mswin_19?
95
+ mswin? && on_19?
96
+ end
97
+
98
+ def mswin_20?
99
+ mswin? && on_20?
100
+ end
101
+
102
+ def mswin_21?
103
+ mswin? && on_21?
104
+ end
105
+
106
+ def mswin64?
107
+ Bundler::WINDOWS && Gem::Platform.local.os == "mswin64" && Gem::Platform.local.cpu == 'x64'
108
+ end
109
+
110
+ def mswin64_19?
111
+ mswin64? && on_19?
112
+ end
113
+
114
+ def mswin64_20?
115
+ mswin64? && on_20?
116
+ end
117
+
118
+ def mswin64_21?
119
+ mswin64? && on_21?
120
+ end
121
+
122
+ def mingw?
123
+ Bundler::WINDOWS && Gem::Platform.local.os == "mingw32" && Gem::Platform.local.cpu != 'x64'
124
+ end
125
+
126
+ def mingw_18?
127
+ mingw? && on_18?
128
+ end
129
+
130
+ def mingw_19?
131
+ mingw? && on_19?
132
+ end
133
+
134
+ def mingw_20?
135
+ mingw? && on_20?
136
+ end
137
+
138
+ def mingw_21?
139
+ mingw? && on_21?
140
+ end
141
+
142
+ def x64_mingw?
143
+ Bundler::WINDOWS && Gem::Platform.local.os == "mingw32" && Gem::Platform.local.cpu == 'x64'
144
+ end
145
+
146
+ def x64_mingw_20?
147
+ x64_mingw? && on_20?
148
+ end
149
+
150
+ def x64_mingw_21?
151
+ x64_mingw? && on_21?
152
+ end
153
+
154
+ end
155
+ end
@@ -0,0 +1,604 @@
1
+ require "digest/sha1"
2
+ require "set"
3
+
4
+ module Bundler
5
+ class Definition
6
+ include GemHelpers
7
+
8
+ attr_reader :dependencies, :platforms, :sources, :ruby_version,
9
+ :locked_deps
10
+
11
+ # Given a gemfile and lockfile creates a Bundler definition
12
+ #
13
+ # @param gemfile [Pathname] Path to Gemfile
14
+ # @param lockfile [Pathname,nil] Path to Gemfile.lock
15
+ # @param unlock [Hash, Boolean, nil] Gems that have been requested
16
+ # to be updated or true if all gems should be updated
17
+ # @return [Bundler::Definition]
18
+ def self.build(gemfile, lockfile, unlock)
19
+ unlock ||= {}
20
+ gemfile = Pathname.new(gemfile).expand_path
21
+
22
+ unless gemfile.file?
23
+ raise GemfileNotFound, "#{gemfile} not found"
24
+ end
25
+
26
+ Dsl.evaluate(gemfile, lockfile, unlock)
27
+ end
28
+
29
+
30
+ #
31
+ # How does the new system work?
32
+ #
33
+ # * Load information from Gemfile and Lockfile
34
+ # * Invalidate stale locked specs
35
+ # * All specs from stale source are stale
36
+ # * All specs that are reachable only through a stale
37
+ # dependency are stale.
38
+ # * If all fresh dependencies are satisfied by the locked
39
+ # specs, then we can try to resolve locally.
40
+ #
41
+ # @param lockfile [Pathname] Path to Gemfile.lock
42
+ # @param dependencies [Array(Bundler::Dependency)] array of dependencies from Gemfile
43
+ # @param sources [Array(Bundler::Source::Rubygems)]
44
+ # @param unlock [Hash, Boolean, nil] Gems that have been requested
45
+ # to be updated or true if all gems should be updated
46
+ # @param ruby_version [Bundler::RubyVersion, nil] Requested Ruby Version
47
+ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil)
48
+ @unlocking = unlock == true || !unlock.empty?
49
+
50
+ @dependencies, @sources, @unlock = dependencies, sources, unlock
51
+ @remote = false
52
+ @specs = nil
53
+ @lockfile_contents = ""
54
+ @ruby_version = ruby_version
55
+
56
+ if lockfile && File.exist?(lockfile)
57
+ @lockfile_contents = Bundler.read_file(lockfile)
58
+ locked = LockfileParser.new(@lockfile_contents)
59
+ @platforms = locked.platforms
60
+
61
+ if unlock != true
62
+ @locked_deps = locked.dependencies
63
+ @locked_specs = SpecSet.new(locked.specs)
64
+ @locked_sources = locked.sources
65
+ else
66
+ @unlock = {}
67
+ @locked_deps = []
68
+ @locked_specs = SpecSet.new([])
69
+ @locked_sources = []
70
+ end
71
+ else
72
+ @unlock = {}
73
+ @platforms = []
74
+ @locked_deps = []
75
+ @locked_specs = SpecSet.new([])
76
+ @locked_sources = []
77
+ end
78
+
79
+ @unlock[:gems] ||= []
80
+ @unlock[:sources] ||= []
81
+
82
+ current_platform = Bundler.rubygems.platforms.map { |p| generic(p) }.compact.last
83
+ @new_platform = !@platforms.include?(current_platform)
84
+ @platforms |= [current_platform]
85
+
86
+ @path_changes = converge_paths
87
+ eager_unlock = expand_dependencies(@unlock[:gems])
88
+ @unlock[:gems] = @locked_specs.for(eager_unlock).map { |s| s.name }
89
+
90
+ @source_changes = converge_sources
91
+ @dependency_changes = converge_dependencies
92
+ @local_changes = converge_locals
93
+
94
+ fixup_dependency_types!
95
+ end
96
+
97
+ def fixup_dependency_types!
98
+ # XXX This is a temporary workaround for a bug when using rubygems 1.8.15
99
+ # where Gem::Dependency#== matches Gem::Dependency#type. As the lockfile
100
+ # doesn't carry a notion of the dependency type, if you use
101
+ # add_development_dependency in a gemspec that's loaded with the gemspec
102
+ # directive, the lockfile dependencies and resolved dependencies end up
103
+ # with a mismatch on #type.
104
+ # Test coverage to catch a regression on this is in gemspec_spec.rb
105
+ @dependencies.each do |d|
106
+ if ld = @locked_deps.find { |l| l.name == d.name }
107
+ ld.instance_variable_set(:@type, d.type)
108
+ end
109
+ end
110
+ end
111
+
112
+ def resolve_with_cache!
113
+ raise "Specs already loaded" if @specs
114
+ @sources.each { |s| s.cached! }
115
+ specs
116
+ end
117
+
118
+ def resolve_remotely!
119
+ raise "Specs already loaded" if @specs
120
+ @remote = true
121
+ @sources.each { |s| s.remote! }
122
+ specs
123
+ end
124
+
125
+ # For given dependency list returns a SpecSet with Gemspec of all the required
126
+ # dependencies.
127
+ # 1. The method first resolves the dependencies specified in Gemfile
128
+ # 2. After that it tries and fetches gemspec of resolved dependencies
129
+ #
130
+ # @return [Bundler::SpecSet]
131
+ def specs
132
+ @specs ||= begin
133
+ specs = resolve.materialize(requested_dependencies)
134
+
135
+ unless specs["bundler"].any?
136
+ local = Bundler.settings[:frozen] ? rubygems_index : index
137
+ bundler = local.search(Gem::Dependency.new('bundler', VERSION)).last
138
+ specs["bundler"] = bundler if bundler
139
+ end
140
+
141
+ specs
142
+ end
143
+ end
144
+
145
+ def new_specs
146
+ specs - @locked_specs
147
+ end
148
+
149
+ def removed_specs
150
+ @locked_specs - specs
151
+ end
152
+
153
+ def new_platform?
154
+ @new_platform
155
+ end
156
+
157
+ def missing_specs
158
+ missing = []
159
+ resolve.materialize(requested_dependencies, missing)
160
+ missing
161
+ end
162
+
163
+ def requested_specs
164
+ @requested_specs ||= begin
165
+ groups = self.groups - Bundler.settings.without
166
+ groups.map! { |g| g.to_sym }
167
+ specs_for(groups)
168
+ end
169
+ end
170
+
171
+ def current_dependencies
172
+ dependencies.reject { |d| !d.should_include? }
173
+ end
174
+
175
+ def specs_for(groups)
176
+ deps = dependencies.select { |d| (d.groups & groups).any? }
177
+ deps.delete_if { |d| !d.should_include? }
178
+ specs.for(expand_dependencies(deps))
179
+ end
180
+
181
+ # Resolve all the dependencies specified in Gemfile. It ensures that
182
+ # dependencies that have been already resolved via locked file and are fresh
183
+ # are reused when resolving dependencies
184
+ #
185
+ # @return [SpecSet] resolved dependencies
186
+ def resolve
187
+ @resolve ||= begin
188
+ if Bundler.settings[:frozen] || (!@unlocking && nothing_changed?)
189
+ @locked_specs
190
+ else
191
+ last_resolve = converge_locked_specs
192
+
193
+ # Record the specs available in each gem's source, so that those
194
+ # specs will be available later when the resolver knows where to
195
+ # look for that gemspec (or its dependencies)
196
+ source_requirements = {}
197
+ dependencies.each do |dep|
198
+ next unless dep.source
199
+ source_requirements[dep.name] = dep.source.specs
200
+ end
201
+
202
+ # Run a resolve against the locally available gems
203
+ last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve)
204
+ end
205
+ end
206
+ end
207
+
208
+ def index
209
+ @index ||= Index.build do |idx|
210
+ dependency_names = @dependencies.dup || []
211
+ dependency_names.map! {|d| d.name }
212
+
213
+ @sources.each do |s|
214
+ if s.is_a?(Bundler::Source::Rubygems)
215
+ s.dependency_names = dependency_names.uniq
216
+ idx.add_source s.specs
217
+ else
218
+ source_index = s.specs
219
+ dependency_names += source_index.unmet_dependency_names
220
+ idx.add_source source_index
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ # used when frozen is enabled so we can find the bundler
227
+ # spec, even if (say) a git gem is not checked out.
228
+ def rubygems_index
229
+ @rubygems_index ||= Index.build do |idx|
230
+ rubygems = @sources.find{|s| s.is_a?(Source::Rubygems) }
231
+ idx.add_source rubygems.specs
232
+ end
233
+ end
234
+
235
+ def rubygems_remotes
236
+ @sources.select{|s| s.is_a?(Source::Rubygems) }.map{|s| s.remotes }.flatten
237
+ end
238
+
239
+ def groups
240
+ dependencies.map { |d| d.groups }.flatten.uniq
241
+ end
242
+
243
+ def lock(file)
244
+ contents = to_lock
245
+
246
+ # Convert to \r\n if the existing lock has them
247
+ # i.e., Windows with `git config core.autocrlf=true`
248
+ contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match("\r\n")
249
+
250
+ return if @lockfile_contents == contents
251
+
252
+ if Bundler.settings[:frozen]
253
+ Bundler.ui.error "Cannot write a changed lockfile while frozen."
254
+ return
255
+ end
256
+
257
+ File.open(file, 'wb'){|f| f.puts(contents) }
258
+ rescue Errno::EACCES
259
+ raise Bundler::InstallError,
260
+ "There was an error while trying to write to Gemfile.lock. It is likely that \n" \
261
+ "you need to allow write permissions for the file at path: \n" \
262
+ "#{File.expand_path(file)}"
263
+ end
264
+
265
+ def to_lock
266
+ out = ""
267
+
268
+ sorted_sources.each do |source|
269
+ # Add the source header
270
+ out << source.to_lock
271
+ # Find all specs for this source
272
+ resolve.
273
+ select { |s| s.source == source }.
274
+ # This needs to be sorted by full name so that
275
+ # gems with the same name, but different platform
276
+ # are ordered consistently
277
+ sort_by { |s| s.full_name }.
278
+ each do |spec|
279
+ next if spec.name == 'bundler'
280
+ out << spec.to_lock
281
+ end
282
+ out << "\n"
283
+ end
284
+
285
+ out << "PLATFORMS\n"
286
+
287
+ platforms.map { |p| p.to_s }.sort.each do |p|
288
+ out << " #{p}\n"
289
+ end
290
+
291
+ out << "\n"
292
+ out << "DEPENDENCIES\n"
293
+
294
+ handled = []
295
+ dependencies.
296
+ sort_by { |d| d.to_s }.
297
+ each do |dep|
298
+ next if handled.include?(dep.name)
299
+ out << dep.to_lock
300
+ handled << dep.name
301
+ end
302
+
303
+ out
304
+ end
305
+
306
+ def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
307
+ changes = false
308
+
309
+ msg = "You are trying to install in deployment mode after changing\n" \
310
+ "your Gemfile. Run `bundle install` elsewhere and add the\n" \
311
+ "updated Gemfile.lock to version control."
312
+
313
+ unless explicit_flag
314
+ msg += "\n\nIf this is a development machine, remove the Gemfile " \
315
+ "freeze \nby running `bundle install --no-deployment`."
316
+ end
317
+
318
+ added = []
319
+ deleted = []
320
+ changed = []
321
+
322
+ if @locked_sources != @sources
323
+ new_sources = @sources - @locked_sources
324
+ deleted_sources = @locked_sources - @sources
325
+
326
+ if new_sources.any?
327
+ added.concat new_sources.map { |source| "* source: #{source}" }
328
+ end
329
+
330
+ if deleted_sources.any?
331
+ deleted.concat deleted_sources.map { |source| "* source: #{source}" }
332
+ end
333
+
334
+ changes = true
335
+ end
336
+
337
+ both_sources = Hash.new { |h,k| h[k] = ["no specified source", "no specified source"] }
338
+ @dependencies.each { |d| both_sources[d.name][0] = d.source if d.source }
339
+ @locked_deps.each { |d| both_sources[d.name][1] = d.source if d.source }
340
+ both_sources.delete_if { |k,v| v[0] == v[1] }
341
+
342
+ if @dependencies != @locked_deps
343
+ new_deps = @dependencies - @locked_deps
344
+ deleted_deps = @locked_deps - @dependencies
345
+
346
+ if new_deps.any?
347
+ added.concat new_deps.map { |d| "* #{pretty_dep(d)}" }
348
+ end
349
+
350
+ if deleted_deps.any?
351
+ deleted.concat deleted_deps.map { |d| "* #{pretty_dep(d)}" }
352
+ end
353
+
354
+ both_sources.each do |name, sources|
355
+ changed << "* #{name} from `#{sources[0]}` to `#{sources[1]}`"
356
+ end
357
+
358
+ changes = true
359
+ end
360
+
361
+ msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any?
362
+ msg << "\n\nYou have deleted from the Gemfile:\n" << deleted.join("\n") if deleted.any?
363
+ msg << "\n\nYou have changed in the Gemfile:\n" << changed.join("\n") if changed.any?
364
+ msg << "\n"
365
+
366
+ raise ProductionError, msg if added.any? || deleted.any? || changed.any?
367
+ end
368
+
369
+ def validate_ruby!
370
+ return unless ruby_version
371
+
372
+ if diff = ruby_version.diff(Bundler.ruby_version)
373
+ problem, expected, actual = diff
374
+
375
+ msg = case problem
376
+ when :engine
377
+ "Your Ruby engine is #{actual}, but your Gemfile specified #{expected}"
378
+ when :version
379
+ "Your Ruby version is #{actual}, but your Gemfile specified #{expected}"
380
+ when :engine_version
381
+ "Your #{Bundler.ruby_version.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}"
382
+ when :patchlevel
383
+ if !expected.is_a?(String)
384
+ "The Ruby patchlevel in your Gemfile must be a string"
385
+ else
386
+ "Your Ruby patchlevel is #{actual}, but your Gemfile specified #{expected}"
387
+ end
388
+ end
389
+
390
+ raise RubyVersionMismatch, msg
391
+ end
392
+ end
393
+
394
+ private
395
+
396
+ def nothing_changed?
397
+ !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes
398
+ end
399
+
400
+ def pretty_dep(dep, source = false)
401
+ msg = "#{dep.name}"
402
+ msg << " (#{dep.requirement})" unless dep.requirement == Gem::Requirement.default
403
+ msg << " from the `#{dep.source}` source" if source && dep.source
404
+ msg
405
+ end
406
+
407
+ # Check if the specs of the given source changed
408
+ # according to the locked source. A block should be
409
+ # in order to specify how the locked version of
410
+ # the source should be found.
411
+ def specs_changed?(source, &block)
412
+ locked = @locked_sources.find(&block)
413
+
414
+ if locked
415
+ unlocking = @locked_specs.any? do |locked_spec|
416
+ locked_spec.source != locked
417
+ end
418
+ end
419
+
420
+ !locked || unlocking || source.specs != locked.specs
421
+ end
422
+
423
+ # Get all locals and override their matching sources.
424
+ # Return true if any of the locals changed (for example,
425
+ # they point to a new revision) or depend on new specs.
426
+ def converge_locals
427
+ locals = []
428
+
429
+ Bundler.settings.local_overrides.map do |k,v|
430
+ spec = @dependencies.find { |s| s.name == k }
431
+ source = spec && spec.source
432
+ if source && source.respond_to?(:local_override!)
433
+ source.unlock! if @unlock[:gems].include?(spec.name)
434
+ locals << [ source, source.local_override!(v) ]
435
+ end
436
+ end
437
+
438
+ locals.any? do |source, changed|
439
+ changed || specs_changed?(source) { |o| source.class == o.class && source.uri == o.uri }
440
+ end
441
+ end
442
+
443
+ def converge_paths
444
+ @sources.any? do |source|
445
+ next unless source.instance_of?(Source::Path)
446
+ specs_changed?(source) do |ls|
447
+ ls.class == source.class && ls.path == source.path
448
+ end
449
+ end
450
+ end
451
+
452
+ def converge_sources
453
+ changes = false
454
+
455
+ # Get the Rubygems source from the Gemfile.lock
456
+ locked_gem = @locked_sources.find { |s| s.kind_of?(Source::Rubygems) }
457
+
458
+ # Get the Rubygems source from the Gemfile
459
+ actual_gem = @sources.find { |s| s.kind_of?(Source::Rubygems) }
460
+
461
+ # If there is a Rubygems source in both
462
+ if locked_gem && actual_gem
463
+ # Merge the remotes from the Gemfile into the Gemfile.lock
464
+ changes = changes | locked_gem.replace_remotes(actual_gem)
465
+ end
466
+
467
+ # Replace the sources from the Gemfile with the sources from the Gemfile.lock,
468
+ # if they exist in the Gemfile.lock and are `==`. If you can't find an equivalent
469
+ # source in the Gemfile.lock, use the one from the Gemfile.
470
+ @sources.map! do |source|
471
+ @locked_sources.find { |s| s == source } || source
472
+ end
473
+ changes = changes | (Set.new(@sources) != Set.new(@locked_sources))
474
+
475
+ @sources.each do |source|
476
+ # If the source is unlockable and the current command allows an unlock of
477
+ # the source (for example, you are doing a `bundle update <foo>` of a git-pinned
478
+ # gem), unlock it. For git sources, this means to unlock the revision, which
479
+ # will cause the `ref` used to be the most recent for the branch (or master) if
480
+ # an explicit `ref` is not used.
481
+ if source.respond_to?(:unlock!) && @unlock[:sources].include?(source.name)
482
+ source.unlock!
483
+ changes = true
484
+ end
485
+ end
486
+
487
+ changes
488
+ end
489
+
490
+ def converge_dependencies
491
+ (@dependencies + @locked_deps).each do |dep|
492
+ if dep.source
493
+ dep.source = @sources.find { |s| dep.source == s }
494
+ end
495
+ end
496
+ Set.new(@dependencies) != Set.new(@locked_deps)
497
+ end
498
+
499
+ # Remove elements from the locked specs that are expired. This will most
500
+ # commonly happen if the Gemfile has changed since the lockfile was last
501
+ # generated
502
+ def converge_locked_specs
503
+ deps = []
504
+
505
+ # Build a list of dependencies that are the same in the Gemfile
506
+ # and Gemfile.lock. If the Gemfile modified a dependency, but
507
+ # the gem in the Gemfile.lock still satisfies it, this is fine
508
+ # too.
509
+ locked_deps_hash = @locked_deps.inject({}) { |hsh, dep| hsh[dep] = dep; hsh }
510
+ @dependencies.each do |dep|
511
+ locked_dep = locked_deps_hash[dep]
512
+
513
+ if in_locked_deps?(dep, locked_dep) || satisfies_locked_spec?(dep)
514
+ deps << dep
515
+ elsif dep.source.is_a?(Source::Path) && dep.current_platform? && (!locked_dep || dep.source != locked_dep.source)
516
+ @locked_specs.each do |s|
517
+ @unlock[:gems] << s.name if s.source == dep.source
518
+ end
519
+
520
+ dep.source.unlock! if dep.source.respond_to?(:unlock!)
521
+ dep.source.specs.each { |s| @unlock[:gems] << s.name }
522
+ end
523
+ end
524
+
525
+ converged = []
526
+ @locked_specs.each do |s|
527
+ s.source = @sources.find { |src| s.source == src }
528
+
529
+ # Don't add a spec to the list if its source is expired. For example,
530
+ # if you change a Git gem to Rubygems.
531
+ next if s.source.nil? || @unlock[:sources].include?(s.name)
532
+ # If the spec is from a path source and it doesn't exist anymore
533
+ # then we just unlock it.
534
+
535
+ # Path sources have special logic
536
+ if s.source.instance_of?(Source::Path)
537
+ other = s.source.specs[s].first
538
+
539
+ # If the spec is no longer in the path source, unlock it. This
540
+ # commonly happens if the version changed in the gemspec
541
+ next unless other
542
+
543
+ deps2 = other.dependencies.select { |d| d.type != :development }
544
+ # If the dependencies of the path source have changed, unlock it
545
+ next unless s.dependencies.sort == deps2.sort
546
+ end
547
+
548
+ converged << s
549
+ end
550
+
551
+ resolve = SpecSet.new(converged)
552
+ resolve = resolve.for(expand_dependencies(deps, true), @unlock[:gems])
553
+ diff = @locked_specs.to_a - resolve.to_a
554
+
555
+ # Now, we unlock any sources that do not have anymore gems pinned to it
556
+ @sources.each do |source|
557
+ next unless source.respond_to?(:unlock!)
558
+
559
+ unless resolve.any? { |s| s.source == source }
560
+ source.unlock! if !diff.empty? && diff.any? { |s| s.source == source }
561
+ end
562
+ end
563
+
564
+ resolve
565
+ end
566
+
567
+ def in_locked_deps?(dep, d)
568
+ d && dep.source == d.source
569
+ end
570
+
571
+ def satisfies_locked_spec?(dep)
572
+ @locked_specs.any? { |s| s.satisfies?(dep) && (!dep.source || s.source == dep.source) }
573
+ end
574
+
575
+ def expanded_dependencies
576
+ @expanded_dependencies ||= expand_dependencies(dependencies, @remote)
577
+ end
578
+
579
+ def expand_dependencies(dependencies, remote = false)
580
+ deps = []
581
+ dependencies.each do |dep|
582
+ dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name)
583
+ next unless remote || dep.current_platform?
584
+ dep.gem_platforms(@platforms).each do |p|
585
+ deps << DepProxy.new(dep, p) if remote || p == generic(Gem::Platform.local)
586
+ end
587
+ end
588
+ deps
589
+ end
590
+
591
+ def sorted_sources
592
+ @sources.sort_by do |s|
593
+ # Place GEM at the top
594
+ [ s.is_a?(Source::Rubygems) ? 1 : 0, s.to_s ]
595
+ end
596
+ end
597
+
598
+ def requested_dependencies
599
+ groups = self.groups - Bundler.settings.without
600
+ groups.map! { |g| g.to_sym }
601
+ dependencies.reject { |d| !d.should_include? || (d.groups & groups).empty? }
602
+ end
603
+ end
604
+ end