* lib/rubygems: Import RubyGems 2.1.0 Release Candidate

* test/rubygems:  ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2013-08-26 20:24:51 +00:00
parent cddd93a575
commit e487a7f53c
49 changed files with 888 additions and 354 deletions

View file

@ -1,3 +1,8 @@
Tue Aug 27 05:24:34 2013 Eric Hodel <drbrain@segment7.net>
* lib/rubygems: Import RubyGems 2.1.0 Release Candidate
* test/rubygems: ditto.
Mon Aug 26 16:24:58 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Aug 26 16:24:58 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (parser_nextc): warn carriage return in middle of line. * parse.y (parser_nextc): warn carriage return in middle of line.

View file

@ -8,7 +8,7 @@
require 'rbconfig' require 'rbconfig'
module Gem module Gem
VERSION = '2.1.0.rc.1' VERSION = '2.1.0.rc.2'
end end
# Must be first since it unloads the prelude from 1.9.2 # Must be first since it unloads the prelude from 1.9.2
@ -36,9 +36,9 @@ require 'rubygems/errors'
# #
# Further RubyGems documentation can be found at: # Further RubyGems documentation can be found at:
# #
# * {RubyGems Guides}[http://guides.rubygems.org]
# * {RubyGems API}[http://rubygems.rubyforge.org/rdoc] (also available from # * {RubyGems API}[http://rubygems.rubyforge.org/rdoc] (also available from
# <tt>gem server</tt>) # <tt>gem server</tt>)
# * {RubyGems Bookshelf}[http://docs.rubygems.org]
# #
# == RubyGems Plugins # == RubyGems Plugins
# #
@ -1048,16 +1048,14 @@ module Gem
# #
def register_default_spec(spec) def register_default_spec(spec)
new_format, prefix_pattern = nil new_format = Gem.default_gems_use_full_paths? || spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }
spec.files.each do |file|
if new_format == nil
new_format = spec.require_paths.any? {|path| file.start_with? path}
if new_format
prefix_group = spec.require_paths.map {|f| f + "/"}.join("|") prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")
prefix_pattern = /^(#{prefix_group})/ prefix_pattern = /^(#{prefix_group})/
end end
spec.files.each do |file|
if new_format if new_format
file = file.sub(prefix_pattern, "") file = file.sub(prefix_pattern, "")
next unless $~ next unless $~

View file

@ -1,11 +1,109 @@
module Gem ##
# BasicSpecification is an abstract class which implements some common code used by # BasicSpecification is an abstract class which implements some common code
# both Specification and StubSpecification. # used by both Specification and StubSpecification.
class BasicSpecification
class Gem::BasicSpecification
##
# The path this gemspec was loaded from. This attribute is not persisted.
attr_reader :loaded_from
def self.default_specifications_dir def self.default_specifications_dir
File.join(Gem.default_dir, "specifications", "default") File.join(Gem.default_dir, "specifications", "default")
end end
##
# True when the gem has been activated
def activated?
raise NotImplementedError
end
##
# Returns the full path to the base gem directory.
#
# eg: /usr/local/lib/ruby/gems/1.8
def base_dir
return Gem.dir unless loaded_from
@base_dir ||= if default_gem? then
File.dirname File.dirname File.dirname loaded_from
else
File.dirname File.dirname loaded_from
end
end
##
# Return true if this spec can require +file+.
def contains_requirable_file? file
root = full_gem_path
suffixes = Gem.suffixes
require_paths.any? do |lib|
base = "#{root}/#{lib}/#{file}"
suffixes.any? { |suf| File.file? "#{base}#{suf}" }
end
end
def default_gem?
loaded_from &&
File.dirname(loaded_from) == self.class.default_specifications_dir
end
def find_full_gem_path # :nodoc:
# TODO: also, shouldn't it default to full_name if it hasn't been written?
path = File.expand_path File.join(gems_dir, full_name)
path.untaint
path if File.directory? path
end
private :find_full_gem_path
##
# The full path to the gem (install path + full name).
def full_gem_path
# TODO: This is a heavily used method by gems, so we'll need
# to aleast just alias it to #gem_dir rather than remove it.
@full_gem_path ||= find_full_gem_path
end
##
# Returns the full name (name-version) of this Gem. Platform information
# is included (name-version-platform) if it is specified and not the
# default Ruby platform.
def full_name
if platform == Gem::Platform::RUBY or platform.nil? then
"#{name}-#{version}".untaint
else
"#{name}-#{version}-#{platform}".untaint
end
end
##
# Returns the full path to the gems directory containing this spec's
# gem directory. eg: /usr/local/lib/ruby/1.8/gems
def gems_dir
# TODO: this logic seems terribly broken, but tests fail if just base_dir
@gems_dir ||= File.join(loaded_from && base_dir || Gem.dir, "gems")
end
##
# Set the path the Specification was loaded from. +path+ is converted to a
# String.
def loaded_from= path
@loaded_from = path && path.to_s
@full_gem_path = nil
@gems_dir = nil
@base_dir = nil
end
## ##
# Name of the gem # Name of the gem
@ -13,13 +111,6 @@ module Gem
raise NotImplementedError raise NotImplementedError
end end
##
# Version of the gem
def version
raise NotImplementedError
end
## ##
# Platform of the gem # Platform of the gem
@ -34,13 +125,6 @@ module Gem
raise NotImplementedError raise NotImplementedError
end end
##
# True when the gem has been activated
def activated?
raise NotImplementedError
end
## ##
# Return a Gem::Specification from this gem # Return a Gem::Specification from this gem
@ -49,91 +133,11 @@ module Gem
end end
## ##
# The filename of the gem specification # Version of the gem
attr_reader :filename
## def version
# Set the filename of the Specification was loaded from. +path+ is converted raise NotImplementedError
# to a String.
def filename= path
@filename = path && path.to_s
@full_gem_path = nil
@gems_dir = nil
@base_dir = nil
end end
##
# Return true if this spec can require +file+.
def contains_requirable_file? file
root = full_gem_path
suffixes = Gem.suffixes
require_paths.any? do |lib|
base = "#{root}/#{lib}/#{file}"
suffixes.any? { |suf| File.file? "#{base}#{suf}" }
end
end
##
# The full path to the gem (install path + full name).
def full_gem_path
# TODO: This is a heavily used method by gems, so we'll need
# to aleast just alias it to #gem_dir rather than remove it.
@full_gem_path ||= find_full_gem_path
end
# :nodoc:
def find_full_gem_path
# TODO: also, shouldn't it default to full_name if it hasn't been written?
path = File.expand_path File.join(gems_dir, full_name)
path.untaint
path if File.directory? path
end
private :find_full_gem_path
##
# Returns the full path to the gems directory containing this spec's
# gem directory. eg: /usr/local/lib/ruby/1.8/gems
def gems_dir
# TODO: this logic seems terribly broken, but tests fail if just base_dir
@gems_dir ||= File.join(filename && base_dir || Gem.dir, "gems")
end
##
# Returns the full path to the base gem directory.
#
# eg: /usr/local/lib/ruby/gems/1.8
def base_dir
return Gem.dir unless filename
@base_dir ||= if default_gem? then
File.dirname File.dirname File.dirname filename
else
File.dirname File.dirname filename
end
end
def default_gem?
filename &&
File.dirname(filename) == self.class.default_specifications_dir
end
##
# Returns the full name (name-version) of this Gem. Platform information
# is included (name-version-platform) if it is specified and not the
# default Ruby platform.
def full_name
if platform == Gem::Platform::RUBY or platform.nil? then
"#{name}-#{version}".untaint
else
"#{name}-#{version}-#{platform}".untaint
end
end
end
end end

View file

@ -15,6 +15,25 @@ class Gem::Commands::BuildCommand < Gem::Command
"GEMSPEC_FILE gemspec file name to build a gem for" "GEMSPEC_FILE gemspec file name to build a gem for"
end end
def description # :nodoc:
<<-EOF
The build command allows you to create a gem from a ruby gemspec.
The best way to build a gem is to use a Rakefile and the Gem::PackageTask
which ships with RubyGems.
The gemspec can either be created by hand or extracted from an existing gem
with gem spec:
$ gem unpack my_gem-1.0.gem
Unpacked gem: '.../my_gem-1.0'
$ gem spec my_gem-1.0.gem --ruby > my_gem-1.0/my_gem-1.0.gemspec
$ cd my_gem-1.0
[edit gem contents]
$ gem build my_gem-1.0.gemspec
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} GEMSPEC_FILE" "#{program_name} GEMSPEC_FILE"
end end

