rubygems-update 1.1.1 → 1.2.0

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 (152) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +267 -1
  3. data/Rakefile +13 -7
  4. data/doc/release_notes/rel_1_2_0.rdoc +105 -0
  5. data/lib/rubygems.rb +82 -14
  6. data/lib/rubygems/command.rb +1 -1
  7. data/lib/rubygems/command_manager.rb +3 -2
  8. data/lib/rubygems/commands/cert_command.rb +1 -1
  9. data/lib/rubygems/commands/dependency_command.rb +57 -19
  10. data/lib/rubygems/commands/environment_command.rb +2 -0
  11. data/lib/rubygems/commands/fetch_command.rb +3 -1
  12. data/lib/rubygems/commands/install_command.rb +3 -3
  13. data/lib/rubygems/commands/list_command.rb +30 -28
  14. data/lib/rubygems/commands/lock_command.rb +1 -1
  15. data/lib/rubygems/commands/outdated_command.rb +5 -2
  16. data/lib/rubygems/commands/pristine_command.rb +3 -44
  17. data/lib/rubygems/commands/query_command.rb +80 -21
  18. data/lib/rubygems/commands/sources_command.rb +56 -28
  19. data/lib/rubygems/commands/specification_command.rb +4 -3
  20. data/lib/rubygems/commands/stale_command.rb +27 -0
  21. data/lib/rubygems/commands/update_command.rb +35 -22
  22. data/lib/rubygems/config_file.rb +29 -12
  23. data/lib/rubygems/custom_require.rb +1 -1
  24. data/lib/rubygems/defaults.rb +1 -1
  25. data/lib/rubygems/dependency.rb +63 -9
  26. data/lib/rubygems/dependency_installer.rb +60 -23
  27. data/lib/rubygems/dependency_list.rb +1 -1
  28. data/lib/rubygems/doc_manager.rb +5 -5
  29. data/lib/rubygems/gem_openssl.rb +1 -1
  30. data/lib/rubygems/indexer.rb +269 -84
  31. data/lib/rubygems/install_update_options.rb +6 -0
  32. data/lib/rubygems/installer.rb +35 -12
  33. data/lib/rubygems/local_remote_options.rb +26 -5
  34. data/lib/rubygems/platform.rb +15 -1
  35. data/lib/rubygems/remote_fetcher.rb +158 -90
  36. data/lib/rubygems/requirement.rb +16 -12
  37. data/lib/rubygems/rubygems_version.rb +1 -1
  38. data/lib/rubygems/security.rb +2 -2
  39. data/lib/rubygems/server.rb +239 -110
  40. data/lib/rubygems/source_index.rb +44 -18
  41. data/lib/rubygems/source_info_cache.rb +1 -1
  42. data/lib/rubygems/spec_fetcher.rb +251 -0
  43. data/lib/rubygems/specification.rb +120 -38
  44. data/lib/rubygems/test_utilities.rb +120 -0
  45. data/lib/rubygems/uninstaller.rb +11 -10
  46. data/lib/rubygems/user_interaction.rb +149 -74
  47. data/lib/rubygems/validator.rb +3 -3
  48. data/lib/rubygems/version.rb +23 -21
  49. data/setup.rb +105 -100
  50. data/test/gemutilities.rb +63 -86
  51. data/test/test_config.rb +0 -5
  52. data/test/test_gem.rb +22 -2
  53. data/test/test_gem_command_manager.rb +1 -1
  54. data/test/test_gem_commands_dependency_command.rb +125 -6
  55. data/test/test_gem_commands_environment_command.rb +1 -0
  56. data/test/test_gem_commands_fetch_command.rb +24 -4
  57. data/test/test_gem_commands_install_command.rb +6 -8
  58. data/test/{test_gem_outdated_command.rb → test_gem_commands_outdated_command.rb} +5 -2
  59. data/test/test_gem_commands_pristine_command.rb +13 -4
  60. data/test/test_gem_commands_query_command.rb +113 -37
  61. data/test/test_gem_commands_sources_command.rb +101 -31
  62. data/test/test_gem_commands_specification_command.rb +4 -1
  63. data/test/test_gem_commands_stale_command.rb +39 -0
  64. data/test/test_gem_commands_update_command.rb +17 -27
  65. data/test/test_gem_config_file.rb +38 -1
  66. data/test/test_gem_dependency.rb +51 -0
  67. data/test/test_gem_dependency_installer.rb +133 -25
  68. data/test/test_gem_gem_path_searcher.rb +4 -1
  69. data/test/test_gem_indexer.rb +124 -19
  70. data/test/test_gem_installer.rb +32 -2
  71. data/test/test_gem_local_remote_options.rb +6 -5
  72. data/test/test_gem_remote_fetcher.rb +14 -9
  73. data/test/test_gem_server.rb +207 -21
  74. data/test/test_gem_source_index.rb +203 -63
  75. data/test/test_gem_source_info_cache.rb +8 -6
  76. data/test/test_gem_source_info_cache_entry.rb +11 -9
  77. data/test/test_gem_spec_fetcher.rb +303 -0
  78. data/test/test_gem_specification.rb +91 -7
  79. data/test/test_gem_uninstaller.rb +21 -0
  80. data/test/test_gem_version.rb +14 -5
  81. data/test/test_kernel.rb +1 -1
  82. metadata +10 -73
  83. metadata.gz.sig +0 -0
  84. data/lib/rubygems/indexer/abstract_index_builder.rb +0 -88
  85. data/lib/rubygems/indexer/latest_index_builder.rb +0 -35
  86. data/lib/rubygems/indexer/marshal_index_builder.rb +0 -17
  87. data/lib/rubygems/indexer/master_index_builder.rb +0 -54
  88. data/lib/rubygems/indexer/quick_index_builder.rb +0 -50
  89. data/test/gem_installer_test_case.rbc +0 -0
  90. data/test/gem_package_tar_test_case.rbc +0 -0
  91. data/test/gemutilities.rbc +0 -0
  92. data/test/mockgemui.rbc +0 -0
  93. data/test/simple_gem.rbc +0 -0
  94. data/test/test_config.rbc +0 -0
  95. data/test/test_gem.rbc +0 -0
  96. data/test/test_gem_builder.rbc +0 -0
  97. data/test/test_gem_command.rbc +0 -0
  98. data/test/test_gem_command_manager.rbc +0 -0
  99. data/test/test_gem_commands_build_command.rbc +0 -0
  100. data/test/test_gem_commands_cert_command.rbc +0 -0
  101. data/test/test_gem_commands_check_command.rbc +0 -0
  102. data/test/test_gem_commands_contents_command.rbc +0 -0
  103. data/test/test_gem_commands_dependency_command.rbc +0 -0
  104. data/test/test_gem_commands_environment_command.rbc +0 -0
  105. data/test/test_gem_commands_fetch_command.rbc +0 -0
  106. data/test/test_gem_commands_generate_index_command.rbc +0 -0
  107. data/test/test_gem_commands_install_command.rbc +0 -0
  108. data/test/test_gem_commands_mirror_command.rbc +0 -0
  109. data/test/test_gem_commands_pristine_command.rbc +0 -0
  110. data/test/test_gem_commands_query_command.rbc +0 -0
  111. data/test/test_gem_commands_server_command.rbc +0 -0
  112. data/test/test_gem_commands_sources_command.rbc +0 -0
  113. data/test/test_gem_commands_specification_command.rbc +0 -0
  114. data/test/test_gem_commands_unpack_command.rbc +0 -0
  115. data/test/test_gem_commands_update_command.rbc +0 -0
  116. data/test/test_gem_config_file.rbc +0 -0
  117. data/test/test_gem_dependency.rbc +0 -0
  118. data/test/test_gem_dependency_installer.rbc +0 -0
  119. data/test/test_gem_dependency_list.rbc +0 -0
  120. data/test/test_gem_digest.rbc +0 -0
  121. data/test/test_gem_doc_manager.rbc +0 -0
  122. data/test/test_gem_ext_configure_builder.rbc +0 -0
  123. data/test/test_gem_ext_ext_conf_builder.rbc +0 -0
  124. data/test/test_gem_ext_rake_builder.rbc +0 -0
  125. data/test/test_gem_format.rbc +0 -0
  126. data/test/test_gem_gem_path_searcher.rbc +0 -0
  127. data/test/test_gem_gem_runner.rbc +0 -0
  128. data/test/test_gem_indexer.rbc +0 -0
  129. data/test/test_gem_install_update_options.rbc +0 -0
  130. data/test/test_gem_installer.rbc +0 -0
  131. data/test/test_gem_local_remote_options.rbc +0 -0
  132. data/test/test_gem_outdated_command.rbc +0 -0
  133. data/test/test_gem_package_tar_header.rbc +0 -0
  134. data/test/test_gem_package_tar_input.rbc +0 -0
  135. data/test/test_gem_package_tar_output.rbc +0 -0
  136. data/test/test_gem_package_tar_reader.rbc +0 -0
  137. data/test/test_gem_package_tar_reader_entry.rbc +0 -0
  138. data/test/test_gem_package_tar_writer.rbc +0 -0
  139. data/test/test_gem_platform.rbc +0 -0
  140. data/test/test_gem_remote_fetcher.rbc +0 -0
  141. data/test/test_gem_requirement.rbc +0 -0
  142. data/test/test_gem_server.rbc +0 -0
  143. data/test/test_gem_source_index.rbc +0 -0
  144. data/test/test_gem_source_info_cache.rbc +0 -0
  145. data/test/test_gem_source_info_cache_entry.rbc +0 -0
  146. data/test/test_gem_specification.rbc +0 -0
  147. data/test/test_gem_stream_ui.rbc +0 -0
  148. data/test/test_gem_uninstaller.rbc +0 -0
  149. data/test/test_gem_validator.rbc +0 -0
  150. data/test/test_gem_version.rbc +0 -0
  151. data/test/test_gem_version_option.rbc +0 -0
  152. data/test/test_kernel.rbc +0 -0
