rubygems-update 1.0.1 → 1.1.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 (172) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +248 -0
  3. data/README +2 -0
  4. data/Rakefile +47 -23
  5. data/bin/gem +9 -4
  6. data/bin/update_rubygems +15 -1
  7. data/examples/application/bin/myapp +0 -0
  8. data/lib/rubygems.rb +506 -373
  9. data/lib/rubygems/builder.rb +14 -7
  10. data/lib/rubygems/command.rb +9 -9
  11. data/lib/rubygems/command_manager.rb +1 -0
  12. data/lib/rubygems/commands/cleanup_command.rb +67 -69
  13. data/lib/rubygems/commands/environment_command.rb +16 -10
  14. data/lib/rubygems/commands/fetch_command.rb +7 -9
  15. data/lib/rubygems/commands/install_command.rb +9 -3
  16. data/lib/rubygems/commands/list_command.rb +2 -4
  17. data/lib/rubygems/commands/mirror_command.rb +1 -1
  18. data/lib/rubygems/commands/query_command.rb +52 -5
  19. data/lib/rubygems/commands/sources_command.rb +19 -10
  20. data/lib/rubygems/commands/specification_command.rb +10 -6
  21. data/lib/rubygems/commands/uninstall_command.rb +23 -6
  22. data/lib/rubygems/commands/unpack_command.rb +15 -3
  23. data/lib/rubygems/commands/update_command.rb +27 -25
  24. data/lib/rubygems/custom_require.rb +1 -1
  25. data/lib/rubygems/defaults.rb +8 -1
  26. data/lib/rubygems/dependency_installer.rb +72 -104
  27. data/lib/rubygems/digest/digest_adapter.rb +0 -0
  28. data/lib/rubygems/digest/md5.rb +0 -0
  29. data/lib/rubygems/digest/sha1.rb +0 -0
  30. data/lib/rubygems/digest/sha2.rb +0 -0
  31. data/lib/rubygems/exceptions.rb +22 -1
  32. data/lib/rubygems/format.rb +16 -10
  33. data/lib/rubygems/indexer.rb +46 -33
  34. data/lib/rubygems/indexer/abstract_index_builder.rb +10 -2
  35. data/lib/rubygems/indexer/latest_index_builder.rb +35 -0
  36. data/lib/rubygems/indexer/master_index_builder.rb +9 -8
  37. data/lib/rubygems/indexer/quick_index_builder.rb +5 -3
  38. data/lib/rubygems/install_update_options.rb +7 -1
  39. data/lib/rubygems/installer.rb +8 -5
  40. data/lib/rubygems/package.rb +17 -774
  41. data/lib/rubygems/package/f_sync_dir.rb +24 -0
  42. data/lib/rubygems/package/tar_header.rb +245 -0
  43. data/lib/rubygems/package/tar_input.rb +219 -0
  44. data/lib/rubygems/package/tar_output.rb +143 -0
  45. data/lib/rubygems/package/tar_reader.rb +86 -0
  46. data/lib/rubygems/package/tar_reader/entry.rb +99 -0
  47. data/lib/rubygems/package/tar_writer.rb +180 -0
  48. data/lib/rubygems/remote_fetcher.rb +131 -16
  49. data/lib/rubygems/requirement.rb +2 -0
  50. data/lib/rubygems/rubygems_version.rb +1 -1
  51. data/lib/rubygems/security.rb +1 -0
  52. data/lib/rubygems/server.rb +85 -104
  53. data/lib/rubygems/source_index.rb +412 -329
  54. data/lib/rubygems/source_info_cache.rb +232 -99
  55. data/lib/rubygems/source_info_cache_entry.rb +14 -4
  56. data/lib/rubygems/specification.rb +9 -10
  57. data/lib/rubygems/timer.rb +0 -0
  58. data/lib/rubygems/uninstaller.rb +56 -32
  59. data/lib/rubygems/user_interaction.rb +4 -10
  60. data/lib/rubygems/validator.rb +0 -0
  61. data/scripts/gemdoc.rb +0 -0
  62. data/scripts/specdoc.rb +0 -0
  63. data/setup.rb +56 -19
  64. data/test/gem_installer_test_case.rb +86 -0
  65. data/test/gem_installer_test_case.rbc +0 -0
  66. data/test/gem_package_tar_test_case.rb +146 -0
  67. data/test/gem_package_tar_test_case.rbc +0 -0
  68. data/test/gemutilities.rb +123 -38
  69. data/test/gemutilities.rbc +0 -0
  70. data/test/mockgemui.rb +5 -13
  71. data/test/mockgemui.rbc +0 -0
  72. data/test/private_key.pem +27 -0
  73. data/test/public_cert.pem +20 -0
  74. data/test/simple_gem.rbc +0 -0
  75. data/test/test_config.rbc +0 -0
  76. data/test/test_gem.rb +46 -4
  77. data/test/test_gem.rbc +0 -0
  78. data/test/test_gem_builder.rbc +0 -0
  79. data/test/test_gem_command.rbc +0 -0
  80. data/test/test_gem_command_manager.rb +4 -2
  81. data/test/test_gem_command_manager.rbc +0 -0
  82. data/test/test_gem_commands_build_command.rbc +0 -0
  83. data/test/test_gem_commands_cert_command.rb +5 -1
  84. data/test/test_gem_commands_cert_command.rbc +0 -0
  85. data/test/test_gem_commands_check_command.rbc +0 -0
  86. data/test/test_gem_commands_contents_command.rbc +0 -0
  87. data/test/test_gem_commands_dependency_command.rbc +0 -0
  88. data/test/test_gem_commands_environment_command.rb +17 -1
  89. data/test/test_gem_commands_environment_command.rbc +0 -0
  90. data/test/test_gem_commands_fetch_command.rb +6 -5
  91. data/test/test_gem_commands_fetch_command.rbc +0 -0
  92. data/test/test_gem_commands_generate_index_command.rbc +0 -0
  93. data/test/test_gem_commands_install_command.rb +36 -28
  94. data/test/test_gem_commands_install_command.rbc +0 -0
  95. data/test/test_gem_commands_mirror_command.rbc +0 -0
  96. data/test/test_gem_commands_pristine_command.rbc +0 -0
  97. data/test/test_gem_commands_query_command.rb +143 -19
  98. data/test/test_gem_commands_query_command.rbc +0 -0
  99. data/test/test_gem_commands_server_command.rb +1 -1
  100. data/test/test_gem_commands_server_command.rbc +0 -0
  101. data/test/test_gem_commands_sources_command.rb +67 -9
  102. data/test/test_gem_commands_sources_command.rbc +0 -0
  103. data/test/test_gem_commands_specification_command.rb +3 -2
  104. data/test/test_gem_commands_specification_command.rbc +0 -0
  105. data/test/test_gem_commands_unpack_command.rb +46 -4
  106. data/test/test_gem_commands_unpack_command.rbc +0 -0
  107. data/test/test_gem_commands_update_command.rb +174 -0
  108. data/test/test_gem_commands_update_command.rbc +0 -0
  109. data/test/test_gem_config_file.rbc +0 -0
  110. data/test/test_gem_dependency.rbc +0 -0
  111. data/test/test_gem_dependency_installer.rb +172 -187
  112. data/test/test_gem_dependency_installer.rbc +0 -0
  113. data/test/test_gem_dependency_list.rbc +0 -0
  114. data/test/test_gem_digest.rb +0 -0
  115. data/test/test_gem_digest.rbc +0 -0
  116. data/test/test_gem_doc_manager.rbc +0 -0
  117. data/test/test_gem_ext_configure_builder.rb +9 -6
  118. data/test/test_gem_ext_configure_builder.rbc +0 -0
  119. data/test/test_gem_ext_ext_conf_builder.rbc +0 -0
  120. data/test/test_gem_ext_rake_builder.rbc +0 -0
  121. data/test/test_gem_format.rb +1 -1
  122. data/test/test_gem_format.rbc +0 -0
  123. data/test/test_gem_gem_path_searcher.rbc +0 -0
  124. data/test/test_gem_gem_runner.rbc +0 -0
  125. data/test/test_gem_indexer.rb +7 -2
  126. data/test/test_gem_indexer.rbc +0 -0
  127. data/test/test_gem_install_update_options.rbc +0 -0
  128. data/test/test_gem_installer.rb +5 -84
  129. data/test/test_gem_installer.rbc +0 -0
  130. data/test/test_gem_local_remote_options.rbc +0 -0
  131. data/test/test_gem_outdated_command.rbc +0 -0
  132. data/test/test_gem_package_tar_header.rb +137 -0
  133. data/test/test_gem_package_tar_header.rbc +0 -0
  134. data/test/test_gem_package_tar_input.rb +119 -0
  135. data/test/test_gem_package_tar_input.rbc +0 -0
  136. data/test/test_gem_package_tar_output.rb +104 -0
  137. data/test/test_gem_package_tar_output.rbc +0 -0
  138. data/test/test_gem_package_tar_reader.rb +53 -0
  139. data/test/test_gem_package_tar_reader.rbc +0 -0
  140. data/test/test_gem_package_tar_reader_entry.rb +116 -0
  141. data/test/test_gem_package_tar_reader_entry.rbc +0 -0
  142. data/test/test_gem_package_tar_writer.rb +151 -0
  143. data/test/test_gem_package_tar_writer.rbc +0 -0
  144. data/test/test_gem_platform.rbc +0 -0
  145. data/test/test_gem_remote_fetcher.rb +189 -17
  146. data/test/test_gem_remote_fetcher.rbc +0 -0
  147. data/test/test_gem_requirement.rbc +0 -0
  148. data/test/test_gem_server.rb +13 -12
  149. data/test/test_gem_server.rbc +0 -0
  150. data/test/test_gem_source_index.rb +305 -56
  151. data/test/test_gem_source_index.rbc +0 -0
  152. data/test/test_gem_source_info_cache.rb +179 -53
  153. data/test/test_gem_source_info_cache.rbc +0 -0
  154. data/test/test_gem_source_info_cache_entry.rb +41 -10
  155. data/test/test_gem_source_info_cache_entry.rbc +0 -0
  156. data/test/test_gem_specification.rb +7 -7
  157. data/test/test_gem_specification.rbc +0 -0
  158. data/test/test_gem_stream_ui.rbc +0 -0
  159. data/test/test_gem_uninstaller.rb +43 -0
  160. data/test/test_gem_uninstaller.rbc +0 -0
  161. data/test/test_gem_validator.rbc +0 -0
  162. data/test/test_gem_version.rb +1 -1
  163. data/test/test_gem_version.rbc +0 -0
  164. data/test/test_gem_version_option.rbc +0 -0
  165. data/test/test_kernel.rb +1 -0
  166. data/test/test_kernel.rbc +0 -0
  167. metadata +85 -8
  168. metadata.gz.sig +0 -0
  169. data/lib/rubygems/gem_open_uri.rb +0 -7
  170. data/lib/rubygems/open-uri.rb +0 -773
  171. data/test/test_open_uri.rb +0 -13
  172. data/test/test_package.rb +0 -608
