rubygems-update 0.9.4 → 0.9.5

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

Potentially problematic release.


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

Files changed (225) hide show
  1. data/ChangeLog +587 -0
  2. data/README +0 -1
  3. data/Rakefile +39 -12
  4. data/TODO +0 -5
  5. data/bin/gem +7 -7
  6. data/bin/update_rubygems +1 -1
  7. data/examples/application/an-app.gemspec +1 -1
  8. data/gemspecs/cgikit-1.1.0.gemspec +1 -2
  9. data/gemspecs/jabber4r.gemspec +1 -1
  10. data/gemspecs/linguistics.gemspec +1 -1
  11. data/gemspecs/ook.gemspec +1 -1
  12. data/gemspecs/progressbar.gemspec +1 -1
  13. data/gemspecs/redcloth.gemspec +1 -1
  14. data/gemspecs/rublog.gemspec +1 -1
  15. data/gemspecs/ruby-doom.gemspec +1 -1
  16. data/gemspecs/rubyjdwp.gemspec +1 -1
  17. data/gemspecs/statistics.gemspec +1 -1
  18. data/lib/rubygems.rb +167 -105
  19. data/lib/rubygems/builder.rb +12 -10
  20. data/lib/rubygems/command.rb +177 -60
  21. data/lib/rubygems/command_manager.rb +30 -38
  22. data/lib/rubygems/commands/build_command.rb +42 -46
  23. data/lib/rubygems/commands/cert_command.rb +72 -69
  24. data/lib/rubygems/commands/check_command.rb +63 -63
  25. data/lib/rubygems/commands/cleanup_command.rb +25 -7
  26. data/lib/rubygems/commands/contents_command.rb +70 -62
  27. data/lib/rubygems/commands/dependency_command.rb +131 -86
  28. data/lib/rubygems/commands/environment_command.rb +67 -46
  29. data/lib/rubygems/commands/fetch_command.rb +62 -0
  30. data/lib/rubygems/commands/generate_index_command.rb +57 -0
  31. data/lib/rubygems/commands/help_command.rb +163 -73
  32. data/lib/rubygems/commands/install_command.rb +114 -128
  33. data/lib/rubygems/commands/list_command.rb +10 -8
  34. data/lib/rubygems/commands/lock_command.rb +101 -0
  35. data/lib/rubygems/commands/mirror_command.rb +105 -0
  36. data/lib/rubygems/commands/outdated_command.rb +24 -15
  37. data/lib/rubygems/commands/pristine_command.rb +118 -88
  38. data/lib/rubygems/commands/query_command.rb +109 -77
  39. data/lib/rubygems/commands/rdoc_command.rb +13 -10
  40. data/lib/rubygems/commands/search_command.rb +10 -8
  41. data/lib/rubygems/commands/server_command.rb +48 -0
  42. data/lib/rubygems/commands/sources_command.rb +104 -83
  43. data/lib/rubygems/commands/specification_command.rb +65 -51
  44. data/lib/rubygems/commands/uninstall_command.rb +17 -12
  45. data/lib/rubygems/commands/unpack_command.rb +68 -68
  46. data/lib/rubygems/commands/update_command.rb +72 -25
  47. data/lib/rubygems/commands/which_command.rb +86 -0
  48. data/lib/rubygems/config_file.rb +202 -78
  49. data/lib/rubygems/custom_require.rb +7 -88
  50. data/lib/rubygems/dependency.rb +65 -0
  51. data/lib/rubygems/dependency_installer.rb +232 -0
  52. data/lib/rubygems/dependency_list.rb +133 -105
  53. data/lib/rubygems/digest/md5.rb +4 -1
  54. data/lib/rubygems/digest/sha2.rb +1 -1
  55. data/lib/rubygems/doc_manager.rb +41 -19
  56. data/lib/rubygems/exceptions.rb +63 -0
  57. data/lib/rubygems/ext.rb +18 -0
  58. data/lib/rubygems/ext/builder.rb +56 -0
  59. data/lib/rubygems/ext/configure_builder.rb +24 -0
  60. data/lib/rubygems/ext/ext_conf_builder.rb +23 -0
  61. data/lib/rubygems/ext/rake_builder.rb +27 -0
  62. data/lib/rubygems/format.rb +16 -6
  63. data/lib/rubygems/gem_openssl.rb +43 -6
  64. data/lib/rubygems/gem_path_searcher.rb +84 -0
  65. data/lib/rubygems/gem_runner.rb +20 -5
  66. data/lib/rubygems/indexer.rb +163 -0
  67. data/lib/rubygems/indexer/abstract_index_builder.rb +80 -0
  68. data/lib/rubygems/indexer/marshal_index_builder.rb +17 -0
  69. data/lib/rubygems/indexer/master_index_builder.rb +53 -0
  70. data/lib/rubygems/indexer/quick_index_builder.rb +48 -0
  71. data/lib/rubygems/install_update_options.rb +87 -0
  72. data/lib/rubygems/installer.rb +316 -562
  73. data/lib/rubygems/local_remote_options.rb +106 -0
  74. data/lib/rubygems/old_format.rb +5 -13
  75. data/lib/rubygems/open-uri.rb +2 -0
  76. data/lib/rubygems/package.rb +28 -32
  77. data/lib/rubygems/platform.rb +187 -0
  78. data/lib/rubygems/remote_fetcher.rb +46 -29
  79. data/lib/rubygems/remote_installer.rb +11 -18
  80. data/lib/rubygems/requirement.rb +157 -0
  81. data/lib/rubygems/rubygems_version.rb +1 -1
  82. data/lib/rubygems/security.rb +715 -457
  83. data/lib/rubygems/server.rb +77 -59
  84. data/lib/rubygems/source_index.rb +154 -83
  85. data/lib/rubygems/source_info_cache.rb +73 -30
  86. data/lib/rubygems/source_info_cache_entry.rb +12 -3
  87. data/lib/rubygems/specification.rb +378 -145
  88. data/lib/rubygems/uninstaller.rb +183 -0
  89. data/lib/rubygems/user_interaction.rb +38 -9
  90. data/lib/rubygems/validator.rb +53 -24
  91. data/lib/rubygems/version.rb +126 -289
  92. data/lib/rubygems/version_option.rb +49 -0
  93. data/pkgs/sources/lib/sources.rb +1 -4
  94. data/pkgs/sources/sources.gemspec +3 -3
  95. data/scripts/gemdoc.rb +0 -1
  96. data/setup.rb +166 -1505
  97. data/test/bogussources.rb +0 -1
  98. data/test/data/gem-private_key.pem +27 -0
  99. data/test/data/gem-public_cert.pem +20 -0
  100. data/test/functional.rb +3 -105
  101. data/test/gemutilities.rb +145 -24
  102. data/test/insure_session.rb +0 -1
  103. data/test/{test_datadir.rb → test_config.rb} +7 -13
  104. data/test/test_gem.rb +360 -9
  105. data/test/test_gem_builder.rb +34 -0
  106. data/test/{test_command.rb → test_gem_command.rb} +119 -62
  107. data/test/{test_parse_commands.rb → test_gem_command_manager.rb} +64 -40
  108. data/test/test_gem_commands_build_command.rb +75 -0
  109. data/test/test_gem_commands_cert_command.rb +122 -0
  110. data/test/test_gem_commands_check_command.rb +25 -0
  111. data/test/test_gem_commands_contents_command.rb +92 -0
  112. data/test/test_gem_commands_dependency_command.rb +108 -0
  113. data/test/test_gem_commands_environment_command.rb +117 -0
  114. data/test/test_gem_commands_fetch_command.rb +34 -0
  115. data/test/test_gem_commands_generate_index_command.rb +32 -0
  116. data/test/test_gem_commands_install_command.rb +160 -0
  117. data/test/test_gem_commands_mirror_command.rb +56 -0
  118. data/test/test_gem_commands_pristine_command.rb +100 -0
  119. data/test/test_gem_commands_query_command.rb +82 -0
  120. data/test/test_gem_commands_sources_command.rb +147 -0
  121. data/test/test_gem_commands_specification_command.rb +93 -0
  122. data/test/test_gem_commands_unpack_command.rb +55 -0
  123. data/test/test_gem_config_file.rb +210 -0
  124. data/test/test_gem_dependency.rb +89 -0
  125. data/test/test_gem_dependency_installer.rb +542 -0
  126. data/test/test_gem_dependency_list.rb +212 -0
  127. data/test/test_gem_doc_manager.rb +32 -0
  128. data/test/test_gem_ext_configure_builder.rb +13 -17
  129. data/test/test_gem_ext_ext_conf_builder.rb +9 -9
  130. data/test/test_gem_ext_rake_builder.rb +23 -11
  131. data/test/test_gem_format.rb +69 -0
  132. data/test/test_gem_gem_path_searcher.rb +57 -0
  133. data/test/test_gem_gem_runner.rb +35 -0
  134. data/test/test_gem_indexer.rb +119 -0
  135. data/test/test_gem_install_update_options.rb +40 -0
  136. data/test/test_gem_installer.rb +796 -0
  137. data/test/test_gem_local_remote_options.rb +84 -0
  138. data/test/test_gem_outdated_command.rb +11 -9
  139. data/test/test_gem_platform.rb +240 -0
  140. data/test/{test_remote_fetcher.rb → test_gem_remote_fetcher.rb} +124 -55
  141. data/test/{test_remote_installer.rb → test_gem_remote_installer.rb} +3 -4
  142. data/test/test_gem_requirement.rb +223 -0
  143. data/test/test_gem_server.rb +71 -0
  144. data/test/test_gem_source_index.rb +429 -0
  145. data/test/test_gem_source_info_cache.rb +79 -17
  146. data/test/test_gem_source_info_cache_entry.rb +11 -9
  147. data/test/test_gem_specification.rb +738 -0
  148. data/test/test_gem_stream_ui.rb +117 -0
  149. data/test/test_gem_validator.rb +70 -0
  150. data/test/test_gem_version.rb +191 -0
  151. data/test/test_gem_version_option.rb +77 -0
  152. data/test/{test_require_gem.rb → test_kernel.rb} +19 -12
  153. data/test/test_open_uri.rb +1 -2
  154. data/test/test_package.rb +45 -34
  155. metadata +116 -141
  156. data/Releases +0 -127
  157. data/bin/gem_mirror +0 -73
  158. data/bin/gem_server +0 -6
  159. data/bin/gemlock +0 -127
  160. data/bin/gemri +0 -24
  161. data/bin/gemwhich +0 -89
  162. data/bin/index_gem_repository.rb +0 -302
  163. data/lib/gemconfigure.rb +0 -24
  164. data/lib/rubygems/gem_commands.rb +0 -273
  165. data/pkgs/sources/sources-0.0.1.gem +0 -0
  166. data/post-install.rb +0 -121
  167. data/test/brokenbuildgem.rb +0 -35
  168. data/test/data/PostMessage-0.0.1.gem +0 -0
  169. data/test/data/a-0.0.1.gem +0 -0
  170. data/test/data/a-0.0.2.gem +0 -0
  171. data/test/data/b-0.0.2.gem +0 -0
  172. data/test/data/broken-1.0.0.gem +0 -0
  173. data/test/data/broken_build/broken-build.gemspec +0 -20
  174. data/test/data/broken_build/ext/extconf.rb +0 -3
  175. data/test/data/broken_build/ext/foo.c +0 -1
  176. data/test/data/c-1.2.gem +0 -0
  177. data/test/data/gemhome/cache/a-0.0.1.gem +0 -0
  178. data/test/data/gemhome/cache/a-0.0.2.gem +0 -0
  179. data/test/data/gemhome/cache/b-0.0.2.gem +0 -0
  180. data/test/data/gemhome/cache/c-1.2.gem +0 -0
  181. data/test/data/gemhome/gems/a-0.0.1/lib/code.rb +0 -1
  182. data/test/data/gemhome/gems/a-0.0.2/lib/code.rb +0 -1
  183. data/test/data/gemhome/gems/b-0.0.2/lib/code.rb +0 -1
  184. data/test/data/gemhome/gems/c-1.2/lib/code.rb +0 -1
  185. data/test/data/gemhome/specifications/a-0.0.1.gemspec +0 -8
  186. data/test/data/gemhome/specifications/a-0.0.2.gemspec +0 -8
  187. data/test/data/gemhome/specifications/b-0.0.2.gemspec +0 -8
  188. data/test/data/gemhome/specifications/c-1.2.gemspec +0 -8
  189. data/test/data/legacy/keyedlist-0.4.0.ruby +0 -11
  190. data/test/data/legacy/keyedlist-0.4.0.yaml +0 -16
  191. data/test/data/lib/code.rb +0 -1
  192. data/test/data/one/README.one +0 -1
  193. data/test/data/one/lib/one.rb +0 -9
  194. data/test/data/one/one-0.0.1.gem +0 -0
  195. data/test/data/one/one.gemspec +0 -17
  196. data/test/data/one/one.yaml +0 -40
  197. data/test/data/post_install.gemspec +0 -19
  198. data/test/functional_extension_gems.rb +0 -48
  199. data/test/functional_generate_yaml_index.rb +0 -104
  200. data/test/gemenvironment.rb +0 -59
  201. data/test/io_capture.rb +0 -33
  202. data/test/mock/gems/gems/sources-0.0.1/lib/sources.rb +0 -11
  203. data/test/mock/gems/specifications/sources-0.0.1.gemspec +0 -8
  204. data/test/onegem.rb +0 -35
  205. data/test/test_builder.rb +0 -34
  206. data/test/test_check_command.rb +0 -34
  207. data/test/test_configfile.rb +0 -42
  208. data/test/test_dependency_list.rb +0 -169
  209. data/test/test_file_list.rb +0 -101
  210. data/test/test_format.rb +0 -49
  211. data/test/test_gem_sources_command.rb +0 -135
  212. data/test/test_gemloadpaths.rb +0 -51
  213. data/test/test_gempaths.rb +0 -170
  214. data/test/test_installer.rb +0 -369
  215. data/test/test_loadmanager.rb +0 -48
  216. data/test/test_process_commands.rb +0 -52
  217. data/test/test_source_index.rb +0 -231
  218. data/test/test_specific_extras.rb +0 -46
  219. data/test/test_specification.rb +0 -565
  220. data/test/test_user_interaction.rb +0 -48
  221. data/test/test_validator.rb +0 -59
  222. data/test/test_version_comparison.rb +0 -321
  223. data/test/testgem.rc +0 -7
  224. data/test/user_capture.rb +0 -7
  225. data/test/yaml_data.rb +0 -63