@@ -42,7 +42,7 @@ module Gem
42
42
  #
43
43
  # gem_path:: [String] Path to gem file
44
44
  def verify_gem_file(gem_path)
45
- File.open gem_path, 'rb' do |file|
45
+ open gem_path, Gem.binary_mode do |file|
46
46
  gem_data = file.read
47
47
  verify_gem gem_data
48
48
  end
@@ -91,7 +91,7 @@ module Gem
91
91
 
92
92
  begin
93
93
  verify_gem_file(gem_path)
94
- File.open(gem_path, 'rb') do |file|
94
+ open gem_path, Gem.binary_mode do |file|
95
95
  format = Gem::Format.from_file_by_path(gem_path)
96
96
  format.file_entries.each do |entry, data|
97
97
  # Found this file. Delete it from list
@@ -99,7 +99,7 @@ module Gem
99
99
 
100
100
  next unless data # HACK `gem check -a mkrf`
101
101
 
102
- File.open(File.join(gem_directory, entry['path']), 'rb') do |f|
102
+ open File.join(gem_directory, entry['path']), Gem.binary_mode do |f|
103
103
  unless Gem::MD5.hexdigest(f.read).to_s ==
104
104
  Gem::MD5.hexdigest(data).to_s then
105
105
  errors[gem_name] << ErrorData.new(entry['path'], "installed file doesn't match original from gem")
