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,58 +1,72 @@
1
- module Gem
2
- module Commands
3
- class SpecificationCommand < Command
4
- include VersionOption
5
- include LocalRemoteOptions
6
- include CommandAids
7
-
8
- def initialize
9
- super('specification', 'Display gem specification (in yaml)',
10
- {:domain=>:local, :version=>"> 0.0.0"})
11
- add_version_option('examine')
12
- add_local_remote_options
13
- add_option('--all', 'Output specifications for all versions of',
14
- 'the gem') do |value, options|
15
- options[:all] = true
16
- end
17
- end
1
+ require 'yaml'
2
+ require 'rubygems/command'
3
+ require 'rubygems/local_remote_options'
4
+ require 'rubygems/version_option'
5
+ require 'rubygems/source_info_cache'
18
6
 
19
- def defaults_str
20
- "--local --version '(latest)'"
21
- end
7
+ class Gem::Commands::SpecificationCommand < Gem::Command
22
8
 
23
- def usage
24
- "#{program_name} GEMFILE"
25
- end
9
+ include Gem::LocalRemoteOptions
10
+ include Gem::VersionOption
26
11
 
27
- def arguments
28
- "GEMFILE Name of a .gem file to examine"
29
- end
12
+ def initialize
13
+ super 'specification', 'Display gem specification (in yaml)',
14
+ :domain => :local, :version => Gem::Requirement.default
15
+
16
+ add_version_option('examine')
17
+ add_platform_option
18
+
19
+ add_option('--all', 'Output specifications for all versions of',
20
+ 'the gem') do |value, options|
21
+ options[:all] = true
22
+ end
23
+
24
+ add_local_remote_options
25
+ end
26
+
27
+ def arguments # :nodoc:
28
+ "GEMFILE name of gem to show the gemspec for"
29
+ end
30
+
31
+ def defaults_str # :nodoc:
32
+ "--local --version '#{Gem::Requirement.default}'"
33
+ end
30
34
 