@@ -1,57 +1,53 @@
1
- module Gem
2
- module Commands
3
- class BuildCommand < Command
4
- include CommandAids
1
+ require 'rubygems/command'
2
+ require 'rubygems/builder'
5
3
 
6
- def initialize
7
- super('build', 'Build a gem from a gemspec')
8
- end
4
+ class Gem::Commands::BuildCommand < Gem::Command
9
5
 
10
- def usage
11
- "#{program_name} GEMSPEC_FILE"
12
- end
6
+ def initialize
7
+ super('build', 'Build a gem from a gemspec')
8
+ end
13
9
 
14
- def arguments
15
- "GEMSPEC_FILE name of gemspec file used to build the gem"
16
- end
10
+ def arguments # :nodoc:
11
+ "GEMSPEC_FILE gemspec file name to build a gem for"
12
+ end
17
13
 
18
- def execute
19
- gemspec = get_one_gem_name
20
- if File.exist?(gemspec)
21
- specs = load_gemspecs(gemspec)
22
- specs.each do |spec|
23
- Gem::Builder.new(spec).build
24
- end
25
- return
26
- else
27
- alert_error "Gemspec file not found: #{gemspec}"
28
- end
14
+ def usage # :nodoc:
15
+ "#{program_name} GEMSPEC_FILE"
16
+ end
17
+
18
+ def execute
19
+ gemspec = get_one_gem_name
20
+ if File.exist?(gemspec)
21
+ specs = load_gemspecs(gemspec)
22
+ specs.each do |spec|
23
+ Gem::Builder.new(spec).build
29
24
  end