@@ -8,6 +8,7 @@ require 'rubygems'
8
8
 
9
9
  ##
10
10
  # The Version class processes string versions into comparable values
11
+
11
12
  class Gem::Version
12
13
 
13
14
  include Comparable
@@ -17,11 +18,8 @@ class Gem::Version
17
18
  attr_reader :version
18
19
 
19
20
  ##
20
- # Checks if version string is valid format
21
- #
22
- # str:: [String] the version string
23
- # return:: [Boolean] true if the string format is correct, otherwise false
24
- #
21
+ # Returns true if +version+ is a valid version string.
22
+
25
23
  def self.correct?(version)
26
24
  case version
27
25
  when Integer, /\A\s*(\d+(\.\d+)*)*\s*\z/ then true
@@ -36,7 +34,7 @@ class Gem::Version
36
34
  # ver1 = Version.create('1.3.17') # -> (Version object)
37
35
  # ver2 = Version.create(ver1) # -> (ver1)
38
36
  # ver3 = Version.create(nil) # -> nil
39
- #
37
+
40
38
  def self.create(input)
41
39
  if input.respond_to? :version then
42
40
  input
@@ -48,10 +46,9 @@ class Gem::Version
48
46
  end
49
47
 
50
48
  ##
51
- # Constructs a version from the supplied string
52
- #
53
- # version:: [String] The version string. Format is digit.digit...
54
- #
49
+ # Constructs a Version from the +version+ string. A version string is a
50
+ # series of digits separated by dots.
51
+
55
52
  def initialize(version)
56
53
  raise ArgumentError, "Malformed version number string #{version}" unless
57
54
  self.class.correct?(version)
@@ -73,7 +70,9 @@ class Gem::Version
73
70
  self.version = array[0]
74
71
  end
75
72
 
73
+ ##
76
74
  # Strip ignored trailing zeros.
75
+
77
76
  def normalize
78
77
  @ints = build_array_from_version_string
