rake 0.9.2 → 13.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.rdoc +43 -0
  3. data/Gemfile +10 -0
  4. data/History.rdoc +2386 -0
  5. data/MIT-LICENSE +1 -1
  6. data/README.rdoc +64 -109
  7. data/Rakefile +22 -386
  8. data/bin/bundle +105 -0
  9. data/bin/console +7 -0
  10. data/bin/rake +20 -23
  11. data/bin/rdoc +29 -0
  12. data/bin/rubocop +29 -0
  13. data/bin/setup +6 -0
  14. data/doc/command_line_usage.rdoc +65 -21
  15. data/doc/glossary.rdoc +40 -49
  16. data/doc/jamis.rb +1 -0
  17. data/doc/rake.1 +156 -0
  18. data/doc/rakefile.rdoc +127 -62
  19. data/exe/rake +27 -0
  20. data/lib/rake.rb +37 -31
  21. data/lib/rake/application.rb +507 -272
  22. data/lib/rake/backtrace.rb +24 -0
  23. data/lib/rake/clean.rb +55 -8
  24. data/lib/rake/cloneable.rb +11 -19
  25. data/lib/rake/cpu_counter.rb +107 -0
  26. data/lib/rake/default_loader.rb +5 -0
  27. data/lib/rake/dsl_definition.rb +74 -46
  28. data/lib/rake/early_time.rb +5 -1
  29. data/lib/rake/ext/core.rb +5 -6
  30. data/lib/rake/ext/string.rb +61 -52
  31. data/lib/rake/file_creation_task.rb +4 -3
  32. data/lib/rake/file_list.rb +81 -49
  33. data/lib/rake/file_task.rb +15 -8
  34. data/lib/rake/file_utils.rb +69 -47
  35. data/lib/rake/file_utils_ext.rb +18 -26
  36. data/lib/rake/invocation_chain.rb +25 -19
  37. data/lib/rake/invocation_exception_mixin.rb +1 -0
  38. data/lib/rake/late_time.rb +18 -0
  39. data/lib/rake/linked_list.rb +112 -0
  40. data/lib/rake/loaders/makefile.rb +23 -9
  41. data/lib/rake/multi_task.rb +4 -6
  42. data/lib/rake/name_space.rb +36 -23
  43. data/lib/rake/packagetask.rb +71 -34
  44. data/lib/rake/phony.rb +16 -0
  45. data/lib/rake/private_reader.rb +21 -0
  46. data/lib/rake/promise.rb +100 -0
  47. data/lib/rake/pseudo_status.rb +8 -2
  48. data/lib/rake/rake_module.rb +41 -3
  49. data/lib/rake/rake_test_loader.rb +21 -7
  50. data/lib/rake/rule_recursion_overflow_error.rb +2 -2
  51. data/lib/rake/scope.rb +43 -0
  52. data/lib/rake/task.rb +186 -79
  53. data/lib/rake/task_argument_error.rb +1 -0
  54. data/lib/rake/task_arguments.rb +50 -15
  55. data/lib/rake/task_manager.rb +89 -65
  56. data/lib/rake/tasklib.rb +2 -12
  57. data/lib/rake/testtask.rb +61 -63
  58. data/lib/rake/thread_history_display.rb +49 -0
  59. data/lib/rake/thread_pool.rb +163 -0
  60. data/lib/rake/trace_output.rb +23 -0
  61. data/lib/rake/version.rb +7 -7
  62. data/lib/rake/win32.rb +14 -18
  63. data/rake.gemspec +43 -0
  64. metadata +82 -221
  65. data/.gemtest +0 -0
  66. data/CHANGES +0 -509
  67. data/RRR +0 -9
  68. data/TODO +0 -20
  69. data/doc/rake.1.gz +0 -0
  70. data/doc/release_notes/rake-0.4.14.rdoc +0 -23
  71. data/doc/release_notes/rake-0.4.15.rdoc +0 -35
  72. data/doc/release_notes/rake-0.5.0.rdoc +0 -53
  73. data/doc/release_notes/rake-0.5.3.rdoc +0 -78
  74. data/doc/release_notes/rake-0.5.4.rdoc +0 -46
  75. data/doc/release_notes/rake-0.6.0.rdoc +0 -141
  76. data/doc/release_notes/rake-0.7.0.rdoc +0 -119
  77. data/doc/release_notes/rake-0.7.1.rdoc +0 -59
  78. data/doc/release_notes/rake-0.7.2.rdoc +0 -121
  79. data/doc/release_notes/rake-0.7.3.rdoc +0 -47
  80. data/doc/release_notes/rake-0.8.0.rdoc +0 -114
  81. data/doc/release_notes/rake-0.8.2.rdoc +0 -165
  82. data/doc/release_notes/rake-0.8.3.rdoc +0 -112
  83. data/doc/release_notes/rake-0.8.4.rdoc +0 -147
  84. data/doc/release_notes/rake-0.8.5.rdoc +0 -53
  85. data/doc/release_notes/rake-0.8.6.rdoc +0 -55
  86. data/doc/release_notes/rake-0.8.7.rdoc +0 -55
  87. data/doc/release_notes/rake-0.9.0.rdoc +0 -112
  88. data/doc/release_notes/rake-0.9.1.rdoc +0 -52
  89. data/doc/release_notes/rake-0.9.2.rdoc +0 -49
  90. data/install.rb +0 -90
  91. data/lib/rake/alt_system.rb +0 -109
  92. data/lib/rake/classic_namespace.rb +0 -9
  93. data/lib/rake/contrib/compositepublisher.rb +0 -21
  94. data/lib/rake/contrib/ftptools.rb +0 -150
  95. data/lib/rake/contrib/publisher.rb +0 -69
  96. data/lib/rake/contrib/rubyforgepublisher.rb +0 -16
  97. data/lib/rake/contrib/sshpublisher.rb +0 -45
  98. data/lib/rake/contrib/sys.rb +0 -191
  99. data/lib/rake/ext/module.rb +0 -39
  100. data/lib/rake/ext/time.rb +0 -14
  101. data/lib/rake/gempackagetask.rb +0 -13
  102. data/lib/rake/pathmap.rb +0 -1
  103. data/lib/rake/rdoctask.rb +0 -230
  104. data/lib/rake/ruby182_test_unit_fix.rb +0 -25
  105. data/lib/rake/runtest.rb +0 -21
  106. data/test/check_expansion.rb +0 -5
  107. data/test/check_no_expansion.rb +0 -5
  108. data/test/data/access/Rakefile +0 -35
  109. data/test/data/chains/Rakefile +0 -15
  110. data/test/data/comments/Rakefile +0 -18
  111. data/test/data/default/Rakefile +0 -17
  112. data/test/data/deprecated_import/Rakefile +0 -1
  113. data/test/data/dryrun/Rakefile +0 -22
  114. data/test/data/extra/Rakefile +0 -1
  115. data/test/data/file_creation_task/Rakefile +0 -31
  116. data/test/data/imports/Rakefile +0 -19
  117. data/test/data/imports/deps.mf +0 -1
  118. data/test/data/multidesc/Rakefile +0 -15
  119. data/test/data/namespace/Rakefile +0 -64
  120. data/test/data/rakelib/test1.rb +0 -4
  121. data/test/data/rbext/rakefile.rb +0 -3
  122. data/test/data/sample.mf +0 -14
  123. data/test/data/statusreturn/Rakefile +0 -6
  124. data/test/data/unittest/Rakefile +0 -1
  125. data/test/data/verbose/Rakefile +0 -34
  126. data/test/file_creation.rb +0 -34
  127. data/test/helper.rb +0 -44
  128. data/test/in_environment.rb +0 -35
  129. data/test/reqfile.rb +0 -3
  130. data/test/reqfile2.rb +0 -3
  131. data/test/shellcommand.rb +0 -3
  132. data/test/test_rake.rb +0 -38
  133. data/test/test_rake_application.rb +0 -364
  134. data/test/test_rake_application_options.rb +0 -382
  135. data/test/test_rake_clean.rb +0 -12
  136. data/test/test_rake_definitions.rb +0 -80
  137. data/test/test_rake_directory_task.rb +0 -55
  138. data/test/test_rake_dsl.rb +0 -73
  139. data/test/test_rake_early_time.rb +0 -31
  140. data/test/test_rake_extension.rb +0 -59
  141. data/test/test_rake_file_creation_task.rb +0 -62
  142. data/test/test_rake_file_list.rb +0 -633
  143. data/test/test_rake_file_list_path_map.rb +0 -8
  144. data/test/test_rake_file_task.rb +0 -104
  145. data/test/test_rake_file_utils.rb +0 -252
  146. data/test/test_rake_ftp_file.rb +0 -59
  147. data/test/test_rake_functional.rb +0 -468
  148. data/test/test_rake_invocation_chain.rb +0 -52
  149. data/test/test_rake_makefile_loader.rb +0 -23
  150. data/test/test_rake_multi_task.rb +0 -51
  151. data/test/test_rake_name_space.rb +0 -43
  152. data/test/test_rake_package_task.rb +0 -78
  153. data/test/test_rake_path_map.rb +0 -157
  154. data/test/test_rake_path_map_explode.rb +0 -31
  155. data/test/test_rake_path_map_partial.rb +0 -18
  156. data/test/test_rake_pseudo_status.rb +0 -20
  157. data/test/test_rake_rdoc_task.rb +0 -81
  158. data/test/test_rake_require.rb +0 -35
  159. data/test/test_rake_rules.rb +0 -346
  160. data/test/test_rake_task.rb +0 -271
  161. data/test/test_rake_task_argument_parsing.rb +0 -116
  162. data/test/test_rake_task_arguments.rb +0 -86
  163. data/test/test_rake_task_lib.rb +0 -9
  164. data/test/test_rake_task_manager.rb +0 -145
  165. data/test/test_rake_task_manager_argument_resolution.rb +0 -36
  166. data/test/test_rake_task_with_arguments.rb +0 -162
  167. data/test/test_rake_test_task.rb +0 -122
  168. data/test/test_rake_top_level_functions.rb +0 -76
  169. data/test/test_rake_win32.rb +0 -83
  170. data/test/test_sys.rb +0 -20
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Rake
2
3
 
