rubygems-update 2.4.4 → 2.4.5

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

Potentially problematic release.


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

Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.rdoc +58 -0
  3. data/History.txt +42 -0
  4. data/Manifest.txt +1 -1
  5. data/lib/rubygems.rb +8 -2
  6. data/lib/rubygems/basic_specification.rb +52 -22
  7. data/lib/rubygems/commands/contents_command.rb +0 -1
  8. data/lib/rubygems/commands/pristine_command.rb +15 -1
  9. data/lib/rubygems/commands/uninstall_command.rb +1 -1
  10. data/lib/rubygems/commands/update_command.rb +0 -2
  11. data/lib/rubygems/core_ext/kernel_gem.rb +8 -1
  12. data/lib/rubygems/core_ext/kernel_require.rb +1 -1
  13. data/lib/rubygems/dependency.rb +1 -1
  14. data/lib/rubygems/dependency_list.rb +1 -5
  15. data/lib/rubygems/ext/ext_conf_builder.rb +1 -1
  16. data/lib/rubygems/indexer.rb +1 -1
  17. data/lib/rubygems/installer.rb +2 -2
  18. data/lib/rubygems/package/old.rb +2 -2
  19. data/lib/rubygems/package/tar_writer.rb +9 -3
  20. data/lib/rubygems/remote_fetcher.rb +5 -1
  21. data/lib/rubygems/request/connection_pools.rb +5 -1
  22. data/lib/rubygems/request/http_pool.rb +9 -0
  23. data/lib/rubygems/request_set.rb +1 -4
  24. data/lib/rubygems/request_set/lockfile.rb +21 -8
  25. data/lib/rubygems/resolver/api_set.rb +1 -1
  26. data/lib/rubygems/resolver/api_specification.rb +1 -1
  27. data/lib/rubygems/resolver/installer_set.rb +1 -1
  28. data/lib/rubygems/source.rb +6 -2
  29. data/lib/rubygems/specification.rb +10 -2
  30. data/lib/rubygems/stub_specification.rb +11 -5
  31. data/lib/rubygems/test_case.rb +31 -0
  32. data/lib/rubygems/text.rb +2 -2
  33. data/lib/rubygems/user_interaction.rb +0 -1
  34. data/test/rubygems/test_gem.rb +15 -32
  35. data/test/rubygems/test_gem_commands_pristine_command.rb +92 -0
  36. data/test/rubygems/test_gem_package_tar_writer.rb +10 -6
  37. data/test/rubygems/test_gem_remote_fetcher.rb +25 -1
  38. data/test/rubygems/test_gem_request_set_lockfile.rb +28 -0
  39. data/test/rubygems/test_gem_resolver_api_specification.rb +2 -2
  40. data/test/rubygems/test_gem_resolver_installer_set.rb +14 -0
  41. data/test/rubygems/test_gem_source.rb +14 -0
  42. data/test/rubygems/test_gem_specification.rb +50 -1
  43. data/test/rubygems/test_gem_stub_specification.rb +9 -1
  44. data/test/rubygems/test_gem_text.rb +16 -0
  45. data/test/rubygems/test_kernel.rb +24 -0
  46. metadata +4 -3
  47. data/CONTRIBUTING +0 -32
@@ -23,6 +23,15 @@ class Gem::Request::HTTPPool # :nodoc:
23
23
  @queue.push connection
24
24
  end
25
25
 
26
+ def close_all
27
+ until @queue.empty?
28
+ if connection = @queue.pop(true) and connection.started?
29
+ connection.finish
30
+ end
31
+ end
32
+ @queue.push(nil)
33
+ end
34
+
26
35
  private
27
36
 
28
37
  def make_connection
@@ -403,10 +403,7 @@ class Gem::RequestSet
403
403
  "Unresolved dependency found during sorting - #{dep} (requested by #{node.spec.full_name})"
404
404
  end
405
405
 
406
- begin
407
- yield match
408
- rescue TSort::Cyclic
409
- end
406
+ yield match
410
407
  end
411
408
  end
412
409
 
@@ -200,6 +200,8 @@ class Gem::RequestSet::Lockfile
200
200
 
201
201
  platforms = @requests.map { |request| request.spec.platform }.uniq
202
202
 
