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
Create a Package Task with the given name and version.
[ show source ]
# File lib/rake/packagetask.rb, line 78 78: def initialize(name=nil, version=nil) 79: init(name, version) 80: yield self if block_given? 81: define unless name.nil? 82: end
Public Instance methods
Create the tasks defined by this task library.
[ show source ]
# File lib/rake/packagetask.rb, line 99 99: def define 100: fail "Version required (or :noversion)" if @version.nil? 101: @version = nil if :noversion == @version 102: 103: desc "Build all the packages" 104: task :package 105: 106: desc "Force a rebuild of the package files" 107: task :repackage => [:clobber_package, :package] 108: 109: desc "Remove package products" 110: task :clobber_package do 111: rm_r package_dir rescue nil 112: end 113: 114: task :clobber => [:clobber_package] 115: 116: [ 117: [need_tar, tgz_file, "z"], 118: [need_tar_gz, tar_gz_file, "z"], 119: [need_tar_bz2, tar_bz2_file, "j"] 120: ].each do |(need, file, flag)| 121: if need 122: task :package => ["#{package_dir}/#{file}"] 123: file "#{package_dir}/#{file}" => [package_dir_path] + package_files do 124: chdir(package_dir) do 125: sh %{#{@tar_command} #{flag}cvf #{file} #{package_name}} 126: end 127: end 128: end 129: end 130: 131: if need_zip 132: task :package => ["#{package_dir}/#{zip_file}"] 133: file "#{package_dir}/#{zip_file}" => [package_dir_path] + package_files do 134: chdir(package_dir) do 135: sh %{#{@zip_command} -r #{zip_file} #{package_name}} 136: end 137: end 138: end 139: 140: directory package_dir 141: 142: file package_dir_path => @package_files do 143: mkdir_p package_dir rescue nil 144: @package_files.each do |fn| 145: f = File.join(package_dir_path, fn) 146: fdir = File.dirname(f) 147: mkdir_p(fdir) if !File.exist?(fdir) 148: if File.directory?(fn) 149: mkdir_p(f) 150: else 151: rm_f f 152: safe_ln(fn, f) 153: end 154: end 155: end 156: self 157: end
Initialization that bypasses the "yield self" and "define" step.
[ show source ]
# File lib/rake/packagetask.rb, line 85 85: def init(name, version) 86: @name = name 87: @version = version 88: @package_files = Rake::FileList.new 89: @package_dir = 'pkg' 90: @need_tar = false 91: @need_tar_gz = false 92: @need_tar_bz2 = false 93: @need_zip = false 94: @tar_command = 'tar' 95: @zip_command = 'zip' 96: end
[ show source ]
# File lib/rake/packagetask.rb, line 163 163: def package_dir_path 164: "#{package_dir}/#{package_name}" 165: end
[ show source ]
# File lib/rake/packagetask.rb, line 159 159: def package_name 160: @version ? "#{@name}-#{@version}" : @name 161: end
[ show source ]
# File lib/rake/packagetask.rb, line 175 175: def tar_bz2_file 176: "#{package_name}.tar.bz2" 177: end
[ show source ]
# File lib/rake/packagetask.rb, line 171 171: def tar_gz_file 172: "#{package_name}.tar.gz" 173: end
[ show source ]
# File lib/rake/packagetask.rb, line 167 167: def tgz_file 168: "#{package_name}.tgz" 169: end
[ show source ]
# File lib/rake/packagetask.rb, line 179 179: def zip_file 180: "#{package_name}.zip" 181: end