rubygems-update 1.3.1 → 1.3.2

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 (128) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +24 -0
  3. data/.document +4 -3
  4. data/ChangeLog +382 -1
  5. data/Manifest.txt +214 -0
  6. data/README +1 -49
  7. data/Rakefile +124 -191
  8. data/bin/gem +1 -4
  9. data/cruise_config.rb +22 -0
  10. data/doc/release_notes/rel_1_3_1.rdoc +3 -3
  11. data/doc/release_notes/rel_1_3_2.rdoc +119 -0
  12. data/lib/gauntlet_rubygems.rb +50 -0
  13. data/lib/rubygems.rb +250 -25
  14. data/lib/rubygems/builder.rb +62 -60
  15. data/lib/rubygems/command.rb +421 -319
  16. data/lib/rubygems/command_manager.rb +153 -125
  17. data/lib/rubygems/commands/check_command.rb +12 -7
  18. data/lib/rubygems/commands/cleanup_command.rb +11 -2
  19. data/lib/rubygems/commands/contents_command.rb +42 -18
  20. data/lib/rubygems/commands/generate_index_command.rb +91 -15
  21. data/lib/rubygems/commands/install_command.rb +33 -47
  22. data/lib/rubygems/commands/query_command.rb +36 -20
  23. data/lib/rubygems/commands/rdoc_command.rb +62 -68
  24. data/lib/rubygems/commands/search_command.rb +26 -32
  25. data/lib/rubygems/commands/setup_command.rb +353 -0
  26. data/lib/rubygems/commands/sources_command.rb +5 -0
  27. data/lib/rubygems/commands/specification_command.rb +23 -3
  28. data/lib/rubygems/commands/uninstall_command.rb +71 -61
  29. data/lib/rubygems/commands/unpack_command.rb +14 -12
  30. data/lib/rubygems/commands/update_command.rb +26 -5
  31. data/lib/rubygems/defaults.rb +16 -3
  32. data/lib/rubygems/dependency.rb +38 -7
  33. data/lib/rubygems/dependency_installer.rb +7 -4
  34. data/lib/rubygems/digest/digest_adapter.rb +42 -33
  35. data/lib/rubygems/digest/sha1.rb +6 -1
  36. data/lib/rubygems/digest/sha2.rb +5 -0
  37. data/lib/rubygems/doc_manager.rb +31 -11
  38. data/lib/rubygems/ext/ext_conf_builder.rb +2 -1
  39. data/lib/rubygems/ext/rake_builder.rb +6 -2
  40. data/lib/rubygems/format.rb +63 -63
  41. data/lib/rubygems/gem_openssl.rb +14 -2
  42. data/lib/rubygems/gem_path_searcher.rb +7 -3
  43. data/lib/rubygems/gem_runner.rb +59 -39
  44. data/lib/rubygems/indexer.rb +450 -109
  45. data/lib/rubygems/install_update_options.rb +13 -1
  46. data/lib/rubygems/installer.rb +25 -22
  47. data/lib/rubygems/local_remote_options.rb +5 -3
  48. data/lib/rubygems/old_format.rb +124 -120
  49. data/lib/rubygems/package/tar_header.rb +25 -3
  50. data/lib/rubygems/package/tar_input.rb +5 -5
  51. data/lib/rubygems/package/tar_output.rb +2 -0
  52. data/lib/rubygems/package/tar_reader.rb +19 -0
  53. data/lib/rubygems/package/tar_reader/entry.rb +43 -0
  54. data/lib/rubygems/package/tar_writer.rb +65 -3
  55. data/lib/rubygems/package_task.rb +117 -0
  56. data/lib/rubygems/platform.rb +12 -8
  57. data/lib/rubygems/remote_fetcher.rb +43 -24
  58. data/lib/rubygems/require_paths_builder.rb +14 -12
  59. data/lib/rubygems/requirement.rb +15 -6
  60. data/lib/rubygems/rubygems_version.rb +14 -1
  61. data/lib/rubygems/source_index.rb +38 -16
  62. data/lib/rubygems/source_info_cache_entry.rb +2 -2
  63. data/lib/rubygems/spec_fetcher.rb +43 -20
  64. data/lib/rubygems/specification.rb +1122 -947
  65. data/lib/rubygems/text.rb +30 -0
  66. data/lib/rubygems/timer.rb +14 -11
  67. data/lib/rubygems/uninstaller.rb +25 -5
  68. data/lib/rubygems/user_interaction.rb +294 -264
  69. data/lib/rubygems/validator.rb +70 -36
  70. data/lib/rubygems/version.rb +97 -33
  71. data/lib/rubygems/version_option.rb +1 -0
  72. data/setup.rb +11 -306
  73. data/test/foo/discover.rb +0 -0
  74. data/test/gem_installer_test_case.rb +22 -11
  75. data/test/gem_package_tar_test_case.rb +0 -14
  76. data/test/gemutilities.rb +89 -8
  77. data/test/mockgemui.rb +2 -1
  78. data/test/rubygems_plugin.rb +16 -0
  79. data/test/test_gem.rb +107 -36
  80. data/test/test_gem_command.rb +3 -13
  81. data/test/test_gem_command_manager.rb +1 -14
  82. data/test/test_gem_commands_cert_command.rb +1 -1
  83. data/test/test_gem_commands_contents_command.rb +63 -0
  84. data/test/test_gem_commands_environment_command.rb +1 -1
  85. data/test/test_gem_commands_generate_index_command.rb +104 -1
  86. data/test/test_gem_commands_install_command.rb +95 -0
  87. data/test/test_gem_commands_pristine_command.rb +3 -3
  88. data/test/test_gem_commands_query_command.rb +46 -0
  89. data/test/test_gem_commands_sources_command.rb +9 -5
  90. data/test/test_gem_commands_specification_command.rb +31 -0
  91. data/test/test_gem_commands_uninstall_command.rb +3 -2
  92. data/test/test_gem_commands_unpack_command.rb +3 -2
  93. data/test/test_gem_commands_update_command.rb +12 -7
  94. data/test/test_gem_dependency.rb +62 -11
  95. data/test/test_gem_dependency_installer.rb +18 -5
  96. data/test/test_gem_dependency_list.rb +6 -6
  97. data/test/test_gem_doc_manager.rb +7 -1
  98. data/test/test_gem_ext_configure_builder.rb +8 -10
  99. data/test/test_gem_ext_ext_conf_builder.rb +14 -8
  100. data/test/test_gem_gem_path_searcher.rb +1 -1
  101. data/test/test_gem_gem_runner.rb +11 -0
  102. data/test/test_gem_indexer.rb +398 -21
  103. data/test/test_gem_install_update_options.rb +20 -6
  104. data/test/test_gem_installer.rb +22 -14
  105. data/test/test_gem_local_remote_options.rb +2 -1
  106. data/test/test_gem_package_tar_header.rb +3 -3
  107. data/test/test_gem_package_tar_input.rb +3 -3
  108. data/test/test_gem_package_tar_output.rb +2 -2
  109. data/test/test_gem_package_task.rb +70 -0
  110. data/test/test_gem_platform.rb +12 -6
  111. data/test/test_gem_remote_fetcher.rb +23 -1
  112. data/test/test_gem_source_index.rb +32 -21
  113. data/test/test_gem_spec_fetcher.rb +77 -5
  114. data/test/test_gem_specification.rb +274 -1
  115. data/test/test_gem_uninstaller.rb +34 -4
  116. data/test/test_gem_version.rb +94 -4
  117. data/test/test_gem_version_option.rb +13 -0
  118. data/test/test_kernel.rb +4 -4
  119. data/util/CL2notes +56 -0
  120. data/util/gem_prelude.rb.template +251 -0
  121. metadata +30 -20
  122. metadata.gz.sig +3 -4
  123. data/TODO +0 -1
  124. data/scripts/buildtests.rb +0 -31
  125. data/scripts/gemdoc.rb +0 -67
  126. data/scripts/runtest.rb +0 -40
  127. data/scripts/specdoc.rb +0 -171
  128. data/scripts/upload_gemdoc.rb +0 -140
