Repository: buildr Updated Branches: refs/heads/master 6eb4586d3 -> 4fd3b06bc
BUILDR-620: resources.filter should not run on non-text files Project: http://git-wip-us.apache.org/repos/asf/buildr/repo Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/4fd3b06b Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/4fd3b06b Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/4fd3b06b Branch: refs/heads/master Commit: 4fd3b06bcc4dd05599a2e6149b8d2af4790ba9ae Parents: 6eb4586 Author: Antoine Toulme <[email protected]> Authored: Sun Aug 14 00:07:03 2016 -0700 Committer: Antoine Toulme <[email protected]> Committed: Sun Aug 14 00:07:03 2016 -0700 ---------------------------------------------------------------------- CHANGELOG | 1 + lib/buildr/core/filter.rb | 7 +++++++ spec/core/common_spec.rb | 7 +++++++ 3 files changed, 15 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/buildr/blob/4fd3b06b/CHANGELOG ---------------------------------------------------------------------- diff --git a/CHANGELOG b/CHANGELOG index b32d947..dc02680 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,7 @@ * Fixed: BUILDR-653 Using Eclipse compiler (ECJ) * Fixed: BUILDR-476 Buildr doesn't respect company repository manager * Fixed: BUILDR-454 Definition-level parent-child references-by-name fail in 1.4.0 but not in 1.3.5. Submitted by Rhett Sutphin. +* Fixed: BUILDR-620 resources.filter should not run on non-text files * Change: Update the custom_pom addon to generate poms with exclusions section that excludes all transitive dependencies. This is required as buildr dependencies are not transitive while Maven's dependencies are transitive by default. http://git-wip-us.apache.org/repos/asf/buildr/blob/4fd3b06b/lib/buildr/core/filter.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/core/filter.rb b/lib/buildr/core/filter.rb index 53edf3e..8d62765 100644 --- a/lib/buildr/core/filter.rb +++ b/lib/buildr/core/filter.rb @@ -308,8 +308,15 @@ module Buildr #:nodoc: end self end + + BINARY_FILES = [ '*.png', '*.gif', '*.jpg', '*.jpeg' ] + + def is_binary?(content, path) + !!path && BINARY_FILES.any? { |glob| File.fnmatch(glob, path) } + end def transform(content, path = nil) + return content if is_binary?(content, path) type = Regexp === mapper_type ? :regexp : mapper_type raise ArgumentError, "Invalid mapper type: #{type.inspect}" unless respond_to?("#{type}_transform", true) self.__send__("#{type}_transform", content, path) { |key| config[key] || config[key.to_s.to_sym] } http://git-wip-us.apache.org/repos/asf/buildr/blob/4fd3b06b/spec/core/common_spec.rb ---------------------------------------------------------------------- diff --git a/spec/core/common_spec.rb b/spec/core/common_spec.rb index a72d1bb..e9ceb31 100644 --- a/spec/core/common_spec.rb +++ b/spec/core/common_spec.rb @@ -401,6 +401,13 @@ describe Buildr::Filter do read(file).should eql("#{File.basename(file)} with value1 and value2") end end + + it 'should not apply filters to binary files' do + ["jpg", "jpeg", "gif", "png"].each { |ext| write "images/file.#{ext}", 'something' } + filter = @filter.from('images').into('target').using('key1'=>'value1', 'key2'=>'value2') + filter.instance_variable_get("@mapper").should_not_receive(:maven_transform) + filter.run + end it 'should apply hash mapping using Ant style' do 1.upto(4) { |i| write "src/file#{i}", "file#{i} with @key1@ and @key2@" }
