Skip to content

Commit

Permalink
Zip file example and extended ZipDirectory to support multiple direct…
Browse files Browse the repository at this point in the history
…ories
  • Loading branch information
BenHall committed Nov 21, 2009
1 parent 513e0c1 commit 4051ba5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 44 deletions.
65 changes: 33 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
pkg
obj
bin
deploy
deploy/*
_ReSharper.*
*.csproj.user
*.resharper.user
*.resharper
*.suo
*.cache
~$*
*.tmp
*.eprj
spec/support/AssemblyInfo/AssemblyInfo.cs
spec/support/CodeCoverage/nunit/TestResult.xml
spec/support/CodeCoverage/nunit/test-coverage.*
spec/support/CodeCoverage/nunit/html
spec/support/CodeCoverage/mspec/html
spec/support/CodeCoverage/html
spec/support/CodeCoverage/report/output
spec/support/CodeCoverage/test-coverage.xml
spec/support/zip/*.zip
spec/support/expandtemplates/output
spec/support/expandtemplates/working
github-test.rb
Albacore-*.gem
Albacore.gemspec
albacore-*.gem
albacore.gemspec
.idea
web.config.example
pkg
obj
bin
deploy
deploy/*
_ReSharper.*
*.csproj.user
*.resharper.user
*.resharper
*.suo
*.cache
~$*
*.tmp
*.eprj
spec/support/AssemblyInfo/AssemblyInfo.cs
spec/support/CodeCoverage/nunit/TestResult.xml
spec/support/CodeCoverage/nunit/test-coverage.*
spec/support/CodeCoverage/nunit/html
spec/support/CodeCoverage/mspec/html
spec/support/CodeCoverage/html
spec/support/CodeCoverage/report/output
spec/support/CodeCoverage/test-coverage.xml
spec/support/zip/*.zip
spec/support/expandtemplates/output
spec/support/expandtemplates/working
github-test.rb
Albacore-*.gem
Albacore.gemspec
albacore-*.gem
albacore.gemspec
.idea
web.config.example
albacore_example.zip
25 changes: 17 additions & 8 deletions lib/albacore/zipdirectory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
class ZipDirectory
include YAMLConfig

attr_accessor :directory_to_zip
attr_accessor :directories_to_zip
attr_accessor :output_path
attr_accessor :additional_files
attr_accessor :file

Expand All @@ -15,9 +16,9 @@ def initialize
end

def package()
return if @directory_to_zip.nil?
return if @directories_to_zip.nil?

@directory_to_zip.sub!(%r[/$],'')
clean_directories_names
remove zip_name

ZipFile.open(zip_name, 'w') do |zipfile|
Expand All @@ -26,6 +27,10 @@ def package()
end
end

def clean_directories_names
@directories_to_zip.each { |d| d.sub!(%r[/$],'')}
end

def remove(filename)
FileUtils.rm filename, :force=>true
end
Expand All @@ -35,14 +40,18 @@ def reject_file(f)
end

def zip_name()
File.join(@directory_to_zip, @file)
@output_path = @directories_to_zip.first unless @output_path
File.join(@output_path, @file)
end

def zip_directory(zipfile)
Dir["#{@directory_to_zip}/**/**"].reject{|f| reject_file(f)}.each do |file_path|
file_name = file_path.sub(@directory_to_zip+'/','');
zipfile.add(file_name, file_path)
end
@directories_to_zip.each do |d|
Dir["#{d}/**/**"].reject{|f| reject_file(f)}.each do |file_path|
file_name = file_path
file_name = file_path.sub(d + '/','') if @directories_to_zip.count == 1
zipfile.add(file_name, file_path)
end
end
end

def zip_additional(zipfile)
Expand Down
15 changes: 11 additions & 4 deletions rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,23 @@

ncr.required_coverage << NCover::BranchCoverage.new(:minimum => 10)
ncr.required_coverage << NCover::CyclomaticComplexity.new(:maximum => 1)
end
end

desc "Run the sample for renaming a File"
Albacore::RenameTask.new do |rename|
Albacore::RenameTask.new() do |rename|
FileUtils.touch 'web.uat.config.example'

#This is the main part

rename.actual_name = 'web.uat.config.example'
rename.target_name = 'web.config.example'
end

desc "Run ZipDirectory example"
Albacore::ZipTask.new() do |zip|
zip.output_path = File.dirname(__FILE__)
zip.directories_to_zip = ["lib", "spec"]
zip.additional_files = "README.markdown"
zip.file = 'albacore_example.zip'
end
end

namespace :jeweler do
Expand Down

0 comments on commit 4051ba5

Please sign in to comment.