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
rescue NoMethodError => ex
15
# Using rubygems prior to 0.6.1
20
# Create a package based upon a Gem spec. Gem packages, as well as
21
# zip files and tar/gzipped packages can be produced by this task.
23
# In addition to the Rake targets generated by PackageTask, a
24
# GemPackageTask will also generate the following tasks:
26
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.gem"</b>]
27
# Create a Ruby GEM package with the given name and version.
29
# Example using a Ruby GEM spec:
33
# spec = Gem::Specification.new do |s|
34
# s.platform = Gem::Platform::RUBY
35
# s.summary = "Ruby based make-like utility."
37
# s.version = PKG_VERSION
38
# s.requirements << 'none'
39
# s.require_path = 'lib'
40
# s.autorequire = 'rake'
42
# s.description = <<EOF
43
# Rake is a Make-like program implemented in Ruby. Tasks
44
# and dependencies are specified in standard Ruby syntax.
48
# Rake::GemPackageTask.new(spec) do |pkg|
53
class GemPackageTask < PackageTask
54
# Ruby GEM spec containing the metadata for this package. The
55
# name, version and package_files are automatically determined
56
# from the GEM spec and don't need to be explicitly provided.
57
attr_accessor :gem_spec
59
# Create a GEM Package task library. Automatically define the gem
60
# if a block is given. If no block is supplied, then +define+
61
# needs to be called to define the task.
62
def initialize(gem_spec)
64
yield self if block_given?
65
define if block_given?
68
# Initialization tasks without the "yield self" or define
71
super(gem.name, gem.version)
73
@package_files += gem_spec.files if gem_spec.files
76
# Create the Rake tasks and actions specified by this
77
# GemPackageTask. (+define+ is automatically called if a block is
81
task :package => [:gem]
82
desc "Build the gem file #{gem_file}"
83
task :gem => ["#{package_dir}/#{gem_file}"]
84
file "#{package_dir}/#{gem_file}" => [package_dir] + @gem_spec.files do
85
when_writing("Creating GEM") {
86
Gem::Builder.new(gem_spec).build
88
mv gem_file, "#{package_dir}/#{gem_file}"
95
if @gem_spec.platform == Gem::Platform::RUBY
98
"#{package_name}-#{@gem_spec.platform}.gem"