Class: Rake::PackageTask

Inherits:
TaskLib show all
Defined in:
lib/rake/packagetask.rb

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

Constant Summary

Constant Summary

Constants included from FileUtilsExt

FileUtilsExt::DEFAULT

Constants included from FileUtils

FileUtils::LN_SUPPORTED, FileUtils::RUBY

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from TaskLib

#paste

Methods included from FileUtilsExt

#nowrite, #rake_check_options, #rake_merge_option, #rake_output_message, #verbose, #when_writing

Methods included from FileUtils

#ruby, #safe_ln, #sh, #split_all

Methods included from Cloneable

#clone, #dup

Constructor Details

- (PackageTask) initialize(name = nil, version = nil) {|_self| ... }

Create a Package Task with the given name and version. Use :noversion as the version to build a package without a version or to provide a fully-versioned package name.

Yields:

  • (_self)

Yield Parameters:



79
80
81
82
83
# File 'lib/rake/packagetask.rb', line 79

def initialize(name=nil, version=nil)
  init(name, version)
  yield self if block_given?
  define unless name.nil?
end

Instance Attribute Details

- (Object) name

Name of the package (from the GEM Spec).



46
47
48
# File 'lib/rake/packagetask.rb', line 46

def name
  @name
end

- (Object) need_tar

True if a gzipped tar file (tgz) should be produced (default is false).



55
56
57
# File 'lib/rake/packagetask.rb', line 55

def need_tar
  @need_tar
end

- (Object) need_tar_bz2

True if a bzip2'd tar file (tar.bz2) should be produced (default is false).



61
62
63
# File 'lib/rake/packagetask.rb', line 61

def need_tar_bz2
  @need_tar_bz2
end

- (Object) need_tar_gz

True if a gzipped tar file (tar.gz) should be produced (default is false).



58
59
60
# File 'lib/rake/packagetask.rb', line 58

def need_tar_gz
  @need_tar_gz
end

- (Object) need_zip

True if a zip file should be produced (default is false)



64
65
66
# File 'lib/rake/packagetask.rb', line 64

def need_zip
  @need_zip
end

- (Object) package_dir

Directory used to store the package files (default is 'pkg').



52
53
54
# File 'lib/rake/packagetask.rb', line 52

def package_dir
  @package_dir
end

- (Object) package_files

List of files to be included in the package.



67
68
69
# File 'lib/rake/packagetask.rb', line 67

def package_files
  @package_files
end

- (Object) tar_command

Tar command for gzipped or bzip2ed archives. The default is 'tar'.



70
71
72
# File 'lib/rake/packagetask.rb', line 70

def tar_command
  @tar_command
end

- (Object) version

Version of the package (e.g. '1.3.2').



49
50
51
# File 'lib/rake/packagetask.rb', line 49

def version
  @version
end

- (Object) zip_command

Zip command for zipped archives. The default is 'zip'.



73
74
75
# File 'lib/rake/packagetask.rb', line 73

def zip_command
  @zip_command
end

Instance Method Details

- (Object) define

Create the tasks defined by this task library.



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
150
151
152
153
154
155
156
157
158
# File 'lib/rake/packagetask.rb', line 100

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_command} #{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_command} -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

- (Object) init(name, version)

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



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rake/packagetask.rb', line 86

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
  @tar_command = 'tar'
  @zip_command = 'zip'
end

- (Object) package_dir_path



164
165
166
# File 'lib/rake/packagetask.rb', line 164

def package_dir_path
  "#{package_dir}/#{package_name}"
end

- (Object) package_name



160
161
162
# File 'lib/rake/packagetask.rb', line 160

def package_name
  @version ? "#{@name}-#{@version}" : @name
end

- (Object) tar_bz2_file



176
177
178
# File 'lib/rake/packagetask.rb', line 176

def tar_bz2_file
  "#{package_name}.tar.bz2"
end

- (Object) tar_gz_file



172
173
174
# File 'lib/rake/packagetask.rb', line 172

def tar_gz_file
  "#{package_name}.tar.gz"
end

- (Object) tgz_file



168
169
170
# File 'lib/rake/packagetask.rb', line 168

def tgz_file
  "#{package_name}.tgz"
end

- (Object) zip_file



180
181
182
# File 'lib/rake/packagetask.rb', line 180

def zip_file
  "#{package_name}.zip"
end