3
4
  # EarlyTime is a fake timestamp that occurs _before_ any other time value.
@@ -5,11 +6,14 @@ module Rake
5
6
  include Comparable
6
7
  include Singleton
7
8
 
9
+ ##
10
+ # The EarlyTime always comes before +other+!
11
+
8
12
  def <=>(other)
9
13
  -1
10
14
  end
11
15
 
12
- def to_s
16
+ def to_s # :nodoc:
13
17
  "<EARLY TIME>"
14
18
  end
15
19
  end
data/lib/rake/ext/core.rb CHANGED
@@ -1,8 +1,6 @@
1
- ######################################################################
2
- # Core extension library
3
- #
1
+ # frozen_string_literal: true
4
2
  class Module
5
- # Check for an existing method in the current class before extending. IF
3
+ # Check for an existing method in the current class before extending. If
6
4
  # the method already exists, then a warning is printed and the extension is
7
5
  # not added. Otherwise the block is yielded and any definitions in the
8
6
  # block will take effect.
@@ -17,9 +15,10 @@ class Module
17
15
  # end
18
16
  # end
19
17
  #
20
- def rake_extension(method)
18
+ def rake_extension(method) # :nodoc:
21
19
  if method_defined?(method)
22
- $stderr.puts "WARNING: Possible conflict with Rake extension: #{self}##{method} already exists"
20
+ $stderr.puts "WARNING: Possible conflict with Rake extension: " +
21
+ "#{self}##{method} already exists"
23
22
  else
