You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by to...@apache.org on 2010/03/26 22:07:02 UTC

svn commit: r928060 - in /buildr/trunk: lib/buildr/core/filter.rb spec/core/common_spec.rb

Author: toulmean
Date: Fri Mar 26 21:07:02 2010
New Revision: 928060

URL: http://svn.apache.org/viewvc?rev=928060&view=rev
Log:
fix for BUILDR-408: Filter include() and exclude() should accept Rake tasks

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

Modified: buildr/trunk/lib/buildr/core/filter.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/filter.rb?rev=928060&r1=928059&r2=928060&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/filter.rb (original)
+++ buildr/trunk/lib/buildr/core/filter.rb Fri Mar 26 21:07:02 2010
@@ -84,6 +84,8 @@ module Buildr
       return nil unless @target_dir
       unless @target
         @target = file(File.expand_path(@target_dir)) { |task| run if @target == task }
+        @target.enhance @include.select {|f| f.is_a?(Rake::FileTask)}
+        @target.enhance @exclude.select {|f| f.is_a?(Rake::FileTask)}
         @target.enhance copy_map.values
       end
       @target
@@ -215,6 +217,8 @@ module Buildr
         return File.fnmatch(pattern, file)
       when pattern.is_a?(Proc)
         return pattern.call(file)
+      when pattern.is_a?(Rake::FileTask)
+        return pattern.to_s.match(file)
       else
         raise "Cannot interpret pattern #{pattern}"
       end

Modified: buildr/trunk/spec/core/common_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/common_spec.rb?rev=928060&r1=928059&r2=928060&view=diff
==============================================================================
--- buildr/trunk/spec/core/common_spec.rb (original)
+++ buildr/trunk/spec/core/common_spec.rb Fri Mar 26 21:07:02 2010
@@ -318,6 +318,11 @@ describe Buildr::Filter do
     @filter.from('src').into('target').include(lambda {|file| file[-1, 1].to_i%2 == 0}).run
     Dir['target/*'].sort.should eql(['target/file2', 'target/file4'])
   end
+  
+  it 'should respond to :include with a FileTask and use these inclusion patterns' do
+    @filter.from('src').into('target').include(file('target/file2'), file('target/file4')).run
+    Dir['target/*'].sort.should eql(['target/file2', 'target/file4'])
+  end
 
   it 'should respond to :exclude and return self' do
     @filter.exclude('file').should be(@filter)
@@ -337,6 +342,21 @@ describe Buildr::Filter do
     @filter.from('src').into('target').exclude(lambda {|file| file[-1, 1].to_i%2 == 0}).run
     Dir['target/*'].sort.should eql(['target/file1', 'target/file3'])
   end
+  
+  it 'should respond to :exclude with a FileTask and use these exclusion patterns' do
+    @filter.from('src').into('target').exclude(file('target/file1'), file('target/file3')).run
+    Dir['target/*'].sort.should eql(['target/file2', 'target/file4'])
+  end
+  
+  it 'should respond to :exclude with a FileTask, use these exclusion patterns and depend on those tasks' do
+    file1 = false
+    file2 = false
+    @filter.from('src').into('target').exclude(file('target/file1').enhance { file1 = true }, file('target/file3').enhance {file2 = true }).run
+    Dir['target/*'].sort.should eql(['target/file2', 'target/file4'])
+    @filter.target.invoke
+    file1.should be_true
+    file2.should be_true
+  end
 
   it 'should copy files over' do
     @filter.from('src').into('target').run



Re: svn commit: r928060 - in /buildr/trunk: lib/buildr/core/filter.rb spec/core/common_spec.rb

Posted by Antoine Toulme <an...@lunar-ocean.com>.
I would say that if you use a task in the exclude filter, you expect it to
be called at some point. Either by the filter or before. Since it is a
FileTask, it will only be called once (I only implemented support for
FileTask, not generic Rake Tasks).

For the two boolean values, something's wrong with that ? I wanted to make
sure both tasks ran and being able to debug it.

I don't use tasks in include and exclude but Regexps and Procs made me able
to hack support for some pretty special packaging of OSGi:
http://github.com/intalio/buildr4osgi/blob/master/lib/buildr4osgi/osgi/packaging.rb
see line 243. I'm not very happy with the code but it works.

On Sat, Mar 27, 2010 at 09:26, lacton <la...@users.sourceforge.net> wrote:

> On Sat, Mar 27, 2010 at 3:16 PM, Alex Boisvert <al...@gmail.com>
> wrote:
> > On Sat, Mar 27, 2010 at 4:19 AM, lacton <lacton@users.sourceforge.net
> >wrote:
> >
> >> I have two questions.
> >>
> >> 1. Why should buildr invoke a FileTask given to the exclude() method?
> >> For the include() method, I understand and appreciate the feature, but
> >> I don't understand the point for the exclude method.
> >>
> >
> > I was also perplexed when I suggested it.    The valid use cases are few
> and
> > far between.   I think the main reason is to maintain symmetry with
> > include().
> >
> > alex
>
> So, it seems to be a choice between API clarity through symmetry and
> runtime performance (i.e., fewer tasks to run).
>
> Both ways seem valid to me.  What do the others think about this issue?
>
> lacton
>

Re: svn commit: r928060 - in /buildr/trunk: lib/buildr/core/filter.rb spec/core/common_spec.rb