25
+ else
26
+ alert_error "Gemspec file not found: #{gemspec}"
27
+ end
28
+ end
30
29
 
31
- def load_gemspecs(filename)
32
- if yaml?(filename)
33
- require 'yaml'
34
- result = []
35
- open(filename) do |f|
36
- begin
37
- while spec = Gem::Specification.from_yaml(f)
38
- result << spec
39
- end
40
- rescue EndOfYAMLException => e
41
- # OK
42
- end
30
+ def load_gemspecs(filename)
31
+ if yaml?(filename)
32
+ result = []
33
+ open(filename) do |f|
34
+ begin
35
+ while not f.eof? and spec = Gem::Specification.from_yaml(f)
36
+ result << spec
43
37
  end
44
- else
45
- result = [Gem::Specification.load(filename)]
38
+ rescue Gem::EndOfYAMLException => e
39
+ # OK
46
40
  end
47
- result
48
- end
49
-
50
- def yaml?(filename)
51
- line = open(filename) { |f| line = f.gets }
52
- result = line =~ %r{^--- *!ruby/object:Gem::Specification}
53
- result
54
41
  end
42
+ else
43
+ result = [Gem::Specification.load(filename)]
55
44
  end
45
+ result
46
+ end
47
+
48
+ def yaml?(filename)
49
+ line = open(filename) { |f| line = f.gets }
50
+ result = line =~ %r{^--- *!ruby/object:Gem::Specification}
51
+ result
56
52
  end
