forked from Albacore/albacore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Unzip task. Added Example in rakefile.
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ albacore.gemspec | |
web.config.example | ||
albacore_example.zip | ||
TestResult.xml | ||
temp | ||
unziptask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters