| Class | Gem::Commands::UpdateCommand |
| In: |
lib/rubygems/commands/update_command.rb
|
| Parent: | Gem::Command |
# File lib/rubygems/commands/update_command.rb, line 15
15: def initialize
16: super 'update',
17: 'Update the named gems (or all installed gems) in the local repository',
18: :generate_rdoc => true,
19: :generate_ri => true,
20: :force => false,
21: :test => false
22:
23: add_install_update_options
24:
25: add_option('--system',
26: 'Update the RubyGems system software') do |value, options|
27: options[:system] = value
28: end
29:
30: add_local_remote_options
31: add_platform_option
32: add_prerelease_option "as update targets"
33: end
Update the RubyGems software to version.
# File lib/rubygems/commands/update_command.rb, line 141
141: def do_rubygems_update(version)
142: args = []
143: args.push '--prefix', Gem.prefix unless Gem.prefix.nil?
144: args << '--no-rdoc' unless options[:generate_rdoc]
145: args << '--no-ri' unless options[:generate_ri]
146: args << '--no-format-executable' if options[:no_format_executable]
147:
148: update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
149:
150: Dir.chdir update_dir do
151: say "Installing RubyGems #{version}"
152: setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
153:
154: # Make sure old rubygems isn't loaded
155: old = ENV["RUBYOPT"]
156: ENV.delete("RUBYOPT")
157: system setup_cmd
158: ENV["RUBYOPT"] = old if old
159: end
160: end
# File lib/rubygems/commands/update_command.rb, line 47
47: def execute
48: hig = {}
49:
50: if options[:system] then
51: if ENV.include?('REALLY_GEM_UPDATE_SYSTEM')
52: say "Updating RubyGems"
53:
54: unless options[:args].empty? then
55: raise "No gem names are allowed with the --system option"
56: end
57:
58: rubygems_update = Gem::Specification.new
59: rubygems_update.name = 'rubygems-update'
60: rubygems_update.version = Gem::Version.new Gem::VERSION
61: hig['rubygems-update'] = rubygems_update
62:
63: options[:user_install] = false
64: else
65: fail "gem update --system is disabled on Debian, because it will overwrite the content of the rubygems Debian package, and might break your Debian system in subtle ways. The Debian-supported way to update rubygems is through apt-get, using Debian official repositories.\nIf you really know what you are doing, you can still update rubygems by setting the REALLY_GEM_UPDATE_SYSTEM environment variable, but please remember that this is completely unsupported by Debian."
66: end
67: else
68: say "Updating installed gems"
69:
70: hig = {} # highest installed gems
71:
72: Gem.source_index.each do |name, spec|
73: if hig[spec.name].nil? or hig[spec.name].version < spec.version then
74: hig[spec.name] = spec
75: end
76: end
77: end
78:
79: gems_to_update = which_to_update hig, options[:args]
80:
81: updated = []
82:
83: installer = Gem::DependencyInstaller.new options
84:
85: gems_to_update.uniq.sort.each do |name|
86: next if updated.any? { |spec| spec.name == name }
87: success = false
88:
89: say "Updating #{name}"
90: begin
91: installer.install name
92: success = true
93: rescue Gem::InstallError => e
94: alert_error "Error installing #{name}:\n\t#{e.message}"
95: success = false
96: end
97:
98: installer.installed_gems.each do |spec|
99: updated << spec
100: say "Successfully installed #{spec.full_name}" if success
101: end
102: end
103:
104: if gems_to_update.include? "rubygems-update" then
105: Gem.source_index.refresh!
106:
107: update_gems = Gem.source_index.find_name 'rubygems-update'
108:
109: latest_update_gem = update_gems.sort_by { |s| s.version }.last
110:
111: say "Updating RubyGems to #{latest_update_gem.version}"
112: installed = do_rubygems_update latest_update_gem.version
113:
114: say "RubyGems system software updated" if installed
115: else
116: if updated.empty? then
117: say "Nothing to update"
118: else
119: say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}"
120:
121: if options[:generate_ri] then
122: updated.each do |gem|
123: Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
124: end
125:
126: Gem::DocManager.update_ri_cache
127: end
128:
129: if options[:generate_rdoc] then
130: updated.each do |gem|
131: Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
132: end
133: end
134: end
135: end
136: end
# File lib/rubygems/commands/update_command.rb, line 162
162: def which_to_update(highest_installed_gems, gem_names)
163: result = []
164:
165: highest_installed_gems.each do |l_name, l_spec|
166: next if not gem_names.empty? and
167: gem_names.all? { |name| /#{name}/ !~ l_spec.name }
168:
169: dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
170:
171: begin
172: fetcher = Gem::SpecFetcher.fetcher
173: spec_tuples = fetcher.find_matching dependency
174: rescue Gem::RemoteFetcher::FetchError => e
175: raise unless fetcher.warn_legacy e do
176: require 'rubygems/source_info_cache'
177:
178: dependency.name = '' if dependency.name == //
179:
180: specs = Gem::SourceInfoCache.search_with_source dependency
181:
182: spec_tuples = specs.map do |spec, source_uri|
183: [[spec.name, spec.version, spec.original_platform], source_uri]
184: end
185: end
186: end
187:
188: matching_gems = spec_tuples.select do |(name, version, platform),|
189: name == l_name and Gem::Platform.match platform
190: end
191:
192: highest_remote_gem = matching_gems.sort_by do |(name, version),|
193: version
194: end.last
195:
196: if highest_remote_gem and
197: l_spec.version < highest_remote_gem.first[1] then
198: result << l_name
199: end
200: end
201:
202: result
203: end