Skip to content

Commit

Permalink
No longer delete core directories in clean task.
Browse files Browse the repository at this point in the history
Removed FileList exclude code duplication.
Added block based FileList exclusion.
Removed rake_dup.


git-svn-id: svn+ssh://rubyforge.org/var/svn/rake/trunk@580 5af023f1-ac1a-0410-98d6-829a145c37ef
  • Loading branch information
jimweirich committed Feb 25, 2007
1 parent 858eae6 commit c5ec238
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 50 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
70 changes: 23 additions & 47 deletions lib/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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
Expand All @@ -1106,20 +1089,24 @@ 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


# 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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion lib/rake/clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rakelib/shame.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- ruby -*-

begin
require 'rbosax'
require 'rbosa'
require 'code_statistics'

desc "Publish Code/Test Ratio on iChat"
Expand Down
9 changes: 8 additions & 1 deletion test/test_filelist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]$/)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c5ec238

Please sign in to comment.