79
78
 
@@ -94,10 +93,8 @@ class Gem::Version
94
93
  end
95
94
 
96
95
  ##
97
- # Convert version to integer array
98
- #
99
- # return:: [Array] list of integers
100
- #
96
+ # Returns an integer array representation of this Version.
97
+
101
98
  def to_ints
102
99
  normalize unless @ints
103
100
  @ints
@@ -117,20 +114,25 @@ class Gem::Version
117
114
  end
118
115
 
119
116
  ##
120
- # Compares two versions
121
- #
122
- # other:: [Version or .ints] other version to compare to
123
- # return:: [Fixnum] -1, 0, 1
124
- #
117
+ # Compares this version with +other+ returning -1, 0, or 1 if the other
118
+ # version is larger, the same, or smaller than this one.
119
+
125
120
  def <=>(other)
121
+ return nil unless self.class === other
126
122
  return 1 unless other
127
123
  @ints <=> other.ints
128
124
  end
129
125
 
130
- alias eql? == # :nodoc:
126
+ ##
127
+ # A Version is only eql? to another version if it has the same version
128
+ # string. "1.0" is not the same version as "1".
129
+
130
+ def eql?(other)
131
+ self.class === other and @version == other.version
132
+ end
131
133
 
132
134
  def hash # :nodoc:
133
- to_ints.inject { |hash_code, n| hash_code + n }
135
+ @version.hash
134
136
  end
135
137
 
136
138
  # Return a new version object where the next to the last revision
data/setup.rb CHANGED
@@ -20,35 +20,83 @@ end
20
20
 
21
21
  $:.unshift 'lib'
22
22
  require 'rubygems'
23
+ require 'getoptlong'
24
+
25
+ opts = GetoptLong.new(
26
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
27
+ [ '--prefix', GetoptLong::REQUIRED_ARGUMENT ],
28
+ [ '--no-format-executable', GetoptLong::NO_ARGUMENT ],
29
+ [ '--no-rdoc', GetoptLong::NO_ARGUMENT ],
30
+ [ '--no-ri', GetoptLong::NO_ARGUMENT ],
31
+ [ '--vendor', GetoptLong::NO_ARGUMENT ],
32
+ [ '--destdir', GetoptLong::REQUIRED_ARGUMENT ]
33
+ )
34
+
35
+ prefix = ''
36
+ format_executable = true
37
+ rdoc = true
38
+ ri = true
39
+ site_or_vendor = :sitelibdir
40
+ install_destdir = ''
41
+
42
+ opts.each do | opt, arg |
43
+ case opt
44
+ when '--help'
45
+ puts <<HELP
46
+ ruby setup.rb [options]:
47
+
48
+ RubyGems will install the gem command with a name matching ruby's
49
+ prefix and suffix. If ruby was installed as `ruby18`, gem will be
50
+ installed as `gem18`.
51
+
52
+ By default, this RubyGems will install gem as:
53
+ #{Gem.default_exec_format % 'gem'}
54
+
55
+ Options:
56
+ --help Print this message
57
+ --prefix=DIR Prefix path for installing RubyGems
58
+ Will not affect gem repository location
59
+ --no-format-executable Force installation as `gem`
60
+ --no-rdoc Don't build RDoc for RubyGems
61
+ --no-ri Don't build ri for RubyGems
62
+ --vendor Install into vendorlibdir not sitelibdir
63
+ (Requires Ruby 1.8.7)
64
+ --destdir Root directory to install rubygems into
65
+ Used mainly for packaging RubyGems
66
+ HELP
67
+ exit 0
68
+
69
+ when '--no-rdoc'
70
+ rdoc = false
71
+
72
+ when '--no-ri'
73
+ ri = false
74
+
75
+ when '--no-format-executable'
76
+ format_executable = false
77
+
78
+ when '--prefix'
79
+ prefix = File.expand_path(arg)
80
+
81
+ when '--vendor'
82
+ vendor_dir_version = Gem::Version::Requirement.create('>= 1.8.7')
83
+ unless vendor_dir_version.satisfied_by? Gem.ruby_version then
84
+ abort "To use --vendor you need ruby #{vendor_dir_version}, current #{Gem.ruby_version}"
85
+ end
86
+ site_or_vendor = :vendorlibdir
87
+
88
+ when '--destdir'
89
+ install_destdir = File.expand_path(arg)
90
+ end
91
+ end
23
92
 