57
- end
53
+ end
@@ -1,83 +1,86 @@
1
- module Gem
2
- module Commands
3
-
4
- class CertCommand < Command
5
- include CommandAids
6
-
7
- def initialize
8
- super(
9
- 'cert',
10
- 'Adjust RubyGems certificate settings',
11
- {
12
- })
1
+ require 'rubygems/command'
2
+ require 'rubygems/security'
13
3
 
14
- add_option('-a', '--add CERT', 'Add a trusted certificate.') do |value, options|
15
- cert = OpenSSL::X509::Certificate.new(File.read(value))
16
- Gem::Security.add_trusted_cert(cert)
17
- puts "Added #{cert.subject.to_s}"
18
- end
19
-
20
- add_option('-l', '--list', 'List trusted certificates.') do |value, options|
21
- glob_str = File::join(Gem::Security::OPT[:trust_dir], '*.pem')
22
- Dir::glob(glob_str) do |path|
23
- cert = OpenSSL::X509::Certificate.new(File.read(path))
24
- # this could proably be formatted more gracefully
25
- puts cert.subject.to_s
26
- end
27
- end
4
+ class Gem::Commands::CertCommand < Gem::Command
28
5
 
29
- add_option('-r', '--remove STRING',
30
- 'Remove trusted certificates containing',
31
- 'STRING.') do |value, options|
32
- trust_dir = Gem::Security::OPT[:trust_dir]
33
- glob_str = File::join(trust_dir, '*.pem')
6
+ def initialize
7
+ super 'cert', 'Manage RubyGems certificates and signing settings'
34
8
 
