lib/core/checks.rb in buildr-1.2.2 vs lib/core/checks.rb in buildr-1.2.3

- old
+ new

@@ -267,64 +267,58 @@ end end module Buildr - class ZipTask + class ArchiveTask class Path # :call-seq: # exist() => boolean # # Returns true if this path exists. This only works if the path has any entries in it, # so exist on path happens to be the opposite of empty. def exist?() - !empty? + !entries.empty? end # :call-seq: # empty?() => boolean # # Returns true if this path is empty (has no other entries inside). def empty?() - check { |entries| entries.empty? } + entries.all? { |entry| entry.empty? } end # :call-seq: # contain(file*) => boolean # # 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) - check do |entries| - files.all? { |file| entries.detect { |entry| File.fnmatch(file, entry.to_s) } } - end + files.all? { |file| entries.detect { |entry| File.fnmatch(file, entry.to_s) } } end # :call-seq: # entry(name) => ZipEntry # # Returns a ZIP file entry. You can use this to check if the entry exists and its contents, # for example: # package(:jar).path("META-INF").entry("LICENSE").should contain(/Apache Software License/) def entry(name) - ::Zip::ZipEntry.new(root.name, "#{@path}#{name}") + root.entry("#{@path}#{name}") end protected - def check() #:nodoc: - unless @cached_entries - if @path - base = Regexp.new("^" + Regexp.escape(@path || "")) - @cached_entries = root.path(nil).check.select { |entry| entry.name =~ base }.map { |entry| entry.name.sub(base, "") } - else - @cached_entries = Zip::ZipFile.open(root.name) { |zip| zip.entries } - end - end - block_given? ? yield(@cached_entries) : @cached_entries + def entries() #:nodoc: + return root.entries unless @path + @entries ||= root.entries.inject([]) { |selected, entry| + selected << entry.name.sub(@path, "") if entry.name.starts_with?(@path) + selected + } end end # :call-seq: @@ -342,17 +336,26 @@ # file names and glob patterns (using *, **, etc). def contain?(*files) path("").contain?(*files) end + end + + + class ZipTask + # :call-seq: # entry(name) => Entry # # Returns a ZIP file entry. You can use this to check if the entry exists and its contents, # for example: # package(:jar).entry("META-INF/LICENSE").should contain(/Apache Software License/) - def entry(name) - path("").entry(name) + def entry(entry_name) + ::Zip::ZipEntry.new(name, entry_name) + end + + def entries() #:nodoc: + @entries ||= Zip::ZipFile.open(name) { |zip| zip.entries } end end end