@@ -13,6 +13,8 @@ class TestGemUninstaller < GemInstallerTestCase
13
13
  build_rake_in do
14
14
  use_ui ui do
15
15
  @installer.install
16
+ @user_installer.install
17
+ Gem::Uninstaller.new(@user_spec.name, :executables => false).uninstall
16
18
  end
17
19
  end
18
20
  end
@@ -50,7 +52,7 @@ class TestGemUninstaller < GemInstallerTestCase
50
52
  def test_path_ok_eh
51
53
  uninstaller = Gem::Uninstaller.new nil
52
54
 
53
- assert_equal true, uninstaller.path_ok?(@spec)
55
+ assert_equal true, uninstaller.path_ok?(@gemhome, @spec)
54
56
  end
55
57
 
56
58
  def test_path_ok_eh_legacy
@@ -59,7 +61,13 @@ class TestGemUninstaller < GemInstallerTestCase
59
61
  @spec.loaded_from.gsub! @spec.full_name, '\&-legacy'
60
62
  @spec.platform = 'legacy'
61
63
 
62
- assert_equal true, uninstaller.path_ok?(@spec)
64
+ assert_equal true, uninstaller.path_ok?(@gemhome, @spec)
65
+ end
66
+
67
+ def test_path_ok_eh_user
68
+ uninstaller = Gem::Uninstaller.new nil
69
+
70
+ assert_equal true, uninstaller.path_ok?(Gem.user_dir, @user_spec)
63
71
  end
