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.zip”
-
Create a zip package archive (if need_zip is true).
Example:
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 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.
Methods inherited from TaskLib
Constructor Details
#initialize(name = nil, version = nil) {|_self| ... } ⇒ PackageTask
Create a Package Task with the given name and version.
60 61 62 63 64 |
# File 'lib/rake/packagetask.rb', line 60 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).
42 43 44 |
# File 'lib/rake/packagetask.rb', line 42 def name @name end |
#need_tar ⇒ Object
True if a gzipped tar file should be produced (default is false).
51 52 53 |
# File 'lib/rake/packagetask.rb', line 51 def need_tar @need_tar end |
#need_zip ⇒ Object
True if a zip file should be produced (default is false)
54 55 56 |
# File 'lib/rake/packagetask.rb', line 54 def need_zip @need_zip end |
#package_dir ⇒ Object
Directory used to store the package files (default is ‘pkg’).
48 49 50 |
# File 'lib/rake/packagetask.rb', line 48 def package_dir @package_dir end |
#package_files ⇒ Object
List of files to be included in the package.
57 58 59 |
# File 'lib/rake/packagetask.rb', line 57 def package_files @package_files end |
#version ⇒ Object
Version of the package (e.g. ‘1.3.2’).
45 46 47 |
# File 'lib/rake/packagetask.rb', line 45 def version @version end |
Instance Method Details
#define ⇒ Object
Create the tasks defined by this task library.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 |
# File 'lib/rake/packagetask.rb', line 77 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] 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}} 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.
67 68 69 70 71 72 73 74 |
# File 'lib/rake/packagetask.rb', line 67 def init(name, version) @name = name @version = version @package_files = Rake::FileList.new @package_dir = 'pkg' @need_tar = false @need_zip = false end |