Class: Buildr::ZipTask
- Inherits:
-
Rake::FileTask
- Object
- Rake::FileTask
- Buildr::ZipTask
- Includes:
- IncludeFiles
- Defined in:
- lib/tasks/zip.rb
Overview
The ZipTask creates a new ZIP file. You can include any number of files and and directories, use exclusion patterns, and include files into specific directories.
Direct Known Subclasses
Defined Under Namespace
Modules: IncludeFiles Classes: Path, ZipExpander
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
-
#initialize(*args) ⇒ ZipTask
constructor
A new instance of ZipTask.
- #invoke_prerequisites ⇒ Object
- #needed? ⇒ Boolean
-
#path(path) ⇒ Object
Returns a path to which you can include/exclude files.
-
#with(options) ⇒ Object
Pass options to the task.
Methods included from IncludeFiles
Constructor Details
#initialize(*args) ⇒ ZipTask
Returns a new instance of ZipTask.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/tasks/zip.rb', line 137 def initialize(*args) super @paths = { nil=>self } setup_path enhance do |task| puts "Creating #{task.name}" if verbose # We're here because the Zip file does not exist, or one of the files is # newer than the Zip contents; in the later case, opening the Zip file # will add to its contents instead of replacing it, so we want the Zip # gone before we change it. We also don't want to see any partial updates. rm task.name, :verbose=>false rescue nil mkpath File.dirname(task.name), :verbose=>false begin Zip::ZipFile.open(task.name, Zip::ZipFile::CREATE) { |zip| create zip } rescue rm task.name, :verbose=>false rescue nil raise end end end |
Instance Method Details
#[]=(key, value) ⇒ Object
212 213 214 |
# File 'lib/tasks/zip.rb', line 212 def []=(key, value) fail "#{self.class} does not support the attribute #{key}" end |
#invoke_prerequisites ⇒ Object
216 217 218 219 |
# File 'lib/tasks/zip.rb', line 216 def invoke_prerequisites() super @paths.collect { |name, path| path. }.flatten.each { |src| file(src).invoke } end |
#needed? ⇒ Boolean
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/tasks/zip.rb', line 221 def needed?() return true unless File.exist?(name) # You can do something like: # include("foo", :path=>"foo").exclude("foo/bar", path=>"foo"). # include("foo/bar", :path=>"foo/bar") # This will play havoc if we handled all the prerequisites together # under the task, so instead we handle them individually for each path. # # We need to check that any file we include is not newer than the # contents of the ZIP. The file itself but also the directory it's # coming from, since some tasks touch the directory, e.g. when the # content of target/classes is included into a WAR. most_recent = @paths.collect { |name, path| path. }.flatten. each { |src| File.directory?(src) ? FileList[File.join(src, "**", "*")] | [src] : src }.flatten. select { |file| File.exist?(file) }.collect { |file| File.stat(file).mtime }.max File.stat(name).mtime < (most_recent || Rake::EARLY) || super end |
#path(path) ⇒ Object
Returns a path to which you can include/exclude files.
zip(..).include("foo", :path=>"bar")
is equivalen to:
zip(..).path("bar").include("foo")
200 201 202 |
# File 'lib/tasks/zip.rb', line 200 def path(path) path.blank? ? @paths[nil] : (@paths[path] ||= Path.new(path)) end |
#with(options) ⇒ Object
Pass options to the task. Returns self.
205 206 207 208 209 210 |
# File 'lib/tasks/zip.rb', line 205 def with() .each do |key, value| self[key] = value end self end |