64
72
 
65
73
  def test_uninstall
@@ -72,12 +80,34 @@ class TestGemUninstaller < GemInstallerTestCase
72
80
  end
73
81
 
74
82
  Gem.post_uninstall do
75
- assert !File.exist?(gem_dir), 'gem_dir should not exist'
83
+ refute File.exist?(gem_dir), 'gem_dir should not exist'
84
+ end
85
+
86
+ uninstaller.uninstall
87
+
88
+ refute File.exist?(gem_dir)
89
+
90
+ assert_same uninstaller, @pre_uninstall_hook_arg
91
+ assert_same uninstaller, @post_uninstall_hook_arg
92
+ end
93
+
94
+ def test_uninstall_user
95
+ uninstaller = Gem::Uninstaller.new @user_spec.name, :executables => true,
96
+ :user_install => true
97
+
98
+ gem_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name
99
+
100
+ Gem.pre_uninstall do
101
+ assert File.exist?(gem_dir), 'gem_dir should exist'
102
+ end
103
+
104
+ Gem.post_uninstall do
105
+ refute File.exist?(gem_dir), 'gem_dir should not exist'
76
106
  end
77
107
 
78
108
  uninstaller.uninstall
79
109
 
80
- assert !File.exist?(gem_dir)
110
+ refute File.exist?(gem_dir)
81
111
 
82
112
  assert_same uninstaller, @pre_uninstall_hook_arg
83
113
  assert_same uninstaller, @post_uninstall_hook_arg
@@ -12,9 +12,13 @@ class TestGemVersion < RubyGemTestCase
12
12
  def setup
13
13
  super
14
14
 
15
+ version = Object.new
16
+ def version.to_s() '1.4.0' end
17
+
15
18
  @v1_0 = Gem::Version.new '1.0'
16
19
  @v1_2 = Gem::Version.new '1.2'
17
20
  @v1_3 = Gem::Version.new '1.3'
21
+ @v1_4_0 = Gem::Version.new version
18
22
  end
19
23
 
20
24
  def test_class_create
@@ -64,6 +68,11 @@ class TestGemVersion < RubyGemTestCase
64
68
  assert_equal "5.3", v.bump.to_s
65
69
  end
66
70
 
71
+ def test_bump_alpha
72
+ v = Gem::Version.new("5.2.4.a")
73
+ assert_equal "5.3", v.bump.to_s
74
+ end
75
+
67
76
  def test_bump_one_level
68
77
  v = Gem::Version.new("5")
69
78
  assert_equal "6", v.bump.to_s
@@ -83,6 +92,20 @@ class TestGemVersion < RubyGemTestCase
83
92
  assert_equal false, @v1_3.eql?(@v1_2)
84
93
  end
85
94
 
