Class: Rake::PackageTask
Overview
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
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Name of the package (from the GEM Spec).
-
#need_tar ⇒ Object
True if a gzipped tar file (tgz) should be produced (default is false).
-
#need_tar_bz2 ⇒ Object
True if a bzip2’d tar file (tar.bz2) should be produced (default is false).
-
#need_tar_gz ⇒ Object
True if a gzipped tar file (tar.gz) should be produced (default is false).
-
#need_zip ⇒ Object
True if a zip file should be produced (default is false).
-
#package_dir ⇒ Object
Directory used to store the package files (default is ‘pkg’).
-
#package_files ⇒ Object
List of files to be included in the package.
-
#version ⇒ Object
Version of the package (e.g. ‘1.3.2’).
Instance Method Summary collapse
-
#define ⇒ Object
Create the tasks defined by this task library.
-
#init(name, version) ⇒ Object
Initialization that bypasses the “yield self” and “define” step.
-
#initialize(name = nil, version = nil) {|_self| ... } ⇒ PackageTask
constructor
Create a Package Task with the given name and version.
- #package_dir_path ⇒ Object
- #package_name ⇒ Object
- #tar_bz2_file ⇒ Object
- #tar_gz_file ⇒ Object
- #tgz_file ⇒ Object
- #zip_file ⇒ Object
Methods inherited from TaskLib
Methods included from Cloneable
Constructor Details
#initialize(name = nil, version = nil) {|_self| ... } ⇒ PackageTask
Create a Package Task with the given name and version.
72 73 74 75 76 |
# File 'lib/rake/packagetask.rb', line 72 def initialize(name=nil, version=nil) init(name, version) yield self if block_given? define unless name.nil? end |
Instance Attribute Details
#name ⇒ Object
Name of the package (from the GEM Spec).
48 49 50 |
# File 'lib/rake/packagetask.rb', line 48 def name @name end |
#need_tar ⇒ Object
True if a gzipped tar file (tgz) should be produced (default is false).
57 58 59 |
# File 'lib/rake/packagetask.rb', line 57 def need_tar @need_tar end |
#need_tar_bz2 ⇒ Object
True if a bzip2’d tar file (tar.bz2) should be produced (default is false).
63 64 65 |
# File 'lib/rake/packagetask.rb', line 63 def need_tar_bz2 @need_tar_bz2 end |
#need_tar_gz ⇒ Object
True if a gzipped tar file (tar.gz) should be produced (default is false).
60 61 62 |
# File 'lib/rake/packagetask.rb', line 60 def need_tar_gz @need_tar_gz end |
#need_zip ⇒ Object
True if a zip file should be produced (default is false)
66 67 68 |
# File 'lib/rake/packagetask.rb', line 66 def need_zip @need_zip end |
#package_dir ⇒ Object
Directory used to store the package files (default is ‘pkg’).
54 55 56 |
# File 'lib/rake/packagetask.rb', line 54 def package_dir @package_dir end |
#package_files ⇒ Object
List of files to be included in the package.
69 70 71 |
# File 'lib/rake/packagetask.rb', line 69 def package_files @package_files end |
#version ⇒ Object
Version of the package (e.g. ‘1.3.2’).
51 52 53 |
# File 'lib/rake/packagetask.rb', line 51 def version @version end |
Instance Method Details
#define ⇒ Object
Create the tasks defined by this task library.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rake/packagetask.rb', line 91 def define fail "Version required (or :noversion)" if @version.nil? @version = nil if :noversion == @version desc "Build all the packages" task :package desc "Force a rebuild of the package files" task :repackage => [:clobber_package, :package] desc "Remove package products" task :clobber_package do rm_r package_dir rescue nil end task :clobber => [:clobber_package] [ [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}} end end end directory package_dir file package_dir_path => @package_files do mkdir_p package_dir rescue nil @package_files.each do |fn| f = File.join(package_dir_path, fn) fdir = File.dirname(f) mkdir_p(fdir) if !File.exist?(fdir) if File.directory?(fn) mkdir_p(f) else rm_f f safe_ln(fn, f) end end end self end |
#init(name, version) ⇒ Object
Initialization that bypasses the “yield self” and “define” step.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rake/packagetask.rb', line 79 def init(name, version) @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 |
#package_dir_path ⇒ Object
155 156 157 |
# File 'lib/rake/packagetask.rb', line 155 def package_dir_path "#{package_dir}/#{package_name}" end |
#package_name ⇒ Object
151 152 153 |
# File 'lib/rake/packagetask.rb', line 151 def package_name @version ? "#{@name}-#{@version}" : @name end |
#tar_bz2_file ⇒ Object
167 168 169 |
# File 'lib/rake/packagetask.rb', line 167 def tar_bz2_file "#{package_name}.tar.bz2" end |
#tar_gz_file ⇒ Object
163 164 165 |
# File 'lib/rake/packagetask.rb', line 163 def tar_gz_file "#{package_name}.tar.gz" end |
#tgz_file ⇒ Object
159 160 161 |
# File 'lib/rake/packagetask.rb', line 159 def tgz_file "#{package_name}.tgz" end |
#zip_file ⇒ Object
171 172 173 |
# File 'lib/rake/packagetask.rb', line 171 def zip_file "#{package_name}.zip" end |