2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/indexer'
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2007-11-10 02:48:56 -05:00
|
|
|
# Construct the master Gem index file.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
class Gem::Indexer::MasterIndexBuilder < Gem::Indexer::AbstractIndexBuilder
|
|
|
|
|
|
|
|
def start_index
|
|
|
|
super
|
|
|
|
@index = Gem::SourceIndex.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_index
|
|
|
|
super
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2007-11-20 00:56:43 -05:00
|
|
|
@file.puts "--- !ruby/object:#{@index.class}"
|
|
|
|
@file.puts "gems:"
|
|
|
|
|
|
|
|
gems = @index.sort_by { |name, gemspec| gemspec.sort_obj }
|
|
|
|
gems.each do |name, gemspec|
|
|
|
|
yaml = gemspec.to_yaml.gsub(/^/, ' ')
|
|
|
|
yaml = yaml.sub(/\A ---/, '') # there's a needed extra ' ' here
|
|
|
|
@file.print " #{gemspec.original_name}:"
|
|
|
|
@file.puts yaml
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup
|
|
|
|
super
|
|
|
|
|
|
|
|
index_file_name = File.join @directory, @filename
|
|
|
|
|
|
|
|
compress index_file_name, "Z"
|
2008-03-31 18:40:06 -04:00
|
|
|
paranoid index_file_name, "#{index_file_name}.Z"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
@files << "#{@filename}.Z"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def add(spec)
|
|
|
|
@index.add_spec(spec)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def paranoid(path, compressed_path)
|
|
|
|
data = Gem.read_binary path
|
|
|
|
compressed_data = Gem.read_binary compressed_path
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
if data != unzip(compressed_data) then
|
2008-03-31 18:40:06 -04:00
|
|
|
raise "Compressed file #{compressed_path} does not match uncompressed file #{path}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|