95
+ def test_eql_eh4
96
+ v1_4 = Gem::Version.new '1.4'
97
+ v1_4_0 = Gem::Version.new "1.4.0"
98
+
99
+ assert_equal true, v1_4_0.eql?(@v1_4_0)
100
+ assert_equal true, @v1_4_0.eql?(v1_4_0)
101
+
102
+ assert_equal false, v1_4.eql?(@v1_4_0)
103
+ assert_equal false, @v1_4_0.eql?(v1_4)
104
+
105
+ assert_equal false, @v1_4_0.eql?(@v1_3)
106
+ assert_equal false, @v1_3.eql?(@v1_4_0)
107
+ end
108
+
86
109
  def test_equals2
87
110
  v = Gem::Version.new("1.2")
88
111
 
@@ -96,12 +119,17 @@ class TestGemVersion < RubyGemTestCase
96
119
  def test_hash
97
120
  v1_2 = Gem::Version.new "1.2"
98
121
  v1_2_0 = Gem::Version.new "1.2.0"
122
+ v1_4_0 = Gem::Version.new "1.4.0"
99
123
 
100
124
  assert_equal v1_2.hash, @v1_2.hash
101
125
 
102
126
  refute_equal v1_2_0.hash, @v1_2.hash
103
127
 
128
+ assert_equal v1_4_0.hash, @v1_4_0.hash
129
+
104
130
  refute_equal @v1_2.hash, @v1_3.hash
131
+
132
+ refute_equal @v1_2.hash, @v1_4_0.hash
105
133
  end
106
134
 
107
135
  def test_illformed_requirements
@@ -113,9 +141,12 @@ class TestGemVersion < RubyGemTestCase
113
141
  end
114
142
 
115
143
  def test_normalize
116
- assert_equal [1], Gem::Version.new("1").to_ints
117
- assert_equal [1], Gem::Version.new("1.0").to_ints
118
- assert_equal [1, 1], Gem::Version.new("1.1").to_ints
144
+ assert_equal [0], Gem::Version.new("").normalize.map { |part| part.value }
145
+ assert_equal [0], Gem::Version.new("0").normalize.map { |part| part.value }
146
+ assert_equal [1], Gem::Version.new("1").normalize.map { |part| part.value }
147
+ assert_equal [1], Gem::Version.new("1.0").normalize.map { |part| part.value }
148
+ assert_equal [1, 1], Gem::Version.new("1.1").normalize.map { |part| part.value }
149
+ assert_equal [1, 1, "a"], Gem::Version.new("1.1.a").normalize.map { |part| part.value }
119
150
  end
120
151
 
121
152
  def test_ok
@@ -139,9 +170,34 @@ class TestGemVersion < RubyGemTestCase
139
170
  assert_adequate( "", "< 0.1")
140
171
  assert_adequate( " ", "< 0.1 ")
141
172
  assert_adequate( "", " < 0.1")
173
+ assert_adequate( " ", "> 0.a ")
174
+ assert_adequate( "", " > 0.a")
142
175
  assert_adequate( "0", "=")
143
176
  assert_adequate( "0", ">=")
144
177
  assert_adequate( "0", "<=")
178
+ assert_adequate( "3.1", "< 3.2.rc1")
179
+ assert_adequate( "3.2.0", "> 3.2.0.rc1")
180
+ assert_adequate( "3.2.0.rc2", "> 3.2.0.rc1")
181
+ assert_adequate( "3.0.rc2", "< 3.0")
182
+ assert_adequate( "3.0.rc2", "< 3.0.0")
183
+ assert_adequate( "3.0.rc2", "< 3.0.1")
184
+ end
185
+
186
+ def test_parse_parts_from_version_string
187
+ assert_equal [], part_values(Gem::Version.new("").parse_parts_from_version_string)
188
+ assert_equal [1], part_values(Gem::Version.new("1").parse_parts_from_version_string)
189
+ assert_equal [1, 0], part_values(Gem::Version.new("1.0").parse_parts_from_version_string)
190
+ assert_equal [1, 0, "a"], part_values(Gem::Version.new("1.0.a").parse_parts_from_version_string)
191
+ end
192
+
193
+ def test_prerelease
194
+ assert Gem::Version.new('1.2.0.a').prerelease?
195
+ assert Gem::Version.new('2.9.b').prerelease?
196
+ assert Gem::Version.new('22.1.50.0.d').prerelease?
197
+
198
+ refute Gem::Version.new('1.2.0').prerelease?
199
+ refute Gem::Version.new('2.9').prerelease?
200
+ refute Gem::Version.new('22.1.50.0').prerelease?
145
201
  end
