mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
8103d46a4d
commit
688ccc9602
3 changed files with 54 additions and 30 deletions
|
@ -85,7 +85,7 @@ command help for an example.
|
||||||
end
|
end
|
||||||
|
|
||||||
if @options[:spec]
|
if @options[:spec]
|
||||||
spec, metadata = get_metadata path, security_policy
|
spec, metadata = Gem::Package.metadata(path, security_policy)
|
||||||
|
|
||||||
if metadata.nil?
|
if metadata.nil?
|
||||||
alert_error "--spec is unsupported on '#{name}' (old format gem)"
|
alert_error "--spec is unsupported on '#{name}' (old format gem)"
|
||||||
|
@ -173,32 +173,4 @@ command help for an example.
|
||||||
|
|
||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
|
||||||
# Extracts the Gem::Specification and raw metadata from the .gem file at
|
|
||||||
# +path+.
|
|
||||||
#--
|
|
||||||
# TODO move to Gem::Package as #raw_spec or something
|
|
||||||
|
|
||||||
def get_metadata(path, security_policy = nil)
|
|
||||||
format = Gem::Package.new path, security_policy
|
|
||||||
spec = format.spec
|
|
||||||
|
|
||||||
metadata = nil
|
|
||||||
|
|
||||||
File.open path, Gem.binary_mode do |io|
|
|
||||||
tar = Gem::Package::TarReader.new io
|
|
||||||
tar.each_entry do |entry|
|
|
||||||
case entry.full_name
|
|
||||||
when 'metadata' then
|
|
||||||
metadata = entry.read
|
|
||||||
when 'metadata.gz' then
|
|
||||||
metadata = Gem::Util.gunzip entry.read
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return spec, metadata
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -156,6 +156,32 @@ class Gem::Package
|
||||||
Gem::Package::Old.new gem
|
Gem::Package::Old.new gem
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Extracts the Gem::Specification and raw metadata from the .gem file at
|
||||||
|
# +path+.
|
||||||
|
#--
|
||||||
|
|
||||||
|
def self.metadata(path, security_policy = nil)
|
||||||
|
format = new(path, security_policy)
|
||||||
|
spec = format.spec
|
||||||
|
|
||||||
|
metadata = nil
|
||||||
|
|
||||||
|
File.open path, Gem.binary_mode do |io|
|
||||||
|
tar = Gem::Package::TarReader.new io
|
||||||
|
tar.each_entry do |entry|
|
||||||
|
case entry.full_name
|
||||||
|
when 'metadata' then
|
||||||
|
metadata = entry.read
|
||||||
|
when 'metadata.gz' then
|
||||||
|
metadata = Gem::Util.gunzip entry.read
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return spec, metadata
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Creates a new package that will read or write to the file +gem+.
|
# Creates a new package that will read or write to the file +gem+.
|
||||||
|
|
||||||
|
@ -690,7 +716,6 @@ EOM
|
||||||
rescue Zlib::GzipFile::Error => e
|
rescue Zlib::GzipFile::Error => e
|
||||||
raise Gem::Package::FormatError.new(e.message, entry.full_name)
|
raise Gem::Package::FormatError.new(e.message, entry.full_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'rubygems/package/digest_io'
|
require 'rubygems/package/digest_io'
|
||||||
|
|
|
@ -420,6 +420,33 @@ class TestGemPackage < Gem::Package::TarTestCase
|
||||||
assert_equal %w[lib/code.rb], reader.contents
|
assert_equal %w[lib/code.rb], reader.contents
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_metadata
|
||||||
|
data_tgz = util_tar_gz { }
|
||||||
|
|
||||||
|
gem = util_tar do |tar|
|
||||||
|
tar.add_file 'data.tar.gz', 0644 do |io|
|
||||||
|
io.write data_tgz.string
|
||||||
|
end
|
||||||
|
|
||||||
|
tar.add_file 'metadata.gz', 0644 do |io|
|
||||||
|
Zlib::GzipWriter.wrap io do |gzio|
|
||||||
|
gzio.write @spec.to_yaml
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
gem_path = "#{@destination}/test.gem"
|
||||||
|
|
||||||
|
File.open gem_path, "wb" do |io|
|
||||||
|
io.write gem.string
|
||||||
|
end
|
||||||
|
|
||||||
|
spec, metadata = Gem::Package.metadata(gem_path)
|
||||||
|
|
||||||
|
assert_equal @spec, spec
|
||||||
|
assert_match @spec.to_yaml, metadata.force_encoding("UTF-8")
|
||||||
|
end
|
||||||
|
|
||||||
def test_contents
|
def test_contents
|
||||||
package = Gem::Package.new @gem
|
package = Gem::Package.new @gem
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue