lib/rake/packagetask.rb in rake-0.4.15 vs lib/rake/packagetask.rb in rake-0.5.0
- old
+ new
@@ -25,16 +25,22 @@
# of date.
#
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tgz"</b>]
# Create a gzipped tar package (if <em>need_tar</em> is true).
#
+ # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.gz"</b>]
+ # Create a gzipped tar package (if <em>need_tar_gz</em> is true).
+ #
+ # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.bz2"</b>]
+ # Create a bzip2'd tar package (if <em>need_tar_bz2</em> is true).
+ #
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.zip"</b>]
# Create a zip package archive (if <em>need_zip</em> is true).
#
# Example:
#
- # PackageTask.new("rake", "1.2.3") do |p|
+ # Rake::PackageTask.new("rake", "1.2.3") do |p|
# p.need_tar = true
# p.package_files.include("lib/**/*.rb")
# end
#
class PackageTask < TaskLib
@@ -45,13 +51,19 @@
attr_accessor :version
# Directory used to store the package files (default is 'pkg').
attr_accessor :package_dir
- # True if a gzipped tar file should be produced (default is false).
+ # True if a gzipped tar file (tgz) should be produced (default is false).
attr_accessor :need_tar
+ # True if a gzipped tar file (tar.gz) should be produced (default is false).
+ attr_accessor :need_tar_gz
+
+ # True if a bzip2'd tar file (tar.bz2) should be produced (default is false).
+ attr_accessor :need_tar_bz2
+
# True if a zip file should be produced (default is false)
attr_accessor :need_zip
# List of files to be included in the package.
attr_accessor :package_files
@@ -68,10 +80,12 @@
@name = name
@version = version
@package_files = Rake::FileList.new
@package_dir = 'pkg'
@need_tar = false
+ @need_tar_gz = false
+ @need_tar_bz2 = false
@need_zip = false
end
# Create the tasks defined by this task library.
def define
@@ -89,19 +103,25 @@
rm_r package_dir rescue nil
end
task :clobber => [:clobber_package]
- if need_tar
- task :package => ["#{package_dir}/#{tgz_file}"]
- file "#{package_dir}/#{tgz_file}" => [package_dir_path] + package_files do
- chdir(package_dir) do
- sh %{tar zcvf #{tgz_file} #{package_name}}
+ [
+ [need_tar, tgz_file, "z"],
+ [need_tar_gz, tar_gz_file, "z"],
+ [need_tar_bz2, tar_bz2_file, "j"]
+ ].each do |(need, file, flag)|
+ if need
+ task :package => ["#{package_dir}/#{file}"]
+ file "#{package_dir}/#{file}" => [package_dir_path] + package_files do
+ chdir(package_dir) do
+ sh %{tar #{flag}cvf #{file} #{package_name}}
+ end
end
end
end
-
+
if need_zip
task :package => ["#{package_dir}/#{zip_file}"]
file "#{package_dir}/#{zip_file}" => [package_dir_path] + package_files do
chdir(package_dir) do
sh %{zip -r #{zip_file} #{package_name}}
@@ -138,9 +158,17 @@
"#{package_dir}/#{package_name}"
end
def tgz_file
"#{package_name}.tgz"
+ end
+
+ def tar_gz_file
+ "#{package_name}.tar.gz"
+ end
+
+ def tar_bz2_file
+ "#{package_name}.tar.bz2"
end
def zip_file
"#{package_name}.zip"
end