rubygems-update 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (78) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +31 -0
  3. data/doc/release_notes/rel_1_3_1.rdoc +75 -0
  4. data/lib/rubygems.rb +23 -13
  5. data/lib/rubygems/commands/check_command.rb +2 -1
  6. data/lib/rubygems/commands/unpack_command.rb +1 -1
  7. data/lib/rubygems/commands/update_command.rb +4 -5
  8. data/lib/rubygems/config_file.rb +4 -1
  9. data/lib/rubygems/custom_require.rb +15 -7
  10. data/lib/rubygems/defaults.rb +5 -0
  11. data/lib/rubygems/installer.rb +1 -1
  12. data/lib/rubygems/rubygems_version.rb +1 -1
  13. data/lib/rubygems/source_index.rb +1 -2
  14. data/lib/rubygems/validator.rb +147 -125
  15. data/test/functional.rb +6 -2
  16. data/test/gem_installer_test_case.rb +1 -1
  17. data/test/gemutilities.rb +19 -5
  18. data/test/test_config.rb +0 -2
  19. data/test/test_gem.rb +4 -4
  20. data/test/test_gem_builder.rb +0 -1
  21. data/test/test_gem_command.rb +2 -3
  22. data/test/test_gem_command_manager.rb +0 -1
  23. data/test/test_gem_commands_build_command.rb +0 -1
  24. data/test/test_gem_commands_cert_command.rb +0 -1
  25. data/test/test_gem_commands_check_command.rb +0 -1
  26. data/test/test_gem_commands_contents_command.rb +2 -3
  27. data/test/test_gem_commands_dependency_command.rb +2 -3
  28. data/test/test_gem_commands_environment_command.rb +1 -2
  29. data/test/test_gem_commands_fetch_command.rb +0 -1
  30. data/test/test_gem_commands_generate_index_command.rb +1 -1
  31. data/test/test_gem_commands_install_command.rb +2 -3
  32. data/test/test_gem_commands_list_command.rb +1 -2
  33. data/test/test_gem_commands_lock_command.rb +1 -2
  34. data/test/test_gem_commands_mirror_command.rb +0 -1
  35. data/test/test_gem_commands_outdated_command.rb +0 -1
  36. data/test/test_gem_commands_pristine_command.rb +1 -2
  37. data/test/test_gem_commands_query_command.rb +5 -6
  38. data/test/test_gem_commands_server_command.rb +0 -1
  39. data/test/test_gem_commands_sources_command.rb +0 -1
  40. data/test/test_gem_commands_specification_command.rb +1 -2
  41. data/test/test_gem_commands_stale_command.rb +0 -1
  42. data/test/test_gem_commands_uninstall_command.rb +5 -4
  43. data/test/test_gem_commands_unpack_command.rb +0 -1
  44. data/test/test_gem_commands_update_command.rb +0 -1
  45. data/test/test_gem_config_file.rb +0 -2
  46. data/test/test_gem_dependency.rb +13 -14
  47. data/test/test_gem_dependency_installer.rb +4 -5
  48. data/test/test_gem_dependency_list.rb +0 -3
  49. data/test/test_gem_digest.rb +12 -10
  50. data/test/test_gem_doc_manager.rb +1 -2
  51. data/test/test_gem_ext_configure_builder.rb +1 -2
  52. data/test/test_gem_ext_ext_conf_builder.rb +2 -3
  53. data/test/test_gem_ext_rake_builder.rb +2 -3
  54. data/test/test_gem_format.rb +4 -6
  55. data/test/test_gem_gem_path_searcher.rb +0 -1
  56. data/test/test_gem_gem_runner.rb +0 -1
  57. data/test/test_gem_indexer.rb +2 -3
  58. data/test/test_gem_install_update_options.rb +1 -2
  59. data/test/test_gem_installer.rb +16 -15
  60. data/test/test_gem_local_remote_options.rb +1 -2
  61. data/test/test_gem_package_tar_reader_entry.rb +5 -5
  62. data/test/test_gem_package_tar_writer.rb +10 -10
  63. data/test/test_gem_platform.rb +6 -19
  64. data/test/test_gem_remote_fetcher.rb +18 -12
  65. data/test/test_gem_requirement.rb +14 -15
  66. data/test/test_gem_server.rb +0 -1
  67. data/test/test_gem_source_index.rb +5 -6
  68. data/test/test_gem_source_info_cache.rb +5 -7
  69. data/test/test_gem_source_info_cache_entry.rb +1 -2
  70. data/test/test_gem_spec_fetcher.rb +0 -1
  71. data/test/test_gem_specification.rb +11 -12
  72. data/test/test_gem_stream_ui.rb +0 -1
  73. data/test/test_gem_validator.rb +4 -5
  74. data/test/test_gem_version.rb +9 -10
  75. data/test/test_gem_version_option.rb +0 -1
  76. data/test/test_kernel.rb +1 -3
  77. metadata +4 -3
  78. metadata.gz.sig +0 -0