Posted by lacton <la...@users.sourceforge.net>.
On Sat, Mar 27, 2010 at 3:16 PM, Alex Boisvert <al...@gmail.com> wrote:
> On Sat, Mar 27, 2010 at 4:19 AM, lacton <la...@users.sourceforge.net>wrote:
>
>> I have two questions.
>>
>> 1. Why should buildr invoke a FileTask given to the exclude() method?
>> For the include() method, I understand and appreciate the feature, but
>> I don't understand the point for the exclude method.
>>
>
> I was also perplexed when I suggested it.    The valid use cases are few and
> far between.   I think the main reason is to maintain symmetry with
> include().
>
> alex

So, it seems to be a choice between API clarity through symmetry and
runtime performance (i.e., fewer tasks to run).

Both ways seem valid to me.  What do the others think about this issue?

lacton

Re: svn commit: r928060 - in /buildr/trunk: lib/buildr/core/filter.rb spec/core/common_spec.rb

Posted by Alex Boisvert <al...@gmail.com>.
On Sat, Mar 27, 2010 at 4:19 AM, lacton <la...@users.sourceforge.net>wrote:

> I have two questions.
>
> 1. Why should buildr invoke a FileTask given to the exclude() method?
> For the include() method, I understand and appreciate the feature, but
> I don't understand the point for the exclude method.
>

I was also perplexed when I suggested it.    The valid use cases are few and
far between.   I think the main reason is to maintain symmetry with
include().

alex

Re: svn commit: r928060 - in /buildr/trunk: lib/buildr/core/filter.rb spec/core/common_spec.rb

Posted by lacton <la...@users.sourceforge.net>.
I have two questions.

1. Why should buildr invoke a FileTask given to the exclude() method?
For the include() method, I understand and appreciate the feature, but
I don't understand the point for the exclude method.

2. Why two boolean values in the 'should respond to :exclude with a
FileTask, use these exclusion patterns and depend on those tasks' spec
instead of one?

lacton

On Fri, Mar 26, 2010 at 10:07 PM,  <to...@apache.org> wrote:
> Author: toulmean
> Date: Fri Mar 26 21:07:02 2010
> New Revision: 928060
>
> URL: http://svn.apache.org/viewvc?rev=928060&view=rev
> Log:
> fix for BUILDR-408: Filter include() and exclude() should accept Rake tasks
>
> Modified:
>    buildr/trunk/lib/buildr/core/filter.rb
>    buildr/trunk/spec/core/common_spec.rb
>
> Modified: buildr/trunk/lib/buildr/core/filter.rb
> URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/filter.rb?rev=928060&r1=928059&r2=928060&view=diff
> ==============================================================================
> --- buildr/trunk/lib/buildr/core/filter.rb (original)
> +++ buildr/trunk/lib/buildr/core/filter.rb Fri Mar 26 21:07:02 2010
> @@ -84,6 +84,8 @@ module Buildr
>       return nil unless @target_dir
>       unless @target
>         @target = file(File.expand_path(@target_dir)) { |task| run if @target == task }
> +        @target.enhance @include.select {|f| f.is_a?(Rake::FileTask)}
> +        @target.enhance @exclude.select {|f| f.is_a?(Rake::FileTask)}
>         @target.enhance copy_map.values
>       end
>       @target
> @@ -215,6 +217,8 @@ module Buildr
>         return File.fnmatch(pattern, file)
>       when pattern.is_a?(Proc)
>         return pattern.call(file)
> +      when pattern.is_a?(Rake::FileTask)
> +        return pattern.to_s.match(file)
>       else
>         raise "Cannot interpret pattern #{pattern}"
>       end
>
> Modified: buildr/trunk/spec/core/common_spec.rb
> URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/common_spec.rb?rev=928060&r1=928059&r2=928060&view=diff
> ==============================================================================
> --- buildr/trunk/spec/core/common_spec.rb (original)
> +++ buildr/trunk/spec/core/common_spec.rb Fri Mar 26 21:07:02 2010
> @@ -318,6 +318,11 @@ describe Buildr::Filter do
>     @filter.from('src').into('target').include(lambda {|file| file[-1, 1].to_i%2 == 0}).run
>     Dir['target/*'].sort.should eql(['target/file2', 'target/file4'])
>   end
> +
> +  it 'should respond to :include with a FileTask and use these inclusion patterns' do
> +    @filter.from('src').into('target').include(file('target/file2'), file('target/file4')).run
> +    Dir['target/*'].sort.should eql(['target/file2', 'target/file4'])
> +  end
>
>   it 'should respond to :exclude and return self' do
>     @filter.exclude('file').should be(@filter)
> @@ -337,6 +342,21 @@ describe Buildr::Filter do
>     @filter.from('src').into('target').exclude(lambda {|file| file[-1, 1].to_i%2 == 0}).run
>     Dir['target/*'].sort.should eql(['target/file1', 'target/file3'])
>   end
> +
> +  it 'should respond to :exclude with a FileTask and use these exclusion patterns' do
> +    @filter.from('src').into('target').exclude(file('target/file1'), file('target/file3')).run
> +    Dir['target/*'].sort.should eql(['target/file2', 'target/file4'])
> +  end
> +
> +  it 'should respond to :exclude with a FileTask, use these exclusion patterns and depend on those tasks' do
> +    file1 = false
> +    file2 = false
> +    @filter.from('src').into('target').exclude(file('target/file1').enhance { file1 = true }, file('target/file3').enhance {file2 = true }).run
> +    Dir['target/*'].sort.should eql(['target/file2', 'target/file4'])
> +    @filter.target.invoke
> +    file1.should be_true
> +    file2.should be_true
> +  end
>
>   it 'should copy files over' do
>     @filter.from('src').into('target').run
>
>
>