203
+ platforms = platforms.sort_by { |platform| platform.to_s }
204
+
203
205
  platforms.sort.each do |platform|
204
206
  out << " #{platform}"
205
207
  end
@@ -277,14 +279,7 @@ class Gem::RequestSet::Lockfile
277
279
  when :bang then
278
280
  get :bang
279
281
 
280
- spec = @set.sets.select { |set|
281
- Gem::Resolver::GitSet === set or
282
- Gem::Resolver::VendorSet === set
283
- }.map { |set|
284
- set.specs[name]
285
- }.compact.first
286
-
287
- requirements << spec.version
282
+ requirements << pinned_requirement(name)
288
283
  when :l_paren then
289
284
  get :l_paren
290
285
 
@@ -300,6 +295,13 @@ class Gem::RequestSet::Lockfile
300
295
  end
301
296
 
302
297
  get :r_paren
298
+
299
+ if peek[0] == :bang then
300
+ requirements.clear
301
+ requirements << pinned_requirement(name)
302
+
303
+ get :bang
304
+ end
303
305
  end
304
306
 
305
307
  @set.gem name, *requirements
@@ -507,6 +509,17 @@ class Gem::RequestSet::Lockfile
507
509
  @tokens.first || [:EOF]
508
510
  end
509
511
 
512
+ def pinned_requirement name # :nodoc:
513
+ spec = @set.sets.select { |set|
514
+ Gem::Resolver::GitSet === set or
515
+ Gem::Resolver::VendorSet === set
516
+ }.map { |set|
517
+ set.specs[name]
518
+ }.compact.first
519
+
520
+ spec.version
521
+ end
522
+
510
523
  def skip type # :nodoc:
511
524
  get while not @tokens.empty? and peek.first == type
512
525
  end
@@ -72,7 +72,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set
72
72
  @to_fetch += needed
73
73
  end
74
74
 
75
- def prefetch_now
75
+ def prefetch_now # :nodoc:
76
76
  needed, @to_fetch = @to_fetch, []
77
77
 
78
78
  uri = @dep_uri + "?gems=#{needed.sort.join ','}"
@@ -19,7 +19,7 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification
19
19
  @set = set
20
20
  @name = api_data[:name]
21
21
  @version = Gem::Version.new api_data[:number]
22
- @platform = api_data[:platform]
22
+ @platform = Gem::Platform.new api_data[:platform]
23
23
  @dependencies = api_data[:dependencies].map do |name, ver|
24
24
  Gem::Dependency.new name, ver.split(/\s*,\s*/)
25
25
  end
@@ -154,7 +154,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set
154
154
  end
155
155
 
156
156
  def prefetch(reqs)
157
- @remote_set.prefetch(reqs)
157
+ @remote_set.prefetch(reqs) if consider_remote?
158
158
  end
159
159
 
160
160
  def prerelease= allow_prerelease
@@ -26,8 +26,12 @@ class Gem::Source
26
26
  # Creates a new Source which will use the index located at +uri+.
27
27
 
28
28
  def initialize(uri)
29
- unless uri.kind_of? URI
30
- uri = URI.parse(uri.to_s)
29
+ begin
30
+ unless uri.kind_of? URI
31
+ uri = URI.parse(uri.to_s)
32
+ end
33
+ rescue URI::InvalidURIError
34
+ raise if Gem::Source == self.class
31
35
  end
32
36
 
33
37
  @uri = uri
@@ -709,8 +709,6 @@ class Gem::Specification < Gem::BasicSpecification
709
709
  specs = {}
710
710
  Gem.loaded_specs.each_value{|s| specs[s] = true}
711
711
  @@all.each{|s| s.activated = true if specs[s]}
712
-
713
- _resort!(@@all)
714
712
  end
715
713
  @@all
716
714
  end
@@ -1478,6 +1476,16 @@ class Gem::Specification < Gem::BasicSpecification
1478
1476
  File.join build_info_dir, "#{full_name}.info"
1479
1477
  end
1480
1478
 
1479
+ ##
1480
+ # Used to detect if the gem is bundled in older version of Ruby, but not
1481
+ # detectable as default gem (see BasicSpecification#default_gem?).
1482
+
1483
+ def bundled_gem_in_old_ruby?
1484
+ !default_gem? &&
1485
+ RUBY_VERSION < "2.0.0" &&
1486
+ summary == "This #{name} is bundled with Ruby"
1487
+ end
1488
+
1481
1489
  ##