@@ -65,13 +65,20 @@ EOM
65
65
  end
66
66
 
67
67
  def write_package
68
- Package.open(@spec.file_name, "w", @signer) do |pkg|
69
- pkg.metadata = @spec.to_yaml
70
- @spec.files.each do |file|
71
- next if File.directory? file
72
- pkg.add_file_simple(file, File.stat(@spec.file_name).mode & 0777,
73
- File.size(file)) do |os|
74
- os.write File.open(file, "rb"){|f|f.read}
68
+ open @spec.file_name, 'wb' do |gem_io|
69
+ Gem::Package.open gem_io, 'w', @signer do |pkg|
70
+ pkg.metadata = @spec.to_yaml
71
+
72
+ @spec.files.each do |file|
73
+ next if File.directory? file
74
+
75
+ stat = File.stat file
76
+ mode = stat.mode & 0777
77
+ size = stat.size
78
+
79
+ pkg.add_file_simple file, mode, size do |tar_io|
80
+ tar_io.write open(file, "rb") { |f| f.read }
81
+ end
75
82
  end
76
83
  end
77
84
  end
@@ -136,7 +136,7 @@ module Gem
136
136
  execute
137
137
  end
138
138
  end
139
-
139
+
140
140
  # Call the given block when invoked.
141
141
  #