35
- Dir::glob(glob_str) do |path|
36
- cert = OpenSSL::X509::Certificate.new(File.read(path))
37
- if cert.subject.to_s.downcase.index(value)
38
- puts "Removing '#{cert.subject.to_s}'"
39
- File.unlink(path)
40
- end
41
- end
42
- end
9
+ add_option('-a', '--add CERT',
10
+ 'Add a trusted certificate.') do |value, options|
11
+ cert = OpenSSL::X509::Certificate.new(File.read(value))
12
+ Gem::Security.add_trusted_cert(cert)
13
+ say "Added '#{cert.subject.to_s}'"
14
+ end
43
15
 
44
- add_option('-b', '--build EMAIL_ADDR',
45
- 'Build private key and self-signed',
46
- 'certificate for EMAIL_ADDR.') do |value, options|
47
- vals = Gem::Security::build_self_signed_cert(value)
48
- File::chmod(0600, vals[:key_path])
49
- puts "Public Cert: #{vals[:cert_path]}",
50
- "Private Key: #{vals[:key_path]}",
51
- "Don't forget to move the key file to somewhere private..."
16
+ add_option('-l', '--list',
17
+ 'List trusted certificates.') do |value, options|
18
+ glob_str = File::join(Gem::Security::OPT[:trust_dir], '*.pem')
19
+ Dir::glob(glob_str) do |path|
20
+ begin
21
+ cert = OpenSSL::X509::Certificate.new(File.read(path))
22
+ # this could proably be formatted more gracefully
23
+ say cert.subject.to_s
24
+ rescue OpenSSL::X509::CertificateError
25
+ next
52
26
  end
