Author: vborja
Date: Mon Feb 18 02:11:48 2008
New Revision: 628676
URL: http://svn.apache.org/viewvc?rev=628676&view=rev
Log:
BUILDR-22
- ArchiveTask::Path#excluded? uses File::FNM_PATHNAME so that patterns like
"some/*.class"
match "some/Foo.class" but not "some/bar/Bar.class". "some/**/*.class" will
match both of them.
- Fixed other calls to File.fnmatch to use FNM_PATHNAME when it makes sense.
- Added spec for ArchiveTask#clean
- Updated specs for merge(..).include
- Created simple Merge class so that when ArchiveTask#merge takes several
archives, users may
specify include/exclude patterns for them:
package(..).merge('some.zip', 'other.zip').include("**/*.jpg) # Just
include images from both zips
- Fixed ZipExpander#expand to normalize pathname
Modified:
incubator/buildr/trunk/doc/pages/packaging.textile
incubator/buildr/trunk/lib/core/checks.rb
incubator/buildr/trunk/lib/core/common.rb
incubator/buildr/trunk/lib/tasks/zip.rb
incubator/buildr/trunk/spec/archive_spec.rb
Modified: incubator/buildr/trunk/doc/pages/packaging.textile
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/pages/packaging.textile?rev=628676&r1=628675&r2=628676&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/pages/packaging.textile (original)
+++ incubator/buildr/trunk/doc/pages/packaging.textile Mon Feb 18 02:11:48 2008
@@ -235,7 +235,7 @@
{{{!ruby
# Everything but the libs
-package(:zip).merge('bigbad.war').exclude('libs/*')
+package(:zip).merge('bigbad.war').exclude('libs/**/*')
}}}
Modified: incubator/buildr/trunk/lib/core/checks.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/checks.rb?rev=628676&r1=628675&r2=628676&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/checks.rb (original)
+++ incubator/buildr/trunk/lib/core/checks.rb Mon Feb 18 02:11:48 2008
@@ -296,7 +296,7 @@
# Returns true if this ZIP file path contains all the specified files. You
can use relative
# file names and glob patterns (using *, **, etc).
def contain?(*files)
- files.all? { |file| entries.detect { |entry| File.fnmatch(file,
entry.to_s) } }
+ files.all? { |file| entries.detect { |entry| File.fnmatch(file,
entry.to_s, File::FNM_PATHNAME) } }
end
# :call-seq:
Modified: incubator/buildr/trunk/lib/core/common.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/common.rb?rev=628676&r1=628675&r2=628676&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/common.rb (original)
+++ incubator/buildr/trunk/lib/core/common.rb Mon Feb 18 02:11:48 2008
@@ -344,8 +344,8 @@
base = Pathname.new(source)
files = FileList.recursive(source).
map { |file| Pathname.new(file).relative_path_from(base).to_s }.
- select { |file| @include.empty? || @include.any? { |pattern|
File.fnmatch(pattern, file) } }.
- reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern,
file) } }
+ select { |file| @include.empty? || @include.any? { |pattern|
File.fnmatch(pattern, file, File::FNM_PATHNAME) } }.
+ reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern,
file, File::FNM_PATHNAME) } }
files.each do |file|
src, dest = File.expand_path(file, source), File.expand_path(file,
target.to_s)
map[file] = src if !File.exist?(dest) || File.stat(src).mtime >
File.stat(dest).mtime
Modified: incubator/buildr/trunk/lib/tasks/zip.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/tasks/zip.rb?rev=628676&r1=628675&r2=628676&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/tasks/zip.rb (original)
+++ incubator/buildr/trunk/lib/tasks/zip.rb Mon Feb 18 02:11:48 2008
@@ -88,23 +88,18 @@
# merge(*files) => Merge
# merge(*files, :path=>name) => Merge
def merge(*args)
- options = args.pop if Hash === args.last
+ options = Hash === args.last ? args.pop : {}
files = args.flatten
-
- if options.nil? || options.empty?
- files.collect do |file|
- @sources << proc { file.to_s }
- expander = ZipExpander.new(file)
- @actions << proc { |file_map| expander.expand(file_map, @path) }
- expander
- end.first
- elsif options[:path]
- sans_path = options.reject { |k,v| k == :path }
- path(options[:path]).merge *files + [sans_path]
- self
- else
- raise "Unrecognized option #{options.keys.join(", ")}"
+ rake_check_options options, :path
+ raise ArgumentError, "Expected at least one file to merge" if
files.empty?
+ path = options[:path] || @path
+ expanders = files.collect do |file|
+ @sources << proc { file.to_s }
+ expander = ZipExpander.new(file)
+ @actions << proc { |file_map| expander.expand(file_map, path) }
+ expander
end
+ Merge.new(expanders)
end
# Returns a Path relative to this one.
@@ -157,11 +152,25 @@
end
def excluded?(file)
- @excludes.any? { |exclude| File.fnmatch(exclude, file) }
+ @excludes.any? { |exclude| File.fnmatch(exclude, file,
File::FNM_PATHNAME) }
end
end
+ class Merge
+ def initialize(expanders)
+ @expanders = expanders
+ end
+ def include(*files)
+ @expanders.each { |expander| expander.include(*files) }
+ end
+ alias :<< :include
+
+ def exclude(*files)
+ @expanders.each { |expander| expander.exclude(*files) }
+ end
+ end
+
# Extend one Zip file into another.
class ZipExpander #:nodoc:
@@ -187,9 +196,10 @@
@includes = ['*'] if @includes.empty?
Zip::ZipFile.open(@zip_file) do |source|
source.entries.reject { |entry| entry.directory? }.each do |entry|
- if @includes.any? { |pattern| File.fnmatch(pattern, entry.name) }
&&
- [EMAIL PROTECTED] { |pattern| File.fnmatch(pattern, entry.name)
}
- dest = "#{path}#{entry.name}"
+ if @includes.any? { |pattern| File.fnmatch(pattern, entry.name,
File::FNM_PATHNAME) } &&
+ [EMAIL PROTECTED] { |pattern| File.fnmatch(pattern, entry.name,
File::FNM_PATHNAME) }
+ dest = Pathname.new(File.expand_path(path + "/" + entry.name,
'/')).
+
relative_path_from(Pathname.new(File.expand_path('/'))).to_s
puts "Adding #{dest}" if Rake.application.options.trace
file_map[dest] = lambda { |output| output.write
source.read(entry) }
end
@@ -627,8 +637,8 @@
excludes = @exclude || []
entries.inject({}) do |map, entry|
short = entry.name.sub(@path, '')
- if includes.any? { |pat| File.fnmatch(pat, short) } &&
- !excludes.any? { |pat| File.fnmatch(pat, short) }
+ if includes.any? { |pat| File.fnmatch(pat, short,
File::FNM_PATHNAME) } &&
+ !excludes.any? { |pat| File.fnmatch(pat, short,
File::FNM_PATHNAME) }
map[short] = entry
end
map
Modified: incubator/buildr/trunk/spec/archive_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/archive_spec.rb?rev=628676&r1=628675&r2=628676&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/archive_spec.rb (original)
+++ incubator/buildr/trunk/spec/archive_spec.rb Mon Feb 18 02:11:48 2008
@@ -44,6 +44,11 @@
inspect_archive { |archive| archive.should be_empty }
end
+ 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
archive(@archive).include(@files).invoke
inspect_archive { |archive| @files.each { |f|
archive[File.basename(f)].should eql(content_for(f)) } }
@@ -176,15 +181,21 @@
create_for_merge do |src|
archive(@archive).merge(src).include(File.basename(@files.first))
archive(@archive).invoke
- inspect_archive { |archive| archive[File.basename(@files.first)].should
eql(content_for(@files.first)) }
+ inspect_archive do |archive|
+ archive[File.basename(@files.first)].should
eql(content_for(@files.first))
+ archive[File.basename(@files.last)].should be_nil
+ end
end
end
-
+
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
- inspect_archive { |archive| @files[1..-1].each { |f|
archive[File.basename(f)].should eql(content_for(f)) } }
+ inspect_archive do |archive|
+ @files[1..-1].each { |f| archive[File.basename(f)].should
eql(content_for(f)) }
+ archive[File.basename(@files.first)].should be_nil
+ end
end
end
@@ -375,7 +386,7 @@
FileList[File.join(@target, "test/path/*")].size.should be(1)
Rake::Task.clear ; rm_rf @target
- unzip(@target=>@zip).include("test/**").target.invoke
+ unzip(@target=>@zip).include("test/**/*").target.invoke
FileList[File.join(@target, "test/path/*")].size.should be(2)
end
end