View file

@ -79,6 +79,13 @@ class Gem::Commands::CheckCommand < Gem::Command
'--gems --alien' '--gems --alien'
end end
def description # :nodoc:
<<-EOF
The check command can list and repair problems with installed gems and
specifications and will clean up gems that have been partially uninstalled.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} [OPTIONS] [GEMNAME ...]" "#{program_name} [OPTIONS] [GEMNAME ...]"
end end

View file

@ -6,7 +6,7 @@ class Gem::Commands::CleanupCommand < Gem::Command
def initialize def initialize
super 'cleanup', super 'cleanup',
'Clean up old versions of installed gems in the local repository', 'Clean up old versions of installed gems',
:force => false, :install_dir => Gem.dir :force => false, :install_dir => Gem.dir
add_option('-n', '-d', '--dryrun', add_option('-n', '-d', '--dryrun',
@ -33,11 +33,11 @@ class Gem::Commands::CleanupCommand < Gem::Command
def description # :nodoc: def description # :nodoc:
<<-EOF <<-EOF
The cleanup command removes old gems from GEM_HOME. If an older version is The cleanup command removes old versions of gems from GEM_HOME that are not
installed elsewhere in GEM_PATH the cleanup command won't touch it. required to meet a dependency. If a gem is installed elsewhere in GEM_PATH
the cleanup command won't delete it.
Older gems that are required to satisify the dependencies of gems If no gems are named all gems in GEM_HOME are cleaned.
are not removed.
EOF EOF
end end

View file

@ -45,6 +45,14 @@ class Gem::Commands::ContentsCommand < Gem::Command
"--no-lib-only --prefix" "--no-lib-only --prefix"
end end
def description # :nodoc:
<<-EOF
The contents command lists the files in an installed gem. The listing can
be given as full file names, file names without the installed directory
prefix or only the files that are requireable.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...]" "#{program_name} GEMNAME [GEMNAME ...]"
end end

View file

@ -38,6 +38,17 @@ class Gem::Commands::DependencyCommand < Gem::Command
"--local --version '#{Gem::Requirement.default}' --no-reverse-dependencies" "--local --version '#{Gem::Requirement.default}' --no-reverse-dependencies"
end end
def description # :nodoc:
<<-EOF
The dependency commands lists which other gems a given gem depends on. For
local gems only the reverse dependencies can be shown (which gems depend on
the named gem).
The dependency list can be displayed in a format suitable for piping for
use with other commands.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} GEMNAME" "#{program_name} GEMNAME"
end end

View file

@ -21,6 +21,9 @@ class Gem::Commands::EnvironmentCommand < Gem::Command
def description # :nodoc: def description # :nodoc:
<<-EOF <<-EOF
The environment command lets you query rubygems for its configuration for
use in shell scripts or as a debugging aid.
The RubyGems environment can be controlled through command line arguments, The RubyGems environment can be controlled through command line arguments,
gemrc files, environment variables and built-in defaults. gemrc files, environment variables and built-in defaults.

View file

@ -28,6 +28,16 @@ class Gem::Commands::FetchCommand < Gem::Command
"--version '#{Gem::Requirement.default}'" "--version '#{Gem::Requirement.default}'"
end end
def description # :nodoc:
<<-EOF
The fetch command fetches gem files that can be stored for later use or
unpacked to examine their contents.
See the build command help for an example of unpacking a gem, modifying it,
then repackaging it.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...]" "#{program_name} GEMNAME [GEMNAME ...]"
end end

View file

@ -8,7 +8,7 @@ require 'rubygems/commands/query_command'
class Gem::Commands::ListCommand < Gem::Commands::QueryCommand class Gem::Commands::ListCommand < Gem::Commands::QueryCommand
def initialize def initialize
super 'list', 'Display gems whose name starts with STRING' super 'list', 'Display local gems whose name starts with STRING'
remove_option('--name-matches') remove_option('--name-matches')
end end
@ -21,6 +21,17 @@ class Gem::Commands::ListCommand < Gem::Commands::QueryCommand
"--local --no-details" "--local --no-details"
end end
def description # :nodoc:
<<-EOF
The list command is used to view the gems you have installed locally.
The --details option displays additional details including the summary, the
homepage, the author, the locations of different versions of the gem.
To search for remote gems use the search command.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} [STRING]" "#{program_name} [STRING]"
end end

View file

@ -10,6 +10,12 @@ class Gem::Commands::MirrorCommand < Gem::Command
end end
end end
def description # :nodoc:
<<-EOF
The mirror command has been moved to the rubygems-mirror gem.
EOF
end
def execute def execute
alert_error "Install the rubygems-mirror gem for the mirror command" alert_error "Install the rubygems-mirror gem for the mirror command"
end end

View file

@ -15,6 +15,15 @@ class Gem::Commands::OutdatedCommand < Gem::Command
add_platform_option add_platform_option
end end
def description # :nodoc:
<<-EOF
The outdated command lists gems you way wish to upgrade to a newer version.
You can check for dependency mismatches using the dependency command and
update the gems with the update or install commands.
EOF
end
def execute def execute
Gem::Specification.outdated_and_latest_version.each do |spec, remote_version| Gem::Specification.outdated_and_latest_version.each do |spec, remote_version|
say "#{spec.name} (#{spec.version} < #{remote_version})" say "#{spec.name} (#{spec.version} < #{remote_version})"

View file