24
23
  yield
25
24
  end
@@ -1,19 +1,20 @@
1
- require 'rake/ext/core'
1
+ # frozen_string_literal: true
2
+ require "rake/ext/core"
2
3
 
3
- ######################################################################
4
- # Rake extension methods for String.
5
- #
6
4
  class String
5
+
7
6
  rake_extension("ext") do
8
7
  # Replace the file extension with +newext+. If there is no extension on
9
8
  # the string, append the new extension to the end. If the new extension
10
9
  # is not given, or is the empty string, remove any existing extension.
11
10
  #
12
11
  # +ext+ is a user added method for the String class.
13
- def ext(newext='')
14
- return self.dup if ['.', '..'].include? self
15
- if newext != ''
16
- newext = (newext =~ /^\./) ? newext : ("." + newext)
12
+ #
13
+ # This String extension comes from Rake
14
+ def ext(newext="")
15
+ return self.dup if [".", ".."].include? self
16
+ if newext != ""
17
+ newext = "." + newext unless newext =~ /^\./
17
18
  end
18
19
  self.chomp(File.extname(self)) << newext
19
20
  end
@@ -21,11 +22,13 @@ class String
21
22
 
22
23
  rake_extension("pathmap") do
23
24
  # Explode a path into individual components. Used by +pathmap+.
25
+ #
26
+ # This String extension comes from Rake
24
27
  def pathmap_explode
25
28
  head, tail = File.split(self)
26
29
  return [self] if head == self
27
- return [tail] if head == '.' || tail == '/'
28
- return [head, tail] if head == '/'
30
+ return [tail] if head == "." || tail == "/"
31
+ return [head, tail] if head == "/"
29
32
  return head.pathmap_explode + [tail]
30
33
  end
31
34
  protected :pathmap_explode
@@ -33,6 +36,8 @@ class String
33
36
  # Extract a partial path from the path. Include +n+ directories from the
34
37
  # front end (left hand side) if +n+ is positive. Include |+n+|
35
38
  # directories from the back end (right hand side) if +n+ is negative.
39
+ #
40
+ # This String extension comes from Rake
36
41
  def pathmap_partial(n)
37
42
  dirs = File.dirname(self).pathmap_explode
38
43
  partial_dirs =
@@ -47,19 +52,21 @@ class String
47
52
  end
48
53
  protected :pathmap_partial
49
54
 
50
- # Preform the pathmap replacement operations on the given path. The
55
+ # Perform the pathmap replacement operations on the given path. The
51
56
  # patterns take the form 'pat1,rep1;pat2,rep2...'.
57
+ #
58
+ # This String extension comes from Rake
52
59
  def pathmap_replace(patterns, &block)
53
60
  result = self
54
- patterns.split(';').each do |pair|
55
- pattern, replacement = pair.split(',')
61
+ patterns.split(";").each do |pair|
62
+ pattern, replacement = pair.split(",")
56
63
  pattern = Regexp.new(pattern)
57
- if replacement == '*' && block_given?
64
+ if replacement == "*" && block_given?
58
65
  result = result.sub(pattern, &block)
59
66
  elsif replacement
60
67
  result = result.sub(pattern, replacement)
61
68
  else
62
- result = result.sub(pattern, '')
69
+ result = result.sub(pattern, "")
63
70
  end
64
71
  end
65
72
  result
@@ -70,35 +77,36 @@ class String
70
77
  # controls the details of the mapping. The following special patterns are
71
78
  # recognized:
72
79
  #
73
- # * <b>%p</b> -- The complete path.
74
- # * <b>%f</b> -- The base file name of the path, with its file extension,
75
- # but without any directories.
76
- # * <b>%n</b> -- The file name of the path without its file extension.
77
- # * <b>%d</b> -- The directory list of the path.
78
- # * <b>%x</b> -- The file extension of the path. An empty string if there
79
- # is no extension.
80
- # * <b>%X</b> -- Everything *but* the file extension.
81
- # * <b>%s</b> -- The alternate file separator if defined, otherwise use
82
- # the standard file separator.
83
- # * <b>%%</b> -- A percent sign.
84
- #
85
- # The %d specifier can also have a numeric prefix (e.g. '%2d'). If the
86
- # number is positive, only return (up to) +n+ directories in the path,
87
- # starting from the left hand side. If +n+ is negative, return (up to)
88
- # |+n+| directories from the right hand side of the path.
80
+ # <tt>%p</tt> :: The complete path.
81
+ # <tt>%f</tt> :: The base file name of the path, with its file extension,
82
+ # but without any directories.
83
+ # <tt>%n</tt> :: The file name of the path without its file extension.
84
+ # <tt>%d</tt> :: The directory list of the path.
85
+ # <tt>%x</tt> :: The file extension of the path. An empty string if there
86
+ # is no extension.
87
+ # <tt>%X</tt> :: Everything *but* the file extension.
88
+ # <tt>%s</tt> :: The alternate file separator if defined, otherwise use #
89
+ # the standard file separator.
90
+ # <tt>%%</tt> :: A percent sign.
91
+ #
92
+ # The <tt>%d</tt> specifier can also have a numeric prefix (e.g. '%2d').
93
+ # If the number is positive, only return (up to) +n+ directories in the
94
+ # path, starting from the left hand side. If +n+ is negative, return (up
95
+ # to) +n+ directories from the right hand side of the path.
89
96
  #
90
97
  # Examples:
91
98
  #
92
99
  # 'a/b/c/d/file.txt'.pathmap("%2d") => 'a/b'
93
100
  # 'a/b/c/d/file.txt'.pathmap("%-2d") => 'c/d'
94
101
  #
