lib/buildr/core/checks.rb in vic-buildr-1.3.3 vs lib/buildr/core/checks.rb in vic-buildr-1.3.4

- old
+ new

@@ -13,14 +13,11 @@ # License for the specific language governing permissions and limitations under # the License. require 'buildr/core/project' -require 'buildr/packaging/zip' -#require 'test/unit' -require 'spec/matchers' -require 'spec/expectations' +autoload :Spec, 'spec' module Buildr # Methods added to Project to allow checking the build. module Checks @@ -116,12 +113,12 @@ # - All instance methods defined in context, so we can pass method calls to the context. # - it() method to return subject, description() method to return description. # - All matchers defined by Buildr and RSpec. klass = Class.new klass.instance_eval do - context.class.instance_methods(false).each do |method| - define_method(method) { |*args| context.send(method, *args) } + context.class.instance_methods.each do |method| + define_method(method) { |*args| context.send(method, *args) } unless instance_methods.include?(method) end define_method(:it) { subject } define_method(:description) { description } include Spec::Matchers include Matchers @@ -247,134 +244,9 @@ all? { |pattern| contents =~ pattern } end end end -end - - -module Zip #:nodoc: - class ZipEntry - - # :call-seq: - # exist() => boolean - # - # Returns true if this entry exists. - def exist?() - Zip::ZipFile.open(zipfile) { |zip| zip.file.exist?(@name) } - end - - # :call-seq: - # empty?() => boolean - # - # Returns true if this entry is empty. - def empty?() - Zip::ZipFile.open(zipfile) { |zip| zip.file.read(@name) }.empty? - end - - # :call-seq: - # contain(patterns*) => boolean - # - # Returns true if this ZIP file entry matches against all the arguments. An argument may be - # a string or regular expression. - def contain?(*patterns) - content = Zip::ZipFile.open(zipfile) { |zip| zip.file.read(@name) } - patterns.map { |pattern| Regexp === pattern ? pattern : Regexp.new(Regexp.escape(pattern.to_s)) }. - all? { |pattern| content =~ pattern } - end - - end -end - - -class Buildr::ArchiveTask - - class Path #:nodoc: - - # :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?() - !entries.empty? - end - - # :call-seq: - # empty?() => boolean - # - # Returns true if this path is empty (has no other entries inside). - def 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) - files.all? { |file| entries.detect { |entry| File.fnmatch(file, entry.to_s, File::FNM_PATHNAME) } } - 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) - root.entry("#{@path}#{name}") - end - - protected - - def entries() #:nodoc: - return root.entries unless @path - @entries ||= root.entries.inject([]) { |selected, entry| - selected << entry.name.sub(@path, "") if entry.name.index(@path) == 0 - selected - } - end - - end - - # :call-seq: - # empty?() => boolean - # - # Returns true if this ZIP file is empty (has no other entries inside). - def empty?() - path("").empty - end - - # :call-seq: - # contain(file*) => boolean - # - # Returns true if this ZIP file contains all the specified files. You can use absolute - # file names and glob patterns (using *, **, etc). - def contain?(*files) - path("").contain?(*files) - end - -end - - -class Buildr::ZipTask #:nodoc: - - # :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(entry_name) - ::Zip::ZipEntry.new(name, entry_name) - end - - def entries() #:nodoc: - @entries ||= Zip::ZipFile.open(name) { |zip| zip.entries } - end - end class Buildr::Project include Buildr::Checks