@ -7,7 +7,14 @@ class Gem::Commands::OwnerCommand < Gem::Command
include Gem::GemcutterUtilities include Gem::GemcutterUtilities
def description # :nodoc: def description # :nodoc:
'Manage gem owners on RubyGems.org.' <<-EOF
The owner command lets you add and remove owners of a gem on a push
server (the default is https://rubygems.org).
The owner of a gem has the permission to push new versions, yank existing
versions or edit the HTML page of the gem. Be careful of who you give push
permission to.
EOF
end end
def arguments # :nodoc: def arguments # :nodoc:
@ -19,7 +26,7 @@ class Gem::Commands::OwnerCommand < Gem::Command
end end
def initialize def initialize
super 'owner', description super 'owner', 'Manage gem owners of a gem on the push server'
add_proxy_option add_proxy_option
add_key_option add_key_option
defaults.merge! :add => [], :remove => [] defaults.merge! :add => [], :remove => []

View file

@ -21,7 +21,8 @@ class Gem::Commands::PristineCommand < Gem::Command
end end
add_option('--[no-]extensions', add_option('--[no-]extensions',
'Restore gems with extensions') do |value, options| 'Restore gems with extensions',
'in addition to regular gems') do |value, options|
options[:extensions] = value options[:extensions] = value
end end
@ -49,23 +50,23 @@ class Gem::Commands::PristineCommand < Gem::Command
def description # :nodoc: def description # :nodoc:
<<-EOF <<-EOF
The pristine command compares the installed gems with the contents of the The pristine command compares an installed gem with the contents of its
cached gem and restores any files that don't match the cached gem's copy. cached .gem file and restores any files that don't match the cached .gem's
copy.
If you have made modifications to your installed gems, the pristine command If you have made modifications to an installed gem, the pristine command
will revert them. After all the gem's files have been checked all bin stubs will revert them. All extensions are rebuilt and all bin stubs for the gem
for the gem are regenerated. are regenerated after checking for modifications.
If the cached gem cannot be found, you will need to use `gem install` to If the cached gem cannot be found it will be downloaded.
revert the gem.
If --no-extensions is provided pristine will not attempt to restore gems If --no-extensions is provided pristine will not attempt to restore a gem
with extensions. with an extension.
EOF EOF
end end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} [args]" "#{program_name} [GEMNAME ...]"
end end
def execute def execute

View file

@ -8,7 +8,13 @@ class Gem::Commands::PushCommand < Gem::Command
include Gem::GemcutterUtilities include Gem::GemcutterUtilities
def description # :nodoc: def description # :nodoc:
'Push a gem up to RubyGems.org' <<-EOF
The push command uploads a gem to the push server (the default is
https://rubygems.org) and adds it to the index.
The gem can be removed from the index (but only the index) using the yank
command. For further discussion see the help for the yank command.
EOF
end end
def arguments # :nodoc: def arguments # :nodoc:
@ -20,7 +26,7 @@ class Gem::Commands::PushCommand < Gem::Command
end end
def initialize def initialize
super 'push', description, :host => self.host super 'push', 'Push a gem up to the gem server', :host => self.host
add_proxy_option add_proxy_option
add_key_option add_key_option

View file

@ -61,6 +61,15 @@ class Gem::Commands::QueryCommand < Gem::Command
"--local --name-matches // --no-details --versions --no-installed" "--local --name-matches // --no-details --versions --no-installed"
end end
def description # :nodoc:
<<-EOF
The query command is the basis for the list and search commands.
You should really use the list and search commands instead. This command
is too hard to use.
EOF
end
def execute def execute
exit_code = 0 exit_code = 0

View file

@ -45,8 +45,12 @@ class Gem::Commands::RdocCommand < Gem::Command
def description # :nodoc: def description # :nodoc:
<<-DESC <<-DESC
The rdoc command builds RDoc and RI documentation for installed gems. Use The rdoc command builds documentation for installed gems. By default
--overwrite to force rebuilding of documentation. only documentation is built using rdoc, but additional types of
documentation may be built through rubygems plugins and the
Gem.post_installs hook.
Use --overwrite to force rebuilding of documentation.
DESC DESC
end end

View file

@ -4,7 +4,7 @@ require 'rubygems/commands/query_command'
class Gem::Commands::SearchCommand < Gem::Commands::QueryCommand class Gem::Commands::SearchCommand < Gem::Commands::QueryCommand
def initialize def initialize
super 'search', 'Display all gems whose name contains STRING' super 'search', 'Display remote gems whose name contains STRING'
remove_option '--name-matches' remove_option '--name-matches'
@ -19,6 +19,19 @@ class Gem::Commands::SearchCommand < Gem::Commands::QueryCommand
"--remote --no-details" "--remote --no-details"
end end
def description # :nodoc:
<<-EOF
The search command displays remote gems whose name contains the given
string.
The --details option displays additional details from the gem but will
take a little longer to complete as it must download the information
individually from the index.
To list local gems use the list command.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} [STRING]" "#{program_name} [STRING]"
end end

View file

@ -97,6 +97,53 @@ Do you want to add this insecure source?
'--list' '--list'
end end
def description # :nodoc:
<<-EOF
RubyGems fetches gems from the sources you have configured (stored in your
~/.gemrc).
The default source is https://rubygems.org, but you may have older sources
configured. This guide will help you update your sources or configure
yourself to use your own gem server.
Without any arguments the sources lists your currently configured sources:
$ gem sources
*** CURRENT SOURCES ***
https://rubygems.org
This may list multiple sources or non-rubygems sources. You probably
configured them before or have an old `~/.gemrc`. If you have sources you
do not recognize you should remove them.
RubyGems has been configured to serve gems via the following URLs through
its history:
* http://gems.rubyforge.org (RubyGems 1.3.6 and earlier)
* http://rubygems.org (RubyGems 1.3.7 through 1.8.25)
* https://rubygems.org (RubyGems 2.0.1 and newer)
Since all of these sources point to the same set of gems you only need one
of them in your list. https://rubygems.org is recommended as it brings the
protections of an SSL connection to gem downloads.
To add a source use the --add argument:
$ gem sources --add https://rubygems.org
https://rubygems.org added to sources
RubyGems will check to see if gems can be installed from the source given
before it is added.
To remove a source use the --remove argument:
$ gem sources --remove http://rubygems.org
http://rubygems.org removed from sources
EOF
end
def list # :nodoc: def list # :nodoc:
say "*** CURRENT SOURCES ***" say "*** CURRENT SOURCES ***"
say say

View file

@ -50,6 +50,22 @@ FIELD name of gemspec field to show
"--local --version '#{Gem::Requirement.default}' --yaml" "--local --version '#{Gem::Requirement.default}' --yaml"
end end
def description # :nodoc:
<<-EOF
The specification command allows you to extract the specification from
a gem for examination.
The specification can be output in YAML, ruby or Marshal formats.
Specific fields in the specification can be extracted in YAML format:
$ gem spec rake summary
--- Ruby based make-like utility.
...
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} [GEMFILE] [FIELD]" "#{program_name} [GEMFILE] [FIELD]"
end end

View file

@ -5,6 +5,16 @@ class Gem::Commands::StaleCommand < Gem::Command
super('stale', 'List gems along with access times') super('stale', 'List gems along with access times')
end end
def description # :nodoc:
<<-EOF
The stale command lists the latest access time for all the files in your
installed gems.
You can use this command to discover gems and gem versions you are no
longer using.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name}" "#{program_name}"
end end