24
- if ARGV.include? '--help' or ARGV.include? '-h' then
25
- puts "ruby setup.rb [options]:"
26
- puts
27
- puts "RubyGems will install the gem command with a name matching ruby's"
28
- puts "prefix and suffix. If ruby was installed as `ruby18`, gem will be"
29
- puts "installed as `gem18`."
30
- puts
31
- puts "By default, this RubyGems will install gem as:"
32
- puts
33
- puts " #{Gem.default_exec_format % 'gem'}"
34
- puts
35
- puts "Options:"
36
- puts
37
- puts " --prefix=DIR Prefix path for installing RubyGems"
38
- puts " Will not affect gem repository location"
39
- puts
40
- puts " --no-format-executable Force installation as `gem`"
41
- puts
42
- puts " --no-rdoc Don't build RDoc for RubyGems"
43
- puts
44
- puts " --no-ri Don't build ri for RubyGems"
45
-
46
- exit
93
+ unless install_destdir.empty? then
94
+ ENV['GEM_HOME'] ||= File.join(install_destdir,
95
+ Gem.default_dir.sub(/\A[a-z]:/i, ''))
47
96
  end
48
97
 
49
98
  require 'fileutils'
50
99
  require 'rbconfig'
51
- require 'rdoc/rdoc'
52
100
  require 'tmpdir'
53
101
 
54
102
  include FileUtils::Verbose
@@ -66,42 +114,33 @@ end
66
114
  lib_dir = nil
67
115
  bin_dir = nil
68
116
 
69
- if ARGV.grep(/^--prefix/).empty? then
70
- lib_dir = Gem::ConfigMap[:sitelibdir]
117
+ if prefix.empty?
118
+ lib_dir = Gem::ConfigMap[site_or_vendor]
71
119
  bin_dir = Gem::ConfigMap[:bindir]
72
120
  else
73
- prefix = nil
74
-
75
- prefix_arg = ARGV.grep(/^--prefix=/).first
76
- if prefix_arg =~ /^--prefix=(.*)/ then
77
- prefix = $1
78
- else
79
- path_index = ARGV.index '--prefix'
80
- prefix = ARGV[path_index + 1]
81
- end
82
-
83
- prefix = File.expand_path prefix
84
-
85
- raise "invalid --prefix #{prefix.inspect}" if prefix.nil?
86
-
87
121
  # Apple installed RubyGems into libdir, and RubyGems <= 1.1.0 gets confused
88
- # about installation location, so switch back to sitelibdir.
122
+ # about installation location, so switch back to sitelibdir/vendorlibdir.
89
123
  if defined?(APPLE_GEM_HOME) and
90
124
  # just in case Apple and RubyGems don't get this patched up proper.
91
125
  (prefix == Gem::ConfigMap[:libdir] or
92
126
  # this one is important
93
127
  prefix == File.join(Gem::ConfigMap[:libdir], 'ruby')) then
94
- lib_dir = Gem::ConfigMap[:sitelibdir]
128
+ lib_dir = Gem::ConfigMap[site_or_vendor]
95
129
  bin_dir = Gem::ConfigMap[:bindir]
96
130
  else
97
131
  lib_dir = File.join prefix, 'lib'
98
132
  bin_dir = File.join prefix, 'bin'
99
-
100
- mkdir_p lib_dir
101
- mkdir_p bin_dir
102
133
  end
103
134
  end
104
135
 
136
+ unless install_destdir.empty?
137
+ lib_dir = File.join install_destdir, lib_dir
138
+ bin_dir = File.join install_destdir, bin_dir
139
+ end
140
+
141
+ mkdir_p lib_dir
142
+ mkdir_p bin_dir
143
+
105
144
  Dir.chdir 'lib' do
106
145
  lib_files = Dir[File.join('**', '*rb')]
107
146
 
@@ -122,10 +161,10 @@ Dir.chdir 'bin' do
122
161
  bin_files.delete 'update_rubygems'
123
162
 
124
163
  bin_files.each do |bin_file|
125
- bin_file_formatted = if ARGV.include? '--no-format-executable' then
126
- bin_file
127
- else
164
+ bin_file_formatted = if format_executable then
128
165
  Gem.default_exec_format % bin_file
166
+ else
167
+ bin_file
129
168
  end
130
169
 
131
170
  dest_file = File.join bin_dir, bin_file_formatted
@@ -202,14 +241,17 @@ abort "#{deprecation_message}"
202
241
  end
203
242
 
204
243
  # Remove source caches
244
+ if install_destdir.empty?
245
+ require 'rubygems/source_info_cache'
205
246
 
