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'
|
|
|
|
require 'rubygems/source_info_cache'
|
|
|
|
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',
|
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
|
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
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
options[:args] = ["rubygems-update"]
|
|
|
|
else
|
2008-03-31 18:40:06 -04:00
|
|
|
say "Updating installed gems"
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-04-11 16:57:02 -04: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
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
pattern = if options[:args].empty? then
|
2008-04-11 16:57:02 -04:00
|
|
|
//
|
2008-03-31 18:40:06 -04:00
|
|
|
else
|
|
|
|
Regexp.union(*options[:args])
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
remote_gemspecs = Gem::SourceInfoCache.search pattern
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
gems_to_update = which_to_update hig, remote_gemspecs
|
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 }
|
2008-04-11 16:57:02 -04:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
say "Updating #{name}"
|
|
|
|
installer.install name
|
2008-04-11 16:57:02 -04:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
installer.installed_gems.each do |spec|
|
|
|
|
updated << spec
|
|
|
|
say "Successfully installed #{spec.full_name}"
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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 ', '}"
|
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]
|
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
|
|
|
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
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|