View file

@ -88,6 +88,16 @@ class Gem::Commands::UninstallCommand < Gem::Command
"--user-install" "--user-install"
end end
def description # :nodoc:
<<-EOF
The uninstall command removes a previously installed gem.
RubyGems will ask for confirmation if you are attempting to uninstall a gem
that is a dependency of an existing gem. You can use the
--ignore-dependencies option to skip this check.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...]" "#{program_name} GEMNAME [GEMNAME ...]"
end end
@ -104,15 +114,18 @@ class Gem::Commands::UninstallCommand < Gem::Command
end end
def uninstall_all def uninstall_all
install_dir = options[:install_dir] _, specs = Gem::Specification.partition { |spec| spec.default_gem? }
dirs_to_be_emptied = Dir[File.join(install_dir, '*')] specs.each do |spec|
dirs_to_be_emptied.delete_if { |dir| dir.end_with? 'build_info' } options[:version] = spec.version
dirs_to_be_emptied.each do |dir| begin
FileUtils.rm_rf Dir[File.join(dir, '*')] Gem::Uninstaller.new(spec.name, options).uninstall
rescue Gem::InstallError
end end
alert("Successfully uninstalled all gems in #{install_dir}") end
alert "Uninstalled all gems in #{options[:install_dir]}"
end end
def uninstall_specific def uninstall_specific

View file

@ -34,6 +34,24 @@ class Gem::Commands::UnpackCommand < Gem::Command
"--version '#{Gem::Requirement.default}'" "--version '#{Gem::Requirement.default}'"
end end
def description
<<-EOF
The unpack command allows you to examine the contents of a gem or modify
them to help diagnose a bug.
You can add the contents of the unpacked gem to the load path using the
RUBYLIB environment variable or -I:
$ gem unpack my_gem
Unpacked gem: '.../my_gem-1.0'
[edit my_gem-1.0/lib/my_gem.rb]
$ ruby -Imy_gem-1.0/lib -S other_program
You can repackage an unpacked gem using the build command. See the build
command help for an example.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} GEMNAME" "#{program_name} GEMNAME"
end end

View file

@ -52,6 +52,15 @@ class Gem::Commands::UpdateCommand < Gem::Command
"--document --no-force --install-dir #{Gem.dir}" "--document --no-force --install-dir #{Gem.dir}"
end end
def description # :nodoc:
<<-EOF
The update command will update your gems to the latest version.
The update comamnd does not remove the previous version. Use the cleanup
command to remove old versions.
EOF
end
def usage # :nodoc: def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...]" "#{program_name} GEMNAME [GEMNAME ...]"
end end

View file

@ -23,6 +23,17 @@ class Gem::Commands::WhichCommand < Gem::Command
"--no-gems-first --no-all" "--no-gems-first --no-all"
end end
def description # :nodoc:
<<-EOF
The which command is like the shell which command and shows you where
the file you wish to require lives.
You can use the which command to help determine why you are requiring a
version you did not expect or to look at the content of a file you are
requiring to see why it does not behave as you expect.
EOF
end
def execute def execute
found = false found = false

View file

@ -9,7 +9,21 @@ class Gem::Commands::YankCommand < Gem::Command
include Gem::GemcutterUtilities include Gem::GemcutterUtilities
def description # :nodoc: def description # :nodoc:
'Remove a specific gem version release from RubyGems.org' <<-EOF
The yank command removes a gem you pushed to a server from the server's
index.
Note that if you push a gem to rubygems.org the yank command does not
prevent other people from downloading the gem via the download link.
Once you have pushed a gem several downloads will happen automatically
via the webhooks. If you accidentally pushed passwords or other sensitive
data you will need to change them immediately and yank your gem.
If you are yanking a gem due to intellectual property reasons contact
http://help.rubygems.org for permanant removal. Be sure to mention this
as the reason for the removal request.
EOF
end end
def arguments # :nodoc: def arguments # :nodoc:
@ -21,7 +35,7 @@ class Gem::Commands::YankCommand < Gem::Command
end end
def initialize def initialize
super 'yank', description super 'yank', 'Remove a pushed gem from the index'
add_version_option("remove") add_version_option("remove")
add_platform_option("remove") add_platform_option("remove")

View file

@ -8,6 +8,8 @@ require 'monitor'
module Kernel module Kernel
RUBYGEMS_ACTIVATION_MONITOR = Monitor.new # :nodoc:
if defined?(gem_original_require) then if defined?(gem_original_require) then
# Ruby ships with a custom_require, override its require # Ruby ships with a custom_require, override its require
remove_method :require remove_method :require
@ -33,10 +35,8 @@ module Kernel
# The normal <tt>require</tt> functionality of returning false if # The normal <tt>require</tt> functionality of returning false if
# that file has already been loaded is preserved. # that file has already been loaded is preserved.
ACTIVATION_MONITOR = Monitor.new
def require path def require path
ACTIVATION_MONITOR.enter RUBYGEMS_ACTIVATION_MONITOR.enter
spec = Gem.find_unresolved_default_spec(path) spec = Gem.find_unresolved_default_spec(path)
if spec if spec
@ -118,7 +118,7 @@ module Kernel
raise load_error raise load_error
ensure ensure
ACTIVATION_MONITOR.exit RUBYGEMS_ACTIVATION_MONITOR.exit
end end
private :require private :require

View file

@ -134,4 +134,11 @@ module Gem
def self.default_cert_path def self.default_cert_path
File.join Gem.user_home, ".gem", "gem-public_cert.pem" File.join Gem.user_home, ".gem", "gem-public_cert.pem"
end end
##
# Whether to expect full paths in default gems - true for non-MRI
# ruby implementations
def self.default_gems_use_full_paths?
ruby_engine != 'ruby'
end
end end

View file

@ -5,8 +5,7 @@ require 'rubygems/package'
require 'rubygems/installer' require 'rubygems/installer'
require 'rubygems/spec_fetcher' require 'rubygems/spec_fetcher'
require 'rubygems/user_interaction' require 'rubygems/user_interaction'
require 'rubygems/source/local' require 'rubygems/source'
require 'rubygems/source/specific_file'
require 'rubygems/available_set' require 'rubygems/available_set'
## ##
@ -251,7 +250,6 @@ class Gem::DependencyInstaller
def find_spec_by_name_and_version gem_name, def find_spec_by_name_and_version gem_name,
version = Gem::Requirement.default, version = Gem::Requirement.default,
prerelease = false prerelease = false
set = Gem::AvailableSet.new set = Gem::AvailableSet.new
if consider_local? if consider_local?
@ -269,7 +267,6 @@ class Gem::DependencyInstaller
if set.empty? if set.empty?
dep = Gem::Dependency.new gem_name, version dep = Gem::Dependency.new gem_name, version
# HACK Dependency objects should be immutable
dep.prerelease = true if prerelease dep.prerelease = true if prerelease
set = find_gems_with_sources(dep) set = find_gems_with_sources(dep)

View file

