mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rubygems/commands/rdoc_command.rb: When overwriting
documentation, remove existing documentation first. * lib/rubygems/server.rb: Fixed documentation links. * test/rubygems/test_gem_server.rb: Test for the above. * lib/rubygems/rdoc.rb: Reduced diff with RDoc::RubyGemsHook * test/rubygems/test_gem_rdoc.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
497f8904cb
commit
1dfe3d93fa
6 changed files with 145 additions and 95 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
Fri Dec 14 13:58:40 2012 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* lib/rubygems/commands/rdoc_command.rb: When overwriting
|
||||
documentation, remove existing documentation first.
|
||||
|
||||
* lib/rubygems/server.rb: Fixed documentation links.
|
||||
* test/rubygems/test_gem_server.rb: Test for the above.
|
||||
|
||||
* lib/rubygems/rdoc.rb: Reduced diff with RDoc::RubyGemsHook
|
||||
* test/rubygems/test_gem_rdoc.rb: ditto
|
||||
|
||||
Fri Dec 14 10:36:10 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* vm_trace.c (exec_hooks): add volatile to avoid segv.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'rubygems/command'
|
||||
require 'rubygems/version_option'
|
||||
require 'rubygems/rdoc'
|
||||
require 'fileutils'
|
||||
|
||||
class Gem::Commands::RdocCommand < Gem::Command
|
||||
include Gem::VersionOption
|
||||
|
@ -72,6 +73,11 @@ The rdoc command builds RDoc and RI documentation for installed gems. Use
|
|||
|
||||
doc.force = options[:overwrite]
|
||||
|
||||
if options[:overwrite] then
|
||||
FileUtils.rm_rf File.join(spec.doc_dir, 'ri')
|
||||
FileUtils.rm_rf File.join(spec.doc_dir, 'rdoc')
|
||||
end
|
||||
|
||||
begin
|
||||
doc.generate
|
||||
rescue Errno::ENOENT => e
|
||||
|
|
|
@ -86,18 +86,16 @@ class Gem::RDoc # :nodoc: all
|
|||
def self.load_rdoc
|
||||
return if @rdoc_version
|
||||
|
||||
begin
|
||||
require 'rdoc/rdoc'
|
||||
require 'rdoc/rdoc'
|
||||
|
||||
@rdoc_version = if ::RDoc.const_defined? :VERSION then
|
||||
Gem::Version.new ::RDoc::VERSION
|
||||
else
|
||||
Gem::Version.new '1.0.1'
|
||||
end
|
||||
@rdoc_version = if ::RDoc.const_defined? :VERSION then
|
||||
Gem::Version.new ::RDoc::VERSION
|
||||
else
|
||||
Gem::Version.new '1.0.1'
|
||||
end
|
||||
|
||||
rescue LoadError => e
|
||||
raise Gem::DocumentError, "RDoc is not installed: #{e}"
|
||||
end
|
||||
rescue LoadError => e
|
||||
raise Gem::DocumentError, "RDoc is not installed: #{e}"
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -107,7 +105,7 @@ class Gem::RDoc # :nodoc: all
|
|||
#
|
||||
# Only +generate_ri+ is enabled by default.
|
||||
|
||||
def initialize spec, generate_rdoc = false, generate_ri = true
|
||||
def initialize spec, generate_rdoc = true, generate_ri = true
|
||||
@doc_dir = spec.doc_dir
|
||||
@file_info = nil
|
||||
@force = false
|
||||
|
@ -123,6 +121,8 @@ class Gem::RDoc # :nodoc: all
|
|||
|
||||
##
|
||||
# Removes legacy rdoc arguments from +args+
|
||||
#--
|
||||
# TODO move to RDoc::Options
|
||||
|
||||
def delete_legacy_args args
|
||||
args.delete '--inline-source'
|
||||
|
@ -138,16 +138,20 @@ class Gem::RDoc # :nodoc: all
|
|||
# Documentation will be generated into +destination+
|
||||
|
||||
def document generator, options, destination
|
||||
generator_name = generator
|
||||
|
||||
options = options.dup
|
||||
options.exclude ||= [] # TODO maybe move to RDoc::Options#finish
|
||||
options.setup_generator generator
|
||||
options.op_dir = destination
|
||||
options.finish
|
||||
|
||||
@rdoc.options = options
|
||||
@rdoc.generator = options.generator.new options
|
||||
generator = options.generator.new @rdoc.store, options
|
||||
|
||||
say "Installing #{generator} documentation for #{@spec.full_name}"
|
||||
@rdoc.options = options
|
||||
@rdoc.generator = generator
|
||||
|
||||
say "Installing #{generator_name} documentation for #{@spec.full_name}"
|
||||
|
||||
FileUtils.mkdir_p options.op_dir
|
||||
|
||||
|
@ -169,44 +173,51 @@ class Gem::RDoc # :nodoc: all
|
|||
|
||||
setup
|
||||
|
||||
options = nil
|
||||
|
||||
if Gem::Requirement.new('< 3').satisfied_by? self.class.rdoc_version then
|
||||
generate_legacy
|
||||
else
|
||||
::RDoc::TopLevel.reset # TODO ::RDoc::RDoc.reset
|
||||
::RDoc::Parser::C.reset
|
||||
return
|
||||
end
|
||||
|
||||
::RDoc::TopLevel.reset # TODO ::RDoc::RDoc.reset
|
||||
::RDoc::Parser::C.reset
|
||||
|
||||
args = @spec.rdoc_options
|
||||
args.concat @spec.require_paths
|
||||
args.concat @spec.extra_rdoc_files
|
||||
|
||||
case config_args = Gem.configuration[:rdoc]
|
||||
when String then
|
||||
args = args.concat config_args.split
|
||||
when Array then
|
||||
args = args.concat config_args
|
||||
end
|
||||
|
||||
delete_legacy_args args
|
||||
|
||||
Dir.chdir @spec.full_gem_path do
|
||||
options = ::RDoc::Options.new
|
||||
options.default_title = "#{@spec.full_name} Documentation"
|
||||
options.files = []
|
||||
options.files.push(*@spec.require_paths)
|
||||
options.files.push(*@spec.extra_rdoc_files)
|
||||
|
||||
args = @spec.rdoc_options
|
||||
|
||||
case config_args = Gem.configuration[:rdoc]
|
||||
when String then
|
||||
args = args.concat config_args.split
|
||||
when Array then
|
||||
args = args.concat config_args
|
||||
end
|
||||
|
||||
delete_legacy_args args
|
||||
options.parse args
|
||||
options.quiet = !Gem.configuration.really_verbose
|
||||
|
||||
@rdoc = new_rdoc
|
||||
@rdoc.options = options
|
||||
|
||||
Dir.chdir @spec.full_gem_path do
|
||||
@file_info = @rdoc.parse_files options.files
|
||||
end
|
||||
|
||||
document 'ri', options, @ri_dir if
|
||||
@generate_ri and (@force or not File.exist? @ri_dir)
|
||||
|
||||
document 'darkfish', options, @rdoc_dir if
|
||||
@generate_rdoc and (@force or not File.exist? @rdoc_dir)
|
||||
end
|
||||
|
||||
options.quiet = !Gem.configuration.really_verbose
|
||||
|
||||
@rdoc = new_rdoc
|
||||
@rdoc.options = options
|
||||
|
||||
say "Parsing documentation for #{@spec.full_name}"
|
||||
|
||||
Dir.chdir @spec.full_gem_path do
|
||||
@file_info = @rdoc.parse_files options.files
|
||||
end
|
||||
|
||||
document 'ri', options, @ri_dir if
|
||||
@generate_ri and (@force or not File.exist? @ri_dir)
|
||||
|
||||
document 'darkfish', options, @rdoc_dir if
|
||||
@generate_rdoc and (@force or not File.exist? @rdoc_dir)
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -268,7 +279,7 @@ class Gem::RDoc # :nodoc: all
|
|||
# #new_rdoc creates a new RDoc instance. This method is provided only to
|
||||
# make testing easier.
|
||||
|
||||
def new_rdoc
|
||||
def new_rdoc # :nodoc:
|
||||
::RDoc::RDoc.new
|
||||
end
|
||||
|
||||
|
|
|
@ -79,7 +79,9 @@ class Gem::Server
|
|||
|
||||
<b><%=spec["name"]%> <%=spec["version"]%></b>
|
||||
|
||||
<% if spec["rdoc_installed"] then %>
|
||||
<% if spec["ri_installed"] then %>
|
||||
<a href="<%=spec["doc_path"]%>">[rdoc]</a>
|
||||
<% elsif spec["rdoc_installed"] then %>
|
||||
<a href="<%=spec["doc_path"]%>">[rdoc]</a>
|
||||
<% else %>
|
||||
<span title="rdoc not installed">[rdoc]</span>
|
||||
|
@ -464,7 +466,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
|
|||
|
||||
def have_rdoc_4_plus?
|
||||
@have_rdoc_4_plus ||=
|
||||
Gem::Requirement.new('>= 4').satisfied_by? Gem::RDoc.rdoc_version
|
||||
Gem::Requirement.new('>= 4.0.0.preview2').satisfied_by? Gem::RDoc.rdoc_version
|
||||
end
|
||||
|
||||
def latest_specs(req, res)
|
||||
|
@ -604,6 +606,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
|
|||
"homepage" => spec.homepage,
|
||||
"name" => spec.name,
|
||||
"rdoc_installed" => Gem::RDoc.new(spec).rdoc_installed?,
|
||||
"ri_installed" => Gem::RDoc.new(spec).ri_installed?,
|
||||
"summary" => spec.summary,
|
||||
"version" => spec.version.to_s,
|
||||
}
|
||||
|
@ -619,7 +622,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
|
|||
"has_deps" => false,
|
||||
"homepage" => "http://docs.rubygems.org/",
|
||||
"name" => 'rubygems',
|
||||
"rdoc_installed" => true,
|
||||
"ri_installed" => true,
|
||||
"summary" => "RubyGems itself",
|
||||
"version" => Gem::VERSION,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'rubygems/test_case'
|
||||
require 'rubygems'
|
||||
require 'rubygems/test_case'
|
||||
require 'rubygems/rdoc'
|
||||
|
||||
class TestGemRDoc < Gem::TestCase
|
||||
|
@ -9,9 +9,17 @@ class TestGemRDoc < Gem::TestCase
|
|||
def setup
|
||||
super
|
||||
|
||||
@a = quick_spec 'a'
|
||||
@a = quick_spec 'a' do |s|
|
||||
s.rdoc_options = %w[--main MyTitle]
|
||||
s.extra_rdoc_files = %w[README]
|
||||
end
|
||||
|
||||
@rdoc = Gem::RDoc.new @a
|
||||
write_file File.join(@tempdir, 'lib', 'a.rb')
|
||||
write_file File.join(@tempdir, 'README')
|
||||
|
||||
install_gem @a
|
||||
|
||||
@hook = Gem::RDoc.new @a
|
||||
|
||||
begin
|
||||
Gem::RDoc.load_rdoc
|
||||
|
@ -27,16 +35,16 @@ class TestGemRDoc < Gem::TestCase
|
|||
# shipped for backwards compatibility.
|
||||
|
||||
def rdoc_3?
|
||||
Gem::Requirement.new('~> 3.0').satisfied_by? @rdoc.class.rdoc_version
|
||||
Gem::Requirement.new('~> 3.0').satisfied_by? @hook.class.rdoc_version
|
||||
end
|
||||
|
||||
def rdoc_3_8_or_better?
|
||||
Gem::Requirement.new('>= 3.8').satisfied_by? @rdoc.class.rdoc_version
|
||||
Gem::Requirement.new('>= 3.8').satisfied_by? @hook.class.rdoc_version
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
assert @rdoc.generate_rdoc
|
||||
assert @rdoc.generate_ri
|
||||
assert @hook.generate_rdoc
|
||||
assert @hook.generate_ri
|
||||
|
||||
rdoc = Gem::RDoc.new @a, false, false
|
||||
|
||||
|
@ -52,7 +60,7 @@ class TestGemRDoc < Gem::TestCase
|
|||
-p
|
||||
]
|
||||
|
||||
@rdoc.delete_legacy_args args
|
||||
@hook.delete_legacy_args args
|
||||
|
||||
assert_empty args
|
||||
end
|
||||
|
@ -63,12 +71,13 @@ class TestGemRDoc < Gem::TestCase
|
|||
options = RDoc::Options.new
|
||||
options.files = []
|
||||
|
||||
@rdoc.instance_variable_set :@rdoc, @rdoc.new_rdoc
|
||||
@rdoc.instance_variable_set :@file_info, []
|
||||
rdoc = @hook.new_rdoc
|
||||
@hook.instance_variable_set :@rdoc, rdoc
|
||||
@hook.instance_variable_set :@file_info, []
|
||||
|
||||
@rdoc.document 'darkfish', options, @a.doc_dir('rdoc')
|
||||
@hook.document 'darkfish', options, @a.doc_dir('rdoc')
|
||||
|
||||
assert @rdoc.rdoc_installed?
|
||||
assert @hook.rdoc_installed?
|
||||
end unless rdoc_4
|
||||
|
||||
def test_generate
|
||||
|
@ -77,12 +86,12 @@ class TestGemRDoc < Gem::TestCase
|
|||
FileUtils.mkdir_p @a.doc_dir
|
||||
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
||||
|
||||
@rdoc.generate
|
||||
@hook.generate
|
||||
|
||||
assert @rdoc.rdoc_installed?
|
||||
assert @rdoc.ri_installed?
|
||||
assert @hook.rdoc_installed?
|
||||
assert @hook.ri_installed?
|
||||
|
||||
rdoc = @rdoc.instance_variable_get :@rdoc
|
||||
rdoc = @hook.instance_variable_get :@rdoc
|
||||
|
||||
refute rdoc.options.hyperlink_all
|
||||
end unless rdoc_4
|
||||
|
@ -95,9 +104,9 @@ class TestGemRDoc < Gem::TestCase
|
|||
FileUtils.mkdir_p @a.doc_dir
|
||||
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
||||
|
||||
@rdoc.generate
|
||||
@hook.generate
|
||||
|
||||
rdoc = @rdoc.instance_variable_get :@rdoc
|
||||
rdoc = @hook.instance_variable_get :@rdoc
|
||||
|
||||
assert rdoc.options.hyperlink_all
|
||||
end unless rdoc_4
|
||||
|
@ -110,21 +119,21 @@ class TestGemRDoc < Gem::TestCase
|
|||
FileUtils.mkdir_p @a.doc_dir
|
||||
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
||||
|
||||
@rdoc.generate
|
||||
@hook.generate
|
||||
|
||||
rdoc = @rdoc.instance_variable_get :@rdoc
|
||||
rdoc = @hook.instance_variable_get :@rdoc
|
||||
|
||||
assert rdoc.options.hyperlink_all
|
||||
end unless rdoc_4
|
||||
|
||||
def test_generate_disabled
|
||||
@rdoc.generate_rdoc = false
|
||||
@rdoc.generate_ri = false
|
||||
@hook.generate_rdoc = false
|
||||
@hook.generate_ri = false
|
||||
|
||||
@rdoc.generate
|
||||
@hook.generate
|
||||
|
||||
refute @rdoc.rdoc_installed?
|
||||
refute @rdoc.ri_installed?
|
||||
refute @hook.rdoc_installed?
|
||||
refute @hook.ri_installed?
|
||||
end
|
||||
|
||||
def test_generate_force
|
||||
|
@ -134,9 +143,9 @@ class TestGemRDoc < Gem::TestCase
|
|||
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
||||
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
||||
|
||||
@rdoc.force = true
|
||||
@hook.force = true
|
||||
|
||||
@rdoc.generate
|
||||
@hook.generate
|
||||
|
||||
assert_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
|
||||
assert_path_exists File.join(@a.doc_dir('ri'), 'cache.ri')
|
||||
|
@ -149,7 +158,7 @@ class TestGemRDoc < Gem::TestCase
|
|||
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
||||
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
||||
|
||||
@rdoc.generate
|
||||
@hook.generate
|
||||
|
||||
refute_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
|
||||
refute_path_exists File.join(@a.doc_dir('ri'), 'cache.ri')
|
||||
|
@ -161,10 +170,10 @@ class TestGemRDoc < Gem::TestCase
|
|||
FileUtils.mkdir_p @a.doc_dir
|
||||
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
||||
|
||||
@rdoc.generate_legacy
|
||||
@hook.generate_legacy
|
||||
|
||||
assert @rdoc.rdoc_installed?
|
||||
assert @rdoc.ri_installed?
|
||||
assert @hook.rdoc_installed?
|
||||
assert @hook.ri_installed?
|
||||
end unless rdoc_4
|
||||
|
||||
def test_legacy_rdoc
|
||||
|
@ -173,31 +182,31 @@ class TestGemRDoc < Gem::TestCase
|
|||
FileUtils.mkdir_p @a.doc_dir
|
||||
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
||||
|
||||
@rdoc.legacy_rdoc '--op', @a.doc_dir('rdoc')
|
||||
@hook.legacy_rdoc '--op', @a.doc_dir('rdoc')
|
||||
|
||||
assert @rdoc.rdoc_installed?
|
||||
assert @hook.rdoc_installed?
|
||||
end unless rdoc_4
|
||||
|
||||
def test_new_rdoc
|
||||
assert_kind_of RDoc::RDoc, @rdoc.new_rdoc
|
||||
assert_kind_of RDoc::RDoc, @hook.new_rdoc
|
||||
end
|
||||
|
||||
def test_rdoc_installed?
|
||||
refute @rdoc.rdoc_installed?
|
||||
refute @hook.rdoc_installed?
|
||||
|
||||
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
||||
|
||||
assert @rdoc.rdoc_installed?
|
||||
assert @hook.rdoc_installed?
|
||||
end
|
||||
|
||||
def test_remove
|
||||
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
||||
FileUtils.mkdir_p @a.doc_dir 'ri'
|
||||
|
||||
@rdoc.remove
|
||||
@hook.remove
|
||||
|
||||
refute @rdoc.rdoc_installed?
|
||||
refute @rdoc.ri_installed?
|
||||
refute @hook.rdoc_installed?
|
||||
refute @hook.ri_installed?
|
||||
|
||||
assert_path_exists @a.doc_dir
|
||||
end
|
||||
|
@ -208,7 +217,7 @@ class TestGemRDoc < Gem::TestCase
|
|||
FileUtils.chmod 0, @a.base_dir
|
||||
|
||||
e = assert_raises Gem::FilePermissionError do
|
||||
@rdoc.remove
|
||||
@hook.remove
|
||||
end
|
||||
|
||||
assert_equal @a.base_dir, e.directory
|
||||
|
@ -217,15 +226,15 @@ class TestGemRDoc < Gem::TestCase
|
|||
end
|
||||
|
||||
def test_ri_installed?
|
||||
refute @rdoc.ri_installed?
|
||||
refute @hook.ri_installed?
|
||||
|
||||
FileUtils.mkdir_p @a.doc_dir 'ri'
|
||||
|
||||
assert @rdoc.ri_installed?
|
||||
assert @hook.ri_installed?
|
||||
end
|
||||
|
||||
def test_setup
|
||||
@rdoc.setup
|
||||
@hook.setup
|
||||
|
||||
assert_path_exists @a.doc_dir
|
||||
end
|
||||
|
@ -236,12 +245,16 @@ class TestGemRDoc < Gem::TestCase
|
|||
FileUtils.chmod 0, @a.doc_dir
|
||||
|
||||
e = assert_raises Gem::FilePermissionError do
|
||||
@rdoc.setup
|
||||
@hook.setup
|
||||
end
|
||||
|
||||
assert_equal @a.doc_dir, e.directory
|
||||
ensure
|
||||
FileUtils.chmod(0755, @a.doc_dir) if File.directory?(@a.doc_dir)
|
||||
if File.exist? @a.doc_dir
|
||||
FileUtils.chmod 0755, @a.doc_dir
|
||||
FileUtils.rm_r @a.doc_dir
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class TestGemServer < Gem::TestCase
|
|||
|
||||
def test_have_rdoc_4_plus_eh
|
||||
orig_rdoc_version = Gem::RDoc.rdoc_version
|
||||
Gem::RDoc.instance_variable_set :@rdoc_version, Gem::Version.new('4.0')
|
||||
Gem::RDoc.instance_variable_set(:@rdoc_version, Gem::Version.new('4.0'))
|
||||
|
||||
server = Gem::Server.new Gem.dir, 0, false
|
||||
assert server.have_rdoc_4_plus?
|
||||
|
@ -49,6 +49,12 @@ class TestGemServer < Gem::TestCase
|
|||
|
||||
server = Gem::Server.new Gem.dir, 0, false
|
||||
refute server.have_rdoc_4_plus?
|
||||
|
||||
Gem::RDoc.instance_variable_set(:@rdoc_version,
|
||||
Gem::Version.new('4.0.0.preview2'))
|
||||
|
||||
server = Gem::Server.new Gem.dir, 0, false
|
||||
assert server.have_rdoc_4_plus?
|
||||
ensure
|
||||
Gem::RDoc.instance_variable_set :@rdoc_version, orig_rdoc_version
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue