Create a packaging task that will package the project into distributable files (e.g zip archive or tar files).

The PackageTask will create the following targets:

:package
Create all the requested package files.
:clobber_package
Delete all the package files. This target is automatically added to the main clobber target.
:repackage
Rebuild the package files from scratch, even if they are not out of date.
"package_dir/name-version.tgz"
Create a gzipped tar package (if need_tar is true).
"package_dir/name-version.tar.gz"
Create a gzipped tar package (if need_tar_gz is true).
"package_dir/name-version.tar.bz2"
Create a bzip2‘d tar package (if need_tar_bz2 is true).
"package_dir/name-version.zip"
Create a zip package archive (if need_zip is true).

Example:

  Rake::PackageTask.new("rake", "1.2.3") do |p|
    p.need_tar = true
    p.package_files.include("lib/**/*.rb")
  end
Methods
Attributes
[RW] name Name of the package (from the GEM Spec).
[RW] need_tar True if a gzipped tar file (tgz) should be produced (default is false).
[RW] need_tar_bz2 True if a bzip2‘d tar file (tar.bz2) should be produced (default is false).
[RW] need_tar_gz True if a gzipped tar file (tar.gz) should be produced (default is false).
[RW] need_zip True if a zip file should be produced (default is false)
[RW] package_dir Directory used to store the package files (default is ‘pkg’).
[RW] package_files List of files to be included in the package.
[RW] tar_command Tar command for gzipped or bzip2ed archives. The default is ‘tar’.
[RW] version Version of the package (e.g. ‘1.3.2’).
[RW] zip_command Zip command for zipped archives. The default is ‘zip’.
Public Class methods
new(name=nil, version=nil) {|self if block_given?| ...}

Create a Package Task with the given name and version.

    # File lib/rake/packagetask.rb, line 80
80:     def initialize(name=nil, version=nil)
81:       init(name, version)
82:       yield self if block_given?
83:       define unless name.nil?
84:     end
Public Instance methods
define()

Create the tasks defined by this task library.

     # File lib/rake/packagetask.rb, line 101
101:     def define
102:       fail "Version required (or :noversion)" if @version.nil?
103:       @version = nil if :noversion == @version
104: 
105:       desc "Build all the packages"
106:       task :package
107:       
108:       desc "Force a rebuild of the package files"
109:       task 'package:force' => ['package:clean', :package]
110:       
111:       desc "Remove package products" 
112:       task 'package:clean' do
113:         rm_r package_dir rescue nil
114:       end
115: 
116:       task :clean => ['package:clean']
117: 
118:       [
119:         [need_tar, tgz_file, "z"],
120:         [need_tar_gz, tar_gz_file, "z"],
121:         [need_tar_bz2, tar_bz2_file, "j"]
122:       ].each do |(need, file, flag)|
123:         if need
124:           task :package => ["#{package_dir}/#{file}"]
125:           file "#{package_dir}/#{file}" => [package_dir_path] + package_files do
126:             chdir(package_dir) do
127:               sh %{#{@tar_command} #{flag}cvf #{file} #{package_name}}
128:             end
129:           end
130:         end
131:       end
132:       
133:       if need_zip
134:         task :package => ["#{package_dir}/#{zip_file}"]
135:         file "#{package_dir}/#{zip_file}" => [package_dir_path] + package_files do
136:           chdir(package_dir) do
137:             sh %{#{@zip_command} -r #{zip_file} #{package_name}}
138:           end
139:         end
140:       end
141: 
142:       directory package_dir
143: 
144:       file package_dir_path => @package_files do
145:         mkdir_p package_dir rescue nil
146:         @package_files.each do |fn|
147:           f = File.join(package_dir_path, fn)
148:           fdir = File.dirname(f)
149:           mkdir_p(fdir) if !File.exist?(fdir)
150:           if File.directory?(fn)
151:             mkdir_p(f)
152:           else
153:             rm_f f
154:             safe_ln(fn, f)
155:           end
156:         end
157:       end
158:       self
159:     end
init(name, version)

Initialization that bypasses the "yield self" and "define" step.

    # File lib/rake/packagetask.rb, line 87
87:     def init(name, version)
88:       @name = name
89:       @version = version
90:       @package_files = Rake::FileList.new
91:       @package_dir = 'pkg'
92:       @need_tar = false
93:       @need_tar_gz = false
94:       @need_tar_bz2 = false
95:       @need_zip = false
96:       @tar_command = 'tar'
97:       @zip_command = 'zip'
98:     end
package_dir_path()
     # File lib/rake/packagetask.rb, line 165
165:     def package_dir_path
166:       "#{package_dir}/#{package_name}"
167:     end
package_name()
     # File lib/rake/packagetask.rb, line 161
161:     def package_name
162:       @version ? "#{@name}-#{@version}" : @name
163:     end
tar_bz2_file()
     # File lib/rake/packagetask.rb, line 177
177:     def tar_bz2_file
178:       "#{package_name}.tar.bz2"
179:     end
tar_gz_file()
     # File lib/rake/packagetask.rb, line 173
173:     def tar_gz_file
174:       "#{package_name}.tar.gz"
175:     end
tgz_file()
     # File lib/rake/packagetask.rb, line 169
169:     def tgz_file
170:       "#{package_name}.tgz"
171:     end
zip_file()
     # File lib/rake/packagetask.rb, line 181
181:     def zip_file
182:       "#{package_name}.zip"
183:     end