2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/command'
|
|
|
|
require 'rubygems/install_update_options'
|
|
|
|
require 'rubygems/local_remote_options'
|
|
|
|
require 'rubygems/source_info_cache'
|
|
|
|
require 'rubygems/version_option'
|
|
|
|
|
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',
|
2007-12-20 03:39:12 -05:00
|
|
|
:generate_rdoc => true,
|
|
|
|
:generate_ri => true,
|
|
|
|
:force => false,
|
|
|
|
:test => false,
|
|
|
|
:install_dir => Gem.dir
|
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
|
|
|
|
if options[:system] then
|
|
|
|
say "Updating RubyGems..."
|
|
|
|
|
|
|
|
unless options[:args].empty? then
|
|
|
|
fail "No gem names are allowed with the --system option"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
options[:args] = ["rubygems-update"]
|
|
|
|
else
|
|
|
|
say "Updating installed gems..."
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
hig = highest_installed_gems = {}
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
Gem::SourceIndex.from_installed_gems.each do |name, spec|
|
|
|
|
if hig[spec.name].nil? or hig[spec.name].version < spec.version then
|
|
|
|
hig[spec.name] = spec
|
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
remote_gemspecs = Gem::SourceInfoCache.search(//)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
gems_to_update = if options[:args].empty? then
|
|
|
|
which_to_update(highest_installed_gems, remote_gemspecs)
|
|
|
|
else
|
|
|
|
options[:args]
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
options[:domain] = :remote # install from remote source
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
# HACK use the real API
|
|
|
|
install_command = Gem::CommandManager.instance['install']
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
gems_to_update.uniq.sort.each do |name|
|
|
|
|
say "Attempting remote update of #{name}"
|
|
|
|
options[:args] = [name]
|
|
|
|
options[:ignore_dependencies] = true # HACK skip seen gems instead
|
|
|
|
install_command.merge_options(options)
|
|
|
|
install_command.execute
|
|
|
|
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
|
|
|
|
latest_ruby_gem = remote_gemspecs.select do |s|
|
|
|
|
s.name == 'rubygems-update'
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
latest_ruby_gem = latest_ruby_gem.sort_by { |s| s.version }.last
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
say "Updating version of RubyGems to #{latest_ruby_gem.version}"
|
|
|
|
installed = do_rubygems_update latest_ruby_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
|
|
|
|
updated = gems_to_update.uniq.sort.collect { |g| g.to_s }
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
if updated.empty? then
|
|
|
|
say "Nothing to update"
|
|
|
|
else
|
|
|
|
say "Gems updated: #{updated.join ', '}"
|
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
|
|
|
|
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]
|
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
|
|
|
success = false
|
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
|
|
|
|
if Gem.win_platform? then
|
|
|
|
system "set RUBYOPT= & #{setup_cmd}"
|
|
|
|
else
|
|
|
|
system "RUBYOPT=\"\" #{setup_cmd}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def which_to_update(highest_installed_gems, remote_gemspecs)
|
|
|
|
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|
|
|
|
|
matching_gems = remote_gemspecs.select do |spec|
|
|
|
|
spec.name == l_name and Gem.platforms.any? do |platform|
|
|
|
|
platform == spec.platform
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
highest_remote_gem = matching_gems.sort_by { |spec| spec.version }.last
|
|
|
|
|
|
|
|
if highest_remote_gem and
|
|
|
|
l_spec.version < highest_remote_gem.version then
|
|
|
|
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
|
|
|
|