31
- def execute
32
- if local?
33
- gem = get_one_gem_name
34
- gem_specs = Gem::SourceIndex.from_installed_gems.search(gem, options[:version])
35
- unless gem_specs.empty?
36
- require 'yaml'
37
- output = lambda { |spec| say spec.to_yaml; say "\n" }
38
- if options[:all]
39
- gem_specs.each(&output)
40
- else
41
- spec = gem_specs.sort_by { |spec| spec.version }.last
42
- output[spec]
43
- end
44
- else
45
- alert_error "Unknown gem #{gem}"
46
- end
47
- end
48
-
49
- if remote?
50
- say "(Remote 'info' operation is not yet implemented.)"
51
- # NOTE: when we do implement remote info, make sure we don't
52
- # duplicate huge swabs of local data. If it's the same, just
53
- # say it's the same.
54
- end
35
+ def usage # :nodoc:
36
+ "#{program_name} [GEMFILE]"
37
+ end
38
+
39
+ def execute
40
+ specs = []
41
+ gem = get_one_gem_name
42
+
43
+ if local? then
44
+ source_index = Gem::SourceIndex.from_installed_gems
45
+ specs.push(*source_index.search(/\A#{gem}\z/, options[:version]))
46
+ end
47
+
48
+ if remote? then
49
+ alert_warning "Remote information is not complete\n\n"
50
+
51
+ Gem::SourceInfoCache.cache_data.each do |_,sice|
52
+ specs.push(*sice.source_index.search(gem, options[:version]))
55
53
  end
56
54
  end
55
+
56
+ if specs.empty? then
57
+ alert_error "Unknown gem '#{gem}'"
58
+ terminate_interaction 1
59
+ end
60
+
61
+ output = lambda { |spec| say spec.to_yaml; say "\n" }
62
+
63
+ if options[:all] then
64
+ specs.each(&output)
65
+ else
66
+ spec = specs.sort_by { |spec| spec.version }.last
67
+ output[spec]
68
+ end
57
69
  end
58
- end
70
+
71
+ end
72
+
@@ -1,12 +1,16 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/version_option'
3
+ require 'rubygems/uninstaller'
4
+
1
5
  module Gem
2
6
  module Commands
3
7
  class UninstallCommand < Command
8
+
4
9
  include VersionOption
5
- include CommandAids
6
10
 
7
11
  def initialize
8
- super('uninstall', 'Uninstall gems from the local repository',
9
- { :version => "> 0" })
12
+ super 'uninstall', 'Uninstall gems from the local repository',
13
+ :version => Gem::Requirement.default
10
14
 
11
15
  add_option('-a', '--[no-]all',
12
16
  'Uninstall all matching versions'
@@ -26,19 +30,20 @@ module Gem
26
30
  options[:executables] = value
27
31
  end
28
32
 
29
- add_version_option('uninstall')
33
+ add_version_option
34
+ add_platform_option
30
35
  end
31
36
 
32
- def defaults_str
33
- "--version '> 0' --no-force"
37
+ def arguments # :nodoc:
38
+ "GEMNAME name of gem to uninstall"
34
39
  end
35
-
36
- def usage
37
- "#{program_name} GEMNAME [GEMNAME ...]"
40
+
41
+ def defaults_str # :nodoc:
42
+ "--version '#{Gem::Requirement.default}' --no-force"
38
43
  end
39
44
 
40
- def arguments
41
- "GEMNAME name of gem to uninstall"
45
+ def usage # :nodoc:
46
+ "#{program_name} GEMNAME [GEMNAME ...]"
42
47
  end
43
48
 
44
49
  def execute
@@ -48,4 +53,4 @@ module Gem
48
53
  end
49
54
  end
50
55
  end
51
- end
56
+ end
@@ -1,76 +1,76 @@
1
- module Gem
2
- module Commands
3
- class UnpackCommand < Command
4
- include VersionOption
5
- include CommandAids
1
+ require 'fileutils'
2
+ require 'rubygems/command'
3
+ require 'rubygems/installer'
4
+ require 'rubygems/version_option'
6
5
 
7
- def initialize
8
- super(
9
- 'unpack',
10
- 'Unpack an installed gem to the current directory',
11
- { :version => '> 0' }
12
- )
13
- add_version_option('unpack')
14
- end
6
+ class Gem::Commands::UnpackCommand < Gem::Command
15
7
 
16
- def defaults_str
17
- "--version '> 0'"
18
- end
8
+ include Gem::VersionOption
19
9
 
20
- def usage
21
- "#{program_name} GEMNAME"
22
- end
10
+ def initialize
11
+ super 'unpack', 'Unpack an installed gem to the current directory',
12
+ :version => Gem::Requirement.default
13
+ add_version_option
14
+ end
15
+
16
+ def arguments # :nodoc:
17
+ "GEMNAME name of gem to unpack"
18
+ end
19
+
20
+ def defaults_str # :nodoc:
21
+ "--version '#{Gem::Requirement.default}'"
22
+ end
23
23
 
24
- def arguments
25
- "GEMNAME Name of the gem to unpack"
26
- end
24
+ def usage # :nodoc:
25
+ "#{program_name} GEMNAME"
26
+ end
27
27
 
28
- # TODO: allow, e.g., 'gem unpack rake-0.3.1'. Find a general
29
- # solution for this, so that it works for uninstall as well. (And
30
- # check other commands at the same time.)
31
- def execute
32
- gemname = get_one_gem_name
33
- path = get_path(gemname, options[:version])
34
- if path
35
- require 'fileutils'
36
- target_dir = File.basename(path).sub(/\.gem$/, '')
37
- FileUtils.mkdir_p target_dir
38
- Installer.new(path).unpack(File.expand_path(target_dir))
39
- say "Unpacked gem: '#{target_dir}'"
40
- else
41
- alert_error "Gem '#{gemname}' not installed."
42
- end
43
- end
28
+ #--
29
+ # TODO: allow, e.g., 'gem unpack rake-0.3.1'. Find a general solution for
30
+ # this, so that it works for uninstall as well. (And check other commands
31
+ # at the same time.)
32
+ def execute
33
+ gemname = get_one_gem_name
34
+ path = get_path(gemname, options[:version])
35
+ if path
36
+ target_dir = File.basename(path).sub(/\.gem$/, '')
37
+ FileUtils.mkdir_p target_dir
38
+ Gem::Installer.new(path).unpack(File.expand_path(target_dir))
39
+ say "Unpacked gem: '#{target_dir}'"
40
+ else
41
+ alert_error "Gem '#{gemname}' not installed."
42
+ end
43
+ end
44
44
 
45
- # Return the full path to the cached gem file matching the given
46
- # name and version requirement. Returns 'nil' if no match.
47
- # Example:
48
- #
49
- # get_path('rake', '> 0.4') # -> '/usr/lib/ruby/gems/1.8/cache/rake-0.4.2.gem'
50
- # get_path('rake', '< 0.1') # -> nil
51
- # get_path('rak') # -> nil (exact name required)
52
- #
53
- # TODO: This should be refactored so that it's a general service.
54
- # I don't think any of our existing classes are the right place
55
- # though. Just maybe 'Cache'?
56
- #
57
- # TODO: It just uses Gem.dir for now. What's an easy way to get
58
- # the list of source directories?
59
- #
60
- def get_path(gemname, version_req)
61
- return gemname if gemname =~ /\.gem$/i
62
- specs = SourceIndex.from_installed_gems.search(gemname, version_req)
63
- selected = specs.sort_by { |s| s.version }.last
64
- return nil if selected.nil?
65
- # We expect to find (basename).gem in the 'cache' directory.
66
- # Furthermore, the name match must be exact (ignoring case).
67
- if gemname =~ /^#{selected.name}$/i
68
- filename = selected.full_name + '.gem'
69
- return File.join(Gem.dir, 'cache', filename)
70
- else
71
- return nil
72
- end
73
- end
45
+ # Return the full path to the cached gem file matching the given
46
+ # name and version requirement. Returns 'nil' if no match.
47
+ #
48
+ # Example:
49
+ #
50
+ # get_path('rake', '> 0.4') # -> '/usr/lib/ruby/gems/1.8/cache/rake-0.4.2.gem'
51
+ # get_path('rake', '< 0.1') # -> nil
52
+ # get_path('rak') # -> nil (exact name required)
53
+ #--
54
+ # TODO: This should be refactored so that it's a general service. I don't
55
+ # think any of our existing classes are the right place though. Just maybe
56
+ # 'Cache'?
57
+ #
58
+ # TODO: It just uses Gem.dir for now. What's an easy way to get the list of
59
+ # source directories?
60
+ def get_path(gemname, version_req)
61
+ return gemname if gemname =~ /\.gem$/i
62
+ specs = Gem::SourceIndex.from_installed_gems.search(/\A#{gemname}\z/, version_req)
63
+ selected = specs.sort_by { |s| s.version }.last
64
+ return nil if selected.nil?
65
+ # We expect to find (basename).gem in the 'cache' directory.
66
+ # Furthermore, the name match must be exact (ignoring case).
67
+ if gemname =~ /^#{selected.name}$/i
68
+ filename = selected.full_name + '.gem'
69
+ return File.join(Gem.dir, 'cache', filename)
70
+ else
71
+ return nil
74
72
  end
75
73
  end
76
- end
74
+
75
+ end
76
+
@@ -1,12 +1,21 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/install_update_options'
3
+ require 'rubygems/local_remote_options'
4
+ require 'rubygems/source_info_cache'
5
+ require 'rubygems/version_option'
6
+
1
7
  module Gem
2
8
  module Commands
3
9
  class UpdateCommand < Command
4
- include InstallUpdateOptions
10
+
11
+ include Gem::InstallUpdateOptions
12
+ include Gem::LocalRemoteOptions
13
+ include Gem::VersionOption
5
14
 
6
15
  def initialize
7
16
  super(
8
17
  'update',
9
- 'Update the named gem (or all installed gems) in the local repository',
18
+ 'Update the named gems (or all installed gems) in the local repository',
10
19
  {
11
20
  :generate_rdoc => true,
12
21
  :generate_ri => true,
@@ -14,73 +23,111 @@ module Gem
14
23
  :test => false,
15
24
  :install_dir => Gem.dir
16
25
  })
26
+
17
27
  add_install_update_options
28
+
18
29
  add_option('--system',
19
30
  'Update the RubyGems system software') do |value, options|
20
31
  options[:system] = value
21
32
  end
33
+
34
+ add_local_remote_options
35
+
36
+ add_platform_option
37
+ end
38
+
39
+ def arguments # :nodoc:
40
+ "GEMNAME name of gem to update"
22
41
  end
23
-
24
- def defaults_str
42
+
43
+ def defaults_str # :nodoc:
25
44
  "--rdoc --ri --no-force --no-test\n" +
26
45
  "--install-dir #{Gem.dir}"
27
46
  end
28
47
 
29
- def arguments
30
- "GEMNAME(s) name of gem(s) to update"
48
+ def usage # :nodoc:
49
+ "#{program_name} GEMNAME [GEMNAME ...]"
31
50
  end
32
51
 
33
52
  def execute
34
- if options[:system]
53
+ if options[:system] then
35
54
  say "Updating RubyGems..."
36
- if ! options[:args].empty?
55
+
56
+ unless options[:args].empty? then
37
57
  fail "No gem names are allowed with the --system option"
38
58
  end
59
+
39
60
  options[:args] = ["rubygems-update"]
40
61
  else
41
62
  say "Updating installed gems..."
42
63
  end
64
+
43
65
  hig = highest_installed_gems = {}
66
+
44
67
  Gem::SourceIndex.from_installed_gems.each do |name, spec|
45
68
  if hig[spec.name].nil? or hig[spec.name].version < spec.version
46
69
  hig[spec.name] = spec
47
70
  end
48
71
  end
72
+
49
73
  remote_gemspecs = Gem::SourceInfoCache.search(//)
50
- gems_to_update = if(options[:args].empty?) then
51
- which_to_update(highest_installed_gems, remote_gemspecs)
52
- else
53
- options[:args]
54
- end
74
+
75
+ gems_to_update = if options[:args].empty? then
76
+ which_to_update(highest_installed_gems, remote_gemspecs)
77
+ else
78
+ options[:args]
79
+ end
80
+
55
81
  options[:domain] = :remote # install from remote source
56
- install_command = command_manager['install']
82
+
83
+ # HACK use the real API
84
+ install_command = Gem::CommandManager.instance['install']
85
+
57
86
  gems_to_update.uniq.sort.each do |name|
58
87
  say "Attempting remote update of #{name}"
59
88
  options[:args] = [name]
89
+ options[:ignore_dependencies] = true # HACK skip seen gems instead
60
90
  install_command.merge_options(options)
61
91
  install_command.execute
62
92
  end
63
- if gems_to_update.include?("rubygems-update")
93
+
94
+ if gems_to_update.include?("rubygems-update") then
64
95
  latest_ruby_gem = remote_gemspecs.select { |s|
65
- s.name == 'rubygems-update'
96
+ s.name == 'rubygems-update'
66
97
  }.sort_by { |s|
67
98
  s.version
68
99
  }.last
100
+
69
101
  say "Updating version of RubyGems to #{latest_ruby_gem.version}"
70
- do_rubygems_update(latest_ruby_gem.version.to_s)
71
- end
72
- if(options[:system]) then
73
- say "RubyGems system software updated"
102
+ installed = do_rubygems_update(latest_ruby_gem.version.to_s)
103
+
104
+ say "RubyGems system software updated" if installed
74
105
  else
75
106
  say "Gems: [#{gems_to_update.uniq.sort.collect{|g| g.to_s}.join(', ')}] updated"
76
107
  end
77
108
  end
78
109
 
79
110
  def do_rubygems_update(version_string)
80
- update_dir = File.join(Gem.dir, "gems", "rubygems-update-#{version_string}")
81
- Dir.chdir(update_dir) do
82
- puts "Installing RubyGems #{version_string}"
83
- system "#{Gem.ruby} setup.rb"
111
+ args = []
112
+ args.push '--prefix', Gem.prefix unless Gem.prefix.nil?
113
+ args << '--no-rdoc' unless options[:generate_rdoc]
114
+ args << '--no-ri' unless options[:generate_ri]
115
+
116
+ update_dir = File.join(Gem.dir, 'gems',
117
+ "rubygems-update-#{version_string}")
118
+
119
+ success = false
120
+
121
+ Dir.chdir update_dir do
122
+ say "Installing RubyGems #{version_string}"
123
+ setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
124
+
125
+ # Make sure old rubygems isn't loaded
126
+ if Gem.win_platform? then
127
+ system "set RUBYOPT= & #{setup_cmd}"
128
+ else
129
+ system "RUBYOPT=\"\" #{setup_cmd}"
130
+ end
84
131
  end
85
132
  end
86
133
 
@@ -99,4 +146,4 @@ module Gem
99
146
  end
100
147
  end
101
148
  end
102
- end
149
+ end