mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Import RubyGems trunk revision 1493.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7a4aad7535
commit
fbf59bdbea
144 changed files with 21330 additions and 0 deletions
81
lib/rubygems/builder.rb
Normal file
81
lib/rubygems/builder.rb
Normal file
|
@ -0,0 +1,81 @@
|
|||
#--
|
||||
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
||||
# All rights reserved.
|
||||
# See LICENSE.txt for permissions.
|
||||
#++
|
||||
|
||||
module Gem
|
||||
|
||||
##
|
||||
# The Builder class processes RubyGem specification files
|
||||
# to produce a .gem file.
|
||||
#
|
||||
class Builder
|
||||
|
||||
include UserInteraction
|
||||
##
|
||||
# Constructs a builder instance for the provided specification
|
||||
#
|
||||
# spec:: [Gem::Specification] The specification instance
|
||||
#
|
||||
def initialize(spec)
|
||||
require "yaml"
|
||||
require "rubygems/package"
|
||||
require "rubygems/security"
|
||||
|
||||
@spec = spec
|
||||
end
|
||||
|
||||
##
|
||||
# Builds the gem from the specification. Returns the name of the file
|
||||
# written.
|
||||
#
|
||||
def build
|
||||
@spec.mark_version
|
||||
@spec.validate
|
||||
@signer = sign
|
||||
write_package
|
||||
say success
|
||||
@spec.file_name
|
||||
end
|
||||
|
||||
def success
|
||||
<<-EOM
|
||||
Successfully built RubyGem
|
||||
Name: #{@spec.name}
|
||||
Version: #{@spec.version}
|
||||
File: #{@spec.full_name+'.gem'}
|
||||
EOM
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sign
|
||||
# if the signing key was specified, then load the file, and swap
|
||||
# to the public key (TODO: we should probably just omit the
|
||||
# signing key in favor of the signing certificate, but that's for
|
||||
# the future, also the signature algorithm should be configurable)
|
||||
signer = nil
|
||||
if @spec.respond_to?(:signing_key) && @spec.signing_key
|
||||
signer = Gem::Security::Signer.new(@spec.signing_key, @spec.cert_chain)
|
||||
@spec.signing_key = nil
|
||||
@spec.cert_chain = signer.cert_chain.map { |cert| cert.to_s }
|
||||
end
|
||||
signer
|
||||
end
|
||||
|
||||
def write_package
|
||||
Package.open(@spec.file_name, "w", @signer) do |pkg|
|
||||
pkg.metadata = @spec.to_yaml
|
||||
@spec.files.each do |file|
|
||||
next if File.directory? file
|
||||
pkg.add_file_simple(file, File.stat(@spec.file_name).mode & 0777,
|
||||
File.size(file)) do |os|
|
||||
os.write File.open(file, "rb"){|f|f.read}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue