2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4 # See LICENSE.txt for permissions.
10 # The Builder class processes RubyGem specification files
11 # to produce a .gem file.
15 include UserInteraction
17 # Constructs a builder instance for the provided specification
19 # spec:: [Gem::Specification] The specification instance
23 require "rubygems/package"
24 require "rubygems/security"
30 # Builds the gem from the specification. Returns the name of the file
44 Successfully built RubyGem
46 Version: #{@spec.version}
47 File: #{@spec.full_name+'.gem'}
54 # if the signing key was specified, then load the file, and swap
55 # to the public key (TODO: we should probably just omit the
56 # signing key in favor of the signing certificate, but that's for
57 # the future, also the signature algorithm should be configurable)
59 if @spec.respond_to?(:signing_key) && @spec.signing_key
60 signer = Gem::Security::Signer.new(@spec.signing_key, @spec.cert_chain)
61 @spec.signing_key = nil
62 @spec.cert_chain = signer.cert_chain.map { |cert| cert.to_s }
68 open @spec.file_name, 'wb' do |gem_io|
69 Gem::Package.open gem_io, 'w', @signer do |pkg|
70 pkg.metadata = @spec.to_yaml
72 @spec.files.each do |file|
73 next if File.directory? file
76 mode = stat.mode & 0777
79 pkg.add_file_simple file, mode, size do |tar_io|
80 tar_io.write open(file, "rb") { |f| f.read }