You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by as...@apache.org on 2008/04/10 03:01:47 UTC
svn commit: r646608 - in /incubator/buildr/trunk:
lib/buildr/core/application.rb lib/buildr/core/transports.rb
lib/buildr/core/util.rb lib/buildr/java/packaging.rb
lib/buildr/packaging/zip.rb spec/application_spec.rb spec/archive_spec.rb
Author: assaf
Date: Wed Apr 9 18:01:40 2008
New Revision: 646608
URL: http://svn.apache.org/viewvc?rev=646608&view=rev
Log:
SFTP upload now accepts release_to password option.
Added Buildr.environment, and now testing Buildr.application shortcuts in Buildr module.
Fixed issue where zip.merge(:path=>) fails when path is '/'.
Modified:
incubator/buildr/trunk/lib/buildr/core/application.rb
incubator/buildr/trunk/lib/buildr/core/transports.rb
incubator/buildr/trunk/lib/buildr/core/util.rb
incubator/buildr/trunk/lib/buildr/java/packaging.rb
incubator/buildr/trunk/lib/buildr/packaging/zip.rb
incubator/buildr/trunk/spec/application_spec.rb
incubator/buildr/trunk/spec/archive_spec.rb
Modified: incubator/buildr/trunk/lib/buildr/core/application.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/application.rb?rev=646608&r1=646607&r2=646608&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/application.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/application.rb Wed Apr 9 18:01:40 2008
@@ -70,10 +70,6 @@
@user = load_from('settings', @application.home_dir)
@build = load_from('build')
@profiles = load_from('profiles')
- # .inject({}) { |hash, (name, value)|
- # value ||= {}
- # raise 'Each profile must be empty or contain name/value pairs.' unless Hash === value
- # hash.update(name=>value) }
end
# User settings loaded from setting.yaml file in user's home directory.
@@ -122,12 +118,12 @@
@name = 'Buildr'
@requires = []
@top_level_tasks = []
- @home_dir = File.expand_path('.buildr', ENV['HOME'])
- @environment = ENV['BUILDR_ENV']
parse_options
collect_tasks
top_level_tasks.unshift 'buildr:initialize'
+ @home_dir = File.expand_path('.buildr', ENV['HOME'])
mkpath @home_dir unless File.exist?(@home_dir)
+ @environment = ENV['BUILDR_ENV'] ||= 'development'
end
# Returns list of Gems associated with this buildfile, as listed in build.yaml.
@@ -309,12 +305,18 @@
Rake.application
end
- def application=(app)
+ def application=(app) #:nodoc:
Rake.application = app
end
+ # Returns the Settings associated with this build.
def settings
Buildr.application.settings
+ end
+
+ # Copied from BUILD_ENV.
+ def environment
+ Buildr.application.environment
end
end
Modified: incubator/buildr/trunk/lib/buildr/core/transports.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/transports.rb?rev=646608&r1=646607&r2=646608&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/transports.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/transports.rb Wed Apr 9 18:01:40 2008
@@ -346,7 +346,7 @@
class << self
# Caching of passwords, so we only need to ask once.
- def passwords()
+ def passwords
@passwords ||= {}
end
end
@@ -355,7 +355,7 @@
def write_internal(options, &block) #:nodoc:
# SSH options are based on the username/password from the URI.
- ssh_options = { :port=>port, :username=>user }.merge(options[:ssh_options] || {})
+ ssh_options = { :port=>port, :username=>user, :password=>password }.merge(options[:ssh_options] || {})
ssh_options[:password] ||= SFTP.passwords[host]
begin
puts "Connecting to #{host}" if Buildr.application.options.trace
Modified: incubator/buildr/trunk/lib/buildr/core/util.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/util.rb?rev=646608&r1=646607&r2=646608&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/util.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/util.rb Wed Apr 9 18:01:40 2008
@@ -78,9 +78,24 @@
end
end
- def relative_path(to, from = ".")
- to, from = File.expand_path(to.to_s, "/"), File.expand_path(from.to_s, "/")
- Pathname.new(to).relative_path_from(Pathname.new(from)).to_s
+ # Return the path to the first argument, starting from the path provided by the
+ # second argument.
+ #
+ # For example:
+ # relative_path('foo/bar', 'foo')
+ # => 'bar'
+ # relative_path('foo/bar', 'baz')
+ # => '../foo/bar'
+ # relative_path('foo/bar')
+ # => 'foo/bar'
+ # relative_path('/foo/bar', 'baz')
+ # => '/foo/bar'
+ def relative_path(to, from = '.')
+ to = Pathname.new(to).cleanpath
+ return to.to_s if from.nil?
+ to_path = Pathname.new(File.expand_path(to.to_s, "/"))
+ from_path = Pathname.new(File.expand_path(from.to_s, "/"))
+ to_path.relative_path_from(from_path).to_s
end
# Generally speaking, it's not a good idea to operate on dot files (files starting with dot).
Modified: incubator/buildr/trunk/lib/buildr/java/packaging.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/packaging.rb?rev=646608&r1=646607&r2=646608&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/packaging.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/packaging.rb Wed Apr 9 18:01:40 2008
@@ -504,8 +504,9 @@
from = component[:path]
@classpath = @components.select { |comp| comp[:type] == :lib }.
map do |lib|
- lib_path = File.join(lib[:path].to_s, lib[:artifact].to_s.pathmap('%f'))
- Util.relative_path(lib_path, from)
+ basename = lib[:artifact].to_s.pathmap('%f')
+ full_path = lib[:path].empty? ? basename : File.join(lib[:path], basename)
+ Util.relative_path(full_path, from)
end
end
@@ -518,7 +519,8 @@
xml.application do
xml.tag! 'display-name', display_name
@components.each do |comp|
- uri = Util.relative_path(File.join(comp[:path].to_s, comp[:artifact].to_s.pathmap('%f')))
+ basename = comp[:artifact].to_s.pathmap('%f')
+ uri = comp[:path].empty? ? basename : File.join(comp[:path], basename)
case comp[:type]
when :war
xml.module :id=>comp[:id] do
Modified: incubator/buildr/trunk/lib/buildr/packaging/zip.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/packaging/zip.rb?rev=646608&r1=646607&r2=646608&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/packaging/zip.rb (original)
+++ incubator/buildr/trunk/lib/buildr/packaging/zip.rb Wed Apr 9 18:01:40 2008
@@ -217,7 +217,7 @@
source.entries.reject { |entry| entry.directory? }.each do |entry|
if @includes.any? { |pattern| File.fnmatch(pattern, entry.name, File::FNM_PATHNAME) } &&
!@excludes.any? { |pattern| File.fnmatch(pattern, entry.name, File::FNM_PATHNAME) }
- dest = Util.relative_path(path + "/" + entry.name)
+ dest = path =~ /^\/?$/ ? entry.name : Util.relative_path(path + "/" + entry.name)
puts "Adding #{dest}" if Buildr.application.options.trace
file_map[dest] = lambda { |output| output.write source.read(entry) }
end
Modified: incubator/buildr/trunk/spec/application_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/application_spec.rb?rev=646608&r1=646607&r2=646608&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/application_spec.rb (original)
+++ incubator/buildr/trunk/spec/application_spec.rb Wed Apr 9 18:01:40 2008
@@ -29,6 +29,26 @@
end
end
+ describe 'environment' do
+ it 'should return value of BUILDR_ENV' do
+ ENV['BUILDR_ENV'] = 'qa'
+ Buildr::Application.new.environment.should eql('qa')
+ end
+
+ it 'should default to development' do
+ Buildr::Application.new.environment.should eql('development')
+ end
+
+ it 'should set environment name from -e argument' do
+ ARGV.push('-e', 'test')
+ Buildr::Application.new.environment.should eql('test')
+ ENV['BUILDR_ENV'].should eql('test')
+ end
+
+ after do
+ ENV['BUILDR_ENV'] = nil
+ end
+ end
describe 'gems' do
@@ -177,16 +197,6 @@
end
-describe 'ENV' do
-
- describe 'BUILDR_ENV' do
- it 'should default to development' do
- ENV['BUILDR_ENV'].should eql('development')
- end
- end
-end
-
-
describe Buildr, 'settings' do
describe 'user' do
@@ -281,4 +291,26 @@
end
+end
+
+
+describe Buildr do
+
+ describe 'environment' do
+ it 'should be same as Buildr.application.environment' do
+ Buildr.environment.should eql(Buildr.application.environment)
+ end
+ end
+
+ describe 'application' do
+ it 'should be same as Rake.application' do
+ Buildr.application.should == Rake.application
+ end
+ end
+
+ describe 'settings' do
+ it 'should be same as Buildr.application.settings' do
+ Buildr.settings.should == Buildr.application.settings
+ end
+ end
end
Modified: incubator/buildr/trunk/spec/archive_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/archive_spec.rb?rev=646608&r1=646607&r2=646608&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/archive_spec.rb (original)
+++ incubator/buildr/trunk/spec/archive_spec.rb Wed Apr 9 18:01:40 2008
@@ -17,9 +17,9 @@
require File.join(File.dirname(__FILE__), 'spec_helpers')
-describe "ArchiveTask", :shared=>true do
+describe 'ArchiveTask', :shared=>true do
before do
- @dir = File.expand_path("test")
+ @dir = File.expand_path('test')
@files = %w{Test1.txt Text2.html}.map { |file| File.expand_path(file, @dir) }.
each { |file| write file, content_for(file) }
end
@@ -32,51 +32,51 @@
# Create an archive not using the archive task, this way we do have a file in existence, but we don't
# have an already invoked task. Yield an archive task to the block which can use it to include files,
# set options, etc.
- def create_without_task()
- archive(@archive + ".tmp").tap do |task|
+ def create_without_task
+ archive(@archive + '.tmp').tap do |task|
yield task if block_given?
task.invoke
mv task.name, @archive
end
end
- def create_for_merge()
- zip(@archive + ".src").include(@files).tap do |task|
+ def create_for_merge
+ zip(@archive + '.src').include(@files).tap do |task|
task.invoke
yield task
end
end
- it "should point to archive file" do
+ it 'should point to archive file' do
archive(@archive).name.should eql(@archive)
end
- it "should create file" do
+ it 'should create file' do
lambda { archive(@archive).invoke }.should change { File.exist?(@archive) }.to(true)
end
- it "should create empty archive if no files included" do
+ it 'should create empty archive if no files included' do
archive(@archive).invoke
inspect_archive { |archive| archive.should be_empty }
end
- it "should create empty archive if called #clean method" do
+ it 'should create empty archive if called #clean method' do
archive(@archive).include(@files).clean.invoke
inspect_archive { |archive| archive.should be_empty }
end
- it "should archive all included files" do
+ it 'should archive all included files' do
archive(@archive).include(@files).invoke
inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
inspect_archive.size.should eql(@files.size)
end
- it "should include entry for directory" do
+ it 'should include entry for directory' do
archive(@archive).include(@dir).invoke
- inspect_archive { |archive| @files.each { |f| archive["test/" + File.basename(f)].should eql(content_for(f)) } }
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
end
- it "should not archive any excluded files" do
+ it 'should not archive any excluded files' do
archive(@archive).include(@files).exclude(@files.last).invoke
inspect_archive do |archive|
archive.keys.should include(File.basename(@files.first))
@@ -84,15 +84,15 @@
end
end
- it "should not archive any excluded files in included directories" do
+ it 'should not archive any excluded files in included directories' do
archive(@archive).include(@dir).exclude(@files.last).invoke
inspect_archive do |archive|
- archive.keys.should include("test/" + File.basename(@files.first))
- archive.keys.should_not include("test/" + File.basename(@files.last))
+ archive.keys.should include('test/' + File.basename(@files.first))
+ archive.keys.should_not include('test/' + File.basename(@files.last))
end
end
- it "should not archive any excluded files when using :from/:as" do
+ it 'should not archive any excluded files when using :from/:as' do
archive(@archive).include(:from=>@dir).exclude(@files.last).invoke
inspect_archive do |archive|
archive.keys.should include(File.basename(@files.first))
@@ -100,7 +100,7 @@
end
end
- it "should exclude entire directory and all its children" do
+ it 'should exclude entire directory and all its children' do
mkpath "#{@dir}/sub"
write "#{@dir}/sub/test"
archive(@archive).include(@dir).exclude("#{@dir}/sub").invoke
@@ -109,83 +109,93 @@
end
end
- it "should archive files into specified path" do
- archive(@archive).include(@files, :path=>"code").invoke
- inspect_archive { |archive| @files.each { |f| archive["code/" + File.basename(f)].should eql(content_for(f)) } }
+ it 'should not archive any excluded files when pattern is *.ext' do
+ write "test/file.txt"
+ write "test/file.swf"
+ archive(@archive).include(@dir).exclude('**/*.swf').invoke
+ inspect_archive do |archive|
+ archive.keys.should include('test/file.txt')
+ archive.keys.should_not include('test/file.swf')
+ end
+ end
+
+ it 'should archive files into specified path' do
+ archive(@archive).include(@files, :path=>'code').invoke
+ inspect_archive { |archive| @files.each { |f| archive['code/' + File.basename(f)].should eql(content_for(f)) } }
end
- it "should include entry for directory" do
+ it 'should include entry for directory' do
archive(@archive).include(@dir).invoke
- inspect_archive { |archive| @files.each { |f| archive["test/" + File.basename(f)].should eql(content_for(f)) } }
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
end
- it "should archive files into specified path" do
- archive(@archive).include(@files, :path=>"code").invoke
- inspect_archive { |archive| @files.each { |f| archive["code/" + File.basename(f)].should eql(content_for(f)) } }
+ it 'should archive files into specified path' do
+ archive(@archive).include(@files, :path=>'code').invoke
+ inspect_archive { |archive| @files.each { |f| archive['code/' + File.basename(f)].should eql(content_for(f)) } }
end
- it "should archive directories into specified path" do
- archive(@archive).include(@dir, :path=>"code").invoke
- inspect_archive { |archive| @files.each { |f| archive["code/test/" + File.basename(f)].should eql(content_for(f)) } }
+ it 'should archive directories into specified path' do
+ archive(@archive).include(@dir, :path=>'code').invoke
+ inspect_archive { |archive| @files.each { |f| archive['code/test/' + File.basename(f)].should eql(content_for(f)) } }
end
- it "should understand . in path" do
- archive(@archive).path(".").should == archive(@archive).path("")
- archive(@archive).path("foo").path(".").should == archive(@archive).path("foo")
+ it 'should understand . in path' do
+ archive(@archive).path('.').should == archive(@archive).path('')
+ archive(@archive).path('foo').path('.').should == archive(@archive).path('foo')
end
- it "should understand .. in path" do
- archive(@archive).path("..").should == archive(@archive).path("")
- archive(@archive).path("foo").path("..").should == archive(@archive).path("")
- archive(@archive).path("foo/bar").path("..").should == archive(@archive).path("foo")
+ it 'should understand .. in path' do
+ archive(@archive).path('..').should == archive(@archive).path('')
+ archive(@archive).path('foo').path('..').should == archive(@archive).path('')
+ archive(@archive).path('foo/bar').path('..').should == archive(@archive).path('foo')
end
- it "should understand leading / in path" do
- archive(@archive).path("/").should == archive(@archive).path("")
- archive(@archive).path("foo/bar").path("/").should == archive(@archive).path("")
+ it 'should understand leading / in path' do
+ archive(@archive).path('/').should == archive(@archive).path('')
+ archive(@archive).path('foo/bar').path('/').should == archive(@archive).path('')
end
- it "should archive file into specified name" do
- archive(@archive).include(@files.first, :as=>"test/sample").invoke
- inspect_archive { |archive| @files.each { |f| archive["test/sample"].should eql(content_for(@files.first)) } }
+ it 'should archive file into specified name' do
+ archive(@archive).include(@files.first, :as=>'test/sample').invoke
+ inspect_archive { |archive| @files.each { |f| archive['test/sample'].should eql(content_for(@files.first)) } }
end
- it "should archive file into specified name/path" do
- archive(@archive).include(@files.first, :as=>"test/sample", :path=>"path").invoke
- inspect_archive { |archive| @files.each { |f| archive["path/test/sample"].should eql(content_for(@files.first)) } }
+ it 'should archive file into specified name/path' do
+ archive(@archive).include(@files.first, :as=>'test/sample', :path=>'path').invoke
+ inspect_archive { |archive| @files.each { |f| archive['path/test/sample'].should eql(content_for(@files.first)) } }
end
- it "should archive files starting with dot" do
- write "test/.config", "# configuration"
- archive(@archive).include("test").invoke
- inspect_archive { |archive| @files.each { |f| archive["test/.config"].should eql("# configuration") } }
+ it 'should archive files starting with dot' do
+ write 'test/.config', '# configuration'
+ archive(@archive).include('test').invoke
+ inspect_archive { |archive| @files.each { |f| archive['test/.config'].should eql('# configuration') } }
end
- it "should archive directory into specified name" do
- archive(@archive).include(@dir, :as=>"code").invoke
- inspect_archive { |archive| @files.each { |f| archive["code/" + File.basename(f)].should eql(content_for(f)) } }
+ it 'should archive directory into specified name' do
+ archive(@archive).include(@dir, :as=>'code').invoke
+ inspect_archive { |archive| @files.each { |f| archive['code/' + File.basename(f)].should eql(content_for(f)) } }
end
- it "should archive directory into specified name/path" do
- archive(@archive).include(@dir, :as=>"code", :path=>"path").invoke
- inspect_archive { |archive| @files.each { |f| archive["path/code/" + File.basename(f)].should eql(content_for(f)) } }
+ it 'should archive directory into specified name/path' do
+ archive(@archive).include(@dir, :as=>'code', :path=>'path').invoke
+ inspect_archive { |archive| @files.each { |f| archive['path/code/' + File.basename(f)].should eql(content_for(f)) } }
end
- it "should archive directory contents" do
- archive(@archive).include(@dir, :as=>".").invoke
+ it 'should archive directory contents' do
+ archive(@archive).include(@dir, :as=>'.').invoke
inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
end
- it "should archive directory contents into specified path" do
- archive(@archive).include(@dir, :as=>".", :path=>"path").invoke
- inspect_archive { |archive| @files.each { |f| archive["path/" + File.basename(f)].should eql(content_for(f)) } }
+ it 'should archive directory contents into specified path' do
+ archive(@archive).include(@dir, :as=>'.', :path=>'path').invoke
+ inspect_archive { |archive| @files.each { |f| archive['path/' + File.basename(f)].should eql(content_for(f)) } }
end
- it "should not allow two files with the :as argument" do
- lambda { archive(@archive).include(@files.first, @files.last, :as=>"test/sample") }.should raise_error(RuntimeError, /one file/)
+ it 'should not allow two files with the :as argument' do
+ lambda { archive(@archive).include(@files.first, @files.last, :as=>'test/sample') }.should raise_error(RuntimeError, /one file/)
end
- it "should expand another archive file" do
+ it 'should expand another archive file' do
create_for_merge do |src|
archive(@archive).merge(src)
archive(@archive).invoke
@@ -193,7 +203,7 @@
end
end
- it "should expand another archive file with include pattern" do
+ it 'should expand another archive file with include pattern' do
create_for_merge do |src|
archive(@archive).merge(src).include(File.basename(@files.first))
archive(@archive).invoke
@@ -204,7 +214,7 @@
end
end
- it "should expand another archive file with exclude pattern" do
+ it 'should expand another archive file with exclude pattern' do
create_for_merge do |src|
archive(@archive).merge(src).exclude(File.basename(@files.first))
archive(@archive).invoke
@@ -215,15 +225,31 @@
end
end
- it "should expand another archive file into path" do
+ it 'should expand another archive file into path' do
create_for_merge do |src|
- archive(@archive).path("test").merge(src)
+ archive(@archive).path('test').merge(src)
archive(@archive).invoke
- inspect_archive { |archive| @files.each { |f| archive["test/" + File.basename(f)].should eql(content_for(f)) } }
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
+ end
+ end
+
+ it 'should expand another archive file into path with :path option' do
+ create_for_merge do |src|
+ archive(@archive).merge(src, :path=>'test')
+ archive(@archive).invoke
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
+ end
+ end
+
+ it "should expand another archive file into path with :path=>'/'" do
+ create_for_merge do |src|
+ archive(@archive).merge(src, :path=>'/')
+ archive(@archive).invoke
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
end
end
- it "should expand another archive file into path with merge option" do
+ it 'should expand another archive file into path with merge option' do
create_for_merge do |src|
archive(@archive).include(src, :merge=>true)
archive(@archive).invoke
@@ -231,7 +257,7 @@
end
end
- it "should update if one of the files is recent" do
+ it 'should update if one of the files is recent' do
create_without_task { |archive| archive.include(@files) }
# Touch archive file to some point in the past. This effectively makes
# all included files newer.
@@ -240,7 +266,7 @@
File.stat(@archive).mtime.should be_close(Time.now, 10)
end
- it "should do nothing if all files are uptodate" do
+ it 'should do nothing if all files are uptodate' do
create_without_task { |archive| archive.include(@files) }
# By touching all files in the past, there's nothing new to update.
(@files + [@archive]).each { |f| File.utime Time.now - 100, Time.now - 100, f }
@@ -248,23 +274,23 @@
File.stat(@archive).mtime.should be_close(Time.now - 100, 10)
end
- it "should update if one of the files is recent" do
+ it 'should update if one of the files is recent' do
create_without_task { |archive| archive.include(@files) }
# Change files, we expect to see new content.
- write @files.first, "/* Refreshed */"
+ write @files.first, '/* Refreshed */'
File.utime(Time.now - 100, Time.now - 100, @archive) # Touch archive file to some point in the past.
archive(@archive).include(@files).invoke
- inspect_archive { |archive| archive[File.basename(@files.first)].should eql("/* Refreshed */") }
+ inspect_archive { |archive| archive[File.basename(@files.first)].should eql('/* Refreshed */') }
end
- it "should create new archive when updating" do
+ it 'should create new archive when updating' do
create_without_task { |archive| archive.include(@files) }
File.utime(Time.now - 100, Time.now - 100, @archive) # Touch archive file to some point in the past.
archive(@archive).include(@files[1..-1]).invoke
inspect_archive.size.should be(@files.size - 1)
end
- it "should not accept invalid options" do
+ it 'should not accept invalid options' do
archive(@archive).include(@files)
lambda { archive(@archive).with :option=>true }.should raise_error
end
@@ -272,13 +298,13 @@
describe TarTask do
- it_should_behave_like "ArchiveTask"
- before { @archive = File.expand_path("test.tar") }
+ it_should_behave_like 'ArchiveTask'
+ before { @archive = File.expand_path('test.tar') }
define_method(:archive) { |file| tar(file) }
- def inspect_archive()
+ def inspect_archive
entries = {}
- Archive::Tar::Minitar.open @archive, "r" do |reader|
+ Archive::Tar::Minitar.open @archive, 'r' do |reader|
reader.each { |entry| entries[entry.directory ? "#{entry.name}/" : entry.name] = entry.read }
end
yield entries if block_given?
@@ -287,15 +313,15 @@
end
-describe TarTask, " gzipped" do
- it_should_behave_like "ArchiveTask"
- before { @archive = File.expand_path("test.tgz") }
+describe TarTask, ' gzipped' do
+ it_should_behave_like 'ArchiveTask'
+ before { @archive = File.expand_path('test.tgz') }
define_method(:archive) { |file| tar(file) }
- def inspect_archive()
+ def inspect_archive
entries = {}
Zlib::GzipReader.open @archive do |gzip|
- Archive::Tar::Minitar.open gzip, "r" do |reader|
+ Archive::Tar::Minitar.open gzip, 'r' do |reader|
reader.each { |entry| entries[entry.directory ? "#{entry.name}/" : entry.name] = entry.read }
end
end
@@ -306,11 +332,11 @@
describe ZipTask do
- it_should_behave_like "ArchiveTask"
- before { @archive = File.expand_path("test.zip") }
+ it_should_behave_like 'ArchiveTask'
+ before { @archive = File.expand_path('test.zip') }
define_method(:archive) { |file| zip(file) }
- def inspect_archive()
+ def inspect_archive
entries = {}
Zip::ZipFile.open @archive do |zip|
zip.entries.each do |entry|
@@ -322,21 +348,21 @@
entries
end
- it "should work with path object" do
- archive(@archive).path("code").include(@files)
+ it 'should work with path object' do
+ archive(@archive).path('code').include(@files)
archive(@archive).invoke
- inspect_archive { |archive| archive.keys.should include("code/") }
+ inspect_archive { |archive| archive.keys.should include('code/') }
end
end
describe Unzip do
before do
- @zip = File.expand_path("test.zip")
- @dir = File.expand_path("test")
+ @zip = File.expand_path('test.zip')
+ @dir = File.expand_path('test')
@files = %w{Test1.txt Text2.html}.map { |file| File.join(@dir, file) }.
each { |file| write file, content_for(file) }
- @target = File.expand_path("target")
+ @target = File.expand_path('target')
end
# Not too smart, we just create some content based on file name to
@@ -350,7 +376,7 @@
yield
end
- it "should touch target directory" do
+ it 'should touch target directory' do
with_zip do
mkdir @target
File.utime(Time.now - 10, Time.now - 10, @target)
@@ -359,97 +385,97 @@
File.stat(@target).mtime.should be_close(Time.now, 2)
end
- it "should expand files" do
+ it 'should expand files' do
with_zip do
unzip(@target=>@zip).target.invoke
@files.each { |f| File.read(File.join(@target, File.basename(f))).should eql(content_for(f)) }
end
end
- it "should expand all files" do
+ it 'should expand all files' do
with_zip do
unzip(@target=>@zip).target.invoke
- FileList[File.join(@target, "*")].size.should be(@files.size)
+ FileList[File.join(@target, '*')].size.should be(@files.size)
end
end
- it "should expand only included files" do
+ it 'should expand only included files' do
with_zip do
only = File.basename(@files.first)
unzip(@target=>@zip).include(only).target.invoke
- FileList[File.join(@target, "*")].should include(File.expand_path(only, @target))
- FileList[File.join(@target, "*")].size.should be(1)
+ FileList[File.join(@target, '*')].should include(File.expand_path(only, @target))
+ FileList[File.join(@target, '*')].size.should be(1)
end
end
- it "should expand all but excluded files" do
+ it 'should expand all but excluded files' do
with_zip do
except = File.basename(@files.first)
unzip(@target=>@zip).exclude(except).target.invoke
- FileList[File.join(@target, "*")].should_not include(File.expand_path(except, @target))
- FileList[File.join(@target, "*")].size.should be(@files.size - 1)
+ FileList[File.join(@target, '*')].should_not include(File.expand_path(except, @target))
+ FileList[File.join(@target, '*')].size.should be(@files.size - 1)
end
end
- it "should include with nested path patterns" do
- with_zip @files, :path=>"test/path" do
+ it 'should include with nested path patterns' do
+ with_zip @files, :path=>'test/path' do
only = File.basename(@files.first)
unzip(@target=>@zip).include(only).target.invoke
- FileList[File.join(@target, "*")].should be_empty
+ FileList[File.join(@target, '*')].should be_empty
Rake::Task.clear ; rm_rf @target
- unzip(@target=>@zip).include("test/path/" + only).target.invoke
- FileList[File.join(@target, "test/path/*")].size.should be(1)
+ unzip(@target=>@zip).include('test/path/' + only).target.invoke
+ FileList[File.join(@target, 'test/path/*')].size.should be(1)
Rake::Task.clear ; rm_rf @target
- unzip(@target=>@zip).include("test/**/*").target.invoke
- FileList[File.join(@target, "test/path/*")].size.should be(2)
+ unzip(@target=>@zip).include('test/**/*').target.invoke
+ FileList[File.join(@target, 'test/path/*')].size.should be(2)
end
end
- it "should include with relative path" do
- with_zip @files, :path=>"test/path" do
+ it 'should include with relative path' do
+ with_zip @files, :path=>'test/path' do
only = File.basename(@files.first)
- unzip(@target=>@zip).tap { |unzip| unzip.from_path("test").include(only) }.target.invoke
- FileList[File.join(@target, "*")].should be_empty
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include(only) }.target.invoke
+ FileList[File.join(@target, '*')].should be_empty
Rake::Task.clear ; rm_rf @target
- unzip(@target=>@zip).tap { |unzip| unzip.from_path("test").include("test/*") }.target.invoke
- FileList[File.join(@target, "path/*")].should be_empty
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('test/*') }.target.invoke
+ FileList[File.join(@target, 'path/*')].should be_empty
Rake::Task.clear ; rm_rf @target
- unzip(@target=>@zip).tap { |unzip| unzip.from_path("test").include("path/*" + only) }.target.invoke
- FileList[File.join(@target, "path/*")].size.should be(1)
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('path/*' + only) }.target.invoke
+ FileList[File.join(@target, 'path/*')].size.should be(1)
Rake::Task.clear ; rm_rf @target
- unzip(@target=>@zip).tap { |unzip| unzip.from_path("test").include("path/*") }.target.invoke
- FileList[File.join(@target, "path/*")].size.should be(2)
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('path/*') }.target.invoke
+ FileList[File.join(@target, 'path/*')].size.should be(2)
end
end
- it "should exclude with relative path" do
- with_zip @files, :path=>"test" do
+ it 'should exclude with relative path' do
+ with_zip @files, :path=>'test' do
except = File.basename(@files.first)
- unzip(@target=>@zip).tap { |unzip| unzip.from_path("test").exclude(except) }.target.invoke
- FileList[File.join(@target, "*")].should include(File.join(@target, File.basename(@files[1])))
- FileList[File.join(@target, "*")].size.should be(@files.size - 1)
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').exclude(except) }.target.invoke
+ FileList[File.join(@target, '*')].should include(File.join(@target, File.basename(@files[1])))
+ FileList[File.join(@target, '*')].size.should be(@files.size - 1)
end
end
- it "should return itself from root method" do
+ it 'should return itself from root method' do
task = unzip(@target=>@zip)
task.root.should be(task)
- task.from_path("foo").root.should be(task)
+ task.from_path('foo').root.should be(task)
end
- it "should return target task from target method" do
+ it 'should return target task from target method' do
task = unzip(@target=>@zip)
task.target.should be(file(@target))
- task.from_path("foo").target.should be(file(@target))
+ task.from_path('foo').target.should be(file(@target))
end
- it "should alias from_path as path" do
+ it 'should alias from_path as path' do
task = unzip(@target=>@zip)
- task.from_path("foo").should be(task.path("foo"))
+ task.from_path('foo').should be(task.path('foo'))
end
end