95
- # Also the %d, %p, %f, %n, %x, and %X operators can take a
96
- # pattern/replacement argument to perform simple string substitutions on a
97
- # particular part of the path. The pattern and replacement are separated
98
- # by a comma and are enclosed by curly braces. The replacement spec comes
99
- # after the % character but before the operator letter. (e.g.
100
- # "%{old,new}d"). Multiple replacement specs should be separated by
101
- # semi-colons (e.g. "%{old,new;src,bin}d").
102
+ # Also the <tt>%d</tt>, <tt>%p</tt>, <tt>%f</tt>, <tt>%n</tt>,
103
+ # <tt>%x</tt>, and <tt>%X</tt> operators can take a pattern/replacement
104
+ # argument to perform simple string substitutions on a particular part of
105
+ # the path. The pattern and replacement are separated by a comma and are
106
+ # enclosed by curly braces. The replacement spec comes after the %
107
+ # character but before the operator letter. (e.g. "%{old,new}d").
108
+ # Multiple replacement specs should be separated by semi-colons (e.g.
109
+ # "%{old,new;src,bin}d").
102
110
  #
103
111
  # Regular expressions may be used for the pattern, and back refs may be
104
112
  # used in the replacement text. Curly braces, commas and semi-colons are
@@ -107,11 +115,11 @@ class String
107
115
  #
108
116
  # For example:
109
117
  #
110
- # "src/org/onestepback/proj/A.java".pathmap("%{^src,bin}X.class")
118
+ # "src/org/onestepback/proj/A.java".pathmap("%{^src,class}X.class")
111
119
  #
112
120
  # returns:
113
121
  #
114
- # "bin/org/onestepback/proj/A.class"
122
+ # "class/org/onestepback/proj/A.class"
115
123
  #
116
124
  # If the replacement text is '*', then a block may be provided to perform
117
125
  # some arbitrary calculation for the replacement.
@@ -126,34 +134,35 @@ class String
126
134
  #
127
135
  # "/path/to/file.txt"
128
136
  #
137
+ # This String extension comes from Rake
129
138
  def pathmap(spec=nil, &block)
130
139
  return self if spec.nil?
131
- result = ''
140
+ result = "".dup
132
141
  spec.scan(/%\{[^}]*\}-?\d*[sdpfnxX%]|%-?\d+d|%.|[^%]+/) do |frag|
133
142
  case frag
134
- when '%f'
143
+ when "%f"
135
144
  result << File.basename(self)
136
- when '%n'
145
+ when "%n"
137
146
  result << File.basename(self).ext
138
- when '%d'
147
+ when "%d"
139
148
  result << File.dirname(self)
140
- when '%x'
149
+ when "%x"
141
150
  result << File.extname(self)
142
- when '%X'
151
+ when "%X"
143
152
  result << self.ext
144
- when '%p'
153
+ when "%p"
145
154
  result << self
146
- when '%s'
155
+ when "%s"
147
156
  result << (File::ALT_SEPARATOR || File::SEPARATOR)
148
- when '%-'
157
+ when "%-"
149
158
  # do nothing
150
- when '%%'
159
+ when "%%"
151
160
  result << "%"
152
161
  when /%(-?\d+)d/
153
162
  result << pathmap_partial($1.to_i)
154
163
  when /^%\{([^}]*)\}(\d*[dpfnxX])/
155
164
  patterns, operator = $1, $2
156
- result << pathmap('%' + operator).pathmap_replace(patterns, &block)
165
+ result << pathmap("%" + operator).pathmap_replace(patterns, &block)
157
166
  when /^%/
158
167
  fail ArgumentError, "Unknown pathmap specifier #{frag} in '#{spec}'"
159
168
  else
@@ -163,5 +172,5 @@ class String
163
172
  result
164
173
  end
165
174
  end
166
- end # class String
167
175
 
176
+ end
@@ -1,5 +1,6 @@
1
- require 'rake/file_task'
2
- require 'rake/early_time'
1
+ # frozen_string_literal: true
2
+ require "rake/file_task"
3
+ require "rake/early_time"
3
4
 
4
5
  module Rake
5
6
 
@@ -11,7 +12,7 @@ module Rake
11
12
  class FileCreationTask < FileTask
12
13
  # Is this file task needed? Yes if it doesn't exist.
13
14
  def needed?
14
- ! File.exist?(name)
15
+ !File.exist?(name)
15
16
  end
16
17
 
17
18
  # Time stamp for file creation task. This time stamp is earlier