206
- require 'rubygems/source_info_cache'
207
-
208
- user_cache_file = Gem::SourceInfoCache.user_cache_file
209
- system_cache_file = Gem::SourceInfoCache.system_cache_file
247
+ user_cache_file = File.join(install_destdir,
248
+ Gem::SourceInfoCache.user_cache_file)
249
+ system_cache_file = File.join(install_destdir,
250
+ Gem::SourceInfoCache.system_cache_file)
210
251
 
211
- rm_f user_cache_file if File.writable? File.dirname(user_cache_file)
212
- rm_f system_cache_file if File.writable? File.dirname(system_cache_file)
252
+ rm_f user_cache_file if File.writable? File.dirname(user_cache_file)
253
+ rm_f system_cache_file if File.writable? File.dirname(system_cache_file)
254
+ end
213
255
 
214
256
  # install RDoc
215
257
 
@@ -226,6 +268,13 @@ if File.writable? gem_doc_dir and
226
268
  end
227
269
 
228
270
  def run_rdoc(*args)
271
+ begin
272
+ gem 'rdoc'
273
+ rescue Gem::LoadError
274
+ end
275
+
276
+ require 'rdoc/rdoc'
277
+
229
278
  args << '--quiet'
230
279
  args << '--main' << 'README'
231
280
  args << '.' << 'README' << 'LICENSE.txt' << 'GPL.txt'
@@ -234,13 +283,13 @@ if File.writable? gem_doc_dir and
234
283
  r.document args
235
284
  end
236
285
 
237
- unless ARGV.include? '--no-ri' then
286
+ if ri then
238
287
  ri_dir = File.join rubygems_doc_dir, 'ri'
239
288
  puts "Installing #{rubygems_name} ri into #{ri_dir}"
240
289
  run_rdoc '--ri', '--op', ri_dir
241
290
  end
242
291
 
243
- unless ARGV.include? '--no-rdoc' then
292
+ if rdoc then
244
293
  rdoc_dir = File.join rubygems_doc_dir, 'rdoc'
245
294
  puts "Installing #{rubygems_name} rdoc into #{rdoc_dir}"
246
295
  run_rdoc '--op', rdoc_dir
@@ -250,50 +299,6 @@ else
250
299
  puts "Set the GEM_HOME environment variable if you want RDoc generated"
251
300
  end
252
301
 
253
- # Remove stubs
254
-
255
- def stub?(path)
256
- return unless File.readable? path
257
- File.read(path, 40) =~ /^# This file was generated by RubyGems/ and
258
- File.readlines(path).size < 20
259
- end
260
-
261
- puts "As of RubyGems 0.8.0, library stubs are no longer needed."
262
- puts "Searching $LOAD_PATH for stubs to optionally delete (may take a while)"
263
-
264
- gemfiles = Dir[File.join("{#{($LOAD_PATH).join(',')}}", '**', '*.rb')]
265
- gemfiles = gemfiles.map { |file| File.expand_path file }.uniq
266
-
267
- puts "...done."
268
-
269
- seen_stub = false
270
-
271
- gemfiles.each do |file|
272
- next if File.directory? file
273
- next unless stub? file
274
-
275
- unless seen_stub then
276
- puts "\nRubyGems has detected stubs that can be removed. Confirm their removal:"
277
- end
278
- seen_stub = true
279
-
280
- print " * remove #{file}? [y/n] "
281
- answer = gets
282
-
283
- if answer =~ /y/i then
284
- unlink file
285
- puts " (removed)"
286
- else
287
- puts " (skipping)"
288
- end
289
- end
290
-
291
- if seen_stub then
292
- puts "Finished with library stubs."
293
- else
294
- puts "No library stubs found."
295
- end
296
-
297
302
  puts
298
303
  puts "-" * 78
299
304
  puts
@@ -10,10 +10,9 @@ at_exit { $SAFE = 1 }
10
10
  require 'fileutils'
11
11
  require 'test/unit'
12
12
  require 'tmpdir'
13
- require 'tempfile'
14
13
  require 'uri'
15
- require 'rubygems/source_info_cache'
16
14
  require 'rubygems/package'
15
+ require 'rubygems/test_utilities'
17
16
 
18
17
  require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui')
19
18
 
@@ -27,54 +26,6 @@ module Gem
27
26
  end
28
27
  end
29
28
 