@ -96,12 +96,15 @@ class Gem::PackageTask < Rake::PackageTask
def define def define
super super
task :package => [:gem]
gem_file = File.basename gem_spec.cache_file gem_file = File.basename gem_spec.cache_file
gem_path = File.join package_dir, gem_file gem_path = File.join package_dir, gem_file
gem_dir = File.join package_dir, gem_spec.full_name gem_dir = File.join package_dir, gem_spec.full_name
task :package => [:gem]
directory package_dir
directory gem_dir
desc "Build the gem file #{gem_file}" desc "Build the gem file #{gem_file}"
task :gem => [gem_path] task :gem => [gem_path]

View file

@ -213,6 +213,9 @@ class Gem::Security::Policy
if @only_signed then if @only_signed then
raise Gem::Security::Exception, raise Gem::Security::Exception,
"unsigned gems are not allowed by the #{name} policy" "unsigned gems are not allowed by the #{name} policy"
elsif digests.empty? then
# lack of signatures is irrelevant if there is nothing to check
# against
else else
alert_warning "#{full_name} is not signed" alert_warning "#{full_name} is not signed"
end end
@ -246,6 +249,8 @@ class Gem::Security::Policy
if @only_trusted then if @only_trusted then
check_trust chain, digester, trust_dir check_trust chain, digester, trust_dir
elsif signatures.empty? and digests.empty? then
# trust is irrelevant if there's no signatures to verify
else else
alert_warning "#{subject signer} is not trusted for #{full_name}" alert_warning "#{subject signer} is not trusted for #{full_name}"
end end

View file

@ -62,6 +62,22 @@ class Gem::Security::Signer
end end
end end
##
# Extracts the full name of +cert+. If the certificate has a subjectAltName
# this value is preferred, otherwise the subject is used.
def extract_name cert # :nodoc:
subject_alt_name = cert.extensions.find { |e| 'subjectAltName' == e.oid }
if subject_alt_name then
/\Aemail:/ =~ subject_alt_name.value
$' || subject_alt_name.value
else
cert.subject
end
end
## ##
# Loads any missing issuers in the cert chain from the trusted certificates. # Loads any missing issuers in the cert chain from the trusted certificates.
# #
@ -89,7 +105,9 @@ class Gem::Security::Signer
re_sign_key re_sign_key
end end
Gem::Security::SigningPolicy.verify @cert_chain, @key full_name = extract_name @cert_chain.last
Gem::Security::SigningPolicy.verify @cert_chain, @key, {}, {}, full_name
@key.sign @digest_algorithm.new, data @key.sign @digest_algorithm.new, data
end end

View file

@ -26,15 +26,17 @@ class Gem::Source
def <=>(other) def <=>(other)
case other case other
when Gem::Source::Installed, Gem::Source::Local then when Gem::Source::Installed,
Gem::Source::Local,
Gem::Source::SpecificFile then
-1 -1
when Gem::Source then when Gem::Source then
if !@uri if !@uri
return 0 unless other.uri return 0 unless other.uri
return -1 return 1
end end
return 1 if !other.uri return -1 if !other.uri
@uri.to_s <=> other.uri.to_s @uri.to_s <=> other.uri.to_s
else else
@ -158,3 +160,5 @@ class Gem::Source
end end
require 'rubygems/source/installed' require 'rubygems/source/installed'
require 'rubygems/source/specific_file'
require 'rubygems/source/local'

View file

@ -1,7 +1,7 @@
require 'rubygems/source'
class Gem::Source::Local < Gem::Source class Gem::Source::Local < Gem::Source
def initialize def initialize
@specs = nil
@api_uri = nil
@uri = nil @uri = nil
end end
@ -22,7 +22,8 @@ class Gem::Source::Local < Gem::Source
end end
def inspect # :nodoc: def inspect # :nodoc:
"#<%s specs: %p>" % [self.class, @specs.keys] keys = @specs ? @specs.keys.sort : 'NOT LOADED'
"#<%s specs: %p>" % [self.class, keys]
end end
def load_specs(type) def load_specs(type)

View file

@ -25,4 +25,32 @@ class Gem::Source::SpecificFile < Gem::Source
raise Gem::Exception, "Unable to download '#{spec.full_name}'" raise Gem::Exception, "Unable to download '#{spec.full_name}'"
end end
def pretty_print q # :nodoc:
q.group 2, '[Local:', ']' do
q.breakable
q.text @path
end
end
##
# Orders this source against +other+.
#
# If +other+ is a SpecificFile from a different gem name +nil+ is returned.
#
# If +other+ is a SpecificFile from the same gem name the versions are
# compared using Gem::Version#<=>
#
# Otherwise Gem::Source#<=> is used.
def <=> other
case other
when Gem::Source::SpecificFile then
return nil if @spec.name != other.spec.name
@spec.version <=> other.spec.version
else
super
end
end
end end

View file