27
+ end
28
+ end
53
29
 
54
- add_option('-C', '--certificate CERT',
55
- 'Certificate for --sign command.') do |value, options|
56
- cert = OpenSSL::X509::Certificate.new(File.read(value))
57
- Gem::Security::OPT[:issuer_cert] = cert
58
- end
30
+ add_option('-r', '--remove STRING',
31
+ 'Remove trusted certificates containing',
32
+ 'STRING.') do |value, options|
33
+ trust_dir = Gem::Security::OPT[:trust_dir]
34
+ glob_str = File::join(trust_dir, '*.pem')
59
35
 
60
- add_option('-K', '--private-key KEY',
61
- 'Private key for --sign command.') do |value, options|
62
- key = OpenSSL::PKey::RSA.new(File.read(value))
63
- Gem::Security::OPT[:issuer_key] = key
36
+ Dir::glob(glob_str) do |path|
37
+ begin
38
+ cert = OpenSSL::X509::Certificate.new(File.read(path))
39
+ if cert.subject.to_s.downcase.index(value)
40
+ say "Removed '#{cert.subject.to_s}'"
41
+ File.unlink(path)
42
+ end
43
+ rescue OpenSSL::X509::CertificateError
44
+ next
64
45
  end
46
+ end
47
+ end
65
48
 
49
+ add_option('-b', '--build EMAIL_ADDR',
50
+ 'Build private key and self-signed',
51
+ 'certificate for EMAIL_ADDR.') do |value, options|
52
+ vals = Gem::Security.build_self_signed_cert(value)
53
+ File.chmod 0600, vals[:key_path]
54
+ say "Public Cert: #{vals[:cert_path]}"
55
+ say "Private Key: #{vals[:key_path]}"
56
+ say "Don't forget to move the key file to somewhere private..."
57
+ end
66
58
 
67
- add_option('-s', '--sign NEWCERT',
68
- 'Sign a certificate with my key and',
69
- 'certificate.') do |value, options|
70
- cert = OpenSSL::X509::Certificate.new(File.read(value))
71
- my_cert = Gem::Security::OPT[:issuer_cert]
72
- my_key = Gem::Security::OPT[:issuer_key]
73
- cert = Gem::Security.sign_cert(cert, my_key, my_cert)
74
- File::open(value, 'wb') { |file| file.write(cert.to_pem) }
75
- end
59
+ add_option('-C', '--certificate CERT',
60
+ 'Certificate for --sign command.') do |value, options|
61
+ cert = OpenSSL::X509::Certificate.new(File.read(value))
62
+ Gem::Security::OPT[:issuer_cert] = cert
63
+ end
76
64
 
77
- end
65
+ add_option('-K', '--private-key KEY',
66
+ 'Private key for --sign command.') do |value, options|
67
+ key = OpenSSL::PKey::RSA.new(File.read(value))
68
+ Gem::Security::OPT[:issuer_key] = key
69
+ end
78
70
 