1482
1490
  # Returns the full path to the cache directory containing this
1483
1491
  # spec's cached gem.
@@ -42,6 +42,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
42
42
  self.loaded_from = filename
43
43
  @data = nil
44
44
  @extensions = nil
45
+ @name = nil
45
46
  @spec = nil
46
47
  end
47
48
 
@@ -49,8 +50,11 @@ class Gem::StubSpecification < Gem::BasicSpecification
49
50
  # True when this gem has been activated
50
51
 
51
52
  def activated?
52
- loaded = Gem.loaded_specs[name]
53
- loaded && loaded.version == version
53
+ @activated ||=
54
+ begin
55
+ loaded = Gem.loaded_specs[name]
56
+ loaded && loaded.version == version
57
+ end
54
58
  end
55
59
 
56
60
  def build_extensions # :nodoc:
@@ -154,9 +158,11 @@ class Gem::StubSpecification < Gem::BasicSpecification
154
158
  # The full Gem::Specification for this gem, loaded from evalling its gemspec
155
159
 
156
160
  def to_spec
157
- @spec ||= Gem.loaded_specs.values.find { |spec|
158
- spec.name == @name and spec.version == @version
159
- }
161
+ @spec ||= if @data then
162
+ Gem.loaded_specs.values.find { |spec|
163
+ spec.name == name and spec.version == version
164
+ }
165
+ end
160
166
 
161
167
  @spec ||= Gem::Specification.load(loaded_from)
162
168
  @spec.ignored = @ignored if instance_variable_defined? :@ignored
@@ -1035,6 +1035,37 @@ Also, a list:
1035
1035
  Zlib::Deflate.deflate data
1036
1036
  end
1037
1037
 
1038
+ def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil)
1039
+ if Gem.instance_variables.include? :@ruby_version or
1040
+ Gem.instance_variables.include? '@ruby_version' then
1041
+ Gem.send :remove_instance_variable, :@ruby_version
1042
+ end
1043
+
1044
+ @RUBY_VERSION = RUBY_VERSION
1045
+ @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
1046
+ @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION)
1047
+
1048
+ Object.send :remove_const, :RUBY_VERSION
1049
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
1050
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
1051
+
1052
+ Object.const_set :RUBY_VERSION, version
1053
+ Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel
1054
+ Object.const_set :RUBY_REVISION, revision if revision
1055
+ end
1056
+
1057
+ def util_restore_RUBY_VERSION
1058
+ Object.send :remove_const, :RUBY_VERSION
1059
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
1060
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
1061
+
1062
+ Object.const_set :RUBY_VERSION, @RUBY_VERSION
1063
+ Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if
1064
+ defined?(@RUBY_PATCHLEVEL)
1065
+ Object.const_set :RUBY_REVISION, @RUBY_REVISION if
1066
+ defined?(@RUBY_REVISION)
1067
+ end
1068
+
1038
1069
  ##
1039
1070
  # Is this test being run on a Windows platform?
1040
1071
 
@@ -27,9 +27,9 @@ module Gem::Text
27
27
  end
28
28
 
29
29
  def min3 a, b, c # :nodoc:
30
- if a < b && a < c
30
+ if a < b && a < c then
31
31
  a
32
- elsif b < a && b < c
32
+ elsif b < c then
33
33
  b
34
34
  else
35
35
  c
@@ -318,7 +318,6 @@ class Gem::StreamUI
318
318
  elsif Gem.win_platform?
319
319
  def _gets_noecho
320
320
  require "Win32API"
321
- char = nil
322
321
  password = ''
323
322
 
324
323
  while char = Win32API.new("crtdll", "_getch", [ ], "L").Call do
@@ -112,6 +112,20 @@ class TestGem < Gem::TestCase
112
112
  end
113
113
  end
114
114
 
115
+ def test_self_bin_path_active
116
+ a1 = util_spec 'a', '1' do |s|
117
+ s.executables = ['exec']
118
+ end
119
+
120
+ util_spec 'a', '2' do |s|
121
+ s.executables = ['exec']
122
+ end
123
+
124
+ a1.activate
125
+
126
+ assert_match 'a-1/bin/exec', Gem.bin_path('a', 'exec', '>= 0')
127
+ end
128
+
115
129
  def test_self_bin_path_no_exec_name
