3
# Define a package task library to aid in the definition of GEM
8
require 'rake/packagetask'
9
require 'rubygems/user_interaction'
10
require 'rubygems/builder'
14
# Create a package based upon a Gem spec. Gem packages, as well as
15
# zip files and tar/gzipped packages can be produced by this task.
17
# In addition to the Rake targets generated by PackageTask, a
18
# GemPackageTask will also generate the following tasks:
20
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.gem"</b>]
21
# Create a Ruby GEM package with the given name and version.
23
# Example using a Ruby GEM spec:
27
# spec = Gem::Specification.new do |s|
28
# s.platform = Gem::Platform::RUBY
29
# s.summary = "Ruby based make-like utility."
31
# s.version = PKG_VERSION
32
# s.requirements << 'none'
33
# s.require_path = 'lib'
34
# s.autorequire = 'rake'
36
# s.description = <<EOF
37
# Rake is a Make-like program implemented in Ruby. Tasks
38
# and dependencies are specified in standard Ruby syntax.
42
# Rake::GemPackageTask.new(spec) do |pkg|
47
class GemPackageTask < PackageTask
48
# Ruby GEM spec containing the metadata for this package. The
49
# name, version and package_files are automatically determined
50
# from the GEM spec and don't need to be explicitly provided.
51
attr_accessor :gem_spec
53
# Create a GEM Package task library. Automatically define the gem
54
# if a block is given. If no block is supplied, then +define+
55
# needs to be called to define the task.
56
def initialize(gem_spec)
58
yield self if block_given?
59
define if block_given?
62
# Initialization tasks without the "yield self" or define
65
super(gem.name, gem.version)
67
@package_files += gem_spec.files if gem_spec.files
70
# Create the Rake tasks and actions specified by this
71
# GemPackageTask. (+define+ is automatically called if a block is
75
task :package => [:gem]
76
desc "Build the gem file #{gem_file}"
77
task :gem => ["#{package_dir}/#{gem_file}"]
78
file "#{package_dir}/#{gem_file}" => [package_dir] + @gem_spec.files do
79
when_writing("Creating GEM") {
80
Gem::Builder.new(gem_spec).build
82
mv gem_file, "#{package_dir}/#{gem_file}"
89
if @gem_spec.platform == Gem::Platform::RUBY
92
"#{package_name}-#{@gem_spec.platform}.gem"