diff --git a/CHANGES b/CHANGES index 7b786b5d0..e9ff573e4 100644 --- a/CHANGES +++ b/CHANGES @@ -29,6 +29,12 @@ * Added a protected 'require "rubygems"' to test/test_application to unbreak cruisecontrol.rb. * Added the handful of RakeFileUtils to the private method as well. +* Added block based exclusion. +* The clean task will no longer delete 'core' if it is a directory. +* Removed rake_dup. Now we just simply rescue a bad dup. +* Refactored the FileList reject logic to remove duplication. +* Removed if __FILE__ at the end of the rake.rb file. +* Fixed the rake shame task. == Version 0.7.1 diff --git a/lib/rake.rb b/lib/rake.rb index e1dc8ea53..0190c5af2 100755 --- a/lib/rake.rb +++ b/lib/rake.rb @@ -39,27 +39,6 @@ require 'thread' require 'ostruct' -# Some objects are dupable, some are not. So we define a version of -# dup (called rake_dup) that returns self on the handful of classes -# that are not dupable. - -module Kernel - # Duplicate an object if it can be duplicated. If it can not be - # cloned or duplicated, then just return the original object. - def rake_dup() - dup - end -end - -[NilClass, FalseClass, TrueClass, Fixnum, Symbol].each do |clazz| - clazz.class_eval { - # Duplicate an object if it can be duplicated. If it can not be - # cloned or duplicated, then just return the original object. - def rake_dup() self end - } -end - - ###################################################################### # Rake extensions to Module. # @@ -303,7 +282,8 @@ def clone sibling = self.class.new instance_variables.each do |ivar| value = self.instance_variable_get(ivar) - sibling.instance_variable_set(ivar, value.rake_dup) + new_value = value.clone rescue value + sibling.instance_variable_set(ivar, new_value) end sibling end @@ -1060,6 +1040,7 @@ def initialize(*patterns) @pending_add = [] @pending = false @exclude_patterns = DEFAULT_IGNORE_PATTERNS.dup + @exclude_procs = DEFAULT_IGNORE_PROCS.dup @exclude_re = nil @items = [] patterns.each { |pattern| include(pattern) } @@ -1089,7 +1070,9 @@ def include(*filenames) # Register a list of file name patterns that should be excluded # from the list. Patterns may be regular expressions, glob - # patterns or regular strings. + # patterns or regular strings. In addition, a block given to + # exclude will remove entries that return true when given to the + # block. # # Note that glob patterns are expanded against the file system. # If a file is explicitly added to a file list, but does not exist @@ -1106,12 +1089,14 @@ def include(*filenames) # If "a.c" is not a file, then ... # FileList['a.c', 'b.c'].exclude("a.*") => ['a.c', 'b.c'] # - def exclude(*patterns) - patterns.each do |pat| @exclude_patterns << pat end - if ! @pending - calculate_exclude_regexp - reject! { |fn| fn =~ @exclude_re } + def exclude(*patterns, &block) + patterns.each do |pat| + @exclude_patterns << pat end + if block_given? + @exclude_procs << block + end + resolve_exclude if ! @pending self end @@ -1119,7 +1104,9 @@ def exclude(*patterns) # Clear all the exclude patterns so that we exclude nothing. def clear_exclude @exclude_patterns = [] + @exclude_procs = [] calculate_exclude_regexp if ! @pending + self end # Define equality. @@ -1192,17 +1179,8 @@ def resolve_add(fn) private :resolve_add def resolve_exclude - @exclude_patterns.each do |pat| - case pat - when Regexp - reject! { |fn| fn =~ pat } - when /[*?]/ - reject_list = Dir[pat] - reject! { |fn| reject_list.include?(fn) } - else - reject! { |fn| fn == pat } - end - end + calculate_exclude_regexp + reject! { |fn| exclude?(fn) } self end private :resolve_exclude @@ -1311,15 +1289,17 @@ def add_matching(pattern) # Should the given file name be excluded? def exclude?(fn) calculate_exclude_regexp unless @exclude_re - fn =~ @exclude_re + fn =~ @exclude_re || @exclude_procs.any? { |p| p.call(fn) } end DEFAULT_IGNORE_PATTERNS = [ /(^|[\/\\])CVS([\/\\]|$)/, /(^|[\/\\])\.svn([\/\\]|$)/, /\.bak$/, - /~$/, - /(^|[\/\\])core$/ + /~$/ + ] + DEFAULT_IGNORE_PROCS = [ + proc { |fn| fn =~ /(^|[\/\\])core$/ && ! File.directory?(fn) } ] @exclude_patterns = DEFAULT_IGNORE_PATTERNS.dup @@ -2001,8 +1981,4 @@ def const_missing(const_name) rake_original_const_missing(const_name) end end -end - -if __FILE__ == $0 then - Rake::Application.new.run -end +end \ No newline at end of file diff --git a/lib/rake/clean.rb b/lib/rake/clean.rb index 581daf871..4ee2c5ac9 100644 --- a/lib/rake/clean.rb +++ b/lib/rake/clean.rb @@ -16,7 +16,9 @@ require 'rake' CLEAN = Rake::FileList["**/*~", "**/*.bak", "**/core"] -CLEAN.clear_exclude +CLEAN.clear_exclude.exclude { |fn| + fn.pathmap("%f") == 'core' && File.directory?(fn) +} desc "Remove any temporary products." task :clean do diff --git a/rakelib/shame.rake b/rakelib/shame.rake index a8c5b631a..1e0853238 100644 --- a/rakelib/shame.rake +++ b/rakelib/shame.rake @@ -2,7 +2,7 @@ # -*- ruby -*- begin - require 'rbosax' + require 'rbosa' require 'code_statistics' desc "Publish Code/Test Ratio on iChat" diff --git a/test/test_filelist.rb b/test/test_filelist.rb index eca067042..f05771b7c 100644 --- a/test/test_filelist.rb +++ b/test/test_filelist.rb @@ -143,6 +143,13 @@ def test_exclude fl.exclude('testdata/existing') assert_equal [], fl end + + def test_excluding_via_block + fl = FileList['testdata/a.c', 'testdata/b.c', 'testdata/xyz.c'] + fl.exclude { |fn| fn.pathmap('%n') == 'xyz' } + assert fl.exclude?("xyz.c"), "Should exclude xyz.c" + assert_equal ['testdata/a.c', 'testdata/b.c'], fl + end def test_exclude_return_on_create fl = FileList['testdata/*'].exclude(/.*\.[hcx]$/) @@ -380,7 +387,7 @@ def test_array_equality b = ['a', 'b'] assert a == b assert b == a -# assert a.eql?(b) +# assert a.eql?(b) # assert b.eql?(a) assert ! a.equal?(b) assert ! b.equal?(a)