30
- class FakeFetcher
31
-
32
- attr_reader :data
33
- attr_accessor :uri
34
- attr_accessor :paths
35
-
36
- def initialize
37
- @data = {}
38
- @paths = []
39
- @uri = nil
40
- end
41
-
42
- def fetch_path(path)
43
- path = path.to_s
44
- @paths << path
45
- raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
46
- data = @data[path]
47
- raise Gem::RemoteFetcher::FetchError, "no data for #{path}" if data.nil?
48
- data.respond_to?(:call) ? data.call : data
49
- end
50
-
51
- def fetch_size(path)
52
- path = path.to_s
53
- @paths << path
54
- raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
55
- data = @data[path]
56
- raise Gem::RemoteFetcher::FetchError, "no data for #{path}" if data.nil?
57
- data.respond_to?(:call) ? data.call : data.length
58
- end
59
-
60
- def download spec, source_uri, install_dir = Gem.dir
61
- name = "#{spec.full_name}.gem"
62
- path = File.join(install_dir, 'cache', name)
63
-
64
- Gem.ensure_gem_subdirectories install_dir
65
-
66
- if source_uri =~ /^http/ then
67
- File.open(path, "wb") do |f|
68
- f.write fetch_path(File.join(source_uri, "gems", name))
69
- end
70
- else
71
- FileUtils.cp source_uri, path
72
- end
73
-
74
- path
75
- end
76
- end
77
-
78
29
  class RubyGemTestCase < Test::Unit::TestCase
79
30
 
80
31
  include Gem::DefaultUserInteraction
@@ -94,8 +45,13 @@ class RubyGemTestCase < Test::Unit::TestCase
94
45
  @gemcache = File.join(@gemhome, "source_cache")
95
46
  @usrcache = File.join(@gemhome, ".gem", "user_cache")
96
47
  @latest_usrcache = File.join(@gemhome, ".gem", "latest_user_cache")
48
+ @userhome = File.join @tempdir, 'userhome'
49
+
50
+ ENV['HOME'] = @userhome
51
+ Gem.instance_variable_set :@user_home, nil
97
52
 
98
53
  FileUtils.mkdir_p @gemhome
54
+ FileUtils.mkdir_p @userhome
99
55
 
100
56
  ENV['GEMCACHE'] = @usrcache
101
57
  Gem.use_paths(@gemhome)
@@ -104,9 +60,12 @@ class RubyGemTestCase < Test::Unit::TestCase
104
60
  Gem.configuration.verbose = true
105
61
  Gem.configuration.update_sources = true
106
62
 
107
- @gem_repo = "http://gems.example.com"
63
+ @gem_repo = "http://gems.example.com/"
64
+ @uri = URI.parse @gem_repo
108
65
  Gem.sources.replace [@gem_repo]
109
66
 
67
+ Gem::SpecFetcher.fetcher = nil
68
+
110
69
  @orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
111
70
  Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:RUBY_INSTALL_NAME]
112
71
 
@@ -131,7 +90,7 @@ class RubyGemTestCase < Test::Unit::TestCase
131
90
  Gem::ConfigMap[:arch] = @orig_arch
132
91
 
133
92
  if defined? Gem::RemoteFetcher then
134
- Gem::RemoteFetcher.instance_variable_set :@fetcher, nil
93
+ Gem::RemoteFetcher.fetcher = nil
135
94
  end
136
95
 
137
96
  FileUtils.rm_rf @tempdir
@@ -141,7 +100,6 @@ class RubyGemTestCase < Test::Unit::TestCase
141
100
  ENV.delete 'GEM_PATH'
142
101
 
143
102
  Gem.clear_paths
144
- Gem::SourceInfoCache.instance_variable_set :@cache, nil
145
103
  end
146
104
 
147
105
  def install_gem gem
@@ -154,7 +112,7 @@ class RubyGemTestCase < Test::Unit::TestCase
154
112
  end
155
113
 
156
114
  gem = File.join(@tempdir, "#{gem.full_name}.gem").untaint
157
- Gem::Installer.new(gem).install
115
+ Gem::Installer.new(gem, :wrappers => true).install
158
116
  end
159
117
 
160
118
  def prep_cache_files(lc)
@@ -231,6 +189,8 @@ class RubyGemTestCase < Test::Unit::TestCase
231
189
 
232
190
  spec.loaded_from = written_path
233
191
 
192
+ Gem.source_index.add_spec spec
193
+
234
194
  return spec
235
195
  end
236
196
 
@@ -254,6 +214,12 @@ class RubyGemTestCase < Test::Unit::TestCase
254
214
  end
