summaryrefslogtreecommitdiff
path: root/lib/rubygems
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-22 08:24:42 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-22 08:24:42 +0000
commit372dcece3f69989d133f720468f1e24aa1133cda (patch)
treec173ca48a23ce18afa44feb15bf68d2dd14ac619 /lib/rubygems
parentd0e5a34ac7c34e70c145024a0fed8f6042814f29 (diff)
Update to RubyGems 1.3.7.pre.1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems')
-rw-r--r--lib/rubygems/builder.rb2
-rw-r--r--lib/rubygems/command.rb12
-rw-r--r--lib/rubygems/command_manager.rb24
-rw-r--r--lib/rubygems/commands/contents_command.rb2
-rw-r--r--lib/rubygems/commands/dependency_command.rb4
-rw-r--r--lib/rubygems/commands/environment_command.rb5
-rw-r--r--lib/rubygems/commands/fetch_command.rb10
-rw-r--r--lib/rubygems/commands/install_command.rb3
-rw-r--r--lib/rubygems/commands/query_command.rb19
-rw-r--r--lib/rubygems/commands/server_command.rb8
-rw-r--r--lib/rubygems/commands/setup_command.rb2
-rw-r--r--lib/rubygems/commands/unpack_command.rb58
-rw-r--r--lib/rubygems/commands/update_command.rb2
-rw-r--r--lib/rubygems/defaults.rb5
-rw-r--r--lib/rubygems/dependency.rb38
-rw-r--r--lib/rubygems/dependency_installer.rb13
-rw-r--r--lib/rubygems/doc_manager.rb7
-rw-r--r--lib/rubygems/errors.rb35
-rw-r--r--lib/rubygems/exceptions.rb11
-rw-r--r--lib/rubygems/indexer.rb2
-rw-r--r--lib/rubygems/installer.rb11
-rw-r--r--lib/rubygems/package.rb10
-rw-r--r--lib/rubygems/package/f_sync_dir.rb8
-rw-r--r--lib/rubygems/package/tar_header.rb8
-rw-r--r--lib/rubygems/package/tar_output.rb8
-rw-r--r--lib/rubygems/package/tar_reader.rb8
-rw-r--r--lib/rubygems/package/tar_writer.rb8
-rw-r--r--lib/rubygems/package_task.rb3
-rw-r--r--lib/rubygems/platform.rb3
-rw-r--r--lib/rubygems/remote_fetcher.rb12
-rw-r--r--lib/rubygems/requirement.rb5
-rw-r--r--lib/rubygems/server.rb51
-rw-r--r--lib/rubygems/source_index.rb6
-rw-r--r--lib/rubygems/source_info_cache.rb8
-rw-r--r--lib/rubygems/spec_fetcher.rb40
-rw-r--r--lib/rubygems/specification.rb72
-rw-r--r--lib/rubygems/validator.rb5
-rw-r--r--lib/rubygems/version.rb4
38 files changed, 365 insertions, 167 deletions
diff --git a/lib/rubygems/builder.rb b/lib/rubygems/builder.rb
index 9e7f262243..2bcd4b0bb3 100644
--- a/lib/rubygems/builder.rb
+++ b/lib/rubygems/builder.rb
@@ -4,6 +4,8 @@
# See LICENSE.txt for permissions.
#++
+require 'rubygems/user_interaction'
+
##
# The Builder class processes RubyGem specification files
# to produce a .gem file.
diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb
index 08692bdb70..3491937358 100644
--- a/lib/rubygems/command.rb
+++ b/lib/rubygems/command.rb
@@ -146,6 +146,18 @@ class Gem::Command
end
##
+ #
+ # Display to the user that a gem couldn't be found and reasons why
+ def show_lookup_failure(gem_name, version, errors=nil)
+ if errors and !errors.empty?
+ alert_error "Could not find a valid gem '#{gem_name}' (#{version}), here is why:"
+ errors.each { |x| say " #{x.wordy}" }
+ else
+ alert_error "Could not find a valid gem '#{gem_name}' (#{version}) in any repository"
+ end
+ end
+
+ ##
# Get all gem names from the command line.
def get_all_gem_names
diff --git a/lib/rubygems/command_manager.rb b/lib/rubygems/command_manager.rb
index 11344f1fb6..176e6a0bb4 100644
--- a/lib/rubygems/command_manager.rb
+++ b/lib/rubygems/command_manager.rb
@@ -75,10 +75,10 @@ class Gem::CommandManager
end
##
- # Register the command object.
+ # Register the Symbol +command+ as a gem command.
- def register_command(command_obj)
- @commands[command_obj] = false
+ def register_command(command)
+ @commands[command] = false
end
##
@@ -123,7 +123,7 @@ class Gem::CommandManager
say Gem::Command::HELP
terminate_interaction(0)
when '-v', '--version'
- say Gem::RubyGemsVersion
+ say Gem::VERSION
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)
+ commands.const_get const_name
rescue NameError
- if retried then
- raise
- else
- retried = true
+ raise if retried
+
+ retried = true
+ begin
require "rubygems/commands/#{command_name}_command"
- retry
+ rescue Exception => e
+ alert_error "Loading command: #{command_name} (#{e.class})\n #{e}"
+ ui.errs.puts "\t#{e.backtrace.join "\n\t"}" if
+ Gem.configuration.backtrace
end
+ retry
end.new
end
diff --git a/lib/rubygems/commands/contents_command.rb b/lib/rubygems/commands/contents_command.rb
index ce2c655240..a49918689c 100644
--- a/lib/rubygems/commands/contents_command.rb
+++ b/lib/rubygems/commands/contents_command.rb
@@ -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
+ :specdirs => [], :lib_only => false, :prefix => true
add_version_option
diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb
index 35702fbc6e..649e3c2d2d 100644
--- a/lib/rubygems/commands/dependency_command.rb
+++ b/lib/rubygems/commands/dependency_command.rb
@@ -159,7 +159,9 @@ class Gem::Commands::DependencyCommand < Gem::Command
response
end
- # Returns list of [specification, dep] that are satisfied by spec.
+ ##
+ # Returns an Array of [specification, dep] that are satisfied by +spec+.
+
def find_reverse_dependencies(spec)
result = []
diff --git a/lib/rubygems/commands/environment_command.rb b/lib/rubygems/commands/environment_command.rb
index f3550cae28..a8284b4bf6 100644
--- a/lib/rubygems/commands/environment_command.rb
+++ b/lib/rubygems/commands/environment_command.rb
@@ -69,7 +69,7 @@ lib/rubygems/defaults/operating_system.rb
when /^packageversion/ then
out << Gem::RubyGemsPackageVersion
when /^version/ then
- out << Gem::RubyGemsVersion
+ out << Gem::VERSION
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 << " - RUBYGEMS VERSION: #{Gem::VERSION}\n"
out << " - RUBY VERSION: #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}"
out << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
@@ -109,6 +109,7 @@ lib/rubygems/defaults/operating_system.rb
out << " - GEM CONFIGURATION:\n"
Gem.configuration.each do |name, value|
+ value = value.gsub(/./, '*') if name == 'gemcutter_key'
out << " - #{name.inspect} => #{value.inspect}\n"
end
diff --git a/lib/rubygems/commands/fetch_command.rb b/lib/rubygems/commands/fetch_command.rb
index b12e1b4a5d..43229c0512 100644
--- a/lib/rubygems/commands/fetch_command.rb
+++ b/lib/rubygems/commands/fetch_command.rb
@@ -34,7 +34,7 @@ class Gem::Commands::FetchCommand < Gem::Command
def execute
version = options[:version] || Gem::Requirement.default
- all = Gem::Requirement.default
+ all = Gem::Requirement.default != version
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,
+ specs_and_sources = Gem::SpecFetcher.fetcher.fetch(dep, all, true,
dep.prerelease?)
+ specs_and_sources, errors =
+ Gem::SpecFetcher.fetcher.fetch_with_errors(dep, all, 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"
+ show_lookup_failure gem_name, version, errors
next
end
diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb
index df6b3e5f2c..06a89eeb0a 100644
--- a/lib/rubygems/commands/install_command.rb
+++ b/lib/rubygems/commands/install_command.rb
@@ -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
+ show_lookup_failure e.name, e.version, e.errors
+
exit_code |= 2
end
end
diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb
index 7dd0a4a0d6..93b417015c 100644
--- a/lib/rubygems/commands/query_command.rb
+++ b/lib/rubygems/commands/query_command.rb
@@ -21,7 +21,7 @@ class Gem::Commands::QueryCommand < Gem::Command
options[:installed] = value
end
- add_version_option
+ add_version_option command, "for use with --installed"
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 ', '})"
+ list = if platforms.empty? or options[:details] then
+ matching_tuples.map { |(name, version,_),_| version }.uniq
+ else
+ platforms.sort.reverse.map do |version, pls|
+ if pls == [Gem::Platform::RUBY] then
+ version
+ else
+ ruby = pls.delete Gem::Platform::RUBY
+ platform_list = [ruby, *pls.sort].compact
+ "#{version} #{platform_list.join ' '}"
+ end
+ end
+ end.join ', '
+
+ entry << " (#{list})"
end
if options[:details] then
diff --git a/lib/rubygems/commands/server_command.rb b/lib/rubygems/commands/server_command.rb
index 6bc58367e9..4277787035 100644
--- a/lib/rubygems/commands/server_command.rb
+++ b/lib/rubygems/commands/server_command.rb
@@ -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
+ :port => 8808, :gemdir => [], :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
+ 'directories from which to serve gems',
+ 'multiple directories may be provided' 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
+ options[:gemdir] << Gem.dir if options[:gemdir].empty?
Gem::Server.run options
end
diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb
index f5f5185f86..4bc115eaf8 100644
--- a/lib/rubygems/commands/setup_command.rb
+++ b/lib/rubygems/commands/setup_command.rb
@@ -231,7 +231,7 @@ TEXT
def install_rdoc
gem_doc_dir = File.join Gem.dir, 'doc'
- rubygems_name = "rubygems-#{Gem::RubyGemsVersion}"
+ rubygems_name = "rubygems-#{Gem::VERSION}"
rubygems_doc_dir = File.join gem_doc_dir, rubygems_name
if File.writable? gem_doc_dir and
diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb
index 84a53b107a..8ed99babbe 100644
--- a/lib/rubygems/commands/unpack_command.rb
+++ b/lib/rubygems/commands/unpack_command.rb
@@ -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|
+ 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
+ def download dependency
+ found = Gem::SpecFetcher.fetcher.fetch dependency
+
+ return if found.empty?
+
+ spec, source_uri = found.first
+
+ Gem::RemoteFetcher.fetcher.download spec, source_uri
+ 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]
+ dependency = Gem::Dependency.new name, options[:version]
+ path = get_path dependency
if path then
- basename = File.basename(path, '.gem')
- target_dir = File.expand_path File.join(options[:target], basename)
+ basename = File.basename path, '.gem'
+ target_dir = File.expand_path basename, options[:target]
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)
+ # 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
+ def get_path dependency
+ return dependency.name if dependency.name =~ /\.gem$/i
+
+ specs = Gem.source_index.search dependency
selected = specs.sort_by { |s| s.version }.last
- return nil if selected.nil?
+ return download(dependency) 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
+ return unless dependency.name =~ /^#{selected.name}$/i
- Gem.path.find do |gem_dir|
- path = File.join gem_dir, 'cache', filename
- File.exist? path
- end
+ # We expect to find (basename).gem in the 'cache' directory. Furthermore,
+ # the name match must be exact (ignoring case).
+ filename = selected.file_name
+ path = nil
- path
- else
- nil
+ Gem.path.find do |gem_dir|
+ path = File.join gem_dir, 'cache', filename
+ File.exist? path
end
+
+ path
end
end
diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb
index 4b0439df1f..45d82e9385 100644
--- a/lib/rubygems/commands/update_command.rb
+++ b/lib/rubygems/commands/update_command.rb
@@ -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
+ rubygems_update.version = Gem::Version.new Gem::VERSION
hig['rubygems-update'] = rubygems_update
options[:user_install] = false
diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb
index c3c4737892..8950d0f73d 100644
--- a/lib/rubygems/defaults.rb
+++ b/lib/rubygems/defaults.rb
@@ -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])
+ 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)
+ if File.exist? Gem.user_home then
[user_dir, default_dir]
else
[default_dir]
diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb
index 351991067d..ec5d88b607 100644
--- a/lib/rubygems/dependency.rb
+++ b/lib/rubygems/dependency.rb
@@ -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
+ ##
+ # What does this dependency require?
+
def requirement
return @requirement if defined?(@requirement) and @requirement
@@ -160,7 +160,16 @@ class Gem::Dependency
__requirement
end
- alias_method :version_requirement, :version_requirements
+ alias version_requirement version_requirements # :nodoc:
+
+ def version_requirements= requirements # :nodoc:
+ warn "#{Gem.location_of_caller.join ':'}:Warning: " \
+ "Gem::Dependency#version_requirements= is deprecated " \
+ "and will be removed on or after August 2010. " \
+ "Use Gem::Dependency.new."
+
+ @requirement = Gem::Requirement.create requirements
+ end
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
+ if Regexp === pattern then
+ return false unless pattern =~ other.name
+ else
+ return false unless pattern == other.name
+ end
reqs = other.requirement.requirements
@@ -202,5 +214,19 @@ class Gem::Dependency
requirement.satisfied_by? version
end
+ def match?(spec_name, spec_version)
+ pattern = name
+
+ if Regexp === pattern
+ return false unless pattern =~ spec_name
+ else
+ return false unless pattern == spec_name
+ end
+
+ return true if requirement.none?
+
+ requirement.satisfied_by? Gem::Version.new(spec_version)
+ end
+
end
diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb
index 9d9aaba400..099d223295 100644
--- a/lib/rubygems/dependency_installer.rb
+++ b/lib/rubygems/dependency_installer.rb
@@ -69,6 +69,10 @@ class Gem::DependencyInstaller
@install_dir = options[:install_dir] || Gem.dir
@cache_dir = options[:cache_dir] || @install_dir
+
+ # Set with any errors that SpecFetcher finds while search through
+ # gemspecs for a dep
+ @errors = nil
end
##
@@ -78,6 +82,8 @@ class Gem::DependencyInstaller
# local gems preferred over remote gems.
def find_gems_with_sources(dep)
+ # Reset the errors
+ @errors = nil
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?
+ found, @errors = Gem::SpecFetcher.fetcher.fetch_with_errors 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"
+ raise Gem::GemNotFoundException.new(
+ "Could not find a valid gem '#{gem_name}' (#{version}) locally or in a repository",
+ gem_name, version, @errors)
end
@specs_and_sources = [spec_and_source]
diff --git a/lib/rubygems/doc_manager.rb b/lib/rubygems/doc_manager.rb
index a4976ae10a..d26d87a26f 100644
--- a/lib/rubygems/doc_manager.rb
+++ b/lib/rubygems/doc_manager.rb
@@ -179,7 +179,10 @@ class Gem::DocManager
r = RDoc::RDoc.new
old_pwd = Dir.pwd
- Dir.chdir(@spec.full_gem_path)
+ Dir.chdir @spec.full_gem_path
+
+ say "rdoc #{args.join ' '}" if Gem.configuration.really_verbose
+
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)
+ Dir.chdir old_pwd
end
end
diff --git a/lib/rubygems/errors.rb b/lib/rubygems/errors.rb
new file mode 100644
index 0000000000..950b34d744
--- /dev/null
+++ b/lib/rubygems/errors.rb
@@ -0,0 +1,35 @@
+class Gem::ErrorReason; end
+
+# Generated when trying to lookup a gem to indicate that the gem
+# was found, but that it isn't usable on the current platform.
+#
+# fetch and install read these and report them to the user to aid
+# in figuring out why a gem couldn't be installed.
+#
+class Gem::PlatformMismatch < Gem::ErrorReason
+
+ attr_reader :name
+ attr_reader :version
+ attr_reader :platforms
+
+ def initialize(name, version)
+ @name = name
+ @version = version
+ @platforms = []
+ end
+
+ def add_platform(platform)
+ @platforms << platform
+ end
+
+ def wordy
+ prefix = "Found #{@name} (#{@version})"
+
+ if @platforms.size == 1
+ "#{prefix}, but was for platform #{@platforms[0]}"
+ else
+ "#{prefix}, but was for platforms #{@platforms.join(' ,')}"
+ end
+ end
+
+end
diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb
index d6c60c7a02..55d67f9125 100644
--- a/lib/rubygems/exceptions.rb
+++ b/lib/rubygems/exceptions.rb
@@ -37,7 +37,16 @@ class Gem::FormatException < Gem::Exception
attr_accessor :file_path
end
-class Gem::GemNotFoundException < Gem::Exception; end
+class Gem::GemNotFoundException < Gem::Exception
+ def initialize(msg, name=nil, version=nil, errors=nil)
+ super msg
+ @name = name
+ @version = version
+ @errors = errors
+ end
+
+ attr_reader :name, :version, :errors
+end
class Gem::InstallError < Gem::Exception; end
diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb
index baa582447d..f85fe8467d 100644
--- a/lib/rubygems/indexer.rb
+++ b/lib/rubygems/indexer.rb
@@ -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>
+ <generator>RubyGems v#{Gem::VERSION}</generator>
<docs>http://cyber.law.harvard.edu/rss/rss.html</docs>
HEADER
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 50f8d20b33..f64696fe7a 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -133,7 +133,8 @@ class Gem::Installer
end
FileUtils.mkdir_p @gem_home
- raise Gem::FilePermissionError, @gem_home unless File.writable? @gem_home
+ raise Gem::FilePermissionError, @gem_home unless
+ options[:unpack] or 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
+ unless rrgv.satisfied_by? Gem::Version.new(Gem::VERSION) 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)
+ def generate_windows_script(filename, bindir)
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)
+ 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
+ generate_windows_script filename, bindir
#else
# FileUtils.rm_f bin_script_path
# FileUtils.cp exec_path, bin_script_path,
diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb
index 0fd64025ad..937da584cb 100644
--- a/lib/rubygems/package.rb
+++ b/lib/rubygems/package.rb
@@ -1,8 +1,8 @@
-# -*- coding: iso-8859-1 -*-
-#++
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
+# -*- coding: utf-8 -*-
#--
+# 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)
diff --git a/lib/rubygems/package/f_sync_dir.rb b/lib/rubygems/package/f_sync_dir.rb
index e15035ec37..f7eb7f3ce3 100644
--- a/lib/rubygems/package/f_sync_dir.rb
+++ b/lib/rubygems/package/f_sync_dir.rb
@@ -1,8 +1,8 @@
-# -*- coding: iso-8859-1 -*-
-#++
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
+# -*- coding: utf-8 -*-
#--
+# Copyright (C) 2004 Mauricio Julio Fernández Pradier
+# See LICENSE.txt for additional licensing information.
+#++
module Gem::Package::FSyncDir
diff --git a/lib/rubygems/package/tar_header.rb b/lib/rubygems/package/tar_header.rb
index 0689c319b9..4f923b9b5e 100644
--- a/lib/rubygems/package/tar_header.rb
+++ b/lib/rubygems/package/tar_header.rb
@@ -1,8 +1,8 @@
-# -*- coding: iso-8859-1 -*-
-#++
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
+# -*- coding: utf-8 -*-
#--
+# Copyright (C) 2004 Mauricio Julio Fernández Pradier
+# See LICENSE.txt for additional licensing information.
+#++
##
#--
diff --git a/lib/rubygems/package/tar_output.rb b/lib/rubygems/package/tar_output.rb
index 98fa8b8fe1..7d99a51127 100644
--- a/lib/rubygems/package/tar_output.rb
+++ b/lib/rubygems/package/tar_output.rb
@@ -1,8 +1,8 @@
-# -*- coding: iso-8859-1 -*-
-#++
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
+# -*- coding: utf-8 -*-
#--
+# 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.
diff --git a/lib/rubygems/package/tar_reader.rb b/lib/rubygems/package/tar_reader.rb
index b28714d124..e6a71d386c 100644
--- a/lib/rubygems/package/tar_reader.rb
+++ b/lib/rubygems/package/tar_reader.rb
@@ -1,8 +1,8 @@
-# -*- coding: iso-8859-1 -*-
-#++
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
+# -*- coding: utf-8 -*-
#--
+# 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
diff --git a/lib/rubygems/package/tar_writer.rb b/lib/rubygems/package/tar_writer.rb
index b5fc89e55e..d115162a76 100644
--- a/lib/rubygems/package/tar_writer.rb
+++ b/lib/rubygems/package/tar_writer.rb
@@ -1,8 +1,8 @@
-# -*- coding: iso-8859-1 -*-
-#++
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
+# -*- coding: utf-8 -*-
#--
+# Copyright (C) 2004 Mauricio Julio Fernández Pradier
+# See LICENSE.txt for additional licensing information.
+#++
##
# Allows writing of tar files
diff --git a/lib/rubygems/package_task.rb b/lib/rubygems/package_task.rb
index bb0a60464e..d43dfc8323 100644
--- a/lib/rubygems/package_task.rb
+++ b/lib/rubygems/package_task.rb
@@ -102,6 +102,7 @@ class Gem::PackageTask < Rake::PackageTask
gem_file = gem_spec.file_name
gem_path = File.join package_dir, gem_file
+ gem_dir = File.join package_dir, gem_spec.full_name
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
+ file gem_path => [package_dir, gem_dir] + @gem_spec.files do
when_writing "Creating #{gem_spec.file_name}" do
Gem::Builder.new(gem_spec).build
verbose trace do
diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb
index f5410cf4f7..c9a084707a 100644
--- a/lib/rubygems/platform.rb
+++ b/lib/rubygems/platform.rb
@@ -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 /^dotnet$/ then [ 'dotnet', nil ]
+ when /^dotnet([\d.]*)/ then [ 'dotnet', $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 /dotnet(\-(\d+\.\d+))?/ then ['universal','dotnet', $2 ]
when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2 ]
when 'powerpc-darwin' then ['powerpc', 'darwin', nil ]
when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1 ]
diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb
index dbd4cef816..07cd55b161 100644
--- a/lib/rubygems/remote_fetcher.rb
+++ b/lib/rubygems/remote_fetcher.rb
@@ -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))
+ source_uri = URI.parse(URI.const_defined?(:DEFAULT_PARSER) ?
+ URI::DEFAULT_PARSER.escape(source_uri) :
+ URI.escape(source_uri))
end
scheme = source_uri.scheme
@@ -252,6 +254,8 @@ class Gem::RemoteFetcher
connection.start unless connection.started?
connection
+ rescue Errno::EHOSTDOWN => e
+ raise FetchError.new(e.message, uri)
end
##
@@ -309,7 +313,7 @@ class Gem::RemoteFetcher
request.basic_auth uri.user, uri.password
end
- ua = "RubyGems/#{Gem::RubyGemsVersion} #{Gem::Platform.local}"
+ ua = "RubyGems/#{Gem::VERSION} #{Gem::Platform.local}"
ua << " Ruby/#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}"
ua << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
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
+ rescue EOFError, Timeout::Error,
+ Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE
+
requests = @requests[connection.object_id]
say "connection reset after #{requests} requests, retrying" if
Gem.configuration.really_verbose
diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb
index d9b510a76d..d51bf8ffa3 100644
--- a/lib/rubygems/requirement.rb
+++ b/lib/rubygems/requirement.rb
@@ -93,9 +93,14 @@ class Gem::Requirement
requirements.uniq!
requirements << ">= 0" if requirements.empty?
+ @none = (requirements == ">= 0")
@requirements = requirements.map! { |r| self.class.parse r }
end
+ def none?
+ @none ||= (to_s == ">= 0")
+ end
+
def as_list # :nodoc:
requirements.map { |op, version| "#{op} #{version}" }
end
diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb
index 24c9e044e1..c1a578920c 100644
--- a/lib/rubygems/server.rb
+++ b/lib/rubygems/server.rb
@@ -33,6 +33,8 @@ require 'rubygems/doc_manager'
class Gem::Server
+ attr_reader :spec_dirs
+
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)
+ ##
+ # Only the first directory in gem_dirs is used for serving gems
+
+ def initialize(gem_dirs, port, daemon, addresses = nil)
Socket.do_not_reverse_lookup = true
- @gem_dir = gem_dir
+ @gem_dirs = Array gem_dirs
@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'
+ @spec_dirs = @gem_dirs.map do |gem_dir|
+ 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"
+ unless File.directory? spec_dir then
+ raise ArgumentError, "#{gem_dir} does not appear to be a gem repository"
+ end
+
+ spec_dir
end
- @source_index = Gem::SourceIndex.from_gems_in @spec_dir
+ @source_index = Gem::SourceIndex.from_gems_in(*@spec_dirs)
end
def Marshal(req, res)
@source_index.refresh!
- res['date'] = File.stat(@spec_dir).mtime
+ add_date res
index = Marshal.dump @source_index
@@ -471,12 +480,18 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
res.body << index
end
+ def add_date res
+ res['date'] = @spec_dirs.map do |spec_dir|
+ File.stat(spec_dir).mtime
+ end.max
+ end
+
def latest_specs(req, res)
@source_index.refresh!
res['content-type'] = 'application/x-gzip'
- res['date'] = File.stat(@spec_dir).mtime
+ add_date res
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
+ add_date res
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
+ add_date res
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",
+ "doc_path" => "/doc_root/rubygems-#{Gem::VERSION}/rdoc/index.html",
"executables" => [{"executable" => 'gem', "is_last" => true}],
"only_one_executable" => true,
- "full_name" => "rubygems-#{Gem::RubyGemsVersion}",
+ "full_name" => "rubygems-#{Gem::VERSION}",
"has_deps" => false,
"homepage" => "http://docs.rubygems.org/",
"name" => 'rubygems',
"rdoc_installed" => true,
"summary" => "RubyGems itself",
- "version" => Gem::RubyGemsVersion,
+ "version" => Gem::VERSION,
}
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|
+ found_gems = Dir.glob("{#{@gem_dirs.join ','}}/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
+ add_date res
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)
+ File.join(@gem_dir.first, 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
+ add_date res
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
+ add_date res
index = @source_index.to_yaml
diff --git a/lib/rubygems/source_index.rb b/lib/rubygems/source_index.rb
index ac5d8add1e..f9b8ea0f81 100644
--- a/lib/rubygems/source_index.rb
+++ b/lib/rubygems/source_index.rb
@@ -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
+ spec_code = if defined? Encoding then
File.read file_name, :encoding => 'UTF-8'
+ else
+ File.read file_name
end.untaint
begin
diff --git a/lib/rubygems/source_info_cache.rb b/lib/rubygems/source_info_cache.rb
index 4289cdb52a..36615d82a1 100644
--- a/lib/rubygems/source_info_cache.rb
+++ b/lib/rubygems/source_info_cache.rb
@@ -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)
+ unless pattern.kind_of? Gem::Dependency then
+ 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)
+ pattern = Gem::Dependency.new(pattern, Gem::Requirement.default)
end
sic_entry.source_index.search(pattern, only_platform).each do |spec|
diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb
index 027970c342..dac35d85d0 100644
--- a/lib/rubygems/spec_fetcher.rb
+++ b/lib/rubygems/spec_fetcher.rb
@@ -3,6 +3,7 @@ require 'fileutils'
require 'rubygems/remote_fetcher'
require 'rubygems/user_interaction'
+require 'rubygems/errors'
##
# 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
+ def fetch_with_errors(dependency, all = false, matching_platform = true, prerelease = false)
+ specs_and_sources, errors = find_matching_with_errors dependency, all, matching_platform, prerelease
- specs_and_sources.map do |spec_tuple, source_uri|
+ ss = specs_and_sources.map do |spec_tuple, source_uri|
[fetch_spec(spec_tuple, URI.parse(source_uri)), source_uri]
end
+ return [ss, errors]
+
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)
+ return [Gem::SourceInfoCache.search_with_source(dependency,
+ matching_platform, all), nil]
end
end
+ def fetch(*args)
+ fetch_with_errors(*args).first
+ 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)
+ def find_matching_with_errors(dependency, all = false, matching_platform = true, prerelease = false)
found = {}
+ rejected_specs = {}
+
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))
+ if dependency.match?(spec_name, version)
+ if matching_platform and !Gem::Platform.match(spec_platform)
+ pm = (rejected_specs[dependency] ||= Gem::PlatformMismatch.new(spec_name, version))
+ pm.add_platform spec_platform
+ false
+ else
+ true
+ end
+ end
end
end
+ errors = rejected_specs.values
+
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
+ [specs_and_sources, errors]
+ end
+
+ def find_matching(*args)
+ find_matching_with_errors(*args).first
end
##
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 472d60817b..4c5a02d39c 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -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)
+ data = File.read filename
+ eval data, nil, filename
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
+ @rubygems_version = Gem::VERSION
end
##
@@ -677,33 +677,43 @@ class Gem::Specification
}
end
- def to_yaml(opts = {}) # :nodoc:
+ def encode_with coder # :nodoc:
mark_version
attributes = @@attributes.map { |name,| name.to_s }.sort
attributes = attributes - %w[name version platform]
+ coder.add 'name', @name
+ coder.add 'version', @version
+ platform = case @original_platform
+ when nil, '' then
+ 'ruby'
+ when String then
+ @original_platform
+ else
+ @original_platform.to_s
+ end
+ coder.add 'platform', platform
+
+ attributes.each do |name|
+ coder.add name, instance_variable_get("@#{name}")
+ end
+ end
+
+ def to_yaml(opts = {}) # :nodoc:
+ return super if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
+
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
+ encode_with map
end
end
end
+ def init_with coder # :nodoc:
+ yaml_initialize coder.tag, coder.map
+ 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"
+ result << " if Gem::Version.new(Gem::VERSION) >= 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
+ if rubygems_version != Gem::VERSION then
raise Gem::InvalidSpecificationException,
- "expected RubyGems version #{Gem::RubyGemsVersion}, was #{rubygems_version}"
+ "expected RubyGems version #{Gem::VERSION}, 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
+ required_attribute :rubygems_version, Gem::VERSION
##
# :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
+ # DO NOT CHANGE TO ||= ! This is not a normal accessor. (yes, it sucks)
+ @files = [@files,
+ @test_files,
+ add_bindir(@executables),
+ @extra_rdoc_files,
+ @extensions,
+ ].flatten.uniq.compact
end
-
end
-
diff --git a/lib/rubygems/validator.rb b/lib/rubygems/validator.rb
index 38ee62fd6d..16e12ef02e 100644
--- a/lib/rubygems/validator.rb
+++ b/lib/rubygems/validator.rb
@@ -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')
+ gem 'test-unit'
rescue Gem::LoadError
- # Ignore - use the test-unit library that's part of the standard library
+ # Ignore - use the test-unit library that's part of the standard library
end
##
diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb
index 77403ff32b..50d8204a5d 100644
--- a/lib/rubygems/version.rb
+++ b/lib/rubygems/version.rb
@@ -212,7 +212,7 @@ class Gem::Version
end
def hash # :nodoc:
- segments.hash
+ @hash ||= 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.