@ -206,15 +206,19 @@ class Gem::Specification < Gem::BasicSpecification
attr_reader :version attr_reader :version
## ##
# Paths in the gem to add to <tt>$LOAD_PATH</tt> when this gem is activated. # Paths in the gem to add to <code>$LOAD_PATH</code> when this gem is
# activated.
#
# If you have an extension you do not need to add <code>"ext"</code> to the
# require path, the extension build process will copy the extension files
# into "lib" for you.
#
# The default value is <code>"lib"</code>
# #
# Usage: # Usage:
# #
# # If all library files are in the root directory... # # If all library files are in the root directory...
# spec.require_path = '.' # spec.require_path = '.'
#
# # If you have 'lib' and 'ext' directories...
# spec.require_paths << 'ext'
attr_accessor :require_paths attr_accessor :require_paths
@ -228,7 +232,7 @@ class Gem::Specification < Gem::BasicSpecification
## ##
# A short summary of this gem's description. Displayed in `gem list -d`. # A short summary of this gem's description. Displayed in `gem list -d`.
# #
# The description should be more detailed than the summary. # The #description should be more detailed than the summary.
# #
# Usage: # Usage:
# #
@ -241,21 +245,23 @@ class Gem::Specification < Gem::BasicSpecification
# #
# This is usually Gem::Platform::RUBY or Gem::Platform::CURRENT. # This is usually Gem::Platform::RUBY or Gem::Platform::CURRENT.
# #
# Most gems contain pure Ruby code; they should simply leave the default value # Most gems contain pure Ruby code; they should simply leave the default
# in place. Some gems contain C (or other) code to be compiled into a Ruby # value in place. Some gems contain C (or other) code to be compiled into a
# “extension”. The should leave the default value in place unless their code # Ruby "extension". The should leave the default value in place unless
# will only compile on a certain type of system. Some gems consist of # their code will only compile on a certain type of system. Some gems
# pre-compiled code (“binary gems”). Its especially important that they set # consist of pre-compiled code ("binary gems"). It's especially important
# the platform attribute appropriately. A shortcut is to set the platform to # that they set the platform attribute appropriately. A shortcut is to set
# Gem::Platform::CURRENT, which will cause the gem builder to set the platform # the platform to Gem::Platform::CURRENT, which will cause the gem builder
# to the appropriate value for the system on which the build is being performed. # to set the platform to the appropriate value for the system on which the
# build is being performed.
# #
# If this attribute is set to a non-default value, it will be included in the # If this attribute is set to a non-default value, it will be included in
# filename of the gem when it is built, e.g. fxruby-1.2.0-win32.gem. # the filename of the gem when it is built such as:
# nokogiri-1.6.0-x86-mingw32.gem
# #
# Usage: # Usage:
# #
# spec.platform = Gem::Platform::Win32 # spec.platform = Gem::Platform.local
def platform= platform def platform= platform
if @original_platform.nil? or if @original_platform.nil? or
@ -357,7 +363,7 @@ class Gem::Specification < Gem::BasicSpecification
attr_reader :description attr_reader :description
## ##
# A contact email for this gem # A contact email address (or addresses) for this gem
# #
# Usage: # Usage:
# #
@ -473,6 +479,8 @@ class Gem::Specification < Gem::BasicSpecification
# Usage: # Usage:
# #
# spec.extensions << 'ext/rmagic/extconf.rb' # spec.extensions << 'ext/rmagic/extconf.rb'
#
# See Gem::Ext::Builder for information about writing extensions for gems.
def extensions def extensions
@extensions ||= [] @extensions ||= []
@ -502,6 +510,8 @@ class Gem::Specification < Gem::BasicSpecification
# This should just be the name of your license. The full # This should just be the name of your license. The full
# text of the license should be inside of the gem when you build it. # text of the license should be inside of the gem when you build it.
# #
# You can set multiple licenses with #licenses=
#
# Usage: # Usage:
# spec.license = 'MIT' # spec.license = 'MIT'
@ -538,15 +548,20 @@ class Gem::Specification < Gem::BasicSpecification
end end
## ##
# The version of Ruby required by this gem # The version of Ruby required by this gem. The ruby version can be
# specified to the patch-level:
#
# $ ruby -v -e 'p Gem.ruby_version'
# ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
# #<Gem::Version "2.0.0.247">
# #
# Usage: # Usage:
# #
# # If it will work with 1.8.6 or greater... # # This gem will work with 1.8.6 or greater...
# spec.required_ruby_version = '>= 1.8.6' # spec.required_ruby_version = '>= 1.8.6'
# #
# # Hopefully by now: # # Only with ruby 2.0.x
# spec.required_ruby_version = '>= 1.9.2' # spec.required_ruby_version = '~> 2.0'
def required_ruby_version= req def required_ruby_version= req
@required_ruby_version = Gem::Requirement.create req @required_ruby_version = Gem::Requirement.create req
@ -554,7 +569,7 @@ class Gem::Specification < Gem::BasicSpecification
## ##
# Lists the external (to RubyGems) requirements that must be met for this gem # Lists the external (to RubyGems) requirements that must be met for this gem
# to work. Its simply information for the user. # to work. It's simply information for the user.
# #
# Usage: # Usage:
# #
@ -592,7 +607,7 @@ class Gem::Specification < Gem::BasicSpecification
# #
# Deprecated: It is neither supported nor functional. # Deprecated: It is neither supported nor functional.
attr_accessor :autorequire attr_accessor :autorequire # :nodoc:
## ##
# Sets the default executable for this gem. # Sets the default executable for this gem.
@ -615,9 +630,12 @@ class Gem::Specification < Gem::BasicSpecification
# The RubyGems version required by this gem # The RubyGems version required by this gem
attr_reader :required_rubygems_version attr_reader :required_rubygems_version
## ##
# The rubyforge project this gem lives under. i.e. RubyGems' # The rubyforge project this gem lives under. i.e. RubyGems'
# rubyforge_project is "rubygems". # rubyforge_project is "rubygems".
#
# This option is deprecated.
attr_accessor :rubyforge_project attr_accessor :rubyforge_project
@ -768,7 +786,7 @@ class Gem::Specification < Gem::BasicSpecification
# -- wilsonb # -- wilsonb
def self.all= specs def self.all= specs
@@all = specs @@all = @@stubs = specs
end end
## ##
@ -1320,7 +1338,7 @@ class Gem::Specification < Gem::BasicSpecification
end end
## ##
# Singular reader for #authors # Singular reader for #authors. Returns the first author in the list
def author def author
val = authors and val.first val = authors and val.first
@ -1328,6 +1346,8 @@ class Gem::Specification < Gem::BasicSpecification
## ##
# The list of author names who wrote this gem. # The list of author names who wrote this gem.
#
# spec.authors = ['Chad Fowler', 'Jim Weirich', 'Rich Kilmer']
def authors def authors
@authors ||= [] @authors ||= []
@ -1407,7 +1427,9 @@ class Gem::Specification < Gem::BasicSpecification
end end
## ##
# The date this gem was created. Lazily defaults to TODAY. # The date this gem was created. Lazily defaults to the current UTC date.
#
# There is no need to set this in your gem specification.
def date def date
@date ||= TODAY @date ||= TODAY
@ -1454,7 +1476,7 @@ class Gem::Specification < Gem::BasicSpecification
# Deprecated: The name of the gem is assumed to be the name of the # Deprecated: The name of the gem is assumed to be the name of the
# executable now. See Gem.bin_path. # executable now. See Gem.bin_path.
def default_executable def default_executable # :nodoc:
if defined?(@default_executable) and @default_executable if defined?(@default_executable) and @default_executable
result = @default_executable result = @default_executable
elsif @executables and @executables.size == 1 elsif @executables and @executables.size == 1
@ -1513,7 +1535,7 @@ class Gem::Specification < Gem::BasicSpecification
end end
## ##
# A long description of this gem # A detailed description of this gem. See also #summary
def description= str def description= str
@description = str.to_s @description = str.to_s
@ -1672,7 +1694,7 @@ class Gem::Specification < Gem::BasicSpecification
# #
# Formerly used to indicate this gem was RDoc-capable. # Formerly used to indicate this gem was RDoc-capable.
def has_rdoc def has_rdoc # :nodoc:
true true
end end
@ -1681,11 +1703,11 @@ class Gem::Specification < Gem::BasicSpecification
# #
# Formerly used to indicate this gem was RDoc-capable. # Formerly used to indicate this gem was RDoc-capable.
def has_rdoc= ignored def has_rdoc= ignored # :nodoc:
@has_rdoc = true @has_rdoc = true
end end
alias :has_rdoc? :has_rdoc alias :has_rdoc? :has_rdoc # :nodoc:
## ##
# True if this gem has files in test_files # True if this gem has files in test_files
@ -1818,7 +1840,7 @@ class Gem::Specification < Gem::BasicSpecification
@licenses ||= [] @licenses ||= []
end end
def filename= path def loaded_from= path # :nodoc:
super super
@bin_dir = nil @bin_dir = nil
@ -1831,17 +1853,6 @@ class Gem::Specification < Gem::BasicSpecification
@spec_file = nil @spec_file = nil
end end
##
# Path this gemspec was loaded from. This attribute is not persisted.
alias loaded_from filename
##
# Set the location a Specification was loaded from. +obj+ is converted
# to a String.
alias loaded_from= filename=
## ##
# Sets the rubygems_version to the current RubyGems version. # Sets the rubygems_version to the current RubyGems version.

View file

@ -1,8 +1,9 @@
module Gem ##
# Gem::StubSpecification reads the stub: line from the gemspec # Gem::StubSpecification reads the stub: line from the gemspec. This prevents
# This prevents us having to eval the entire gemspec in order to # us having to eval the entire gemspec in order to find out certain
# find out certain information. # information.
class StubSpecification < BasicSpecification
class Gem::StubSpecification < Gem::BasicSpecification
# :nodoc: # :nodoc:
PREFIX = "# stub: " PREFIX = "# stub: "
@ -13,8 +14,7 @@ module Gem
'r' 'r'
end end
# :nodoc: class StubLine # :nodoc: all
class StubLine
attr_reader :parts attr_reader :parts
def initialize(data) def initialize(data)
@ -39,11 +39,40 @@ module Gem
end end
def initialize(filename) def initialize(filename)
self.filename = filename self.loaded_from = filename
@data = nil @data = nil
@spec = nil @spec = nil
end end
##
# True when this gem has been activated
def activated?
loaded = Gem.loaded_specs[name]
loaded && loaded.version == version
end
##
# If the gemspec contains a stubline, returns a StubLine instance. Otherwise
# returns the full Gem::Specification.
def data
unless @data
open loaded_from, OPEN_MODE do |file|
begin
file.readline # discard encoding line
stubline = file.readline.chomp
@data = StubLine.new(stubline) if stubline.start_with?(PREFIX)
rescue EOFError
end
end
end
@data ||= to_spec
end
private :data
## ##
# Name of the gem # Name of the gem
@ -51,13 +80,6 @@ module Gem
@name ||= data.name @name ||= data.name
end end
##
# Version of the gem
def version
@version ||= data.version
end
## ##
# Platform of the gem # Platform of the gem
@ -76,15 +98,7 @@ module Gem
# The full Gem::Specification for this gem, loaded from evalling its gemspec # The full Gem::Specification for this gem, loaded from evalling its gemspec
def to_spec def to_spec
@spec ||= Gem::Specification.load(filename) @spec ||= Gem::Specification.load(loaded_from)
end
##
# True when this gem has been activated
def activated?
loaded = Gem.loaded_specs[name]
loaded && loaded.version == version
end end
## ##
@ -95,25 +109,12 @@ module Gem
data data
end end
private
## ##
# If the gemspec contains a stubline, returns a StubLine instance. Otherwise # Version of the gem
# returns the full Gem::Specification.
def data def version
unless @data @version ||= data.version
open filename, OPEN_MODE do |file|
begin
file.readline # discard encoding line
stubline = file.readline.chomp
@data = StubLine.new(stubline) if stubline.start_with?(PREFIX)
rescue EOFError
end
end
end end
@data ||= to_spec
end
end
end end

View file

@ -808,6 +808,7 @@ Also, a list:
write_file File.join(*%W[gems #{@a1.original_name} lib code.rb]) write_file File.join(*%W[gems #{@a1.original_name} lib code.rb])
write_file File.join(*%W[gems #{@a2.original_name} lib code.rb]) write_file File.join(*%W[gems #{@a2.original_name} lib code.rb])
write_file File.join(*%W[gems #{@a3a.original_name} lib code.rb]) write_file File.join(*%W[gems #{@a3a.original_name} lib code.rb])
write_file File.join(*%W[gems #{@a_evil9.original_name} lib code.rb])
write_file File.join(*%W[gems #{@b2.original_name} lib code.rb]) write_file File.join(*%W[gems #{@b2.original_name} lib code.rb])
write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb]) write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb])
write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb]) write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb])

View file

@ -1181,6 +1181,28 @@ class TestGem < Gem::TestCase
assert_equal nil, Gem.find_unresolved_default_spec("README") assert_equal nil, Gem.find_unresolved_default_spec("README")
end end
def test_default_gems_use_full_paths
begin
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, 'ruby'
refute Gem.default_gems_use_full_paths?
ensure
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, engine
end
begin
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, 'jruby'
assert Gem.default_gems_use_full_paths?
ensure
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, engine
end
end
def with_plugin(path) def with_plugin(path)
test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}", test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}",
@@project_dir) @@project_dir)

View file

@ -191,21 +191,30 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end end
def test_execute_all def test_execute_all
ui = Gem::MockGemUi.new "y\n"
util_make_gems util_make_gems
util_setup_gem ui
assert Gem::Specification.find_all_by_name('a').length > 1 default = new_default_spec 'default', '1'
install_default_gems default
gemhome2 = "#{@gemhome}2"
a_4 = quick_spec 'a', 4
install_gem a_4, :install_dir => gemhome2
Gem::Specification.dirs = [@gemhome, gemhome2]
assert_includes Gem::Specification.all_names, 'a-1'
assert_includes Gem::Specification.all_names, 'a-4'
assert_includes Gem::Specification.all_names, 'default-1'
@cmd.options[:all] = true @cmd.options[:all] = true
@cmd.options[:args] = [] @cmd.options[:args] = []
use_ui ui do use_ui @ui do
@cmd.execute @cmd.execute
end end
refute_includes Gem::Specification.all_names, 'a' assert_equal %w[a-4 default-1], Gem::Specification.all_names.sort
end end
end end

View file

@ -4,16 +4,37 @@ require 'rubygems/package_task'
class TestGemPackageTask < Gem::TestCase class TestGemPackageTask < Gem::TestCase
def setup
super
Rake.application = Rake::Application.new
RakeFileUtils.verbose_flag = false
end
def test_gem_package def test_gem_package
gem = Gem::Specification.new do |g| gem = Gem::Specification.new do |g|
g.name = "pkgr" g.name = "pkgr"
g.version = "1.2.3" g.version = "1.2.3"
g.files = Rake::FileList["x"].resolve
g.authors = %w[author]
g.files = %w[x]
g.summary = 'summary'
end end
pkg = Gem::PackageTask.new(gem) do |p| pkg = Gem::PackageTask.new(gem) do |p|
p.package_files << "y" p.package_files << "y"
end end
assert_equal ["x", "y"], pkg.package_files
assert_equal %w[x y], pkg.package_files
Dir.chdir @tempdir do
FileUtils.touch 'x'
FileUtils.touch 'y'
Rake.application['package'].invoke
assert_path_exists 'pkg/pkgr-1.2.3.gem'
end
end end
def test_gem_package_with_current_platform def test_gem_package_with_current_platform

View file

@ -351,6 +351,17 @@ class TestGemSecurityPolicy < Gem::TestCase
end end
end end
def test_verify_no_signatures_no_digests
Gem::Security.trust_dir.trust_cert PUBLIC_CERT
use_ui @ui do
@no.verify [PUBLIC_CERT], nil, {}, {}, 'some_gem'
end
assert_empty @ui.output
assert_empty @ui.error
end
def test_verify_not_enough_signatures def test_verify_not_enough_signatures
Gem::Security.trust_dir.trust_cert PUBLIC_CERT Gem::Security.trust_dir.trust_cert PUBLIC_CERT

