mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to RubyGems 1.3.4 r2223
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a6afbaeb3b
commit
31c94ffeb5
126 changed files with 7610 additions and 3747 deletions
|
@ -21,6 +21,10 @@ class Gem::Commands::CheckCommand < Gem::Command
|
|||
options[:alien] = true
|
||||
end
|
||||
|
||||
add_option('-v', '--verbose', "Spew more words") do |value, options|
|
||||
options[:verbose] = true
|
||||
end
|
||||
|
||||
add_option('-t', '--test', "Run unit tests for gem") do |value, options|
|
||||
options[:test] = true
|
||||
end
|
||||
|
@ -38,16 +42,17 @@ class Gem::Commands::CheckCommand < Gem::Command
|
|||
|
||||
if options[:alien]
|
||||
say "Performing the 'alien' operation"
|
||||
Gem::Validator.new.alien.each do |key, val|
|
||||
if(val.size > 0)
|
||||
say
|
||||
gems = get_all_gem_names rescue []
|
||||
Gem::Validator.new.alien(gems).sort.each do |key, val|
|
||||
unless val.empty? then
|
||||
say "#{key} has #{val.size} problems"
|
||||
val.each do |error_entry|
|
||||
say "\t#{error_entry.path}:"
|
||||
say "\t#{error_entry.problem}"
|
||||
say
|
||||
say " #{error_entry.path}:"
|
||||
say " #{error_entry.problem}"
|
||||
end
|
||||
else
|
||||
say "#{key} is error-free"
|
||||
say "#{key} is error-free" if options[:verbose]
|
||||
end
|
||||
say
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'rubygems/command'
|
||||
require 'rubygems/source_index'
|
||||
require 'rubygems/dependency_list'
|
||||
require 'rubygems/uninstaller'
|
||||
|
||||
class Gem::Commands::CleanupCommand < Gem::Command
|
||||
|
||||
|
@ -22,6 +23,13 @@ class Gem::Commands::CleanupCommand < Gem::Command
|
|||
"--no-dryrun"
|
||||
end
|
||||
|
||||
def description # :nodoc:
|
||||
<<-EOF
|
||||
The cleanup command removes old gems from GEM_HOME. If an older version is
|
||||
installed elsewhere in GEM_PATH the cleanup command won't touch it.
|
||||
EOF
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} [GEMNAME ...]"
|
||||
end
|
||||
|
@ -41,7 +49,8 @@ class Gem::Commands::CleanupCommand < Gem::Command
|
|||
|
||||
unless options[:args].empty? then
|
||||
options[:args].each do |gem_name|
|
||||
specs = Gem.cache.search(/^#{gem_name}$/i)
|
||||
dep = Gem::Dependency.new gem_name, Gem::Requirement.default
|
||||
specs = Gem.source_index.search dep
|
||||
specs.each do |spec|
|
||||
gems_to_cleanup << spec
|
||||
end
|
||||
|
@ -56,7 +65,6 @@ class Gem::Commands::CleanupCommand < Gem::Command
|
|||
primary_gems[spec.name].version != spec.version
|
||||
}
|
||||
|
||||
uninstall_command = Gem::CommandManager.instance['uninstall']
|
||||
deplist = Gem::DependencyList.new
|
||||
gems_to_cleanup.uniq.each do |spec| deplist.add spec end
|
||||
|
||||
|
@ -69,14 +77,21 @@ class Gem::Commands::CleanupCommand < Gem::Command
|
|||
say "Attempting to uninstall #{spec.full_name}"
|
||||
|
||||
options[:args] = [spec.name]
|
||||
options[:version] = "= #{spec.version}"
|
||||
options[:executables] = false
|
||||
|
||||
uninstaller = Gem::Uninstaller.new spec.name, options
|
||||
uninstall_options = {
|
||||
:executables => false,
|
||||
:version => "= #{spec.version}",
|
||||
}
|
||||
|
||||
if Gem.user_dir == spec.installation_path then
|
||||
uninstall_options[:install_dir] = spec.installation_path
|
||||
end
|
||||
|
||||
uninstaller = Gem::Uninstaller.new spec.name, uninstall_options
|
||||
|
||||
begin
|
||||
uninstaller.uninstall
|
||||
rescue Gem::DependencyRemovalException,
|
||||
rescue Gem::DependencyRemovalException, Gem::InstallError,
|
||||
Gem::GemNotInHomeException => e
|
||||
say "Unable to uninstall #{spec.full_name}:"
|
||||
say "\t#{e.class}: #{e.message}"
|
||||
|
|
|
@ -11,6 +11,11 @@ class Gem::Commands::ContentsCommand < Gem::Command
|
|||
|
||||
add_version_option
|
||||
|
||||
add_option( '--all',
|
||||
"Contents for all gems") do |all, options|
|
||||
options[:all] = all
|
||||
end
|
||||
|
||||
add_option('-s', '--spec-dir a,b,c', Array,
|
||||
"Search for gems under specific paths") do |spec_dirs, options|
|
||||
options[:specdirs] = spec_dirs
|
||||
|
@ -20,6 +25,11 @@ class Gem::Commands::ContentsCommand < Gem::Command
|
|||
"Only return files in the Gem's lib_dirs") do |lib_only, options|
|
||||
options[:lib_only] = lib_only
|
||||
end
|
||||
|
||||
add_option( '--[no-]prefix',
|
||||
"Don't include installed path prefix") do |prefix, options|
|
||||
options[:prefix] = prefix
|
||||
end
|
||||
end
|
||||
|
||||
def arguments # :nodoc:
|
||||
|
@ -27,46 +37,60 @@ class Gem::Commands::ContentsCommand < Gem::Command
|
|||
end
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--no-lib-only"
|
||||
"--no-lib-only --prefix"
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} GEMNAME"
|
||||
"#{program_name} GEMNAME [GEMNAME ...]"
|
||||
end
|
||||
|
||||
def execute
|
||||
version = options[:version] || Gem::Requirement.default
|
||||
gem = get_one_gem_name
|
||||
|
||||
s = options[:specdirs].map do |i|
|
||||
spec_dirs = options[:specdirs].map do |i|
|
||||
[i, File.join(i, "specifications")]
|
||||
end.flatten
|
||||
|
||||
path_kind = if s.empty? then
|
||||
s = Gem::SourceIndex.installed_spec_directories
|
||||
path_kind = if spec_dirs.empty? then
|
||||
spec_dirs = Gem::SourceIndex.installed_spec_directories
|
||||
"default gem paths"
|
||||
else
|
||||
"specified path"
|
||||
end
|
||||
|
||||
si = Gem::SourceIndex.from_gems_in(*s)
|
||||
si = Gem::SourceIndex.from_gems_in(*spec_dirs)
|
||||
|
||||
gem_spec = si.find_name(gem, version).last
|
||||
gem_names = if options[:all] then
|
||||
si.map { |_, spec| spec.name }
|
||||
else
|
||||
get_all_gem_names
|
||||
end
|
||||
|
||||
unless gem_spec then
|
||||
say "Unable to find gem '#{gem}' in #{path_kind}"
|
||||
gem_names.each do |name|
|
||||
gem_spec = si.find_name(name, version).last
|
||||
|
||||
if Gem.configuration.verbose then
|
||||
say "\nDirectories searched:"
|
||||
s.each { |dir| say dir }
|
||||
unless gem_spec then
|
||||
say "Unable to find gem '#{name}' in #{path_kind}"
|
||||
|
||||
if Gem.configuration.verbose then
|
||||
say "\nDirectories searched:"
|
||||
spec_dirs.each { |dir| say dir }
|
||||
end
|
||||
|
||||
terminate_interaction 1 if gem_names.length == 1
|
||||
end
|
||||
|
||||
terminate_interaction
|
||||
end
|
||||
files = options[:lib_only] ? gem_spec.lib_files : gem_spec.files
|
||||
|
||||
files = options[:lib_only] ? gem_spec.lib_files : gem_spec.files
|
||||
files.each do |f|
|
||||
say File.join(gem_spec.full_gem_path, f)
|
||||
files.each do |f|
|
||||
path = if options[:prefix] then
|
||||
File.join gem_spec.full_gem_path, f
|
||||
else
|
||||
f
|
||||
end
|
||||
|
||||
say path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,55 +1,131 @@
|
|||
require 'rubygems/command'
|
||||
require 'rubygems/indexer'
|
||||
|
||||
##
|
||||
# Generates a index files for use as a gem server.
|
||||
#
|
||||
# See `gem help generate_index`
|
||||
|
||||
class Gem::Commands::GenerateIndexCommand < Gem::Command
|
||||
|
||||
def initialize
|
||||
super 'generate_index',
|
||||
'Generates the index files for a gem server directory',
|
||||
:directory => '.'
|
||||
:directory => '.', :build_legacy => true, :build_modern => true
|
||||
|
||||
add_option '-d', '--directory=DIRNAME',
|
||||
'repository base dir containing gems subdir' do |dir, options|
|
||||
options[:directory] = File.expand_path dir
|
||||
end
|
||||
|
||||
add_option '--[no-]legacy',
|
||||
'Generate indexes for RubyGems older than',
|
||||
'1.2.0' do |value, options|
|
||||
unless options[:build_modern] or value then
|
||||
raise OptionParser::InvalidOption, 'no indicies will be built'
|
||||
end
|
||||
|
||||
options[:build_legacy] = value
|
||||
end
|
||||
|
||||
add_option '--[no-]modern',
|
||||
'Generate indexes for RubyGems newer',
|
||||
'than 1.2.0' do |value, options|
|
||||
unless options[:build_legacy] or value then
|
||||
raise OptionParser::InvalidOption, 'no indicies will be built'
|
||||
end
|
||||
|
||||
options[:build_modern] = value
|
||||
end
|
||||
|
||||
add_option '--update',
|
||||
'Update modern indexes with gems added',
|
||||
'since the last update' do |value, options|
|
||||
options[:update] = value
|
||||
end
|
||||
|
||||
add_option :RSS, '--rss-gems-host=GEM_HOST',
|
||||
'Host name where gems are served from,',
|
||||
'used for GUID and enclosure values' do |value, options|
|
||||
options[:rss_gems_host] = value
|
||||
end
|
||||
|
||||
add_option :RSS, '--rss-host=HOST',
|
||||
'Host name for more gems information,',
|
||||
'used for RSS feed link' do |value, options|
|
||||
options[:rss_host] = value
|
||||
end
|
||||
|
||||
add_option :RSS, '--rss-title=TITLE',
|
||||
'Set title for RSS feed' do |value, options|
|
||||
options[:rss_title] = value
|
||||
end
|
||||
end
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--directory ."
|
||||
"--directory . --legacy --modern"
|
||||
end
|
||||
|
||||
def description # :nodoc:
|
||||
<<-EOF
|
||||
The generate_index command creates a set of indexes for serving gems
|
||||
statically. The command expects a 'gems' directory under the path given to
|
||||
the --directory option. When done, it will generate a set of files like this:
|
||||
the --directory option. The given directory will be the directory you serve
|
||||
as the gem repository.
|
||||
|
||||
gems/ # .gem files you want to index
|
||||
For `gem generate_index --directory /path/to/repo`, expose /path/to/repo via
|
||||
your HTTP server configuration (not /path/to/repo/gems).
|
||||
|
||||
When done, it will generate a set of files like this:
|
||||
|
||||
gems/*.gem # .gem files you want to
|
||||
# index
|
||||
|
||||
specs.<version>.gz # specs index
|
||||
latest_specs.<version>.gz # latest specs index
|
||||
prerelease_specs.<version>.gz # prerelease specs index
|
||||
quick/Marshal.<version>/<gemname>.gemspec.rz # Marshal quick index file
|
||||
|
||||
# these files support legacy RubyGems
|
||||
quick/index
|
||||
quick/index.rz # quick index manifest
|
||||
quick/<gemname>.gemspec.rz # legacy YAML quick index file
|
||||
quick/Marshal.<version>/<gemname>.gemspec.rz # Marshal quick index file
|
||||
quick/<gemname>.gemspec.rz # legacy YAML quick index
|
||||
# file
|
||||
Marshal.<version>
|
||||
Marshal.<version>.Z # Marshal full index
|
||||
Marshal.<version>.Z # Marshal full index
|
||||
yaml
|
||||
yaml.Z # legacy YAML full index
|
||||
yaml.Z # legacy YAML full index
|
||||
|
||||
The .Z and .rz extension files are compressed with the inflate algorithm. The
|
||||
Marshal version number comes from ruby's Marshal::MAJOR_VERSION and
|
||||
Marshal::MINOR_VERSION constants. It is used to ensure compatibility. The
|
||||
yaml indexes exist for legacy RubyGems clients and fallback in case of Marshal
|
||||
version changes.
|
||||
The .Z and .rz extension files are compressed with the inflate algorithm.
|
||||
The Marshal version number comes from ruby's Marshal::MAJOR_VERSION and
|
||||
Marshal::MINOR_VERSION constants. It is used to ensure compatibility.
|
||||
The yaml indexes exist for legacy RubyGems clients and fallback in case of
|
||||
Marshal version changes.
|
||||
|
||||
If --rss-host and --rss-gem-host are given an RSS feed will be generated at
|
||||
index.rss containing gems released in the last two days.
|
||||
EOF
|
||||
end
|
||||
|
||||
def execute
|
||||
if options[:update] and
|
||||
(options[:rss_host] or options[:rss_gems_host]) then
|
||||
alert_error '--update not compatible with RSS generation'
|
||||
terminate_interaction 1
|
||||
end
|
||||
|
||||
if not File.exist?(options[:directory]) or
|
||||
not File.directory?(options[:directory]) then
|
||||
alert_error "unknown directory name #{directory}."
|
||||
terminate_interaction 1
|
||||
else
|
||||
indexer = Gem::Indexer.new options[:directory]
|
||||
indexer.generate_index
|
||||
indexer = Gem::Indexer.new options.delete(:directory), options
|
||||
|
||||
if options[:update] then
|
||||
indexer.update_index
|
||||
else
|
||||
indexer.generate_index
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,6 +6,11 @@ require 'rubygems/local_remote_options'
|
|||
require 'rubygems/validator'
|
||||
require 'rubygems/version_option'
|
||||
|
||||
##
|
||||
# Gem installer command line tool
|
||||
#
|
||||
# See `gem help install`
|
||||
|
||||
class Gem::Commands::InstallCommand < Gem::Command
|
||||
|
||||
include Gem::VersionOption
|
||||
|
@ -14,11 +19,11 @@ class Gem::Commands::InstallCommand < Gem::Command
|
|||
|
||||
def initialize
|
||||
defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({
|
||||
:generate_rdoc => true,
|
||||
:generate_ri => true,
|
||||
:generate_rdoc => true,
|
||||
:generate_ri => true,
|
||||
:format_executable => false,
|
||||
:test => false,
|
||||
:version => Gem::Requirement.default,
|
||||
:test => false,
|
||||
:version => Gem::Requirement.default,
|
||||
})
|
||||
|
||||
super 'install', 'Install a gem into the local repository', defaults
|
||||
|
@ -43,11 +48,51 @@ class Gem::Commands::InstallCommand < Gem::Command
|
|||
The install command installs local or remote gem into a gem repository.
|
||||
|
||||
For gems with executables ruby installs a wrapper file into the executable
|
||||
directory by deault. This can be overridden with the --no-wrappers option.
|
||||
directory by default. This can be overridden with the --no-wrappers option.
|
||||
The wrapper allows you to choose among alternate gem versions using _version_.
|
||||
|
||||
For example `rake _0.7.3_ --version` will run rake version 0.7.3 if a newer
|
||||
version is also installed.
|
||||
|
||||
If an extension fails to compile during gem installation the gem
|
||||
specification is not written out, but the gem remains unpacked in the
|
||||
repository. You may need to specify the path to the library's headers and
|
||||
libraries to continue. You can do this by adding a -- between RubyGems'
|
||||
options and the extension's build options:
|
||||
|
||||
$ gem install some_extension_gem
|
||||
[build fails]
|
||||
Gem files will remain installed in \\
|
||||
/path/to/gems/some_extension_gem-1.0 for inspection.
|
||||
Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out
|
||||
$ gem install some_extension_gem -- --with-extension-lib=/path/to/lib
|
||||
[build succeeds]
|
||||
$ gem list some_extension_gem
|
||||
|
||||
*** LOCAL GEMS ***
|
||||
|
||||
some_extension_gem (1.0)
|
||||
$
|
||||
|
||||
If you correct the compilation errors by editing the gem files you will need
|
||||
to write the specification by hand. For example:
|
||||
|
||||
$ gem install some_extension_gem
|
||||
[build fails]
|
||||
Gem files will remain installed in \\
|
||||
/path/to/gems/some_extension_gem-1.0 for inspection.
|
||||
Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out
|
||||
$ [cd /path/to/gems/some_extension_gem-1.0]
|
||||
$ [edit files or what-have-you and run make]
|
||||
$ gem spec ../../cache/some_extension_gem-1.0.gem --ruby > \\
|
||||
../../specifications/some_extension_gem-1.0.gemspec
|
||||
$ gem list some_extension_gem
|
||||
|
||||
*** LOCAL GEMS ***
|
||||
|
||||
some_extension_gem (1.0)
|
||||
$
|
||||
|
||||
EOF
|
||||
end
|
||||
|
||||
|
@ -65,24 +110,11 @@ version is also installed.
|
|||
|
||||
ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
|
||||
|
||||
install_options = {
|
||||
:env_shebang => options[:env_shebang],
|
||||
:domain => options[:domain],
|
||||
:force => options[:force],
|
||||
:format_executable => options[:format_executable],
|
||||
:ignore_dependencies => options[:ignore_dependencies],
|
||||
:install_dir => options[:install_dir],
|
||||
:security_policy => options[:security_policy],
|
||||
:wrappers => options[:wrappers],
|
||||
:bin_dir => options[:bin_dir],
|
||||
:development => options[:development],
|
||||
}
|
||||
|
||||
exit_code = 0
|
||||
|
||||
get_all_gem_names.each do |gem_name|
|
||||
begin
|
||||
inst = Gem::DependencyInstaller.new install_options
|
||||
inst = Gem::DependencyInstaller.new options
|
||||
inst.install gem_name, options[:version]
|
||||
|
||||
inst.installed_gems.each do |spec|
|
||||
|
@ -96,46 +128,40 @@ version is also installed.
|
|||
rescue Gem::GemNotFoundException => e
|
||||
alert_error e.message
|
||||
exit_code |= 2
|
||||
# rescue => e
|
||||
# # TODO: Fix this handle to allow the error to propagate to
|
||||
# # the top level handler. Examine the other errors as
|
||||
# # well. This implementation here looks suspicious to me --
|
||||
# # JimWeirich (4/Jan/05)
|
||||
# alert_error "Error installing gem #{gem_name}: #{e.message}"
|
||||
# return
|
||||
end
|
||||
end
|
||||
|
||||
unless installed_gems.empty? then
|
||||
gems = installed_gems.length == 1 ? 'gem' : 'gems'
|
||||
say "#{installed_gems.length} #{gems} installed"
|
||||
end
|
||||
|
||||
# NOTE: *All* of the RI documents must be generated first.
|
||||
# For some reason, RI docs cannot be generated after any RDoc
|
||||
# documents are generated.
|
||||
# NOTE: *All* of the RI documents must be generated first. For some
|
||||
# reason, RI docs cannot be generated after any RDoc documents are
|
||||
# generated.
|
||||
|
||||
if options[:generate_ri] then
|
||||
installed_gems.each do |gem|
|
||||
Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
|
||||
if options[:generate_ri] then
|
||||
installed_gems.each do |gem|
|
||||
Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
|
||||
end
|
||||
|
||||
Gem::DocManager.update_ri_cache
|
||||
end
|
||||
|
||||
Gem::DocManager.update_ri_cache
|
||||
end
|
||||
|
||||
if options[:generate_rdoc] then
|
||||
installed_gems.each do |gem|
|
||||
Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
|
||||
if options[:generate_rdoc] then
|
||||
installed_gems.each do |gem|
|
||||
Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if options[:test] then
|
||||
installed_gems.each do |spec|
|
||||
gem_spec = Gem::SourceIndex.from_installed_gems.search(spec.name, spec.version.version).first
|
||||
result = Gem::Validator.new.unit_test(gem_spec)
|
||||
if result and not result.passed?
|
||||
unless ask_yes_no("...keep Gem?", true) then
|
||||
Gem::Uninstaller.new(spec.name, :version => spec.version.version).uninstall
|
||||
if options[:test] then
|
||||
installed_gems.each do |spec|
|
||||
gem_spec = Gem::SourceIndex.from_installed_gems.find_name(spec.name, spec.version.version).first
|
||||
result = Gem::Validator.new.unit_test(gem_spec)
|
||||
if result and not result.passed?
|
||||
unless ask_yes_no("...keep Gem?", true)
|
||||
require 'rubygems/uninstaller'
|
||||
Gem::Uninstaller.new(spec.name, :version => spec.version.version).uninstall
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,9 +2,11 @@ require 'rubygems/command'
|
|||
require 'rubygems/local_remote_options'
|
||||
require 'rubygems/spec_fetcher'
|
||||
require 'rubygems/version_option'
|
||||
require 'rubygems/text'
|
||||
|
||||
class Gem::Commands::QueryCommand < Gem::Command
|
||||
|
||||
include Gem::Text
|
||||
include Gem::LocalRemoteOptions
|
||||
include Gem::VersionOption
|
||||
|
||||
|
@ -43,6 +45,11 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
options[:all] = value
|
||||
end
|
||||
|
||||
add_option( '--prerelease',
|
||||
'Display prerelease versions') do |value, options|
|
||||
options[:prerelease] = value
|
||||
end
|
||||
|
||||
add_local_remote_options
|
||||
end
|
||||
|
||||
|
@ -54,6 +61,7 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
exit_code = 0
|
||||
|
||||
name = options[:name]
|
||||
prerelease = options[:prerelease]
|
||||
|
||||
if options[:installed] then
|
||||
if name.source.empty? then
|
||||
|
@ -72,6 +80,10 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
dep = Gem::Dependency.new name, Gem::Requirement.default
|
||||
|
||||
if local? then
|
||||
if prerelease and not both? then
|
||||
alert_warning "prereleases are always shown locally"
|
||||
end
|
||||
|
||||
if ui.outs.tty? or both? then
|
||||
say
|
||||
say "*** LOCAL GEMS ***"
|
||||
|
@ -98,8 +110,13 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
|
||||
begin
|
||||
fetcher = Gem::SpecFetcher.fetcher
|
||||
spec_tuples = fetcher.find_matching dep, all, false
|
||||
spec_tuples = fetcher.find_matching dep, all, false, prerelease
|
||||
rescue Gem::RemoteFetcher::FetchError => e
|
||||
if prerelease then
|
||||
raise Gem::OperationNotSupportedError,
|
||||
"Prereleases not supported on legacy repositories"
|
||||
end
|
||||
|
||||
raise unless fetcher.warn_legacy e do
|
||||
require 'rubygems/source_info_cache'
|
||||
|
||||
|
@ -145,6 +162,12 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
version
|
||||
end.reverse
|
||||
|
||||
platforms = Hash.new { |h,version| h[version] = [] }
|
||||
|
||||
matching_tuples.map do |(name, version, platform,_),_|
|
||||
platforms[version] << platform if platform
|
||||
end
|
||||
|
||||
seen = {}
|
||||
|
||||
matching_tuples.delete_if do |(name, version,_),_|
|
||||
|
@ -174,6 +197,28 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
end
|
||||
|
||||
entry << "\n"
|
||||
|
||||
non_ruby = platforms.any? do |_, pls|
|
||||
pls.any? { |pl| pl != Gem::Platform::RUBY }
|
||||
end
|
||||
|
||||
if non_ruby then
|
||||
if platforms.length == 1 then
|
||||
title = platforms.values.length == 1 ? 'Platform' : 'Platforms'
|
||||
entry << " #{title}: #{platforms.values.sort.join ', '}\n"
|
||||
else
|
||||
entry << " Platforms:\n"
|
||||
platforms.sort_by do |version,|
|
||||
version
|
||||
end.each do |version, pls|
|
||||
label = " #{version}: "
|
||||
data = format_text pls.sort.join(', '), 68, label.length
|
||||
data[0, label.length] = label
|
||||
entry << data << "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
authors = "Author#{spec.authors.length > 1 ? 's' : ''}: "
|
||||
authors << spec.authors.join(', ')
|
||||
entry << format_text(authors, 68, 4)
|
||||
|
@ -187,6 +232,12 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4)
|
||||
end
|
||||
|
||||
if spec.license and not spec.license.empty? then
|
||||
licenses = "License#{spec.licenses.length > 1 ? 's' : ''}: "
|
||||
licenses << spec.licenses.join(', ')
|
||||
entry << "\n" << format_text(licenses, 68, 4)
|
||||
end
|
||||
|
||||
if spec.loaded_from then
|
||||
if matching_tuples.length == 1 then
|
||||
loaded_from = File.dirname File.dirname(spec.loaded_from)
|
||||
|
@ -209,25 +260,5 @@ class Gem::Commands::QueryCommand < Gem::Command
|
|||
say output.join(options[:details] ? "\n\n" : "\n")
|
||||
end
|
||||
|
||||
##
|
||||
# Used for wrapping and indenting text
|
||||
|
||||
def format_text(text, wrap, indent=0)
|
||||
result = []
|
||||
work = text.dup
|
||||
|
||||
while work.length > wrap
|
||||
if work =~ /^(.{0,#{wrap}})[ \n]/o then
|
||||
result << $1
|
||||
work.slice!(0, $&.length)
|
||||
else
|
||||
result << work.slice!(0, wrap)
|
||||
end
|
||||
end
|
||||
|
||||
result << work if work.length.nonzero?
|
||||
result.join("\n").gsub(/^/, " " * indent)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -2,81 +2,75 @@ require 'rubygems/command'
|
|||
require 'rubygems/version_option'
|
||||
require 'rubygems/doc_manager'
|
||||
|
||||
module Gem
|
||||
module Commands
|
||||
class RdocCommand < Command
|
||||
include VersionOption
|
||||
class Gem::Commands::RdocCommand < Gem::Command
|
||||
include Gem::VersionOption
|
||||
|
||||
def initialize
|
||||
super('rdoc',
|
||||
'Generates RDoc for pre-installed gems',
|
||||
{
|
||||
:version => Gem::Requirement.default,
|
||||
:include_rdoc => true,
|
||||
:include_ri => true,
|
||||
})
|
||||
add_option('--all',
|
||||
'Generate RDoc/RI documentation for all',
|
||||
'installed gems') do |value, options|
|
||||
options[:all] = value
|
||||
end
|
||||
add_option('--[no-]rdoc',
|
||||
'Include RDoc generated documents') do
|
||||
|value, options|
|
||||
options[:include_rdoc] = value
|
||||
end
|
||||
add_option('--[no-]ri',
|
||||
'Include RI generated documents'
|
||||
) do |value, options|
|
||||
options[:include_ri] = value
|
||||
end
|
||||
add_version_option
|
||||
def initialize
|
||||
super 'rdoc', 'Generates RDoc for pre-installed gems',
|
||||
:version => Gem::Requirement.default,
|
||||
:include_rdoc => true, :include_ri => true
|
||||
|
||||
add_option('--all',
|
||||
'Generate RDoc/RI documentation for all',
|
||||
'installed gems') do |value, options|
|
||||
options[:all] = value
|
||||
end
|
||||
|
||||
add_option('--[no-]rdoc',
|
||||
'Include RDoc generated documents') do |value, options|
|
||||
options[:include_rdoc] = value
|
||||
end
|
||||
|
||||
add_option('--[no-]ri',
|
||||
'Include RI generated documents') do |value, options|
|
||||
options[:include_ri] = value
|
||||
end
|
||||
|
||||
add_version_option
|
||||
end
|
||||
|
||||
def arguments # :nodoc:
|
||||
"GEMNAME gem to generate documentation for (unless --all)"
|
||||
end
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--version '#{Gem::Requirement.default}' --rdoc --ri"
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} [args]"
|
||||
end
|
||||
|
||||
def execute
|
||||
if options[:all] then
|
||||
specs = Gem::SourceIndex.from_installed_gems.collect { |name, spec|
|
||||
spec
|
||||
}
|
||||
else
|
||||
gem_name = get_one_gem_name
|
||||
dep = Gem::Dependency.new gem_name, options[:version]
|
||||
specs = Gem::SourceIndex.from_installed_gems.search dep
|
||||
end
|
||||
|
||||
if specs.empty?
|
||||
fail "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
|
||||
end
|
||||
|
||||
def arguments # :nodoc:
|
||||
"GEMNAME gem to generate documentation for (unless --all)"
|
||||
end
|
||||
Gem::DocManager.update_ri_cache
|
||||
end
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--version '#{Gem::Requirement.default}' --rdoc --ri"
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} [args]"
|
||||
end
|
||||
|
||||
def execute
|
||||
if options[:all]
|
||||
specs = Gem::SourceIndex.from_installed_gems.collect { |name, spec|
|
||||
spec
|
||||
}
|
||||
else
|
||||
gem_name = get_one_gem_name
|
||||
specs = Gem::SourceIndex.from_installed_gems.search(
|
||||
gem_name, options[:version])
|
||||
end
|
||||
|
||||
if specs.empty?
|
||||
fail "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
|
||||
end
|
||||
|
||||
Gem::DocManager.update_ri_cache
|
||||
end
|
||||
|
||||
if options[:include_rdoc]
|
||||
specs.each do |spec|
|
||||
Gem::DocManager.new(spec).generate_rdoc
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
if options[:include_rdoc]
|
||||
specs.each do |spec|
|
||||
Gem::DocManager.new(spec).generate_rdoc
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,37 +1,31 @@
|
|||
require 'rubygems/command'
|
||||
require 'rubygems/commands/query_command'
|
||||
|
||||
module Gem
|
||||
module Commands
|
||||
class Gem::Commands::SearchCommand < Gem::Commands::QueryCommand
|
||||
|
||||
class SearchCommand < QueryCommand
|
||||
|
||||
def initialize
|
||||
super(
|
||||
'search',
|
||||
'Display all gems whose name contains STRING'
|
||||
)
|
||||
remove_option('--name-matches')
|
||||
end
|
||||
|
||||
def arguments # :nodoc:
|
||||
"STRING fragment of gem name to search for"
|
||||
end
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--local --no-details"
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} [STRING]"
|
||||
end
|
||||
|
||||
def execute
|
||||
string = get_one_optional_argument
|
||||
options[:name] = /#{string}/i
|
||||
super
|
||||
end
|
||||
end
|
||||
def initialize
|
||||
super 'search', 'Display all gems whose name contains STRING'
|
||||
|
||||
remove_option '--name-matches'
|
||||
end
|
||||
|
||||
def arguments # :nodoc:
|
||||
"STRING fragment of gem name to search for"
|
||||
end
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--local --no-details"
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} [STRING]"
|
||||
end
|
||||
|
||||
def execute
|
||||
string = get_one_optional_argument
|
||||
options[:name] = /#{string}/i
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,23 @@ class Gem::Commands::ServerCommand < Gem::Command
|
|||
super 'server', 'Documentation and gem repository HTTP server',
|
||||
:port => 8808, :gemdir => Gem.dir, :daemon => false
|
||||
|
||||
add_option '-p', '--port=PORT', Integer,
|
||||
OptionParser.accept :Port do |port|
|
||||
if port =~ /\A\d+\z/ then
|
||||
port = Integer port
|
||||
raise OptionParser::InvalidArgument, "#{port}: not a port number" if
|
||||
port > 65535
|
||||
|
||||
port
|
||||
else
|
||||
begin
|
||||
Socket.getservbyname port
|
||||
rescue SocketError => e
|
||||
raise OptionParser::InvalidArgument, "#{port}: no such named service"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
add_option '-p', '--port=PORT', :Port,
|
||||
'port to listen on' do |port, options|
|
||||
options[:port] = port
|
||||
end
|
||||
|
@ -37,6 +53,12 @@ for gem installation.
|
|||
|
||||
To install gems from a running server, use `gem install GEMNAME --source
|
||||
http://gem_server_host:8808`
|
||||
|
||||
You can set up a shortcut to gem server documentation using the URL:
|
||||
|
||||
http://localhost:8808/rdoc?q=%s - Firefox
|
||||
http://localhost:8808/rdoc?q=* - LaunchBar
|
||||
|
||||
EOF
|
||||
end
|
||||
|
||||
|
|
353
lib/rubygems/commands/setup_command.rb
Normal file
353
lib/rubygems/commands/setup_command.rb
Normal file
|
@ -0,0 +1,353 @@
|
|||
require 'rubygems/command'
|
||||
require 'fileutils'
|
||||
require 'rbconfig'
|
||||
require 'tmpdir'
|
||||
require 'pathname'
|
||||
|
||||
##
|
||||
# Installs RubyGems itself. This command is ordinarily only available from a
|
||||
# RubyGems checkout or tarball.
|
||||
|
||||
class Gem::Commands::SetupCommand < Gem::Command
|
||||
|
||||
def initialize
|
||||
super 'setup', 'Install RubyGems',
|
||||
:format_executable => true, :rdoc => true, :ri => true,
|
||||
:site_or_vendor => :sitelibdir,
|
||||
:destdir => '', :prefix => ''
|
||||
|
||||
add_option '--prefix=PREFIX',
|
||||
'Prefix path for installing RubyGems',
|
||||
'Will not affect gem repository location' do |prefix, options|
|
||||
options[:prefix] = File.expand_path prefix
|
||||
end
|
||||
|
||||
add_option '--destdir=DESTDIR',
|
||||
'Root directory to install RubyGems into',
|
||||
'Mainly used for packaging RubyGems' do |destdir, options|
|
||||
options[:destdir] = File.expand_path destdir
|
||||
end
|
||||
|
||||
add_option '--[no-]vendor',
|
||||
'Install into vendorlibdir not sitelibdir',
|
||||
'(Requires Ruby 1.8.7)' do |vendor, options|
|
||||
if vendor and Gem.ruby_version < Gem::Version.new('1.8.7') then
|
||||
raise OptionParser::InvalidOption,
|
||||
"requires ruby 1.8.7+ (you have #{Gem.ruby_version})"
|
||||
end
|
||||
|
||||
options[:site_or_vendor] = vendor ? :vendorlibdir : :sitelibdir
|
||||
end
|
||||
|
||||
add_option '--[no-]format-executable',
|
||||
'Makes `gem` match ruby',
|
||||
'If ruby is ruby18, gem will be gem18' do |value, options|
|
||||
options[:format_executable] = value
|
||||
end
|
||||
|
||||
add_option '--[no-]rdoc',
|
||||
'Generate RDoc documentation for RubyGems' do |value, options|
|
||||
options[:rdoc] = value
|
||||
end
|
||||
|
||||
add_option '--[no-]ri',
|
||||
'Generate RI documentation for RubyGems' do |value, options|
|
||||
options[:ri] = value
|
||||
end
|
||||
end
|
||||
|
||||
def check_ruby_version
|
||||
required_version = Gem::Requirement.new '>= 1.8.6'
|
||||
|
||||
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
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--format-executable --rdoc --ri"
|
||||
end
|
||||
|
||||
def description # :nodoc:
|
||||
<<-EOF
|
||||
Installs RubyGems itself.
|
||||
|
||||
RubyGems installs RDoc for itself in GEM_HOME. By default this is:
|
||||
#{Gem.dir}
|
||||
|
||||
If you prefer a different directory, set the GEM_HOME environment variable.
|
||||
|
||||
RubyGems will install the gem command with a name matching ruby's
|
||||
prefix and suffix. If ruby was installed as `ruby18`, gem will be
|
||||
installed as `gem18`.
|
||||
|
||||
By default, this RubyGems will install gem as:
|
||||
#{Gem.default_exec_format % 'gem'}
|
||||
EOF
|
||||
end
|
||||
|
||||
def execute
|
||||
install_destdir = options[:destdir]
|
||||
|
||||
unless install_destdir.empty? then
|
||||
ENV['GEM_HOME'] ||= File.join(install_destdir,
|
||||
Gem.default_dir.gsub(/^[a-zA-Z]:/, ''))
|
||||
end
|
||||
|
||||
check_ruby_version
|
||||
|
||||
if Gem.configuration.really_verbose then
|
||||
extend FileUtils::Verbose
|
||||
else
|
||||
extend FileUtils
|
||||
end
|
||||
|
||||
lib_dir, bin_dir = make_destination_dirs install_destdir
|
||||
|
||||
install_lib lib_dir
|
||||
|
||||
install_executables bin_dir
|
||||
|
||||
remove_old_bin_files bin_dir
|
||||
|
||||
remove_source_caches install_destdir
|
||||
|
||||
install_rdoc
|
||||
|
||||
say
|
||||
say "-" * 78
|
||||
say
|
||||
|
||||
release_notes = File.join Dir.pwd, 'doc', 'release_notes',
|
||||
"rel_#{Gem::RubyGemsVersion.gsub '.', '_'}.rdoc"
|
||||
|
||||
if File.exist? release_notes then
|
||||
say File.read(release_notes)
|
||||
else
|
||||
say "Oh-no! Unable to find release notes!"
|
||||
say "Looked in: #{release_notes}" if Gem.configuration.really_verbose
|
||||
end
|
||||
|
||||
say
|
||||
say "-" * 78
|
||||
say
|
||||
|
||||
say "RubyGems installed the following executables:"
|
||||
say @bin_file_names.map { |name| "\t#{name}\n" }
|
||||
say
|
||||
|
||||
unless @bin_file_names.grep(/#{File::SEPARATOR}gem$/) then
|
||||
say "If `gem` was installed by a previous RubyGems installation, you may need"
|
||||
say "to remove it by hand."
|
||||
say
|
||||
end
|
||||
end
|
||||
|
||||
def install_executables(bin_dir)
|
||||
say "Installing gem executable"
|
||||
|
||||
@bin_file_names = []
|
||||
|
||||
Dir.chdir 'bin' do
|
||||
bin_files = Dir['*']
|
||||
|
||||
bin_files.delete 'update_rubygems'
|
||||
|
||||
bin_files.each do |bin_file|
|
||||
bin_file_formatted = if options[:format_executable] then
|
||||
Gem.default_exec_format % bin_file
|
||||
else
|
||||
bin_file
|
||||
end
|
||||
|
||||
dest_file = File.join bin_dir, bin_file_formatted
|
||||
bin_tmp_file = File.join Dir.tmpdir, bin_file
|
||||
|
||||
begin
|
||||
bin = File.readlines bin_file
|
||||
bin[0] = "#!#{Gem.ruby}\n"
|
||||
|
||||
File.open bin_tmp_file, 'w' do |fp|
|
||||
fp.puts bin.join
|
||||
end
|
||||
|
||||
install bin_tmp_file, dest_file, :mode => 0755
|
||||
@bin_file_names << dest_file
|
||||
ensure
|
||||
rm bin_tmp_file
|
||||
end
|
||||
|
||||
next unless Gem.win_platform?
|
||||
|
||||
begin
|
||||
bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat"
|
||||
|
||||
File.open bin_cmd_file, 'w' do |file|
|
||||
file.puts <<-TEXT
|
||||
@ECHO OFF
|
||||
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
||||
@"#{File.basename(Gem.ruby).chomp('"')}" "#{dest_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
GOTO :EOF
|
||||
:WinNT
|
||||
@"#{File.basename(Gem.ruby).chomp('"')}" "%~dpn0" %*
|
||||
TEXT
|
||||
end
|
||||
|
||||
install bin_cmd_file, "#{dest_file}.bat", :mode => 0755
|
||||
ensure
|
||||
rm bin_cmd_file
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def install_lib(lib_dir)
|
||||
say "Installing RubyGems"
|
||||
|
||||
Dir.chdir 'lib' do
|
||||
lib_files = Dir[File.join('**', '*rb')]
|
||||
|
||||
lib_files.each do |lib_file|
|
||||
dest_file = File.join lib_dir, lib_file
|
||||
dest_dir = File.dirname dest_file
|
||||
mkdir_p dest_dir unless File.directory? dest_dir
|
||||
|
||||
install lib_file, dest_file, :mode => 0644
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def install_rdoc
|
||||
gem_doc_dir = File.join Gem.dir, 'doc'
|
||||
rubygems_name = "rubygems-#{Gem::RubyGemsVersion}"
|
||||
rubygems_doc_dir = File.join gem_doc_dir, rubygems_name
|
||||
|
||||
if File.writable? gem_doc_dir and
|
||||
(not File.exist? rubygems_doc_dir or
|
||||
File.writable? rubygems_doc_dir) then
|
||||
say "Removing old RubyGems RDoc and ri"
|
||||
Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir|
|
||||
rm_rf dir
|
||||
end
|
||||
|
||||
if options[:ri] then
|
||||
ri_dir = File.join rubygems_doc_dir, 'ri'
|
||||
say "Installing #{rubygems_name} ri into #{ri_dir}"
|
||||
run_rdoc '--ri', '--op', ri_dir
|
||||
end
|
||||
|
||||
if options[:rdoc] then
|
||||
rdoc_dir = File.join rubygems_doc_dir, 'rdoc'
|
||||
say "Installing #{rubygems_name} rdoc into #{rdoc_dir}"
|
||||
run_rdoc '--op', rdoc_dir
|
||||
end
|
||||
else
|
||||
say "Skipping RDoc generation, #{gem_doc_dir} not writable"
|
||||
say "Set the GEM_HOME environment variable if you want RDoc generated"
|
||||
end
|
||||
end
|
||||
|
||||
def make_destination_dirs(install_destdir)
|
||||
lib_dir = nil
|
||||
bin_dir = nil
|
||||
|
||||
prefix = options[:prefix]
|
||||
site_or_vendor = options[:site_or_vendor]
|
||||
|
||||
if prefix.empty? then
|
||||
lib_dir = Gem::ConfigMap[site_or_vendor]
|
||||
bin_dir = Gem::ConfigMap[:bindir]
|
||||
else
|
||||
# Apple installed RubyGems into libdir, and RubyGems <= 1.1.0 gets
|
||||
# confused about installation location, so switch back to
|
||||
# sitelibdir/vendorlibdir.
|
||||
if defined?(APPLE_GEM_HOME) and
|
||||
# just in case Apple and RubyGems don't get this patched up proper.
|
||||
(prefix == Gem::ConfigMap[:libdir] or
|
||||
# this one is important
|
||||
prefix == File.join(Gem::ConfigMap[:libdir], 'ruby')) then
|
||||
lib_dir = Gem::ConfigMap[site_or_vendor]
|
||||
bin_dir = Gem::ConfigMap[:bindir]
|
||||
else
|
||||
lib_dir = File.join prefix, 'lib'
|
||||
bin_dir = File.join prefix, 'bin'
|
||||
end
|
||||
end
|
||||
|
||||
unless install_destdir.empty? then
|
||||
lib_dir = File.join install_destdir, lib_dir.gsub(/^[a-zA-Z]:/, '')
|
||||
bin_dir = File.join install_destdir, bin_dir.gsub(/^[a-zA-Z]:/, '')
|
||||
end
|
||||
|
||||
mkdir_p lib_dir
|
||||
mkdir_p bin_dir
|
||||
|
||||
return lib_dir, bin_dir
|
||||
end
|
||||
|
||||
def remove_old_bin_files(bin_dir)
|
||||
old_bin_files = {
|
||||
'gem_mirror' => 'gem mirror',
|
||||
'gem_server' => 'gem server',
|
||||
'gemlock' => 'gem lock',
|
||||
'gemri' => 'ri',
|
||||
'gemwhich' => 'gem which',
|
||||
'index_gem_repository.rb' => 'gem generate_index',
|
||||
}
|
||||
|
||||
old_bin_files.each do |old_bin_file, new_name|
|
||||
old_bin_path = File.join bin_dir, old_bin_file
|
||||
next unless File.exist? old_bin_path
|
||||
|
||||
deprecation_message = "`#{old_bin_file}` has been deprecated. Use `#{new_name}` instead."
|
||||
|
||||
File.open old_bin_path, 'w' do |fp|
|
||||
fp.write <<-EOF
|
||||
#!#{Gem.ruby}
|
||||
|
||||
abort "#{deprecation_message}"
|
||||
EOF
|
||||
end
|
||||
|
||||
next unless Gem.win_platform?
|
||||
|
||||
File.open "#{old_bin_path}.bat", 'w' do |fp|
|
||||
fp.puts %{@ECHO.#{deprecation_message}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def remove_source_caches(install_destdir)
|
||||
if install_destdir.empty?
|
||||
require 'rubygems/source_info_cache'
|
||||
|
||||
user_cache_file = File.join(install_destdir,
|
||||
Gem::SourceInfoCache.user_cache_file)
|
||||
system_cache_file = File.join(install_destdir,
|
||||
Gem::SourceInfoCache.system_cache_file)
|
||||
|
||||
say "Removing old source_cache files"
|
||||
rm_f user_cache_file if File.writable? File.dirname(user_cache_file)
|
||||
rm_f system_cache_file if File.writable? File.dirname(system_cache_file)
|
||||
end
|
||||
end
|
||||
|
||||
def run_rdoc(*args)
|
||||
begin
|
||||
gem 'rdoc'
|
||||
rescue Gem::LoadError
|
||||
end
|
||||
|
||||
require 'rdoc/rdoc'
|
||||
|
||||
args << '--quiet'
|
||||
args << '--main' << 'README'
|
||||
args << '.' << 'README' << 'LICENSE.txt' << 'GPL.txt'
|
||||
|
||||
r = RDoc::RDoc.new
|
||||
r.document args
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -3,9 +3,12 @@ require 'rubygems/command'
|
|||
require 'rubygems/remote_fetcher'
|
||||
require 'rubygems/source_info_cache'
|
||||
require 'rubygems/spec_fetcher'
|
||||
require 'rubygems/local_remote_options'
|
||||
|
||||
class Gem::Commands::SourcesCommand < Gem::Command
|
||||
|
||||
include Gem::LocalRemoteOptions
|
||||
|
||||
def initialize
|
||||
super 'sources',
|
||||
'Manage the sources and cache file RubyGems uses to search for gems'
|
||||
|
@ -30,6 +33,8 @@ class Gem::Commands::SourcesCommand < Gem::Command
|
|||
add_option '-u', '--update', 'Update source cache' do |value, options|
|
||||
options[:update] = value
|
||||
end
|
||||
|
||||
add_proxy_option
|
||||
end
|
||||
|
||||
def defaults_str
|
||||
|
|
|
@ -12,7 +12,8 @@ class Gem::Commands::SpecificationCommand < Gem::Command
|
|||
|
||||
def initialize
|
||||
super 'specification', 'Display gem specification (in yaml)',
|
||||
:domain => :local, :version => Gem::Requirement.default
|
||||
:domain => :local, :version => Gem::Requirement.default,
|
||||
:format => :yaml
|
||||
|
||||
add_version_option('examine')
|
||||
add_platform_option
|
||||
|
@ -22,26 +23,62 @@ class Gem::Commands::SpecificationCommand < Gem::Command
|
|||
options[:all] = true
|
||||
end
|
||||
|
||||
add_option('--ruby', 'Output ruby format') do |value, options|
|
||||
options[:format] = :ruby
|
||||
end
|
||||
|
||||
add_option('--yaml', 'Output RUBY format') do |value, options|
|
||||
options[:format] = :yaml
|
||||
end
|
||||
|
||||
add_option('--marshal', 'Output Marshal format') do |value, options|
|
||||
options[:format] = :marshal
|
||||
end
|
||||
|
||||
add_local_remote_options
|
||||
end
|
||||
|
||||
def arguments # :nodoc:
|
||||
"GEMFILE name of gem to show the gemspec for"
|
||||
<<-ARGS
|
||||
GEMFILE name of gem to show the gemspec for
|
||||
FIELD name of gemspec field to show
|
||||
ARGS
|
||||
end
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--local --version '#{Gem::Requirement.default}'"
|
||||
"--local --version '#{Gem::Requirement.default}' --yaml"
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} [GEMFILE]"
|
||||
"#{program_name} [GEMFILE] [FIELD]"
|
||||
end
|
||||
|
||||
def execute
|
||||
specs = []
|
||||
gem = get_one_gem_name
|
||||
gem = options[:args].shift
|
||||
|
||||
unless gem then
|
||||
raise Gem::CommandLineError,
|
||||
"Please specify a gem name or file on the command line"
|
||||
end
|
||||
|
||||
dep = Gem::Dependency.new gem, options[:version]
|
||||
|
||||
field = get_one_optional_argument
|
||||
|
||||
if field then
|
||||
field = field.intern
|
||||
|
||||
if options[:format] == :ruby then
|
||||
raise Gem::CommandLineError, "--ruby and FIELD are mutually exclusive"
|
||||
end
|
||||
|
||||
unless Gem::Specification.attribute_names.include? field then
|
||||
raise Gem::CommandLineError,
|
||||
"no field %p on Gem::Specification" % field.to_s
|
||||
end
|
||||
end
|
||||
|
||||
if local? then
|
||||
if File.exist? gem then
|
||||
specs << Gem::Format.from_file_by_path(gem).spec rescue nil
|
||||
|
@ -63,7 +100,17 @@ class Gem::Commands::SpecificationCommand < Gem::Command
|
|||
terminate_interaction 1
|
||||
end
|
||||
|
||||
output = lambda { |s| say s.to_yaml; say "\n" }
|
||||
output = lambda do |s|
|
||||
s = s.send field if field
|
||||
|
||||
say case options[:format]
|
||||
when :ruby then s.to_ruby
|
||||
when :marshal then Marshal.dump s
|
||||
else s.to_yaml
|
||||
end
|
||||
|
||||
say "\n"
|
||||
end
|
||||
|
||||
if options[:all] then
|
||||
specs.each(&output)
|
||||
|
|
|
@ -2,72 +2,82 @@ require 'rubygems/command'
|
|||
require 'rubygems/version_option'
|
||||
require 'rubygems/uninstaller'
|
||||
|
||||
module Gem
|
||||
module Commands
|
||||
class UninstallCommand < Command
|
||||
##
|
||||
# Gem uninstaller command line tool
|
||||
#
|
||||
# See `gem help uninstall`
|
||||
|
||||
include VersionOption
|
||||
class Gem::Commands::UninstallCommand < Gem::Command
|
||||
|
||||
def initialize
|
||||
super 'uninstall', 'Uninstall gems from the local repository',
|
||||
:version => Gem::Requirement.default
|
||||
include Gem::VersionOption
|
||||
|
||||
add_option('-a', '--[no-]all',
|
||||
'Uninstall all matching versions'
|
||||
) do |value, options|
|
||||
options[:all] = value
|
||||
end
|
||||
def initialize
|
||||
super 'uninstall', 'Uninstall gems from the local repository',
|
||||
:version => Gem::Requirement.default, :user_install => true
|
||||
|
||||
add_option('-I', '--[no-]ignore-dependencies',
|
||||
'Ignore dependency requirements while',
|
||||
'uninstalling') do |value, options|
|
||||
options[:ignore] = value
|
||||
end
|
||||
add_option('-a', '--[no-]all',
|
||||
'Uninstall all matching versions'
|
||||
) do |value, options|
|
||||
options[:all] = value
|
||||
end
|
||||
|
||||
add_option('-x', '--[no-]executables',
|
||||
'Uninstall applicable executables without',
|
||||
'confirmation') do |value, options|
|
||||
options[:executables] = value
|
||||
end
|
||||
add_option('-I', '--[no-]ignore-dependencies',
|
||||
'Ignore dependency requirements while',
|
||||
'uninstalling') do |value, options|
|
||||
options[:ignore] = value
|
||||
end
|
||||
|
||||
add_option('-i', '--install-dir DIR',
|
||||
'Directory to uninstall gem from') do |value, options|
|
||||
options[:install_dir] = File.expand_path(value)
|
||||
end
|
||||
add_option('-x', '--[no-]executables',
|
||||
'Uninstall applicable executables without',
|
||||
'confirmation') do |value, options|
|
||||
options[:executables] = value
|
||||
end
|
||||
|
||||
add_option('-n', '--bindir DIR',
|
||||
'Directory to remove binaries from') do |value, options|
|
||||
options[:bin_dir] = File.expand_path(value)
|
||||
end
|
||||
add_option('-i', '--install-dir DIR',
|
||||
'Directory to uninstall gem from') do |value, options|
|
||||
options[:install_dir] = File.expand_path(value)
|
||||
end
|
||||
|
||||
add_version_option
|
||||
add_platform_option
|
||||
end
|
||||
add_option('-n', '--bindir DIR',
|
||||
'Directory to remove binaries from') do |value, options|
|
||||
options[:bin_dir] = File.expand_path(value)
|
||||
end
|
||||
|
||||
def arguments # :nodoc:
|
||||
"GEMNAME name of gem to uninstall"
|
||||
end
|
||||
add_option('--[no-]user-install',
|
||||
'Uninstall from user\'s home directory',
|
||||
'in addition to GEM_HOME.') do |value, options|
|
||||
options[:user_install] = value
|
||||
end
|
||||
|
||||
def defaults_str # :nodoc:
|
||||
"--version '#{Gem::Requirement.default}' --no-force " \
|
||||
"--install-dir #{Gem.dir}"
|
||||
end
|
||||
add_version_option
|
||||
add_platform_option
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} GEMNAME [GEMNAME ...]"
|
||||
end
|
||||
def arguments # :nodoc:
|
||||
"GEMNAME name of gem to uninstall"
|
||||
end
|
||||
|
||||
def execute
|
||||
get_all_gem_names.each do |gem_name|
|
||||
begin
|
||||
Gem::Uninstaller.new(gem_name, options).uninstall
|
||||
rescue Gem::GemNotInHomeException => e
|
||||
spec = e.spec
|
||||
alert("In order to remove #{spec.name}, please execute:\n" \
|
||||
"\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}")
|
||||
end
|
||||
end
|
||||
def defaults_str # :nodoc:
|
||||
"--version '#{Gem::Requirement.default}' --no-force " \
|
||||
"--install-dir #{Gem.dir}\n" \
|
||||
"--user-install"
|
||||
end
|
||||
|
||||
def usage # :nodoc:
|
||||
"#{program_name} GEMNAME [GEMNAME ...]"
|
||||
end
|
||||
|
||||
def execute
|
||||
get_all_gem_names.each do |gem_name|
|
||||
begin
|
||||
Gem::Uninstaller.new(gem_name, options).uninstall
|
||||
rescue Gem::GemNotInHomeException => e
|
||||
spec = e.spec
|
||||
alert("In order to remove #{spec.name}, please execute:\n" \
|
||||
"\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class Gem::Commands::UnpackCommand < Gem::Command
|
|||
:version => Gem::Requirement.default,
|
||||
:target => Dir.pwd
|
||||
|
||||
add_option('--target', 'target directory for unpacking') do |value, options|
|
||||
add_option('--target=DIR', 'target directory for unpacking') do |value, options|
|
||||
options[:target] = value
|
||||
end
|
||||
|
||||
|
@ -35,18 +35,20 @@ class Gem::Commands::UnpackCommand < Gem::Command
|
|||
# TODO: allow, e.g., 'gem unpack rake-0.3.1'. Find a general solution for
|
||||
# this, so that it works for uninstall as well. (And check other commands
|
||||
# at the same time.)
|
||||
def execute
|
||||
gemname = get_one_gem_name
|
||||
path = get_path(gemname, options[:version])
|
||||
|
||||
if path then
|
||||
basename = File.basename(path).sub(/\.gem$/, '')
|
||||
target_dir = File.expand_path File.join(options[:target], basename)
|
||||
FileUtils.mkdir_p target_dir
|
||||
Gem::Installer.new(path, :unpack => true).unpack target_dir
|
||||
say "Unpacked gem: '#{target_dir}'"
|
||||
else
|
||||
alert_error "Gem '#{gemname}' not installed."
|
||||
def execute
|
||||
get_all_gem_names.each do |name|
|
||||
path = get_path name, options[:version]
|
||||
|
||||
if path then
|
||||
basename = File.basename(path).sub(/\.gem$/, '')
|
||||
target_dir = File.expand_path File.join(options[:target], basename)
|
||||
FileUtils.mkdir_p target_dir
|
||||
Gem::Installer.new(path, :unpack => true).unpack target_dir
|
||||
say "Unpacked gem: '#{target_dir}'"
|
||||
else
|
||||
alert_error "Gem '#{name}' not installed."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ class Gem::Commands::UpdateCommand < Gem::Command
|
|||
super 'update',
|
||||
'Update the named gems (or all installed gems) in the local repository',
|
||||
:generate_rdoc => true,
|
||||
:generate_ri => true,
|
||||
:force => false,
|
||||
:test => false
|
||||
:generate_ri => true,
|
||||
:force => false,
|
||||
:test => false
|
||||
|
||||
add_install_update_options
|
||||
|
||||
|
@ -80,20 +80,27 @@ class Gem::Commands::UpdateCommand < Gem::Command
|
|||
|
||||
gems_to_update.uniq.sort.each do |name|
|
||||
next if updated.any? { |spec| spec.name == name }
|
||||
success = false
|
||||
|
||||
say "Updating #{name}"
|
||||
installer.install name
|
||||
begin
|
||||
installer.install name
|
||||
success = true
|
||||
rescue Gem::InstallError => e
|
||||
alert_error "Error installing #{name}:\n\t#{e.message}"
|
||||
success = false
|
||||
end
|
||||
|
||||
installer.installed_gems.each do |spec|
|
||||
updated << spec
|
||||
say "Successfully installed #{spec.full_name}"
|
||||
say "Successfully installed #{spec.full_name}" if success
|
||||
end
|
||||
end
|
||||
|
||||
if gems_to_update.include? "rubygems-update" then
|
||||
Gem.source_index.refresh!
|
||||
|
||||
update_gems = Gem.source_index.search 'rubygems-update'
|
||||
update_gems = Gem.source_index.find_name 'rubygems-update'
|
||||
|
||||
latest_update_gem = update_gems.sort_by { |s| s.version }.last
|
||||
|
||||
|
@ -106,6 +113,20 @@ class Gem::Commands::UpdateCommand < Gem::Command
|
|||
say "Nothing to update"
|
||||
else
|
||||
say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}"
|
||||
|
||||
if options[:generate_ri] then
|
||||
updated.each do |gem|
|
||||
Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
|
||||
end
|
||||
|
||||
Gem::DocManager.update_ri_cache
|
||||
end
|
||||
|
||||
if options[:generate_rdoc] then
|
||||
updated.each do |gem|
|
||||
Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,7 +46,7 @@ class Gem::Commands::WhichCommand < Gem::Command
|
|||
end
|
||||
|
||||
say "(checking gem #{spec.full_name} for #{arg})" if
|
||||
Gem.configuration.verbose
|
||||
Gem.configuration.verbose and $stdout.tty?
|
||||
end
|
||||
|
||||
paths = find_paths arg, dirs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue