summaryrefslogtreecommitdiff
path: root/lib/rubygems/indexer.rb
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-01 03:45:05 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-01 03:45:05 +0000
commitd22130922e7842226d38d59680e4bbb48a28a5f0 (patch)
tree39594d3a14641dd5488a99a5e633239296fa5742 /lib/rubygems/indexer.rb
parent4752539e3f3e563d559732c52424206bd6f12dbd (diff)
Import rubygems 1.8.5 (released @ 137c80f)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/indexer.rb')
-rw-r--r--lib/rubygems/indexer.rb238
1 files changed, 116 insertions, 122 deletions
diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb
index 6e481c6790..c367532c43 100644
--- a/lib/rubygems/indexer.rb
+++ b/lib/rubygems/indexer.rb
@@ -79,7 +79,7 @@ class Gem::Indexer
@rss_gems_host = options[:rss_gems_host]
@dest_directory = directory
- @directory = File.join Dir.tmpdir, "gem_generate_index_#{$$}"
+ @directory = File.join(Dir.tmpdir, "gem_generate_index_#{$$}")
marshal_name = "Marshal.#{Gem.marshal_version}"
@@ -87,24 +87,23 @@ class Gem::Indexer
@marshal_index = File.join @directory, marshal_name
@quick_dir = File.join @directory, 'quick'
-
@quick_marshal_dir = File.join @quick_dir, marshal_name
+ @quick_marshal_dir_base = File.join "quick", marshal_name # FIX: UGH
@quick_index = File.join @quick_dir, 'index'
@latest_index = File.join @quick_dir, 'latest_index'
@specs_index = File.join @directory, "specs.#{Gem.marshal_version}"
- @latest_specs_index = File.join @directory,
- "latest_specs.#{Gem.marshal_version}"
- @prerelease_specs_index = File.join(@directory,
- "prerelease_specs.#{Gem.marshal_version}")
-
- @dest_specs_index = File.join @dest_directory,
- "specs.#{Gem.marshal_version}"
- @dest_latest_specs_index = File.join @dest_directory,
- "latest_specs.#{Gem.marshal_version}"
- @dest_prerelease_specs_index = File.join @dest_directory,
- "prerelease_specs.#{Gem.marshal_version}"
+ @latest_specs_index =
+ File.join(@directory, "latest_specs.#{Gem.marshal_version}")
+ @prerelease_specs_index =
+ File.join(@directory, "prerelease_specs.#{Gem.marshal_version}")
+ @dest_specs_index =
+ File.join(@dest_directory, "specs.#{Gem.marshal_version}")
+ @dest_latest_specs_index =
+ File.join(@dest_directory, "latest_specs.#{Gem.marshal_version}")
+ @dest_prerelease_specs_index =
+ File.join(@dest_directory, "prerelease_specs.#{Gem.marshal_version}")
@rss_index = File.join @directory, 'index.rss'
@@ -129,12 +128,16 @@ class Gem::Indexer
##
# Build various indicies
- def build_indicies(index)
+ def build_indicies
# Marshal gemspecs are used by both modern and legacy RubyGems
- build_marshal_gemspecs index
- build_legacy_indicies index if @build_legacy
- build_modern_indicies index if @build_modern
- build_rss index
+
+ Gem::Specification.dirs = []
+ Gem::Specification.add_specs(*map_gems_to_specs(gem_file_list))
+
+ build_marshal_gemspecs
+ build_legacy_indicies if @build_legacy
+ build_modern_indicies if @build_modern
+ build_rss
compress_indicies
end
@@ -142,7 +145,9 @@ class Gem::Indexer
##
# Builds indicies for RubyGems older than 1.2.x
- def build_legacy_indicies(index)
+ def build_legacy_indicies
+ index = collect_specs
+
say "Generating Marshal master index"
Gem.time 'Generated Marshal master index' do
@@ -158,16 +163,17 @@ class Gem::Indexer
##
# Builds Marshal quick index gemspecs.
- def build_marshal_gemspecs(index)
- progress = ui.progress_reporter index.size,
- "Generating Marshal quick index gemspecs for #{index.size} gems",
+ def build_marshal_gemspecs
+ count = Gem::Specification.count
+ progress = ui.progress_reporter count,
+ "Generating Marshal quick index gemspecs for #{count} gems",
"Complete"
files = []
Gem.time 'Generated Marshal quick index gemspecs' do
- index.gems.each do |original_name, spec|
- spec_file_name = "#{original_name}.gemspec.rz"
+ Gem::Specification.each do |spec|
+ spec_file_name = "#{spec.original_name}.gemspec.rz"
marshal_name = File.join @quick_marshal_dir, spec_file_name
marshal_zipped = Gem.deflate Marshal.dump(spec)
@@ -175,7 +181,7 @@ class Gem::Indexer
files << marshal_name
- progress.updated original_name
+ progress.updated spec.original_name
end
progress.done
@@ -195,8 +201,8 @@ class Gem::Indexer
Gem.time "Generated #{name} index" do
open(file, 'wb') do |io|
specs = index.map do |*spec|
- # We have to splat here because latest_specs is an array,
- # while the others are hashes. See the TODO in source_index.rb
+ # We have to splat here because latest_specs is an array, while the
+ # others are hashes.
spec = spec.flatten.last
platform = spec.original_platform
@@ -219,13 +225,15 @@ class Gem::Indexer
##
# Builds indicies for RubyGems 1.2 and newer. Handles full, latest, prerelease
- def build_modern_indicies(index)
- build_modern_index(index.released_specs.sort, @specs_index, 'specs')
- build_modern_index(index.latest_specs.sort,
- @latest_specs_index,
- 'latest specs')
- build_modern_index(index.prerelease_specs.sort,
- @prerelease_specs_index,
+ def build_modern_indicies
+ prerelease, released = Gem::Specification.partition { |s|
+ s.version.prerelease?
+ }
+ latest_specs = Gem::Specification.latest_specs
+
+ build_modern_index(released.sort, @specs_index, 'specs')
+ build_modern_index(latest_specs.sort, @latest_specs_index, 'latest specs')
+ build_modern_index(prerelease.sort, @prerelease_specs_index,
'prerelease specs')
@files += [@specs_index,
@@ -240,7 +248,7 @@ class Gem::Indexer
# Builds an RSS feed for past two days gem releases according to the gem's
# date.
- def build_rss(index)
+ def build_rss
if @rss_host.nil? or @rss_gems_host.nil? then
if Gem.configuration.really_verbose then
alert_warning "no --rss-host or --rss-gems-host, RSS generation disabled"
@@ -272,31 +280,18 @@ class Gem::Indexer
today = Gem::Specification::TODAY
yesterday = today - 86400
- index = index.select do |_, spec|
- spec_date = spec.date
-
- case spec_date
- when Date
- Time.parse(spec_date.to_s) >= yesterday
- when Time
- spec_date >= yesterday
- end
- end
-
- index = index.select do |_, spec|
+ index = Gem::Specification.select do |spec|
spec_date = spec.date
+ # TODO: remove this and make YAML based specs properly normalized
+ spec_date = Time.parse(spec_date.to_s) if Date === spec_date
- case spec_date
- when Date
- Time.parse(spec_date.to_s) <= today
- when Time
- spec_date <= today
- end
+ spec_date >= yesterday && spec_date <= today
end
- index.sort_by { |_, spec| [-spec.date.to_i, spec] }.each do |_, spec|
- gem_path = CGI.escapeHTML "http://#{@rss_gems_host}/gems/#{spec.file_name}"
- size = File.stat(spec.loaded_from).size rescue next
+ index.sort_by { |spec| [-spec.date.to_i, spec] }.each do |spec|
+ file_name = File.basename spec.cache_file
+ gem_path = CGI.escapeHTML "http://#{@rss_gems_host}/gems/#{file_name}"
+ size = File.stat(spec.loaded_from).size # rescue next
description = spec.description || spec.summary || ''
authors = Array spec.authors
@@ -347,54 +342,56 @@ class Gem::Indexer
@files << @rss_index
end
+ def map_gems_to_specs gems
+ gems.map { |gemfile|
+ if File.size(gemfile) == 0 then
+ alert_warning "Skipping zero-length gem: #{gemfile}"
+ next
+ end
+
+ begin
+ spec = Gem::Format.from_file_by_path(gemfile).spec
+ spec.loaded_from = gemfile
+
+ # HACK: fuck this shit - borks all tests that use pl1
+ # if File.basename(gemfile, ".gem") != spec.original_name then
+ # exp = spec.full_name
+ # exp << " (#{spec.original_name})" if
+ # spec.original_name != spec.full_name
+ # msg = "Skipping misnamed gem: #{gemfile} should be named #{exp}"
+ # alert_warning msg
+ # next
+ # end
+
+ abbreviate spec
+ sanitize spec
+
+ spec
+ rescue SignalException => e
+ alert_error "Received signal, exiting"
+ raise
+ rescue Exception => e
+ msg = ["Unable to process #{gemfile}",
+ "#{e.message} (#{e.class})",
+ "\t#{e.backtrace.join "\n\t"}"].join("\n")
+ alert_error msg
+ end
+ }.compact
+ end
+
##
# Collect specifications from .gem files from the gem directory.
def collect_specs(gems = gem_file_list)
- index = Gem::SourceIndex.new
-
- progress = ui.progress_reporter gems.size,
- "Loading #{gems.size} gems from #{@dest_directory}",
- "Loaded all gems"
+ Deprecate.skip_during do
+ index = Gem::SourceIndex.new
- Gem.time 'loaded' do
- gems.each do |gemfile|
- if File.size(gemfile.to_s) == 0 then
- alert_warning "Skipping zero-length gem: #{gemfile}"
- next
- end
-
- begin
- spec = Gem::Format.from_file_by_path(gemfile).spec
- spec.loaded_from = gemfile
-
- unless gemfile =~ /\/#{Regexp.escape spec.original_name}.*\.gem\z/i then
- expected_name = spec.full_name
- expected_name << " (#{spec.original_name})" if
- spec.original_name != spec.full_name
- alert_warning "Skipping misnamed gem: #{gemfile} should be named #{expected_name}"
- next
- end
-
- abbreviate spec
- sanitize spec
-
- index.add_spec spec, spec.original_name
-
- progress.updated spec.original_name
-
- rescue SignalException => e
- alert_error "Received signal, exiting"
- raise
- rescue Exception => e
- alert_error "Unable to process #{gemfile}\n#{e.message} (#{e.class})\n\t#{e.backtrace.join "\n\t"}"
- end
+ map_gems_to_specs(gems).each do |spec|
+ index.add_spec spec, spec.original_name
end
- progress.done
+ index
end
-
- index
end
##
@@ -454,7 +451,7 @@ class Gem::Indexer
# List of gem file names to index.
def gem_file_list
- Dir.glob(File.join(@dest_directory, "gems", "*.gem"))
+ Dir[File.join(@dest_directory, "gems", '*.gem')]
end
##
@@ -462,8 +459,7 @@ class Gem::Indexer
def generate_index
make_temp_directories
- index = collect_specs
- build_indicies index
+ build_indicies
install_indicies
rescue SignalException
ensure
@@ -487,24 +483,22 @@ class Gem::Indexer
say "Moving index into production dir #{@dest_directory}" if verbose
- files = @files.dup
+ files = @files
files.delete @quick_marshal_dir if files.include? @quick_dir
- if files.include? @quick_marshal_dir and
- not files.include? @quick_dir then
+ if files.include? @quick_marshal_dir and not files.include? @quick_dir then
files.delete @quick_marshal_dir
- quick_marshal_dir = @quick_marshal_dir.sub @directory, ''
- dst_name = File.join @dest_directory, quick_marshal_dir
+ dst_name = File.join(@dest_directory, @quick_marshal_dir_base)
FileUtils.mkdir_p File.dirname(dst_name), :verbose => verbose
FileUtils.rm_rf dst_name, :verbose => verbose
- FileUtils.mv @quick_marshal_dir, dst_name, :verbose => verbose,
- :force => true
+ FileUtils.mv(@quick_marshal_dir, dst_name,
+ :verbose => verbose, :force => true)
end
files = files.map do |path|
- path.sub @directory, ''
+ path.sub(/^#{Regexp.escape @directory}\/?/, '') # HACK?
end
files.each do |file|
@@ -512,8 +506,8 @@ class Gem::Indexer
dst_name = File.join @dest_directory, file
FileUtils.rm_rf dst_name, :verbose => verbose
- FileUtils.mv src_name, @dest_directory, :verbose => verbose,
- :force => true
+ FileUtils.mv(src_name, @dest_directory,
+ :verbose => verbose, :force => true)
end
end
@@ -544,10 +538,10 @@ class Gem::Indexer
# be replaced by their XML entity equivalent.
def sanitize(spec)
- spec.summary = sanitize_string(spec.summary)
- spec.description = sanitize_string(spec.description)
+ spec.summary = sanitize_string(spec.summary)
+ spec.description = sanitize_string(spec.description)
spec.post_install_message = sanitize_string(spec.post_install_message)
- spec.authors = spec.authors.collect { |a| sanitize_string(a) }
+ spec.authors = spec.authors.collect { |a| sanitize_string(a) }
spec
end
@@ -593,14 +587,16 @@ class Gem::Indexer
terminate_interaction 0
end
- index = collect_specs updated_gems
+ specs = map_gems_to_specs updated_gems
+ prerelease, released = specs.partition { |s| s.version.prerelease? }
- files = build_marshal_gemspecs index
+ files = build_marshal_gemspecs
Gem.time 'Updated indexes' do
- update_specs_index index.released_gems, @dest_specs_index, @specs_index
- update_specs_index index.released_gems, @dest_latest_specs_index, @latest_specs_index
- update_specs_index(index.prerelease_gems, @dest_prerelease_specs_index,
+ update_specs_index released, @dest_specs_index, @specs_index
+ update_specs_index released, @dest_latest_specs_index, @latest_specs_index
+ update_specs_index(prerelease,
+ @dest_prerelease_specs_index,
@prerelease_specs_index)
end
@@ -618,12 +614,12 @@ class Gem::Indexer
files << "#{@prerelease_specs_index}.gz"
files = files.map do |path|
- path.sub @directory, ''
+ path.sub(/^#{Regexp.escape @directory}\/?/, '') # HACK?
end
files.each do |file|
src_name = File.join @directory, file
- dst_name = File.join @dest_directory, File.dirname(file)
+ dst_name = File.join @dest_directory, file # REFACTOR: duped above
FileUtils.mv src_name, dst_name, :verbose => verbose,
:force => true
@@ -639,7 +635,7 @@ class Gem::Indexer
def update_specs_index(index, source, dest)
specs_index = Marshal.load Gem.read_binary(source)
- index.each do |_, spec|
+ index.each do |spec|
platform = spec.original_platform
platform = Gem::Platform::RUBY if platform.nil? or platform.empty?
specs_index << [spec.name, spec.version, platform]
@@ -651,6 +647,4 @@ class Gem::Indexer
Marshal.dump specs_index, io
end
end
-
end
-