146
202
 
147
203
  def test_satisfied_by_eh_boxed
@@ -169,7 +225,12 @@ class TestGemVersion < RubyGemTestCase
169
225
  end
170
226
 
171
227
  def test_spaceship
228
+ assert_equal 0, Gem::Version.new('1.0') <=> Gem::Version.new('1.0.0')
229
+ assert_equal 1, Gem::Version.new('1.0') <=> Gem::Version.new('1.0.a')
172
230
  assert_equal 1, Gem::Version.new('1.8.2') <=> Gem::Version.new('0.0.0')
231
+ assert_equal 1, Gem::Version.new('1.8.2') <=> Gem::Version.new('1.8.2.a')
232
+ assert_equal 1, Gem::Version.new('1.8.2.b') <=> Gem::Version.new('1.8.2.a')
233
+ assert_equal 0, Gem::Version.new('') <=> Gem::Version.new('0')
173
234
  end
174
235
 
175
236
  def test_boxed
@@ -201,7 +262,7 @@ class TestGemVersion < RubyGemTestCase
201
262
  def assert_inadequate(version, requirement)
202
263
  ver = Gem::Version.new(version)
203
264
  req = Gem::Version::Requirement.new(requirement)
204
- assert ! req.satisfied_by?(ver),
265
+ refute req.satisfied_by?(ver),
205
266
  "Version #{version} should not be adequate for Requirement #{requirement}"
206
267
  end
207
268
 
@@ -210,5 +271,34 @@ class TestGemVersion < RubyGemTestCase
210
271
  assert_equal @v1_0.version, actual.version
211
272
  end
212
273
 
274
+ def part_values(*parts)
275
+ parts.flatten.map { |part| part.value }
276
+ end
277
+ end
278
+
279
+ class TestGemVersionPart < RubyGemTestCase
280
+ def test_initialize
281
+ assert_equal 1, Gem::Version::Part.new(1).value
282
+ assert_equal 1, Gem::Version::Part.new("1").value
283
+ assert_equal "a", Gem::Version::Part.new("a").value
284
+ end
285
+
286
+ def test_spaceship
287
+ assert_equal(-1, Gem::Version::Part.new(1) <=> Gem::Version::Part.new(2))
288
+ assert_equal( 0, Gem::Version::Part.new(2) <=> Gem::Version::Part.new(2))
289
+ assert_equal( 1, Gem::Version::Part.new(2) <=> Gem::Version::Part.new(1))
290
+
291
+ assert_equal(-1, Gem::Version::Part.new("a") <=> Gem::Version::Part.new("b"))
292
+ assert_equal( 0, Gem::Version::Part.new("b") <=> Gem::Version::Part.new("b"))
293
+ assert_equal( 1, Gem::Version::Part.new("b") <=> Gem::Version::Part.new("a"))
294
+
295
+ assert_equal(-1, Gem::Version::Part.new("a") <=> Gem::Version::Part.new(1))
296
+ assert_equal( 1, Gem::Version::Part.new(1) <=> Gem::Version::Part.new("a"))
297
+ end
298
+
299
+ def test_succ
300
+ assert_equal 2, Gem::Version::Part.new(1).succ.value
301
+ assert_equal "b", Gem::Version::Part.new("a").succ.value
302
+ end
213
303
  end
214
304
 
@@ -23,6 +23,19 @@ class TestGemVersionOption < RubyGemTestCase
23
23
  assert @cmd.handles?(%w[--version >1])
24
24
  end
25
25
 
26
+ def test_enables_prerelease
27
+ @cmd.add_version_option
28
+
29
+ @cmd.handle_options %w[mygem -v 0.2.0.a]
30
+ assert @cmd.options[:prerelease]
31
+
32
+ @cmd.handle_options %w[mygem -v 0.2.0]
33
+ refute @cmd.options[:prerelease]
34
+
35
+ @cmd.handle_options %w[mygem]
36
+ refute @cmd.options[:prerelease]
37
+ end
38
+
26
39
  def test_platform_option
27
40
  @cmd.add_platform_option
28
41
 
