mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update RubyGems to 1.1.1 r1778 (almost 1.2)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f98e6b91de
commit
9d4f37f51f
71 changed files with 3765 additions and 1127 deletions
|
@ -46,37 +46,67 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|||
options[:args] << '.' if options[:args].empty?
|
||||
specs = {}
|
||||
|
||||
source_indexes = []
|
||||
source_indexes = Hash.new do |h, source_uri|
|
||||
h[source_uri] = Gem::SourceIndex.new
|
||||
end
|
||||
|
||||
pattern = /\A#{Regexp.union(*options[:args])}/
|
||||
dependency = Gem::Dependency.new pattern, options[:version]
|
||||
|
||||
if options[:reverse_dependencies] and remote? and not local? then
|
||||
alert_error 'Only reverse dependencies for local gems are supported.'
|
||||
terminate_interaction 1
|
||||
end
|
||||
|
||||
if local? then
|
||||
source_indexes << Gem::SourceIndex.from_installed_gems
|
||||
end
|
||||
|
||||
if remote? then
|
||||
Gem::SourceInfoCache.cache_data.map do |_, sice|
|
||||
source_indexes << sice.source_index
|
||||
Gem.source_index.search(dependency).each do |spec|
|
||||
source_indexes[:local].add_spec spec
|
||||
end
|
||||
end
|
||||
|
||||
options[:args].each do |name|
|
||||
new_specs = nil
|
||||
source_indexes.each do |source_index|
|
||||
new_specs = find_gems(name, source_index)
|
||||
if remote? and not options[:reverse_dependencies] then
|
||||
fetcher = Gem::SpecFetcher.fetcher
|
||||
|
||||
begin
|
||||
fetcher.find_matching(dependency).each do |spec_tuple, source_uri|
|
||||
spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
|
||||
|
||||
source_indexes[source_uri].add_spec spec
|
||||
end
|
||||
rescue Gem::RemoteFetcher::FetchError => e
|
||||
raise unless fetcher.warn_legacy e do
|
||||
require 'rubygems/source_info_cache'
|
||||
|
||||
specs = Gem::SourceInfoCache.search_with_source dependency, false
|
||||
|
||||
specs.each do |spec, source_uri|
|
||||
source_indexes[source_uri].add_spec spec
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
say "No match found for #{name} (#{options[:version]})" if
|
||||
new_specs.empty?
|
||||
|
||||
specs = specs.merge new_specs
|
||||
end
|
||||
|
||||
terminate_interaction 1 if specs.empty?
|
||||
if source_indexes.empty? then
|
||||
patterns = options[:args].join ','
|
||||
say "No gems found matching #{patterns} (#{options[:version]})" if
|
||||
Gem.configuration.verbose
|
||||
|
||||
terminate_interaction 1
|
||||
end
|
||||
|
||||
specs = {}
|
||||
|
||||
source_indexes.values.each do |source_index|
|
||||
source_index.gems.each do |name, spec|
|
||||
specs[spec.full_name] = [source_index, spec]
|
||||
end
|
||||
end
|
||||
|
||||
reverse = Hash.new { |h, k| h[k] = [] }
|
||||
|
||||
if options[:reverse_dependencies] then
|
||||
specs.values.each do |source_index, spec|
|
||||
reverse[spec.full_name] = find_reverse_dependencies spec, source_index
|
||||
specs.values.each do |_, spec|
|
||||
reverse[spec.full_name] = find_reverse_dependencies spec
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -118,10 +148,10 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|||
end
|
||||
|
||||
# Retuns list of [specification, dep] that are satisfied by spec.
|
||||
def find_reverse_dependencies(spec, source_index)
|
||||
def find_reverse_dependencies(spec)
|
||||
result = []
|
||||
|
||||
source_index.each do |name, sp|
|
||||
Gem.source_index.each do |name, sp|
|
||||
sp.dependencies.each do |dep|
|
||||
dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep
|
||||
|
||||
|
@ -146,5 +176,6 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|||
|
||||
specs
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@ class Gem::Commands::EnvironmentCommand < Gem::Command
|
|||
|
||||
out << " - RUBY EXECUTABLE: #{Gem.ruby}\n"
|
||||
|
||||
out << " - EXECUTABLE DIRECTORY: #{Gem.bindir}\n"
|
||||
|
||||
out << " - RUBYGEMS PLATFORMS:\n"
|
||||
Gem.platforms.each do |platform|
|
||||
out << " - #{platform}\n"
|
||||
|
|
|
@ -33,12 +33,14 @@ class Gem::Commands::FetchCommand < Gem::Command
|
|||
|
||||
def execute
|
||||
version = options[:version] || Gem::Requirement.default
|
||||
all = Gem::Requirement.default
|
||||
|
||||
gem_names = get_all_gem_names
|
||||
|
||||
gem_names.each do |gem_name|
|
||||
dep = Gem::Dependency.new gem_name, version
|
||||
specs_and_sources = Gem::SourceInfoCache.search_with_source dep, true
|
||||
|
||||
specs_and_sources = Gem::SpecFetcher.fetcher.fetch dep, all
|
||||
|
||||
specs_and_sources.sort_by { |spec,| spec.version }
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ class Gem::Commands::InstallCommand < Gem::Command
|
|||
defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({
|
||||
:generate_rdoc => true,
|
||||
:generate_ri => true,
|
||||
:install_dir => Gem.dir,
|
||||
:format_executable => false,
|
||||
:test => false,
|
||||
:version => Gem::Requirement.default,
|
||||
|
@ -62,7 +61,8 @@ class Gem::Commands::InstallCommand < Gem::Command
|
|||
:install_dir => options[:install_dir],
|
||||
:security_policy => options[:security_policy],
|
||||
:wrappers => options[:wrappers],
|
||||
:bin_dir => options[:bin_dir]
|
||||
:bin_dir => options[:bin_dir],
|
||||
:development => options[:development],
|
||||
}
|
||||
|
||||
exit_code = 0
|
||||
|
|
|
@ -1,33 +1,35 @@
|
|||
require 'rubygems/command'
|
||||
require 'rubygems/commands/query_command'
|
||||
|
||||
module Gem
|
||||
module Commands
|
||||
class ListCommand < QueryCommand
|
||||
##
|
||||
# An alternate to Gem::Commands::QueryCommand that searches for gems starting
|
||||
# with the the supplied argument.
|
||||
|
||||
def initialize
|
||||
super 'list', 'Display gems whose name starts with STRING'
|
||||
class Gem::Commands::ListCommand < Gem::Commands::QueryCommand
|
||||
|
||||
remove_option('--name-matches')
|
||||
end
|
||||
def initialize
|
||||
super 'list', 'Display gems whose name starts with STRING'
|
||||
|
||||
def arguments # :nodoc:
|
||||
"STRING start of gem name to look for"
|
||||
end
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--local --no-details"
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} [STRING]"
|
||||
end
|
||||
|
||||
def execute
|
||||
string = get_one_optional_argument || ''
|
||||
options[:name] = /^#{string}/i
|
||||
super
|
||||
end
|
||||
end
|
||||
remove_option('--name-matches')
|
||||
end
|
||||
|
||||
def arguments # :nodoc:
|
||||
"STRING start of gem name to look for"
|
||||
end
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--local --no-details"
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} [STRING]"
|
||||
end
|
||||
|
||||
def execute
|
||||
string = get_one_optional_argument || ''
|
||||
options[:name] = /^#{string}/i
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ lock it down to the exact version.
|
|||
say "gem '#{spec.name}', '= #{spec.version}'" unless locked[spec.name]
|
||||
locked[spec.name] = true
|
||||
|
||||
spec.dependencies.each do |dep|
|
||||
spec.runtime_dependencies.each do |dep|
|
||||
next if locked[dep.name]
|
||||
candidates = Gem.source_index.search dep.name, dep.requirement_list
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rubygems/command'
|
||||
require 'rubygems/local_remote_options'
|
||||
require 'rubygems/source_info_cache'
|
||||
require 'rubygems/spec_fetcher'
|
||||
require 'rubygems/version_option'
|
||||
|
||||
class Gem::Commands::OutdatedCommand < Gem::Command
|
||||
|
@ -20,8 +20,11 @@ class Gem::Commands::OutdatedCommand < Gem::Command
|
|||
|
||||
locals.outdated.sort.each do |name|
|
||||
local = locals.search(/^#{name}$/).last
|
||||
remotes = Gem::SourceInfoCache.search_with_source(/^#{name}$/, true)
|
||||
|
||||
dep = Gem::Dependency.new local.name, ">= #{local.version}"
|
||||
remotes = Gem::SpecFetcher.fetcher.fetch dep
|
||||
remote = remotes.last.first
|
||||
|
||||
say "#{local.name} (#{local.version} < #{remote.version})"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,51 +82,10 @@ revert the gem.
|
|||
end
|
||||
|
||||
# TODO use installer options
|
||||
installer = Gem::Installer.new gem, :wrappers => true
|
||||
installer = Gem::Installer.new gem, :wrappers => true, :force => true
|
||||
installer.install
|
||||
|
||||
gem_file = File.join install_dir, "cache", "#{spec.full_name}.gem"
|
||||
|
||||
security_policy = nil # TODO use installer option
|
||||
|
||||
format = Gem::Format.from_file_by_path gem_file, security_policy
|
||||
|
||||
target_directory = File.join(install_dir, "gems", format.spec.full_name)
|
||||
target_directory.untaint
|
||||
|
||||
pristine_files = format.file_entries.collect { |data| data[0]["path"] }
|
||||
file_map = {}
|
||||
|
||||
format.file_entries.each do |entry, file_data|
|
||||
file_map[entry["path"]] = file_data
|
||||
end
|
||||
|
||||
Dir.chdir target_directory do
|
||||
deployed_files = Dir.glob(File.join("**", "*")) +
|
||||
Dir.glob(File.join("**", ".*"))
|
||||
|
||||
pristine_files = pristine_files.map { |f| File.expand_path f }
|
||||
deployed_files = deployed_files.map { |f| File.expand_path f }
|
||||
|
||||
to_redeploy = (pristine_files - deployed_files)
|
||||
to_redeploy = to_redeploy.map { |path| path.untaint}
|
||||
|
||||
if to_redeploy.length > 0 then
|
||||
say "Restoring #{to_redeploy.length} file#{to_redeploy.length == 1 ? "" : "s"} to #{spec.full_name}..."
|
||||
|
||||
to_redeploy.each do |path|
|
||||
say " #{path}"
|
||||
FileUtils.mkdir_p File.dirname(path)
|
||||
File.open(path, "wb") do |out|
|
||||
out.write file_map[path]
|
||||
end
|
||||
end
|
||||
else
|
||||
say "#{spec.full_name} is in pristine condition"
|
||||
end
|
||||
end
|
||||
|
||||
installer.generate_bin
|
||||
installer.build_extensions
|
||||
say "Restored #{spec.full_name}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rubygems/command'
|
||||
require 'rubygems/local_remote_options'
|
||||
require 'rubygems/source_info_cache'
|
||||
require 'rubygems/spec_fetcher'
|
||||
require 'rubygems/version_option'
|
||||
|
||||
class Gem::Commands::QueryCommand < Gem::Command
|
||||
|
@ -74,7 +74,13 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
say "*** LOCAL GEMS ***"
|
||||
say
|
||||
|
||||
output_query_results Gem.source_index.search(name)
|
||||
specs = Gem.source_index.search name
|
||||
|
||||
spec_tuples = specs.map do |spec|
|
||||
[[spec.name, spec.version, spec.original_platform, spec], :local]
|
||||
end
|
||||
|
||||
output_query_results spec_tuples
|
||||
end
|
||||
|
||||
if remote? then
|
||||
|
@ -84,13 +90,26 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
|
||||
all = options[:all]
|
||||
|
||||
dep = Gem::Dependency.new name, Gem::Requirement.default
|
||||
begin
|
||||
Gem::SourceInfoCache.cache all
|
||||
rescue Gem::RemoteFetcher::FetchError
|
||||
# no network
|
||||
fetcher = Gem::SpecFetcher.fetcher
|
||||
spec_tuples = fetcher.find_matching dep, all, false
|
||||
rescue Gem::RemoteFetcher::FetchError => e
|
||||
raise unless fetcher.warn_legacy e do
|
||||
require 'rubygems/source_info_cache'
|
||||
|
||||
dep.name = '' if dep.name == //
|
||||
|
||||
specs = Gem::SourceInfoCache.search_with_source dep, false, all
|
||||
|
||||
spec_tuples = specs.map do |spec, source_uri|
|
||||
[[spec.name, spec.version, spec.original_platform, spec],
|
||||
source_uri]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
output_query_results Gem::SourceInfoCache.search(name, false, all)
|
||||
output_query_results spec_tuples
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -104,28 +123,30 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
!Gem.source_index.search(dep).empty?
|
||||
end
|
||||
|
||||
def output_query_results(gemspecs)
|
||||
def output_query_results(spec_tuples)
|
||||
output = []
|
||||
gem_list_with_version = {}
|
||||
versions = Hash.new { |h,name| h[name] = [] }
|
||||
|
||||
gemspecs.flatten.each do |gemspec|
|
||||
gem_list_with_version[gemspec.name] ||= []
|
||||
gem_list_with_version[gemspec.name] << gemspec
|
||||
spec_tuples.each do |spec_tuple, source_uri|
|
||||
versions[spec_tuple.first] << [spec_tuple, source_uri]
|
||||
end
|
||||
|
||||
gem_list_with_version = gem_list_with_version.sort_by do |name, spec|
|
||||
versions = versions.sort_by do |(name,),|
|
||||
name.downcase
|
||||
end
|
||||
|
||||
gem_list_with_version.each do |gem_name, list_of_matching|
|
||||
list_of_matching = list_of_matching.sort_by { |x| x.version.to_ints }.reverse
|
||||
seen_versions = {}
|
||||
versions.each do |gem_name, matching_tuples|
|
||||
matching_tuples = matching_tuples.sort_by do |(name, version,),|
|
||||
version
|
||||
end.reverse
|
||||
|
||||
list_of_matching.delete_if do |item|
|
||||
if seen_versions[item.version] then
|
||||
seen = {}
|
||||
|
||||
matching_tuples.delete_if do |(name, version,),|
|
||||
if seen[version] then
|
||||
true
|
||||
else
|
||||
seen_versions[item.version] = true
|
||||
seen[version] = true
|
||||
false
|
||||
end
|
||||
end
|
||||
|
@ -133,12 +154,50 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
entry = gem_name.dup
|
||||
|
||||
if options[:versions] then
|
||||
versions = list_of_matching.map { |s| s.version }.uniq
|
||||
versions = matching_tuples.map { |(name, version,),| version }.uniq
|
||||
entry << " (#{versions.join ', '})"
|
||||
end
|
||||
|
||||
entry << "\n" << format_text(list_of_matching[0].summary, 68, 4) if
|
||||
options[:details]
|
||||
if options[:details] then
|
||||
detail_tuple = matching_tuples.first
|
||||
|
||||
spec = if detail_tuple.first.length == 4 then
|
||||
detail_tuple.first.last
|
||||
else
|
||||
uri = URI.parse detail_tuple.last
|
||||
Gem::SpecFetcher.fetcher.fetch_spec detail_tuple.first, uri
|
||||
end
|
||||
|
||||
entry << "\n"
|
||||
authors = "Author#{spec.authors.length > 1 ? 's' : ''}: "
|
||||
authors << spec.authors.join(', ')
|
||||
entry << format_text(authors, 68, 4)
|
||||
|
||||
if spec.rubyforge_project and not spec.rubyforge_project.empty? then
|
||||
rubyforge = "Rubyforge: http://rubyforge.org/projects/#{spec.rubyforge_project}"
|
||||
entry << "\n" << format_text(rubyforge, 68, 4)
|
||||
end
|
||||
|
||||
if spec.homepage and not spec.homepage.empty? then
|
||||
entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4)
|
||||
end
|
||||
|
||||
if spec.loaded_from then
|
||||
if matching_tuples.length == 1 then
|
||||
loaded_from = File.dirname File.dirname(spec.loaded_from)
|
||||
entry << "\n" << " Installed at: #{loaded_from}"
|
||||
else
|
||||
label = 'Installed at'
|
||||
matching_tuples.each do |(_,version,_,s),|
|
||||
loaded_from = File.dirname File.dirname(s.loaded_from)
|
||||
entry << "\n" << " #{label} (#{version}): #{loaded_from}"
|
||||
label = ' ' * label.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
entry << "\n\n" << format_text(spec.summary, 68, 4)
|
||||
end
|
||||
output << entry
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'fileutils'
|
||||
require 'rubygems/command'
|
||||
require 'rubygems/remote_fetcher'
|
||||
require 'rubygems/source_info_cache'
|
||||
require 'rubygems/source_info_cache_entry'
|
||||
require 'rubygems/spec_fetcher'
|
||||
|
||||
class Gem::Commands::SourcesCommand < Gem::Command
|
||||
|
||||
|
@ -21,14 +22,14 @@ class Gem::Commands::SourcesCommand < Gem::Command
|
|||
options[:remove] = value
|
||||
end
|
||||
|
||||
add_option '-u', '--update', 'Update source cache' do |value, options|
|
||||
options[:update] = value
|
||||
end
|
||||
|
||||
add_option '-c', '--clear-all',
|
||||
'Remove all sources (clear the cache)' do |value, options|
|
||||
options[:clear_all] = value
|
||||
end
|
||||
|
||||
add_option '-u', '--update', 'Update source cache' do |value, options|
|
||||
options[:update] = value
|
||||
end
|
||||
end
|
||||
|
||||
def defaults_str
|
||||
|
@ -36,9 +37,23 @@ class Gem::Commands::SourcesCommand < Gem::Command
|
|||
end
|
||||
|
||||
def execute
|
||||
options[:list] = !(options[:add] || options[:remove] || options[:clear_all] || options[:update])
|
||||
options[:list] = !(options[:add] ||
|
||||
options[:clear_all] ||
|
||||
options[:remove] ||
|
||||
options[:update])
|
||||
|
||||
if options[:clear_all] then
|
||||
path = Gem::SpecFetcher.fetcher.dir
|
||||
FileUtils.rm_rf path
|
||||
|
||||
if not File.exist?(path) then
|
||||
say "*** Removed specs cache ***"
|
||||
elsif not File.writable?(path) then
|
||||
say "*** Unable to remove source cache (write protected) ***"
|
||||
else
|
||||
say "*** Unable to remove source cache ***"
|
||||
end
|
||||
|
||||
sic = Gem::SourceInfoCache
|
||||
remove_cache_file 'user', sic.user_cache_file
|
||||
remove_cache_file 'latest user', sic.latest_user_cache_file
|
||||
|
@ -48,15 +63,10 @@ class Gem::Commands::SourcesCommand < Gem::Command
|
|||
|
||||
if options[:add] then
|
||||
source_uri = options[:add]
|
||||
uri = URI.parse source_uri
|
||||
|
||||
sice = Gem::SourceInfoCacheEntry.new nil, nil
|
||||
begin
|
||||
sice.refresh source_uri, true
|
||||
|
||||
Gem::SourceInfoCache.cache_data[source_uri] = sice
|
||||
Gem::SourceInfoCache.cache.update
|
||||
Gem::SourceInfoCache.cache.flush
|
||||
|
||||
Gem::SpecFetcher.fetcher.load_specs uri, 'specs'
|
||||
Gem.sources << source_uri
|
||||
Gem.configuration.write
|
||||
|
||||
|
@ -64,31 +74,32 @@ class Gem::Commands::SourcesCommand < Gem::Command
|
|||
rescue URI::Error, ArgumentError
|
||||
say "#{source_uri} is not a URI"
|
||||
rescue Gem::RemoteFetcher::FetchError => e
|
||||
say "Error fetching #{source_uri}:\n\t#{e.message}"
|
||||
yaml_uri = uri + 'yaml'
|
||||
gem_repo = Gem::RemoteFetcher.fetcher.fetch_size yaml_uri rescue false
|
||||
|
||||
if e.uri =~ /specs\.#{Regexp.escape Gem.marshal_version}\.gz$/ and
|
||||
gem_repo then
|
||||
|
||||
alert_warning <<-EOF
|
||||
RubyGems 1.2+ index not found for:
|
||||
\t#{source_uri}
|
||||
|
||||
Will cause RubyGems to revert to legacy indexes, degrading performance.
|
||||
EOF
|
||||
|
||||
say "#{source_uri} added to sources"
|
||||
else
|
||||
say "Error fetching #{source_uri}:\n\t#{e.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if options[:update] then
|
||||
Gem::SourceInfoCache.cache true
|
||||
Gem::SourceInfoCache.cache.flush
|
||||
|
||||
say "source cache successfully updated"
|
||||
end
|
||||
|
||||
if options[:remove] then
|
||||
source_uri = options[:remove]
|
||||
|
||||
unless Gem.sources.include? source_uri then
|
||||
say "source #{source_uri} not present in cache"
|
||||
else
|
||||
begin # HACK figure out how to get the cache w/o update
|
||||
Gem::SourceInfoCache.cache
|
||||
rescue Gem::RemoteFetcher::FetchError
|
||||
end
|
||||
|
||||
Gem::SourceInfoCache.cache_data.delete source_uri
|
||||
Gem::SourceInfoCache.cache.update
|
||||
Gem::SourceInfoCache.cache.flush
|
||||
Gem.sources.delete source_uri
|
||||
Gem.configuration.write
|
||||
|
||||
|
@ -96,6 +107,23 @@ class Gem::Commands::SourcesCommand < Gem::Command
|
|||
end
|
||||
end
|
||||
|
||||
if options[:update] then
|
||||
fetcher = Gem::SpecFetcher.fetcher
|
||||
|
||||
if fetcher.legacy_repos.empty? then
|
||||
Gem.sources.each do |source_uri|
|
||||
source_uri = URI.parse source_uri
|
||||
fetcher.load_specs source_uri, 'specs'
|
||||
fetcher.load_specs source_uri, 'latest_specs'
|
||||
end
|
||||
else
|
||||
Gem::SourceInfoCache.cache true
|
||||
Gem::SourceInfoCache.cache.flush
|
||||
end
|
||||
|
||||
say "source cache successfully updated"
|
||||
end
|
||||
|
||||
if options[:list] then
|
||||
say "*** CURRENT SOURCES ***"
|
||||
say
|
||||
|
|
|
@ -52,9 +52,10 @@ class Gem::Commands::SpecificationCommand < Gem::Command
|
|||
end
|
||||
|
||||
if remote? then
|
||||
Gem::SourceInfoCache.cache_data.each do |_,sice|
|
||||
specs.push(*sice.source_index.search(gem, options[:version]))
|
||||
end
|
||||
dep = Gem::Dependency.new gem, options[:version]
|
||||
found = Gem::SpecFetcher.fetcher.fetch dep
|
||||
|
||||
specs.push(*found.map { |spec,| spec })
|
||||
end
|
||||
|
||||
if specs.empty? then
|
||||
|
|
27
lib/rubygems/commands/stale_command.rb
Normal file
27
lib/rubygems/commands/stale_command.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'rubygems/command'
|
||||
|
||||
class Gem::Commands::StaleCommand < Gem::Command
|
||||
def initialize
|
||||
super('stale', 'List gems along with access times')
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name}"
|
||||
end
|
||||
|
||||
def execute
|
||||
gem_to_atime = {}
|
||||
Gem.source_index.each do |name, spec|
|
||||
Dir["#{spec.full_gem_path}/**/*.*"].each do |file|
|
||||
next if File.directory?(file)
|
||||
stat = File.stat(file)
|
||||
gem_to_atime[name] ||= stat.atime
|
||||
gem_to_atime[name] = stat.atime if gem_to_atime[name] < stat.atime
|
||||
end
|
||||
end
|
||||
|
||||
gem_to_atime.sort_by { |_, atime| atime }.each do |name, atime|
|
||||
say "#{name} at #{atime.strftime '%c'}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@ require 'rubygems/command'
|
|||
require 'rubygems/command_manager'
|
||||
require 'rubygems/install_update_options'
|
||||
require 'rubygems/local_remote_options'
|
||||
require 'rubygems/source_info_cache'
|
||||
require 'rubygems/spec_fetcher'
|
||||
require 'rubygems/version_option'
|
||||
require 'rubygems/commands/install_command'
|
||||
|
||||
|
@ -15,11 +15,10 @@ class Gem::Commands::UpdateCommand < Gem::Command
|
|||
def initialize
|
||||
super 'update',
|
||||
'Update the named gems (or all installed gems) in the local repository',
|
||||
:generate_rdoc => true,
|
||||
:generate_ri => true,
|
||||
:force => false,
|
||||
:test => false,
|
||||
:install_dir => Gem.dir
|
||||
:generate_rdoc => true,
|
||||
:generate_ri => true,
|
||||
:force => false,
|
||||
:test => false
|
||||
|
||||
add_install_update_options
|
||||
|
||||
|
@ -60,21 +59,13 @@ class Gem::Commands::UpdateCommand < Gem::Command
|
|||
|
||||
hig = {} # highest installed gems
|
||||
|
||||
Gem::SourceIndex.from_installed_gems.each do |name, spec|
|
||||
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
|
||||
end
|
||||
|
||||
pattern = if options[:args].empty? then
|
||||
//
|
||||
else
|
||||
Regexp.union(*options[:args])
|
||||
end
|
||||
|
||||
remote_gemspecs = Gem::SourceInfoCache.search pattern
|
||||
|
||||
gems_to_update = which_to_update hig, remote_gemspecs
|
||||
gems_to_update = which_to_update hig, options[:args]
|
||||
|
||||
updated = []
|
||||
|
||||
|
@ -135,20 +126,42 @@ class Gem::Commands::UpdateCommand < Gem::Command
|
|||
end
|
||||
end
|
||||
|
||||
def which_to_update(highest_installed_gems, remote_gemspecs)
|
||||
def which_to_update(highest_installed_gems, gem_names)
|
||||
result = []
|
||||
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
highest_remote_gem = matching_gems.sort_by { |spec| spec.version }.last
|
||||
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
|
||||
|
||||
if highest_remote_gem and
|
||||
l_spec.version < highest_remote_gem.version then
|
||||
l_spec.version < highest_remote_gem.first[1] then
|
||||
result << l_name
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue