Permalink
Browse files

Spiking out gem signing support

  • Loading branch information...
1 parent 4f9d140 commit 6acef2978ab907eba1d876b57d2d862666acb9c6 @technicalpickles committed Nov 22, 2009
View
1 Rakefile
@@ -27,6 +27,7 @@ Jeweler::Tasks.new do |gem|
gem.add_development_dependency "yard"
gem.add_development_dependency "cucumber"
+
end
Jeweler::GemcutterTasks.new
View
4 bin/jeweler
@@ -1,5 +1,5 @@
-#!/usr/bin/env ruby
-$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
+#!/usr/bin/env ruby -I../lib
+#$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'jeweler/generator'
exit Jeweler::Generator::Application.run!(*ARGV)
View
7 jeweler.gemspec
@@ -9,15 +9,16 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Josh Nichols"]
- s.date = %q{2009-11-19}
+ s.date = %q{2009-11-20}
s.default_executable = %q{jeweler}
s.description = %q{Simple and opinionated helper for creating Rubygem projects on GitHub}
s.email = %q{josh@technicalpickles.com}
s.executables = ["jeweler"]
s.extra_rdoc_files = [
"ChangeLog.markdown",
"LICENSE",
- "README.markdown"
+ "README.markdown",
+ "TODO"
]
s.files = [
".gitignore",
@@ -50,6 +51,7 @@ Gem::Specification.new do |s|
"lib/jeweler.rb",
"lib/jeweler/commands.rb",
"lib/jeweler/commands/build_gem.rb",
+ "lib/jeweler/commands/build_signing_key.rb",
"lib/jeweler/commands/check_dependencies.rb",
"lib/jeweler/commands/install_gem.rb",
"lib/jeweler/commands/release_to_gemcutter.rb",
@@ -82,6 +84,7 @@ Gem::Specification.new do |s|
"lib/jeweler/generator/testunit_mixin.rb",
"lib/jeweler/generator/yard_mixin.rb",
"lib/jeweler/rubyforge_tasks.rb",
+ "lib/jeweler/signer.rb",
"lib/jeweler/specification.rb",
"lib/jeweler/tasks.rb",
"lib/jeweler/templates/.document",
View
5 lib/jeweler.rb
@@ -20,6 +20,7 @@ class Jeweler
autoload :Tasks, 'jeweler/tasks'
autoload :GemcutterTasks, 'jeweler/gemcutter_tasks'
autoload :RubyforgeTasks, 'jeweler/rubyforge_tasks'
+ autoload :Signer, 'jeweler/signer'
autoload :Specification, 'jeweler/specification'
attr_reader :gemspec, :gemspec_helper, :version_helper
@@ -141,6 +142,10 @@ def setup_rubyforge
Jeweler::Commands::SetupRubyforge.build_for(self).run
end
+ def build_signing_key
+ Jeweler::Commands::BuildSigningKey.build_for(self).run
+ end
+
def check_dependencies(type = nil)
command = Jeweler::Commands::CheckDependencies.build_for(self)
command.type = type
View
1 lib/jeweler/commands.rb
@@ -10,6 +10,7 @@ module Commands
autoload :SetupRubyforge, 'jeweler/commands/setup_rubyforge'
autoload :ValidateGemspec, 'jeweler/commands/validate_gemspec'
autoload :WriteGemspec, 'jeweler/commands/write_gemspec'
+ autoload :BuildSigningKey, 'jeweler/commands/build_signing_key'
module Version
autoload :Base, 'jeweler/commands/version/base'
View
12 lib/jeweler/commands/build_gem.rb
@@ -1,17 +1,27 @@
class Jeweler
module Commands
class BuildGem
- attr_accessor :base_dir, :gemspec_helper, :file_utils, :version_helper
+ attr_accessor :base_dir, :gemspec_helper, :file_utils, :version_helper, :signer, :output
def initialize
self.file_utils = FileUtils
+ self.signer = Jeweler::Signer.new
+ self.output = $stdout
end
def run
gemspec_helper.update_version(version_helper) unless gemspec_helper.has_version?
gemspec = gemspec_helper.parse
+ if signer.can_sign?
+ output.puts "Signing with #{signer.key_file}"
+ signer.sign(gemspec) if signer.can_sign?
+
+ else
+ output.puts "Not signing the gem"
+ end
+
require 'rubygems/builder'
gem_file_name = Gem::Builder.new(gemspec).build
View
30 lib/jeweler/commands/build_signing_key.rb
@@ -0,0 +1,30 @@
+class Jeweler
+ module Commands
+ class BuildSigningKey
+ attr_accessor :gemspec_helper, :output, :signer
+
+ def initialize
+ self.output = $stdout
+ self.signer = Signer.new
+ end
+
+ def run
+ if signer.can_sign?
+ output.puts "Signing key already exists, skipping."
+ else
+ output.puts "Generating certificate"
+ signer.build_for(gemspec_helper.parse.email)
+ output.puts "Installed key and certificate."
+ end
+ end
+
+ def self.build_for(jeweler)
+ command = new
+ command.output = jeweler.output
+ command.gemspec_helper = jeweler.gemspec_helper
+ command
+ end
+ end
+ end
+end
+
View
28 lib/jeweler/signer.rb
@@ -0,0 +1,28 @@
+class Jeweler
+ class Signer
+ attr_accessor :key_file, :cert_file
+
+ def initialize
+ self.key_file = File.expand_path("~/.gem/gem-private_key.pem")
+ self.cert_file = File.expand_path("~/.gem/gem-public_cert.pem")
+ end
+
+ def can_sign?
+ File.exist?(key_file) && File.exist?(cert_file)
+ end
+
+ def sign(gemspec)
+ gemspec.signing_key = key_file
+ gemspec.cert_chain = [cert_file]
+ end
+
+ def build_for(email)
+ sh("gem cert --build #{email}")
+
+ mv "gem-private_key.pem", key_file, :verbose => true
+ mv "gem-public_cert.pem", cert_file, :verbose => true
+
+ end
+ end
+
+end
View
5 lib/jeweler/tasks.rb
@@ -170,7 +170,12 @@ def define
task :development do
jeweler.check_dependencies(:development)
end
+ end
+ namespace :signing_key do
+ task :build do
+ jeweler.build_signing_key
+ end
end
end

0 comments on commit 6acef29

Please sign in to comment.