Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update to RubyGems 1.3.6

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@3888 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 7a118b06d05dab28e04f5e73701f9343a7aef3e4 1 parent cefe3fe
Thibault Martin-Lagardette authored
Showing with 1,300 additions and 946 deletions.
  1. +2 −2 bin/gem
  2. +117 −140 lib/rubygems.rb
  3. +4 −2 lib/rubygems/builder.rb
  4. +51 −48 lib/rubygems/command.rb
  5. +2 −0  lib/rubygems/command_manager.rb
  6. +10 −5 lib/rubygems/commands/dependency_command.rb
  7. +1 −1  lib/rubygems/commands/environment_command.rb
  8. +6 −5 lib/rubygems/commands/fetch_command.rb
  9. +1 −0  lib/rubygems/commands/install_command.rb
  10. +8 −8 lib/rubygems/commands/mirror_command.rb
  11. +75 −0 lib/rubygems/commands/owner_command.rb
  12. +1 −1  lib/rubygems/commands/pristine_command.rb
  13. +45 −0 lib/rubygems/commands/push_command.rb
  14. +4 −1 lib/rubygems/commands/query_command.rb
  15. +24 −9 lib/rubygems/commands/rdoc_command.rb
  16. +6 −0 lib/rubygems/commands/server_command.rb
  17. +14 −4 lib/rubygems/commands/setup_command.rb
  18. +2 −2 lib/rubygems/commands/unpack_command.rb
  19. +2 −2 lib/rubygems/commands/update_command.rb
  20. +7 −9 lib/rubygems/commands/which_command.rb
  21. +100 −26 lib/rubygems/config_file.rb
  22. +1 −1  lib/rubygems/defaults.rb
  23. +133 −75 lib/rubygems/dependency.rb
  24. +28 −10 lib/rubygems/dependency_installer.rb
  25. +41 −12 lib/rubygems/dependency_list.rb
  26. +0 −49 lib/rubygems/digest/digest_adapter.rb
  27. +0 −23 lib/rubygems/digest/md5.rb
  28. +0 −22 lib/rubygems/digest/sha1.rb
  29. +0 −22 lib/rubygems/digest/sha2.rb
  30. +7 −0 lib/rubygems/doc_manager.rb
  31. +16 −20 lib/rubygems/format.rb
  32. +1 −1  lib/rubygems/gem_openssl.rb
  33. +10 −12 lib/rubygems/gem_path_searcher.rb
  34. +2 −2 lib/rubygems/indexer.rb
  35. +1 −9 lib/rubygems/install_update_options.rb
  36. +35 −76 lib/rubygems/installer.rb
  37. +1 −2  lib/rubygems/local_remote_options.rb
  38. +0 −1  lib/rubygems/package.rb
  39. +3 −1 lib/rubygems/package/tar_input.rb
  40. +16 −11 lib/rubygems/package_task.rb
  41. +22 −8 lib/rubygems/remote_fetcher.rb
  42. +78 −100 lib/rubygems/requirement.rb
  43. +41 −10 lib/rubygems/server.rb
  44. +5 −5 lib/rubygems/source_index.rb
  45. +2 −2 lib/rubygems/spec_fetcher.rb
  46. +66 −16 lib/rubygems/specification.rb
  47. +33 −4 lib/rubygems/test_utilities.rb
  48. +0 −28 lib/rubygems/timer.rb
  49. +3 −3 lib/rubygems/uninstaller.rb
  50. +45 −0 lib/rubygems/user_interaction.rb
  51. +6 −7 lib/rubygems/validator.rb
  52. +206 −149 lib/rubygems/version.rb
  53. +16 −0 lib/rubygems/version_option.rb