data.tar.gz.sig CHANGED
Binary file
data/ChangeLog CHANGED
@@ -1,5 +1,36 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ 2008-10-25 Eric Hodel <drbrain@segment7.net>
4
+
5
+ * lib/rubygems.rb, lib/rubygems/custom_require.rb: Make kernel
6
+ methods private. Patch #20801 by Stefan Rusterholz. Expose
7
+ our kernel extensions to RDoc. Make Gem::location_of_caller behave on
8
+ Windows. Patch by Daniel Berger.
9
+ * doc/release_notes/rel_1_3_1.rdoc: Final release notes for 1.3.1.
10
+ * lib/rubygems/rubygems_version.rb: 1.3.1.
11
+
12
+ 2008-10-10 Eric Hodel <drbrain@segment7.net>
13
+
14
+ * lib/rubygems/commands/unpack_command.rb: Silence PATH warning.
15
+
16
+ 2008-10-09 Eric Hodel <drbrain@segment7.net>
17
+
18
+ * lib/rubygems.rb: Fix requires for inflate, deflate, etc.
19
+ * test/*: Convert to minitest/unit.
20
+ * lib/rubygems/validator.rb: Fix for MiniTest instead of test/unit
21
+ classic in 1.9.
22
+
23
+ 2008-10-03 Phil Hagelberg <technomancy@gmail.com>
24
+
25
+ * lib/rubygems.rb: Make Gem.dir respect :gemhome value from config.
26
+ * lib/rubygems/config_file.rb: Expose :gemhome value.
27
+
28
+ 2008-09-26 Luis Lavena <luislavena@gmail.com>
29
+
30
+ * lib/rubygems.rb: Disregard ownership of ~ under Windows while
31
+ creating ~/.gem. Fixes issues related to no uid support under
32
+ Windows.
33
+
3
34
  2008-09-24 Eric Hodel <drbrain@segment7.net>
4
35
 
5
36
  * doc/release_notes/rel_1_3_0.rdoc: Final release notes for 1.3.0.
@@ -0,0 +1,75 @@
1
+ = Announce: RubyGems Release 1.3.0
2
+
3
+ NOTE: RubyGems 1.1 and 1.2 have problems upgrading when there is no
4
+ rubygems-update installed. You will need to follow the second set of update
5
+ instructions if you see "Nothing to update".
6
+
7
+ Release 1.3.0 fixes some bugs.
8
+
9
+ Bugs fixed:
10
+
11
+ * Disregard ownership of ~ under Windows while creating ~/.gem. Fixes
12
+ issues related to no uid support under Windows.
13
+ * Fix requires for Gem::inflate, Gem::deflate, etc.
14
+ * Make Gem.dir respect :gemhome value from config. (Note: this feature may be
15
+ removed since it is hard to implement on 1.9.)
16
+ * Kernel methods are now private. Patch #20801 by Stefan Rusterholz.
17
+ * Gem::location_of_caller now behaves on Windows. Patch by Daniel Berger.
18
+ * Silence PATH warning.
19
+
20
+ Deprecation Notices:
21
+
22
+ * Gem::manage_gems will be removed on or after March 2009.
23
+
24
+ For a full list of changes to RubyGems and the contributor for each change, see
25
+ the ChangeLog file.
26
+
27
+ Special thanks to Chad Wooley for backwards compatibility testing and Luis
28
+ Lavena for continuing windows support.
29
+
30
+ == How can I get RubyGems?
31
+
32
+ NOTE: If you have installed RubyGems using a package system you may want to
33
+ install a new RubyGems through the same packaging system.
34
+
35
+ If you have a recent version of RubyGems (0.8.5 or later), then all
36
+ you need to do is:
37
+
38
+ $ gem update --system (you might need to be admin/root)
39
+
40
+ NOTE: RubyGems 1.1 and 1.2 have problems upgrading when there is no
41
+ rubygems-update installed. You will need to follow the second set of update
42
+ instructions if you see "Nothing to update".
43
+
44
+ NOTE: You may have to run the command twice if you have any previosly
45
+ installed rubygems-update gems.
46
+
47
+ If you have an older version of RubyGems installed, then you can still
48
+ do it in two steps:
49
+
50
+ $ gem install rubygems-update (again, might need to be admin/root)
51
+ $ update_rubygems (... here too)
52
+
53
+ If you don't have any gems install, there is still the pre-gem
54
+ approach to getting software ... doing it manually:
55
+
56
+ 1. DOWNLOAD FROM: http://rubyforge.org/frs/?group_id=126
57
+ 2. UNPACK INTO A DIRECTORY AND CD THERE
58
+ 3. INSTALL WITH: ruby setup.rb (you may need admin/root privilege)
59
+
60
+ == To File Bugs
61
+
62
+ The RubyGems bug tracker can be found on RubyForge at:
63
+ http://rubyforge.org/tracker/?func=add&group_id=126&atid=575
64
+
65
+ When filing a bug, `gem env` output will be helpful in diagnosing the issue.
66
+
67
+ If you find a bug where RubyGems crashes, please provide debug output. You can
68
+ do that with `gem --debug the_command`.
69
+
70
+ == Thanks
71
+
72
+ Keep those gems coming!
73
+
74
+ -- Jim & Chad & Eric (for the RubyGems team)
75
+
@@ -43,12 +43,14 @@ module Kernel
43
43
  #
44
44
  # GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
45
45
 
46
- def gem(gem_name, *version_requirements)
46
+ def gem(gem_name, *version_requirements) # :doc:
47
47
  skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
48
48
  raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
49
49
  Gem.activate(gem_name, *version_requirements)
50
50
  end
51
51
 
52
+ private :gem
53
+
52
54
  end
53
55
 
54
56
  ##
@@ -104,10 +106,10 @@ module Gem
104
106
  @ruby = nil
105
107
  @sources = []
106
108
 
107
- @post_install_hooks = []
108
- @post_uninstall_hooks = []
109
- @pre_uninstall_hooks = []
110
- @pre_install_hooks = []
109
+ @post_install_hooks ||= []
110
+ @post_uninstall_hooks ||= []
111
+ @pre_uninstall_hooks ||= []
112
+ @pre_install_hooks ||= []
111
113
 
112
114
  ##
113
115
  # Activates an installed gem matching +gem+. The gem must satisfy
@@ -294,6 +296,7 @@ module Gem
294
296
  # A Zlib::Deflate.deflate wrapper
295
297
 
296
298
  def self.deflate(data)
299
+ require 'zlib'
297
300
  Zlib::Deflate.deflate data
298
301
  end
299
302
 
@@ -302,7 +305,7 @@ module Gem
302
305
 
303
306
  def self.dir
304
307
  @gem_home ||= nil
305
- set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
308
+ set_home(ENV['GEM_HOME'] || Gem.configuration.home || default_dir) unless @gem_home
306
309
  @gem_home
307
310
  end
308
311
 
@@ -395,6 +398,8 @@ module Gem
395
398
  # Zlib::GzipReader wrapper that unzips +data+.
396
399
 
397
400
  def self.gunzip(data)
401
+ require 'stringio'
402
+ require 'zlib'
398
403
  data = StringIO.new data
399
404
 
400
405
  Zlib::GzipReader.new(data).read
@@ -404,6 +409,8 @@ module Gem
404
409
  # Zlib::GzipWriter wrapper that zips +data+.
405
410
 
406
411
  def self.gzip(data)
412
+ require 'stringio'
413
+ require 'zlib'
407
414
  zipped = StringIO.new
408
415
 
409
416
  Zlib::GzipWriter.wrap zipped do |io| io.write data end
@@ -415,6 +422,7 @@ module Gem
415
422
  # A Zlib::Inflate#inflate wrapper
416
423
 
417
424
  def self.inflate(data)
425
+ require 'zlib'
418
426
  Zlib::Inflate.inflate data
419
427
  end
420
428
 
@@ -479,13 +487,13 @@ module Gem
479
487
  # The file name and line number of the caller of the caller of this method.
480
488
 
481
489
  def self.location_of_caller
482
- file, lineno = caller[1].split(':')
483
- lineno = lineno.to_i
490
+ caller[1] =~ /(.*?):(\d+)$/i
491
+ file = $1
492
+ lineno = $2.to_i
493
+
484
494
  [file, lineno]
485
495
  end
486
496
 
487
- private_class_method :location_of_caller
488
-
489
497
  ##
490
498
  # manage_gems is useless and deprecated. Don't call it anymore.
491
499
 
@@ -709,9 +717,11 @@ module Gem
709
717
 
710
718
  @gem_path.uniq!
711
719
  @gem_path.each do |path|
712
- if 0 == File.expand_path(path).index(Gem.user_home) and
713
- Etc.getpwuid.uid != File::Stat.new(Gem.user_home).uid then
714
- next # only create by matching user
720
+ if 0 == File.expand_path(path).index(Gem.user_home)
721
+ unless win_platform? then
722
+ # only create by matching user
723
+ next if Etc.getpwuid.uid != File::Stat.new(Gem.user_home).uid
724
+ end
715
725
  end
716
726
  ensure_gem_subdirectories path
717
727
  end
@@ -31,7 +31,8 @@ class Gem::Commands::CheckCommand < Gem::Command
31
31
  def execute
32
32
  if options[:test]
33
33
  version = options[:version] || Gem::Requirement.default
34
- gem_spec = Gem::SourceIndex.from_installed_gems.search(get_one_gem_name, version).first
34
+ dep = Gem::Dependency.new get_one_gem_name, version
35
+ gem_spec = Gem::SourceIndex.from_installed_gems.search(dep).first
35
36
  Gem::Validator.new.unit_test(gem_spec)
36
37
  end
37
38
 
@@ -43,7 +43,7 @@ class Gem::Commands::UnpackCommand < Gem::Command
43
43
  basename = File.basename(path).sub(/\.gem$/, '')
44
44
  target_dir = File.expand_path File.join(options[:target], basename)
45
45
  FileUtils.mkdir_p target_dir
46
- Gem::Installer.new(path).unpack target_dir
46
+ Gem::Installer.new(path, :unpack => true).unpack target_dir
47
47
  say "Unpacked gem: '#{target_dir}'"
48
48
  else
49
49
  alert_error "Gem '#{gemname}' not installed."
@@ -54,11 +54,10 @@ class Gem::Commands::UpdateCommand < Gem::Command
54
54
  fail "No gem names are allowed with the --system option"
55
55
  end
56
56
 
57
- spec = Gem::Specification.new
58
- spec.name = 'rubygems-update'
59
- spec.version = Gem::Version.new Gem::RubyGemsVersion
60
- spec.version = Gem::Version.new '1.1.1'
61
- hig['rubygems-update'] = spec
57
+ rubygems_update = Gem::Specification.new
58
+ rubygems_update.name = 'rubygems-update'
59
+ rubygems_update.version = Gem::Version.new Gem::RubyGemsVersion
60
+ hig['rubygems-update'] = rubygems_update
62
61
 
63
62
  options[:user_install] = false
64
63
  else
@@ -52,6 +52,8 @@ class Gem::ConfigFile
52
52
  # Where to look for gems
53
53
  attr_accessor :path
54
54
 
55
+ attr_accessor :home
56
+
55
57
  # True if we print backtraces on errors.
56
58
  attr_writer :backtrace
57
59
 
@@ -129,7 +131,8 @@ class Gem::ConfigFile
129
131
  Gem.sources = @hash[:sources] if @hash.key? :sources
130
132
  @verbose = @hash[:verbose] if @hash.key? :verbose
131
133
  @update_sources = @hash[:update_sources] if @hash.key? :update_sources
132
- @path = @hash[:gempath]
134
+ @path = @hash[:gempath] if @hash.key? :gempath
135
+ @home = @hash[:gemhome] if @hash.key? :gemhome
133
136
 
134
137
  handle_arguments arg_list
135
138
  end
@@ -7,11 +7,15 @@
7
7
  require 'rubygems'
8
8
 
9
9
  module Kernel
10
- alias gem_original_require require # :nodoc:
11
10
 
12
- #
13
- # We replace Ruby's require with our own, which is capable of
14
- # loading gems on demand.
11
+ ##
12
+ # The Kernel#require from before RubyGems was loaded.
13
+
14
+ alias gem_original_require require
15
+
16
+ ##
17
+ # When RubyGems is required, Kernel#require is replaced with our own which
18
+ # is capable of loading gems on demand.
15
19
  #
16
20
  # When you call <tt>require 'x'</tt>, this is what happens:
17
21
  # * If the file can be loaded from the existing Ruby loadpath, it
@@ -22,8 +26,8 @@ module Kernel
22
26
  #
23
27
  # The normal <tt>require</tt> functionality of returning false if
24
28
  # that file has already been loaded is preserved.
25
- #
26
- def require(path) # :nodoc:
29
+
30
+ def require(path) # :doc:
27
31
  gem_original_require path
28
32
  rescue LoadError => load_error
29
33
  if load_error.message =~ /#{Regexp.escape path}\z/ and
@@ -34,5 +38,9 @@ module Kernel
34
38
  raise load_error
35
39
  end
36
40
  end
37
- end # module Kernel
41
+
42
+ private :require
43
+ private :gem_original_require
44
+
45
+ end
38
46
 
@@ -1,5 +1,10 @@
1
1
  module Gem
2
2
 
3
+ @post_install_hooks ||= []
4
+ @post_uninstall_hooks ||= []
5
+ @pre_uninstall_hooks ||= []
6
+ @pre_install_hooks ||= []
7
+
3
8
  ##
4
9
  # An Array of the default sources that come with RubyGems
5
10
 
@@ -137,7 +137,7 @@ class Gem::Installer
137
137
  options[:user_install] = true
138
138
  end
139
139
 
140
- if options[:user_install] then
140
+ if options[:user_install] and not options[:unpack] then
141
141
  @gem_home = Gem.user_dir
142
142
 
143
143
  user_bin_dir = File.join(@gem_home, 'bin')
@@ -2,5 +2,5 @@
2
2
  # This file is auto-generated by build scripts.
3
3
  # See: rake update_version
4
4
  module Gem
5
- RubyGemsVersion = '1.3.0'
5
+ RubyGemsVersion = '1.3.1'
6
6
  end
@@ -257,8 +257,7 @@ class Gem::SourceIndex
257
257
 
258
258
  # TODO - Remove support and warning for legacy arguments after 2008/11
259
259
  unless Gem::Dependency === gem_pattern
260
- warn "Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated"
261
- warn "#{caller[0]} is outdated"
260
+ warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated"
262
261
  end
263
262
 
264
263
  case gem_pattern
@@ -10,118 +10,130 @@ require 'rubygems/digest/md5'
10
10
  require 'rubygems/format'
11
11
  require 'rubygems/installer'
12
12
 
13
- module Gem
13
+ ##
14
+ # Validator performs various gem file and gem database validation
15
+
16
+ class Gem::Validator
17
+
18
+ include Gem::UserInteraction
14
19
 
15
20
  ##
16
- # Validator performs various gem file and gem database validation
17
- class Validator
18
- include UserInteraction
19
-
20
- ##
21
- # Given a gem file's contents, validates against its own MD5 checksum
22
- # gem_data:: [String] Contents of the gem file
23
- def verify_gem(gem_data)
24
- raise VerificationError, 'empty gem file' if gem_data.size == 0
25
-
26
- unless gem_data =~ /MD5SUM/ then
27
- return # Don't worry about it...this sucks. Need to fix MD5 stuff for
28
- # new format
29
- # FIXME
30
- end
21
+ # Given a gem file's contents, validates against its own MD5 checksum
22
+ # gem_data:: [String] Contents of the gem file
31
23
 
32
- sum_data = gem_data.gsub(/MD5SUM = "([a-z0-9]+)"/,
33
- "MD5SUM = \"#{"F" * 32}\"")
24
+ def verify_gem(gem_data)
25
+ raise Gem::VerificationError, 'empty gem file' if gem_data.size == 0
34
26
 
35
- unless Gem::MD5.hexdigest(sum_data) == $1.to_s then
36
- raise VerificationError, 'invalid checksum for gem file'
37
- end
27
+ unless gem_data =~ /MD5SUM/ then
28
+ return # Don't worry about it...this sucks. Need to fix MD5 stuff for
29
+ # new format
30
+ # FIXME
38
31
  end
39
32
 
40
- ##
41
- # Given the path to a gem file, validates against its own MD5 checksum
42
- #
43
- # gem_path:: [String] Path to gem file
44
- def verify_gem_file(gem_path)
45
- open gem_path, Gem.binary_mode do |file|
46
- gem_data = file.read
47
- verify_gem gem_data
48
- end
49
- rescue Errno::ENOENT
50
- raise Gem::VerificationError.new("missing gem file #{gem_path}")
33
+ sum_data = gem_data.gsub(/MD5SUM = "([a-z0-9]+)"/,
34
+ "MD5SUM = \"#{"F" * 32}\"")
35
+
36
+ unless Gem::MD5.hexdigest(sum_data) == $1.to_s then
37
+ raise Gem::VerificationError, 'invalid checksum for gem file'
51
38
  end
39
+ end
52
40
 
53
- private
54
- def find_files_for_gem(gem_directory)
55
- installed_files = []
56
- Find.find(gem_directory) {|file_name|
57
- fn = file_name.slice((gem_directory.size)..(file_name.size-1)).sub(/^\//, "")
58
- if(!(fn =~ /CVS/ || File.directory?(fn) || fn == "")) then
59
- installed_files << fn
60
- end
61
-
62
- }
63
- installed_files
41
+ ##
42
+ # Given the path to a gem file, validates against its own MD5 checksum
43
+ #
44
+ # gem_path:: [String] Path to gem file
45
+
46
+ def verify_gem_file(gem_path)
47
+ open gem_path, Gem.binary_mode do |file|
48
+ gem_data = file.read
49
+ verify_gem gem_data
64
50
  end
65
-
66
-
67
- public
68
- ErrorData = Struct.new(:path, :problem)
69
-
70
- ##
71
- # Checks the gem directory for the following potential
72
- # inconsistencies/problems:
73
- # * Checksum gem itself
74
- # * For each file in each gem, check consistency of installed versions
75
- # * Check for files that aren't part of the gem but are in the gems directory
76
- # * 1 cache - 1 spec - 1 directory.
77
- #
78
- # returns a hash of ErrorData objects, keyed on the problem gem's name.
79
- def alien
80
- errors = {}
81
- Gem::SourceIndex.from_installed_gems.each do |gem_name, gem_spec|
82
- errors[gem_name] ||= []
83
- gem_path = File.join(Gem.dir, "cache", gem_spec.full_name) + ".gem"
84
- spec_path = File.join(Gem.dir, "specifications", gem_spec.full_name) + ".gemspec"
85
- gem_directory = File.join(Gem.dir, "gems", gem_spec.full_name)
86
- installed_files = find_files_for_gem(gem_directory)
87
-
88
- if(!File.exist?(spec_path)) then
89
- errors[gem_name] << ErrorData.new(spec_path, "Spec file doesn't exist for installed gem")
90
- end
91
-
92
- begin
93
- verify_gem_file(gem_path)
94
- open gem_path, Gem.binary_mode do |file|
95
- format = Gem::Format.from_file_by_path(gem_path)
96
- format.file_entries.each do |entry, data|
97
- # Found this file. Delete it from list
98
- installed_files.delete remove_leading_dot_dir(entry['path'])
99
-
100
- next unless data # HACK `gem check -a mkrf`
101
-
102
- open File.join(gem_directory, entry['path']), Gem.binary_mode do |f|
103
- unless Gem::MD5.hexdigest(f.read).to_s ==
104
- Gem::MD5.hexdigest(data).to_s then
105
- errors[gem_name] << ErrorData.new(entry['path'], "installed file doesn't match original from gem")
106
- end
51
+ rescue Errno::ENOENT
52
+ raise Gem::VerificationError, "missing gem file #{gem_path}"
53
+ end
54
+
55
+ private
56
+
57
+ def find_files_for_gem(gem_directory)
58
+ installed_files = []
59
+ Find.find(gem_directory) {|file_name|
60
+ fn = file_name.slice((gem_directory.size)..(file_name.size-1)).sub(/^\//, "")
61
+ if(!(fn =~ /CVS/ || File.directory?(fn) || fn == "")) then
62
+ installed_files << fn
63
+ end
64
+
65
+ }
66
+ installed_files
67
+ end
68
+
69
+ public
70
+
71
+ ErrorData = Struct.new :path, :problem
72
+
73
+ ##
74
+ # Checks the gem directory for the following potential
75
+ # inconsistencies/problems:
76
+ #
77
+ # * Checksum gem itself
78
+ # * For each file in each gem, check consistency of installed versions
79
+ # * Check for files that aren't part of the gem but are in the gems directory
80
+ # * 1 cache - 1 spec - 1 directory.
81
+ #
82
+ # returns a hash of ErrorData objects, keyed on the problem gem's name.
83
+
84
+ def alien
85
+ errors = {}
86
+
87
+ Gem::SourceIndex.from_installed_gems.each do |gem_name, gem_spec|
88
+ errors[gem_name] ||= []
89
+
90
+ gem_path = File.join(Gem.dir, "cache", gem_spec.full_name) + ".gem"
91
+ spec_path = File.join(Gem.dir, "specifications", gem_spec.full_name) + ".gemspec"
92
+ gem_directory = File.join(Gem.dir, "gems", gem_spec.full_name)
93
+
94
+ installed_files = find_files_for_gem(gem_directory)
95
+
96
+ unless File.exist? spec_path then
97
+ errors[gem_name] << ErrorData.new(spec_path, "Spec file doesn't exist for installed gem")
98
+ end
99
+
100
+ begin
101
+ verify_gem_file(gem_path)
102
+
103
+ open gem_path, Gem.binary_mode do |file|
104
+ format = Gem::Format.from_file_by_path(gem_path)
105
+ format.file_entries.each do |entry, data|
106
+ # Found this file. Delete it from list
107
+ installed_files.delete remove_leading_dot_dir(entry['path'])
108
+
109
+ next unless data # HACK `gem check -a mkrf`
110
+
111
+ open File.join(gem_directory, entry['path']), Gem.binary_mode do |f|
112
+ unless Gem::MD5.hexdigest(f.read).to_s ==
113
+ Gem::MD5.hexdigest(data).to_s then
114
+ errors[gem_name] << ErrorData.new(entry['path'], "installed file doesn't match original from gem")
107
115
  end
108
116
  end
109
117
  end
110
- rescue VerificationError => e
111
- errors[gem_name] << ErrorData.new(gem_path, e.message)
112
- end
113
- # Clean out directories that weren't explicitly included in the gemspec
114
- # FIXME: This still allows arbitrary incorrect directories.
115
- installed_files.delete_if {|potential_directory|
116
- File.directory?(File.join(gem_directory, potential_directory))
117
- }
118
- if(installed_files.size > 0) then
119
- errors[gem_name] << ErrorData.new(gem_path, "Unmanaged files in gem: #{installed_files.inspect}")
120
118
  end
119
+ rescue Gem::VerificationError => e
120
+ errors[gem_name] << ErrorData.new(gem_path, e.message)
121
+ end
122
+
123
+ # Clean out directories that weren't explicitly included in the gemspec
124
+ # FIXME: This still allows arbitrary incorrect directories.
125
+ installed_files.delete_if {|potential_directory|
126
+ File.directory?(File.join(gem_directory, potential_directory))
127
+ }
128
+ if(installed_files.size > 0) then
129
+ errors[gem_name] << ErrorData.new(gem_path, "Unmanaged files in gem: #{installed_files.inspect}")
121
130
  end
122
- errors
123
131
  end
124
132
 
133
+ errors
134
+ end
135
+
136
+ if RUBY_VERSION < '1.9' then
125
137
  class TestRunner
126
138
  def initialize(suite, ui)
127
139
  @suite = suite
@@ -147,40 +159,50 @@ module Gem
147
159
  end
148
160
 
149
161
  autoload :TestRunner, 'test/unit/ui/testrunnerutilities'
150
-
151
- ##
152
- # Runs unit tests for a given gem specification
153
- def unit_test(gem_spec)
154
- start_dir = Dir.pwd
155
- Dir.chdir(gem_spec.full_gem_path)
156
- $: << File.join(Gem.dir, "gems", gem_spec.full_name)
157
- # XXX: why do we need this gem_spec when we've already got 'spec'?
158
- test_files = gem_spec.test_files
159
- if test_files.empty?
160
- say "There are no unit tests to run for #{gem_spec.full_name}"
161
- require 'test/unit/ui/console/testrunner'
162
- return Test::Unit::TestResult.new
163
- end
164
- gem gem_spec.name, "= #{gem_spec.version.version}"
165
- test_files.each do |f| require f end
162
+ end
163
+
164
+ ##
165
+ # Runs unit tests for a given gem specification
166
+
167
+ def unit_test(gem_spec)
168
+ start_dir = Dir.pwd
169
+ Dir.chdir(gem_spec.full_gem_path)
170
+ $: << File.join(Gem.dir, "gems", gem_spec.full_name)
171
+ # XXX: why do we need this gem_spec when we've already got 'spec'?
172
+ test_files = gem_spec.test_files
173
+
174
+ if test_files.empty? then
175
+ say "There are no unit tests to run for #{gem_spec.full_name}"
176
+ return nil
177
+ end
178
+
179
+ gem gem_spec.name, "= #{gem_spec.version.version}"
180
+
181
+ test_files.each do |f| require f end
182
+
183
+ if RUBY_VERSION < '1.9' then
166
184
  suite = Test::Unit::TestSuite.new("#{gem_spec.name}-#{gem_spec.version}")
185
+
167
186
  ObjectSpace.each_object(Class) do |klass|
168
187
  suite << klass.suite if (klass < Test::Unit::TestCase)
169
188
  end
170
- result = TestRunner.run(suite, ui())
171
- unless result.passed?
172
- alert_error(result.to_s)
173
- #unless ask_yes_no(result.to_s + "...keep Gem?", true) then
174
- #Gem::Uninstaller.new(gem_spec.name, gem_spec.version.version).uninstall
175
- #end
176
- end
177
- result
178
- ensure
179
- Dir.chdir(start_dir)
180
- end
181
189
 
182
- def remove_leading_dot_dir(path)
183
- path.sub(/^\.\//, "")
190
+ result = TestRunner.run suite, ui
191
+
192
+ alert_error result.to_s unless result.passed?
193
+ else
194
+ result = MiniTest::Unit.new
195
+ result.run
184
196
  end
197
+
198
+ result
199
+ ensure
200
+ Dir.chdir(start_dir)
201
+ end
202
+
203
+ def remove_leading_dot_dir(path)
204
+ path.sub(/^\.\//, "")
185
205
  end
206
+
186
207
  end
208
+