buildr-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Boisvert <alex.boisv...@gmail.com>
Subject Re: Resource filtering does not handle binary files?
Date Tue, 27 Sep 2011 18:16:26 GMT
On Tue, Sep 27, 2011 at 10:02 AM, Dieter Vrancken <
dieter.vrancken@luciad.com> wrote:

> We are filtering our resources with settings from the profile and it is
> great! The problem is that one of our devs added a png image to the
> resources directory. As the filter tries to interpolate variables into this
> binary file, it fails miserably. Are we not supposed to put binary files in
> our resources? That would be unfortunate!
>

Hi Dieter,

Yeah, that's a problem.  You can circumvent the problem by monkey-patching
the Mapper class, e.g.,

https://gist.github.com/1245748

module Buildr
  class Filter
    class Mapper

      alias_method :transform_old, :transform

      BINARY_FILES = [ '*.png', '*.gif' ]

      def is_binary?(content, path)
        BINARY_FILES.any? { |glob| File.fnmatch(glob, path) }
      end

      def transform(content, path = nil)
        return content if is_binary?(content, path)
        transform_old(content, path)
      end
    end
  end
end

I'll fix this in Buildr so the next release doesn't apply filter mappings
willy-nelly on binary files.  (BTW, do you have any suggestion on good
binary content detection?)

Thanks for bringing this up.

alex

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message