Skip to content

Commit

Permalink
Added Unzip task. Added Example in rakefile.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenHall committed Dec 6, 2009
1 parent 72c6019 commit 577dde3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ albacore.gemspec
web.config.example
albacore_example.zip
TestResult.xml
temp
unziptask
28 changes: 28 additions & 0 deletions lib/albacore/unzip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'albacore/support/albacore_helper'
require 'zip/zip'
require 'zip/zipfilesystem'
include Zip

class Unzip
include YAMLConfig
include Failure

attr_accessor :unzip_path, :zip_file

def initialize
super()
end

def unzip()
fail_with_message 'Zip File cannot be empty' if @zip_file.nil?
return if @zip_file.nil?

Zip::ZipFile.open(@zip_file) do |zip_file|
zip_file.each do |file|
out_path = File.join(@unzip_path, file.name)
FileUtils.mkdir_p(File.dirname(out_path))
zip_file.extract(file, out_path) unless File.exist?(out_path)
end
end
end
end
16 changes: 16 additions & 0 deletions lib/rake/unziptask.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rake/tasklib'

def unziptask(name=:unzip, *args, &block)
Albacore::UnZipTask.new(name, *args, &block)
end

module Albacore
class UnZipTask < Albacore::AlbacoreTask
def execute(task_args)
@zip = Unzip.new
@block.call(@zip, *task_args) unless @block.nil?
@zip.unzip
fail if @zip.failed
end
end
end
8 changes: 7 additions & 1 deletion rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@
zip.output_path = File.dirname(__FILE__)
zip.directories_to_zip = ["lib", "spec"]
zip.additional_files = "README.markdown"
zip.file = 'albacore_example.zip'
zip.output_file = 'albacore_example.zip'
end

desc "Run UnZip example"
unziptask do |zip|
zip.unzip_path = File.join File.dirname(__FILE__), 'temp'
zip.zip_file = 'albacore_example.zip'
end

desc "MSpec Test Runner Example"
Expand Down

0 comments on commit 577dde3

Please sign in to comment.