2007-11-10 02:48:56 -05:00
|
|
|
#--
|
|
|
|
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
|
|
|
# All rights reserved.
|
|
|
|
# See LICENSE.txt for permissions.
|
|
|
|
#++
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
require 'rubygems'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# The documentation manager generates RDoc and RI for RubyGems.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
class Gem::DocManager
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
include Gem::UserInteraction
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
@configured_args = []
|
|
|
|
|
|
|
|
def self.configured_args
|
|
|
|
@configured_args ||= []
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.configured_args=(args)
|
|
|
|
case args
|
|
|
|
when Array
|
|
|
|
@configured_args = args
|
|
|
|
when String
|
|
|
|
@configured_args = args.split
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Load RDoc from a gem if it is available, otherwise from Ruby's stdlib
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
def self.load_rdoc
|
|
|
|
begin
|
|
|
|
gem 'rdoc'
|
|
|
|
rescue Gem::LoadError
|
|
|
|
# use built-in RDoc
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
begin
|
|
|
|
require 'rdoc/rdoc'
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
@rdoc_version = if defined? RDoc::VERSION then
|
|
|
|
Gem::Version.new RDoc::VERSION
|
|
|
|
else
|
|
|
|
Gem::Version.new '1.0.1' # HACK parsing is hard
|
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
rescue LoadError => e
|
|
|
|
raise Gem::DocumentError,
|
2009-06-09 17:38:59 -04:00
|
|
|
"ERROR: RDoc documentation generator not installed: #{e}"
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def self.rdoc_version
|
|
|
|
@rdoc_version
|
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Updates the RI cache for RDoc 2 if it is installed
|
|
|
|
|
|
|
|
def self.update_ri_cache
|
|
|
|
load_rdoc rescue return
|
|
|
|
|
|
|
|
return unless defined? RDoc::VERSION # RDoc 1 does not have VERSION
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
require 'rdoc/ri/driver'
|
|
|
|
|
|
|
|
options = {
|
|
|
|
:use_cache => true,
|
|
|
|
:use_system => true,
|
|
|
|
:use_site => true,
|
|
|
|
:use_home => true,
|
|
|
|
:use_gems => true,
|
|
|
|
:formatter => RDoc::RI::Formatter,
|
|
|
|
}
|
|
|
|
|
2010-11-08 15:58:42 -05:00
|
|
|
RDoc::RI::Driver.new(options).class_cache
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Create a document manager for +spec+. +rdoc_args+ contains arguments for
|
|
|
|
# RDoc (template etc.) as a String.
|
|
|
|
|
|
|
|
def initialize(spec, rdoc_args="")
|
2011-01-18 19:08:49 -05:00
|
|
|
require 'fileutils'
|
2008-09-25 06:13:50 -04:00
|
|
|
@spec = spec
|
2011-05-31 23:45:05 -04:00
|
|
|
@doc_dir = spec.doc_dir
|
2008-09-25 06:13:50 -04:00
|
|
|
@rdoc_args = rdoc_args.nil? ? [] : rdoc_args.split
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Is the RDoc documentation installed?
|
|
|
|
|
|
|
|
def rdoc_installed?
|
|
|
|
File.exist?(File.join(@doc_dir, "rdoc"))
|
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
##
|
|
|
|
# Is the RI documentation installed?
|
|
|
|
|
|
|
|
def ri_installed?
|
|
|
|
File.exist?(File.join(@doc_dir, "ri"))
|
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Generate the RI documents for this gem spec.
|
|
|
|
#
|
|
|
|
# Note that if both RI and RDoc documents are generated from the same
|
|
|
|
# process, the RI docs should be done first (a likely bug in RDoc will cause
|
|
|
|
# RI docs generation to fail if run after RDoc).
|
|
|
|
|
|
|
|
def generate_ri
|
2009-06-09 17:38:59 -04:00
|
|
|
setup_rdoc
|
|
|
|
install_ri # RDoc bug, ri goes first
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Generate the RDoc documents for this gem spec.
|
|
|
|
#
|
|
|
|
# Note that if both RI and RDoc documents are generated from the same
|
|
|
|
# process, the RI docs should be done first (a likely bug in RDoc will cause
|
|
|
|
# RI docs generation to fail if run after RDoc).
|
|
|
|
|
|
|
|
def generate_rdoc
|
2009-06-09 17:38:59 -04:00
|
|
|
setup_rdoc
|
|
|
|
install_rdoc
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Generate and install RDoc into the documentation directory
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
def install_rdoc
|
|
|
|
rdoc_dir = File.join @doc_dir, 'rdoc'
|
2008-04-11 16:57:02 -04:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
FileUtils.rm_rf rdoc_dir
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
say "Installing RDoc documentation for #{@spec.full_name}..."
|
|
|
|
run_rdoc '--op', rdoc_dir
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Generate and install RI into the documentation directory
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
def install_ri
|
|
|
|
ri_dir = File.join @doc_dir, 'ri'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
FileUtils.rm_rf ri_dir
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
say "Installing ri documentation for #{@spec.full_name}..."
|
|
|
|
run_rdoc '--ri', '--op', ri_dir
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# Run RDoc with +args+, which is an ARGV style argument list
|
|
|
|
|
|
|
|
def run_rdoc(*args)
|
|
|
|
args << @spec.rdoc_options
|
|
|
|
args << self.class.configured_args
|
|
|
|
args << @spec.require_paths.clone
|
|
|
|
args << @spec.extra_rdoc_files
|
2009-06-09 17:38:59 -04:00
|
|
|
args << '--title' << "#{@spec.full_name} Documentation"
|
2011-03-09 17:32:29 -05:00
|
|
|
args << '--quiet'
|
2008-09-25 06:13:50 -04:00
|
|
|
args = args.flatten.map do |arg| arg.to_s end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
if self.class.rdoc_version >= Gem::Version.new('2.4.0') then
|
|
|
|
args.delete '--inline-source'
|
|
|
|
args.delete '--promiscuous'
|
|
|
|
args.delete '-p'
|
|
|
|
args.delete '--one-file'
|
|
|
|
# HACK more
|
|
|
|
end
|
|
|
|
|
2011-03-01 04:41:32 -05:00
|
|
|
debug_args = args.dup
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
r = RDoc::RDoc.new
|
|
|
|
|
|
|
|
old_pwd = Dir.pwd
|
2010-04-22 04:24:42 -04:00
|
|
|
Dir.chdir @spec.full_gem_path
|
|
|
|
|
|
|
|
say "rdoc #{args.join ' '}" if Gem.configuration.really_verbose
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
begin
|
|
|
|
r.document args
|
|
|
|
rescue Errno::EACCES => e
|
|
|
|
dirname = File.dirname e.message.split("-")[1].strip
|
|
|
|
raise Gem::FilePermissionError.new(dirname)
|
2011-01-28 18:46:47 -05:00
|
|
|
rescue Interrupt => e
|
|
|
|
raise e
|
|
|
|
rescue Exception => ex
|
2008-09-25 06:13:50 -04:00
|
|
|
alert_error "While generating documentation for #{@spec.full_name}"
|
|
|
|
ui.errs.puts "... MESSAGE: #{ex}"
|
2011-03-01 04:41:32 -05:00
|
|
|
ui.errs.puts "... RDOC args: #{debug_args.join(' ')}"
|
2008-09-25 06:13:50 -04:00
|
|
|
ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
|
2011-03-01 04:41:32 -05:00
|
|
|
Gem.configuration.backtrace
|
|
|
|
terminate_interaction 1
|
2008-09-25 06:13:50 -04:00
|
|
|
ensure
|
2010-04-22 04:24:42 -04:00
|
|
|
Dir.chdir old_pwd
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
def setup_rdoc
|
|
|
|
if File.exist?(@doc_dir) && !File.writable?(@doc_dir) then
|
|
|
|
raise Gem::FilePermissionError.new(@doc_dir)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
self.class.load_rdoc
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Remove RDoc and RI documentation
|
|
|
|
|
|
|
|
def uninstall_doc
|
2011-05-31 23:45:05 -04:00
|
|
|
base_dir = @spec.base_dir
|
|
|
|
raise Gem::FilePermissionError.new base_dir unless File.writable? base_dir
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
# TODO: ok... that's twice... ugh
|
|
|
|
old_name = [
|
2008-09-25 06:13:50 -04:00
|
|
|
@spec.name, @spec.version, @spec.original_platform].join '-'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
doc_dir = @spec.doc_dir
|
2009-06-09 17:38:59 -04:00
|
|
|
unless File.directory? doc_dir then
|
2011-05-31 23:45:05 -04:00
|
|
|
doc_dir = File.join File.dirname(doc_dir), old_name
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
ri_dir = @spec.ri_dir
|
2009-06-09 17:38:59 -04:00
|
|
|
unless File.directory? ri_dir then
|
2011-05-31 23:45:05 -04:00
|
|
|
ri_dir = File.join File.dirname(ri_dir), old_name
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.rm_rf doc_dir
|
2009-06-09 17:38:59 -04:00
|
|
|
FileUtils.rm_rf ri_dir
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-09-25 06:13:50 -04:00
|
|
|
|