2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/command'
|
2008-03-31 18:40:06 -04:00
|
|
|
require 'rubygems/command_manager'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/install_update_options'
|
|
|
|
require 'rubygems/local_remote_options'
|
2008-06-17 18:04:18 -04:00
|
|
|
require 'rubygems/spec_fetcher'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/version_option'
|
2008-03-31 18:40:06 -04:00
|
|
|
require 'rubygems/commands/install_command'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
class Gem::Commands::UpdateCommand < Gem::Command
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
include Gem::InstallUpdateOptions
|
|
|
|
include Gem::LocalRemoteOptions
|
|
|
|
include Gem::VersionOption
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def initialize
|
|
|
|
super 'update',
|
2007-11-10 02:48:56 -05:00
|
|
|
'Update the named gems (or all installed gems) in the local repository',
|
2008-06-17 18:04:18 -04:00
|
|
|
:generate_rdoc => true,
|
2009-06-09 17:38:59 -04:00
|
|
|
:generate_ri => true,
|
|
|
|
:force => false,
|
|
|
|
:test => false
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
add_install_update_options
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
add_option('--system',
|
|
|
|
'Update the RubyGems system software') do |value, options|
|
|
|
|
options[:system] = value
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
add_local_remote_options
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
add_platform_option
|
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
|
|
|
"GEMNAME name of gem to update"
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def defaults_str # :nodoc:
|
|
|
|
"--rdoc --ri --no-force --no-test --install-dir #{Gem.dir}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def usage # :nodoc:
|
|
|
|
"#{program_name} GEMNAME [GEMNAME ...]"
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2008-09-25 06:13:50 -04:00
|
|
|
hig = {}
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
if options[:system] then
|
2008-03-31 18:40:06 -04:00
|
|
|
say "Updating RubyGems"
|
2007-12-20 03:39:12 -05:00
|
|
|
|
|
|
|
unless options[:args].empty? then
|
|
|
|
fail "No gem names are allowed with the --system option"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
rubygems_update = Gem::Specification.new
|
|
|
|
rubygems_update.name = 'rubygems-update'
|
|
|
|
rubygems_update.version = Gem::Version.new Gem::RubyGemsVersion
|
|
|
|
hig['rubygems-update'] = rubygems_update
|
2008-09-25 06:13:50 -04:00
|
|
|
|
|
|
|
options[:user_install] = false
|
2007-12-20 03:39:12 -05:00
|
|
|
else
|
2008-03-31 18:40:06 -04:00
|
|
|
say "Updating installed gems"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
hig = {} # highest installed gems
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
Gem.source_index.each do |name, spec|
|
|
|
|
if hig[spec.name].nil? or hig[spec.name].version < spec.version then
|
|
|
|
hig[spec.name] = spec
|
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
gems_to_update = which_to_update hig, options[:args]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
updated = []
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-04-11 16:57:02 -04:00
|
|
|
installer = Gem::DependencyInstaller.new options
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
gems_to_update.uniq.sort.each do |name|
|
2008-03-31 18:40:06 -04:00
|
|
|
next if updated.any? { |spec| spec.name == name }
|
2009-06-09 17:38:59 -04:00
|
|
|
success = false
|
2008-04-11 16:57:02 -04:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
say "Updating #{name}"
|
2009-06-09 17:38:59 -04:00
|
|
|
begin
|
|
|
|
installer.install name
|
|
|
|
success = true
|
|
|
|
rescue Gem::InstallError => e
|
|
|
|
alert_error "Error installing #{name}:\n\t#{e.message}"
|
|
|
|
success = false
|
|
|
|
end
|
2008-04-11 16:57:02 -04:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
installer.installed_gems.each do |spec|
|
|
|
|
updated << spec
|
2009-06-09 17:38:59 -04:00
|
|
|
say "Successfully installed #{spec.full_name}" if success
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
if gems_to_update.include? "rubygems-update" then
|
2008-09-25 06:13:50 -04:00
|
|
|
Gem.source_index.refresh!
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
update_gems = Gem.source_index.find_name 'rubygems-update'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
latest_update_gem = update_gems.sort_by { |s| s.version }.last
|
|
|
|
|
|
|
|
say "Updating RubyGems to #{latest_update_gem.version}"
|
|
|
|
installed = do_rubygems_update latest_update_gem.version
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
say "RubyGems system software updated" if installed
|
|
|
|
else
|
|
|
|
if updated.empty? then
|
|
|
|
say "Nothing to update"
|
|
|
|
else
|
2008-03-31 18:40:06 -04:00
|
|
|
say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}"
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
if options[:generate_ri] then
|
|
|
|
updated.each do |gem|
|
|
|
|
Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
|
|
|
|
end
|
|
|
|
|
|
|
|
Gem::DocManager.update_ri_cache
|
|
|
|
end
|
|
|
|
|
|
|
|
if options[:generate_rdoc] then
|
|
|
|
updated.each do |gem|
|
|
|
|
Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
|
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Update the RubyGems software to +version+.
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def do_rubygems_update(version)
|
|
|
|
args = []
|
|
|
|
args.push '--prefix', Gem.prefix unless Gem.prefix.nil?
|
|
|
|
args << '--no-rdoc' unless options[:generate_rdoc]
|
|
|
|
args << '--no-ri' unless options[:generate_ri]
|
2008-04-11 16:57:02 -04:00
|
|
|
args << '--no-format-executable' if options[:no_format_executable]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
Dir.chdir update_dir do
|
|
|
|
say "Installing RubyGems #{version}"
|
|
|
|
setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
# Make sure old rubygems isn't loaded
|
2007-12-27 08:33:04 -05:00
|
|
|
old = ENV["RUBYOPT"]
|
|
|
|
ENV.delete("RUBYOPT")
|
|
|
|
system setup_cmd
|
|
|
|
ENV["RUBYOPT"] = old if old
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def which_to_update(highest_installed_gems, gem_names)
|
2007-12-20 03:39:12 -05:00
|
|
|
result = []
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
highest_installed_gems.each do |l_name, l_spec|
|
2008-06-17 18:04:18 -04:00
|
|
|
next if not gem_names.empty? and
|
|
|
|
gem_names.all? { |name| /#{name}/ !~ l_spec.name }
|
|
|
|
|
|
|
|
dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
|
|
|
|
|
|
|
|
begin
|
|
|
|
fetcher = Gem::SpecFetcher.fetcher
|
|
|
|
spec_tuples = fetcher.find_matching dependency
|
|
|
|
rescue Gem::RemoteFetcher::FetchError => e
|
|
|
|
raise unless fetcher.warn_legacy e do
|
|
|
|
require 'rubygems/source_info_cache'
|
|
|
|
|
|
|
|
dependency.name = '' if dependency.name == //
|
|
|
|
|
|
|
|
specs = Gem::SourceInfoCache.search_with_source dependency
|
|
|
|
|
|
|
|
spec_tuples = specs.map do |spec, source_uri|
|
|
|
|
[[spec.name, spec.version, spec.original_platform], source_uri]
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
matching_gems = spec_tuples.select do |(name, version, platform),|
|
|
|
|
name == l_name and Gem::Platform.match platform
|
|
|
|
end
|
|
|
|
|
|
|
|
highest_remote_gem = matching_gems.sort_by do |(name, version),|
|
|
|
|
version
|
|
|
|
end.last
|
2007-12-20 03:39:12 -05:00
|
|
|
|
|
|
|
if highest_remote_gem and
|
2008-06-17 18:04:18 -04:00
|
|
|
l_spec.version < highest_remote_gem.first[1] then
|
2007-12-20 03:39:12 -05:00
|
|
|
result << l_name
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|
|
|
|
result
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|