buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toulm...@apache.org
Subject svn commit: r927147 - in /buildr/trunk: CHANGELOG lib/buildr/core/filter.rb spec/core/common_spec.rb
Date Wed, 24 Mar 2010 18:44:31 GMT
Author: toulmean
Date: Wed Mar 24 18:44:31 2010
New Revision: 927147

URL: http://svn.apache.org/viewvc?rev=927147&view=rev
Log:
fix for BUILDR-406: Support for regexps in include and exclude patterns

Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/lib/buildr/core/filter.rb
    buildr/trunk/spec/core/common_spec.rb

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=927147&r1=927146&r2=927147&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Wed Mar 24 18:44:31 2010
@@ -1,4 +1,5 @@
 1.4.0 (Pending)
+* Added:  Support for regexps in include and exclude patterns (BUILDR-406)
 * Added:  Support for Scala 2.8 compiler-level change detection and dependency
           tracking
 * Added:  Continuous compilation

Modified: buildr/trunk/lib/buildr/core/filter.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/filter.rb?rev=927147&r1=927146&r2=927147&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/filter.rb (original)
+++ buildr/trunk/lib/buildr/core/filter.rb Wed Mar 24 18:44:31 2010
@@ -41,6 +41,9 @@ module Buildr
   # relative to the source directories, so:
   #   filter.include '*.png'
   # will only include PNG files from any of the source directories.
+  # In the same way, you can use regular expressions, so:
+  #   filter.include /picture_.*\.png/
+  # will only include PNG files starting with picture_ from any of the sources directories.
   #
   # See Buildr#filter.
   class Filter
@@ -204,8 +207,8 @@ module Buildr
       sources.flatten.map(&:to_s).inject({}) do |map, source|
         files = Util.recursive_with_dot_files(source).
           map { |file| Util.relative_path(file, source) }.
-          select { |file| @include.empty? || @include.any? { |pattern| File.fnmatch(pattern,
file) } }.
-          reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern, file) } }
+          select { |file| @include.empty? || @include.any? { |pattern| pattern.is_a?(Regexp)
? file.match(pattern) : File.fnmatch(pattern, file) } }.
+          reject { |file| @exclude.any? { |pattern| pattern.is_a?(Regexp) ? file.match(pattern)
: File.fnmatch(pattern, file) } }
         files.each do |file|
           src, dest = File.expand_path(file, source), File.expand_path(file, target.to_s)
           map[file] = src if !File.exist?(dest) || File.stat(src).mtime >= File.stat(dest).mtime

Modified: buildr/trunk/spec/core/common_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/common_spec.rb?rev=927147&r1=927146&r2=927147&view=diff
==============================================================================
--- buildr/trunk/spec/core/common_spec.rb (original)
+++ buildr/trunk/spec/core/common_spec.rb Wed Mar 24 18:44:31 2010
@@ -308,6 +308,11 @@ describe Buildr::Filter do
     @filter.from('src').into('target').include('file2', 'file3').run
     Dir['target/*'].sort.should eql(['target/file2', 'target/file3'])
   end
+  
+  it 'should respond to :include with regular expressions and use these inclusion patterns'
do
+    @filter.from('src').into('target').include(/file[2|3]/).run
+    Dir['target/*'].sort.should eql(['target/file2', 'target/file3'])
+  end
 
   it 'should respond to :exclude and return self' do
     @filter.exclude('file').should be(@filter)
@@ -317,6 +322,11 @@ describe Buildr::Filter do
     @filter.from('src').into('target').exclude('file2', 'file3').run
     Dir['target/*'].sort.should eql(['target/file1', 'target/file4'])
   end
+  
+  it 'should respond to :exclude  with regular expressions and use these exclusion patterns'
do
+    @filter.from('src').into('target').exclude(/file[2|3]/).run
+    Dir['target/*'].sort.should eql(['target/file1', 'target/file4'])
+  end
 
   it 'should copy files over' do
     @filter.from('src').into('target').run



Mime
View raw message