View file

@ -84,6 +84,12 @@ class TestGemSecuritySigner < Gem::TestCase
assert_equal ENCRYPTED_PRIVATE_KEY.to_s, signer.key.to_s assert_equal ENCRYPTED_PRIVATE_KEY.to_s, signer.key.to_s
end end
def test_extract_name
signer = Gem::Security::Signer.new nil, nil
assert_equal 'child@example', signer.extract_name(CHILD_CERT)
end
def test_load_cert_chain def test_load_cert_chain
Gem::Security.trust_dir.trust_cert PUBLIC_CERT Gem::Security.trust_dir.trust_cert PUBLIC_CERT

View file

@ -184,5 +184,28 @@ class TestGemSource < Gem::TestCase
end end
end end
def test_spaceship
remote = @source
specific = Gem::Source::SpecificFile.new(@a1.cache_file)
installed = Gem::Source::Installed.new
local = Gem::Source::Local.new
assert_equal( 0, remote. <=>(remote), 'remote <=> remote')
assert_equal(-1, remote. <=>(specific), 'remote <=> specific')
assert_equal( 1, specific. <=>(remote), 'specific <=> remote')
assert_equal(-1, remote. <=>(local), 'remote <=> local')
assert_equal( 1, local. <=>(remote), 'local <=> remote')
assert_equal(-1, remote. <=>(installed), 'remote <=> installed')
assert_equal( 1, installed.<=>(remote), 'installed <=> remote')
no_uri = @source.dup
no_uri.instance_variable_set :@uri, nil
assert_equal(-1, remote. <=>(no_uri), 'remote <=> no_uri')
end
end end

View file

@ -0,0 +1,28 @@
require 'rubygems/test_case'
require 'rubygems/source'
class TestGemSourceInstalled < Gem::TestCase
def test_spaceship
a1 = quick_gem 'a', '1'
util_build_gem a1
remote = Gem::Source.new @gem_repo
specific = Gem::Source::SpecificFile.new a1.cache_file
installed = Gem::Source::Installed.new
local = Gem::Source::Local.new
assert_equal( 0, installed.<=>(installed), 'installed <=> installed')
assert_equal(-1, remote. <=>(installed), 'remote <=> installed')
assert_equal( 1, installed.<=>(remote), 'installed <=> remote')
assert_equal( 1, installed.<=>(local), 'installed <=> local')
assert_equal(-1, local. <=>(installed), 'local <=> installed')
assert_equal(-1, specific. <=>(installed), 'specific <=> installed')
assert_equal( 1, installed.<=>(specific), 'installed <=> specific')
end
end

View file

@ -66,18 +66,41 @@ class TestGemSourceLocal < Gem::TestCase
assert_equal s, @a assert_equal s, @a
end end
def test_inspect
assert_equal '#<Gem::Source::Local specs: "NOT LOADED">', @sl.inspect
@sl.load_specs :released
inner = [@a, @ap, @b].map { |t| t.name_tuple }.inspect
assert_equal "#<Gem::Source::Local specs: #{inner}>", @sl.inspect
end
def test_download def test_download
path = @sl.download @a path = @sl.download @a
assert_equal File.expand_path(@a.file_name), path assert_equal File.expand_path(@a.file_name), path
end end
def test_compare def test_spaceship
uri = URI.parse "http://gems.example/foo" a1 = quick_gem 'a', '1'
s = Gem::Source.new uri util_build_gem a1
assert_equal(-1, s <=> @sl) remote = Gem::Source.new @gem_repo
assert_equal 0, @sl <=> @sl specific = Gem::Source::SpecificFile.new a1.cache_file
assert_equal 1, @sl <=> s installed = Gem::Source::Installed.new
local = Gem::Source::Local.new
assert_equal( 0, local. <=>(local), 'local <=> local')
assert_equal(-1, remote. <=>(local), 'remote <=> local')
assert_equal( 1, local. <=>(remote), 'local <=> remote')
assert_equal( 1, installed.<=>(local), 'installed <=> local')
assert_equal(-1, local. <=>(installed), 'local <=> installed')
assert_equal(-1, specific. <=>(local), 'specific <=> local')
assert_equal( 1, local. <=>(specific), 'local <=> specific')
end end
end end

View file

@ -30,4 +30,42 @@ class TestGemSourceSpecificFile < Gem::TestCase
def test_download def test_download
assert_equal @a_gem, @sf.download(@a) assert_equal @a_gem, @sf.download(@a)
end end
def test_spaceship
a1 = quick_gem 'a', '1'
util_build_gem a1
remote = Gem::Source.new @gem_repo
specific = Gem::Source::SpecificFile.new a1.cache_file
installed = Gem::Source::Installed.new
local = Gem::Source::Local.new
assert_equal( 0, specific. <=>(specific), 'specific <=> specific')
assert_equal(-1, remote. <=>(specific), 'remote <=> specific')
assert_equal( 1, specific. <=>(remote), 'specific <=> remote')
assert_equal(-1, specific. <=>(local), 'specific <=> local')
assert_equal( 1, local. <=>(specific), 'local <=> specific')
assert_equal(-1, specific. <=>(installed), 'specific <=> installed')
assert_equal( 1, installed.<=>(specific), 'installed <=> specific')
a2 = quick_gem 'a', '2'
util_build_gem a2
b1 = quick_gem 'b', '1'
util_build_gem b1
a1_source = specific
a2_source = Gem::Source::SpecificFile.new a2.cache_file
b1_source = Gem::Source::SpecificFile.new b1.cache_file
assert_nil a1_source.<=>(b1_source), 'a1_source <=> b1_source'
assert_equal(-1, a1_source.<=>(a2_source), 'a1_source <=> a2_source')
assert_equal( 0, a1_source.<=>(a1_source), 'a1_source <=> a1_source')
assert_equal( 1, a2_source.<=>(a1_source), 'a2_source <=> a1_source')
end
end end

View file

@ -445,6 +445,14 @@ end
end end
end end
def test_self_all_equals
a = new_spec "foo", "1", nil, "lib/foo.rb"
Gem::Specification.all = [a]
assert_equal a, Gem::Specification.find_inactive_by_path('foo')
end
def test_self_attribute_names def test_self_attribute_names
expected_value = %w[ expected_value = %w[
authors authors
@ -1313,7 +1321,7 @@ dependencies: []
end end
def test_base_dir_not_loaded def test_base_dir_not_loaded
@a1.instance_variable_set :@filename, nil @a1.instance_variable_set :@loaded_from, nil
assert_equal Gem.dir, @a1.base_dir assert_equal Gem.dir, @a1.base_dir
end end
@ -1322,7 +1330,7 @@ dependencies: []
default_dir = default_dir =
File.join Gem::Specification.default_specifications_dir, @a1.spec_name File.join Gem::Specification.default_specifications_dir, @a1.spec_name
@a1.instance_variable_set :@filename, default_dir @a1.instance_variable_set :@loaded_from, default_dir
assert_equal Gem.default_dir, @a1.base_dir assert_equal Gem.default_dir, @a1.base_dir
end end