255
215
  end
256
216
 
217
+ def util_clear_gems
218
+ FileUtils.rm_r File.join(@gemhome, 'gems')
219
+ FileUtils.rm_r File.join(@gemhome, 'specifications')
220
+ Gem.source_index.refresh!
221
+ end
222
+
257
223
  def util_gem(name, version, &block)
258
224
  spec = quick_gem(name, version, &block)
259
225
 
@@ -271,6 +237,16 @@ class RubyGemTestCase < Test::Unit::TestCase
271
237
  [spec, cache_file]
272
238
  end
273
239
 
240
+ def util_gzip(data)
241
+ out = StringIO.new
242
+
243
+ Zlib::GzipWriter.wrap out do |io|
244
+ io.write data
245
+ end
246
+
247
+ out.string
248
+ end
249
+
274
250
  def util_make_gems
275
251
  init = proc do |s|
276
252
  s.files = %w[lib/code.rb]
@@ -303,7 +279,7 @@ class RubyGemTestCase < Test::Unit::TestCase
303
279
  end
304
280
 
305
281
  ##
306
- # Set the platform to +cpu+ and +os+
282
+ # Set the platform to +arch+
307
283
 
308
284
  def util_set_arch(arch)
309
285
  Gem::ConfigMap[:arch] = arch
@@ -320,9 +296,7 @@ class RubyGemTestCase < Test::Unit::TestCase
320
296
  require 'socket'
321
297
  require 'rubygems/remote_fetcher'
322
298
 
323
- @uri = URI.parse @gem_repo
324
- @fetcher = FakeFetcher.new
325
- @fetcher.uri = @uri
299
+ @fetcher = Gem::FakeFetcher.new
326
300
 
327
301
  util_make_gems
328
302
 
@@ -338,10 +312,11 @@ class RubyGemTestCase < Test::Unit::TestCase
338
312
  @source_index.add_spec @a_evil9
339
313
  @source_index.add_spec @c1_2
340
314
 
341
- Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
315
+ Gem::RemoteFetcher.fetcher = @fetcher
342
316
  end
343
317
 
344
318
  def util_setup_source_info_cache(*specs)
319
+ require 'rubygems/source_info_cache'
345
320
  require 'rubygems/source_info_cache_entry'
346
321
 
347
322
  specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
@@ -356,6 +331,35 @@ class RubyGemTestCase < Test::Unit::TestCase
356
331
  sic.reset_cache_data
357
332
 
358
333
  Gem::SourceInfoCache.instance_variable_set :@cache, sic
334
+
335
+ si
336
+ end
337
+
338
+ def util_setup_spec_fetcher(*specs)
339
+ specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
340
+ si = Gem::SourceIndex.new specs
341
+
342
+ spec_fetcher = Gem::SpecFetcher.fetcher
343
+
344
+ spec_fetcher.specs[@uri] = []
345
+ si.gems.sort_by { |_, spec| spec }.each do |_, spec|
346
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
347
+ spec_fetcher.specs[@uri] << spec_tuple
348
+ end
349
+
350
+ spec_fetcher.latest_specs[@uri] = []
351
+ si.latest_specs.sort.each do |spec|
352
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
353
+ spec_fetcher.latest_specs[@uri] << spec_tuple
354
+ end
355
+
356
+ si.gems.sort_by { |_,spec| spec }.each do |_, spec|
357
+ path = "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{spec.original_name}.gemspec.rz"
358
+ data = Marshal.dump spec
359
+ data_deflate = Zlib::Deflate.deflate data
360
+ @fetcher.data[path] = data_deflate
361
+ end
362
+
359
363
  si
360
364
  end
361
365
 
@@ -384,30 +388,3 @@ class RubyGemTestCase < Test::Unit::TestCase
384
388
 
385
389
  end
386
390
 
387
- class TempIO
388
-
389
- @@count = 0
390
-
391
- def initialize(string = '')
392
- @tempfile = Tempfile.new "TempIO-#{@@count ++ 1}"
393
- @tempfile.binmode
394
- @tempfile.write string
395
- @tempfile.rewind
396
- end
397
-
398
- def method_missing(meth, *args, &block)
399
- @tempfile.send(meth, *args, &block)
400
- end
401
-
402
- def respond_to?(meth)
403
- @tempfile.respond_to? meth
404
- end
405
-
406
- def string
407
- @tempfile.flush
408
-
409
- Gem.read_binary @tempfile.path
410
- end
411
-
412
- end
413
-