@@ -1,11 +1,11 @@
1
- require 'rake/cloneable'
2
- require 'rake/file_utils_ext'
3
- require 'rake/pathmap'
1
+ # frozen_string_literal: true
2
+ require "rake/cloneable"
3
+ require "rake/file_utils_ext"
4
+ require "rake/ext/string"
4
5
 
5
- ######################################################################
6
6
  module Rake
7
7
 
8
- # #########################################################################
8
+ ##
9
9
  # A FileList is essentially an array with a few helper methods defined to
10
10
  # make file manipulation a bit easier.
11
11
  #
@@ -41,14 +41,14 @@ module Rake
41
41
 
42
42
  # List of array methods (that are not in +Object+) that need to be
43
43
  # delegated.
44
- ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).map { |n| n.to_s }
44
+ ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).map(&:to_s)
45
45
 
46
46
  # List of additional methods that must be delegated.
47
- MUST_DEFINE = %w[to_a inspect <=>]
47
+ MUST_DEFINE = %w[inspect <=>]
48
48
 
49
49
  # List of methods that should not be delegated here (we define special
50
50
  # versions of them explicitly below).
51
- MUST_NOT_DEFINE = %w[to_a to_ary partition *]
51
+ MUST_NOT_DEFINE = %w[to_a to_ary partition * <<]
52
52
 
53
53
  # List of delegated methods that return new array values which need
54
54
  # wrapping.
@@ -58,21 +58,21 @@ module Rake
58
58
  + - & |
59
59
  ]
60
60
 
61
- DELEGATING_METHODS = (ARRAY_METHODS + MUST_DEFINE - MUST_NOT_DEFINE).collect{ |s| s.to_s }.sort.uniq
61
+ DELEGATING_METHODS = (ARRAY_METHODS + MUST_DEFINE - MUST_NOT_DEFINE).map(&:to_s).sort.uniq
62
62
 
63
63
  # Now do the delegation.
64
- DELEGATING_METHODS.each_with_index do |sym, i|
64
+ DELEGATING_METHODS.each do |sym|
65
65
  if SPECIAL_RETURN.include?(sym)