116
130
  e = assert_raises ArgumentError do
117
131
  Gem.bin_path 'a'
@@ -895,7 +909,7 @@ class TestGem < Gem::TestCase
895
909
  end
896
910
 
897
911
  expected = "Ignoring ext-1 because its extensions are not built. " +
898
- "Try: gem pristine ext-1\n"
912
+ "Try: gem pristine ext --version 1\n"
899
913
 
900
914
  assert_equal expected, err
901
915
  end
@@ -1551,37 +1565,6 @@ You may need to `gem install -g` to install missing gems
1551
1565
  @abin_path = File.join spec.full_gem_path, spec.bindir, 'abin'
1552
1566
  end
1553
1567
 
1554
- def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil)
1555
- if Gem.instance_variables.include? :@ruby_version or
1556
- Gem.instance_variables.include? '@ruby_version' then
1557
- Gem.send :remove_instance_variable, :@ruby_version
1558
- end
1559
-
1560
- @RUBY_VERSION = RUBY_VERSION
1561
- @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
1562
- @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION)
1563
-
1564
- Object.send :remove_const, :RUBY_VERSION
1565
- Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
1566
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
1567
-
1568
- Object.const_set :RUBY_VERSION, version
1569
- Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel
1570
- Object.const_set :RUBY_REVISION, revision if revision
1571
- end
1572
-
1573
- def util_restore_RUBY_VERSION
1574
- Object.send :remove_const, :RUBY_VERSION
1575
- Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
1576
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
1577
-
1578
- Object.const_set :RUBY_VERSION, @RUBY_VERSION
1579
- Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if
1580
- defined?(@RUBY_PATCHLEVEL)
1581
- Object.const_set :RUBY_REVISION, @RUBY_REVISION if
1582
- defined?(@RUBY_REVISION)
1583
- end
1584
-
1585
1568
  def util_remove_interrupt_command
1586
1569
  Gem::Commands.send :remove_const, :InterruptCommand if
1587
1570
  Gem::Commands.const_defined? :InterruptCommand
@@ -287,6 +287,57 @@ class TestGemCommandsPristineCommand < Gem::TestCase
287
287
  assert_empty out, out.inspect
288
288
  end
289
289
 
290
+ def test_execute_missing_cache_gem_when_multi_repo
291
+ specs = spec_fetcher do |fetcher|
292
+ fetcher.gem 'a', 1
293
+ fetcher.gem 'b', 1
294
+ end
295
+
296
+ FileUtils.rm_rf File.join(@gemhome, 'gems', 'a-1')
297
+ FileUtils.rm_rf File.join(@gemhome, 'gems', 'b-1')
298
+
299
+ install_gem specs["a-1"]
300
+ FileUtils.rm File.join(@gemhome, 'cache', 'a-1.gem')
301
+
302
+ Gem.clear_paths
303
+ gemhome2 = File.join(@tempdir, 'gemhome2')
304
+ Gem.paths = { "GEM_PATH" => [gemhome2, @gemhome], "GEM_HOME" => gemhome2 }
305
+
306
+ install_gem specs["b-1"]
307
+ FileUtils.rm File.join(gemhome2, 'cache', 'b-1.gem')
308
+
309
+ @cmd.options[:args] = %w[a b]
310
+
311
+ use_ui @ui do
312
+ @cmd.execute
313
+ end
314
+
315
+ out = @ui.output.split "\n"
316
+
317
+ [
318
+ "Restoring gems to pristine condition...",
319
+ "Cached gem for a-1 not found, attempting to fetch...",
320
+ "Restored a-1",
321
+ "Cached gem for b-1 not found, attempting to fetch...",
322
+ "Restored b-1",
323
+ ].each do |line|
324
+ assert_equal line, out.shift
325
+ end
326
+
327
+ assert_empty out, out.inspect
328
+ assert_empty @ui.error
329
+
330
+ assert_path_exists File.join(@gemhome, "cache", 'a-1.gem')
331
+ refute_path_exists File.join(gemhome2, "cache", 'a-2.gem')
332
+ assert_path_exists File.join(@gemhome, "gems", 'a-1')
333
+ refute_path_exists File.join(gemhome2, "gems", 'a-1')
334
+
335
+ assert_path_exists File.join(gemhome2, "cache", 'b-1.gem')
336
+ refute_path_exists File.join(@gemhome, "cache", 'b-2.gem')
337
+ assert_path_exists File.join(gemhome2, "gems", 'b-1')
338
+ refute_path_exists File.join(@gemhome, "gems", 'b-1')
339
+ end
340
+
290
341
  def test_execute_no_gem
