Attached is a patch against the trunk that adds basic PGP signing
support (via GnuPG) to PackageTask.  It adds an accessor attribute
named "need_pgp_signature".  If set, PackageTask and GemPackageTask add
additional file tasks which use GnuPG (http://gnupg.org/) to create
detached PGP signatures of each package file type (.tgz, .tar.gz, .zip,
and .gem).

If that sounds like a bunch of technobabble, don't panic!  It's actually
really easy to use.  Say you've got the following task:

  Rake::GemPackageTask.new(gem_spec) do |pkg|
    pkg.need_tar_gz = true
  end

To add PGP signing support, you'd make it look like so:

  Rake::GemPackageTask.new(gem_spec) do |pkg|
    pkg.need_tar_gz = true
    pkg.need_pgp_signature = true
  end

If you'd like, you can also change the PGP program and/or signature file
extension to something else.  Here's an example:

  Rake::GemPackageTask.new(gem_spec) do |pkg|
    pkg.need_tar_gz = true

    # create pgp signatures for package files
    pkg.need_pgp_signature = true

    # use gpg2 and don't ASCII-armor the signature file
    pkg.pgp_command = 'gpg2 -b'

    # set the PGP signature extension to .sig
    pkg.pgp_file_extension = 'sig'
  end

Personally, I like this feature and find it incredibly useful, although
I could be persuaded by the argument that it doesn't really belong in
PackageTask.  So, at the moment I'm just tossing this out for
discussion, with the not-so-secret hope of sneaking it in under the
radar and into an actual release ;-).

Anyway, the patch is attached.  If you've got a munge-happy email
client, it's also available online at the following URL:

  http://pablotron.org/files/rake-20061212-pkg_pgp_sign.diff

These changes also work just fine under Rake 0.7.1, although the patch
doesn't apply cleanly due to minor whitespace differences in 0.7.1.  If
you're interested in trying out this patch without upgrading to the
development version of Rake, a patch against 0.7.1 is available here:

  http://pablotron.org/files/rake-0.7.1-pkg_pgp_sign.diff

The PGP signatures for both files can be found here:

  http://pablotron.org/files/rake-20061212-pkg_pgp_sign.diff.asc
  http://pablotron.org/files/rake-0.7.1-pkg_pgp_sign.diff.asc

Happy raking...

--
Paul Duncan <[EMAIL PROTECTED]>        OpenPGP Key ID: 0x82C29562
http://www.pablotron.org/               http://www.paulduncan.org/
Index: lib/rake/packagetask.rb
===================================================================
--- lib/rake/packagetask.rb     (revision 577)
+++ lib/rake/packagetask.rb     (working copy)
@@ -68,6 +68,15 @@
     # List of files to be included in the package.
     attr_accessor :package_files
 
+    # True if a detached, ASCII-armored signature of each package file should 
be produced (default is false).
+    attr_accessor :need_pgp_signature
+
+    # Command to create detached OpenPGP signature files (default is 'gpg 
-ba').
+    attr_accessor :pgp_command
+
+    # Extension for detached OpenPGP signature files (default is 'asc').
+    attr_accessor :pgp_file_extension
+
     # Create a Package Task with the given name and version. 
     def initialize(name=nil, version=nil)
       init(name, version)
@@ -85,6 +94,11 @@
       @need_tar_gz = false
       @need_tar_bz2 = false
       @need_zip = false
+
+      # pgp defaults (set to use GnuPG by default)
+      @need_pgp_signature = false
+      @pgp_command = 'gpg -ba'
+      @pgp_file_extension = 'asc'
     end
 
     # Create the tasks defined by this task library.
