slimgems 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/ChangeLog +5811 -0
  2. data/History.txt +887 -0
  3. data/LICENSE.txt +51 -0
  4. data/README.md +87 -0
  5. data/Rakefile +120 -0
  6. data/bin/gem +25 -0
  7. data/bin/update_slimgems +35 -0
  8. data/bootstrap/Rakefile +4 -0
  9. data/hide_lib_for_update/note.txt +5 -0
  10. data/lib/gauntlet_rubygems.rb +50 -0
  11. data/lib/rbconfig/datadir.rb +20 -0
  12. data/lib/rubygems.rb +1220 -0
  13. data/lib/rubygems/builder.rb +102 -0
  14. data/lib/rubygems/command.rb +534 -0
  15. data/lib/rubygems/command_manager.rb +182 -0
  16. data/lib/rubygems/commands/build_command.rb +53 -0
  17. data/lib/rubygems/commands/cert_command.rb +86 -0
  18. data/lib/rubygems/commands/check_command.rb +80 -0
  19. data/lib/rubygems/commands/cleanup_command.rb +106 -0
  20. data/lib/rubygems/commands/contents_command.rb +98 -0
  21. data/lib/rubygems/commands/dependency_command.rb +195 -0
  22. data/lib/rubygems/commands/environment_command.rb +132 -0
  23. data/lib/rubygems/commands/fetch_command.rb +67 -0
  24. data/lib/rubygems/commands/generate_index_command.rb +133 -0
  25. data/lib/rubygems/commands/help_command.rb +172 -0
  26. data/lib/rubygems/commands/install_command.rb +178 -0
  27. data/lib/rubygems/commands/list_command.rb +35 -0
  28. data/lib/rubygems/commands/lock_command.rb +110 -0
  29. data/lib/rubygems/commands/mirror_command.rb +111 -0
  30. data/lib/rubygems/commands/outdated_command.rb +33 -0
  31. data/lib/rubygems/commands/owner_command.rb +75 -0
  32. data/lib/rubygems/commands/pristine_command.rb +93 -0
  33. data/lib/rubygems/commands/push_command.rb +56 -0
  34. data/lib/rubygems/commands/query_command.rb +280 -0
  35. data/lib/rubygems/commands/rdoc_command.rb +91 -0
  36. data/lib/rubygems/commands/search_command.rb +31 -0
  37. data/lib/rubygems/commands/server_command.rb +86 -0
  38. data/lib/rubygems/commands/setup_command.rb +387 -0
  39. data/lib/rubygems/commands/sources_command.rb +157 -0
  40. data/lib/rubygems/commands/specification_command.rb +125 -0
  41. data/lib/rubygems/commands/stale_command.rb +27 -0
  42. data/lib/rubygems/commands/uninstall_command.rb +83 -0
  43. data/lib/rubygems/commands/unpack_command.rb +121 -0
  44. data/lib/rubygems/commands/update_command.rb +212 -0
  45. data/lib/rubygems/commands/which_command.rb +86 -0
  46. data/lib/rubygems/config_file.rb +345 -0
  47. data/lib/rubygems/custom_require.rb +44 -0
  48. data/lib/rubygems/defaults.rb +101 -0
  49. data/lib/rubygems/dependency.rb +227 -0
  50. data/lib/rubygems/dependency_installer.rb +286 -0
  51. data/lib/rubygems/dependency_list.rb +208 -0
  52. data/lib/rubygems/doc_manager.rb +242 -0
  53. data/lib/rubygems/errors.rb +35 -0
  54. data/lib/rubygems/exceptions.rb +91 -0
  55. data/lib/rubygems/ext.rb +18 -0
  56. data/lib/rubygems/ext/builder.rb +56 -0
  57. data/lib/rubygems/ext/configure_builder.rb +25 -0
  58. data/lib/rubygems/ext/ext_conf_builder.rb +24 -0
  59. data/lib/rubygems/ext/rake_builder.rb +39 -0
  60. data/lib/rubygems/format.rb +81 -0
  61. data/lib/rubygems/gem_openssl.rb +92 -0
  62. data/lib/rubygems/gem_path_searcher.rb +100 -0
  63. data/lib/rubygems/gem_runner.rb +79 -0
  64. data/lib/rubygems/gemcutter_utilities.rb +49 -0
  65. data/lib/rubygems/indexer.rb +720 -0
  66. data/lib/rubygems/install_update_options.rb +125 -0
  67. data/lib/rubygems/installer.rb +604 -0
  68. data/lib/rubygems/local_remote_options.rb +135 -0
  69. data/lib/rubygems/old_format.rb +153 -0
  70. data/lib/rubygems/package.rb +97 -0
  71. data/lib/rubygems/package/f_sync_dir.rb +23 -0
  72. data/lib/rubygems/package/tar_header.rb +266 -0
  73. data/lib/rubygems/package/tar_input.rb +222 -0
  74. data/lib/rubygems/package/tar_output.rb +144 -0
  75. data/lib/rubygems/package/tar_reader.rb +106 -0
  76. data/lib/rubygems/package/tar_reader/entry.rb +141 -0
  77. data/lib/rubygems/package/tar_writer.rb +241 -0
  78. data/lib/rubygems/package_task.rb +126 -0
  79. data/lib/rubygems/platform.rb +183 -0
  80. data/lib/rubygems/remote_fetcher.rb +414 -0
  81. data/lib/rubygems/require_paths_builder.rb +18 -0
  82. data/lib/rubygems/requirement.rb +153 -0
  83. data/lib/rubygems/security.rb +814 -0
  84. data/lib/rubygems/server.rb +872 -0
  85. data/lib/rubygems/source_index.rb +597 -0
  86. data/lib/rubygems/source_info_cache.rb +395 -0
  87. data/lib/rubygems/source_info_cache_entry.rb +56 -0
  88. data/lib/rubygems/spec_fetcher.rb +337 -0
  89. data/lib/rubygems/specification.rb +1486 -0
  90. data/lib/rubygems/test_utilities.rb +147 -0
  91. data/lib/rubygems/text.rb +65 -0
  92. data/lib/rubygems/uninstaller.rb +278 -0
  93. data/lib/rubygems/user_interaction.rb +527 -0
  94. data/lib/rubygems/validator.rb +240 -0
  95. data/lib/rubygems/version.rb +316 -0
  96. data/lib/rubygems/version_option.rb +65 -0
  97. data/lib/ubygems.rb +10 -0
  98. data/setup.rb +42 -0
  99. data/test/bogussources.rb +8 -0
  100. data/test/data/gem-private_key.pem +27 -0
  101. data/test/data/gem-public_cert.pem +20 -0
  102. data/test/fake_certlib/openssl.rb +7 -0
  103. data/test/foo/discover.rb +0 -0
  104. data/test/functional.rb +92 -0
  105. data/test/gem_installer_test_case.rb +97 -0
  106. data/test/gem_package_tar_test_case.rb +132 -0
  107. data/test/gemutilities.rb +605 -0
  108. data/test/insure_session.rb +43 -0
  109. data/test/mockgemui.rb +56 -0
  110. data/test/plugin/exception/rubygems_plugin.rb +2 -0
  111. data/test/plugin/load/rubygems_plugin.rb +1 -0
  112. data/test/plugin/standarderror/rubygems_plugin.rb +2 -0
  113. data/test/private_key.pem +27 -0
  114. data/test/public_cert.pem +20 -0
  115. data/test/rubygems_plugin.rb +21 -0
  116. data/test/simple_gem.rb +66 -0
  117. data/test/test_config.rb +12 -0
  118. data/test/test_gem.rb +766 -0
  119. data/test/test_gem_builder.rb +27 -0
  120. data/test/test_gem_command.rb +178 -0
  121. data/test/test_gem_command_manager.rb +207 -0
  122. data/test/test_gem_commands_build_command.rb +74 -0
  123. data/test/test_gem_commands_cert_command.rb +124 -0
  124. data/test/test_gem_commands_check_command.rb +18 -0
  125. data/test/test_gem_commands_contents_command.rb +156 -0
  126. data/test/test_gem_commands_dependency_command.rb +216 -0
  127. data/test/test_gem_commands_environment_command.rb +144 -0
  128. data/test/test_gem_commands_fetch_command.rb +76 -0
  129. data/test/test_gem_commands_generate_index_command.rb +135 -0
  130. data/test/test_gem_commands_install_command.rb +315 -0
  131. data/test/test_gem_commands_list_command.rb +36 -0
  132. data/test/test_gem_commands_lock_command.rb +68 -0
  133. data/test/test_gem_commands_mirror_command.rb +60 -0
  134. data/test/test_gem_commands_outdated_command.rb +40 -0
  135. data/test/test_gem_commands_owner_command.rb +105 -0
  136. data/test/test_gem_commands_pristine_command.rb +108 -0
  137. data/test/test_gem_commands_push_command.rb +81 -0
  138. data/test/test_gem_commands_query_command.rb +426 -0
  139. data/test/test_gem_commands_server_command.rb +59 -0
  140. data/test/test_gem_commands_sources_command.rb +209 -0
  141. data/test/test_gem_commands_specification_command.rb +139 -0
  142. data/test/test_gem_commands_stale_command.rb +38 -0
  143. data/test/test_gem_commands_uninstall_command.rb +83 -0
  144. data/test/test_gem_commands_unpack_command.rb +199 -0
  145. data/test/test_gem_commands_update_command.rb +353 -0
  146. data/test/test_gem_commands_which_command.rb +66 -0
  147. data/test/test_gem_config_file.rb +287 -0
  148. data/test/test_gem_dependency.rb +149 -0
  149. data/test/test_gem_dependency_installer.rb +661 -0
  150. data/test/test_gem_dependency_list.rb +230 -0
  151. data/test/test_gem_doc_manager.rb +31 -0
  152. data/test/test_gem_ext_configure_builder.rb +84 -0
  153. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  154. data/test/test_gem_ext_rake_builder.rb +81 -0
  155. data/test/test_gem_format.rb +70 -0
  156. data/test/test_gem_gem_path_searcher.rb +78 -0
  157. data/test/test_gem_gem_runner.rb +45 -0
  158. data/test/test_gem_gemcutter_utilities.rb +103 -0
  159. data/test/test_gem_indexer.rb +673 -0
  160. data/test/test_gem_install_update_options.rb +68 -0
  161. data/test/test_gem_installer.rb +857 -0
  162. data/test/test_gem_local_remote_options.rb +97 -0
  163. data/test/test_gem_package_tar_header.rb +130 -0
  164. data/test/test_gem_package_tar_input.rb +112 -0
  165. data/test/test_gem_package_tar_output.rb +97 -0
  166. data/test/test_gem_package_tar_reader.rb +46 -0
  167. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  168. data/test/test_gem_package_tar_writer.rb +144 -0
  169. data/test/test_gem_package_task.rb +59 -0
  170. data/test/test_gem_platform.rb +264 -0
  171. data/test/test_gem_remote_fetcher.rb +740 -0
  172. data/test/test_gem_requirement.rb +292 -0
  173. data/test/test_gem_server.rb +356 -0
  174. data/test/test_gem_silent_ui.rb +113 -0
  175. data/test/test_gem_source_index.rb +461 -0
  176. data/test/test_gem_spec_fetcher.rb +410 -0
  177. data/test/test_gem_specification.rb +1291 -0
  178. data/test/test_gem_stream_ui.rb +218 -0
  179. data/test/test_gem_text.rb +43 -0
  180. data/test/test_gem_uninstaller.rb +146 -0
  181. data/test/test_gem_validator.rb +63 -0
  182. data/test/test_gem_version.rb +181 -0
  183. data/test/test_gem_version_option.rb +89 -0
  184. data/test/test_kernel.rb +59 -0
  185. metadata +413 -0
