2007-11-10 02:48:56 -05:00
|
|
|
#--
|
|
|
|
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
|
|
|
# All rights reserved.
|
|
|
|
# See LICENSE.txt for permissions.
|
|
|
|
#++
|
|
|
|
|
|
|
|
require 'rubygems/user_interaction'
|
|
|
|
require 'rubygems/specification'
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
# :stopdoc:
|
2008-09-25 06:13:50 -04:00
|
|
|
module Gem
|
2009-06-09 17:38:59 -04:00
|
|
|
autoload :SpecFetcher, 'rubygems/spec_fetcher'
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
# :startdoc:
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# The SourceIndex object indexes all the gems available from a
|
|
|
|
# particular source (e.g. a list of gem directories, or a remote
|
|
|
|
# source). A SourceIndex maps a gem full name to a gem
|
|
|
|
# specification.
|
|
|
|
#
|
|
|
|
# NOTE:: The class used to be named Cache, but that became
|
|
|
|
# confusing when cached source fetchers where introduced. The
|
|
|
|
# constant Gem::Cache is an alias for this class to allow old
|
|
|
|
# YAMLized source index objects to load properly.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
class Gem::SourceIndex
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
include Enumerable
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
include Gem::UserInteraction
|
|
|
|
|
2009-12-08 02:19:09 -05:00
|
|
|
attr_reader :gems # :nodoc:
|
2008-04-11 16:57:02 -04:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
|
|
|
# Directories to use to refresh this SourceIndex when calling refresh!
|
|
|
|
|
|
|
|
attr_accessor :spec_dirs
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
class << self
|
2007-11-10 02:48:56 -05:00
|
|
|
include Gem::UserInteraction
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Factory method to construct a source index instance for a given
|
|
|
|
# path.
|
|
|
|
#
|
|
|
|
# deprecated::
|
|
|
|
# If supplied, from_installed_gems will act just like
|
|
|
|
# +from_gems_in+. This argument is deprecated and is provided
|
|
|
|
# just for backwards compatibility, and should not generally
|
|
|
|
# be used.
|
2008-06-17 18:04:18 -04:00
|
|
|
#
|
2008-03-31 18:40:06 -04:00
|
|
|
# return::
|
|
|
|
# SourceIndex instance
|
|
|
|
|
|
|
|
def from_installed_gems(*deprecated)
|
|
|
|
if deprecated.empty?
|
|
|
|
from_gems_in(*installed_spec_directories)
|
|
|
|
else
|
|
|
|
from_gems_in(*deprecated) # HACK warn
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2008-04-11 16:57:02 -04:00
|
|
|
# Returns a list of directories from Gem.path that contain specifications.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
def installed_spec_directories
|
2008-04-11 16:57:02 -04:00
|
|
|
Gem.path.collect { |dir| File.join(dir, "specifications") }
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Creates a new SourceIndex from the ruby format gem specifications in
|
|
|
|
# +spec_dirs+.
|
|
|
|
|
|
|
|
def from_gems_in(*spec_dirs)
|
2008-06-17 18:04:18 -04:00
|
|
|
source_index = new
|
|
|
|
source_index.spec_dirs = spec_dirs
|
|
|
|
source_index.refresh!
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Loads a ruby-format specification from +file_name+ and returns the
|
|
|
|
# loaded spec.
|
|
|
|
|
|
|
|
def load_specification(file_name)
|
2009-06-09 17:38:59 -04:00
|
|
|
return nil unless file_name and File.exist? file_name
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
spec_code = if defined? Encoding then
|
2009-06-09 17:38:59 -04:00
|
|
|
File.read file_name, :encoding => 'UTF-8'
|
2010-04-22 04:24:42 -04:00
|
|
|
else
|
|
|
|
File.read file_name
|
2009-06-09 17:38:59 -04:00
|
|
|
end.untaint
|
|
|
|
|
|
|
|
begin
|
2008-03-31 18:40:06 -04:00
|
|
|
gemspec = eval spec_code, binding, file_name
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
if gemspec.is_a?(Gem::Specification)
|
|
|
|
gemspec.loaded_from = file_name
|
|
|
|
return gemspec
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
alert_warning "File '#{file_name}' does not evaluate to a gem specification"
|
2008-06-17 18:04:18 -04:00
|
|
|
rescue SignalException, SystemExit
|
|
|
|
raise
|
2008-03-31 18:40:06 -04:00
|
|
|
rescue SyntaxError => e
|
|
|
|
alert_warning e
|
|
|
|
alert_warning spec_code
|
|
|
|
rescue Exception => e
|
2008-09-25 06:13:50 -04:00
|
|
|
alert_warning "#{e.inspect}\n#{spec_code}"
|
2008-03-31 18:40:06 -04:00
|
|
|
alert_warning "Invalid .gemspec format in '#{file_name}'"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
return nil
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2009-06-09 17:38:59 -04:00
|
|
|
# Constructs a source index instance from the provided specifications, which
|
|
|
|
# is a Hash of gem full names and Gem::Specifications.
|
|
|
|
#--
|
|
|
|
# TODO merge @gems and @prerelease_gems and provide a separate method
|
|
|
|
# #prerelease_gems
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
def initialize(specifications={})
|
2009-12-08 02:19:09 -05:00
|
|
|
@gems = {}
|
2009-06-09 17:38:59 -04:00
|
|
|
specifications.each{ |full_name, spec| add_spec spec }
|
2008-06-17 18:04:18 -04:00
|
|
|
@spec_dirs = nil
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2009-12-08 02:19:09 -05:00
|
|
|
# TODO: remove method
|
2009-06-09 17:38:59 -04:00
|
|
|
def all_gems
|
2009-12-08 02:19:09 -05:00
|
|
|
@gems
|
|
|
|
end
|
|
|
|
|
|
|
|
def prerelease_gems
|
|
|
|
@gems.reject{ |name, gem| !gem.version.prerelease? }
|
|
|
|
end
|
|
|
|
|
|
|
|
def released_gems
|
|
|
|
@gems.reject{ |name, gem| gem.version.prerelease? }
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Reconstruct the source index from the specifications in +spec_dirs+.
|
|
|
|
|
|
|
|
def load_gems_in(*spec_dirs)
|
|
|
|
@gems.clear
|
|
|
|
|
|
|
|
spec_dirs.reverse_each do |spec_dir|
|
|
|
|
spec_files = Dir.glob File.join(spec_dir, '*.gemspec')
|
|
|
|
|
|
|
|
spec_files.each do |spec_file|
|
|
|
|
gemspec = self.class.load_specification spec_file.untaint
|
|
|
|
add_spec gemspec if gemspec
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
self
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2009-12-08 02:19:09 -05:00
|
|
|
# Returns an Array specifications for the latest released versions
|
|
|
|
# of each gem in this index.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def latest_specs
|
|
|
|
result = Hash.new { |h,k| h[k] = [] }
|
|
|
|
latest = {}
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
sort.each do |_, spec|
|
|
|
|
name = spec.name
|
|
|
|
curr_ver = spec.version
|
|
|
|
prev_ver = latest.key?(name) ? latest[name].version : nil
|
|
|
|
|
2009-12-08 02:19:09 -05:00
|
|
|
next if curr_ver.prerelease?
|
2008-03-31 18:40:06 -04:00
|
|
|
next unless prev_ver.nil? or curr_ver >= prev_ver or
|
|
|
|
latest[name].platform != Gem::Platform::RUBY
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
if prev_ver.nil? or
|
|
|
|
(curr_ver > prev_ver and spec.platform == Gem::Platform::RUBY) then
|
|
|
|
result[name].clear
|
|
|
|
latest[name] = spec
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
if spec.platform != Gem::Platform::RUBY then
|
|
|
|
result[name].delete_if do |result_spec|
|
|
|
|
result_spec.platform == spec.platform
|
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
result[name] << spec
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# TODO: why is this a hash while @gems is an array? Seems like
|
|
|
|
# structural similarity would be good.
|
2008-03-31 18:40:06 -04:00
|
|
|
result.values.flatten
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# An array including only the prerelease gemspecs
|
|
|
|
|
|
|
|
def prerelease_specs
|
2009-12-08 02:19:09 -05:00
|
|
|
prerelease_gems.values
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# An array including only the released gemspecs
|
|
|
|
|
|
|
|
def released_specs
|
|
|
|
released_gems.values
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Add a gem specification to the source index.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def add_spec(gem_spec, name = gem_spec.full_name)
|
|
|
|
# No idea why, but the Indexer wants to insert them using original_name
|
|
|
|
# instead of full_name. So we make it an optional arg.
|
2009-12-08 02:19:09 -05:00
|
|
|
@gems[name] = gem_spec
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Add gem specifications to the source index.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def add_specs(*gem_specs)
|
|
|
|
gem_specs.each do |spec|
|
|
|
|
add_spec spec
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Remove a gem specification named +full_name+.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def remove_spec(full_name)
|
2009-12-08 02:19:09 -05:00
|
|
|
@gems.delete full_name
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Iterate over the specifications in the source index.
|
|
|
|
|
|
|
|
def each(&block) # :yields: gem.full_name, gem
|
|
|
|
@gems.each(&block)
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# The gem specification given a full gem spec name.
|
|
|
|
|
|
|
|
def specification(full_name)
|
|
|
|
@gems[full_name]
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# The signature for the source index. Changes in the signature indicate a
|
|
|
|
# change in the index.
|
|
|
|
|
|
|
|
def index_signature
|
2009-06-09 17:38:59 -04:00
|
|
|
require 'digest'
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
Digest::SHA256.new.hexdigest(@gems.keys.sort.join(',')).to_s
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# The signature for the given gem specification.
|
|
|
|
|
|
|
|
def gem_signature(gem_full_name)
|
2009-06-09 17:38:59 -04:00
|
|
|
require 'digest'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
Digest::SHA256.new.hexdigest(@gems[gem_full_name].to_yaml).to_s
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def size
|
|
|
|
@gems.size
|
|
|
|
end
|
|
|
|
alias length size
|
|
|
|
|
|
|
|
##
|
|
|
|
# Find a gem by an exact match on the short name.
|
|
|
|
|
|
|
|
def find_name(gem_name, version_requirement = Gem::Requirement.default)
|
2009-06-09 17:38:59 -04:00
|
|
|
dep = Gem::Dependency.new gem_name, version_requirement
|
2008-09-25 06:13:50 -04:00
|
|
|
search dep
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Search for a gem by Gem::Dependency +gem_pattern+. If +only_platform+
|
|
|
|
# is true, only gems matching Gem::Platform.local will be returned. An
|
|
|
|
# Array of matching Gem::Specification objects is returned.
|
|
|
|
#
|
|
|
|
# For backwards compatibility, a String or Regexp pattern may be passed as
|
|
|
|
# +gem_pattern+, and a Gem::Requirement for +platform_only+. This
|
|
|
|
# behavior is deprecated and will be removed.
|
|
|
|
|
|
|
|
def search(gem_pattern, platform_only = false)
|
|
|
|
version_requirement = nil
|
|
|
|
only_platform = false
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
# TODO - Remove support and warning for legacy arguments after 2008/11
|
|
|
|
unless Gem::Dependency === gem_pattern
|
2009-06-09 17:38:59 -04:00
|
|
|
warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name"
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
case gem_pattern
|
2008-03-31 18:40:06 -04:00
|
|
|
when Regexp then
|
|
|
|
version_requirement = platform_only || Gem::Requirement.default
|
|
|
|
when Gem::Dependency then
|
|
|
|
only_platform = platform_only
|
2010-02-21 21:52:35 -05:00
|
|
|
version_requirement = gem_pattern.requirement
|
2008-06-17 18:04:18 -04:00
|
|
|
gem_pattern = if Regexp === gem_pattern.name then
|
|
|
|
gem_pattern.name
|
|
|
|
elsif gem_pattern.name.empty? then
|
2008-03-31 18:40:06 -04:00
|
|
|
//
|
|
|
|
else
|
|
|
|
/^#{Regexp.escape gem_pattern.name}$/
|
|
|
|
end
|
|
|
|
else
|
|
|
|
version_requirement = platform_only || Gem::Requirement.default
|
|
|
|
gem_pattern = /#{gem_pattern}/i
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
unless Gem::Requirement === version_requirement then
|
|
|
|
version_requirement = Gem::Requirement.create version_requirement
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
specs = all_gems.values.select do |spec|
|
2008-03-31 18:40:06 -04:00
|
|
|
spec.name =~ gem_pattern and
|
2008-09-25 06:13:50 -04:00
|
|
|
version_requirement.satisfied_by? spec.version
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
if only_platform then
|
|
|
|
specs = specs.select do |spec|
|
|
|
|
Gem::Platform.match spec.platform
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
specs.sort_by { |s| s.sort_obj }
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2008-04-11 16:57:02 -04:00
|
|
|
# Replaces the gems in the source index from specifications in the
|
2008-06-17 18:04:18 -04:00
|
|
|
# directories this source index was created from. Raises an exception if
|
|
|
|
# this source index wasn't created from a directory (via from_gems_in or
|
|
|
|
# from_installed_gems, or having spec_dirs set).
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def refresh!
|
2008-06-17 18:04:18 -04:00
|
|
|
raise 'source index not created from disk' if @spec_dirs.nil?
|
|
|
|
load_gems_in(*@spec_dirs)
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Returns an Array of Gem::Specifications that are not up to date.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def outdated
|
|
|
|
outdateds = []
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
latest_specs.each do |local|
|
2008-06-17 19:59:31 -04:00
|
|
|
dependency = Gem::Dependency.new local.name, ">= #{local.version}"
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
fetcher = Gem::SpecFetcher.fetcher
|
|
|
|
remotes = fetcher.find_matching dependency
|
2008-06-17 19:59:31 -04:00
|
|
|
remotes = remotes.map { |(name, version,_),_| version }
|
2008-06-17 18:04:18 -04:00
|
|
|
rescue Gem::RemoteFetcher::FetchError => e
|
|
|
|
raise unless fetcher.warn_legacy e do
|
|
|
|
require 'rubygems/source_info_cache'
|
|
|
|
|
|
|
|
specs = Gem::SourceInfoCache.search_with_source dependency, true
|
|
|
|
|
|
|
|
remotes = specs.map { |spec,| spec.version }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
latest = remotes.sort.last
|
|
|
|
|
2008-06-17 19:59:31 -04:00
|
|
|
outdateds << local.name if latest and local.version < latest
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
outdateds
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Updates this SourceIndex from +source_uri+. If +all+ is false, only the
|
|
|
|
# latest gems are fetched.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def update(source_uri, all)
|
|
|
|
source_uri = URI.parse source_uri unless URI::Generic === source_uri
|
|
|
|
source_uri.path += '/' unless source_uri.path =~ /\/$/
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
use_incremental = false
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
begin
|
|
|
|
gem_names = fetch_quick_index source_uri, all
|
|
|
|
remove_extra gem_names
|
|
|
|
missing_gems = find_missing gem_names
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
return false if missing_gems.size.zero?
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
say "Missing metadata for #{missing_gems.size} gems" if
|
|
|
|
missing_gems.size > 0 and Gem.configuration.really_verbose
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
use_incremental = missing_gems.size <= Gem.configuration.bulk_threshold
|
|
|
|
rescue Gem::OperationNotSupportedError => ex
|
|
|
|
alert_error "Falling back to bulk fetch: #{ex.message}" if
|
|
|
|
Gem.configuration.really_verbose
|
|
|
|
use_incremental = false
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
if use_incremental then
|
|
|
|
update_with_missing(source_uri, missing_gems)
|
|
|
|
else
|
|
|
|
new_index = fetch_bulk_index(source_uri)
|
|
|
|
@gems.replace(new_index.gems)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
true
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def ==(other) # :nodoc:
|
2009-12-08 02:19:09 -05:00
|
|
|
self.class === other and @gems == other.gems
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def dump
|
|
|
|
Marshal.dump(self)
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def fetcher
|
|
|
|
require 'rubygems/remote_fetcher'
|
|
|
|
|
|
|
|
Gem::RemoteFetcher.fetcher
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_index_from(source_uri)
|
|
|
|
@fetch_error = nil
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
indexes = %W[
|
2007-11-10 02:48:56 -05:00
|
|
|
Marshal.#{Gem.marshal_version}.Z
|
|
|
|
Marshal.#{Gem.marshal_version}
|
|
|
|
yaml.Z
|
|
|
|
yaml
|
|
|
|
]
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
indexes.each do |name|
|
|
|
|
spec_data = nil
|
|
|
|
index = source_uri + name
|
|
|
|
begin
|
|
|
|
spec_data = fetcher.fetch_path index
|
|
|
|
spec_data = unzip(spec_data) if name =~ /\.Z$/
|
|
|
|
|
|
|
|
if name =~ /Marshal/ then
|
|
|
|
return Marshal.load(spec_data)
|
|
|
|
else
|
|
|
|
return YAML.load(spec_data)
|
|
|
|
end
|
|
|
|
rescue => e
|
|
|
|
if Gem.configuration.really_verbose then
|
|
|
|
alert_error "Unable to fetch #{name}: #{e.message}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
@fetch_error = e
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
nil
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def fetch_bulk_index(source_uri)
|
2008-06-17 18:04:18 -04:00
|
|
|
say "Bulk updating Gem source index for: #{source_uri}" if
|
|
|
|
Gem.configuration.verbose
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
index = fetch_index_from(source_uri)
|
|
|
|
if index.nil? then
|
|
|
|
raise Gem::RemoteSourceException,
|
2007-11-10 02:48:56 -05:00
|
|
|
"Error fetching remote gem cache: #{@fetch_error}"
|
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
@fetch_error = nil
|
|
|
|
index
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Get the quick index needed for incremental updates.
|
|
|
|
|
|
|
|
def fetch_quick_index(source_uri, all)
|
|
|
|
index = all ? 'index' : 'latest_index'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
zipped_index = fetcher.fetch_path source_uri + "quick/#{index}.rz"
|
|
|
|
|
|
|
|
unzip(zipped_index).split("\n")
|
|
|
|
rescue ::Exception => e
|
|
|
|
unless all then
|
|
|
|
say "Latest index not found, using quick index" if
|
|
|
|
Gem.configuration.really_verbose
|
|
|
|
|
|
|
|
fetch_quick_index source_uri, true
|
|
|
|
else
|
2007-11-10 02:48:56 -05:00
|
|
|
raise Gem::OperationNotSupportedError,
|
2008-03-31 18:40:06 -04:00
|
|
|
"No quick index found: #{e.message}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Make a list of full names for all the missing gemspecs.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def find_missing(spec_names)
|
2008-04-11 16:57:02 -04:00
|
|
|
unless defined? @originals then
|
|
|
|
@originals = {}
|
|
|
|
each do |full_name, spec|
|
|
|
|
@originals[spec.original_name] = spec
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
spec_names.find_all { |full_name|
|
2008-04-11 16:57:02 -04:00
|
|
|
@originals[full_name].nil?
|
2008-03-31 18:40:06 -04:00
|
|
|
}
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def remove_extra(spec_names)
|
|
|
|
dictionary = spec_names.inject({}) { |h, k| h[k] = true; h }
|
|
|
|
each do |name, spec|
|
2008-04-11 16:57:02 -04:00
|
|
|
remove_spec name unless dictionary.include? spec.original_name
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
|
|
|
# Unzip the given string.
|
|
|
|
|
|
|
|
def unzip(string)
|
|
|
|
require 'zlib'
|
2008-06-17 18:04:18 -04:00
|
|
|
Gem.inflate string
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Tries to fetch Marshal representation first, then YAML
|
|
|
|
|
|
|
|
def fetch_single_spec(source_uri, spec_name)
|
|
|
|
@fetch_error = nil
|
|
|
|
|
|
|
|
begin
|
|
|
|
marshal_uri = source_uri + "quick/Marshal.#{Gem.marshal_version}/#{spec_name}.gemspec.rz"
|
|
|
|
zipped = fetcher.fetch_path marshal_uri
|
|
|
|
return Marshal.load(unzip(zipped))
|
|
|
|
rescue => ex
|
|
|
|
@fetch_error = ex
|
|
|
|
|
|
|
|
if Gem.configuration.really_verbose then
|
|
|
|
say "unable to fetch marshal gemspec #{marshal_uri}: #{ex.class} - #{ex}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
begin
|
|
|
|
yaml_uri = source_uri + "quick/#{spec_name}.gemspec.rz"
|
|
|
|
zipped = fetcher.fetch_path yaml_uri
|
|
|
|
return YAML.load(unzip(zipped))
|
|
|
|
rescue => ex
|
|
|
|
@fetch_error = ex
|
|
|
|
if Gem.configuration.really_verbose then
|
|
|
|
say "unable to fetch YAML gemspec #{yaml_uri}: #{ex.class} - #{ex}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Update the cached source index with the missing names.
|
|
|
|
|
|
|
|
def update_with_missing(source_uri, missing_names)
|
|
|
|
progress = ui.progress_reporter(missing_names.size,
|
2007-11-10 02:48:56 -05:00
|
|
|
"Updating metadata for #{missing_names.size} gems from #{source_uri}")
|
2008-03-31 18:40:06 -04:00
|
|
|
missing_names.each do |spec_name|
|
|
|
|
gemspec = fetch_single_spec(source_uri, spec_name)
|
|
|
|
if gemspec.nil? then
|
|
|
|
ui.say "Failed to download spec #{spec_name} from #{source_uri}:\n" \
|
2007-11-10 02:48:56 -05:00
|
|
|
"\t#{@fetch_error.message}"
|
2008-03-31 18:40:06 -04:00
|
|
|
else
|
|
|
|
add_spec gemspec
|
|
|
|
progress.updated spec_name
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
@fetch_error = nil
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
progress.done
|
|
|
|
progress.count
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
# :stopdoc:
|
2008-03-31 18:40:06 -04:00
|
|
|
module Gem
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
2008-03-31 18:40:06 -04:00
|
|
|
# Cache is an alias for SourceIndex to allow older YAMLized source index
|
|
|
|
# objects to load properly.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
Cache = SourceIndex
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
# :startdoc:
|
2007-11-10 02:48:56 -05:00
|
|
|
|