rkh-bundler 1.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/.gitignore +22 -0
  2. data/.travis.yml +42 -0
  3. data/CHANGELOG.md +1105 -0
  4. data/ISSUES.md +67 -0
  5. data/LICENSE +23 -0
  6. data/README.md +31 -0
  7. data/Rakefile +208 -0
  8. data/UPGRADING.md +103 -0
  9. data/bin/bundle +31 -0
  10. data/bundler.gemspec +31 -0
  11. data/lib/bundler.rb +353 -0
  12. data/lib/bundler/capistrano.rb +11 -0
  13. data/lib/bundler/cli.rb +693 -0
  14. data/lib/bundler/definition.rb +568 -0
  15. data/lib/bundler/dep_proxy.rb +43 -0
  16. data/lib/bundler/dependency.rb +134 -0
  17. data/lib/bundler/deployment.rb +58 -0
  18. data/lib/bundler/dsl.rb +256 -0
  19. data/lib/bundler/endpoint_specification.rb +78 -0
  20. data/lib/bundler/environment.rb +47 -0
  21. data/lib/bundler/fetcher.rb +225 -0
  22. data/lib/bundler/gem_helper.rb +162 -0
  23. data/lib/bundler/gem_helpers.rb +23 -0
  24. data/lib/bundler/gem_installer.rb +9 -0
  25. data/lib/bundler/gem_tasks.rb +2 -0
  26. data/lib/bundler/graph.rb +148 -0
  27. data/lib/bundler/index.rb +187 -0
  28. data/lib/bundler/installer.rb +190 -0
  29. data/lib/bundler/lazy_specification.rb +79 -0
  30. data/lib/bundler/lockfile_parser.rb +127 -0
  31. data/lib/bundler/match_platform.rb +13 -0
  32. data/lib/bundler/psyched_yaml.rb +15 -0
  33. data/lib/bundler/remote_specification.rb +57 -0
  34. data/lib/bundler/resolver.rb +486 -0
  35. data/lib/bundler/ruby_version.rb +94 -0
  36. data/lib/bundler/rubygems_ext.rb +153 -0
  37. data/lib/bundler/rubygems_integration.rb +394 -0
  38. data/lib/bundler/runtime.rb +233 -0
  39. data/lib/bundler/settings.rb +128 -0
  40. data/lib/bundler/setup.rb +23 -0
  41. data/lib/bundler/shared_helpers.rb +71 -0
  42. data/lib/bundler/source.rb +869 -0
  43. data/lib/bundler/spec_set.rb +137 -0
  44. data/lib/bundler/templates/Executable +16 -0
  45. data/lib/bundler/templates/Executable.standalone +12 -0
  46. data/lib/bundler/templates/Gemfile +4 -0
  47. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  48. data/lib/bundler/templates/newgem/LICENSE.tt +22 -0
  49. data/lib/bundler/templates/newgem/README.md.tt +29 -0
  50. data/lib/bundler/templates/newgem/Rakefile.tt +2 -0
  51. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  52. data/lib/bundler/templates/newgem/gitignore.tt +17 -0
  53. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +9 -0
  54. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  55. data/lib/bundler/templates/newgem/newgem.gemspec.tt +17 -0
  56. data/lib/bundler/ui.rb +88 -0
  57. data/lib/bundler/vendor/net/http/faster.rb +27 -0
  58. data/lib/bundler/vendor/net/http/persistent.rb +468 -0
  59. data/lib/bundler/vendor/thor.rb +358 -0
  60. data/lib/bundler/vendor/thor/actions.rb +314 -0
  61. data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
  62. data/lib/bundler/vendor/thor/actions/create_link.rb +57 -0
  63. data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
  64. data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
  65. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +270 -0
  66. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +109 -0
  67. data/lib/bundler/vendor/thor/base.rb +576 -0
  68. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
  69. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  70. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
  71. data/lib/bundler/vendor/thor/error.rb +30 -0
  72. data/lib/bundler/vendor/thor/group.rb +273 -0
  73. data/lib/bundler/vendor/thor/invocation.rb +168 -0
  74. data/lib/bundler/vendor/thor/parser.rb +4 -0
  75. data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
  76. data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
  77. data/lib/bundler/vendor/thor/parser/option.rb +120 -0
  78. data/lib/bundler/vendor/thor/parser/options.rb +172 -0
  79. data/lib/bundler/vendor/thor/rake_compat.rb +66 -0
  80. data/lib/bundler/vendor/thor/runner.rb +309 -0
  81. data/lib/bundler/vendor/thor/shell.rb +88 -0
  82. data/lib/bundler/vendor/thor/shell/basic.rb +302 -0
  83. data/lib/bundler/vendor/thor/shell/color.rb +108 -0
  84. data/lib/bundler/vendor/thor/shell/html.rb +121 -0
  85. data/lib/bundler/vendor/thor/task.rb +113 -0
  86. data/lib/bundler/vendor/thor/util.rb +229 -0
  87. data/lib/bundler/vendor/thor/version.rb +3 -0
  88. data/lib/bundler/vendored_thor.rb +7 -0
  89. data/lib/bundler/version.rb +6 -0
  90. data/lib/bundler/vlad.rb +11 -0
  91. data/man/bundle-config.ronn +130 -0
  92. data/man/bundle-exec.ronn +111 -0
  93. data/man/bundle-install.ronn +335 -0
  94. data/man/bundle-package.ronn +59 -0
  95. data/man/bundle-update.ronn +176 -0
  96. data/man/bundle.ronn +83 -0
  97. data/man/gemfile.5.ronn +324 -0
  98. data/man/index.txt +6 -0
  99. data/spec/bundler/dsl_spec.rb +48 -0
  100. data/spec/bundler/gem_helper_spec.rb +174 -0
  101. data/spec/bundler/source_spec.rb +25 -0
  102. data/spec/cache/gems_spec.rb +239 -0
  103. data/spec/cache/git_spec.rb +124 -0
  104. data/spec/cache/path_spec.rb +103 -0
  105. data/spec/cache/platform_spec.rb +57 -0
  106. data/spec/install/deploy_spec.rb +211 -0
  107. data/spec/install/gems/c_ext_spec.rb +48 -0
  108. data/spec/install/gems/dependency_api_spec.rb +402 -0
  109. data/spec/install/gems/env_spec.rb +107 -0
  110. data/spec/install/gems/flex_spec.rb +313 -0
  111. data/spec/install/gems/groups_spec.rb +268 -0
  112. data/spec/install/gems/packed_spec.rb +84 -0
  113. data/spec/install/gems/platform_spec.rb +208 -0
  114. data/spec/install/gems/post_install_spec.rb +47 -0
  115. data/spec/install/gems/resolving_spec.rb +72 -0
  116. data/spec/install/gems/simple_case_spec.rb +814 -0
  117. data/spec/install/gems/standalone_spec.rb +260 -0
  118. data/spec/install/gems/sudo_spec.rb +74 -0
  119. data/spec/install/gems/win32_spec.rb +26 -0
  120. data/spec/install/gemspec_spec.rb +170 -0
  121. data/spec/install/git_spec.rb +796 -0
  122. data/spec/install/invalid_spec.rb +35 -0
  123. data/spec/install/path_spec.rb +405 -0
  124. data/spec/install/upgrade_spec.rb +26 -0
  125. data/spec/lock/git_spec.rb +35 -0
  126. data/spec/lock/lockfile_spec.rb +809 -0
  127. data/spec/other/check_spec.rb +265 -0
  128. data/spec/other/clean_spec.rb +492 -0
  129. data/spec/other/config_spec.rb +138 -0
  130. data/spec/other/console_spec.rb +54 -0
  131. data/spec/other/exec_spec.rb +229 -0
  132. data/spec/other/ext_spec.rb +37 -0
  133. data/spec/other/help_spec.rb +39 -0
  134. data/spec/other/init_spec.rb +40 -0
  135. data/spec/other/newgem_spec.rb +87 -0
  136. data/spec/other/open_spec.rb +35 -0
  137. data/spec/other/outdated_spec.rb +93 -0
  138. data/spec/other/platform_spec.rb +881 -0
  139. data/spec/other/show_spec.rb +88 -0
  140. data/spec/quality_spec.rb +62 -0
  141. data/spec/realworld/edgecases_spec.rb +177 -0
  142. data/spec/resolver/basic_spec.rb +20 -0
  143. data/spec/resolver/platform_spec.rb +82 -0
  144. data/spec/runtime/executable_spec.rb +120 -0
  145. data/spec/runtime/load_spec.rb +107 -0
  146. data/spec/runtime/platform_spec.rb +90 -0
  147. data/spec/runtime/require_spec.rb +261 -0
  148. data/spec/runtime/setup_spec.rb +755 -0
  149. data/spec/runtime/with_clean_env_spec.rb +80 -0
  150. data/spec/spec_helper.rb +98 -0
  151. data/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb +13 -0
  152. data/spec/support/artifice/endpoint.rb +54 -0
  153. data/spec/support/artifice/endpoint_500.rb +37 -0
  154. data/spec/support/artifice/endpoint_api_missing.rb +16 -0
  155. data/spec/support/artifice/endpoint_basic_authentication.rb +13 -0
  156. data/spec/support/artifice/endpoint_extra.rb +27 -0
  157. data/spec/support/artifice/endpoint_extra_missing.rb +15 -0
  158. data/spec/support/artifice/endpoint_fallback.rb +18 -0
  159. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  160. data/spec/support/artifice/endpoint_redirect.rb +15 -0
  161. data/spec/support/builders.rb +604 -0
  162. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  163. data/spec/support/fakeweb/windows.rb +23 -0
  164. data/spec/support/helpers.rb +317 -0
  165. data/spec/support/indexes.rb +112 -0
  166. data/spec/support/matchers.rb +77 -0
  167. data/spec/support/path.rb +73 -0
  168. data/spec/support/platforms.rb +86 -0
  169. data/spec/support/ruby_ext.rb +20 -0
  170. data/spec/support/rubygems_ext.rb +37 -0
  171. data/spec/support/rubygems_hax/platform.rb +22 -0
  172. data/spec/support/sudo.rb +21 -0
  173. data/spec/update/gems_spec.rb +134 -0
  174. data/spec/update/git_spec.rb +196 -0
  175. data/spec/update/source_spec.rb +51 -0
  176. metadata +338 -0
@@ -0,0 +1,568 @@
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
+
10
+ def self.build(gemfile, lockfile, unlock)
11
+ unlock ||= {}
12
+ gemfile = Pathname.new(gemfile).expand_path
13
+
14
+ unless gemfile.file?
15
+ raise GemfileNotFound, "#{gemfile} not found"
16
+ end
17
+
18
+ Dsl.evaluate(gemfile, lockfile, unlock)
19
+ end
20
+
21
+ =begin
22
+ How does the new system work?
23
+ ===
24
+ * Load information from Gemfile and Lockfile
25
+ * Invalidate stale locked specs
26
+ * All specs from stale source are stale
27
+ * All specs that are reachable only through a stale
28
+ dependency are stale.
29
+ * If all fresh dependencies are satisfied by the locked
30
+ specs, then we can try to resolve locally.
31
+ =end
32
+
33
+ def initialize(lockfile, dependencies, sources, unlock, ruby_version = "")
34
+ @unlocking = unlock == true || !unlock.empty?
35
+
36
+ @dependencies, @sources, @unlock = dependencies, sources, unlock
37
+ @remote = false
38
+ @specs = nil
39
+ @lockfile_contents = ""
40
+ @ruby_version = ruby_version
41
+
42
+ if lockfile && File.exists?(lockfile)
43
+ @lockfile_contents = Bundler.read_file(lockfile)
44
+ locked = LockfileParser.new(@lockfile_contents)
45
+ @platforms = locked.platforms
46
+
47
+ if unlock != true
48
+ @locked_deps = locked.dependencies
49
+ @locked_specs = SpecSet.new(locked.specs)
50
+ @locked_sources = locked.sources
51
+ else
52
+ @unlock = {}
53
+ @locked_deps = []
54
+ @locked_specs = SpecSet.new([])
55
+ @locked_sources = []
56
+ end
57
+ else
58
+ @unlock = {}
59
+ @platforms = []
60
+ @locked_deps = []
61
+ @locked_specs = SpecSet.new([])
62
+ @locked_sources = []
63
+ end
64
+
65
+ @unlock[:gems] ||= []
66
+ @unlock[:sources] ||= []
67
+
68
+ current_platform = Bundler.rubygems.platforms.map { |p| generic(p) }.compact.last
69
+ @new_platform = !@platforms.include?(current_platform)
70
+ @platforms |= [current_platform]
71
+
72
+ @path_changes = converge_paths
73
+ eager_unlock = expand_dependencies(@unlock[:gems])
74
+ @unlock[:gems] = @locked_specs.for(eager_unlock).map { |s| s.name }
75
+
76
+ @source_changes = converge_sources
77
+ @dependency_changes = converge_dependencies
78
+ @local_changes = converge_locals
79
+
80
+ fixup_dependency_types!
81
+ end
82
+
83
+ def fixup_dependency_types!
84
+ # XXX This is a temporary workaround for a bug when using rubygems 1.8.15
85
+ # where Gem::Dependency#== matches Gem::Dependency#type. As the lockfile
86
+ # doesn't carry a notion of the dependency type, if you use
87
+ # add_development_dependency in a gemspec that's loaded with the gemspec
88
+ # directive, the lockfile dependencies and resolved dependencies end up
89
+ # with a mismatch on #type.
90
+ # Test coverage to catch a regression on this is in gemspec_spec.rb
91
+ @dependencies.each do |d|
92
+ if ld = @locked_deps.find { |l| l.name == d.name }
93
+ ld.instance_variable_set(:@type, d.type)
94
+ end
95
+ end
96
+ end
97
+
98
+ def resolve_with_cache!
99
+ raise "Specs already loaded" if @specs
100
+ @sources.each { |s| s.cached! }
101
+ specs
102
+ end
103
+
104
+ def resolve_remotely!
105
+ raise "Specs already loaded" if @specs
106
+ @remote = true
107
+ @sources.each { |s| s.remote! }
108
+ specs
109
+ end
110
+
111
+ def specs
112
+ @specs ||= begin
113
+ specs = resolve.materialize(requested_dependencies)
114
+
115
+ unless specs["bundler"].any?
116
+ local = Bundler.settings[:frozen] ? rubygems_index : index
117
+ bundler = local.search(Gem::Dependency.new('bundler', VERSION)).last
118
+ specs["bundler"] = bundler if bundler
119
+ end
120
+
121
+ specs
122
+ end
123
+ end
124
+
125
+ def new_specs
126
+ specs - @locked_specs
127
+ end
128
+
129
+ def removed_specs
130
+ @locked_specs - specs
131
+ end
132
+
133
+ def new_platform?
134
+ @new_platform
135
+ end
136
+
137
+ def missing_specs
138
+ missing = []
139
+ resolve.materialize(requested_dependencies, missing)
140
+ missing
141
+ end
142
+
143
+ def requested_specs
144
+ @requested_specs ||= begin
145
+ groups = self.groups - Bundler.settings.without
146
+ groups.map! { |g| g.to_sym }
147
+ specs_for(groups)
148
+ end
149
+ end
150
+
151
+ def current_dependencies
152
+ dependencies.reject { |d| !d.should_include? }
153
+ end
154
+
155
+ def specs_for(groups)
156
+ deps = dependencies.select { |d| (d.groups & groups).any? }
157
+ deps.delete_if { |d| !d.should_include? }
158
+ specs.for(expand_dependencies(deps))
159
+ end
160
+
161
+ def resolve
162
+ @resolve ||= begin
163
+ if Bundler.settings[:frozen] || (!@unlocking && nothing_changed?)
164
+ @locked_specs
165
+ else
166
+ last_resolve = converge_locked_specs
167
+
168
+ # Record the specs available in each gem's source, so that those
169
+ # specs will be available later when the resolver knows where to
170
+ # look for that gemspec (or its dependencies)
171
+ source_requirements = {}
172
+ dependencies.each do |dep|
173
+ next unless dep.source
174
+ source_requirements[dep.name] = dep.source.specs
175
+ end
176
+
177
+ # Run a resolve against the locally available gems
178
+ last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve)
179
+ end
180
+ end
181
+ end
182
+
183
+ def index
184
+ @index ||= Index.build do |idx|
185
+ dependency_names = @dependencies.dup || []
186
+ dependency_names.map! {|d| d.name }
187
+
188
+ @sources.each do |s|
189
+ if s.is_a?(Bundler::Source::Rubygems)
190
+ s.dependency_names = dependency_names.uniq
191
+ idx.add_source s.specs
192
+ else
193
+ source_index = s.specs
194
+ dependency_names += source_index.unmet_dependency_names
195
+ idx.add_source source_index
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ # used when frozen is enabled so we can find the bundler
202
+ # spec, even if (say) a git gem is not checked out.
203
+ def rubygems_index
204
+ @rubygems_index ||= Index.build do |idx|
205
+ rubygems = @sources.find{|s| s.is_a?(Source::Rubygems) }
206
+ idx.add_source rubygems.specs
207
+ end
208
+ end
209
+
210
+ def no_sources?
211
+ @sources.length == 1 && @sources.first.remotes.empty?
212
+ end
213
+
214
+ def groups
215
+ dependencies.map { |d| d.groups }.flatten.uniq
216
+ end
217
+
218
+ def lock(file)
219
+ contents = to_lock
220
+
221
+ # Convert to \r\n if the existing lock has them
222
+ # i.e., Windows with `git config core.autocrlf=true`
223
+ contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match("\r\n")
224
+
225
+ return if @lockfile_contents == contents
226
+
227
+ if Bundler.settings[:frozen]
228
+ # TODO: Warn here if we got here.
229
+ return
230
+ end
231
+
232
+ File.open(file, 'wb'){|f| f.puts(contents) }
233
+ end
234
+
235
+ def to_lock
236
+ out = ""
237
+
238
+ sorted_sources.each do |source|
239
+ # Add the source header
240
+ out << source.to_lock
241
+ # Find all specs for this source
242
+ resolve.
243
+ select { |s| s.source == source }.
244
+ # This needs to be sorted by full name so that
245
+ # gems with the same name, but different platform
246
+ # are ordered consistantly
247
+ sort_by { |s| s.full_name }.
248
+ each do |spec|
249
+ next if spec.name == 'bundler'
250
+ out << spec.to_lock
251
+ end
252
+ out << "\n"
253
+ end
254
+
255
+ out << "PLATFORMS\n"
256
+
257
+ platforms.map { |p| p.to_s }.sort.each do |p|
258
+ out << " #{p}\n"
259
+ end
260
+
261
+ out << "\n"
262
+ out << "DEPENDENCIES\n"
263
+
264
+ handled = []
265
+ dependencies.
266
+ sort_by { |d| d.to_s }.
267
+ each do |dep|
268
+ next if handled.include?(dep.name)
269
+ out << dep.to_lock
270
+ handled << dep.name
271
+ end
272
+
273
+ out
274
+ end
275
+
276
+ def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
277
+ changes = false
278
+
279
+ msg = "You are trying to install in deployment mode after changing\n" \
280
+ "your Gemfile. Run `bundle install` elsewhere and add the\n" \
281
+ "updated Gemfile.lock to version control."
282
+
283
+ unless explicit_flag
284
+ msg += "\n\nIf this is a development machine, remove the Gemfile " \
285
+ "freeze \nby running `bundle install --no-deployment`."
286
+ end
287
+
288
+ added = []
289
+ deleted = []
290
+ changed = []
291
+
292
+ if @locked_sources != @sources
293
+ new_sources = @sources - @locked_sources
294
+ deleted_sources = @locked_sources - @sources
295
+
296
+ if new_sources.any?
297
+ added.concat new_sources.map { |source| "* source: #{source}" }
298
+ end
299
+
300
+ if deleted_sources.any?
301
+ deleted.concat deleted_sources.map { |source| "* source: #{source}" }
302
+ end
303
+
304
+ changes = true
305
+ end
306
+
307
+ both_sources = Hash.new { |h,k| h[k] = ["no specified source", "no specified source"] }
308
+ @dependencies.each { |d| both_sources[d.name][0] = d.source if d.source }
309
+ @locked_deps.each { |d| both_sources[d.name][1] = d.source if d.source }
310
+ both_sources.delete_if { |k,v| v[0] == v[1] }
311
+
312
+ if @dependencies != @locked_deps
313
+ new_deps = @dependencies - @locked_deps
314
+ deleted_deps = @locked_deps - @dependencies
315
+
316
+ if new_deps.any?
317
+ added.concat new_deps.map { |d| "* #{pretty_dep(d)}" }
318
+ end
319
+
320
+ if deleted_deps.any?
321
+ deleted.concat deleted_deps.map { |d| "* #{pretty_dep(d)}" }
322
+ end
323
+
324
+ both_sources.each do |name, sources|
325
+ changed << "* #{name} from `#{sources[0]}` to `#{sources[1]}`"
326
+ end
327
+
328
+ changes = true
329
+ end
330
+
331
+ msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any?
332
+ msg << "\n\nYou have deleted from the Gemfile:\n" << deleted.join("\n") if deleted.any?
333
+ msg << "\n\nYou have changed in the Gemfile:\n" << changed.join("\n") if changed.any?
334
+ msg << "\n"
335
+
336
+ raise ProductionError, msg if added.any? || deleted.any? || changed.any?
337
+ end
338
+
339
+ def validate_ruby!
340
+ return unless ruby_version
341
+
342
+ system_ruby_version = Bundler::SystemRubyVersion.new
343
+ if diff = ruby_version.diff(system_ruby_version)
344
+ problem, expected, actual = diff
345
+
346
+ msg = case problem
347
+ when :engine
348
+ "Your Ruby engine is #{actual}, but your Gemfile specified #{expected}"
349
+ when :version
350
+ "Your Ruby version is #{actual}, but your Gemfile specified #{expected}"
351
+ when :engine_version
352
+ "Your #{system_ruby_version.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}"
353
+ end
354
+
355
+ raise RubyVersionMismatch, msg
356
+ end
357
+ end
358
+
359
+ private
360
+
361
+ def nothing_changed?
362
+ !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes
363
+ end
364
+
365
+ def pretty_dep(dep, source = false)
366
+ msg = "#{dep.name}"
367
+ msg << " (#{dep.requirement})" unless dep.requirement == Gem::Requirement.default
368
+ msg << " from the `#{dep.source}` source" if source && dep.source
369
+ msg
370
+ end
371
+
372
+ # Check if the specs of the given source changed
373
+ # according to the locked source. A block should be
374
+ # in order to specify how the locked version of
375
+ # the source should be found.
376
+ def specs_changed?(source, &block)
377
+ locked = @locked_sources.find(&block)
378
+
379
+ if locked
380
+ unlocking = locked.specs.any? do |spec|
381
+ @locked_specs.any? do |locked_spec|
382
+ locked_spec.source != locked
383
+ end
384
+ end
385
+ end
386
+
387
+ !locked || unlocking || source.specs != locked.specs
388
+ end
389
+
390
+ # Get all locals and override their matching sources.
391
+ # Return true if any of the locals changed (for example,
392
+ # they point to a new revision) or depend on new specs.
393
+ def converge_locals
394
+ locals = []
395
+
396
+ Bundler.settings.local_overrides.map do |k,v|
397
+ spec = @dependencies.find { |s| s.name == k }
398
+ source = spec && spec.source
399
+ if source && source.respond_to?(:local_override!)
400
+ locals << [ source, source.local_override!(v) ]
401
+ end
402
+ end
403
+
404
+ locals.any? do |source, changed|
405
+ changed || specs_changed?(source) { |o| source.class === o.class && source.uri == o.uri }
406
+ end
407
+ end
408
+
409
+ def converge_paths
410
+ @sources.any? do |source|
411
+ next unless source.instance_of?(Source::Path)
412
+ specs_changed?(source) do |ls|
413
+ ls.class == source.class && ls.path == source.path
414
+ end
415
+ end
416
+ end
417
+
418
+ def converge_sources
419
+ changes = false
420
+
421
+ # Get the Rubygems source from the Gemfile.lock
422
+ locked_gem = @locked_sources.find { |s| Source::Rubygems === s }
423
+
424
+ # Get the Rubygems source from the Gemfile
425
+ actual_gem = @sources.find { |s| Source::Rubygems === s }
426
+
427
+ # If there is a Rubygems source in both
428
+ if locked_gem && actual_gem
429
+ # Merge the remotes from the Gemfile into the Gemfile.lock
430
+ changes = changes | locked_gem.replace_remotes(actual_gem)
431
+ end
432
+
433
+ # Replace the sources from the Gemfile with the sources from the Gemfile.lock,
434
+ # if they exist in the Gemfile.lock and are `==`. If you can't find an equivalent
435
+ # source in the Gemfile.lock, use the one from the Gemfile.
436
+ @sources.map! do |source|
437
+ @locked_sources.find { |s| s == source } || source
438
+ end
439
+ changes = changes | (Set.new(@sources) != Set.new(@locked_sources))
440
+
441
+ @sources.each do |source|
442
+ # If the source is unlockable and the current command allows an unlock of
443
+ # the source (for example, you are doing a `bundle update <foo>` of a git-pinned
444
+ # gem), unlock it. For git sources, this means to unlock the revision, which
445
+ # will cause the `ref` used to be the most recent for the branch (or master) if
446
+ # an explicit `ref` is not used.
447
+ if source.respond_to?(:unlock!) && @unlock[:sources].include?(source.name)
448
+ source.unlock!
449
+ changes = true
450
+ end
451
+ end
452
+
453
+ changes
454
+ end
455
+
456
+ def converge_dependencies
457
+ (@dependencies + @locked_deps).each do |dep|
458
+ if dep.source
459
+ dep.source = @sources.find { |s| dep.source == s }
460
+ end
461
+ end
462
+ Set.new(@dependencies) != Set.new(@locked_deps)
463
+ end
464
+
465
+ # Remove elements from the locked specs that are expired. This will most
466
+ # commonly happen if the Gemfile has changed since the lockfile was last
467
+ # generated
468
+ def converge_locked_specs
469
+ deps = []
470
+
471
+ # Build a list of dependencies that are the same in the Gemfile
472
+ # and Gemfile.lock. If the Gemfile modified a dependency, but
473
+ # the gem in the Gemfile.lock still satisfies it, this is fine
474
+ # too.
475
+ @dependencies.each do |dep|
476
+ locked_dep = @locked_deps.find { |d| dep == d }
477
+
478
+ if in_locked_deps?(dep, locked_dep) || satisfies_locked_spec?(dep)
479
+ deps << dep
480
+ elsif dep.source.is_a?(Source::Path) && dep.current_platform? && (!locked_dep || dep.source != locked_dep.source)
481
+ @locked_specs.each do |s|
482
+ @unlock[:gems] << s.name if s.source == dep.source
483
+ end
484
+
485
+ dep.source.unlock! if dep.source.respond_to?(:unlock!)
486
+ dep.source.specs.each { |s| @unlock[:gems] << s.name }
487
+ end
488
+ end
489
+
490
+ converged = []
491
+ @locked_specs.each do |s|
492
+ s.source = @sources.find { |src| s.source == src }
493
+
494
+ # Don't add a spec to the list if its source is expired. For example,
495
+ # if you change a Git gem to Rubygems.
496
+ next if s.source.nil? || @unlock[:sources].include?(s.name)
497
+ # If the spec is from a path source and it doesn't exist anymore
498
+ # then we just unlock it.
499
+
500
+ # Path sources have special logic
501
+ if s.source.instance_of?(Source::Path)
502
+ other = s.source.specs[s].first
503
+
504
+ # If the spec is no longer in the path source, unlock it. This
505
+ # commonly happens if the version changed in the gemspec
506
+ next unless other
507
+
508
+ deps2 = other.dependencies.select { |d| d.type != :development }
509
+ # If the dependencies of the path source have changed, unlock it
510
+ next unless s.dependencies.sort == deps2.sort
511
+ end
512
+
513
+ converged << s
514
+ end
515
+
516
+ resolve = SpecSet.new(converged)
517
+ resolve = resolve.for(expand_dependencies(deps, true), @unlock[:gems])
518
+ diff = @locked_specs.to_a - resolve.to_a
519
+
520
+ # Now, we unlock any sources that do not have anymore gems pinned to it
521
+ @sources.each do |source|
522
+ next unless source.respond_to?(:unlock!)
523
+
524
+ unless resolve.any? { |s| s.source == source }
525
+ source.unlock! if !diff.empty? && diff.any? { |s| s.source == source }
526
+ end
527
+ end
528
+
529
+ resolve
530
+ end
531
+
532
+ def in_locked_deps?(dep, d)
533
+ d && dep.source == d.source
534
+ end
535
+
536
+ def satisfies_locked_spec?(dep)
537
+ @locked_specs.any? { |s| s.satisfies?(dep) && (!dep.source || s.source == dep.source) }
538
+ end
539
+
540
+ def expanded_dependencies
541
+ @expanded_dependencies ||= expand_dependencies(dependencies, @remote)
542
+ end
543
+
544
+ def expand_dependencies(dependencies, remote = false)
545
+ deps = []
546
+ dependencies.each do |dep|
547
+ dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name)
548
+ dep.gem_platforms(@platforms).each do |p|
549
+ deps << DepProxy.new(dep, p) if remote || p == generic(Gem::Platform.local)
550
+ end
551
+ end
552
+ deps
553
+ end
554
+
555
+ def sorted_sources
556
+ @sources.sort_by do |s|
557
+ # Place GEM at the top
558
+ [ s.is_a?(Source::Rubygems) ? 1 : 0, s.to_s ]
559
+ end
560
+ end
561
+
562
+ def requested_dependencies
563
+ groups = self.groups - Bundler.settings.without
564
+ groups.map! { |g| g.to_sym }
565
+ dependencies.reject { |d| !d.should_include? || (d.groups & groups).empty? }
566
+ end
567
+ end
568
+ end