@@ -31,14 +31,14 @@ class TestKernel < RubyGemTestCase
31
31
 
32
32
  def test_gem_redundent
33
33
  assert gem('a', '= 1'), "Should load"
34
- assert ! gem('a', '= 1'), "Should not load"
34
+ refute gem('a', '= 1'), "Should not load"
35
35
  assert_equal 1, $:.select { |p| %r{a-1/lib} =~ p }.size
36
36
  assert_equal 1, $:.select { |p| %r{a-1/bin} =~ p }.size
37
37
  end
38
38
 
39
39
  def test_gem_overlapping
40
40
  assert gem('a', '= 1'), "Should load"
41
- assert ! gem('a', '>= 1'), "Should not load"
41
+ refute gem('a', '>= 1'), "Should not load"
42
42
  assert_equal 1, $:.select { |p| %r{a-1/lib} =~ p }.size
43
43
  assert_equal 1, $:.select { |p| %r{a-1/bin} =~ p }.size
44
44
  end
@@ -55,8 +55,8 @@ class TestKernel < RubyGemTestCase
55
55
 
56
56
  assert $:.any? { |p| %r{a-1/lib} =~ p }
57
57
  assert $:.any? { |p| %r{a-1/bin} =~ p }
58
- assert ! $:.any? { |p| %r{a-2/lib} =~ p }
59
- assert ! $:.any? { |p| %r{a-2/bin} =~ p }
58
+ refute $:.any? { |p| %r{a-2/lib} =~ p }
59
+ refute $:.any? { |p| %r{a-2/bin} =~ p }
60
60
  end
61
61
 