@@ -117,6 +131,8 @@
               sh %{tar #{flag}cvf #{file} #{package_name}}
             end
           end
+
+          pgp_task_for(file) if @need_pgp_signature
         end
       end
       
@@ -126,6 +142,8 @@
           chdir(package_dir) do
             sh %{zip -r #{zip_file} #{package_name}}
           end
+
+          pgp_task_for(zip_file) if @need_pgp_signature
         end
       end
 
@@ -148,6 +166,18 @@
       self
     end
 
+    def pgp_task_for(src_file)
+      src_path = "[EMAIL PROTECTED]/#{src_file}"
+      sig_path = "[EMAIL PROTECTED]"
+
+      task :package => [sig_path]
+      file sig_path => [src_path] do
+        chdir(@package_dir) do
+          sh [EMAIL PROTECTED] #{src_file}}
+        end
+      end
+    end
+
     def package_name
       @version ? "[EMAIL PROTECTED]@version}" : @name
     end
Index: lib/rake/gempackagetask.rb
===================================================================
--- lib/rake/gempackagetask.rb  (revision 577)
+++ lib/rake/gempackagetask.rb  (working copy)
@@ -86,6 +86,8 @@
           }
         }
       end
+
+      pgp_task_for(gem_file) if @need_pgp_signature
     end
     
     def gem_file
diff -ur rake-0.7.1/lib/rake/gempackagetask.rb 
rake-0.7.1-pgp_sign/lib/rake/gempackagetask.rb
--- rake-0.7.1/lib/rake/gempackagetask.rb       2006-12-12 21:48:03.000000000 
-0500
+++ rake-0.7.1-pgp_sign/lib/rake/gempackagetask.rb      2006-12-12 
21:40:04.000000000 -0500
@@ -86,6 +86,8 @@
          }
        }
       end
+
+      pgp_task_for(gem_file) if @need_pgp_signature
     end
     
     def gem_file
diff -ur rake-0.7.1/lib/rake/packagetask.rb 
rake-0.7.1-pgp_sign/lib/rake/packagetask.rb
--- rake-0.7.1/lib/rake/packagetask.rb  2006-12-12 21:48:03.000000000 -0500
+++ rake-0.7.1-pgp_sign/lib/rake/packagetask.rb 2006-12-12 21:46:38.000000000 
-0500
@@ -68,6 +68,15 @@
     # List of files to be included in the package.
     attr_accessor :package_files
 
+    # True if a detached, ASCII-armored signature of each package file should 
be produced (default is false).
+    attr_accessor :need_pgp_signature
+
+    # Command to create detached OpenPGP signature files (default is 'gpg 
-ba').
+    attr_accessor :pgp_command
+
+    # Extension for detached OpenPGP signature files (default is 'asc').
+    attr_accessor :pgp_file_extension
+
     # Create a Package Task with the given name and version. 
     def initialize(name=nil, version=nil)
       init(name, version)
@@ -85,6 +94,11 @@
       @need_tar_gz = false
       @need_tar_bz2 = false
       @need_zip = false
+
+      # pgp defaults (set to use GnuPG by default)
+      @need_pgp_signature = false
+      @pgp_command = 'gpg -ba'
+      @pgp_file_extension = 'asc'
     end
 
     # Create the tasks defined by this task library.
@@ -117,6 +131,8 @@
              sh %{tar #{flag}cvf #{file} #{package_name}}
            end
          end
+
+        pgp_task_file(file) if @need_pgp_signature
        end
       end
       
@@ -127,6 +143,8 @@
            sh %{zip -r #{zip_file} #{package_name}}
          end
        end
+
+        pgp_task_file(file) if @need_pgp_signature
       end
 
       directory package_dir
@@ -148,6 +166,18 @@
       self
     end
 
+    def pgp_task_for(src_file)
+      src_path = "[EMAIL PROTECTED]/#{src_file}"
+      sig_path = "[EMAIL PROTECTED]"
+
+      task :package => [sig_path]
+      file sig_path => [src_path] do
+        chdir(@package_dir) do
+          sh [EMAIL PROTECTED] #{src_file}}
+        end
+      end
+    end
+
     def package_name
       @version ? "[EMAIL PROTECTED]@version}" : @name
     end

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Rake-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rake-devel

Reply via email to