lib/tasks/zip.rb in buildr-0.16.0 vs lib/tasks/zip.rb in buildr-0.18.0

- old
+ new

@@ -17,22 +17,23 @@ if Hash === files.last options = files.pop else options = {} end + files = files.flatten if options[:path] path(options[:path]).include *files +[ options.reject { |k,v| k == :path } ] elsif options[:as] raise "You can only use the :as option in combination with the :path option" unless options.keys.size == 1 raise "You can only use one file with the :as option" unless files.size == 1 - include_as(files.first, options[:as]) + include_as(files.first.to_s, options[:as]) elsif options[:merge] raise "You can only use the :merge option in combination with the :path option" unless options.keys.size == 1 files.each { |file| merge file } elsif options.keys.empty? - (@files ||= FileList[]).include *files + (@files ||= FileList[]).include files.map(&:to_s) else raise "Unrecognized option #{options.keys.join(", ")}" end self end @@ -53,11 +54,11 @@ if options[:path] path(options[:path]).merge *files +[ options.reject { |k,v| k == :path } ] elsif options.keys.empty? files.collect do |file| - @expand_sources << proc { artifacts(file).map(&:to_s) } + @expand_sources << proc { file.to_s } expander = ZipExpander.new(file) @add_files << proc { |zip| expander.expand(zip, @path) } expander end.first else @@ -67,11 +68,11 @@ protected def setup_path(path = nil) @path = "#{path}/" if path - expand_src = proc { artifacts(*@files || []).map(&:to_s) } + expand_src = proc { (@files || []).map(&:to_s).uniq } @expand_sources = [ expand_src ] @add_files = [] << proc do |zip| expand_src.call.each do |file| if File.directory?(file) in_directory(file, @files) do |file, rel_path| @@ -85,13 +86,13 @@ end end end def include_as(source, as) - @expand_sources << proc { artifacts(source).map(&:to_s) } + @expand_sources << proc { source } @add_files << proc do |zip| - file = artifacts(source).first.to_s + file = source.to_s if File.directory?(file) in_directory(file) do |file, rel_path| puts "Adding #{@path}#{as}/#{rel_path}" if Rake.application.options.trace zip.add file, "#{@path}#{as}/#{rel_path}" end @@ -156,11 +157,11 @@ class ZipExpander def initialize(zip_file) - @zip_file = zip_file + @zip_file = zip_file.to_s end def include(*files) (@includes ||= []) @includes |= files @@ -174,11 +175,11 @@ end def expand(zip, path) @includes ||= ["*"] @excludes ||= [] - Zip::ZipFile.open(artifacts(@zip_file).map(&:to_s).first) do |source| + 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) } && !@excludes.any? { |pattern| File.fnmatch(pattern, entry.name) } puts "Adding #{path}#{entry.name}" if Rake.application.options.trace zip.get_output_stream("#{path}#{entry.name}") { |output| output.write source.read(entry) } @@ -230,43 +231,16 @@ # coming from, since some tasks touch the directory, e.g. when the # content of target/classes is included into a WAR. most_recent = @paths.collect { |name, path| path.expand_sources }.flatten. each { |src| File.directory?(src) ? FileList[File.join(src, "**", "*")] | [src] : src }.flatten. select { |file| File.exist?(file) }.collect { |file| File.stat(file).mtime }.max - File.stat(name).mtime < (most_recent || Rake::EARLY) + File.stat(name).mtime < (most_recent || Rake::EARLY) || super end protected def create(zip) @paths.each { |name, obj| obj.add_file zip } - end - - def zip_map() - unless @zip_map - args = @paths.collect do |path, files| - if path - dest_for = proc { |f| File.join(path, f) } - else - dest_for = proc { |f| f } - end - artifacts(*files).map(&:to_s).collect do |file| - if File.directory?(file) - # Include all files inside the directory, with path starting - # from the directory itself. - prefix = File.dirname(file) + File::SEPARATOR - Dir[File.join(file, "**", "*")].sort. - reject { |file| File.directory?(file) || files.exclude?(file) }. - collect { |file| [ dest_for[file.sub(prefix, "")], file ] } - else - # Include just that one file, sans its diectory path. - [ dest_for[File.basename(file)], file ] - end - end - end.flatten - @zip_map = Hash[ *args ] - end - @zip_map end end # The ZipTask creates a new ZIP file. You can include any number of files and