142
142
  # Normal command invocations just executes the +execute+ method of
@@ -146,7 +146,7 @@ module Gem
146
146
  def when_invoked(&block)
147
147
  @when_invoked = block
148
148
  end
149
-
149
+
150
150
  # Add a command-line option and handler to the command.
151
151
  #
152
152
  # See OptionParser#make_switch for an explanation of +opts+.
@@ -165,7 +165,7 @@ module Gem
165
165
  option_list.reject! { |args, _| args.any? { |x| x =~ /^#{name}/ } }
166
166
  end
167
167
  end
168
-
168
+
169
169
  # Merge a set of command options with the set of default options
170
170
  # (without modifying the default option hash).
171
171
  def merge_options(new_options)
@@ -191,7 +191,7 @@ module Gem
191
191
  parser.parse!(args)
192
192
  @options[:args] = args
193
193
  end
194
-
194
+
195
195
  def add_extra_args(args)
196
196
  result = []
197
197
  s_extra = Command.specific_extra_args(@command)
@@ -291,7 +291,7 @@ module Gem
291
291
  def common_options
292
292
  @common_options ||= []
293
293
  end
294
-
294
+
295
295
  def add_common_option(*args, &handler)
296
296
  Gem::Command.common_options << [args, handler]
297
297
  end
@@ -315,7 +315,7 @@ module Gem
315
315
  def specific_extra_args(cmd)
316
316
  specific_extra_args_hash[cmd]
317
317
  end
318
-
318
+
319
319
  # Add a list of extra arguments for the given command. +args+
320
320
  # may be an array or a string to be split on white space.
321
321
  def add_specific_extra_args(cmd,args)
@@ -334,7 +334,7 @@ module Gem
334
334
  # ----------------------------------------------------------------
335
335
  # Add the options common to all commands.
336
336
 
337
- add_common_option('-h', '--help',
337
+ add_common_option('-h', '--help',
338
338
  'Get help on this command') do
339
339
  |value, options|
340
340
  options[:help] = true
@@ -358,11 +358,11 @@ module Gem
358
358
  # commands. Both options are actually handled before the other
359
359
  # options get parsed.
360
360
 
361
- add_common_option('--config-file FILE',
361
+ add_common_option('--config-file FILE',
362
362
  "Use this config file instead of default") do
363
363
  end
364
364
 
365
- add_common_option('--backtrace',
365
+ add_common_option('--backtrace',
366
366
  'Show stack backtrace on errors') do
367
367
  end
368
368
 
@@ -123,6 +123,7 @@ module Gem
123
123
  end
124
124
 
125
125
  private
126
+
126
127
  def load_and_instantiate(command_name)
127
128
  command_name = command_name.to_s
128
129
  retried = false
@@ -2,92 +2,90 @@ require 'rubygems/command'
2
2
  require 'rubygems/source_index'
3
3
  require 'rubygems/dependency_list'
4
4
 
5
- module Gem
6
- module Commands
7
- class CleanupCommand < Command
8
- def initialize
9
- super(
10
- 'cleanup',
5
+ class Gem::Commands::CleanupCommand < Gem::Command
6
+
7
+ def initialize
8
+ super 'cleanup',
11
9
  'Clean up old versions of installed gems in the local repository',
12
- {
13
- :force => false,
14
- :test => false,
15
- :install_dir => Gem.dir
16
- })
17
- add_option('-d', '--dryrun', "") do |value, options|
18
- options[:dryrun] = true
19
- end
20
- end
10
+ :force => false, :test => false, :install_dir => Gem.dir
21
11
 
22
- def arguments # :nodoc:
23
- "GEMNAME name of gem to cleanup"
24
- end
12
+ add_option('-d', '--dryrun', "") do |value, options|
13
+ options[:dryrun] = true
14
+ end
15
+ end
25
16
 
26
- def defaults_str # :nodoc:
27
- "--no-dryrun"
28
- end
17
+ def arguments # :nodoc:
18
+ "GEMNAME name of gem to cleanup"
19
+ end
20
+
21
+ def defaults_str # :nodoc:
22
+ "--no-dryrun"
23
+ end
24
+
25
+ def usage # :nodoc:
26
+ "#{program_name} [GEMNAME ...]"
27
+ end
28
+
29
+ def execute
30
+ say "Cleaning up installed gems..."
31
+ primary_gems = {}
29
32
 
30
- def usage # :nodoc:
31
- "#{program_name} [GEMNAME ...]"
33
+ Gem.source_index.each do |name, spec|
34
+ if primary_gems[spec.name].nil? or
35
+ primary_gems[spec.name].version < spec.version then
36
+ primary_gems[spec.name] = spec
32
37
  end
38
+ end
33
39
 
34
- def execute
35
- say "Cleaning up installed gems..."
36
- srcindex = Gem::SourceIndex.from_installed_gems
37
- primary_gems = {}
40
+ gems_to_cleanup = []
38
41
 
39
- srcindex.each do |name, spec|
40
- if primary_gems[spec.name].nil? or primary_gems[spec.name].version < spec.version
41
- primary_gems[spec.name] = spec
42
- end
42
+ unless options[:args].empty? then
43
+ options[:args].each do |gem_name|
44
+ specs = Gem.cache.search(/^#{gem_name}$/i)
45
+ specs.each do |spec|
46
+ gems_to_cleanup << spec
43
47
  end
48
+ end
49
+ else
50
+ Gem.source_index.each do |name, spec|
51
+ gems_to_cleanup << spec
52
+ end
53
+ end
44
54
 
45
- gems_to_cleanup = []
46
-
47
- unless options[:args].empty? then
48
- options[:args].each do |gem_name|
49
- specs = Gem.cache.search(/^#{gem_name}$/i)
50
- specs.each do |spec|
51
- gems_to_cleanup << spec
52
- end
53
- end
54
- else
55
- srcindex.each do |name, spec|
56
- gems_to_cleanup << spec
57
- end
58
- end
55
+ gems_to_cleanup = gems_to_cleanup.select { |spec|
56
+ primary_gems[spec.name].version != spec.version
57
+ }
59
58
 
60
- gems_to_cleanup = gems_to_cleanup.select { |spec|
61
- primary_gems[spec.name].version != spec.version
62
- }
59
+ uninstall_command = Gem::CommandManager.instance['uninstall']
60
+ deplist = Gem::DependencyList.new
61
+ gems_to_cleanup.uniq.each do |spec| deplist.add spec end
63
62
 
64
- uninstall_command = Gem::CommandManager.instance['uninstall']
65
- deplist = DependencyList.new
66
- gems_to_cleanup.uniq.each do |spec| deplist.add(spec) end
63
+ deps = deplist.strongly_connected_components.flatten.reverse
67
64
 
68
- deplist.dependency_order.each do |spec|
69
- if options[:dryrun] then
70
- say "Dry Run Mode: Would uninstall #{spec.full_name}"
71
- else
72
- say "Attempting uninstall on #{spec.full_name}"
65
+ deps.each do |spec|
66
+ if options[:dryrun] then
67
+ say "Dry Run Mode: Would uninstall #{spec.full_name}"
68
+ else
69
+ say "Attempting to uninstall #{spec.full_name}"
73
70
 
74
- options[:args] = [spec.name]
75
- options[:version] = "= #{spec.version}"
76
- options[:executables] = true
71
+ options[:args] = [spec.name]
72
+ options[:version] = "= #{spec.version}"
73
+ options[:executables] = false
77
74
 
78
- uninstall_command.merge_options(options)
75
+ uninstaller = Gem::Uninstaller.new spec.name, options
79
76
 
80
- begin
81
- uninstall_command.execute
82
- rescue Gem::DependencyRemovalException => ex
83
- say "Unable to uninstall #{spec.full_name} ... continuing with remaining gems"
84
- end
85
- end
77
+ begin
78
+ uninstaller.uninstall
79
+ rescue Gem::DependencyRemovalException,
80
+ Gem::GemNotInHomeException => e
81
+ say "Unable to uninstall #{spec.full_name}:"
82
+ say "\t#{e.class}: #{e.message}"
86
83
  end
87
-
88
- say "Clean Up Complete"
89
84
  end
90
85
  end
91
-
86
+
87
+ say "Clean Up Complete"
92
88
  end
89
+
93
90
  end
91
+
@@ -25,19 +25,18 @@ class Gem::Commands::EnvironmentCommand < Gem::Command
25
25
  def execute
26
26
  out = ''
27
27
  arg = options[:args][0]
28
- if begins?("packageversion", arg) then
28
+ case arg
29
+ when /^packageversion/ then
29
30
  out << Gem::RubyGemsPackageVersion
30
- elsif begins?("version", arg) then
31
+ when /^version/ then
31
32
  out << Gem::RubyGemsVersion
32
- elsif begins?("gemdir", arg) then
33
+ when /^gemdir/, /^gemhome/, /^home/, /^GEM_HOME/ then
33
34
  out << Gem.dir
34
- elsif begins?("gempath", arg) then
35
- out << Gem.path.join("\n")
36
- elsif begins?("remotesources", arg) then
35
+ when /^gempath/, /^path/, /^GEM_PATH/ then
36
+ out << Gem.path.join(File::PATH_SEPARATOR)
37
+ when /^remotesources/ then
37
38
  out << Gem.sources.join("\n")
38
- elsif arg then
39
- fail Gem::CommandLineError, "Unknown enviroment option [#{arg}]"
40
- else
39
+ when nil then
41
40
  out = "RubyGems Environment:\n"
42
41
 
43
42
  out << " - RUBYGEMS VERSION: #{Gem::RubyGemsVersion} (#{Gem::RubyGemsPackageVersion})\n"
@@ -58,7 +57,11 @@ class Gem::Commands::EnvironmentCommand < Gem::Command
58
57
  end
59
58
 
60
59
  out << " - GEM PATHS:\n"
61
- Gem.path.each do |p|
60
+ out << " - #{Gem.dir}\n"
61
+
62
+ path = Gem.path.dup
63
+ path.delete Gem.dir
64
+ path.each do |p|
62
65
  out << " - #{p}\n"
63
66
  end
64
67
 
@@ -71,6 +74,9 @@ class Gem::Commands::EnvironmentCommand < Gem::Command
71
74
  Gem.sources.each do |s|
72
75
  out << " - #{s}\n"
73
76
  end
77
+
78
+ else
79
+ fail Gem::CommandLineError, "Unknown enviroment option [#{arg}]"
74
80
  end
75
81
  say out
76
82
  true
@@ -44,17 +44,15 @@ class Gem::Commands::FetchCommand < Gem::Command
44
44
 
45
45
  spec, source_uri = specs_and_sources.last
46
46
 
47
- gem_file = "#{spec.full_name}.gem"
48
-
49
- gem_path = File.join source_uri, 'gems', gem_file
50
-
51
- gem = Gem::RemoteFetcher.fetcher.fetch_path gem_path
52
-
53
- File.open gem_file, 'wb' do |fp|
54
- fp.write gem
47
+ if spec.nil? then
48
+ alert_error "Could not find #{gem_name} in any repository"
49
+ next
55
50
  end
56
51
 
57
- say "Downloaded #{gem_file}"
52
+ path = Gem::RemoteFetcher.fetcher.download spec, source_uri
53
+ FileUtils.mv path, "#{spec.full_name}.gem"
54
+
55
+ say "Downloaded #{spec.full_name}"
58
56
  end
59
57
  end
60
58
 
@@ -62,13 +62,15 @@ class Gem::Commands::InstallCommand < Gem::Command
62
62
  :install_dir => options[:install_dir],
63
63
  :security_policy => options[:security_policy],
64
64
  :wrappers => options[:wrappers],
65
+ :bin_dir => options[:bin_dir]
65
66
  }
66
67
 
68
+ exit_code = 0
69
+
67
70
  get_all_gem_names.each do |gem_name|
68
71
  begin
69
- inst = Gem::DependencyInstaller.new gem_name, options[:version],
70
- install_options
71
- inst.install
72
+ inst = Gem::DependencyInstaller.new install_options
73
+ inst.install gem_name, options[:version]
72
74
 
73
75
  inst.installed_gems.each do |spec|
74
76
  say "Successfully installed #{spec.full_name}"
@@ -77,8 +79,10 @@ class Gem::Commands::InstallCommand < Gem::Command
77
79
  installed_gems.push(*inst.installed_gems)
78
80
  rescue Gem::InstallError => e
79
81
  alert_error "Error installing #{gem_name}:\n\t#{e.message}"
82
+ exit_code |= 1
80
83
  rescue Gem::GemNotFoundException => e
81
84
  alert_error e.message
85
+ exit_code |= 2
82
86
  # rescue => e
83
87
  # # TODO: Fix this handle to allow the error to propagate to
84
88
  # # the top level handler. Examine the other errors as
@@ -121,6 +125,8 @@ class Gem::Commands::InstallCommand < Gem::Command
121
125
  end
122
126
  end
123
127
  end
128
+
129
+ raise Gem::SystemExitException, exit_code
124
130
  end
125
131
 
126
132
  end
@@ -6,10 +6,8 @@ module Gem
6
6
  class ListCommand < QueryCommand
7
7
 
8
8
  def initialize
9
- super(
10
- 'list',
11
- 'Display all gems whose name starts with STRING'
12
- )
9
+ super 'list', 'Display gems whose name starts with STRING'
10
+
13
11
  remove_option('--name-matches')
14
12
  end
15
13
 
@@ -2,7 +2,7 @@ require 'yaml'
2
2
  require 'zlib'
3
3
 
4
4
  require 'rubygems/command'
5
- require 'rubygems/gem_open_uri'
5
+ require 'open-uri'
6
6
 
7
7
  class Gem::Commands::MirrorCommand < Gem::Command
8
8
 
@@ -1,15 +1,25 @@
1
1
  require 'rubygems/command'
2
2
  require 'rubygems/local_remote_options'
3
3
  require 'rubygems/source_info_cache'
4
+ require 'rubygems/version_option'
4
5
 
5
6
  class Gem::Commands::QueryCommand < Gem::Command
6
7
 
7
8
  include Gem::LocalRemoteOptions
9
+ include Gem::VersionOption
8
10
 
9
11
  def initialize(name = 'query',
10
12
  summary = 'Query gem information in local or remote repositories')
11
13
  super name, summary,
12
- :name => /.*/, :domain => :local, :details => false, :versions => true
14
+ :name => //, :domain => :local, :details => false, :versions => true,
15
+ :installed => false, :version => Gem::Requirement.default
16
+
17
+ add_option('-i', '--[no-]installed',
18
+ 'Check for installed gem') do |value, options|
19
+ options[:installed] = value
20
+ end
21
+
22
+ add_version_option
13
23
 
14
24
  add_option('-n', '--name-matches REGEXP',
15
25
  'Name of gem(s) to query on matches the',
@@ -28,33 +38,70 @@ class Gem::Commands::QueryCommand < Gem::Command
28
38
  options[:details] = false unless value
29
39
  end
30
40
 
41
+ add_option('-a', '--all',
42
+ 'Display all gem versions') do |value, options|
43
+ options[:all] = value
44
+ end
45
+
31
46
  add_local_remote_options
32
47
  end
33
48
 
34
49
  def defaults_str # :nodoc:
35
- "--local --name-matches '.*' --no-details --versions"
50
+ "--local --name-matches // --no-details --versions --no-installed"
36
51
  end
37
52
 
38
53
  def execute
54
+ exit_code = 0
55
+
39
56
  name = options[:name]
40
57
 
58
+ if options[:installed] then
59
+ if name.source.empty? then
60
+ alert_error "You must specify a gem name"
61
+ exit_code |= 4
62
+ elsif installed? name.source, options[:version] then
63
+ say "true"
64
+ else
65
+ say "false"
66
+ exit_code |= 1
67
+ end
68
+
69
+ raise Gem::SystemExitException, exit_code
70
+ end
71
+
41
72
  if local? then
42
73
  say
43
74
  say "*** LOCAL GEMS ***"
44
75
  say
45
- output_query_results Gem.cache.search(name)
76
+
77
+ output_query_results Gem.source_index.search(name)
46
78
  end
47
79
 
48
80
  if remote? then
49
81
  say
50
82
  say "*** REMOTE GEMS ***"
51
83
  say
52
- output_query_results Gem::SourceInfoCache.search(name)
84
+
85
+ begin
86
+ Gem::SourceInfoCache.cache options[:all]
87
+ rescue Gem::RemoteFetcher::FetchError
88
+ # no network
89
+ end
90
+
91
+ output_query_results Gem::SourceInfoCache.search(name, false, true)
53
92
  end
54
93
  end
55
94
 
56
95
  private
57
96
 
97
+ ##
98
+ # Check if gem +name+ version +version+ is installed.
99
+
100
+ def installed?(name, version = Gem::Requirement.default)
101
+ dep = Gem::Dependency.new name, version
102
+ !Gem.source_index.search(dep).empty?
103
+ end
104
+
58
105
  def output_query_results(gemspecs)
59
106
  output = []
60
107
  gem_list_with_version = {}
@@ -98,7 +145,7 @@ class Gem::Commands::QueryCommand < Gem::Command
98
145
 
99
146
  ##
100
147
  # Used for wrapping and indenting text
101
- #
148
+
102
149
  def format_text(text, wrap, indent=0)
103
150
  result = []
104
151
  work = text.dup