62
62
  end
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift 'lib'
4
+
5
+ require 'rubygems'
6
+
7
+ def format_text(text, wrap, indent=0)
8
+ result = []
9
+ work = text.dup
10
+
11
+ while work.length > wrap
12
+ if work =~ /^(.{0,#{wrap}})[ \n]/o then
13
+ result << $1
14
+ work.slice!(0, $&.length)
15
+ else
16
+ result << work.slice!(0, wrap)
17
+ end
18
+ end
19
+
20
+ result << work if work.length.nonzero?
21
+ result.join("\n").gsub(/^/, " " * indent)
22
+ end
23
+
24
+ version = ARGV.shift || Gem::RubyGemsVersion
25
+
26
+ entries = Hash.new { |h,file| h[file] = [] }
27
+ entry = []
28
+ file = nil
29
+
30
+ IO.foreach 'ChangeLog' do |line|
31
+ case line
32
+ when /^\s*$/,
33
+ /^#/,
34
+ /^\d{4}-\d{2}-\d{2}/ then
35
+ next
36
+ when /^\s+\*\s+([^:]+?):\s+#{version}/ then
37
+ entries[file] << entry.join(' ') unless entry.empty?
38
+ break
39
+ when /^\s+\*\s+([^:]+?):\s+/ then
40
+ entries[file] << entry.join(' ') unless entry.empty?
41
+ file = $1
42
+ entry = [$'.strip]
43
+ when /^\s+/ then
44
+ entry << $'.strip
45
+ end
46
+ end
47
+
48
+ entries.sort_by { |file, | file }.each do |file, file_entries|
49
+ puts "* #{file}"
50
+ file_entries.each do |file_entry|
51
+ file_entry = format_text file_entry, 74, 4
52
+ file_entry.sub! ' ', ' * '
53
+ puts file_entry
54
+ end
55
+ end
56
+
@@ -0,0 +1,251 @@
1
+ # depends on: array.rb dir.rb env.rb file.rb hash.rb module.rb regexp.rb
2
+ # vim: filetype=ruby
3
+ # WARN
4
+
5
+ if defined?(Gem) then
6
+
7
+ module Kernel
8
+
9
+ def gem(gem_name, *version_requirements)
10
+ Gem.push_gem_version_on_load_path(gem_name, *version_requirements)
11
+ end
12
+
13
+ end
14
+
15
+ module Gem
16
+
17
+ ConfigMap = {
18
+ :BASERUBY => RbConfig::CONFIG["BASERUBY"],
19
+ :sitedir => RbConfig::CONFIG["sitedir"],
20
+ :ruby_version => RbConfig::CONFIG["ruby_version"],
21
+ :libdir => RbConfig::CONFIG["libdir"],
22
+ :sitelibdir => RbConfig::CONFIG["sitelibdir"],
23
+ :arch => RbConfig::CONFIG["arch"],
24
+ :bindir => RbConfig::CONFIG["bindir"],
25
+ :EXEEXT => RbConfig::CONFIG["EXEEXT"],
26
+ :RUBY_SO_NAME => RbConfig::CONFIG["RUBY_SO_NAME"],
27
+ :ruby_install_name => RbConfig::CONFIG["ruby_install_name"]
28
+ }
29
+
30
+ def self.dir
31
+ @gem_home ||= nil
32
+ set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
33
+ @gem_home
34
+ end
35
+
36
+ def self.path
37
+ @gem_path ||= nil
38
+ unless @gem_path
39
+ paths = [ENV['GEM_PATH']]
40
+ paths << APPLE_GEM_HOME if defined? APPLE_GEM_HOME
41
+ set_paths(paths.compact.join(File::PATH_SEPARATOR))
42
+ end
43
+ @gem_path
44
+ end
45
+
46
+ def self.post_install(&hook)
47
+ @post_install_hooks << hook
48
+ end
49
+
50
+ def self.post_uninstall(&hook)
51
+ @post_uninstall_hooks << hook
52
+ end
53
+
54
+ def self.pre_install(&hook)
55
+ @pre_install_hooks << hook
56
+ end
57
+
58
+ def self.pre_uninstall(&hook)
59
+ @pre_uninstall_hooks << hook
60
+ end
61
+
62
+ def self.set_home(home)
63
+ @gem_home = home
64
+ ensure_gem_subdirectories(@gem_home)
65
+ end
66
+
67
+ def self.set_paths(gpaths)
68
+ if gpaths
69
+ @gem_path = gpaths.split(File::PATH_SEPARATOR)
70
+ @gem_path << Gem.dir
71
+ else
72
+ @gem_path = [Gem.dir]
73
+ end
74
+ @gem_path.uniq!
75
+ @gem_path.each do |gp| ensure_gem_subdirectories(gp) end
76
+ end
77
+
78
+ def self.ensure_gem_subdirectories(path)
79
+ end
80
+
81
+ # INCLUDE rubygems/defaults
82
+
83
+ # Methods before this line will be removed when QuickLoader is replaced
84
+ # with the real RubyGems
85
+
86
+ GEM_PRELUDE_METHODS = Gem.methods(false)
87
+
88
+ begin
89
+ verbose, debug = $VERBOSE, $DEBUG
90
+ $VERBOSE = $DEBUG = nil
91
+
92
+ begin
93
+ require 'rubygems/defaults/operating_system'
94
+ rescue LoadError
95
+ end
96
+
97
+ if defined?(RUBY_ENGINE) then
98
+ begin
99
+ require "rubygems/defaults/#{RUBY_ENGINE}"
100
+ rescue LoadError
101
+ end
102
+ end
103
+ ensure
104
+ $VERBOSE, $DEBUG = verbose, debug
105
+ end
106
+
107
+ module QuickLoader
108
+
109
+ def self.load_full_rubygems_library
110
+ class << Gem
111
+ Gem::GEM_PRELUDE_METHODS.each do |method_name|
112
+ undef_method method_name
113
+ end
114
+ end
115
+
116
+ Kernel.module_eval do
117
+ undef_method :gem if method_defined? :gem
118
+ end
119
+
120
+ $".delete File.join(Gem::ConfigMap[:libdir],
121
+ Gem::ConfigMap[:ruby_install_name],
122
+ Gem::ConfigMap[:ruby_version], 'rubygems.rb')
123
+
124
+ require 'rubygems'
125
+ end
126
+
127
+ GemPaths = {}
128
+ GemVersions = {}
129
+
130
+ def push_gem_version_on_load_path(gem_name, *version_requirements)
131
+ if version_requirements.empty?
132
+ unless GemPaths.has_key?(gem_name)
133
+ raise LoadError.new("Could not find RubyGem #{gem_name} (>= 0)\n")
134
+ end
135
+
136
+ # highest version gems already active
137
+ return false
138
+ else
139
+ if version_requirements.length > 1
140
+ QuickLoader.load_full_rubygems_library
141
+ return gem(gem_name, *version_requirements)
142
+ end
143
+
144
+ requirement, version = version_requirements[0].split
145
+ requirement.strip!
146
+
147
+ if requirement == ">" || requirement == ">="
148
+ if (GemVersions[gem_name] <=> Gem.calculate_integers_for_gem_version(version)) >= 0
149
+ return false
150
+ end
151
+ elsif requirement == "~>"
152
+ loaded_version = GemVersions[gem_name]
153
+ required_version = Gem.calculate_integers_for_gem_version(version)
154
+ if loaded_version && (loaded_version[0] == required_version[0])
155
+ return false
156
+ end
157
+ end
158
+
159
+ QuickLoader.load_full_rubygems_library
160
+ gem(gem_name, *version_requirements)
161
+ end
162
+ end
163
+
164
+ def calculate_integers_for_gem_version(gem_version)
165
+ numbers = gem_version.split(".").collect {|n| n.to_i}
166
+ numbers.pop while numbers.last == 0
167
+ numbers << 0 if numbers.empty?
168
+ numbers
169
+ end
170
+
171
+ def push_all_highest_version_gems_on_load_path
172
+ Gem.path.each do |path|
173
+ gems_directory = File.join(path, "gems")
174
+ if File.exist?(gems_directory)
175
+ Dir.entries(gems_directory).each do |gem_directory_name|
176
+ next if gem_directory_name == "." || gem_directory_name == ".."
177
+ dash = gem_directory_name.rindex("-")
178
+ next if dash.nil?
179
+ gem_name = gem_directory_name[0...dash]
180
+ current_version = GemVersions[gem_name]
181
+ new_version = calculate_integers_for_gem_version(gem_directory_name[dash+1..-1])
182
+ if current_version
183
+ if (current_version <=> new_version) == -1
184
+ GemVersions[gem_name] = new_version
185
+ GemPaths[gem_name] = File.join(gems_directory, gem_directory_name)
186
+ end
187
+ else
188
+ GemVersions[gem_name] = new_version
189
+ GemPaths[gem_name] = File.join(gems_directory, gem_directory_name)
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ require_paths = []
196
+
197
+ GemPaths.each_value do |path|
198
+ if File.exist?(file = File.join(path, ".require_paths")) then
199
+ paths = File.read(file).split.map do |require_path|
200
+ File.join path, require_path
201
+ end
202
+
203
+ require_paths.concat paths
204
+ else
205
+ require_paths << file if File.exist?(file = File.join(path, "bin"))
206
+ require_paths << file if File.exist?(file = File.join(path, "lib"))
207
+ end
208
+ end
209
+
210
+ # "tag" the first require_path inserted into the $LOAD_PATH to enable
211
+ # indexing correctly with rubygems proper when it inserts an explicitly
212
+ # gem version
213
+ unless require_paths.empty?
214
+ require_paths.first.instance_variable_set(:@gem_prelude_index, true)
215
+ end
216
+ # gem directories must come after -I and ENV['RUBYLIB']
217
+ $:[$:.index(ConfigMap[:sitelibdir]),0] = require_paths
218
+ end
219
+
220
+ def const_missing(constant)
221
+ QuickLoader.load_full_rubygems_library
222
+ if Gem.const_defined?(constant)
223
+ Gem.const_get(constant)
224
+ else
225
+ super
226
+ end
227
+ end
228
+
229
+ def method_missing(method, *args, &block)
230
+ QuickLoader.load_full_rubygems_library
231
+ super unless Gem.respond_to?(method)
232
+ Gem.send(method, *args, &block)
233
+ end
234
+ end
235
+
236
+ extend QuickLoader
237
+
238
+ end
239
+
240
+ begin
241
+ Gem.push_all_highest_version_gems_on_load_path
242
+ $" << File.join(Gem::ConfigMap[:libdir], Gem::ConfigMap[:ruby_install_name],
243
+ Gem::ConfigMap[:ruby_version], "rubygems.rb")
244
+ rescue Exception => e
245
+ puts "Error loading gem paths on load path in gem_prelude"
246
+ puts e
247
+ puts e.backtrace.join("\n")
248
+ end
249
+
250
+ end
251
+