diff options
64 files changed, 758 insertions, 239 deletions
@@ -1,3 +1,7 @@ Thu Apr 22 16:43:31 2010 Nobuyoshi Nakada <[email protected]> * parse.y (warn_balanced): removed false warning. @@ -5,6 +5,8 @@ # See LICENSE.txt for permissions. #++ require 'rubygems/defaults' require 'thread' require 'etc' @@ -98,7 +100,7 @@ require 'etc' # -The RubyGems Team module Gem - RubyGemsVersion = VERSION = '1.3.6' ## # Raised when RubyGems is unable to load or activate a gem. Contains the @@ -127,9 +129,9 @@ module Gem :bindir => RbConfig::CONFIG["bindir"], :datadir => RbConfig::CONFIG["datadir"], :libdir => RbConfig::CONFIG["libdir"], - :rubylibprefix => RbConfig::CONFIG["rubylibprefix"], :ruby_install_name => RbConfig::CONFIG["ruby_install_name"], :ruby_version => RbConfig::CONFIG["ruby_version"], :sitedir => RbConfig::CONFIG["sitedir"], :sitelibdir => RbConfig::CONFIG["sitelibdir"], :vendordir => RbConfig::CONFIG["vendordir"] , @@ -144,7 +146,7 @@ module Gem # :stopdoc: MUTEX = Mutex.new - RubyGemsPackageVersion = RubyGemsVersion # :startdoc: ## @@ -310,8 +312,8 @@ module Gem ## # Find the full path to the executable for gem +name+. If the +exec_name+ # is not given, the gem's default_executable is chosen, otherwise the - # specified executable's path is returned. +version_requirements+ allows you - # to specify specific gem versions. def self.bin_path(name, exec_name = nil, *version_requirements) version_requirements = Gem::Requirement.default if @@ -568,9 +570,13 @@ module Gem ## # The index to insert activated gem paths into the $LOAD_PATH. def self.load_path_insert_index - $LOAD_PATH.index {|path| path.instance_variable_defined?(:@gem_prelude_index)} end ## @@ -667,7 +673,7 @@ module Gem def self.prefix dir = File.dirname File.expand_path(__FILE__) - prefix = File.dirname(dir) if prefix == File.expand_path(ConfigMap[:sitelibdir]) or prefix == File.expand_path(ConfigMap[:libdir]) or @@ -942,6 +948,28 @@ module Gem @@win_platform end class << self ## @@ -991,8 +1019,8 @@ module Gem end module Kernel - # defined in gem_prelude.rb - undef gem ## # Use Kernel#gem to activate a specific version of +gem_name+. @@ -1051,12 +1079,18 @@ require 'rubygems/platform' require 'rubygems/builder' # HACK: Needed for rake's package task. begin require 'rubygems/defaults/operating_system' rescue LoadError end if defined?(RUBY_ENGINE) then begin require "rubygems/defaults/#{RUBY_ENGINE}" rescue LoadError end @@ -1064,21 +1098,15 @@ end require 'rubygems/config_file' -Gem.clear_paths - -plugins = Gem.find_files 'rubygems_plugin' - -plugins.each do |plugin| - # Skip older versions of the GemCutter plugin: Its commands are in - # RubyGems proper now. - next if plugin =~ /gemcutter-0\.[0-3]/ - begin - load plugin - rescue => e - warn "error loading #{plugin.inspect}: #{e.message} (#{e.class})" - end -end @@ -4,6 +4,8 @@ # See LICENSE.txt for permissions. #++ ## # The Builder class processes RubyGem specification files # to produce a .gem file. @@ -146,6 +146,18 @@ class Gem::Command end ## # Get all gem names from the command line. def get_all_gem_names @@ -75,10 +75,10 @@ class Gem::CommandManager end ## - # Register the command object. - def register_command(command_obj) - @commands[command_obj] = false end ## @@ -123,7 +123,7 @@ class Gem::CommandManager say Gem::Command::HELP terminate_interaction(0) when '-v', '--version' - say Gem::RubyGemsVersion terminate_interaction(0) when /^-/ alert_error "Invalid option: #{args[0]}. See 'gem --help'." @@ -161,15 +161,19 @@ class Gem::CommandManager retried = false begin - commands.const_get(const_name) rescue NameError - if retried then - raise - else - retried = true require "rubygems/commands/#{command_name}_command" - retry end end.new end @@ -7,7 +7,7 @@ class Gem::Commands::ContentsCommand < Gem::Command def initialize super 'contents', 'Display the contents of the installed gems', - :specdirs => [], :lib_only => false add_version_option @@ -159,7 +159,9 @@ class Gem::Commands::DependencyCommand < Gem::Command response end - # Returns list of [specification, dep] that are satisfied by spec. def find_reverse_dependencies(spec) result = [] @@ -69,7 +69,7 @@ lib/rubygems/defaults/operating_system.rb when /^packageversion/ then out << Gem::RubyGemsPackageVersion when /^version/ then - out << Gem::RubyGemsVersion when /^gemdir/, /^gemhome/, /^home/, /^GEM_HOME/ then out << Gem.dir when /^gempath/, /^path/, /^GEM_PATH/ then @@ -79,7 +79,7 @@ lib/rubygems/defaults/operating_system.rb when nil then out = "RubyGems Environment:\n" - out << " - RUBYGEMS VERSION: #{Gem::RubyGemsVersion}\n" out << " - RUBY VERSION: #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}" out << " level #{RUBY_LEVEL}" if defined? RUBY_LEVEL @@ -109,6 +109,7 @@ lib/rubygems/defaults/operating_system.rb out << " - GEM CONFIGURATION:\n" Gem.configuration.each do |name, value| out << " - #{name.inspect} => #{value.inspect}\n" end @@ -34,7 +34,7 @@ class Gem::Commands::FetchCommand < Gem::Command def execute version = options[:version] || Gem::Requirement.default - all = Gem::Requirement.default gem_names = get_all_gem_names @@ -42,13 +42,17 @@ class Gem::Commands::FetchCommand < Gem::Command dep = Gem::Dependency.new gem_name, version dep.prerelease = options[:prerelease] - specs_and_sources = Gem::SpecFetcher.fetcher.fetch(dep, false, true, dep.prerelease?) spec, source_uri = specs_and_sources.sort_by { |s,| s.version }.last if spec.nil? then - alert_error "Could not find #{gem_name} in any repository" next end @@ -127,7 +127,8 @@ to write the specification by hand. For example: alert_error "Error installing #{gem_name}:\n\t#{e.message}" exit_code |= 1 rescue Gem::GemNotFoundException => e - alert_error e.message exit_code |= 2 end end @@ -21,7 +21,7 @@ class Gem::Commands::QueryCommand < Gem::Command options[:installed] = value end - add_version_option add_option('-n', '--name-matches REGEXP', 'Name of gem(s) to query on matches the', @@ -185,8 +185,21 @@ class Gem::Commands::QueryCommand < Gem::Command entry = gem_name.dup if options[:versions] then - versions = matching_tuples.map { |(name, version,_),_| version }.uniq - entry << " (#{versions.join ', '})" end if options[:details] then @@ -5,7 +5,7 @@ class Gem::Commands::ServerCommand < Gem::Command def initialize super 'server', 'Documentation and gem repository HTTP server', - :port => 8808, :gemdir => Gem.dir, :daemon => false OptionParser.accept :Port do |port| if port =~ /\A\d+\z/ then @@ -29,8 +29,9 @@ class Gem::Commands::ServerCommand < Gem::Command end add_option '-d', '--dir=GEMDIR', - 'directory from which to serve gems' do |gemdir, options| - options[:gemdir] = File.expand_path gemdir end add_option '--[no-]daemon', 'run as a daemon' do |daemon, options| @@ -69,6 +70,7 @@ You can set up a shortcut to gem server documentation using the URL: end def execute Gem::Server.run options end @@ -231,7 +231,7 @@ TEXT def install_rdoc gem_doc_dir = File.join Gem.dir, 'doc' - rubygems_name = "rubygems-#{Gem::RubyGemsVersion}" rubygems_doc_dir = File.join gem_doc_dir, rubygems_name if File.writable? gem_doc_dir and @@ -12,7 +12,8 @@ class Gem::Commands::UnpackCommand < Gem::Command :version => Gem::Requirement.default, :target => Dir.pwd - add_option('--target=DIR', 'target directory for unpacking') do |value, options| options[:target] = value end @@ -31,6 +32,16 @@ class Gem::Commands::UnpackCommand < Gem::Command "#{program_name} GEMNAME" end #-- # TODO: allow, e.g., 'gem unpack rake-0.3.1'. Find a general solution for # this, so that it works for uninstall as well. (And check other commands @@ -38,11 +49,12 @@ class Gem::Commands::UnpackCommand < Gem::Command def execute get_all_gem_names.each do |name| - path = get_path name, options[:version] if path then - basename = File.basename(path, '.gem') - target_dir = File.expand_path File.join(options[:target], basename) FileUtils.mkdir_p target_dir Gem::Installer.new(path, :unpack => true).unpack target_dir say "Unpacked gem: '#{target_dir}'" @@ -52,14 +64,15 @@ class Gem::Commands::UnpackCommand < Gem::Command end end # Return the full path to the cached gem file matching the given # name and version requirement. Returns 'nil' if no match. # # Example: # - # get_path('rake', '> 0.4') # -> '/usr/lib/ruby/gems/1.8/cache/rake-0.4.2.gem' - # get_path('rake', '< 0.1') # -> nil - # get_path('rak') # -> nil (exact name required) #-- # TODO: This should be refactored so that it's a general service. I don't # think any of our existing classes are the right place though. Just maybe @@ -67,30 +80,29 @@ class Gem::Commands::UnpackCommand < Gem::Command # # TODO: It just uses Gem.dir for now. What's an easy way to get the list of # source directories? - def get_path(gemname, version_req) - return gemname if gemname =~ /\.gem$/i - specs = Gem::source_index.find_name gemname, version_req selected = specs.sort_by { |s| s.version }.last - return nil if selected.nil? - # We expect to find (basename).gem in the 'cache' directory. - # Furthermore, the name match must be exact (ignoring case). - if gemname =~ /^#{selected.name}$/i - filename = selected.file_name - path = nil - Gem.path.find do |gem_dir| - path = File.join gem_dir, 'cache', filename - File.exist? path - end - path - else - nil end end end @@ -56,7 +56,7 @@ class Gem::Commands::UpdateCommand < Gem::Command rubygems_update = Gem::Specification.new rubygems_update.name = 'rubygems-update' - rubygems_update.version = Gem::Version.new Gem::RubyGemsVersion hig['rubygems-update'] = rubygems_update options[:user_install] = false @@ -33,15 +33,14 @@ module Gem # Path for gems in the user's home directory def self.user_dir - File.join(Gem.user_home, '.gem', ruby_engine, - ConfigMap[:ruby_version]) end ## # Default gem load path def self.default_path - if File.exist?(Gem.user_home) [user_dir, default_dir] else [default_dir] @@ -69,9 +69,6 @@ class Gem::Dependency end ## - # What does this dependency require? - - ## # A dependency's hash is the XOR of the hashes of +name+, +type+, # and +requirement+. @@ -106,6 +103,9 @@ class Gem::Dependency end end def requirement return @requirement if defined?(@requirement) and @requirement @@ -160,7 +160,16 @@ class Gem::Dependency __requirement end - alias_method :version_requirement, :version_requirements def == other # :nodoc: Gem::Dependency === other && @@ -188,9 +197,12 @@ class Gem::Dependency end pattern = name - pattern = /\A#{Regexp.escape pattern}\Z/ unless Regexp === pattern - return false unless pattern =~ other.name reqs = other.requirement.requirements @@ -202,5 +214,19 @@ class Gem::Dependency requirement.satisfied_by? version end end @@ -69,6 +69,10 @@ class Gem::DependencyInstaller @install_dir = options[:install_dir] || Gem.dir @cache_dir = options[:cache_dir] || @install_dir end ## @@ -78,6 +82,8 @@ class Gem::DependencyInstaller # local gems preferred over remote gems. def find_gems_with_sources(dep) gems_and_sources = [] if @domain == :both or @domain == :local then @@ -99,7 +105,7 @@ class Gem::DependencyInstaller (requirements.length > 1 or (requirements.first != ">=" and requirements.first != ">")) - found = Gem::SpecFetcher.fetcher.fetch dep, all, true, dep.prerelease? gems_and_sources.push(*found) @@ -204,8 +210,9 @@ class Gem::DependencyInstaller end if spec_and_source.nil? then - raise Gem::GemNotFoundException, - "could not find gem #{gem_name} locally or in a repository" end @specs_and_sources = [spec_and_source] @@ -179,7 +179,10 @@ class Gem::DocManager r = RDoc::RDoc.new old_pwd = Dir.pwd - Dir.chdir(@spec.full_gem_path) begin r.document args rescue Errno::EACCES => e @@ -193,7 +196,7 @@ class Gem::DocManager Gem.configuration.backtrace ui.errs.puts "(continuing with the rest of the installation)" ensure - Dir.chdir(old_pwd) end end @@ -0,0 +1,35 @@ @@ -37,7 +37,16 @@ class Gem::FormatException < Gem::Exception attr_accessor :file_path end -class Gem::GemNotFoundException < Gem::Exception; end class Gem::InstallError < Gem::Exception; end @@ -320,7 +320,7 @@ class Gem::Indexer <title>#{rss_title}</title> <link>http://#{rss_host}</link> <description>Recently released gems from http://#{rss_host}</description> - <generator>RubyGems v#{Gem::RubyGemsVersion}</generator> <docs>http://cyber.law.harvard.edu/rss/rss.html</docs> HEADER @@ -133,7 +133,8 @@ class Gem::Installer end FileUtils.mkdir_p @gem_home - raise Gem::FilePermissionError, @gem_home unless File.writable? @gem_home @spec = @format.spec @@ -165,7 +166,7 @@ class Gem::Installer end if rrgv = @spec.required_rubygems_version then - unless rrgv.satisfied_by? Gem::Version.new(Gem::RubyGemsVersion) then raise Gem::InstallError, "#{@spec.name} requires RubyGems version #{rrgv}. " + "Try 'gem update --system' to update RubyGems itself." @@ -270,7 +271,7 @@ class Gem::Installer ## # Creates windows .bat files for easy running of commands - def generate_windows_script(bindir, filename) if Gem.win_platform? then script_name = filename + ".bat" script_path = File.join bindir, File.basename(script_name) @@ -295,7 +296,7 @@ class Gem::Installer @spec.executables.each do |filename| filename.untaint - bin_path = File.expand_path("#{@spec.bindir}/#{filename}", @gem_dir) mode = File.stat(bin_path).mode | 0111 File.chmod mode, bin_path @@ -329,7 +330,7 @@ class Gem::Installer say bin_script_path if Gem.configuration.really_verbose - generate_windows_script bindir, filename #else # FileUtils.rm_f bin_script_path # FileUtils.cp exec_path, bin_script_path, @@ -1,8 +1,8 @@ -# -*- coding: iso-8859-1 -*- -#++ -# Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier -# See LICENSE.txt for additional licensing information. #-- require 'fileutils' require 'find' @@ -13,8 +13,10 @@ require 'zlib' require 'rubygems/security' require 'rubygems/specification' # Wrapper for FileUtils meant to provide logging and additional operations if # needed. class Gem::FileOperations def initialize(logger = nil) @@ -1,8 +1,8 @@ -# -*- coding: iso-8859-1 -*- -#++ -# Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier -# See LICENSE.txt for additional licensing information. #-- module Gem::Package::FSyncDir @@ -1,8 +1,8 @@ -# -*- coding: iso-8859-1 -*- -#++ -# Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier -# See LICENSE.txt for additional licensing information. #-- ## #-- @@ -1,8 +1,8 @@ -# -*- coding: iso-8859-1 -*- -#++ -# Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier -# See LICENSE.txt for additional licensing information. #-- ## # TarOutput is a wrapper to TarWriter that builds gem-format tar file. @@ -1,8 +1,8 @@ -# -*- coding: iso-8859-1 -*- -#++ -# Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier -# See LICENSE.txt for additional licensing information. #-- ## # TarReader reads tar files and allows iteration over their items @@ -1,8 +1,8 @@ -# -*- coding: iso-8859-1 -*- -#++ -# Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier -# See LICENSE.txt for additional licensing information. #-- ## # Allows writing of tar files @@ -102,6 +102,7 @@ class Gem::PackageTask < Rake::PackageTask gem_file = gem_spec.file_name gem_path = File.join package_dir, gem_file desc "Build the gem file #{gem_file}" task :gem => [gem_path] @@ -109,7 +110,7 @@ class Gem::PackageTask < Rake::PackageTask trace = Rake.application.options.trace Gem.configuration.verbose = trace - file gem_path => [package_dir] + @gem_spec.files do when_writing "Creating #{gem_spec.file_name}" do Gem::Builder.new(gem_spec).build verbose trace do @@ -70,6 +70,8 @@ class Gem::Platform when /hpux(\d+)/ then [ 'hpux', $1 ] when /^java$/, /^jruby$/ then [ 'java', nil ] when /^java([\d.]*)/ then [ 'java', $1 ] when /linux/ then [ 'linux', $1 ] when /mingw32/ then [ 'mingw32', nil ] when /(mswin\d+)(\_(\d+))?/ then @@ -148,6 +150,7 @@ class Gem::Platform when /^i686-darwin(\d)/ then ['x86', 'darwin', $1 ] when /^i\d86-linux/ then ['x86', 'linux', nil ] when 'java', 'jruby' then [nil, 'java', nil ] when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2 ] when 'powerpc-darwin' then ['powerpc', 'darwin', nil ] when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1 ] @@ -88,7 +88,9 @@ class Gem::RemoteFetcher # Always escape URI's to deal with potential spaces and such unless URI::Generic === source_uri - source_uri = URI.parse(URI.escape(source_uri)) end scheme = source_uri.scheme @@ -252,6 +254,8 @@ class Gem::RemoteFetcher connection.start unless connection.started? connection end ## @@ -309,7 +313,7 @@ class Gem::RemoteFetcher request.basic_auth uri.user, uri.password end - ua = "RubyGems/#{Gem::RubyGemsVersion} #{Gem::Platform.local}" ua << " Ruby/#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}" ua << " level #{RUBY_LEVEL}" if defined? RUBY_LEVEL ua << ")" @@ -351,7 +355,9 @@ class Gem::RemoteFetcher # HACK work around EOFError bug in Net::HTTP # NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible # to install gems. - rescue EOFError, Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE requests = @requests[connection.object_id] say "connection reset after #{requests} requests, retrying" if Gem.configuration.really_verbose @@ -93,9 +93,14 @@ class Gem::Requirement requirements.uniq! requirements << ">= 0" if requirements.empty? @requirements = requirements.map! { |r| self.class.parse r } end def as_list # :nodoc: requirements.map { |op, version| "#{op} #{version}" } end @@ -33,6 +33,8 @@ require 'rubygems/doc_manager' class Gem::Server include ERB::Util include Gem::UserInteraction @@ -430,29 +432,36 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } options[:addresses]).run end - def initialize(gem_dir, port, daemon, addresses = nil) Socket.do_not_reverse_lookup = true - @gem_dir = gem_dir @port = port @daemon = daemon @addresses = addresses logger = WEBrick::Log.new nil, WEBrick::BasicLog::FATAL @server = WEBrick::HTTPServer.new :DoNotListen => true, :Logger => logger - @spec_dir = File.join @gem_dir, 'specifications' - unless File.directory? @spec_dir then - raise ArgumentError, "#{@gem_dir} does not appear to be a gem repository" end - @source_index = Gem::SourceIndex.from_gems_in @spec_dir end def Marshal(req, res) @source_index.refresh! - res['date'] = File.stat(@spec_dir).mtime index = Marshal.dump @source_index @@ -471,12 +480,18 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } res.body << index end def latest_specs(req, res) @source_index.refresh! res['content-type'] = 'application/x-gzip' - res['date'] = File.stat(@spec_dir).mtime specs = @source_index.latest_specs.sort.map do |spec| platform = spec.original_platform @@ -535,7 +550,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } @source_index.refresh! res['content-type'] = 'text/plain' - res['date'] = File.stat(@spec_dir).mtime case req.request_uri.path when '/quick/index' then @@ -586,7 +601,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } def root(req, res) @source_index.refresh! - res['date'] = File.stat(@spec_dir).mtime raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." unless req.path == '/' @@ -630,16 +645,16 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } specs << { "authors" => "Chad Fowler, Rich Kilmer, Jim Weirich, Eric Hodel and others", "dependencies" => [], - "doc_path" => "/doc_root/rubygems-#{Gem::RubyGemsVersion}/rdoc/index.html", "executables" => [{"executable" => 'gem', "is_last" => true}], "only_one_executable" => true, - "full_name" => "rubygems-#{Gem::RubyGemsVersion}", "has_deps" => false, "homepage" => "http://docs.rubygems.org/", "name" => 'rubygems', "rdoc_installed" => true, "summary" => "RubyGems itself", - "version" => Gem::RubyGemsVersion, } specs = specs.sort_by { |spec| [spec["name"].downcase, spec["version"]] } @@ -718,7 +733,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } # documentation - just put it underneath the main doc folder. def show_rdoc_for_pattern(pattern, res) - found_gems = Dir.glob("#{@gem_dir}/doc/#{pattern}").select {|path| File.exist? File.join(path, 'rdoc/index.html') } case found_gems.length @@ -771,7 +786,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } @server.mount_proc("/gem-server-rdoc-style.css") do |req, res| res['content-type'] = 'text/css' - res['date'] = File.stat(@spec_dir).mtime res.body << RDOC_CSS end @@ -782,7 +797,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } paths = { "/gems" => "/cache/", "/doc_root" => "/doc/" } paths.each do |mount_point, mount_dir| @server.mount(mount_point, WEBrick::HTTPServlet::FileHandler, - File.join(@gem_dir, mount_dir), true) end trap("INT") { @server.shutdown; exit! } @@ -794,7 +809,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } def specs(req, res) @source_index.refresh! - res['date'] = File.stat(@spec_dir).mtime specs = @source_index.sort.map do |_, spec| platform = spec.original_platform @@ -821,7 +836,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } def yaml(req, res) @source_index.refresh! - res['date'] = File.stat(@spec_dir).mtime index = @source_index.to_yaml @@ -85,10 +85,10 @@ class Gem::SourceIndex def load_specification(file_name) return nil unless file_name and File.exist? file_name - spec_code = if !defined?(Encoding) then - File.read file_name - else File.read file_name, :encoding => 'UTF-8' end.untaint begin @@ -285,17 +285,19 @@ class Gem::SourceInfoCache cache_data.map do |source_uri, sic_entry| next unless Gem.sources.include? source_uri # TODO - Remove this gunk after 2008/11 - unless pattern.kind_of?(Gem::Dependency) - pattern = Gem::Dependency.new(pattern, Gem::Requirement.default) end sic_entry.source_index.search pattern, platform_only end.flatten.compact end # Searches all source indexes for +pattern+. If +only_platform+ is true, # only gems matching Gem.platforms will be selected. Returns an Array of # pairs containing the Gem::Specification found and the source_uri it was # found at. def search_with_source(pattern, only_platform = false, all = false) read_all_cache_data if all @@ -306,7 +308,7 @@ class Gem::SourceInfoCache # TODO - Remove this gunk after 2008/11 unless pattern.kind_of?(Gem::Dependency) - pattern = Gem::Dependency.new(pattern, Gem::Requirement.default) end sic_entry.source_index.search(pattern, only_platform).each do |spec| @@ -3,6 +3,7 @@ require 'fileutils' require 'rubygems/remote_fetcher' require 'rubygems/user_interaction' ## # SpecFetcher handles metadata updates from remote gem repositories. @@ -65,22 +66,28 @@ class Gem::SpecFetcher # false, all platforms are returned. If +prerelease+ is true, # prerelease versions are included. - def fetch(dependency, all = false, matching_platform = true, prerelease = false) - specs_and_sources = find_matching dependency, all, matching_platform, prerelease - specs_and_sources.map do |spec_tuple, source_uri| [fetch_spec(spec_tuple, URI.parse(source_uri)), source_uri] end rescue Gem::RemoteFetcher::FetchError => e raise unless warn_legacy e do require 'rubygems/source_info_cache' - return Gem::SourceInfoCache.search_with_source(dependency, - matching_platform, all) end end def fetch_spec(spec, source_uri) spec = spec - [nil, 'ruby', ''] spec_file_name = "#{spec.join '-'}.gemspec" @@ -117,16 +124,27 @@ class Gem::SpecFetcher # matching released versions are returned. If +matching_platform+ # is false, gems for all platforms are returned. - def find_matching(dependency, all = false, matching_platform = true, prerelease = false) found = {} list(all, prerelease).each do |source_uri, specs| found[source_uri] = specs.select do |spec_name, version, spec_platform| - dependency =~ Gem::Dependency.new(spec_name, version) and - (not matching_platform or Gem::Platform.match(spec_platform)) end end specs_and_sources = [] found.each do |source_uri, specs| @@ -134,7 +152,11 @@ class Gem::SpecFetcher specs_and_sources.push(*specs.map { |spec| [spec, uri_str] }) end - specs_and_sources end ## @@ -504,8 +504,8 @@ class Gem::Specification gemspec = nil raise "NESTED Specification.load calls not allowed!" if @@gather @@gather = proc { |gs| gemspec = gs } - data = File.read(filename) - eval(data) gemspec ensure @@gather = nil @@ -524,7 +524,7 @@ class Gem::Specification # Sets the rubygems_version to the current RubyGems version def mark_version - @rubygems_version = Gem::RubyGemsVersion end ## @@ -677,33 +677,43 @@ class Gem::Specification } end - def to_yaml(opts = {}) # :nodoc: mark_version attributes = @@attributes.map { |name,| name.to_s }.sort attributes = attributes - %w[name version platform] yaml = YAML.quick_emit object_id, opts do |out| out.map taguri, to_yaml_style do |map| - map.add 'name', @name - map.add 'version', @version - platform = case @original_platform - when nil, '' then - 'ruby' - when String then - @original_platform - else - @original_platform.to_s - end - map.add 'platform', platform - - attributes.each do |name| - map.add name, instance_variable_get("@#{name}") - end end end end def yaml_initialize(tag, vals) # :nodoc: vals.each do |ivar, val| instance_variable_set "@#{ivar}", val @@ -759,7 +769,7 @@ class Gem::Specification result << " s.specification_version = #{specification_version}" result << nil - result << " if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then" unless dependencies.empty? then dependencies.each do |dep| @@ -804,9 +814,9 @@ class Gem::Specification extend Gem::UserInteraction normalize - if rubygems_version != Gem::RubyGemsVersion then raise Gem::InvalidSpecificationException, - "expected RubyGems version #{Gem::RubyGemsVersion}, was #{rubygems_version}" end @@required_attributes.each do |symbol| @@ -1052,7 +1062,7 @@ class Gem::Specification # # Do not set this, it is set automatically when the gem is packaged. - required_attribute :rubygems_version, Gem::RubyGemsVersion ## # :attr_accessor: specification_version @@ -1481,14 +1491,12 @@ class Gem::Specification end overwrite_accessor :files do - result = [] - result.push(*@files) if defined?(@files) - result.push(*@test_files) if defined?(@test_files) - result.push(*(add_bindir(@executables))) - result.push(*@extra_rdoc_files) if defined?(@extra_rdoc_files) - result.push(*@extensions) if defined?(@extensions) - result.uniq.compact end - end - @@ -10,11 +10,10 @@ require 'digest' require 'rubygems/format' require 'rubygems/installer' -# Load test-unit 2.x if it's a gem begin - Gem.activate('test-unit') rescue Gem::LoadError - # Ignore - use the test-unit library that's part of the standard library end ## @@ -212,7 +212,7 @@ class Gem::Version end def hash # :nodoc: - segments.hash end def inspect # :nodoc: @@ -234,6 +234,7 @@ class Gem::Version def marshal_load array initialize array[0] end ## # A version is considered a prerelease if it contains a letter. @@ -244,6 +245,7 @@ class Gem::Version def pretty_print q # :nodoc: q.text "Gem::Version.new(#{version.inspect})" end ## # The release for this version (e.g. 1.2.0.a -> 1.2.0). # Non-prerelease versions return themselves. @@ -8,13 +8,17 @@ else require 'rubygems' end require 'fileutils' -require 'minitest/unit' require 'tmpdir' require 'uri' require 'rubygems/package' require 'rubygems/test_utilities' require 'pp' require 'yaml' begin gem 'rdoc' @@ -66,10 +70,10 @@ class RubyGemTestCase < MiniTest::Unit::TestCase Gem.ensure_gem_subdirectories @gemhome - if ruby = ENV['RUBY'] - Gem.class_eval {ruby, @ruby = @ruby, ruby} - @orig_ruby = ruby - end Gem.ensure_gem_subdirectories @gemhome @@ -131,7 +135,6 @@ class RubyGemTestCase < MiniTest::Unit::TestCase Gem.pre_uninstall do |uninstaller| @pre_uninstall_hook_arg = uninstaller end - end def teardown @@ -150,9 +153,7 @@ class RubyGemTestCase < MiniTest::Unit::TestCase Gem.clear_paths - if ruby = @orig_ruby - Gem.class_eval {@ruby = ruby} - end if @orig_ENV_HOME then ENV['HOME'] = @orig_ENV_HOME @@ -585,5 +586,3 @@ Also, a list: end -MiniTest::Unit.autorun - @@ -0,0 +1,2 @@ @@ -0,0 +1 @@ @@ -0,0 +1,2 @@ @@ -0,0 +1,5 @@ @@ -1,5 +1,10 @@ require 'rubygems/command_manager' class Gem::Commands::InterruptCommand < Gem::Command def initialize @@ -16,6 +16,8 @@ class TestGem < RubyGemTestCase else %r|/[Rr]uby/[Gg]ems/[0-9.]+| end end def test_self_all_load_paths @@ -258,8 +260,8 @@ class TestGem < RubyGemTestCase def test_self_find_files discover_path = File.join 'lib', 'foo', 'discover.rb' - cwd = File.expand_path('..', __FILE__) - $LOAD_PATH.unshift(cwd.dup) foo1 = quick_gem 'foo', '1' do |s| s.files << discover_path @@ -290,7 +292,7 @@ class TestGem < RubyGemTestCase assert_equal expected, Gem.find_files('foo/discover') ensure - assert_equal(cwd, $LOAD_PATH.shift) end def test_self_latest_load_paths @@ -617,6 +619,38 @@ class TestGem < RubyGemTestCase ENV['USERPATH'] = orig_user_path end if '1.9' > RUBY_VERSION def util_ensure_gem_dirs Gem.ensure_gem_subdirectories @gemhome @additional.each do |dir| @@ -665,5 +699,10 @@ class TestGem < RubyGemTestCase defined?(@RUBY_REVISION) end end @@ -10,6 +10,8 @@ class TestGemCommandManager < RubyGemTestCase end def test_run_interrupt use_ui @ui do assert_raises MockGemUi::TermError do @command_manager.run 'interrupt' @@ -19,6 +21,18 @@ class TestGemCommandManager < RubyGemTestCase end end def test_process_args_bad_arg use_ui @ui do assert_raises(MockGemUi::TermError) { @@ -139,13 +139,15 @@ Rakefile end def test_handle_options - assert_equal false, @cmd.options[:lib_only] - assert_equal [], @cmd.options[:specdirs] - assert_equal nil, @cmd.options[:version] - @cmd.send :handle_options, %w[-l -s foo --version 0.0.2] - assert_equal true, @cmd.options[:lib_only] assert_equal %w[foo], @cmd.options[:specdirs] assert_equal Gem::Requirement.new('0.0.2'), @cmd.options[:version] end @@ -12,6 +12,7 @@ class TestGemCommandsEnvironmentCommand < RubyGemTestCase def test_execute orig_sources = Gem.sources.dup Gem.sources.replace %w[http://gems.example.com] @cmd.send :handle_options, %w[] @@ -32,6 +33,7 @@ class TestGemCommandsEnvironmentCommand < RubyGemTestCase assert_match %r|GEM PATHS:|, @ui.output assert_match %r|- #{Regexp.escape @gemhome}|, @ui.output assert_match %r|GEM CONFIGURATION:|, @ui.output assert_match %r|:verbose => |, @ui.output assert_match %r|REMOTE SOURCES:|, @ui.output assert_equal '', @ui.error @@ -125,7 +127,7 @@ class TestGemCommandsEnvironmentCommand < RubyGemTestCase @cmd.execute end - assert_equal "#{Gem::RubyGemsVersion}\n", @ui.output assert_equal '', @ui.error end @@ -27,7 +27,7 @@ class TestGemCommandsFetchCommand < RubyGemTestCase end assert File.exist?(File.join(@tempdir, @a2.file_name)), - "#{@a2.full_name} fetched" end def test_execute_prerelease @@ -52,5 +52,25 @@ class TestGemCommandsFetchCommand < RubyGemTestCase "#{@a2_pre.full_name} not fetched" end end @@ -145,8 +145,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase end # HACK no repository was checked - assert_equal "ERROR: could not find gem no_such_gem locally or in a repository\n", - @ui.error end def test_execute_no_gem @@ -170,8 +169,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase assert_equal 2, e.exit_code end - assert_equal "ERROR: could not find gem nonexistent locally or in a repository\n", - @ui.error end def test_execute_prerelease @@ -29,7 +29,34 @@ class TestGemCommandsQueryCommand < RubyGemTestCase *** REMOTE GEMS *** a (2) -pl (1) EOF assert_equal expected, @ui.output @@ -51,7 +78,7 @@ pl (1) *** REMOTE GEMS *** a (2, 1) -pl (1) EOF assert_equal expected, @ui.output @@ -73,7 +100,7 @@ pl (1) *** REMOTE GEMS *** a (3.a, 2, 1) -pl (1) EOF assert_equal expected, @ui.output @@ -311,7 +338,7 @@ a (3.a, 2, 1) a_evil (9) b (2) c (1.2) -pl (1) EOF assert_equal expected, @ui.output @@ -348,7 +375,7 @@ pl expected = <<-EOF a (2) -pl (1) EOF assert_equal expected, @ui.output @@ -388,7 +415,7 @@ a (3.a, 2, 1) a_evil (9) b (2) c (1.2) -pl (1) EOF assert_equal expected, @ui.output @@ -13,16 +13,23 @@ class TestGemCommandsServerCommand < RubyGemTestCase @cmd.send :handle_options, %w[-p 8808 --no-daemon] assert_equal false, @cmd.options[:daemon] - assert_equal @gemhome, @cmd.options[:gemdir] assert_equal 8808, @cmd.options[:port] @cmd.send :handle_options, %w[-p 9999 -d /nonexistent --daemon] assert_equal true, @cmd.options[:daemon] - assert_equal File.expand_path('/nonexistent'), @cmd.options[:gemdir] assert_equal 9999, @cmd.options[:port] end def test_handle_options_port @cmd.send :handle_options, %w[-p 0] assert_equal 0, @cmd.options[:port] @@ -64,11 +64,10 @@ class TestGemCommandsUninstallCommand < GemInstallerTestCase util_setup_gem - use_ui @ui do - tmp_rake = ENV['rake'] - ENV['rake'] = @@rake - @installer.install - ENV['rake'] = tmp_rake end @cmd.options[:args] = ["pre"] @@ -22,8 +22,8 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase end end - assert File.exist?(File.join(@tempdir, 'a-3.a')), 'a should be installed' - assert File.exist?(File.join(@tempdir, 'b-2')), 'b should be installed' end def test_execute_gem_path @@ -49,6 +49,7 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase def test_execute_gem_path_missing util_make_gems Gem.clear_paths @@ -68,6 +69,49 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase assert_equal '', @ui.output end def test_execute_with_target_option util_make_gems @@ -46,6 +46,7 @@ class TestGemConfigFile < RubyGemTestCase fp.puts ":benchmark: true" fp.puts ":bulk_threshold: 10" fp.puts ":verbose: false" fp.puts ":sources:" fp.puts " - http://more-gems.example.com" fp.puts "install: --wrappers" @@ -61,6 +62,7 @@ class TestGemConfigFile < RubyGemTestCase assert_equal 10, @cfg.bulk_threshold assert_equal false, @cfg.verbose assert_equal false, @cfg.update_sources assert_equal %w[http://more-gems.example.com], Gem.sources assert_equal '--wrappers', @cfg[:install] assert_equal(['/usr/ruby/1.8/lib/ruby/gems/1.8', '/var/ruby/1.8/gem_home'], @@ -134,5 +134,16 @@ class TestGemDependency < RubyGemTestCase assert d.prerelease? end end @@ -1,5 +1,4 @@ require_relative 'gemutilities' - require 'rubygems/indexer' unless ''.respond_to? :to_xs then @@ -166,7 +165,7 @@ pl-1-i386-linux <title>ExampleForge gems</title> <link>http://example.com</link> <description>Recently released gems from http://example.com</description> - <generator>RubyGems v#{Gem::RubyGemsVersion}</generator> <docs>http://cyber.law.harvard.edu/rss/rss.html</docs> <item> <title>a-2</title> @@ -30,6 +30,9 @@ class TestGemPlatform < RubyGemTestCase 'hppa2.0w-hpux11.31' => ['hppa2.0w', 'hpux', '11'], 'java' => [nil, 'java', nil], 'jruby' => [nil, 'java', nil], 'powerpc-aix5.3.0.0' => ['powerpc', 'aix', '5'], 'powerpc-darwin7' => ['powerpc', 'darwin', '7'], 'powerpc-darwin8' => ['powerpc', 'darwin', '8'], @@ -227,6 +230,22 @@ class TestGemPlatform < RubyGemTestCase util_set_arch 'java' assert_match 'java', Gem::Platform.local assert_match 'jruby', Gem::Platform.local util_set_arch 'powerpc-darwin' assert_match 'powerpc-darwin', Gem::Platform.local @@ -20,6 +20,17 @@ class TestGemServer < RubyGemTestCase @res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0' end def test_Marshal data = StringIO.new "GET /Marshal.#{Gem.marshal_version} HTTP/1.0\r\n\r\n" @req.parse data @@ -85,7 +85,7 @@ Gem::Specification.new do |s| current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 2 - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then else end else @@ -115,6 +115,21 @@ class TestGemSpecFetcher < RubyGemTestCase assert_equal [[@pl1.full_name, @gem_repo]], spec_names end def test_fetch_spec spec_uri = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}" @fetcher.data["#{spec_uri}.rz"] = util_zip(Marshal.dump(@a1)) @@ -220,6 +235,33 @@ class TestGemSpecFetcher < RubyGemTestCase assert_equal [], specs end def test_find_all_platforms util_set_arch 'i386-freebsd6' @@ -473,6 +473,31 @@ end assert_equal expected, @a1.files.sort end def test_files_duplicate @a2.files = %w[a b c d b] @a2.extra_rdoc_files = %w[x y z x] @@ -748,14 +773,14 @@ Gem::Specification.new do |s| s.files = [\"lib/code.rb\"] s.homepage = %q{http://example.com} s.require_paths = [\"lib\"] - s.rubygems_version = %q{#{Gem::RubyGemsVersion}} s.summary = %q{this is a summary} if s.respond_to? :specification_version then current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION} - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q<b>, [\"= 1\"]) else s.add_dependency(%q<b>, [\"= 1\"]) @@ -802,7 +827,7 @@ Gem::Specification.new do |s| s.require_paths = [\"lib\"] s.requirements = [\"A working computer\"] s.rubyforge_project = %q{example} - s.rubygems_version = %q{#{Gem::RubyGemsVersion}} s.summary = %q{this is a summary} s.test_files = [\"test/suite.rb\"] @@ -810,7 +835,7 @@ Gem::Specification.new do |s| current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 3 - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q<rake>, [\"> 0.4\"]) s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"]) s.add_runtime_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"]) @@ -883,7 +908,7 @@ end yaml_str = @a1.to_yaml - same_spec = YAML.load(yaml_str) assert_equal Gem::Platform.new('powerpc-darwin7'), same_spec.platform assert_equal 'powerpc-darwin7.9.0', same_spec.original_platform @@ -1173,7 +1198,7 @@ end @a1.validate end - assert_equal "expected RubyGems version #{Gem::RubyGemsVersion}, was 3", e.message end @@ -1228,6 +1253,20 @@ end assert_equal Gem::Version.new('1'), @a1.version end def util_setup_validate Dir.chdir @tempdir do FileUtils.mkdir_p File.join('ext', 'a') |