291
342
  @cmd.options[:args] = %w[]
292
343
 
@@ -329,6 +380,24 @@ class TestGemCommandsPristineCommand < Gem::TestCase
329
380
  refute File.exist? gem_lib
330
381
  end
331
382
 
383
+ def test_execute_unknown_gem_at_remote_source
384
+ util_spec 'a'
385
+
386
+ @cmd.options[:args] = %w[a]
387
+
388
+ use_ui @ui do
389
+ @cmd.execute
390
+ end
391
+
392
+ assert_equal([
393
+ "Restoring gems to pristine condition...",
394
+ "Cached gem for a-2 not found, attempting to fetch...",
395
+ "Skipped a-2, it was not found from cache and remote sources"
396
+ ], @ui.output.split("\n"))
397
+
398
+ assert_empty @ui.error
399
+ end
400
+
332
401
  def test_execute_default_gem
333
402
  default_gem_spec = new_default_spec("default", "2.0.0.0",
334
403
  nil, "default/gem.rb")
@@ -348,6 +417,29 @@ class TestGemCommandsPristineCommand < Gem::TestCase
348
417
  assert_empty(@ui.error)
349
418
  end
350
419
 
420
+ def test_execute_bundled_gem_on_old_rubies
421
+ util_set_RUBY_VERSION '1.9.3', 551
422
+
423
+ util_spec 'bigdecimal', '1.1.0' do |s|
424
+ s.summary = "This bigdecimal is bundled with Ruby"
425
+ end
426
+
427
+ @cmd.options[:args] = %w[bigdecimal]
428
+
429
+ use_ui @ui do
430
+ @cmd.execute
431
+ end
432
+
433
+ assert_equal([
434
+ "Restoring gems to pristine condition...",
435
+ "Skipped bigdecimal-1.1.0, it is bundled with old Ruby"
436
+ ], @ui.output.split("\n"))
437
+
438
+ assert_empty @ui.error
439
+ ensure
440
+ util_restore_RUBY_VERSION
441
+ end
442
+
351
443
  def test_handle_options
352
444
  @cmd.handle_options %w[]
353
445
 
@@ -224,26 +224,30 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
224
224
  name = File.join 'a', 'b' * 100
225
225
  assert_equal ['b' * 100, 'a'], @tar_writer.split_name(name)
226
226
 
227
- assert_raises Gem::Package::TooLongFileName do
228
- name = File.join 'a', 'b' * 101
227
+ name = File.join 'a', 'b' * 101
228
+ exception = assert_raises Gem::Package::TooLongFileName do
229
229
  @tar_writer.split_name name
230
230
  end
231
+ assert_includes exception.message, name
231
232
  end
232
233
 
233
234
  def test_split_name_too_long_prefix
234
235
  name = File.join 'a' * 155, 'b'
235
236
  assert_equal ['b', 'a' * 155], @tar_writer.split_name(name)
236
237
 
237
- assert_raises Gem::Package::TooLongFileName do
238
- name = File.join 'a' * 156, 'b'
238
+ name = File.join 'a' * 156, 'b'
239
+ exception = assert_raises Gem::Package::TooLongFileName do
239
240
  @tar_writer.split_name name
240
241
  end
242
+ assert_includes exception.message, name
241
243
  end
242
244
 
243
245
  def test_split_name_too_long_total
244
- assert_raises Gem::Package::TooLongFileName do
245
- @tar_writer.split_name 'a' * 257
246
+ name = 'a' * 257
247
+ exception = assert_raises Gem::Package::TooLongFileName do
248
+ @tar_writer.split_name name
246
249
  end
250
+ assert_includes exception.message, name
247
251
  end
248
252
 
249
253
  end