66
- ln = __LINE__+1
66
+ ln = __LINE__ + 1
67
67
  class_eval %{
68
68
  def #{sym}(*args, &block)
69
69
  resolve
70
70
  result = @items.send(:#{sym}, *args, &block)
71
- FileList.new.import(result)
71
+ self.class.new.import(result)
72
72
  end
73
73
  }, __FILE__, ln
74
74
  else
75
- ln = __LINE__+1
75
+ ln = __LINE__ + 1
76
76
  class_eval %{
77
77
  def #{sym}(*args, &block)
78
78
  resolve
@@ -83,6 +83,8 @@ module Rake
83
83
  end
84
84
  end
85
85
 
86
+ GLOB_PATTERN = %r{[*?\[\{]}
87
+
86
88
  # Create a file list from the globbable patterns given. If you wish to
87
89
  # perform multiple includes or excludes at object build time, use the
88
90
  # "yield self" pattern.
@@ -117,7 +119,7 @@ module Rake
117
119
  if fn.respond_to? :to_ary
118
120
  include(*fn.to_ary)
119
121
  else
120
- @pending_add << fn
122
+ @pending_add << Rake.from_pathname(fn)
121
123
  end
122
124
  end
123
125
  @pending = true
@@ -147,16 +149,17 @@ module Rake
147
149
  #
148
150
  def exclude(*patterns, &block)
149
151
  patterns.each do |pat|
150
- @exclude_patterns << pat
151
- end
152
- if block_given?
153
- @exclude_procs << block
152
+ if pat.respond_to? :to_ary
153
+ exclude(*pat.to_ary)
154
+ else
155
+ @exclude_patterns << Rake.from_pathname(pat)
156
+ end
154
157
  end
155
- resolve_exclude if ! @pending
158
+ @exclude_procs << block if block_given?
159
+ resolve_exclude unless @pending
156
160
  self
157
161
  end
158
162
 
159
-
160
163
  # Clear all the exclude patterns so that we exclude nothing.
161
164
  def clear_exclude
162
165
  @exclude_patterns = []
@@ -164,7 +167,7 @@ module Rake
164
167
  self
165
168
  end
166
169
 
167
- # Define equality.
170
+ # A FileList is equal through array equality.
168
171
  def ==(array)
169
172
  to_ary == array
170
173
  end
@@ -191,12 +194,18 @@ module Rake
191
194
  result = @items * other
192
195
  case result
193
196
  when Array
194
- FileList.new.import(result)
197
+ self.class.new.import(result)
195
198
  else
196
199
  result
197
200
  end
198
201
  end
199
202
 
203
+ def <<(obj)
204
+ resolve
205
+ @items << Rake.from_pathname(obj)
206
+ self
207
+ end
208
+
200
209
  # Resolve all the pending adds now.
201
210
  def resolve
202
211
  if @pending
@@ -208,9 +217,9 @@ module Rake
208
217
  self
209
218
  end
210
219
 
211
- def resolve_add(fn)
220
+ def resolve_add(fn) # :nodoc:
212
221
  case fn
213
- when %r{[*?\[\{]}
222
+ when GLOB_PATTERN
214
223
  add_matching(fn)
215
224
  else
216
225
  self << fn
@@ -218,8 +227,8 @@ module Rake
218
227
  end
219
228
  private :resolve_add
220
229
 
221
- def resolve_exclude
222
- reject! { |fn| exclude?(fn) }
230
+ def resolve_exclude # :nodoc:
231
+ reject! { |fn| excluded_from_list?(fn) }
223
232
  self
224
233
  end
225
234
  private :resolve_exclude
@@ -231,7 +240,7 @@ module Rake
231
240
  # FileList['a.c', 'b.c'].sub(/\.c$/, '.o') => ['a.o', 'b.o']
232
241
  #
233
242
  def sub(pat, rep)
234
- inject(FileList.new) { |res, fn| res << fn.sub(pat,rep) }
243
+ inject(self.class.new) { |res, fn| res << fn.sub(pat, rep) }
235
244
  end
236
245
 
237
246
  # Return a new FileList with the results of running +gsub+ against each
@@ -242,26 +251,26 @@ module Rake
242
251
  # => ['lib\\test\\file', 'x\\y']
243
252
  #
244
253
  def gsub(pat, rep)
245
- inject(FileList.new) { |res, fn| res << fn.gsub(pat,rep) }
254
+ inject(self.class.new) { |res, fn| res << fn.gsub(pat, rep) }
246
255
  end
247
256
 
248
257
  # Same as +sub+ except that the original file list is modified.
249
258
  def sub!(pat, rep)
250
- each_with_index { |fn, i| self[i] = fn.sub(pat,rep) }
259
+ each_with_index { |fn, i| self[i] = fn.sub(pat, rep) }
251
260
  self
252
261
  end
253
262
 
254
263
  # Same as +gsub+ except that the original file list is modified.
255
264
  def gsub!(pat, rep)
256
- each_with_index { |fn, i| self[i] = fn.gsub(pat,rep) }
265
+ each_with_index { |fn, i| self[i] = fn.gsub(pat, rep) }
257
266
  self
258
267
  end
259
268
 
260
269
  # Apply the pathmap spec to each of the included file names, returning a
261
270
  # new file list with the modified paths. (See String#pathmap for
262
271
  # details.)
263
- def pathmap(spec=nil)
264
- collect { |fn| fn.pathmap(spec) }
272
+ def pathmap(spec=nil, &block)
273
+ collect { |fn| fn.pathmap(spec, &block) }
265
274
  end
266
275
 
267
276
  # Return a new FileList with <tt>String#ext</tt> method applied to
@@ -272,11 +281,10 @@ module Rake
272
281
  # array.collect { |item| item.ext(newext) }
273
282
  #
274
283
  # +ext+ is a user added method for the Array class.
275
- def ext(newext='')
284
+ def ext(newext="")
276
285
  collect { |fn| fn.ext(newext) }
277
286
  end
278
287
 
279
-
280
288
  # Grep each of the files in the filelist using the given pattern. If a
281
289
  # block is given, call the block on each matching line, passing the file
282
290
  # name, line number, and the matching line of text. If no block is given,
@@ -286,7 +294,7 @@ module Rake
286
294
  matched = 0
287
295
  each do |fn|
288
296
  begin
289
- open(fn, "rb", *options) do |inf|
297
+ File.open(fn, "r", *options) do |inf|
290
298
  count = 0
291
299
  inf.each do |line|
292
300
  count += 1
@@ -310,14 +318,14 @@ module Rake
310
318
  # Return a new file list that only contains file names from the current
311
319
  # file list that exist on the file system.
312
320
  def existing
313
- select { |fn| File.exist?(fn) }
321
+ select { |fn| File.exist?(fn) }.uniq
314
322
  end
315
323
 
316
324
  # Modify the current file list so that it contains only file name that
317
325
  # exist on the file system.
318
326
  def existing!
319
327
  resolve
320
- @items = @items.select { |fn| File.exist?(fn) }
328
+ @items = @items.select { |fn| File.exist?(fn) }.uniq
321
329
  self
322
330
  end
323
331
 
@@ -327,33 +335,42 @@ module Rake
327
335
  resolve
328
336
  result = @items.partition(&block)
329
337
  [
330
- FileList.new.import(result[0]),
331
- FileList.new.import(result[1]),
338
+ self.class.new.import(result[0]),
339
+ self.class.new.import(result[1]),
332
340
  ]
333
341
  end
334
342
 
335
343
  # Convert a FileList to a string by joining all elements with a space.
336
344
  def to_s
337
345
  resolve
338
- self.join(' ')
346
+ self.join(" ")
339
347
  end
340
348
 
341
349
  # Add matching glob patterns.
342
350
  def add_matching(pattern)
343
- Dir[pattern].each do |fn|
344
- self << fn unless exclude?(fn)
351
+ self.class.glob(pattern).each do |fn|
352
+ self << fn unless excluded_from_list?(fn)
345
353
  end
346
354
  end
347
355
  private :add_matching
348
356
 
349
- # Should the given file name be excluded?
350
- def exclude?(fn)
357
+ # Should the given file name be excluded from the list?
358
+ #
359
+ # NOTE: This method was formerly named "exclude?", but Rails
360
+ # introduced an exclude? method as an array method and setup a
361
+ # conflict with file list. We renamed the method to avoid
362
+ # confusion. If you were using "FileList#exclude?" in your user
363
+ # code, you will need to update.
364
+ def excluded_from_list?(fn)
351
365
  return true if @exclude_patterns.any? do |pat|
352
366
  case pat
353
367
  when Regexp
354
368
  fn =~ pat
355
- when /[*?]/
356
- File.fnmatch?(pat, fn, File::FNM_PATHNAME)
369
+ when GLOB_PATTERN
370
+ flags = File::FNM_PATHNAME
371
+ # Ruby <= 1.9.3 does not support File::FNM_EXTGLOB
372
+ flags |= File::FNM_EXTGLOB if defined? File::FNM_EXTGLOB
373
+ File.fnmatch?(pat, fn, flags)
357
374
  else
358
375
  fn == pat
359
376
  end
@@ -368,10 +385,10 @@ module Rake
368
385
  /~$/
369
386
  ]
370
387
  DEFAULT_IGNORE_PROCS = [
371
- proc { |fn| fn =~ /(^|[\/\\])core$/ && ! File.directory?(fn) }
388
+ proc { |fn| fn =~ /(^|[\/\\])core$/ && !File.directory?(fn) }
372
389
  ]
373
390
 
374
- def import(array)
391
+ def import(array) # :nodoc:
375
392
  @items = array
376
393
  self
377
394
  end
@@ -383,6 +400,13 @@ module Rake
383
400
  def [](*args)
384
401
  new(*args)
385
402
  end
403
+
404
+ # Get a sorted list of files matching the pattern. This method
405
+ # should be preferred to Dir[pattern] and Dir.glob(pattern) because
406
+ # the files returned are guaranteed to be sorted.
407
+ def glob(pattern, *args)
408
+ Dir.glob(pattern, *args).sort
409
+ end
386
410
  end
387
411
  end
388
412
  end
@@ -393,11 +417,19 @@ module Rake
393
417
  # Yield each file or directory component.
394
418
  def each_dir_parent(dir) # :nodoc:
395
419
  old_length = nil
396
- while dir != '.' && dir.length != old_length
420
+ while dir != "." && dir.length != old_length
397
421
  yield(dir)
398
422
  old_length = dir.length
399
423
  dir = File.dirname(dir)
400
424
  end
401
425
  end
426
+
427
+ # Convert Pathname and Pathname-like objects to strings;
428
+ # leave everything else alone
429
+ def from_pathname(path) # :nodoc:
430
+ path = path.to_path if path.respond_to?(:to_path)
431
+ path = path.to_str if path.respond_to?(:to_str)
432
+ path
433
+ end
402
434
  end
403
435
  end # module Rake