79
- def execute
80
- end
71
+ add_option('-s', '--sign NEWCERT',
72
+ 'Sign a certificate with my key and',
73
+ 'certificate.') do |value, options|
74
+ cert = OpenSSL::X509::Certificate.new(File.read(value))
75
+ my_cert = Gem::Security::OPT[:issuer_cert]
76
+ my_key = Gem::Security::OPT[:issuer_key]
77
+ cert = Gem::Security.sign_cert(cert, my_key, my_cert)
78
+ File.open(value, 'wb') { |file| file.write(cert.to_pem) }
81
79
  end
82
80
  end
83
- end
81
+
82
+ def execute
83
+ end
84
+
85
+ end
86
+
@@ -1,74 +1,74 @@
1
- module Gem
2
- module Commands
3
- class CheckCommand < Command
4
- include CommandAids
1
+ require 'rubygems/command'
2
+ require 'rubygems/version_option'
3
+ require 'rubygems/validator'
5
4
 
6
- def initialize
7
- super('check', 'Check installed gems',
8
- {:verify => false, :alien => false})
5
+ class Gem::Commands::CheckCommand < Gem::Command
9
6
 
10
- add_option('-v', '--verify FILE',
11
- 'Verify gem file against its internal',
12
- 'checksum') do |value, options|
13
- options[:verify] = value
14
- end
7
+ include Gem::VersionOption
15
8
 
16
- add_option('-a', '--alien', "Report 'unmanaged' or rogue files in the",
17
- "gem repository") do |value, options|
18
- options[:alien] = true
19
- end
9
+ def initialize
10
+ super 'check', 'Check installed gems',
11
+ :verify => false, :alien => false
20
12
 
21
- add_option('-t', '--test', "Run unit tests for gem") do |value, options|
22
- options[:test] = true
23
- end
13
+ add_option( '--verify FILE',
14
+ 'Verify gem file against its internal',
15
+ 'checksum') do |value, options|
16
+ options[:verify] = value
17
+ end
24
18
 
25
- add_option('-V', '--version',
26
- "Specify version for which to run unit tests") do |value, options|
27
- options[:version] = value
28
- end
29
- end
30
-
31
- def execute
32
- if options[:test]
33
- version = options[:version] || "> 0.0.0"
34
- gem_spec = Gem::SourceIndex.from_installed_gems.search(get_one_gem_name, version).first
35
- Gem::Validator.new.unit_test(gem_spec)
36
- end
37
- if options[:alien]
38
- say "Performing the 'alien' operation"
39
- Gem::Validator.new.alien.each do |key, val|
40
- if(val.size > 0)
41
- say "#{key} has #{val.size} problems"
42
- val.each do |error_entry|
43
- say "\t#{error_entry.path}:"
44
- say "\t#{error_entry.problem}"
45
- say
46
- end
47
- else
48
- say "#{key} is error-free"
49
- end
19
+ add_option('-a', '--alien', "Report 'unmanaged' or rogue files in the",
20
+ "gem repository") do |value, options|
21
+ options[:alien] = true
22
+ end
23
+
24
+ add_option('-t', '--test', "Run unit tests for gem") do |value, options|
25
+ options[:test] = true
26
+ end
27
+
28
+ add_version_option 'run tests for'
29
+ end
30
+
31
+ def execute
32
+ if options[:test]
33
+ version = options[:version] || Gem::Requirement.default
34
+ gem_spec = Gem::SourceIndex.from_installed_gems.search(get_one_gem_name, version).first
35
+ Gem::Validator.new.unit_test(gem_spec)
36
+ end
37
+
38
+ if options[:alien]
39
+ say "Performing the 'alien' operation"
40
+ Gem::Validator.new.alien.each do |key, val|
41
+ if(val.size > 0)
42
+ say "#{key} has #{val.size} problems"
43
+ val.each do |error_entry|
44
+ say "\t#{error_entry.path}:"
45
+ say "\t#{error_entry.problem}"
50
46
  say
51
47
  end
48
+ else
49
+ say "#{key} is error-free"
52
50
  end
