diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-29 06:52:18 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-29 06:52:18 +0000 |
commit | 9694bb8cac12969300692dac5a1cf7aa4e3a46cd () | |
tree | c3cb423d701f7049ba9382de052e2a937cd1302d /lib/rubygems/commands | |
parent | 3f606b7063fc7a8b191556365ad343a314719a8d (diff) |
* lib/rubygems*: Updated to RubyGems 2.0
* test/rubygems*: ditto. * common.mk (prelude): Updated for RubyGems 2.0 source rearrangement. * tool/change_maker.rb: Allow invalid UTF-8 characters in source files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
29 files changed, 776 insertions, 453 deletions
@@ -1,5 +1,5 @@ require 'rubygems/command' -require 'rubygems/builder' class Gem::Commands::BuildCommand < Gem::Command @@ -22,11 +22,11 @@ class Gem::Commands::BuildCommand < Gem::Command def execute gemspec = get_one_gem_name - if File.exist? gemspec - spec = load_gemspec gemspec if spec then - Gem::Builder.new(spec).build options[:force] else alert_error "Error loading gemspec. Aborting." terminate_interaction 1 @@ -37,23 +37,5 @@ class Gem::Commands::BuildCommand < Gem::Command end end - def load_gemspec filename - if yaml?(filename) - open(filename) do |f| - begin - Gem::Specification.from_yaml(f) - rescue Gem::EndOfYAMLException - nil - end - end - else - Gem::Specification.load(filename) # can return nil - end - end - - def yaml?(filename) - line = open(filename) { |f| line = f.gets } - result = line =~ %r{!ruby/object:Gem::Specification} - result - end end @@ -4,82 +4,224 @@ require 'rubygems/security' class Gem::Commands::CertCommand < Gem::Command def initialize - super 'cert', 'Manage RubyGems certificates and signing settings' - - add_option('-a', '--add CERT', - 'Add a trusted certificate.') do |value, options| - cert = OpenSSL::X509::Certificate.new(File.read(value)) - Gem::Security.add_trusted_cert(cert) - say "Added '#{cert.subject.to_s}'" - end - - add_option('-l', '--list', - 'List trusted certificates.') do |value, options| - glob_str = File::join(Gem::Security::OPT[:trust_dir], '*.pem') - Dir::glob(glob_str) do |path| - begin - cert = OpenSSL::X509::Certificate.new(File.read(path)) - # this could probably be formatted more gracefully - say cert.subject.to_s - rescue OpenSSL::X509::CertificateError - next - end end end - add_option('-r', '--remove STRING', - 'Remove trusted certificates containing', - 'STRING.') do |value, options| - trust_dir = Gem::Security::OPT[:trust_dir] - glob_str = File::join(trust_dir, '*.pem') - - Dir::glob(glob_str) do |path| - begin - cert = OpenSSL::X509::Certificate.new(File.read(path)) - if cert.subject.to_s.downcase.index(value) - say "Removed '#{cert.subject.to_s}'" - File.unlink(path) - end - rescue OpenSSL::X509::CertificateError - next - end end end add_option('-b', '--build EMAIL_ADDR', 'Build private key and self-signed', - 'certificate for EMAIL_ADDR.') do |value, options| - vals = Gem::Security.build_self_signed_cert(value) - FileUtils.chmod 0600, vals[:key_path] - say "Public Cert: #{vals[:cert_path]}" - say "Private Key: #{vals[:key_path]}" - say "Don't forget to move the key file to somewhere private..." end - add_option('-C', '--certificate CERT', - 'Certificate for --sign command.') do |value, options| - cert = OpenSSL::X509::Certificate.new(File.read(value)) options[:issuer_cert] = cert end - add_option('-K', '--private-key KEY', - 'Private key for --sign command.') do |value, options| - key = OpenSSL::PKey::RSA.new(File.read(value)) - options[:issuer_key] = key end - add_option('-s', '--sign NEWCERT', - 'Sign a certificate with my key and', - 'certificate.') do |value, options| - cert = OpenSSL::X509::Certificate.new(File.read(value)) - my_cert = options[:issuer_cert] - my_key = options[:issuer_key] - cert = Gem::Security.sign_cert(cert, my_key, my_cert) - File.open(value, 'wb') { |file| file.write(cert.to_pem) } end end def execute end end @@ -8,13 +8,7 @@ class Gem::Commands::CheckCommand < Gem::Command def initialize super 'check', 'Check installed gems', - :verify => false, :alien => false - - add_option( '--verify FILE', - 'Verify gem file against its internal', - 'checksum') do |value, options| - options[:verify] = value - end add_option('-a', '--alien', "Report 'unmanaged' or rogue files in the", "gem repository") do |value, options| @@ -25,40 +19,21 @@ class Gem::Commands::CheckCommand < Gem::Command end def execute - if options[:alien] - say "Performing the 'alien' operation" - 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 " #{error_entry.path}:" - say " #{error_entry.problem}" - end - else - say "#{key} is error-free" if Gem.configuration.verbose end - say - end - end - - if options[:verify] - gem_name = options[:verify] - unless gem_name - alert_error "Must specify a .gem file with --verify NAME" - return - end - unless File.exist?(gem_name) - alert_error "Unknown file: #{gem_name}." - return - end - say "Verifying gem: '#{gem_name}'" - begin - Gem::Validator.new.verify_gem_file(gem_name) - rescue Exception - alert_error "#{gem_name} is invalid." end end end @@ -26,6 +26,9 @@ class Gem::Commands::CleanupCommand < Gem::Command <<-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 @@ -56,6 +59,8 @@ installed elsewhere in GEM_PATH the cleanup command won't touch it. primary_gems[spec.name].version != spec.version } deplist = Gem::DependencyList.new gems_to_cleanup.uniq.each do |spec| deplist.add spec end @@ -64,6 +69,8 @@ installed elsewhere in GEM_PATH the cleanup command won't touch it. original_path = Gem.path deps.each do |spec| if options[:dryrun] then say "Dry Run Mode: Would uninstall #{spec.full_name}" else @@ -1,3 +1,4 @@ require 'rubygems/command' require 'rubygems/version_option' @@ -80,19 +81,36 @@ class Gem::Commands::ContentsCommand < Gem::Command terminate_interaction 1 if gem_names.length == 1 end - gem_path = spec.full_gem_path - extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only] - glob = "#{gem_path}#{extra}/**/*" - files = Dir[glob] - - gem_path = File.join gem_path, '' # add trailing / if missing - - files.sort.each do |file| - next if File.directory? file - file = file.sub gem_path, '' unless options[:prefix] - say file end end end @@ -71,14 +71,9 @@ class Gem::Commands::DependencyCommand < Gem::Command if remote? and not options[:reverse_dependencies] then fetcher = Gem::SpecFetcher.fetcher - # REFACTOR: fetcher.find_specs_matching => specs - specs_and_sources = fetcher.find_matching(dependency, - dependency.specific?, true, - dependency.prerelease?) - - specs.concat specs_and_sources.map { |spec_tuple, source_uri| - fetcher.fetch_spec spec_tuple, URI.parse(source_uri) - } end if specs.empty? then @@ -24,33 +24,38 @@ class Gem::Commands::EnvironmentCommand < Gem::Command The RubyGems environment can be controlled through command line arguments, gemrc files, environment variables and built-in defaults. -Command line argument defaults and some RubyGems defaults can be set in -~/.gemrc file for individual users and a /etc/gemrc for all users. A gemrc -is a YAML file with the following YAML keys: :sources: A YAML array of remote gem repositories to install gems from - :verbose: Verbosity of the gem command. false, true, and :really are the levels :update_sources: Enable/disable automatic updating of repository metadata :backtrace: Print backtrace when RubyGems encounters an error :gempath: The paths in which to look for gems - gem_command: A string containing arguments for the specified gem command Example: :verbose: false install: --no-wrappers update: --no-wrappers RubyGems' default local repository can be overridden with the GEM_PATH and -GEM_HOME environment variables. GEM_HOME sets the default repository to -install into. GEM_PATH allows multiple local repositories to be searched for gems. If you are behind a proxy server, RubyGems uses the HTTP_PROXY, HTTP_PROXY_USER and HTTP_PROXY_PASS environment variables to discover the proxy server. If you are packaging RubyGems all of RubyGems' defaults are in lib/rubygems/defaults.rb. You may override these in lib/rubygems/defaults/operating_system.rb @@ -74,7 +79,7 @@ lib/rubygems/defaults/operating_system.rb when /^gempath/, /^path/, /^GEM_PATH/ then out << Gem.path.join(File::PATH_SEPARATOR) when /^remotesources/ then - out << Gem.sources.join("\n") when /^platform/ then out << Gem.platforms.join(File::PATH_SEPARATOR) when nil then @@ -34,7 +34,6 @@ class Gem::Commands::FetchCommand < Gem::Command def execute version = options[:version] || Gem::Requirement.default - all = Gem::Requirement.default != version platform = Gem.platforms.last gem_names = get_all_gem_names @@ -43,32 +42,20 @@ class Gem::Commands::FetchCommand < Gem::Command dep = Gem::Dependency.new gem_name, version dep.prerelease = options[:prerelease] - specs_and_sources, errors = - Gem::SpecFetcher.fetcher.fetch_with_errors(dep, all, true, - dep.prerelease?) - if platform then filtered = specs_and_sources.select { |s,| s.platform == platform } specs_and_sources = filtered unless filtered.empty? end - spec, source_uri = specs_and_sources.sort_by { |s,| s.version }.last if spec.nil? then show_lookup_failure gem_name, version, errors, options[:domain] next end - file = "#{spec.full_name}.gem" - remote_path = URI.parse(source_uri) + "gems/#{file}" - - fetch = Gem::RemoteFetcher.fetcher - - gem = fetch.fetch_path remote_path.to_s - - File.open file, "wb" do |f| - f.write gem - end say "Downloaded #{spec.full_name}" end @@ -11,29 +11,16 @@ class Gem::Commands::GenerateIndexCommand < Gem::Command def initialize super 'generate_index', 'Generates the index files for a gem server 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 Marshal.4.8' 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 @@ -42,27 +29,10 @@ class Gem::Commands::GenerateIndexCommand < Gem::Command '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 . --legacy --modern" end def description # :nodoc: @@ -85,25 +55,15 @@ When done, it will generate a set of files like this: prerelease_specs.<version>.gz # prerelease specs index quick/Marshal.<version>/<gemname>.gemspec.rz # Marshal quick index file - # these files support legacy RubyGems - Marshal.<version> - Marshal.<version>.Z # Marshal 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. - -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 @@ -37,7 +37,7 @@ Some examples of 'gem' usage. * Create a gem: - See http://rubygems.rubyforge.org/wiki/wiki.pl?CreateAGemInTenMinutes * See information about RubyGems: @@ -1,10 +1,11 @@ require 'rubygems/command' -require 'rubygems/doc_manager' require 'rubygems/install_update_options' require 'rubygems/dependency_installer' require 'rubygems/local_remote_options' require 'rubygems/validator' require 'rubygems/version_option' ## # Gem installer command line tool @@ -13,14 +14,14 @@ require 'rubygems/version_option' class Gem::Commands::InstallCommand < Gem::Command include Gem::VersionOption include Gem::LocalRemoteOptions include Gem::InstallUpdateOptions def initialize defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({ - :generate_rdoc => true, - :generate_ri => true, :format_executable => false, :version => Gem::Requirement.default, }) @@ -32,6 +33,14 @@ class Gem::Commands::InstallCommand < Gem::Command add_platform_option add_version_option add_prerelease_option "to be installed. (Only for listed gems)" end def arguments # :nodoc: @@ -39,7 +48,7 @@ class Gem::Commands::InstallCommand < Gem::Command end def defaults_str # :nodoc: - "--both --version '#{Gem::Requirement.default}' --rdoc --ri --no-force\n" \ "--install-dir #{Gem.dir}" end @@ -100,31 +109,73 @@ to write the specification by hand. For example: "#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags" end def execute - if options[:include_dependencies] then - alert "`gem install -y` is now default and will be removed" - alert "use --ignore-dependencies to install only the gems you list" end - installed_gems = [] ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9' exit_code = 0 - get_all_gem_names.each do |gem_name| begin next if options[:conservative] and - not Gem::Dependency.new(gem_name, options[:version]).matching_specs.empty? inst = Gem::DependencyInstaller.new options - inst.install gem_name, options[:version] - inst.installed_gems.each do |spec| - say "Successfully installed #{spec.full_name}" - end - installed_gems.push(*inst.installed_gems) rescue Gem::InstallError => e alert_error "Error installing #{gem_name}:\n\t#{e.message}" exit_code |= 1 @@ -135,27 +186,9 @@ to write the specification by hand. For example: end end - unless installed_gems.empty? then - gems = installed_gems.length == 1 ? 'gem' : 'gems' - say "#{installed_gems.length} #{gems} installed" - - # 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 - 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 - end - end end raise Gem::SystemExitException, exit_code @@ -7,8 +7,9 @@ require 'rubygems/commands/query_command' class Gem::Commands::ListCommand < Gem::Commands::QueryCommand - def initialize - super 'list', 'Display gems whose name starts with STRING' remove_option('--name-matches') end @@ -26,8 +27,9 @@ class Gem::Commands::ListCommand < Gem::Commands::QueryCommand end def execute - string = get_one_optional_argument || '' - options[:name] = /^#{string}/i super end @@ -30,7 +30,7 @@ generated. Example: - gemlock rails-1.0.0 > lockdown.rb will produce in lockdown.rb: @@ -0,0 +1,17 @@ @@ -19,12 +19,15 @@ class Gem::Commands::OutdatedCommand < Gem::Command Gem::Specification.outdated.sort.each do |name| local = Gem::Specification.find_all_by_name(name).max dep = Gem::Dependency.new local.name, ">= #{local.version}" - remotes = Gem::SpecFetcher.fetcher.fetch dep next if remotes.empty? - remote = remotes.last.first - say "#{local.name} (#{local.version} < #{remote.version})" end end end @@ -14,6 +14,10 @@ class Gem::Commands::OwnerCommand < Gem::Command "GEM gem to manage owners for" end def initialize super 'owner', description add_proxy_option @@ -63,12 +67,16 @@ class Gem::Commands::OwnerCommand < Gem::Command 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", api_key end - - with_response response end end @@ -1,5 +1,5 @@ require 'rubygems/command' -require 'rubygems/format' require 'rubygems/installer' require 'rubygems/version_option' @@ -24,6 +24,11 @@ class Gem::Commands::PristineCommand < Gem::Command options[:extensions] = value end add_version_option('restore to', 'pristine condition') end @@ -78,6 +83,11 @@ extensions. say "Restoring gems to pristine condition..." specs.each do |spec| unless spec.extensions.empty? or options[:extensions] then say "Skipped #{spec.full_name}, it needs to compile an extension" next @@ -101,8 +111,13 @@ extensions. :wrappers => true, :force => true, :install_dir => spec.base_dir, - :env_shebang => installer_env_shebang) - installer.install say "Restored #{spec.full_name}" end @@ -1,6 +1,7 @@ require 'rubygems/command' require 'rubygems/local_remote_options' require 'rubygems/gemcutter_utilities' class Gem::Commands::PushCommand < Gem::Command include Gem::LocalRemoteOptions @@ -39,13 +40,23 @@ class Gem::Commands::PushCommand < Gem::Command def send_gem name args = [:post, "api/v1/gems"] - args << options[:host] if options[:host] if Gem.latest_rubygems_version < Gem::Version.new(Gem::VERSION) then alert_error "Using beta/ version of rubygems. Not pushing." terminate_interaction 1 end response = rubygems_api_request(*args) do |request| request.body = Gem.read_binary name request.add_field "Content-Length", request.body.size @@ -21,6 +21,10 @@ class Gem::Commands::QueryCommand < Gem::Command options[:installed] = value end add_version_option command, "for use with --installed" add_option('-n', '--name-matches REGEXP', @@ -80,6 +84,7 @@ class Gem::Commands::QueryCommand < Gem::Command req = Gem::Requirement.default # TODO: deprecate for real dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req } if local? then if prerelease and not both? then @@ -97,7 +102,7 @@ class Gem::Commands::QueryCommand < Gem::Command } spec_tuples = specs.map do |spec| - [[spec.name, spec.version, spec.original_platform, spec], :local] end output_query_results spec_tuples @@ -110,13 +115,27 @@ class Gem::Commands::QueryCommand < Gem::Command say end - all = options[:all] - 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 output_query_results spec_tuples end @@ -135,32 +154,30 @@ class Gem::Commands::QueryCommand < Gem::Command output = [] versions = Hash.new { |h,name| h[name] = [] } - spec_tuples.each do |spec_tuple, source_uri| - versions[spec_tuple.first] << [spec_tuple, source_uri] end - versions = versions.sort_by do |(name,_),_| - name.downcase end versions.each do |gem_name, matching_tuples| - matching_tuples = matching_tuples.sort_by do |(_, version,_),_| - version - end.reverse platforms = Hash.new { |h,version| h[version] = [] } - matching_tuples.map do |(_, version, platform,_),_| - platforms[version] << platform if platform end seen = {} - matching_tuples.delete_if do |(_, version,_),_| - if seen[version] then true else - seen[version] = true false end end @@ -169,7 +186,7 @@ class Gem::Commands::QueryCommand < Gem::Command if options[:versions] then list = if platforms.empty? or options[:details] then - matching_tuples.map { |(_, version,_),_| version }.uniq else platforms.sort.reverse.map do |version, pls| if pls == [Gem::Platform::RUBY] then @@ -188,12 +205,11 @@ class Gem::Commands::QueryCommand < Gem::Command if options[:details] then detail_tuple = matching_tuples.first - spec = if detail_tuple.first.length == 4 then - detail_tuple.first.last - else - uri = URI.parse detail_tuple.last - Gem::SpecFetcher.fetcher.fetch_spec detail_tuple.first, uri - end entry << "\n" @@ -243,9 +259,9 @@ class Gem::Commands::QueryCommand < Gem::Command entry << "\n" << " Installed at: #{loaded_from}" else label = 'Installed at' - matching_tuples.each do |(_,version,_,s),| loaded_from = File.dirname File.dirname(s.loaded_from) - entry << "\n" << " #{label} (#{version}): #{loaded_from}" label = ' ' * label.length end end @@ -1,6 +1,6 @@ require 'rubygems/command' require 'rubygems/version_option' -require 'rubygems/doc_manager' class Gem::Commands::RdocCommand < Gem::Command include Gem::VersionOption @@ -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, :overwrite => false add_option('--all', 'Generate RDoc/RI documentation for all', @@ -39,7 +39,7 @@ class Gem::Commands::RdocCommand < Gem::Command end def defaults_str # :nodoc: - "--version '#{Gem::Requirement.default}' --rdoc --ri --no-overwrite" end def description # :nodoc: @@ -54,37 +54,32 @@ The rdoc command builds RDoc and RI documentation for installed gems. Use 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? - raise "Failed to find gem #{gem_name} to generate RDoc for #{options[:version]}" - end - if options[:include_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.sort.each do |spec| - doc = Gem::DocManager.new(spec) - doc.generate_rdoc if options[:overwrite] || !doc.rdoc_installed? end end - - true end end @@ -1,30 +1,16 @@ require 'rubygems/command' -require 'rubygems/commands/query_command' -class Gem::Commands::SearchCommand < Gem::Commands::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 @@ -78,7 +78,7 @@ You can set up a shortcut to gem server documentation using the URL: end def execute - options[:gemdir] << Gem.dir if options[:gemdir].empty? Gem::Server.run options end @@ -5,14 +5,22 @@ require 'rubygems/command' # RubyGems checkout or tarball. class Gem::Commands::SetupCommand < Gem::Command def initialize require 'tmpdir' 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', @@ -37,14 +45,37 @@ class Gem::Commands::SetupCommand < Gem::Command 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 @@ -58,7 +89,7 @@ class Gem::Commands::SetupCommand < Gem::Command end def defaults_str # :nodoc: - "--format-executable --rdoc --ri" end def description # :nodoc: @@ -110,7 +141,7 @@ By default, this RubyGems will install gem as: uninstall_old_gemcutter - install_rdoc say if @verbose then @@ -118,14 +149,30 @@ By default, this RubyGems will install gem as: say end release_notes = File.join Dir.pwd, 'History.txt' release_notes = if File.exist? release_notes then - open release_notes do |io| - text = io.gets '===' - text << io.gets('===') - text[0...-3].sub(/^# coding:.*?^=/m, '') end else "Oh-no! Unable to find release notes!" end @@ -145,6 +192,31 @@ By default, this RubyGems will install gem as: say "to remove it by hand." say end end def install_executables(bin_dir) @@ -165,7 +237,7 @@ By default, this RubyGems will install gem as: 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 @@ -209,10 +281,7 @@ TEXT say "Installing RubyGems" if @verbose Dir.chdir 'lib' do - lib_files = Dir[File.join('**', '*rb')] - - # Be sure to include our SSL ca bundles - lib_files += Dir[File.join('**', '*pem')] lib_files.each do |lib_file| dest_file = File.join lib_dir, lib_file @@ -229,6 +298,12 @@ TEXT rubygems_name = "rubygems-#{Gem::VERSION}" 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 @@ -237,21 +312,26 @@ TEXT rm_rf dir end - if options[:ri] then - ri_dir = File.join rubygems_doc_dir, 'ri' - say "Installing #{rubygems_name} ri into #{ri_dir}" if @verbose - 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}" if @verbose - run_rdoc '--op', rdoc_dir end elsif @verbose then 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) @@ -331,23 +411,6 @@ abort "#{deprecation_message}" end end - def run_rdoc(*args) - begin - gem 'rdoc' - rescue Gem::LoadError - end - - require 'rdoc/rdoc' - - args << '--main' << 'README.rdoc' << '--quiet' - args << '.' - args << 'README.rdoc' << 'UPGRADING.rdoc' - args << 'LICENSE.txt' << 'MIT.txt' << 'History.txt' - - r = RDoc::RDoc.new - r.document args - end - def uninstall_old_gemcutter require 'rubygems/uninstaller' @@ -48,7 +48,7 @@ class Gem::Commands::SourcesCommand < Gem::Command options[:update]) if options[:clear_all] then - path = Gem::SpecFetcher.fetcher.dir FileUtils.rm_rf path unless File.exist? path then @@ -64,16 +64,19 @@ class Gem::Commands::SourcesCommand < Gem::Command end end - if options[:add] then - source_uri = options[:add] - uri = URI.parse source_uri begin - Gem::SpecFetcher.fetcher.load_specs uri, 'specs' - Gem.sources << source_uri - Gem.configuration.write - say "#{source_uri} added to sources" rescue URI::Error, ArgumentError say "#{source_uri} is not a URI" terminate_interaction 1 @@ -97,12 +100,9 @@ class Gem::Commands::SourcesCommand < Gem::Command end if options[:update] then - fetcher = Gem::SpecFetcher.fetcher - - Gem.sources.each do |update_uri| - update_uri = URI.parse update_uri - fetcher.load_specs update_uri, 'specs' - fetcher.load_specs update_uri, 'latest_specs' end say "source cache successfully updated" @@ -112,8 +112,8 @@ class Gem::Commands::SourcesCommand < Gem::Command say "*** CURRENT SOURCES ***" say - Gem.sources.each do |source| - say source end end end @@ -1,7 +1,7 @@ require 'rubygems/command' require 'rubygems/local_remote_options' require 'rubygems/version_option' -require 'rubygems/format' class Gem::Commands::SpecificationCommand < Gem::Command @@ -17,6 +17,7 @@ class Gem::Commands::SpecificationCommand < Gem::Command add_version_option('examine') add_platform_option add_option('--all', 'Output specifications for all versions of', 'the gem') do |value, options| @@ -62,13 +63,13 @@ FIELD name of gemspec field to show "Please specify a gem name or file on the command line" end - case options[:version] when String - req = Gem::Requirement.parse options[:version] when Gem::Requirement - req = options[:version] else - raise Gem::CommandLineError, "Unsupported version type: #{options[:version]}" end if !req.none? and options[:all] @@ -79,7 +80,7 @@ FIELD name of gemspec field to show if options[:all] dep = Gem::Dependency.new gem else - dep = Gem::Dependency.new gem, options[:version] end field = get_one_optional_argument @@ -89,7 +90,7 @@ FIELD name of gemspec field to show if local? then if File.exist? gem then - specs << Gem::Format.from_file_by_path(gem).spec rescue nil end if specs.empty? then @@ -98,17 +99,14 @@ FIELD name of gemspec field to show end if remote? then - found = Gem::SpecFetcher.fetcher.fetch dep, true - - if dep.prerelease? or options[:prerelease] - found += Gem::SpecFetcher.fetcher.fetch dep, false, true, true - end specs.push(*found.map { |spec,| spec }) end if specs.empty? then - alert_error "Unknown gem '#{gem}'" terminate_interaction 1 end @@ -13,7 +13,8 @@ class Gem::Commands::UninstallCommand < Gem::Command def initialize super 'uninstall', 'Uninstall gems from the local repository', - :version => Gem::Requirement.default, :user_install => true add_option('-a', '--[no-]all', 'Uninstall all matching versions' @@ -27,6 +28,12 @@ class Gem::Commands::UninstallCommand < Gem::Command options[:ignore] = value end add_option('-x', '--[no-]executables', 'Uninstall applicable executables without', 'confirmation') do |value, options| @@ -54,6 +61,12 @@ class Gem::Commands::UninstallCommand < Gem::Command options[:format_executable] = value end add_version_option add_platform_option end @@ -73,19 +86,23 @@ class Gem::Commands::UninstallCommand < Gem::Command end def execute - original_path = Gem.path - get_all_gem_names.each do |gem_name| begin Gem::Uninstaller.new(gem_name, options).uninstall - rescue Gem::InstallError => e - alert e.message 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}") - ensure - Gem.use_paths(*original_path) end end end @@ -69,8 +69,10 @@ class Gem::Commands::UnpackCommand < Gem::Command else basename = File.basename path, '.gem' target_dir = File.expand_path basename, options[:target] - FileUtils.mkdir_p target_dir - Gem::Installer.new(path, :unpack => true).unpack target_dir say "Unpacked gem: '#{target_dir}'" end end @@ -134,9 +136,11 @@ class Gem::Commands::UnpackCommand < Gem::Command ## # Extracts the Gem::Specification and raw metadata from the .gem file at # +path+. def get_metadata path - format = Gem::Format.from_file_by_path path spec = format.spec metadata = nil @@ -1,10 +1,12 @@ require 'rubygems/command' require 'rubygems/command_manager' require 'rubygems/install_update_options' require 'rubygems/local_remote_options' require 'rubygems/spec_fetcher' require 'rubygems/version_option' -require 'rubygems/commands/install_command' class Gem::Commands::UpdateCommand < Gem::Command @@ -13,11 +15,9 @@ class Gem::Commands::UpdateCommand < Gem::Command include Gem::VersionOption def initialize - super 'update', - 'Update the named gems (or all installed gems) in the local repository', - :generate_rdoc => true, - :generate_ri => true, - :force => false add_install_update_options @@ -37,6 +37,9 @@ class Gem::Commands::UpdateCommand < Gem::Command add_local_remote_options add_platform_option add_prerelease_option "as update targets" end def arguments # :nodoc: @@ -44,7 +47,7 @@ class Gem::Commands::UpdateCommand < Gem::Command end def defaults_str # :nodoc: - "--rdoc --ri --no-force --install-dir #{Gem.dir}" end def usage # :nodoc: @@ -52,9 +55,6 @@ class Gem::Commands::UpdateCommand < Gem::Command end def execute - @installer = Gem::DependencyInstaller.new options - @updated = [] - hig = {} if options[:system] then @@ -79,21 +79,7 @@ class Gem::Commands::UpdateCommand < Gem::Command if updated.empty? then 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 @@ -112,7 +98,6 @@ class Gem::Commands::UpdateCommand < Gem::Command @installer.installed_gems.each do |spec| @updated << spec - say "Successfully installed #{spec.full_name}" if success end end @@ -178,8 +163,9 @@ class Gem::Commands::UpdateCommand < Gem::Command args = [] args << '--prefix' << Gem.prefix if Gem.prefix - args << '--no-rdoc' unless options[:generate_rdoc] - args << '--no-ri' unless options[:generate_ri] args << '--no-format-executable' if options[:no_format_executable] update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}" @@ -205,20 +191,20 @@ class Gem::Commands::UpdateCommand < Gem::Command gem_names.all? { |name| /#{name}/ !~ l_spec.name } dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}" fetcher = Gem::SpecFetcher.fetcher - spec_tuples = fetcher.find_matching dependency - matching_gems = spec_tuples.select do |(name, _, platform),| - name == l_name and Gem::Platform.match platform end - highest_remote_gem = matching_gems.sort_by do |(_, version),| - version - end.last - highest_remote_gem ||= [[nil, Gem::Version.new(0), nil]] # "null" object - highest_remote_ver = highest_remote_gem.first[1] if system or (l_spec.version < highest_remote_ver) then result << [l_spec.name, [l_spec.version, highest_remote_ver].max] @@ -0,0 +1,98 @@ |