Class: Rake::Delphi::ZipTask

Inherits:
BasicTask show all
Defined in:
lib/rake/common/ziptask.rb

Instance Method Summary collapse

Methods inherited from BasicTask

#trace?

Constructor Details

#initialize(task, zipfile, files, options = nil) ⇒ ZipTask

Returns a new instance of ZipTask.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rake/common/ziptask.rb', line 37

def initialize(task, zipfile, files, options = nil)
    super(task)
    Logger.trace(Logger::VERBOSE, [zipfile, files])
    raise "zipfile name is not defined!" if zipfile.nil? || zipfile.empty?
    @norubyzip = nil
    @options = options || {}
    begin
        require 'zipruby'
    rescue LoadError
        begin
            require 'zip/zip'
        rescue LoadError
            @norubyzip = true
        end
    end
    raise "no ZIP library (nor zipruby nor rubyzip) found!" if @norubyzip
    if defined? Zip::Archive
        # zipruby used
        Logger.trace(Logger::VERBOSE, '`zipruby` gem is used')
        Zip::Archive.open(zipfile, Zip::CREATE | Zip::TRUNC) do |z|
            files.each do |f|
                zip_addfile(z, f)
            end
        end
    else
        # work with rubyzip
        Logger.trace(Logger::VERBOSE, '`rubyzip` gem is used')
        File.unlink(zipfile) if File.exists?(zipfile)
        Zip.options[:continue_on_exists_proc] = true
        Zip::ZipFile.open(zipfile, Zip::ZipFile::CREATE) do |z|
            files.each do |f|
                zip_addfile(z, f)
            end
        end
    end
end