# File lib/rubygems/indexer.rb, line 54
  def build_index
    @master_index.build do
      @quick_index.build do
        @marshal_index.build do
          @latest_index.build do
            progress = ui.progress_reporter gem_file_list.size,
                                          "Generating index for #{gem_file_list.size} gems in #{@dest_directory}",
                                          "Loaded all gems"

                                          gem_file_list.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

                unless gemfile =~ /\/#{Regexp.escape spec.original_name}.*\.gem\z/i then
                  alert_warning "Skipping misnamed gem: #{gemfile} => #{spec.full_name} (#{spec.original_name})"
                  next
                end

                abbreviate spec
                sanitize spec

                @master_index.add spec
                @quick_index.add spec
                @marshal_index.add spec
                @latest_index.add spec

                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
                                          end

            progress.done

            say "Generating master indexes (this may take a while)"
          end
        end
      end
    end
  end