View
4 bin/gem
@@ -9,10 +9,10 @@ require 'rubygems'
require 'rubygems/gem_runner'
require 'rubygems/exceptions'
-required_version = Gem::Requirement.new "> 1.8.3"
+required_version = Gem::Requirement.new ">= 1.8.6"
unless required_version.satisfied_by? Gem.ruby_version then
- abort "Expected Ruby Version #{required_version}, was #{Gem.ruby_version}"
+ abort "Expected Ruby Version #{required_version}, is #{Gem.ruby_version}"
end
args = ARGV.clone
View
257 lib/rubygems.rb
@@ -9,69 +9,6 @@
require 'thread'
require 'etc'
-module Gem
-
- RubyGemsVersion = VERSION = '1.3.5'
-
- ##
- # Raised when RubyGems is unable to load or activate a gem. Contains the
- # name and version requirements of the gem that either conflicts with
- # already activated gems or that RubyGems is otherwise unable to activate.
-
- class LoadError < ::LoadError
-
- ##
- # Name of gem
-
- attr_accessor :name
-
- ##
- # Version requirement of gem
-
- attr_accessor :version_requirement
-
- end
-
-end
-
-module Kernel
-
- ##
- # Use Kernel#gem to activate a specific version of +gem_name+.
- #
- # +version_requirements+ is a list of version requirements that the
- # specified gem must match, most commonly "= example.version.number". See
- # Gem::Requirement for how to specify a version requirement.
- #
- # If you will be activating the latest version of a gem, there is no need to
- # call Kernel#gem, Kernel#require will do the right thing for you.
- #
- # Kernel#gem returns true if the gem was activated, otherwise false. If the
- # gem could not be found, didn't match the version requirements, or a
- # different version was already activated, an exception will be raised.
- #
- # Kernel#gem should be called *before* any require statements (otherwise
- # RubyGems may load a conflicting library version).
- #
- # In older RubyGems versions, the environment variable GEM_SKIP could be
- # used to skip activation of specified gems, for example to test out changes
- # that haven't been installed yet. Now RubyGems defers to -I and the
- # RUBYLIB environment variable to skip activation of a gem.
- #
- # Example:
- #
- # GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
-
- def gem(gem_name, *version_requirements) # :doc:
- skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
- raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
- Gem.activate(gem_name, *version_requirements)
- end
-
- private :gem
-
-end
-
##
# RubyGems is the Ruby standard for publishing and managing third party
# libraries.
@@ -86,6 +23,7 @@ def gem(gem_name, *version_requirements) # :doc:
#
# * {Creating Gems}[http://docs.rubygems.org/read/chapter/5]
# * Gem::Specification
+# * Gem::Version for version dependency notes
#
# Further RubyGems documentation can be found at:
#
@@ -96,7 +34,8 @@ def gem(gem_name, *version_requirements) # :doc:
# == RubyGems Plugins
#
# As of RubyGems 1.3.2, RubyGems will load plugins installed in gems or
-# $LOAD_PATH. Plugins must be named 'rubygems_plugin' are discovered via
+# $LOAD_PATH. Plugins must be named 'rubygems_plugin' (.rb, .so, etc) and
+# placed at the root of your gem's #require_path. Plugins are discovered via
# Gem::find_files then loaded. Take care when implementing a plugin as your
# plugin file may be loaded multiple times if multiple versions of your gem
# are installed.
@@ -122,7 +61,7 @@ def gem(gem_name, *version_requirements) # :doc:
# == Bugs
#
# You can submit bugs to the
-# {RubyGems bug tracker}[http://rubyforge.org/tracker/?atid=575&group_id=126&func=browse]
+# {RubyGems bug tracker}[http://rubyforge.org/tracker/?atid=575&group_id=126]
# on RubyForge
#
# == Credits
@@ -131,26 +70,26 @@ def gem(gem_name, *version_requirements) # :doc:
#
# RubyGems was originally developed at RubyConf 2003 by:
#
-# * Rich Kilmer -- rich(at)infoether.com
-# * Chad Fowler -- chad(at)chadfowler.com
-# * David Black -- dblack(at)wobblini.net
+# * Rich Kilmer -- rich(at)infoether.com
+# * Chad Fowler -- chad(at)chadfowler.com
+# * David Black -- dblack(at)wobblini.net
# * Paul Brannan -- paul(at)atdesk.com
-# * Jim Weirch -- {jim(at)weirichhouse.org}[mailto:jim@weirichhouse.org]
+# * Jim Weirch -- jim(at)weirichhouse.org
#
# Contributors:
#
-# * Gavin Sinclair -- gsinclair(at)soyabean.com.au
-# * George Marrows -- george.marrows(at)ntlworld.com
-# * Dick Davies -- rasputnik(at)hellooperator.net
+# * Gavin Sinclair -- gsinclair(at)soyabean.com.au
+# * George Marrows -- george.marrows(at)ntlworld.com
+# * Dick Davies -- rasputnik(at)hellooperator.net
# * Mauricio Fernandez -- batsman.geo(at)yahoo.com
-# * Simon Strandgaard -- neoneye(at)adslhome.dk
-# * Dave Glasser -- glasser(at)mit.edu
-# * Paul Duncan -- pabs(at)pablotron.org
-# * Ville Aine -- vaine(at)cs.helsinki.fi
-# * Eric Hodel -- drbrain(at)segment7.net
-# * Daniel Berger -- djberg96(at)gmail.com
-# * Phil Hagelberg -- technomancy(at)gmail.com
-# * Ryan Davis
+# * Simon Strandgaard -- neoneye(at)adslhome.dk
+# * Dave Glasser -- glasser(at)mit.edu
+# * Paul Duncan -- pabs(at)pablotron.org
+# * Ville Aine -- vaine(at)cs.helsinki.fi
+# * Eric Hodel -- drbrain(at)segment7.net
+# * Daniel Berger -- djberg96(at)gmail.com
+# * Phil Hagelberg -- technomancy(at)gmail.com
+# * Ryan Davis -- ryand-ruby(at)zenspider.com
#
# (If your name is missing, PLEASE let us know!)
#
@@ -159,6 +98,20 @@ def gem(gem_name, *version_requirements) # :doc:
# -The RubyGems Team
module Gem
+ RubyGemsVersion = VERSION = '1.3.6'
+
+ ##
+ # Raised when RubyGems is unable to load or activate a gem. Contains the
+ # name and version requirements of the gem that either conflicts with
+ # already activated gems or that RubyGems is otherwise unable to activate.
+
+ class LoadError < ::LoadError
+ # Name of gem
+ attr_accessor :name
+
+ # Version requirement of gem
+ attr_accessor :version_requirement
+ end
##
# Configuration settings from ::RbConfig
@@ -166,23 +119,20 @@ module Gem
ConfigMap = {} unless defined?(ConfigMap)
require 'rbconfig'
- # :stopdoc:
- RbConfig = Config unless defined? ::RbConfig
- # :startdoc:
ConfigMap.merge!(
- :EXEEXT => RbConfig::CONFIG["EXEEXT"],
- :RUBY_SO_NAME => RbConfig::CONFIG["RUBY_SO_NAME"],
- :arch => RbConfig::CONFIG["arch"],
- :bindir => RbConfig::CONFIG["bindir"],
- :datadir => RbConfig::CONFIG["datadir"],
- :libdir => RbConfig::CONFIG["libdir"],
+ :EXEEXT => RbConfig::CONFIG["EXEEXT"],
+ :RUBY_SO_NAME => RbConfig::CONFIG["RUBY_SO_NAME"],
+ :arch => RbConfig::CONFIG["arch"],
+ :bindir => RbConfig::CONFIG["bindir"],
+ :datadir => RbConfig::CONFIG["datadir"],
+ :libdir => RbConfig::CONFIG["libdir"],
:ruby_install_name => RbConfig::CONFIG["ruby_install_name"],
- :ruby_version => RbConfig::CONFIG["ruby_version"],
- :sitedir => RbConfig::CONFIG["sitedir"],
- :sitelibdir => RbConfig::CONFIG["sitelibdir"],
- :vendordir => RbConfig::CONFIG["vendordir"] ,
- :vendorlibdir => RbConfig::CONFIG["vendorlibdir"]
+ :ruby_version => RbConfig::CONFIG["ruby_version"],
+ :sitedir => RbConfig::CONFIG["sitedir"],
+ :sitelibdir => RbConfig::CONFIG["sitelibdir"],
+ :vendordir => RbConfig::CONFIG["vendordir"] ,
+ :vendorlibdir => RbConfig::CONFIG["vendorlibdir"]
)
##
@@ -253,11 +203,11 @@ def self.activate(gem, *version_requirements)
end
unless gem.respond_to?(:name) and
- gem.respond_to?(:version_requirements) then
+ gem.respond_to?(:requirement) then
gem = Gem::Dependency.new(gem, version_requirements)
end
- matches = Gem.source_index.find_name(gem.name, gem.version_requirements)
+ matches = Gem.source_index.find_name(gem.name, gem.requirement)
report_activate_error(gem) if matches.empty?
if @loaded_specs[gem.name] then
@@ -275,7 +225,7 @@ def self.activate(gem, *version_requirements)
e = Gem::LoadError.new msg
e.name = gem.name
- e.version_requirement = gem.version_requirements
+ e.version_requirement = gem.requirement
raise e
end
@@ -351,7 +301,7 @@ def self.available?(gem, *requirements)
requirements = Gem::Requirement.default if requirements.empty?
unless gem.respond_to?(:name) and
- gem.respond_to?(:version_requirements) then
+ gem.respond_to?(:requirement) then
gem = Gem::Dependency.new gem, requirements
end
@@ -546,22 +496,22 @@ def self.find_files(path)
# least on Win32).
def self.find_home
- ['HOME', 'USERPROFILE'].each do |homekey|
- return ENV[homekey] if ENV[homekey]
- end
+ unless RUBY_VERSION > '1.9' then
+ ['HOME', 'USERPROFILE'].each do |homekey|
+ return ENV[homekey] if ENV[homekey]
+ end
- if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
- return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
+ if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
+ return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
+ end
end
- begin
- File.expand_path("~")
- rescue
- if File::ALT_SEPARATOR then
- "C:/"
- else
- "/"
- end
+ File.expand_path "~"
+ rescue
+ if File::ALT_SEPARATOR then
+ "C:/"
+ else
+ "/"
end
end
@@ -815,15 +765,15 @@ def self.report_activate_error(gem)
if matches.empty? then
error = Gem::LoadError.new(
- "Could not find RubyGem #{gem.name} (#{gem.version_requirements})\n")
+ "Could not find RubyGem #{gem.name} (#{gem.requirement})\n")
else
error = Gem::LoadError.new(
"RubyGem version error: " +
- "#{gem.name}(#{matches.first.version} not #{gem.version_requirements})\n")
+ "#{gem.name}(#{matches.first.version} not #{gem.requirement})\n")
end
error.name = gem.name
- error.version_requirement = gem.version_requirements
+ error.version_requirement = gem.requirement
raise error
end
@@ -894,9 +844,8 @@ def self.searcher
# Set the Gem home directory (as reported by Gem.dir).
def self.set_home(home)
- home = home.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
+ home = home.gsub File::ALT_SEPARATOR, File::SEPARATOR if File::ALT_SEPARATOR
@gem_home = home
- ensure_gem_subdirectories(@gem_home)
end
private_class_method :set_home
@@ -921,18 +870,6 @@ def self.set_paths(gpaths)
end
@gem_path.uniq!
- @gem_path.each do |path|
- if 0 == File.expand_path(path).index(Gem.user_home)
- next unless File.directory? Gem.user_home
- unless win_platform? then
- # only create by matching user
- if Etc.getpwuid.nil? || Etc.getpwuid.uid != File::Stat.new(Gem.user_home).uid
- next
- end
- end
- end
- ensure_gem_subdirectories path
- end
end
private_class_method :set_paths
@@ -1085,19 +1022,53 @@ class << self
end
-module Config
- # :stopdoc:
- class << self
- # Return the path to the data directory associated with the named
- # package. If the package is loaded as a gem, return the gem
- # specific data directory. Otherwise return a path to the share
- # area as define by "#{ConfigMap[:datadir]}/#{package_name}".
- def datadir(package_name)
- Gem.datadir(package_name) ||
- File.join(Gem::ConfigMap[:datadir], package_name)
- end
+module Kernel
+
+ ##
+ # Use Kernel#gem to activate a specific version of +gem_name+.
+ #
+ # +version_requirements+ is a list of version requirements that the
+ # specified gem must match, most commonly "= example.version.number". See
+ # Gem::Requirement for how to specify a version requirement.
+ #
+ # If you will be activating the latest version of a gem, there is no need to
+ # call Kernel#gem, Kernel#require will do the right thing for you.
+ #
+ # Kernel#gem returns true if the gem was activated, otherwise false. If the
+ # gem could not be found, didn't match the version requirements, or a
+ # different version was already activated, an exception will be raised.
+ #
+ # Kernel#gem should be called *before* any require statements (otherwise
+ # RubyGems may load a conflicting library version).
+ #
+ # In older RubyGems versions, the environment variable GEM_SKIP could be
+ # used to skip activation of specified gems, for example to test out changes
+ # that haven't been installed yet. Now RubyGems defers to -I and the
+ # RUBYLIB environment variable to skip activation of a gem.
+ #
+ # Example:
+ #
+ # GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
+
+ def gem(gem_name, *version_requirements) # :doc:
+ skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
+ raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
+ Gem.activate(gem_name, *version_requirements)
end
- # :startdoc:
+
+ private :gem
+
+end
+
+##
+# Return the path to the data directory associated with the named package. If
+# the package is loaded as a gem, return the gem specific data directory.
+# Otherwise return a path to the share area as define by
+# "#{ConfigMap[:datadir]}/#{package_name}".
+
+def RbConfig.datadir(package_name)
+ Gem.datadir(package_name) ||
+ File.join(Gem::ConfigMap[:datadir], package_name)
end
require 'rubygems/exceptions'
@@ -1133,6 +1104,12 @@ def datadir(package_name)
plugins = Gem.find_files 'rubygems_plugin'
plugins.each do |plugin|
+
+ # Skip older versions of the GemCutter plugin: Its commands are in
+ # RubyGems proper now.
+
+ next if plugin =~ /gemcutter-0\.[0-3]/
+
begin
load plugin
rescue => e
View
6 lib/rubygems/builder.rb
@@ -11,6 +11,7 @@
class Gem::Builder
include Gem::UserInteraction
+
##
# Constructs a builder instance for the provided specification
#
@@ -33,7 +34,7 @@ def build
@spec.validate
@signer = sign
write_package
- say success
+ say success if Gem.configuration.verbose
@spec.file_name
end
@@ -42,7 +43,7 @@ def success
Successfully built RubyGem
Name: #{@spec.name}
Version: #{@spec.version}
- File: #{@spec.full_name+'.gem'}
+ File: #{@spec.file_name}
EOM
end
@@ -86,5 +87,6 @@ def write_package
end
end
end
+
end
View
99 lib/rubygems/command.rb
@@ -49,7 +49,7 @@ class Gem::Command
def self.build_args
@build_args ||= []
end
-
+
def self.build_args=(value)
@build_args = value
end
@@ -160,8 +160,8 @@ def get_all_gem_names
end
##
- # Get the single gem name from the command line. Fail if there is no gem
- # name or if there is more than one gem name given.
+ # Get a single gem name from the command line. Fail if there is no gem name
+ # or if there is more than one gem name given.
def get_one_gem_name
args = options[:args]
@@ -197,7 +197,7 @@ def get_one_optional_argument
# def usage
# "#{program_name} FILE [FILE ...]"
# end
- #
+ #
# def arguments
# "FILE name of file to find"
# end
@@ -248,11 +248,12 @@ def show_help
# Invoke the command with the given list of arguments.
def invoke(*args)
- handle_options(args)
- if options[:help]
+ handle_options args
+
+ if options[:help] then
show_help
- elsif @when_invoked
- @when_invoked.call(options)
+ elsif @when_invoked then
+ @when_invoked.call options
else
execute
end
@@ -362,37 +363,39 @@ def parser
def create_option_parser
@parser = OptionParser.new
- @parser.separator("")
+ @parser.separator nil
regular_options = @option_groups.delete :options
configure_options "", regular_options
@option_groups.sort_by { |n,_| n.to_s }.each do |group_name, option_list|
+ @parser.separator nil
configure_options group_name, option_list
end
+ @parser.separator nil
configure_options "Common", Gem::Command.common_options
- @parser.separator("")
unless arguments.empty?
- @parser.separator(" Arguments:")
+ @parser.separator nil
+ @parser.separator " Arguments:"
arguments.split(/\n/).each do |arg_desc|
- @parser.separator(" #{arg_desc}")
+ @parser.separator " #{arg_desc}"
end
- @parser.separator("")
end
- @parser.separator(" Summary:")
+ @parser.separator nil
+ @parser.separator " Summary:"
wrap(@summary, 80 - 4).split("\n").each do |line|
- @parser.separator(" #{line.strip}")
+ @parser.separator " #{line.strip}"
end
if description then
formatted = description.split("\n\n").map do |chunk|
- wrap(chunk, 80 - 4)
- end.join("\n")
+ wrap chunk, 80 - 4
+ end.join "\n"
- @parser.separator ""
+ @parser.separator nil
@parser.separator " Description:"
formatted.split("\n").each do |line|
@parser.separator " #{line.rstrip}"
@@ -400,10 +403,10 @@ def create_option_parser
end
unless defaults_str.empty?
- @parser.separator("")
- @parser.separator(" Defaults:")
+ @parser.separator nil
+ @parser.separator " Defaults:"
defaults_str.split(/\n/).each do |line|
- @parser.separator(" #{line}")
+ @parser.separator " #{line}"
end
end
end
@@ -471,33 +474,33 @@ def wrap(text, width) # :doc:
# :stopdoc:
- HELP = %{
- RubyGems is a sophisticated package manager for Ruby. This is a
- basic help message containing pointers to more information.
-
- Usage:
- gem -h/--help
- gem -v/--version
- gem command [arguments...] [options...]
-
- Examples:
- gem install rake
- gem list --local
- gem build package.gemspec
- gem help install
-
- Further help:
- gem help commands list all 'gem' commands
- gem help examples show some examples of usage
- gem help platforms show information about platforms
- gem help <COMMAND> show help on COMMAND
- (e.g. 'gem help install')
- gem server present a web page at
- http://localhost:8808/
- with info about installed gems
- Further information:
- http://rubygems.rubyforge.org
- }.gsub(/^ /, '')
+ HELP = <<-HELP
+RubyGems is a sophisticated package manager for Ruby. This is a
+basic help message containing pointers to more information.
+
+ Usage:
+ gem -h/--help
+ gem -v/--version
+ gem command [arguments...] [options...]
+
+ Examples:
+ gem install rake
+ gem list --local
+ gem build package.gemspec
+ gem help install
+
+ Further help:
+ gem help commands list all 'gem' commands
+ gem help examples show some examples of usage
+ gem help platforms show information about platforms
+ gem help <COMMAND> show help on COMMAND
+ (e.g. 'gem help install')
+ gem server present a web page at
+ http://localhost:8808/
+ with info about installed gems
+ Further information:
+ http://rubygems.rubyforge.org
+ HELP
# :startdoc:
View
2  lib/rubygems/command_manager.rb
@@ -58,7 +58,9 @@ def initialize
register_command :lock
register_command :mirror
register_command :outdated
+ register_command :owner
register_command :pristine
+ register_command :push
register_command :query
register_command :rdoc
register_command :search
View
15 lib/rubygems/commands/dependency_command.rb
@@ -15,6 +15,7 @@ def initialize
add_version_option
add_platform_option
+ add_prerelease_option
add_option('-R', '--[no-]reverse-dependencies',
'Include reverse dependencies in the output') do
@@ -59,6 +60,7 @@ def execute
end
dependency = Gem::Dependency.new pattern, options[:version]
+ dependency.prerelease = options[:prerelease]
if options[:reverse_dependencies] and remote? and not local? then
alert_error 'Only reverse dependencies for local gems are supported.'
@@ -75,7 +77,10 @@ def execute
fetcher = Gem::SpecFetcher.fetcher
begin
- fetcher.find_matching(dependency).each do |spec_tuple, source_uri|
+ specs_and_sources = fetcher.find_matching(dependency, false, true,
+ dependency.prerelease?)
+
+ specs_and_sources.each do |spec_tuple, source_uri|
spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
source_indexes[source_uri].add_spec spec
@@ -120,8 +125,8 @@ def execute
if options[:pipe_format] then
specs.values.sort_by { |_, spec| spec }.each do |_, spec|
unless spec.dependencies.empty?
- spec.dependencies.each do |dep|
- say "#{dep.name} --version '#{dep.version_requirements}'"
+ spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
+ say "#{dep.name} --version '#{dep.requirement}'"
end
end
end
@@ -147,7 +152,7 @@ def print_dependencies(spec, level = 0)
response = ''
response << ' ' * level + "Gem #{spec.full_name}\n"
unless spec.dependencies.empty? then
- spec.dependencies.each do |dep|
+ spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
response << ' ' * level + " #{dep}\n"
end
end
@@ -163,7 +168,7 @@ def find_reverse_dependencies(spec)
dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep
if spec.name == dep.name and
- dep.version_requirements.satisfied_by?(spec.version) then
+ dep.requirement.satisfied_by?(spec.version) then
result << [sp.full_name, dep]
end
end
View
2  lib/rubygems/commands/environment_command.rb
@@ -118,7 +118,7 @@ def execute
end
else
- fail Gem::CommandLineError, "Unknown enviroment option [#{arg}]"
+ raise Gem::CommandLineError, "Unknown enviroment option [#{arg}]"
end
say out
true
View
11 lib/rubygems/commands/fetch_command.rb
@@ -17,6 +17,7 @@ def initialize
add_version_option
add_platform_option
+ add_prerelease_option
end
def arguments # :nodoc:
@@ -39,12 +40,12 @@ def execute
gem_names.each do |gem_name|
dep = Gem::Dependency.new gem_name, version
+ dep.prerelease = options[:prerelease]
- specs_and_sources = Gem::SpecFetcher.fetcher.fetch dep, all
+ specs_and_sources = Gem::SpecFetcher.fetcher.fetch(dep, false, true,
+ dep.prerelease?)
- specs_and_sources.sort_by { |spec,| spec.version }
-
- spec, source_uri = specs_and_sources.last
+ 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"
@@ -52,7 +53,7 @@ def execute
end
path = Gem::RemoteFetcher.fetcher.download spec, source_uri
- FileUtils.mv path, "#{spec.full_name}.gem"
+ FileUtils.mv path, spec.file_name
say "Downloaded #{spec.full_name}"
end
View
1  lib/rubygems/commands/install_command.rb
@@ -32,6 +32,7 @@ def initialize
add_local_remote_options
add_platform_option
add_version_option
+ add_prerelease_option "to be installed. (Only for listed gems)"
end
def arguments # :nodoc:
View
16 lib/rubygems/commands/mirror_command.rb
@@ -51,7 +51,7 @@ def execute
Dir.mkdir gems_dir
end
- sourceindex_data = ''
+ source_index_data = ''
say "fetching: #{get_from}/Marshal.#{Gem.marshal_version}.Z"
@@ -70,18 +70,18 @@ def execute
end
open File.join(get_from.to_s, "Marshal.#{Gem.marshal_version}.Z"), "rb" do |y|
- sourceindex_data = Zlib::Inflate.inflate y.read
+ source_index_data = Zlib::Inflate.inflate y.read
open File.join(save_to, "Marshal.#{Gem.marshal_version}"), "wb" do |out|
- out.write sourceindex_data
+ out.write source_index_data
end
end
- sourceindex = Marshal.load(sourceindex_data)
+ source_index = Marshal.load source_index_data
- progress = ui.progress_reporter sourceindex.size,
- "Fetching #{sourceindex.size} gems"
- sourceindex.each do |fullname, gem|
- gem_file = "#{fullname}.gem"
+ progress = ui.progress_reporter source_index.size,
+ "Fetching #{source_index.size} gems"
+ source_index.each do |fullname, gem|
+ gem_file = gem.file_name
gem_dest = File.join gems_dir, gem_file
unless File.exist? gem_dest then
View
75 lib/rubygems/commands/owner_command.rb
@@ -0,0 +1,75 @@
+require 'rubygems/command'
+require 'rubygems/local_remote_options'
+require 'rubygems/gemcutter_utilities'
+
+class Gem::Commands::OwnerCommand < Gem::Command
+ include Gem::LocalRemoteOptions
+ include Gem::GemcutterUtilities
+
+ def description # :nodoc:
+ 'Manage gem owners on RubyGems.org.'
+ end
+
+ def arguments # :nodoc:
+ "GEM gem to manage owners for"
+ end
+
+ def initialize
+ super 'owner', description
+ add_proxy_option
+ defaults.merge! :add => [], :remove => []
+
+ add_option '-a', '--add EMAIL', 'Add an owner' do |value, options|
+ options[:add] << value
+ end
+
+ add_option '-r', '--remove EMAIL', 'Remove an owner' do |value, options|
+ options[:remove] << value
+ end
+ end
+
+ def execute
+ sign_in
+ name = get_one_gem_name
+
+ add_owners name, options[:add]
+ remove_owners name, options[:remove]
+ show_owners name
+ end
+
+ def show_owners name
+ response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request|
+ request.add_field "Authorization", Gem.configuration.rubygems_api_key
+ end
+
+ with_response response do |resp|
+ owners = YAML.load resp.body
+
+ say "Owners for gem: #{name}"
+ owners.each do |owner|
+ say "- #{owner['email']}"
+ end
+ end
+ end
+
+ def add_owners name, owners
+ manage_owners :post, name, owners
+ end
+
+ def remove_owners name, owners
+ manage_owners :delete, name, owners
+ end
+
+ def manage_owners method, name, owners
+ owners.each do |owner|
+ response = rubygems_api_request method, "api/v1/gems/#{name}/owners" do |request|
+ request.set_form_data 'email' => owner
+ request.add_field "Authorization", Gem.configuration.rubygems_api_key
+ end
+
+ with_response response
+ end
+ end
+
+end
+
View
2  lib/rubygems/commands/pristine_command.rb
@@ -74,7 +74,7 @@ def execute
say "Restoring gem(s) to pristine condition..."
specs.each do |spec|
- gem = Dir[File.join(Gem.dir, 'cache', "#{spec.full_name}.gem")].first
+ gem = Dir[File.join(Gem.dir, 'cache', spec.file_name)].first
if gem.nil? then
alert_error "Cached gem for #{spec.full_name} not found, use `gem install` to restore"
View
45 lib/rubygems/commands/push_command.rb
@@ -0,0 +1,45 @@
+require 'rubygems/command'
+require 'rubygems/local_remote_options'
+require 'rubygems/gemcutter_utilities'
+
+class Gem::Commands::PushCommand < Gem::Command
+ include Gem::LocalRemoteOptions
+ include Gem::GemcutterUtilities
+
+ def description # :nodoc:
+ 'Push a gem up to RubyGems.org'
+ end
+
+ def arguments # :nodoc:
+ "GEM built gem to push up"
+ end
+
+ def usage # :nodoc:
+ "#{program_name} GEM"
+ end
+
+ def initialize
+ super 'push', description
+ add_proxy_option
+ end
+
+ def execute
+ sign_in
+ send_gem get_one_gem_name
+ end
+
+ def send_gem name
+ say "Pushing gem to RubyGems.org..."
+
+ response = rubygems_api_request :post, "api/v1/gems" do |request|
+ request.body = Gem.read_binary name
+ request.add_field "Content-Length", request.body.size
+ request.add_field "Content-Type", "application/octet-stream"
+ request.add_field "Authorization", Gem.configuration.rubygems_api_key
+ end
+
+ with_response response
+ end
+
+end
+
View
5 lib/rubygems/commands/query_command.rb
@@ -45,7 +45,7 @@ def initialize(name = 'query',
options[:all] = value
end
- add_option( '--prerelease',
+ add_option( '--[no-]prerelease',
'Display prerelease versions') do |value, options|
options[:prerelease] = value
end
@@ -111,6 +111,9 @@ def execute
begin
fetcher = Gem::SpecFetcher.fetcher
spec_tuples = fetcher.find_matching dep, all, false, prerelease
+
+ spec_tuples += fetcher.find_matching dep, false, false, true if
+ prerelease and all
rescue Gem::RemoteFetcher::FetchError => e
if prerelease then
raise Gem::OperationNotSupportedError,
View
33 lib/rubygems/commands/rdoc_command.rb
@@ -8,7 +8,7 @@ class Gem::Commands::RdocCommand < Gem::Command
def initialize
super 'rdoc', 'Generates RDoc for pre-installed gems',
:version => Gem::Requirement.default,
- :include_rdoc => true, :include_ri => true
+ :include_rdoc => true, :include_ri => true, :overwrite => false
add_option('--all',
'Generate RDoc/RI documentation for all',
@@ -17,15 +17,20 @@ def initialize
end
add_option('--[no-]rdoc',
- 'Include RDoc generated documents') do |value, options|
+ 'Generate RDoc HTML') do |value, options|
options[:include_rdoc] = value
end
add_option('--[no-]ri',
- 'Include RI generated documents') do |value, options|
+ 'Generate RI data') do |value, options|
options[:include_ri] = value
end
+ add_option('--[no-]overwrite',
+ 'Overwrite installed documents') do |value, options|
+ options[:overwrite] = value
+ end
+
add_version_option
end
@@ -34,7 +39,14 @@ def arguments # :nodoc:
end
def defaults_str # :nodoc:
- "--version '#{Gem::Requirement.default}' --rdoc --ri"
+ "--version '#{Gem::Requirement.default}' --rdoc --ri --no-overwrite"
+ end
+
+ def description # :nodoc:
+ <<-DESC
+The rdoc command builds RDoc and RI documentation for installed gems. Use
+--overwrite to force rebuilding of documentation.
+ DESC
end
def usage # :nodoc:
@@ -53,24 +65,27 @@ def execute
end
if specs.empty?
- fail "Failed to find gem #{gem_name} to generate RDoc for #{options[:version]}"
+ raise "Failed to find gem #{gem_name} to generate RDoc for #{options[:version]}"
end
if options[:include_ri]
- specs.each do |spec|
- Gem::DocManager.new(spec).generate_ri
+ specs.sort.each do |spec|
+ doc = Gem::DocManager.new(spec)
+ doc.generate_ri if options[:overwrite] || !doc.ri_installed?
end
Gem::DocManager.update_ri_cache
end
if options[:include_rdoc]
- specs.each do |spec|
- Gem::DocManager.new(spec).generate_rdoc
+ specs.sort.each do |spec|
+ doc = Gem::DocManager.new(spec)
+ doc.generate_rdoc if options[:overwrite] || !doc.rdoc_installed?
end
end
true
end
+
end
View
6 lib/rubygems/commands/server_command.rb
@@ -36,6 +36,12 @@ def initialize
add_option '--[no-]daemon', 'run as a daemon' do |daemon, options|
options[:daemon] = daemon
end
+
+ add_option '-b', '--bind=HOST,HOST',
+ 'addresses to bind', Array do |address, options|
+ options[:addresses] ||= []
+ options[:addresses].push(*address)
+ end
end
def defaults_str # :nodoc:
View
18 lib/rubygems/commands/setup_command.rb
@@ -2,7 +2,6 @@
require 'fileutils'
require 'rbconfig'
require 'tmpdir'
-require 'pathname'
##
# Installs RubyGems itself. This command is ordinarily only available from a
@@ -57,10 +56,10 @@ def initialize
end
def check_ruby_version
- required_version = Gem::Version.new '1.8.3'
+ required_version = Gem::Requirement.new '>= 1.8.6'
- unless Gem.ruby_version > required_version then
- alert_error "Ruby version > #{required_version} required, is #{Gem.ruby_version}"
+ unless required_version.satisfied_by? Gem.ruby_version then
+ alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}"
terminate_interaction 1
end
end
@@ -117,6 +116,8 @@ def execute
say "RubyGems #{Gem::VERSION} installed"
+ uninstall_old_gemcutter
+
install_rdoc
say
@@ -359,5 +360,14 @@ def run_rdoc(*args)
r.document args
end
+ def uninstall_old_gemcutter
+ require 'rubygems/uninstaller'
+
+ ui = Gem::Uninstaller.new('gemcutter', :all => true, :ignore => true,
+ :version => '< 0.4')
+ ui.uninstall
+ rescue Gem::InstallError
+ end
+
end
View
4 lib/rubygems/commands/unpack_command.rb
@@ -41,7 +41,7 @@ def execute
path = get_path name, options[:version]
if path then
- basename = File.basename(path).sub(/\.gem$/, '')
+ basename = File.basename(path, '.gem')
target_dir = File.expand_path File.join(options[:target], basename)
FileUtils.mkdir_p target_dir
Gem::Installer.new(path, :unpack => true).unpack target_dir
@@ -79,7 +79,7 @@ def get_path(gemname, version_req)
# 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.full_name + '.gem'
+ filename = selected.file_name
path = nil
Gem.path.find do |gem_dir|
View
4 lib/rubygems/commands/update_command.rb
@@ -28,8 +28,8 @@ def initialize
end
add_local_remote_options
-
add_platform_option
+ add_prerelease_option "as update targets"
end
def arguments # :nodoc:
@@ -54,7 +54,7 @@ def execute
say "Updating RubyGems"
unless options[:args].empty? then
- fail "No gem names are allowed with the --system option"
+ raise "No gem names are allowed with the --system option"
end
rubygems_update = Gem::Specification.new
View
16 lib/rubygems/commands/which_command.rb
@@ -27,13 +27,11 @@ def defaults_str # :nodoc:
"--no-gems-first --no-all"
end
- def usage # :nodoc:
- "#{program_name} FILE [FILE ...]"
- end
-
def execute
searcher = Gem::GemPathSearcher.new
+ found = false
+
options[:args].each do |arg|
dirs = $LOAD_PATH
spec = searcher.find arg
@@ -44,19 +42,19 @@ def execute
else
dirs = $LOAD_PATH + gem_paths(spec)
end
-
- say "(checking gem #{spec.full_name} for #{arg})" if
- Gem.configuration.verbose and $stdout.tty?
end
paths = find_paths arg, dirs
if paths.empty? then
- say "Can't find ruby library file or shared library #{arg}"
+ alert_error "Can't find ruby library file or shared library #{arg}"
else
say paths
+ found = true
end
end
+
+ terminate_interaction 1 unless found
end
def find_paths(package_name, dirs)
@@ -80,7 +78,7 @@ def gem_paths(spec)
end
def usage # :nodoc:
- "#{program_name} FILE [...]"
+ "#{program_name} FILE [FILE ...]"
end
end
View
126 lib/rubygems/config_file.rb
@@ -4,10 +4,26 @@
# See LICENSE.txt for permissions.
#++
-require 'yaml'
-
-# Store the gem command options specified in the configuration file. The
-# config file object acts much like a hash.
+##
+# Gem::ConfigFile RubyGems options and gem command options from ~/.gemrc.
+#
+# ~/.gemrc is a YAML file that uses strings to match gem command arguments and
+# symbols to match RubyGems options.
+#
+# Gem command arguments use a String key that matches the command name and
+# allow you to specify default arguments:
+#
+# install: --no-rdoc --no-ri
+# update: --no-rdoc --no-ri
+#
+# You can use <tt>gem:</tt> to set default arguments for all commands.
+#
+# RubyGems options use symbol keys. Valid options are:
+#
+# +:backtrace+:: See #backtrace
+# +:benchmark+:: See #benchmark
+# +:sources+:: Sets Gem::sources
+# +:verbose+:: See #verbose
class Gem::ConfigFile
@@ -52,49 +68,74 @@ class Gem::ConfigFile
SYSTEM_WIDE_CONFIG_FILE = File.join system_config_path, 'gemrc'
+ ##
# List of arguments supplied to the config file object.
+
attr_reader :args
- # Where to look for gems
+ ##
+ # Where to look for gems (deprecated)
+
attr_accessor :path
+ ##
+ # Where to install gems (deprecated)
+
attr_accessor :home
+ ##
# True if we print backtraces on errors.
+
attr_writer :backtrace
+ ##
# True if we are benchmarking this run.
+
attr_accessor :benchmark
- # Bulk threshold value. If the number of missing gems are above
- # this threshold value, then a bulk download technique is used.
+ ##
+ # Bulk threshold value. If the number of missing gems are above this
+ # threshold value, then a bulk download technique is used. (deprecated)
+
attr_accessor :bulk_threshold
+ ##
# Verbose level of output:
# * false -- No output
# * true -- Normal output
# * :loud -- Extra output
+
attr_accessor :verbose
+ ##
# True if we want to update the SourceInfoCache every time, false otherwise
+
attr_accessor :update_sources
+ ##
+ # API key for RubyGems.org
+
+ attr_reader :rubygems_api_key
+
+ ##
# Create the config file object. +args+ is the list of arguments
# from the command line.
#
# The following command line options are handled early here rather
# than later at the time most command options are processed.
#
- # * --config-file and --config-file==NAME -- Obviously these need
- # to be handled by the ConfigFile object to ensure we get the
- # right config file.
- #
- # * --backtrace -- Backtrace needs to be turned on early so that
- # errors before normal option parsing can be properly handled.
+ # <tt>--config-file</tt>, <tt>--config-file==NAME</tt>::
+ # Obviously these need to be handled by the ConfigFile object to ensure we
+ # get the right config file.
#
- # * --debug -- Enable Ruby level debug messages. Handled early
- # for the same reason as --backtrace.
+ # <tt>--backtrace</tt>::
+ # Backtrace needs to be turned on early so that errors before normal
+ # option parsing can be properly handled.
#
+ # <tt>--debug</tt>::
+ # Enable Ruby level debug messages. Handled early for the same reason as
+ # --backtrace.
+
def initialize(arg_list)
@config_file_name = nil
need_config_file_name = false
@@ -131,21 +172,53 @@ def initialize(arg_list)
@hash = @hash.merge user_config
# HACK these override command-line args, which is bad
- @backtrace = @hash[:backtrace] if @hash.key? :backtrace
- @benchmark = @hash[:benchmark] if @hash.key? :benchmark
- @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold
- Gem.sources = @hash[:sources] if @hash.key? :sources
- @verbose = @hash[:verbose] if @hash.key? :verbose
- @update_sources = @hash[:update_sources] if @hash.key? :update_sources
- @path = @hash[:gempath] if @hash.key? :gempath
- @home = @hash[:gemhome] if @hash.key? :gemhome
+ @backtrace = @hash[:backtrace] if @hash.key? :backtrace
+ @benchmark = @hash[:benchmark] if @hash.key? :benchmark
+ @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold
+ @home = @hash[:gemhome] if @hash.key? :gemhome
+ @path = @hash[:gempath] if @hash.key? :gempath
+ @update_sources = @hash[:update_sources] if @hash.key? :update_sources
+ @verbose = @hash[:verbose] if @hash.key? :verbose
+
+ load_rubygems_api_key
+ Gem.sources = @hash[:sources] if @hash.key? :sources
handle_arguments arg_list
end
+ ##
+ # Location of RubyGems.org credentials
+
+ def credentials_path
+ File.join(Gem.user_home, '.gem', 'credentials')
+ end
+
+ def load_rubygems_api_key
+ api_key_hash = File.exists?(credentials_path) ? load_file(credentials_path) : @hash
+
+ @rubygems_api_key = api_key_hash[:rubygems_api_key] if api_key_hash.key? :rubygems_api_key
+ end
+
+ def rubygems_api_key=(api_key)
+ config = load_file(credentials_path).merge(:rubygems_api_key => api_key)
+
+ dirname = File.dirname(credentials_path)
+ Dir.mkdir(dirname) unless File.exists?(dirname)
+
+ require 'yaml'
+
+ File.open(credentials_path, 'w') do |f|
+ f.write config.to_yaml
+ end
+
+ @rubygems_api_key = api_key
+ end
+
def load_file(filename)
+ return {} unless filename and File.exists?(filename)
begin
- YAML.load(File.read(filename)) if filename and File.exist?(filename)
+ require 'yaml'
+ YAML.load(File.read(filename))
rescue ArgumentError
warn "Failed to load #{config_file_name}"
rescue Errno::EACCES
@@ -239,8 +312,9 @@ def to_yaml # :nodoc:
# Writes out this config file, replacing its source.
def write
- File.open config_file_name, 'w' do |fp|
- fp.write self.to_yaml
+ require 'yaml'
+ open config_file_name, 'w' do |io|
+ io.write to_yaml
end
end
View
2  lib/rubygems/defaults.rb
@@ -9,7 +9,7 @@ module Gem
# An Array of the default sources that come with RubyGems
def self.default_sources
- %w[http://gems.rubyforge.org/]
+ %w[http://rubygems.org/]
end
##
View
208 lib/rubygems/dependency.rb
@@ -1,14 +1,22 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
+require "rubygems/requirement"
##
-# The Dependency class holds a Gem name and a Gem::Requirement
+# The Dependency class holds a Gem name and a Gem::Requirement.
class Gem::Dependency
+ # :stopdoc:
+ @warned_version_requirement = false
+
+ def self.warned_version_requirement
+ @warned_version_requirement
+ end
+
+ def self.warned_version_requirement= value
+ @warned_version_requirement = value
+ end
+ # :startdoc:
+
##
# Valid dependency types.
#--
@@ -16,9 +24,9 @@ class Gem::Dependency
# Gem::Specification::CURRENT_SPECIFICATION_VERSION as well.
TYPES = [
- :development,
- :runtime,
- ]
+ :development,
+ :runtime,
+ ]
##
# Dependency name or regular expression.
@@ -26,122 +34,172 @@ class Gem::Dependency
attr_accessor :name
##
- # Dependency type.
+ # Allows you to force this dependency to be a prerelease.
- attr_reader :type
+ attr_writer :prerelease
##
- # Dependent versions.
-
- attr_writer :version_requirements
-
- ##
- # Orders dependencies by name only.
+ # Dependency type.
- def <=>(other)
- [@name] <=> [other.name]
- end
+ attr_reader :type
##
- # Constructs a dependency with +name+ and +requirements+.
+ # Constructs a dependency with +name+ and +requirements+. The last
+ # argument can optionally be the dependency type, which defaults to
+ # <tt>:runtime</tt>.
- def initialize(name, version_requirements, type=:runtime)
- @name = name
+ def initialize name, *requirements
+ type = Symbol === requirements.last ? requirements.pop : :runtime
+ requirements = requirements.first if 1 == requirements.length # unpack
unless TYPES.include? type
- raise ArgumentError, "Valid types are #{TYPES.inspect}, not #{@type.inspect}"
+ raise ArgumentError, "Valid types are #{TYPES.inspect}, "
+ + "not #{@type.inspect}"
end
- @type = type
+ @name = name
+ @requirement = Gem::Requirement.create requirements
+ @type = type
+ @prerelease = false
- @version_requirements = Gem::Requirement.create version_requirements
- @version_requirement = nil # Avoid warnings.
- end
+ # This is for Marshal backwards compatability. See the comments in
+ # +requirement+ for the dirty details.
- def version_requirements
- normalize if defined? @version_requirement and @version_requirement
- @version_requirements
+ @version_requirements = @requirement
end
- def requirement_list
- version_requirements.as_list
- end
+ ##
+ # What does this dependency require?
- alias requirements_list requirement_list
+ ##
+ # A dependency's hash is the XOR of the hashes of +name+, +type+,
+ # and +requirement+.
- def normalize
- ver = @version_requirement.instance_variable_get :@version
- @version_requirements = Gem::Requirement.new([ver])
- @version_requirement = nil
+ def hash # :nodoc:
+ name.hash ^ type.hash ^ requirement.hash
end
- def to_s # :nodoc:
- "#{name} (#{version_requirements}, #{@type || :runtime})"
+ def inspect # :nodoc:
+ "<%s type=%p name=%p requirements=%p>" %
+ [self.class, @type, @name, requirement.to_s]
+ end
+
+ ##
+ # Does this dependency require a prerelease?
+
+ def prerelease?
+ @prerelease || requirement.prerelease?
end
def pretty_print(q) # :nodoc:
q.group 1, 'Gem::Dependency.new(', ')' do
- q.pp @name
+ q.pp name
q.text ','
q.breakable
- q.pp @version_requirements
+ q.pp requirement
q.text ','
q.breakable
- q.pp @type
+ q.pp type
end
end
- def ==(other) # :nodoc:
- self.class === other &&
- self.name == other.name &&
- self.type == other.type &&
- self.version_requirements == other.version_requirements
+ def requirement
+ return @requirement if defined?(@requirement) and @requirement
+
+ # @version_requirements and @version_requirement are legacy ivar
+ # names, and supported here because older gems need to keep
+ # working and Dependency doesn't implement marshal_dump and
+ # marshal_load. In a happier world, this would be an
+ # attr_accessor. The horrifying instance_variable_get you see
+ # below is also the legacy of some old restructurings.
+ #
+ # Note also that because of backwards compatibility (loading new
+ # gems in an old RubyGems installation), we can't add explicit
+ # marshaling to this class until we want to make a big
+ # break. Maybe 2.0.
+ #
+ # Children, define explicit marshal and unmarshal behavior for
+ # public classes. Marshal formats are part of your public API.
+
+ if defined?(@version_requirement) && @version_requirement
+ version = @version_requirement.instance_variable_get :@version
+ @version_requirement = nil
+ @version_requirements = Gem::Requirement.new version
+ end
+
+ @requirement = @version_requirements if defined?(@version_requirements)
end
##
- # Uses this dependency as a pattern to compare to +other+. This dependency
- # will match if the name matches the other's name, and other has only an
- # equal version requirement that satisfies this dependency.
+ # Rails subclasses Gem::Dependency and uses this method, so we'll hack
+ # around it.
- def =~(other)
- other = if self.class === other then
- other
- else
- return false unless other.respond_to? :name and
- other.respond_to? :version
+ alias __requirement requirement # :nodoc:
- Gem::Dependency.new other.name, other.version
- end
+ def requirements_list
+ requirement.as_list
+ end
- pattern = @name
- pattern = /\A#{Regexp.escape @name}\Z/ unless Regexp === pattern
+ def to_s # :nodoc:
+ "#{name} (#{requirement}, #{type})"
+ end
- return false unless pattern =~ other.name
+ def version_requirements # :nodoc:
+ unless Gem::Dependency.warned_version_requirement then
+ warn "#{Gem.location_of_caller.join ':'}:Warning: " \
+ "Gem::Dependency#version_requirements is deprecated " \
+ "and will be removed on or after August 2010. " \
+ "Use #requirement"
- reqs = other.version_requirements.requirements
+ Gem::Dependency.warned_version_requirement = true
+ end
- return false unless reqs.length == 1
- return false unless reqs.first.first == '='
+ __requirement
+ end
- version = reqs.first.last
+ alias_method :version_requirement, :version_requirements
- version_requirements.satisfied_by? version
+ def == other # :nodoc:
+ Gem::Dependency === other &&
+ self.name == other.name &&
+ self.type == other.type &&
+ self.requirement == other.requirement
end
##
- # A dependency's hash is the sum of the hash of the #name, #type and
- # #version_requirements
+ # Dependencies are ordered by name.
- def hash
- name.hash + type.hash + version_requirements.hash
+ def <=> other
+ [@name] <=> [other.name]
end
- def inspect # :nodoc:
- "<%s type=%p name=%p requirements=%p>" % [self.class, @type, @name,
- version_requirements.to_s]
+ ##
+ # Uses this dependency as a pattern to compare to +other+. This
+ # dependency will match if the name matches the other's name, and
+ # other has only an equal version requirement that satisfies this
+ # dependency.
+
+ def =~ other
+ unless Gem::Dependency === other
+ other = Gem::Dependency.new other.name, other.version rescue return false
+ end
+
+ pattern = name
+ pattern = /\A#{Regexp.escape pattern}\Z/ unless Regexp === pattern
+
+ return false unless pattern =~ other.name
+
+ reqs = other.requirement.requirements
+
+ return false unless reqs.length == 1
+ return false unless reqs.first.first == '='
+
+ version = reqs.first.last
+
+ requirement.satisfied_by? version
end
end
View
38 lib/rubygems/dependency_installer.rb
@@ -38,7 +38,7 @@ class Gem::DependencyInstaller
# :format_executable:: See Gem::Installer#initialize.
# :ignore_dependencies:: Don't install any dependencies.
# :install_dir:: See Gem::Installer#install.
- # :prerelease:: Allow prerelease versions
+ # :prerelease:: Allow prerelease versions. See #install.
# :security_policy:: See Gem::Installer::new and Gem::Security.
# :user_install:: See Gem::Installer.new
# :wrappers:: See Gem::Installer::new
@@ -89,14 +89,18 @@ def find_gems_with_sources(dep)
if @domain == :both or @domain == :remote then
begin
- requirements = dep.version_requirements.requirements.map do |req, ver|
+ requirements = dep.requirement.requirements.map do |req, ver|
req
end
- all = !@prerelease && (requirements.length > 1 ||
+ all = !dep.prerelease? &&
+ # we only need latest if there's one requirement and it is
+ # guaranteed to match the newest specs
+ (requirements.length > 1 or
(requirements.first != ">=" and requirements.first != ">"))
- found = Gem::SpecFetcher.fetcher.fetch dep, all, true, @prerelease
+ found = Gem::SpecFetcher.fetcher.fetch dep, all, true, dep.prerelease?
+
gems_and_sources.push(*found)
rescue Gem::RemoteFetcher::FetchError => e
@@ -120,7 +124,7 @@ def find_gems_with_sources(dep)
def gather_dependencies
specs = @specs_and_sources.map { |spec,_| spec }
- dependency_list = Gem::DependencyList.new
+ dependency_list = Gem::DependencyList.new @development
dependency_list.add(*specs)
unless @ignore_dependencies then
@@ -143,7 +147,7 @@ def gather_dependencies
@source_index.any? do |_, installed_spec|
dep.name == installed_spec.name and
- dep.version_requirements.satisfied_by? installed_spec.version
+ dep.requirement.satisfied_by? installed_spec.version
end
end
@@ -164,7 +168,9 @@ def gather_dependencies
# +version+. Returns an Array of specs and sources required for
# installation of the gem.
- def find_spec_by_name_and_version gem_name, version = Gem::Requirement.default
+ def find_spec_by_name_and_version(gem_name,
+ version = Gem::Requirement.default,
+ prerelease = false)
spec_and_source = nil
glob = if File::ALT_SEPARATOR then
@@ -189,6 +195,7 @@ def find_spec_by_name_and_version gem_name, version = Gem::Requirement.default
if spec_and_source.nil? then
dep = Gem::Dependency.new gem_name, version
+ dep.prerelease = true if prerelease
spec_and_sources = find_gems_with_sources(dep).reverse
spec_and_source = spec_and_sources.find { |spec, source|
@@ -205,13 +212,24 @@ def find_spec_by_name_and_version gem_name, version = Gem::Requirement.default
end
##
- # Installs the gem and all its dependencies. Returns an Array of installed
- # gems specifications.
+ # Installs the gem +dep_or_name+ and all its dependencies. Returns an Array
+ # of installed gem specifications.
+ #
+ # If the +:prerelease+ option is set and there is a prerelease for
+ # +dep_or_name+ the prerelease version will be installed.
+ #
+ # Unless explicitly specified as a prerelease dependency, prerelease gems
+ # that +dep_or_name+ depend on will not be installed.
+ #
+ # If c-1.a depends on b-1 and a-1.a and there is a gem b-1.a available then
+ # c-1.a, b-1 and a-1.a will be installed. b-1.a will need to be installed
+ # separately.
def install dep_or_name, version = Gem::Requirement.default
if String === dep_or_name then
- find_spec_by_name_and_version dep_or_name, version
+ find_spec_by_name_and_version dep_or_name, version, @prerelease
else
+ dep_or_name.prerelease = @prerelease
@specs_and_sources = [find_gems_with_sources(dep_or_name).last]
end
View
53 lib/rubygems/dependency_list.rb
@@ -6,23 +6,41 @@
require 'tsort'
+##
+# Gem::DependencyList is used for installing and uninstalling gems in the
+# correct order to avoid conflicts.
+
class Gem::DependencyList
include Enumerable
include TSort
- def self.from_source_index(src_index)
- deps = new
+ ##
+ # Allows enabling/disabling use of development dependencies
+
+ attr_accessor :development
- src_index.each do |full_name, spec|
- deps.add spec
+ ##
+ # Creates a DependencyList from a Gem::SourceIndex +source_index+
+
+ def self.from_source_index(source_index)
+ list = new
+
+ source_index.each do |full_name, spec|
+ list.add spec
end
- deps
+ list
end
- def initialize
+ ##
+ # Creates a new DependencyList. If +development+ is true, development
+ # dependencies will be included.
+
+ def initialize development = false
@specs = []
+
+ @development = development
end
##
@@ -33,8 +51,9 @@ def add(*gemspecs)
end
##
- # Return a list of the specifications in the dependency list, sorted in
- # order so that no spec in the list depends on a gem earlier in the list.
+ # Return a list of the gem specifications in the dependency list, sorted in
+ # order so that no gemspec in the list depends on a gemspec earlier in the
+ # list.
#
# This is useful when removing gems from a set of installed gems. By
# removing them in the returned order, you don't get into as many dependency
@@ -77,6 +96,10 @@ def find_name(full_name)
@specs.find { |spec| spec.full_name == full_name }
end
+ def inspect # :nodoc:
+ "#<%s:0x%x %p>" % [self.class, object_id, map { |s| s.full_name }]
+ end
+
##
# Are all the dependencies in the list satisfied?
@@ -89,10 +112,10 @@ def ok?
end
##
- # Is is ok to remove a gem from the dependency list?
+ # Is is ok to remove a gemspec from the dependency list?
#
# If removing the gemspec creates breaks a currently ok dependency, then it
- # is NOT ok to remove the gem.
+ # is NOT ok to remove the gemspec.
def ok_to_remove?(full_name)
gem_to_remove = find_name full_name
@@ -117,13 +140,16 @@ def ok_to_remove?(full_name)
}
end
+ ##
+ # Removes the gemspec matching +full_name+ from the dependency list
+
def remove_by_name(full_name)
@specs.delete_if { |spec| spec.full_name == full_name }
end
##
# Return a hash of predecessors. <tt>result[spec]</tt> is an Array of
- # gemspecs that have a dependency satisfied by the named spec.
+ # gemspecs that have a dependency satisfied by the named gemspec.
def spec_predecessors
result = Hash.new { |h,k| h[k] = [] }
@@ -152,7 +178,10 @@ def tsort_each_node(&block)
def tsort_each_child(node, &block)
specs = @specs.sort.reverse
- node.dependencies.each do |dep|
+ dependencies = node.runtime_dependencies
+ dependencies.push(*node.development_dependencies) if @development
+
+ dependencies.each do |dep|
specs.each do |spec|
if spec.satisfies_requirement? dep then
begin
View
49 lib/rubygems/digest/digest_adapter.rb
@@ -1,49 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems'
-
-##
-# There is an incompatibility between the way Ruby 1.8.5 and 1.8.6 handles
-# digests. This DigestAdapter will take a pre-1.8.6 digest and adapt it to
-# the 1.8.6 API.
-#
-# Note that only the digest and hexdigest methods are adapted, since these
-# are the only functions used by RubyGems.
-
-class Gem::DigestAdapter
-
- ##
- # Initialize a digest adapter.
-
- def initialize(digest_class)
- @digest_class = digest_class
- end
-
- ##
- # Return a new digester. Since we are only implementing the stateless
- # methods, we will return ourself as the instance.
-
- def new
- self
- end
-
- ##
- # Return the digest of +string+ as a hex string.
-
- def hexdigest(string)
- @digest_class.new(string).hexdigest
- end
-
- ##
- # Return the digest of +string+ as a binary string.
-
- def digest(string)
- @digest_class.new(string).digest
- end
-
-end
-
View
23 lib/rubygems/digest/md5.rb
@@ -1,23 +0,0 @@
-#!/usr/bin/env ruby
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'digest/md5'
-
-# :stopdoc:
-module Gem
- if RUBY_VERSION >= '1.8.6'
- MD5 = Digest::MD5
- else
- require 'rubygems/digest/digest_adapter'
- MD5 = DigestAdapter.new(Digest::MD5)
- def MD5.md5(string)
- self.hexdigest(string)
- end
- end
-end
-# :startdoc:
-
View
22 lib/rubygems/digest/sha1.rb
@@ -1,22 +0,0 @@
-#!/usr/bin/env ruby
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'digest/sha1'
-
-# :stopdoc:
-module Gem
-
- if RUBY_VERSION >= '1.8.6'
- SHA1 = Digest::SHA1
- else
- require 'rubygems/digest/digest_adapter'
- SHA1 = DigestAdapter.new(Digest::SHA1)
- end
-
-end
-# :startdoc:
-
View
22 lib/rubygems/digest/sha2.rb
@@ -1,22 +0,0 @@
-#!/usr/bin/env ruby
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'digest/sha2'
-
-# :stopdoc:
-module Gem
-
- if RUBY_VERSION >= '1.8.6'
- SHA256 = Digest::SHA256
- else
- require 'rubygems/digest/digest_adapter'
- SHA256 = DigestAdapter.new(Digest::SHA256)
- end
-
-end
-# :startdoc:
-
View
7 lib/rubygems/doc_manager.rb
@@ -98,6 +98,13 @@ def rdoc_installed?
end
##
+ # Is the RI documentation installed?
+
+ def ri_installed?
+ File.exist?(File.join(@doc_dir, "ri"))
+ end
+
+ ##
# Generate the RI documents for this gem spec.
#
# Note that if both RI and RDoc documents are generated from the same
View
36 lib/rubygems/format.rb
@@ -14,25 +14,22 @@
class Gem::Format
- attr_accessor :spec, :file_entries, :gem_path
+ attr_accessor :spec
+ attr_accessor :file_entries
+ attr_accessor :gem_path
extend Gem::UserInteraction
##
- # Constructs an instance of a Format object, representing the gem's
- # data structure.
- #
- # gem:: [String] The file name of the gem
- #
+ # Constructs a Format representing the gem's data which came from +gem_path+
+
def initialize(gem_path)
@gem_path = gem_path
end
##
- # Reads the named gem file and returns a Format object, representing
- # the data from the gem file
- #
- # file_path:: [String] Path to the gem file
+ # Reads the gem +file_path+ using +security_policy+ and returns a Format
+ # representing the data in the gem