@@ -0,0 +1,605 @@
1
+ at_exit { $SAFE = 1 }
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ if defined? Gem::QuickLoader
6
+ Gem::QuickLoader.load_full_rubygems_library
7
+ else
8
+ require 'rubygems'
9
+ end
10
+ require 'fileutils'
11
+ require 'minitest/autorun'
12
+ require 'tmpdir'
13
+ require 'uri'
14
+ require 'rubygems/package'
15
+ require 'rubygems/test_utilities'
16
+ require 'pp'
17
+ require 'zlib'
18
+ Gem.load_yaml
19
+
20
+ begin
21
+ gem 'rdoc'
22
+ rescue Gem::LoadError
23
+ end
24
+
25
+ require 'rdoc/rdoc'
26
+
27
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui')
28
+
29
+ module Gem
30
+ def self.searcher=(searcher)
31
+ @searcher = searcher
32
+ end
33
+
34
+ def self.source_index=(si)
35
+ @@source_index = si
36
+ end
37
+
38
+ def self.win_platform=(val)
39
+ @@win_platform = val
40
+ end
41
+
42
+ module DefaultUserInteraction
43
+ @ui = MockGemUi.new
44
+ end
45
+ end
46
+
47
+ class RubyGemTestCase < MiniTest::Unit::TestCase
48
+
49
+ include Gem::DefaultUserInteraction
50
+
51
+ undef_method :default_test if instance_methods.include? 'default_test' or
52
+ instance_methods.include? :default_test
53
+
54
+ def setup
55
+ super
56
+
57
+ @ui = MockGemUi.new
58
+ tmpdir = nil
59
+ Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
60
+ @tempdir = File.join tmpdir, "test_rubygems_#{$$}"
61
+ @tempdir.untaint
62
+ @gemhome = File.join @tempdir, "gemhome"
63
+ @gemcache = File.join(@gemhome, "source_cache")
64
+ @usrcache = File.join(@gemhome, ".gem", "user_cache")
65
+ @latest_usrcache = File.join(@gemhome, ".gem", "latest_user_cache")
66
+ @userhome = File.join @tempdir, 'userhome'
67
+
68
+ Gem.ensure_gem_subdirectories @gemhome
69
+
70
+ @orig_ruby = if ruby = ENV['RUBY'] then
71
+ Gem.class_eval { ruby, @ruby = @ruby, ruby }
72
+ ruby
73
+ end
74
+
75
+ Gem.ensure_gem_subdirectories @gemhome
76
+
77
+ @orig_ENV_HOME = ENV['HOME']
78
+ ENV['HOME'] = @userhome
79
+ Gem.instance_variable_set :@user_home, nil
80
+
81
+ FileUtils.mkdir_p @gemhome
82
+ FileUtils.mkdir_p @userhome
83
+
84
+ ENV['GEMCACHE'] = @usrcache
85
+ Gem.use_paths(@gemhome)
86
+ Gem.loaded_specs.clear
87
+
88
+ Gem.configuration.verbose = true
89
+ Gem.configuration.update_sources = true
90
+
91
+ @gem_repo = "http://gems.example.com/"
92
+ @uri = URI.parse @gem_repo
93
+ Gem.sources.replace [@gem_repo]
94
+
95
+ Gem::SpecFetcher.fetcher = nil
96
+
97
+ @orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
98
+ Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:ruby_install_name]
99
+
100
+ @orig_arch = Gem::ConfigMap[:arch]
101
+
102
+ if win_platform?
103
+ util_set_arch 'i386-mswin32'
104
+ else
105
+ util_set_arch 'i686-darwin8.10.1'
106
+ end
107
+
108
+ @marshal_version = "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
109
+
110
+ @private_key = File.expand_path File.join(File.dirname(__FILE__),
111
+ 'private_key.pem')
112
+ @public_cert = File.expand_path File.join(File.dirname(__FILE__),
113
+ 'public_cert.pem')
114
+
115
+ Gem.post_install_hooks.clear
116
+ Gem.post_uninstall_hooks.clear
117
+ Gem.pre_install_hooks.clear
118
+ Gem.pre_uninstall_hooks.clear
119
+
120
+ Gem.post_install do |installer|
121
+ @post_install_hook_arg = installer
122
+ end
123
+
124
+ Gem.post_uninstall do |uninstaller|
125
+ @post_uninstall_hook_arg = uninstaller
126
+ end
127
+
128
+ Gem.pre_install do |installer|
129
+ @pre_install_hook_arg = installer
130
+ end
131
+
132
+ Gem.pre_uninstall do |uninstaller|
133
+ @pre_uninstall_hook_arg = uninstaller
134
+ end
135
+
136
+ @orig_LOAD_PATH = $LOAD_PATH.dup
137
+ end
138
+
139
+ def teardown
140
+ $LOAD_PATH.replace @orig_LOAD_PATH
141
+
142
+ Gem::ConfigMap[:BASERUBY] = @orig_BASERUBY
143
+ Gem::ConfigMap[:arch] = @orig_arch
144
+
145
+ if defined? Gem::RemoteFetcher then
146
+ Gem::RemoteFetcher.fetcher = nil
147
+ end
148
+
149
+ FileUtils.rm_rf @tempdir
150
+
151
+ ENV.delete 'GEMCACHE'
152
+ ENV.delete 'GEM_HOME'
153
+ ENV.delete 'GEM_PATH'
154
+
155
+ Gem.clear_paths
156
+
157
+ Gem.class_eval { @ruby = ruby } if ruby = @orig_ruby
158
+
159
+ if @orig_ENV_HOME then
160
+ ENV['HOME'] = @orig_ENV_HOME
161
+ else
162
+ ENV.delete 'HOME'
163
+ end
164
+ end
165
+
166
+ def install_gem gem
167
+ require 'rubygems/installer'
168
+
169
+ use_ui MockGemUi.new do
170
+ Dir.chdir @tempdir do
171
+ Gem::Builder.new(gem).build
172
+ end
173
+ end
174
+
175
+ gem = File.join(@tempdir, gem.file_name).untaint
176
+ Gem::Installer.new(gem, :wrappers => true).install
177
+ end
178
+
179
+ def uninstall_gem gem
180
+ require 'rubygems/uninstaller'
181
+
182
+ uninstaller = Gem::Uninstaller.new gem.name, :executables => true,
183
+ :user_install => true
184
+ uninstaller.uninstall
185
+ end
186
+
187
+ def mu_pp(obj)
188
+ s = ''
189
+ s = PP.pp obj, s
190
+ s = s.force_encoding(Encoding.default_external) if defined? Encoding
191
+ s.chomp
192
+ end
193
+
194
+ def prep_cache_files(lc)
195
+ @usr_si ||= Gem::SourceIndex.new
196
+ @usr_sice ||= Gem::SourceInfoCacheEntry.new @usr_si, 0
197
+
198
+ @sys_si ||= Gem::SourceIndex.new
199
+ @sys_sice ||= Gem::SourceInfoCacheEntry.new @sys_si, 0
200
+
201
+ latest_si = Gem::SourceIndex.new
202
+ latest_si.add_specs(*@sys_si.latest_specs)
203
+ latest_sys_sice = Gem::SourceInfoCacheEntry.new latest_si, 0
204
+
205
+ latest_si = Gem::SourceIndex.new
206
+ latest_si.add_specs(*@usr_si.latest_specs)
207
+ latest_usr_sice = Gem::SourceInfoCacheEntry.new latest_si, 0
208
+
209
+ [ [lc.system_cache_file, @sys_sice],
210
+ [lc.latest_system_cache_file, latest_sys_sice],
211
+ [lc.user_cache_file, @usr_sice],
212
+ [lc.latest_user_cache_file, latest_usr_sice],
213
+ ].each do |filename, data|
214
+ FileUtils.mkdir_p File.dirname(filename).untaint
215
+
216
+ open filename.dup.untaint, 'wb' do |f|
217
+ f.write Marshal.dump({ @gem_repo => data })
218
+ end
219
+ end
220
+ end
221
+
222
+ def read_cache(path)
223
+ open path.dup.untaint, 'rb' do |io|
224
+ Marshal.load io.read
225
+ end
226
+ end
227
+
228
+ def read_binary(path)
229
+ Gem.read_binary path
230
+ end
231
+
232
+ def write_file(path)
233
+ path = File.join(@gemhome, path)
234
+ dir = File.dirname path
235
+ FileUtils.mkdir_p dir
236
+
237
+ open path, 'wb' do |io|
238
+ yield io if block_given?
239
+ end
240
+
241
+ path
242
+ end
243
+
244
+ def quick_gem(gemname, version='2')
245
+ require 'rubygems/specification'
246
+
247
+ spec = Gem::Specification.new do |s|
248
+ s.platform = Gem::Platform::RUBY
249
+ s.name = gemname
250
+ s.version = version
251
+ s.author = 'A User'
252
+ s.email = 'example@example.com'
253
+ s.homepage = 'http://example.com'
254
+ s.has_rdoc = true
255
+ s.summary = "this is a summary"
256
+ s.description = "This is a test description"
257
+
258
+ yield(s) if block_given?
259
+ end
260
+
261
+ path = File.join "specifications", spec.spec_name
262
+ written_path = write_file path do |io|
263
+ io.write(spec.to_ruby)
264
+ end
265
+
266
+ spec.loaded_from = written_path
267
+
268
+ Gem.source_index.add_spec spec
269
+
270
+ return spec
271
+ end
272
+
273
+ def util_build_gem(spec)
274
+ dir = File.join(@gemhome, 'gems', spec.full_name)
275
+ FileUtils.mkdir_p dir
276
+
277
+ Dir.chdir dir do
278
+ spec.files.each do |file|
279
+ next if File.exist? file
280
+ FileUtils.mkdir_p File.dirname(file)
281
+ File.open file, 'w' do |fp| fp.puts "# #{file}" end
282
+ end
283
+
284
+ use_ui MockGemUi.new do
285
+ Gem::Builder.new(spec).build
286
+ end
287
+
288
+ FileUtils.mv spec.file_name,
289
+ File.join(@gemhome, 'cache', "#{spec.original_name}.gem")
290
+ end
291
+ end
292
+
293
+ def util_clear_gems
294
+ FileUtils.rm_r File.join(@gemhome, 'gems')
295
+ FileUtils.rm_r File.join(@gemhome, 'specifications')
296
+ Gem.source_index.refresh!
297
+ end
298
+
299
+ def util_gem(name, version, deps = nil, &block)
300
+ if deps then # fuck you eric
301
+ block = proc do |s|
302
+ deps.each do |n, req|
303
+ s.add_dependency n, (req || '>= 0')
304
+ end
305
+ end
306
+ end
307
+
308
+ spec = quick_gem(name, version, &block)
309
+
310
+ util_build_gem spec
311
+
312
+ cache_file = File.join @tempdir, 'gems', "#{spec.original_name}.gem"
313
+ FileUtils.mv File.join(@gemhome, 'cache', "#{spec.original_name}.gem"),
314
+ cache_file
315
+ FileUtils.rm File.join(@gemhome, 'specifications', spec.spec_name)
316
+
317
+ spec.loaded_from = nil
318
+ spec.loaded = false
319
+
320
+ [spec, cache_file]
321
+ end
322
+
323
+ def util_gzip(data)
324
+ out = StringIO.new
325
+
326
+ Zlib::GzipWriter.wrap out do |io|
327
+ io.write data
328
+ end
329
+
330
+ out.string
331
+ end
332
+
333
+ def util_make_gems(prerelease = false)
334
+ @a1 = quick_gem 'a', '1' do |s|
335
+ s.files = %w[lib/code.rb]
336
+ s.require_paths = %w[lib]
337
+ s.date = Gem::Specification::TODAY - 86400
338
+ s.homepage = 'http://a.example.com'
339
+ s.email = %w[example@example.com example2@example.com]
340
+ s.authors = %w[Example Example2]
341
+ s.description = <<-DESC
342
+ This line is really, really long. So long, in fact, that it is more than eighty characters long! The purpose of this line is for testing wrapping behavior because sometimes people don't wrap their text to eighty characters. Without the wrapping, the text might not look good in the RSS feed.
343
+
344
+ Also, a list:
345
+ * An entry that's actually kind of sort
346
+ * an entry that's really long, which will probably get wrapped funny. That's ok, somebody wasn't thinking straight when they made it more than eighty characters.
347
+ DESC
348
+ end
349
+
350
+ init = proc do |s|
351
+ s.files = %w[lib/code.rb]
352
+ s.require_paths = %w[lib]
353
+ end
354
+
355
+ @a2 = quick_gem('a', '2', &init)
356
+ @a3a = quick_gem('a', '3.a', &init)
357
+ @a_evil9 = quick_gem('a_evil', '9', &init)
358
+ @b2 = quick_gem('b', '2', &init)
359
+ @c1_2 = quick_gem('c', '1.2', &init)
360
+ @pl1 = quick_gem 'pl', '1' do |s| # l for legacy
361
+ s.files = %w[lib/code.rb]
362
+ s.require_paths = %w[lib]
363
+ s.platform = Gem::Platform.new 'i386-linux'
364
+ s.instance_variable_set :@original_platform, 'i386-linux'
365
+ end
366
+
367
+ if prerelease
368
+ @a2_pre = quick_gem('a', '2.a', &init)
369
+ write_file File.join(*%W[gems #{@a2_pre.original_name} lib code.rb]) do
370
+ end
371
+ util_build_gem @a2_pre
372
+ end
373
+
374
+ write_file File.join(*%W[gems #{@a1.original_name} lib code.rb]) do end
375
+ write_file File.join(*%W[gems #{@a2.original_name} lib code.rb]) do end
376
+ write_file File.join(*%W[gems #{@a3a.original_name} lib code.rb]) do end
377
+ write_file File.join(*%W[gems #{@b2.original_name} lib code.rb]) do end
378
+ write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb]) do end
379
+ write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb]) do end
380
+
381
+ [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].each do |spec|
382
+ util_build_gem spec
383
+ end
384
+
385
+ FileUtils.rm_r File.join(@gemhome, 'gems', @pl1.original_name)
386
+
387
+ Gem.source_index = nil
388
+ end
389
+
390
+ ##
391
+ # Set the platform to +arch+
392
+
393
+ def util_set_arch(arch)
394
+ Gem::ConfigMap[:arch] = arch
395
+ platform = Gem::Platform.new arch
396
+
397
+ Gem.instance_variable_set :@platforms, nil
398
+ Gem::Platform.instance_variable_set :@local, nil
399
+
400
+ platform
401
+ end
402
+
403
+ def util_setup_fake_fetcher(prerelease = false)
404
+ require 'zlib'
405
+ require 'socket'
406
+ require 'rubygems/remote_fetcher'
407
+
408
+ @fetcher = Gem::FakeFetcher.new
409
+
410
+ util_make_gems(prerelease)
411
+
412
+ @all_gems = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2].sort
413
+ @all_gem_names = @all_gems.map { |gem| gem.full_name }
414
+
415
+ gem_names = [@a1.full_name, @a2.full_name, @a3a.full_name, @b2.full_name]
416
+ @gem_names = gem_names.sort.join("\n")
417
+
418
+ @source_index = Gem::SourceIndex.new
419
+ @source_index.add_spec @a1
420
+ @source_index.add_spec @a2
421
+ @source_index.add_spec @a3a
422
+ @source_index.add_spec @a_evil9
423
+ @source_index.add_spec @c1_2
424
+ @source_index.add_spec @a2_pre if prerelease
425
+
426
+ Gem::RemoteFetcher.fetcher = @fetcher
427
+ end
428
+
429
+ def util_setup_spec_fetcher(*specs)
430
+ specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
431
+ si = Gem::SourceIndex.new specs
432
+
433
+ spec_fetcher = Gem::SpecFetcher.fetcher
434
+
435
+ spec_fetcher.specs[@uri] = []
436
+ si.gems.sort_by { |_, spec| spec }.each do |_, spec|
437
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
438
+ spec_fetcher.specs[@uri] << spec_tuple
439
+ end
440
+
441
+ spec_fetcher.latest_specs[@uri] = []
442
+ si.latest_specs.sort.each do |spec|
443
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
444
+ spec_fetcher.latest_specs[@uri] << spec_tuple
445
+ end
446
+
447
+ spec_fetcher.prerelease_specs[@uri] = []
448
+ si.prerelease_specs.sort.each do |spec|
449
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
450
+ spec_fetcher.prerelease_specs[@uri] << spec_tuple
451
+ end
452
+
453
+ (si.gems.merge si.prerelease_gems).sort_by { |_,spec| spec }.each do |_, spec|
454
+ path = "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{spec.original_name}.gemspec.rz"
455
+ data = Marshal.dump spec
456
+ data_deflate = Zlib::Deflate.deflate data
457
+ @fetcher.data[path] = data_deflate
458
+ end
459
+
460
+ si
461
+ end
462
+
463
+ def util_zip(data)
464
+ Zlib::Deflate.deflate data
465
+ end
466
+
467
+ def self.win_platform?
468
+ Gem.win_platform?
469
+ end
470
+
471
+ def win_platform?
472
+ Gem.win_platform?
473
+ end
474
+
475
+ # Returns whether or not we're on a version of Ruby built with VC++ (or
476
+ # Borland) versus Cygwin, Mingw, etc.
477
+ #
478
+ def self.vc_windows?
479
+ RUBY_PLATFORM.match('mswin')
480
+ end
481
+
482
+ # Returns whether or not we're on a version of Ruby built with VC++ (or
483
+ # Borland) versus Cygwin, Mingw, etc.
484
+ #
485
+ def vc_windows?
486
+ RUBY_PLATFORM.match('mswin')
487
+ end
488
+
489
+ # Returns the make command for the current platform. For versions of Ruby
490
+ # built on MS Windows with VC++ or Borland it will return 'nmake'. On all
491
+ # other platforms, including Cygwin, it will return 'make'.
492
+ #
493
+ def self.make_command
494
+ vc_windows? ? 'nmake' : 'make'
495
+ end
496
+
497
+ # Returns the make command for the current platform. For versions of Ruby
498
+ # built on MS Windows with VC++ or Borland it will return 'nmake'. On all
499
+ # other platforms, including Cygwin, it will return 'make'.
500
+ #
501
+ def make_command
502
+ vc_windows? ? 'nmake' : 'make'
503
+ end
504
+
505
+ # Returns whether or not the nmake command could be found.
506
+ #
507
+ def nmake_found?
508
+ system('nmake /? 1>NUL 2>&1')
509
+ end
510
+
511
+ # NOTE Allow tests to use a random (but controlled) port number instead of
512
+ # a hardcoded one. This helps CI tools when running parallels builds on
513
+ # the same builder slave.
514
+ def self.process_based_port
515
+ @@process_based_port ||= 8000 + $$ % 1000
516
+ end
517
+
518
+ def process_based_port
519
+ self.class.process_based_port
520
+ end
521
+
522
+ def build_rake_in
523
+ gem_ruby = Gem.ruby
524
+ ruby = @@ruby
525
+ Gem.module_eval {@ruby = ruby}
526
+ env_rake = ENV["rake"]
527
+ ENV["rake"] = @@rake
528
+ yield @@rake
529
+ ensure
530
+ Gem.module_eval {@ruby = gem_ruby}
531
+ if env_rake
532
+ ENV["rake"] = env_rake
533
+ else
534
+ ENV.delete("rake")
535
+ end
536
+ end
537
+
538
+ def self.rubybin
539
+ if ruby = ENV["RUBY"]
540
+ return ruby
541
+ end
542
+ ruby = "ruby"
543
+ rubyexe = ruby+".exe"
544
+ 3.times do
545
+ if File.exist? ruby and File.executable? ruby and !File.directory? ruby
546
+ return File.expand_path(ruby)
547
+ end
548
+ if File.exist? rubyexe and File.executable? rubyexe
549
+ return File.expand_path(rubyexe)
550
+ end
551
+ ruby = File.join("..", ruby)
552
+ end
553
+ begin
554
+ require "rbconfig"
555
+ File.join(
556
+ RbConfig::CONFIG["bindir"],
557
+ RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]
558
+ )
559
+ rescue LoadError
560
+ "ruby"
561
+ end
562
+ end
563
+
564
+ @@ruby = rubybin
565
+ env_rake = ENV['rake']
566
+ ruby19_rake = File.expand_path("../../../bin/rake", __FILE__)
567
+ @@rake = if env_rake then
568
+ ENV["rake"]
569
+ elsif File.exist? ruby19_rake then
570
+ @@ruby + " " + ruby19_rake
571
+ else
572
+ 'rake'
573
+ end
574
+
575
+ ##
576
+ # Construct a new Gem::Dependency.
577
+
578
+ def dep name, *requirements
579
+ Gem::Dependency.new name, *requirements
580
+ end
581
+
582
+ ##
583
+ # Construct a new Gem::Requirement.
584
+
585
+ def req *requirements
586
+ return requirements.first if Gem::Requirement === requirements.first
587
+ Gem::Requirement.create requirements
588
+ end
589
+
590
+ ##
591
+ # Construct a new Gem::Specification.
592
+
593
+ def spec name, version, &block
594
+ Gem::Specification.new name, v(version), &block
595
+ end
596
+
597
+ ##
598
+ # Construct a new Gem::Version.
599
+
600
+ def v string
601
+ Gem::Version.create string
602
+ end
603
+
604
+ end
605
+