[前][次][番号順一覧][スレッド一覧]

ruby-changes:26321

From: drbrain <ko1@a...>
Date: Fri, 14 Dec 2012 14:10:11 +0900 (JST)
Subject: [ruby-changes:26321] drbrain:r38372 (trunk): * lib/rubygems/commands/rdoc_command.rb: When overwriting

drbrain	2012-12-14 14:09:37 +0900 (Fri, 14 Dec 2012)

  New Revision: 38372

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38372

  Log:
    * 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

  Modified files:
    trunk/ChangeLog
    trunk/lib/rubygems/commands/rdoc_command.rb
    trunk/lib/rubygems/rdoc.rb
    trunk/lib/rubygems/server.rb
    trunk/test/rubygems/test_gem_rdoc.rb
    trunk/test/rubygems/test_gem_server.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38371)
+++ ChangeLog	(revision 38372)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Dec 14 13:58:40 2012  Eric Hodel  <drbrain@s...>
+
+	* 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@r...>
 
 	* vm_trace.c (exec_hooks): add volatile to avoid segv.
Index: lib/rubygems/rdoc.rb
===================================================================
--- lib/rubygems/rdoc.rb	(revision 38371)
+++ lib/rubygems/rdoc.rb	(revision 38372)
@@ -86,18 +86,16 @@ class Gem::RDoc # :nodoc: all https://github.com/ruby/ruby/blob/trunk/lib/rubygems/rdoc.rb#L86
   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 https://github.com/ruby/ruby/blob/trunk/lib/rubygems/rdoc.rb#L105
   #
   # 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 https://github.com/ruby/ruby/blob/trunk/lib/rubygems/rdoc.rb#L121
 
   ##
   # 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 https://github.com/ruby/ruby/blob/trunk/lib/rubygems/rdoc.rb#L138
   # 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
 
+    generator = options.generator.new @rdoc.store, options
+
     @rdoc.options = options
-    @rdoc.generator = options.generator.new options
+    @rdoc.generator = generator
 
-    say "Installing #{generator} documentation for #{@spec.full_name}"
+    say "Installing #{generator_name} documentation for #{@spec.full_name}"
 
     FileUtils.mkdir_p options.op_dir
 
@@ -169,44 +173,51 @@ class Gem::RDoc # :nodoc: all https://github.com/ruby/ruby/blob/trunk/lib/rubygems/rdoc.rb#L173
 
     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
+    end
 
-      @rdoc = new_rdoc
-      @rdoc.options = options
+    options.quiet = !Gem.configuration.really_verbose
 
-      Dir.chdir @spec.full_gem_path do
-        @file_info = @rdoc.parse_files options.files
-      end
+    @rdoc = new_rdoc
+    @rdoc.options = options
 
-      document 'ri',       options, @ri_dir if
-        @generate_ri   and (@force or not File.exist? @ri_dir)
+    say "Parsing documentation for #{@spec.full_name}"
 
-      document 'darkfish', options, @rdoc_dir if
-        @generate_rdoc and (@force or not File.exist? @rdoc_dir)
+    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 https://github.com/ruby/ruby/blob/trunk/lib/rubygems/rdoc.rb#L279
   # #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
 
Index: lib/rubygems/commands/rdoc_command.rb
===================================================================
--- lib/rubygems/commands/rdoc_command.rb	(revision 38371)
+++ lib/rubygems/commands/rdoc_command.rb	(revision 38372)
@@ -1,6 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/rdoc_command.rb#L1
 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 docu https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/rdoc_command.rb#L73
 
       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
Index: lib/rubygems/server.rb
===================================================================
--- lib/rubygems/server.rb	(revision 38371)
+++ lib/rubygems/server.rb	(revision 38372)
@@ -79,7 +79,9 @@ class Gem::Server https://github.com/ruby/ruby/blob/trunk/lib/rubygems/server.rb#L79
 
     <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: #ffd https://github.com/ruby/ruby/blob/trunk/lib/rubygems/server.rb#L466
 
   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: #ffd https://github.com/ruby/ruby/blob/trunk/lib/rubygems/server.rb#L606
         "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: #ffd https://github.com/ruby/ruby/blob/trunk/lib/rubygems/server.rb#L622
       "has_deps" => false,
       "homepage" => "http://docs.rubygems.org/",
       "name" => 'rubygems',
-      "rdoc_installed" => true,
+      "ri_installed" => true,
       "summary" => "RubyGems itself",
       "version" => Gem::VERSION,
     }
Index: test/rubygems/test_gem_rdoc.rb
===================================================================
--- test/rubygems/test_gem_rdoc.rb	(revision 38371)
+++ test/rubygems/test_gem_rdoc.rb	(revision 38372)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L1
-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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L9
   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
+
+    write_file File.join(@tempdir, 'lib', 'a.rb')
+    write_file File.join(@tempdir, 'README')
 
-    @rdoc = Gem::RDoc.new @a
+    install_gem @a
+
+    @hook = Gem::RDoc.new @a
 
     begin
       Gem::RDoc.load_rdoc
@@ -27,16 +35,16 @@ class TestGemRDoc < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L35
   # 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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L60
       -p
     ]
 
-    @rdoc.delete_legacy_args args
+    @hook.delete_legacy_args args
 
     assert_empty args
   end
@@ -63,12 +71,13 @@ class TestGemRDoc < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L71
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L86
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L104
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L119
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L143
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L158
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L170
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L182
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L217
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L226
   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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_rdoc.rb#L245
     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
+
Index: test/rubygems/test_gem_server.rb
===================================================================
--- test/rubygems/test_gem_server.rb	(revision 38371)
+++ test/rubygems/test_gem_server.rb	(revision 38372)
@@ -40,7 +40,7 @@ class TestGemServer < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_server.rb#L40
 
   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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_server.rb#L49
 
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]