summaryrefslogtreecommitdiff
path: root/lib/rubygems/commands/setup_command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/commands/setup_command.rb')
-rw-r--r--lib/rubygems/commands/setup_command.rb145
1 files changed, 104 insertions, 41 deletions
diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb
index 508ff84a0f..2f1cf0091d 100644
--- a/lib/rubygems/commands/setup_command.rb
+++ b/lib/rubygems/commands/setup_command.rb
@@ -5,14 +5,22 @@ require 'rubygems/command'
# RubyGems checkout or tarball.
class Gem::Commands::SetupCommand < Gem::Command
+ HISTORY_HEADER = /^===\s*[\d.]+\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/
+ VERSION_MATCHER = /^===\s*([\d.]+)\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/
def initialize
require 'tmpdir'
super 'setup', 'Install RubyGems',
- :format_executable => true, :rdoc => true, :ri => true,
+ :format_executable => true, :document => %w[ri],
:site_or_vendor => :sitelibdir,
- :destdir => '', :prefix => ''
+ :destdir => '', :prefix => '', :previous_version => ''
+
+ add_option '--previous-version=VERSION',
+ 'Previous version of rubygems',
+ 'Used for changelog processing' do |version, options|
+ options[:previous_version] = version
+ end
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-]document [TYPES]', Array,
+ 'Generate documentation for RubyGems.',
+ 'List the documentation types you wish to',
+ 'generate. For example: rdoc,ri' do |value, options|
+ options[:document] = case value
+ when nil then %w[rdoc ri]
+ when false then []
+ else value
+ end
+ end
+
add_option '--[no-]rdoc',
'Generate RDoc documentation for RubyGems' do |value, options|
- options[:rdoc] = value
+ if value then
+ options[:document] << 'rdoc'
+ else
+ options[:document].delete 'rdoc'
+ end
+
+ options[:document].uniq!
end
add_option '--[no-]ri',
'Generate RI documentation for RubyGems' do |value, options|
- options[:ri] = value
+ if value then
+ options[:document] << 'ri'
+ else
+ options[:document].delete 'ri'
+ end
+
+ options[:document].uniq!
end
end
@@ -58,7 +89,7 @@ class Gem::Commands::SetupCommand < Gem::Command
end
def defaults_str # :nodoc:
- "--format-executable --rdoc --ri"
+ "--format-executable --document ri"
end
def description # :nodoc:
@@ -110,7 +141,7 @@ By default, this RubyGems will install gem as:
uninstall_old_gemcutter
- install_rdoc
+ documentation_success = install_rdoc
say
if @verbose then
@@ -118,14 +149,30 @@ By default, this RubyGems will install gem as:
say
end
+ if options[:previous_version].empty?
+ options[:previous_version] = Gem::VERSION.sub(/[0-9]+$/, '0')
+ end
+
+ options[:previous_version] = Gem::Version.new(options[:previous_version])
+
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, '')
+ history = File.read release_notes
+ history = history.sub(/^# coding:.*?^=/m, '')
+
+ text = history.split(HISTORY_HEADER)
+ text.shift # correct an off-by-one generated by split
+ version_lines = history.scan(HISTORY_HEADER)
+ versions = history.scan(VERSION_MATCHER).flatten.map { |x| Gem::Version.new(x) }
+
+ history_string = ""
+
+ until versions.length == 0 or versions.shift < options[:previous_version]
+ history_string += version_lines.shift + text.shift
end
+
+ history_string
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
+
+ if documentation_success
+ if options[:document].include? 'rdoc' then
+ say "Rdoc documentation was installed. You may now invoke:"
+ say " gem server"
+ say "and then peruse beautifully formatted documentation for your gems"
+ say "with your web browser."
+ say "If you do not wish to install this documentation in the future, use the"
+ say "--no-document flag, or set it as the default in your ~/.gemrc file. See"
+ say "'gem help env' for details."
+ say
+ end
+
+ if options[:document].include? 'ri' then
+ say "Ruby Interactive (ri) documentation was installed. ri is kind of like man "
+ say "pages for ruby libraries. You may access it like this:"
+ say " ri Classname"
+ say " ri Classname.class_method"
+ say " ri Classname#instance_method"
+ say "If you do not wish to install this documentation in the future, use the"
+ say "--no-document flag, or set it as the default in your ~/.gemrc file. See"
+ say "'gem help env' for details."
+ say
+ end
+ 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
+ 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 = Dir[File.join('**', '*rb')]
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
+ begin
+ Gem.ensure_gem_subdirectories Gem.dir
+ rescue SystemCallError
+ # ignore
+ end
+
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
+ require 'rubygems/rdoc'
- 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
+ fake_spec = Gem::Specification.new 'rubygems', Gem::VERSION
+ def fake_spec.full_gem_path
+ File.expand_path '../../../..', __FILE__
end
+
+ generate_ri = options[:document].include? 'ri'
+ generate_rdoc = options[:document].include? 'rdoc'
+
+ rdoc = Gem::RDoc.new fake_spec, generate_rdoc, generate_ri
+ rdoc.generate
+
+ return true
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
+
+ return false
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'