class Buildr::ArchiveTask

Base class for ZipTask, TarTask and other archives.

Public Instance Methods

<<(*files)
Alias for: include
add(*files)
Alias for: include
clean → self click to toggle source

Removes all previously added content from this archive. Use this method if you want to remove default content from a package. For example, package(:jar) by default includes compiled classes and resources, using this method, you can create an empty jar and afterwards add the desired content to it.

package(:jar).clean.include path_to('desired/content')
# File lib/buildr/packaging/archive.rb, line 362
def clean
  @paths = {}
  @paths[''] = Path.new(self, '')
  @prepares = []
  self
end
contain(file*) → boolean click to toggle source

Returns true if this ZIP file contains all the specified files. You can use absolute file names and glob patterns (using *, **, etc).

# File lib/buildr/packaging/archive.rb, line 529
def contain?(*files)
  path("").contain?(*files)
end
empty? → boolean click to toggle source

Returns true if this ZIP file is empty (has no other entries inside).

# File lib/buildr/packaging/archive.rb, line 520
def empty?
  path("").empty
end
exclude(*files) → self click to toggle source

Excludes files and returns self. Can be used in combination with include to prevent some files from being included.

# File lib/buildr/packaging/archive.rb, line 413
def exclude(*files)
  @paths[''].exclude *files
  self
end
include(*files) → self click to toggle source
include(*files, :path=>path) → self
include(file, :as=>name) → self
include(:from=>path) → self
include(*files, :merge=>true) → self

Include files in this archive, or when called on a path, within that path. Returns self.

The first form accepts a list of files, directories and glob patterns and adds them to the archive. For example, to include the file foo, directory bar (including all files in there) and all files under baz:

zip(..).include('foo', 'bar', 'baz/*')

The second form is similar but adds files/directories under the specified path. For example, to add foo as bar/foo:

zip(..).include('foo', :path=>'bar')

The :path option is the same as using the path method:

zip(..).path('bar').include('foo')

All other options can be used in combination with the :path option.

The third form adds a file or directory under a different name. For example, to add the file foo under the name bar:

zip(..).include('foo', :as=>'bar')

The fourth form adds the contents of a directory using the directory as a prerequisite:

zip(..).include(:from=>'foo')

Unlike include('foo') it includes the contents of the directory, not the directory itself. Unlike include('foo/*'), it uses the directory timestamp for dependency management.

The fifth form includes the contents of another archive by expanding it into this archive. For example:

zip(..).include('foo.zip', :merge=>true).include('bar.zip')

You can also use the method merge.

# File lib/buildr/packaging/archive.rb, line 401
def include(*files)
  fail "AchiveTask.include() called with nil values" if files.include? nil
  @paths[''].include *files if files.compact.size > 0
  self
end
Also aliased as: add, <<
merge(*files) → Merge click to toggle source
merge(*files, :path=>name) → Merge

Merges another archive into this one by including the individual files from the merged archive.

Returns an object that supports two methods: include and exclude. You can use these methods to merge only specific files. For example:

zip(..).merge('src.zip').include('module1/*')
# File lib/buildr/packaging/archive.rb, line 427
def merge(*files)
  @paths[''].merge *files
end
path(name) → Path click to toggle source

Returns a path object. Use the path object to include files under a path, for example, to include the file 'foo' as 'bar/foo':

zip(..).path('bar').include('foo')

Returns a Path object. The Path object implements all the same methods, like include, exclude, merge and so forth. It also implements path and root, so that:

path('foo').path('bar') == path('foo/bar')
path('foo').root == root
# File lib/buildr/packaging/archive.rb, line 442
def path(name)
  return @paths[''] if name.nil?
  normalized = name.split('/').inject([]) do |path, part|
    case part
    when '.', nil, ''
      path
    when '..'
      path[0...-1]
    else
      path << part
    end
  end.join('/')
  @paths[normalized] ||= Path.new(self, normalized)
end
root → ArchiveTask click to toggle source

Call this on an archive to return itself, and on a path to return the archive.

# File lib/buildr/packaging/archive.rb, line 461
def root
  self
end
with(options) → self click to toggle source

Passes options to the task and returns self. Some tasks support additional options, for example, the WarTask supports options like :manifest, :libs and :classes.

For example:

package(:jar).with(:manifest=>'MANIFEST_MF')
# File lib/buildr/packaging/archive.rb, line 473
def with(options)
  options.each do |key, value|
    begin
      send "#{key}=", value
    rescue NoMethodError
      raise ArgumentError, "#{self.class.name} does not support the option #{key}"
    end
  end
  self
end

Protected Instance Methods

prepare(&block) click to toggle source

Adds a prepare block. These blocks are called early on for adding more content to the archive, before invoking prerequsities. Anything you add here will be invoked as a prerequisite and used to determine whether or not to generate this archive. In contrast, enhance blocks are evaluated after it was decided to create this archive.

# File lib/buildr/packaging/archive.rb, line 539
def prepare(&block)
  @prepares << block
end