53
- if options[:verify]
54
- gem_name = options[:verify]
55
- unless gem_name
56
- alert_error "Must specify a .gem file with --verify NAME"
57
- return
58
- end
59
- unless File.exist?(gem_name)
60
- alert_error "Unknown file: #{gem_name}."
61
- return
62
- end
63
- say "Verifying gem: '#{gem_name}'"
64
- begin
65
- Gem::Validator.new.verify_gem_file(gem_name)
66
- rescue Exception => e
67
- alert_error "#{gem_name} is invalid."
68
- end
69
- end
51
+ say
52
+ end
53
+ end
54
+
55
+ if options[:verify]
56
+ gem_name = options[:verify]
57
+ unless gem_name
58
+ alert_error "Must specify a .gem file with --verify NAME"
59
+ return
60
+ end
61
+ unless File.exist?(gem_name)
62
+ alert_error "Unknown file: #{gem_name}."
63
+ return
64
+ end
65
+ say "Verifying gem: '#{gem_name}'"
66
+ begin
67
+ Gem::Validator.new.verify_gem_file(gem_name)
68
+ rescue Exception => e
69
+ alert_error "#{gem_name} is invalid."
70
70
  end
71
-
72
71
  end
73
72
  end
74
- end
73
+
74
+ end
@@ -1,3 +1,7 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/source_index'
3
+ require 'rubygems/dependency_list'
4
+
1
5
  module Gem
2
6
  module Commands
3
7
  class CleanupCommand < Command
@@ -14,26 +18,33 @@ module Gem
14
18
  options[:dryrun] = true
15
19
  end
16
20
  end
17
-
18
- def defaults_str
21
+
22
+ def arguments # :nodoc:
23
+ "GEMNAME name of gem to cleanup"
24
+ end
25
+
26
+ def defaults_str # :nodoc:
19
27
  "--no-dryrun"
20
28
  end
21
29
 
22
- def arguments
23
- "GEMNAME(s) name of gem(s) to cleanup"
30
+ def usage # :nodoc:
31
+ "#{program_name} [GEMNAME ...]"
24
32
  end
25
33
 
26
34
  def execute
27
35
  say "Cleaning up installed gems..."
28
36
  srcindex = Gem::SourceIndex.from_installed_gems
29
37
  primary_gems = {}
38
+
30
39
  srcindex.each do |name, spec|
31
40
  if primary_gems[spec.name].nil? or primary_gems[spec.name].version < spec.version
32
41
  primary_gems[spec.name] = spec
33
42
  end
34
43
  end
44
+
35
45
  gems_to_cleanup = []
36
- if ! options[:args].empty?
46
+
47
+ unless options[:args].empty? then
37
48
  options[:args].each do |gem_name|
38
49
  specs = Gem.cache.search(/^#{gem_name}$/i)
39
50
  specs.each do |spec|
@@ -45,21 +56,27 @@ module Gem
45
56
  gems_to_cleanup << spec
46
57
  end
47
58
  end
59
+
48
60
  gems_to_cleanup = gems_to_cleanup.select { |spec|
49
61
  primary_gems[spec.name].version != spec.version
50
62
  }
51
- uninstall_command = command_manager['uninstall']
63
+
64
+ uninstall_command = Gem::CommandManager.instance['uninstall']
52
65
  deplist = DependencyList.new
53
66
  gems_to_cleanup.uniq.each do |spec| deplist.add(spec) end
67
+
54
68
  deplist.dependency_order.each do |spec|
55
- if options[:dryrun]
69
+ if options[:dryrun] then
56
70
  say "Dry Run Mode: Would uninstall #{spec.full_name}"
57
71
  else
58
72
  say "Attempting uninstall on #{spec.full_name}"
73
+
59
74
  options[:args] = [spec.name]
60
75
  options[:version] = "= #{spec.version}"
61
76
  options[:executables] = true
77
+
62
78
  uninstall_command.merge_options(options)
79
+
63
80
  begin
64
81
  uninstall_command.execute
65
82
  rescue Gem::DependencyRemovalException => ex
@@ -67,6 +84,7 @@ module Gem
67
84
  end
68
85
  end
69
86
  end
87
+
70
88
  say "Clean Up Complete"
71
89
  end
72
90
  end