rake 10.0.0.beta.2 → 13.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/macos.yml +22 -0
  3. data/.github/workflows/ubuntu-rvm.yml +28 -0
  4. data/.github/workflows/ubuntu.yml +20 -0
  5. data/.github/workflows/windows.yml +20 -0
  6. data/CONTRIBUTING.rdoc +43 -0
  7. data/Gemfile +10 -0
  8. data/History.rdoc +2359 -0
  9. data/MIT-LICENSE +1 -1
  10. data/README.rdoc +57 -101
  11. data/Rakefile +22 -354
  12. data/bin/bundle +105 -0
  13. data/bin/console +7 -0
  14. data/bin/rake +19 -27
  15. data/bin/rdoc +29 -0
  16. data/bin/rubocop +29 -0
  17. data/bin/setup +6 -0
  18. data/doc/command_line_usage.rdoc +30 -18
  19. data/doc/glossary.rdoc +40 -49
  20. data/doc/jamis.rb +1 -0
  21. data/doc/rake.1 +156 -0
  22. data/doc/rakefile.rdoc +127 -62
  23. data/exe/rake +27 -0
  24. data/lib/rake.rb +35 -34
  25. data/lib/rake/application.rb +355 -188
  26. data/lib/rake/backtrace.rb +14 -7
  27. data/lib/rake/clean.rb +54 -8
  28. data/lib/rake/cloneable.rb +5 -4
  29. data/lib/rake/cpu_counter.rb +107 -0
  30. data/lib/rake/default_loader.rb +5 -0
  31. data/lib/rake/dsl_definition.rb +58 -19
  32. data/lib/rake/early_time.rb +5 -1
  33. data/lib/rake/ext/core.rb +5 -6
  34. data/lib/rake/ext/string.rb +61 -52
  35. data/lib/rake/file_creation_task.rb +4 -3
  36. data/lib/rake/file_list.rb +81 -49
  37. data/lib/rake/file_task.rb +15 -8
  38. data/lib/rake/file_utils.rb +63 -43
  39. data/lib/rake/file_utils_ext.rb +10 -22
  40. data/lib/rake/invocation_chain.rb +25 -19
  41. data/lib/rake/invocation_exception_mixin.rb +1 -0
  42. data/lib/rake/late_time.rb +18 -0
  43. data/lib/rake/linked_list.rb +112 -0
  44. data/lib/rake/loaders/makefile.rb +23 -9
  45. data/lib/rake/multi_task.rb +2 -1
  46. data/lib/rake/name_space.rb +36 -23
  47. data/lib/rake/packagetask.rb +71 -34
  48. data/lib/rake/phony.rb +6 -3
  49. data/lib/rake/private_reader.rb +21 -0
  50. data/lib/rake/promise.rb +100 -0
  51. data/lib/rake/pseudo_status.rb +8 -2
  52. data/lib/rake/rake_module.rb +34 -11
  53. data/lib/rake/rake_test_loader.rb +18 -13
  54. data/lib/rake/rule_recursion_overflow_error.rb +2 -2
  55. data/lib/rake/scope.rb +43 -0
  56. data/lib/rake/task.rb +166 -82
  57. data/lib/rake/task_argument_error.rb +1 -0
  58. data/lib/rake/task_arguments.rb +45 -14
  59. data/lib/rake/task_manager.rb +82 -50
  60. data/lib/rake/tasklib.rb +2 -12
  61. data/lib/rake/testtask.rb +68 -39
  62. data/lib/rake/thread_history_display.rb +10 -6
  63. data/lib/rake/thread_pool.rb +60 -86
  64. data/lib/rake/trace_output.rb +23 -0
  65. data/lib/rake/version.rb +6 -8
  66. data/lib/rake/win32.rb +14 -18
  67. data/rake.gemspec +36 -0
  68. metadata +64 -166
  69. data/.gemtest +0 -0
  70. data/CHANGES +0 -526
  71. data/TODO +0 -21
  72. data/doc/rake.1.gz +0 -0
  73. data/doc/release_notes/rake-0.4.14.rdoc +0 -23
  74. data/doc/release_notes/rake-0.4.15.rdoc +0 -35
  75. data/doc/release_notes/rake-0.5.0.rdoc +0 -53
  76. data/doc/release_notes/rake-0.5.3.rdoc +0 -78
  77. data/doc/release_notes/rake-0.5.4.rdoc +0 -46
  78. data/doc/release_notes/rake-0.6.0.rdoc +0 -141
  79. data/doc/release_notes/rake-0.7.0.rdoc +0 -119
  80. data/doc/release_notes/rake-0.7.1.rdoc +0 -59
  81. data/doc/release_notes/rake-0.7.2.rdoc +0 -121
  82. data/doc/release_notes/rake-0.7.3.rdoc +0 -47
  83. data/doc/release_notes/rake-0.8.0.rdoc +0 -114
  84. data/doc/release_notes/rake-0.8.2.rdoc +0 -165
  85. data/doc/release_notes/rake-0.8.3.rdoc +0 -112
  86. data/doc/release_notes/rake-0.8.4.rdoc +0 -147
  87. data/doc/release_notes/rake-0.8.5.rdoc +0 -53
  88. data/doc/release_notes/rake-0.8.6.rdoc +0 -55
  89. data/doc/release_notes/rake-0.8.7.rdoc +0 -55
  90. data/doc/release_notes/rake-0.9.0.rdoc +0 -112
  91. data/doc/release_notes/rake-0.9.1.rdoc +0 -52
  92. data/doc/release_notes/rake-0.9.2.2.rdoc +0 -55
  93. data/doc/release_notes/rake-0.9.2.rdoc +0 -49
  94. data/doc/release_notes/rake-0.9.3.rdoc +0 -102
  95. data/doc/release_notes/rake-10.0.0.rdoc +0 -178
  96. data/install.rb +0 -90
  97. data/lib/rake/alt_system.rb +0 -109
  98. data/lib/rake/contrib/compositepublisher.rb +0 -21
  99. data/lib/rake/contrib/ftptools.rb +0 -151
  100. data/lib/rake/contrib/publisher.rb +0 -73
  101. data/lib/rake/contrib/rubyforgepublisher.rb +0 -16
  102. data/lib/rake/contrib/sshpublisher.rb +0 -50
  103. data/lib/rake/ext/module.rb +0 -0
  104. data/lib/rake/ext/time.rb +0 -14
  105. data/lib/rake/pathmap.rb +0 -1
  106. data/lib/rake/ruby182_test_unit_fix.rb +0 -25
  107. data/lib/rake/runtest.rb +0 -21
  108. data/test/file_creation.rb +0 -34
  109. data/test/helper.rb +0 -522
  110. data/test/test_rake.rb +0 -40
  111. data/test/test_rake_application.rb +0 -484
  112. data/test/test_rake_application_options.rb +0 -427
  113. data/test/test_rake_backtrace.rb +0 -67
  114. data/test/test_rake_clean.rb +0 -14
  115. data/test/test_rake_definitions.rb +0 -80
  116. data/test/test_rake_directory_task.rb +0 -57
  117. data/test/test_rake_dsl.rb +0 -40
  118. data/test/test_rake_early_time.rb +0 -31
  119. data/test/test_rake_extension.rb +0 -59
  120. data/test/test_rake_file_creation_task.rb +0 -56
  121. data/test/test_rake_file_list.rb +0 -628
  122. data/test/test_rake_file_list_path_map.rb +0 -8
  123. data/test/test_rake_file_task.rb +0 -122
  124. data/test/test_rake_file_utils.rb +0 -305
  125. data/test/test_rake_ftp_file.rb +0 -59
  126. data/test/test_rake_functional.rb +0 -472
  127. data/test/test_rake_invocation_chain.rb +0 -52
  128. data/test/test_rake_makefile_loader.rb +0 -44
  129. data/test/test_rake_multi_task.rb +0 -59
  130. data/test/test_rake_name_space.rb +0 -43
  131. data/test/test_rake_package_task.rb +0 -79
  132. data/test/test_rake_path_map.rb +0 -157
  133. data/test/test_rake_path_map_explode.rb +0 -34
  134. data/test/test_rake_path_map_partial.rb +0 -18
  135. data/test/test_rake_pseudo_status.rb +0 -21
  136. data/test/test_rake_rake_test_loader.rb +0 -21
  137. data/test/test_rake_reduce_compat.rb +0 -30
  138. data/test/test_rake_require.rb +0 -40
  139. data/test/test_rake_rules.rb +0 -327
  140. data/test/test_rake_task.rb +0 -316
  141. data/test/test_rake_task_argument_parsing.rb +0 -103
  142. data/test/test_rake_task_arguments.rb +0 -88
  143. data/test/test_rake_task_lib.rb +0 -9
  144. data/test/test_rake_task_manager.rb +0 -157
  145. data/test/test_rake_task_manager_argument_resolution.rb +0 -19
  146. data/test/test_rake_task_with_arguments.rb +0 -162
  147. data/test/test_rake_test_task.rb +0 -120
  148. data/test/test_rake_thread_pool.rb +0 -146
  149. data/test/test_rake_top_level_functions.rb +0 -71
  150. data/test/test_rake_win32.rb +0 -72
  151. data/test/test_thread_history_display.rb +0 -91
@@ -1,21 +1,27 @@
1
+ # frozen_string_literal: true
1
2
  module Rake
2
3
 
3
- ####################################################################
4
+ ##
4
5
  # Exit status class for times the system just gives us a nil.
5
- class PseudoStatus
6
+ class PseudoStatus # :nodoc: all
6
7
  attr_reader :exitstatus
8
+
7
9
  def initialize(code=0)
8
10
  @exitstatus = code
9
11
  end
12
+
10
13
  def to_i
11
14
  @exitstatus << 8
12
15
  end
16
+
13
17
  def >>(n)
14
18
  to_i >> n
15
19
  end
20
+
16
21
  def stopped?
17
22
  false
18
23
  end
24
+
19
25
  def exited?
20
26
  true
21
27
  end
@@ -1,9 +1,8 @@
1
- require 'rake/application'
1
+ # frozen_string_literal: true
2
+ require "rake/application"
2
3
 
3
4
  module Rake
4
5
 
5
- # Rake module singleton methods.
6
- #
7
6
  class << self
8
7
  # Current Rake Application
9
8
  def application
@@ -15,6 +14,11 @@ module Rake
15
14
  @application = app
16
15
  end
17
16
 
17
+ def suggested_thread_count # :nodoc:
18
+ @cpu_count ||= Rake::CpuCounter.count
19
+ @cpu_count + 4
20
+ end
21
+
18
22
  # Return the original directory where the Rake application was started.
19
23
  def original_dir
20
24
  application.original_dir
@@ -28,16 +32,35 @@ module Rake
28
32
  # Add files to the rakelib list
29
33
  def add_rakelib(*files)
30
34
  application.options.rakelib ||= []
31
- files.each do |file|
32
- application.options.rakelib << file
33
- end
35
+ application.options.rakelib.concat(files)
34
36
  end
35
37
 
36
- # Get a sorted list of files matching the pattern. This method
37
- # should be prefered to Dir[pattern] and Dir.glob[pattern] because
38
- # the files returned are guaranteed to be sorted.
39
- def glob(pattern, *args)
40
- Dir.glob(pattern, *args).sort
38
+ # Make +block_application+ the default rake application inside a block so
39
+ # you can load rakefiles into a different application.
40
+ #
41
+ # This is useful when you want to run rake tasks inside a library without
42
+ # running rake in a sub-shell.
43
+ #
44
+ # Example:
45
+ #
46
+ # Dir.chdir 'other/directory'
47
+ #
48
+ # other_rake = Rake.with_application do |rake|
49
+ # rake.load_rakefile
50
+ # end
51
+ #
52
+ # puts other_rake.tasks
53
+
54
+ def with_application(block_application = Rake::Application.new)
55
+ orig_application = Rake.application
56
+
57
+ Rake.application = block_application
58
+
59
+ yield block_application
60
+
61
+ block_application
62
+ ensure
63
+ Rake.application = orig_application
41
64
  end
42
65
  end
43
66
 
@@ -1,22 +1,27 @@
1
- require 'rake'
1
+ # frozen_string_literal: true
2
+ require "rake"
2
3
 
3
4
  # Load the test files from the command line.
4
5
  argv = ARGV.select do |argument|
5
- case argument
6
- when /^-/ then
7
- argument
8
- when /\*/ then
9
- FileList[argument].to_a.each do |file|
10
- require File.expand_path file
11
- end
6
+ begin
7
+ case argument
8
+ when /^-/ then
9
+ argument
10
+ when /\*/ then
11
+ FileList[argument].to_a.each do |file|
12
+ require File.expand_path file
13
+ end
12
14
 
13
- false
14
- else
15
- require File.expand_path argument
15
+ false
16
+ else
17
+ require File.expand_path argument
16
18
 
17
- false
19
+ false
20
+ end
21
+ rescue LoadError => e
22
+ raise unless e.path
23
+ abort "\nFile does not exist: #{e.path}\n\n"
18
24
  end
19
25
  end
20
26
 
21
27
  ARGV.replace argv
22
-
@@ -1,4 +1,4 @@
1
-
1
+ # frozen_string_literal: true
2
2
  module Rake
3
3
 
4
4
  # Error indicating a recursion overflow error in task selection.
@@ -13,7 +13,7 @@ module Rake
13
13
  end
14
14
 
15
15
  def message
16
- super + ": [" + @targets.reverse.join(' => ') + "]"
16
+ super + ": [" + @targets.reverse.join(" => ") + "]"
17
17
  end
18
18
  end
19
19
 
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ module Rake
3
+ class Scope < LinkedList # :nodoc: all
4
+
5
+ # Path for the scope.
6
+ def path
7
+ map(&:to_s).reverse.join(":")
8
+ end
9
+
10
+ # Path for the scope + the named path.
11
+ def path_with_task_name(task_name)
12
+ "#{path}:#{task_name}"
13
+ end
14
+
15
+ # Trim +n+ innermost scope levels from the scope. In no case will
16
+ # this trim beyond the toplevel scope.
17
+ def trim(n)
18
+ result = self
19
+ while n > 0 && !result.empty?
20
+ result = result.tail
21
+ n -= 1
22
+ end
23
+ result
24
+ end
25
+
26
+ # Scope lists always end with an EmptyScope object. See Null
27
+ # Object Pattern)
28
+ class EmptyScope < EmptyLinkedList
29
+ @parent = Scope
30
+
31
+ def path
32
+ ""
33
+ end
34
+
35
+ def path_with_task_name(task_name)
36
+ task_name
37
+ end
38
+ end
39
+
40
+ # Singleton null object for an empty scope.
41
+ EMPTY = EmptyScope.new
42
+ end
43
+ end
@@ -1,8 +1,9 @@
1
- require 'rake/invocation_exception_mixin'
1
+ # frozen_string_literal: true
2
+ require "rake/invocation_exception_mixin"
2
3
 
3
4
  module Rake
4
5
 
5
- # #########################################################################
6
+ ##
6
7
  # A Task is the basic unit of work in a Rakefile. Tasks have associated
7
8
  # actions (possibly more than one) and a list of prerequisites. When
8
9
  # invoked, a task will first ensure that all of its prerequisites have an
@@ -14,6 +15,10 @@ module Rake
14
15
  class Task
15
16
  # List of prerequisites for a task.
16
17
  attr_reader :prerequisites
18
+ alias prereqs prerequisites
19
+
20
+ # List of order only prerequisites for a task.
21
+ attr_reader :order_only_prerequisites
17
22
 
18
23
  # List of actions attached to a task.
19
24
  attr_reader :actions
@@ -21,13 +26,6 @@ module Rake
21
26
  # Application owning this task.
22
27
  attr_accessor :application
23
28
 
24
- # Comment for this task. Restricted to a single line of no more than 50
25
- # characters.
26
- attr_reader :comment
27
-
28
- # Full text of the (possibly multi-line) comment.
29
- attr_reader :full_comment
30
-
31
29
  # Array of nested namespaces names used for task lookup by this task.
32
30
  attr_reader :scope
33
31
 
@@ -36,50 +34,81 @@ module Rake
36
34
  # location option set).
37
35
  attr_reader :locations
38
36
 
37
+ # Has this task already been invoked? Already invoked tasks
38
+ # will be skipped unless you reenable them.
39
+ attr_reader :already_invoked
40
+
39
41
  # Return task name
40
42
  def to_s
41
43
  name
42
44
  end
43
45
 
44
- def inspect
46
+ def inspect # :nodoc:
45
47
  "<#{self.class} #{name} => [#{prerequisites.join(', ')}]>"
46
48
  end
47
49
 
48
50
  # List of sources for task.
49
51
  attr_writer :sources
50
52
  def sources
51
- @sources ||= []
53
+ if defined?(@sources)
54
+ @sources
55
+ else
56
+ prerequisites
57
+ end
52
58
  end
53
59
 
54
60
  # List of prerequisite tasks
55
61
  def prerequisite_tasks
56
- prerequisites.collect { |pre| lookup_prerequisite(pre) }
62
+ (prerequisites + order_only_prerequisites).map { |pre| lookup_prerequisite(pre) }
57
63
  end
58
64
 
59
- def lookup_prerequisite(prerequisite_name)
60
- application[prerequisite_name, @scope]
65
+ def lookup_prerequisite(prerequisite_name) # :nodoc:
66
+ scoped_prerequisite_task = application[prerequisite_name, @scope]
67
+ if scoped_prerequisite_task == self
68
+ unscoped_prerequisite_task = application[prerequisite_name]
69
+ end
70
+ unscoped_prerequisite_task || scoped_prerequisite_task
61
71
  end
62
72
  private :lookup_prerequisite
63
73
 
74
+ # List of all unique prerequisite tasks including prerequisite tasks'
75
+ # prerequisites.
76
+ # Includes self when cyclic dependencies are found.
77
+ def all_prerequisite_tasks
78
+ seen = {}
79
+ collect_prerequisites(seen)
80
+ seen.values
81
+ end
82
+
83
+ def collect_prerequisites(seen) # :nodoc:
84
+ prerequisite_tasks.each do |pre|
85
+ next if seen[pre.name]
86
+ seen[pre.name] = pre
87
+ pre.collect_prerequisites(seen)
88
+ end
89
+ end
90
+ protected :collect_prerequisites
91
+
64
92
  # First source from a rule (nil if no sources)
65
93
  def source
66
- @sources.first if defined?(@sources)
94
+ sources.first
67
95
  end
68
96
 
69
97
  # Create a task named +task_name+ with no actions or prerequisites. Use
70
98
  # +enhance+ to add actions and prerequisites.
71
99
  def initialize(task_name, app)
72
- @name = task_name.to_s
73
- @prerequisites = []
74
- @actions = []
100
+ @name = task_name.to_s
101
+ @prerequisites = []
102
+ @actions = []
75
103
  @already_invoked = false
76
- @full_comment = nil
77
- @comment = nil
78
- @lock = Monitor.new
79
- @application = app
80
- @scope = app.current_scope
81
- @arg_names = nil
82
- @locations = []
104
+ @comments = []
105
+ @lock = Monitor.new
106
+ @application = app
107
+ @scope = app.current_scope
108
+ @arg_names = nil
109
+ @locations = []
110
+ @invocation_exception = nil
111
+ @order_only_prerequisites = []
83
112
  end
84
113
 
85
114
  # Enhance a task with prerequisites or actions. Returns self.
@@ -105,7 +134,7 @@ module Rake
105
134
 
106
135
  # Argument description (nil if none).
107
136
  def arg_description # :nodoc:
108
- @arg_names ? "[#{(arg_names || []).join(',')}]" : nil
137
+ @arg_names ? "[#{arg_names.join(',')}]" : nil
109
138
  end
110
139
 
111
140
  # Name of arguments for this task.
@@ -119,11 +148,12 @@ module Rake
119
148
  @already_invoked = false
120
149
  end
121
150
 
122
- # Clear the existing prerequisites and actions of a rake task.
151
+ # Clear the existing prerequisites, actions, comments, and arguments of a rake task.
123
152
  def clear
124
153
  clear_prerequisites
125
154
  clear_actions
126
155
  clear_comments
156
+ clear_args
127
157
  self
128
158
  end
129
159
 
@@ -141,8 +171,13 @@ module Rake
141
171
 
142
172
  # Clear the existing comments on a rake task.
143
173
  def clear_comments
144
- @full_comment = nil
145
- @comment = nil
174
+ @comments = []
175
+ self
176
+ end
177
+
178
+ # Clear the existing arguments on a rake task.
179
+ def clear_args
180
+ @arg_names = nil
146
181
  self
147
182
  end
148
183
 
@@ -154,25 +189,45 @@ module Rake
154
189
 
155
190
  # Same as invoke, but explicitly pass a call chain to detect
156
191
  # circular dependencies.
157
- def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
158
- new_chain = InvocationChain.append(self, invocation_chain)
192
+ #
193
+ # If multiple tasks depend on this
194
+ # one in parallel, they will all fail if the first execution of
195
+ # this task fails.
196
+ def invoke_with_call_chain(task_args, invocation_chain)
197
+ new_chain = Rake::InvocationChain.append(self, invocation_chain)
159
198
  @lock.synchronize do
160
- if application.options.trace
161
- application.trace "** Invoke #{name} #{format_trace_flags}"
199
+ begin
200
+ if application.options.trace
201
+ application.trace "** Invoke #{name} #{format_trace_flags}"
202
+ end
203
+
204
+ if @already_invoked
205
+ if @invocation_exception
206
+ if application.options.trace
207
+ application.trace "** Previous invocation of #{name} failed #{format_trace_flags}"
208
+ end
209
+ raise @invocation_exception
210
+ else
211
+ return
212
+ end
213
+ end
214
+
215
+ @already_invoked = true
216
+
217
+ invoke_prerequisites(task_args, new_chain)
218
+ execute(task_args) if needed?
219
+ rescue Exception => ex
220
+ add_chain_to(ex, new_chain)
221
+ @invocation_exception = ex
222
+ raise ex
162
223
  end
163
- return if @already_invoked
164
- @already_invoked = true
165
- invoke_prerequisites(task_args, new_chain)
166
- execute(task_args) if needed?
167
224
  end
168
- rescue Exception => ex
169
- add_chain_to(ex, new_chain)
170
- raise ex
171
225
  end
172
226
  protected :invoke_with_call_chain
173
227
 
174
- def add_chain_to(exception, new_chain)
175
- exception.extend(InvocationExceptionMixin) unless exception.respond_to?(:chain)
228
+ def add_chain_to(exception, new_chain) # :nodoc:
229
+ exception.extend(InvocationExceptionMixin) unless
230
+ exception.respond_to?(:chain)
176
231
  exception.chain = new_chain if exception.chain.nil?
177
232
  end
178
233
  private :add_chain_to
@@ -182,21 +237,23 @@ module Rake
182
237
  if application.options.always_multitask
183
238
  invoke_prerequisites_concurrently(task_args, invocation_chain)
184
239
  else
185
- prerequisite_tasks.each { |prereq|
186
- prereq_args = task_args.new_scope(prereq.arg_names)
187
- prereq.invoke_with_call_chain(prereq_args, invocation_chain)
240
+ prerequisite_tasks.each { |p|
241
+ prereq_args = task_args.new_scope(p.arg_names)
242
+ p.invoke_with_call_chain(prereq_args, invocation_chain)
188
243
  }
189
244
  end
190
245
  end
191
246
 
192
247
  # Invoke all the prerequisites of a task in parallel.
193
- def invoke_prerequisites_concurrently(args, invocation_chain) # :nodoc:
194
- futures = @prerequisites.collect do |p|
248
+ def invoke_prerequisites_concurrently(task_args, invocation_chain)# :nodoc:
249
+ futures = prerequisite_tasks.map do |p|
250
+ prereq_args = task_args.new_scope(p.arg_names)
195
251
  application.thread_pool.future(p) do |r|
196
- application[r, @scope].invoke_with_call_chain(args, invocation_chain)
252
+ r.invoke_with_call_chain(prereq_args, invocation_chain)
197
253
  end
198
254
  end
199
- futures.each { |f| f.call }
255
+ # Iterate in reverse to improve performance related to thread waiting and switching
256
+ futures.reverse_each(&:value)
200
257
  end
201
258
 
202
259
  # Format the trace flags for display.
@@ -215,17 +272,12 @@ module Rake
215
272
  application.trace "** Execute (dry run) #{name}"
216
273
  return
217
274
  end
218
- if application.options.trace
219
- application.trace "** Execute #{name}"
220
- end
275
+ application.trace "** Execute #{name}" if application.options.trace
221
276
  application.enhance_with_matching_rule(name) if @actions.empty?
222
- @actions.each do |act|
223
- case act.arity
224
- when 1
225
- act.call(self)
226
- else
227
- act.call(self, args)
228
- end
277
+ if opts = Hash.try_convert(args) and !opts.empty?
278
+ @actions.each { |act| act.call(self, args, **opts)}
279
+ else
280
+ @actions.each { |act| act.call(self, args)}
229
281
  end
230
282
  end
231
283
 
@@ -243,59 +295,91 @@ module Rake
243
295
  # Add a description to the task. The description can consist of an option
244
296
  # argument list (enclosed brackets) and an optional comment.
245
297
  def add_description(description)
246
- return if ! description
298
+ return unless description
247
299
  comment = description.strip
248
- add_comment(comment) if comment && ! comment.empty?
300
+ add_comment(comment) if comment && !comment.empty?
249
301
  end
250
302
 
251
- # Writing to the comment attribute is the same as adding a description.
252
- def comment=(description)
253
- add_description(description)
303
+ def comment=(comment) # :nodoc:
304
+ add_comment(comment)
254
305
  end
255
306
 
256
- # Add a comment to the task. If a comment already exists, separate
257
- # the new comment with " / ".
258
- def add_comment(comment)
259
- if @full_comment
260
- @full_comment << " / "
261
- else
262
- @full_comment = ''
263
- end
264
- @full_comment << comment
265
- if @full_comment =~ /\A([^.]+?\.)( |$)/
266
- @comment = $1
307
+ def add_comment(comment) # :nodoc:
308
+ return if comment.nil?
309
+ @comments << comment unless @comments.include?(comment)
310
+ end
311
+ private :add_comment
312
+
313
+ # Full collection of comments. Multiple comments are separated by
314
+ # newlines.
315
+ def full_comment
316
+ transform_comments("\n")
317
+ end
318
+
319
+ # First line (or sentence) of all comments. Multiple comments are
320
+ # separated by a "/".
321
+ def comment
322
+ transform_comments(" / ") { |c| first_sentence(c) }
323
+ end
324
+
325
+ # Transform the list of comments as specified by the block and
326
+ # join with the separator.
327
+ def transform_comments(separator, &block)
328
+ if @comments.empty?
329
+ nil
267
330
  else
268
- @comment = @full_comment
331
+ block ||= lambda { |c| c }
332
+ @comments.map(&block).join(separator)
269
333
  end
270
334
  end
271
- private :add_comment
335
+ private :transform_comments
336
+
337
+ # Get the first sentence in a string. The sentence is terminated
338
+ # by the first period, exclamation mark, or the end of the line.
339
+ # Decimal points do not count as periods.
340
+ def first_sentence(string)
341
+ string.split(/(?<=\w)(\.|!)[ \t]|(\.$|!)|\n/).first
342
+ end
343
+ private :first_sentence
272
344
 
273
345
  # Set the names of the arguments for this task. +args+ should be
274
346
  # an array of symbols, one for each argument name.
275
347
  def set_arg_names(args)
276
- @arg_names = args.map { |a| a.to_sym }
348
+ @arg_names = args.map(&:to_sym)
277
349
  end
278
350
 
279
351
  # Return a string describing the internal state of a task. Useful for
280
352
  # debugging.
281
353
  def investigation
282
- result = "------------------------------\n"
354
+ result = "------------------------------\n".dup
283
355
  result << "Investigating #{name}\n"
284
356
  result << "class: #{self.class}\n"
285
357
  result << "task needed: #{needed?}\n"
286
358
  result << "timestamp: #{timestamp}\n"
287
359
  result << "pre-requisites: \n"
288
360
  prereqs = prerequisite_tasks
289
- prereqs.sort! {|a,b| a.timestamp <=> b.timestamp}
361
+ prereqs.sort! { |a, b| a.timestamp <=> b.timestamp }
290
362
  prereqs.each do |p|
291
363
  result << "--#{p.name} (#{p.timestamp})\n"
292
364
  end
293
- latest_prereq = prerequisite_tasks.collect { |pre| pre.timestamp }.max
365
+ latest_prereq = prerequisite_tasks.map(&:timestamp).max
294
366
  result << "latest-prerequisite time: #{latest_prereq}\n"
295
367
  result << "................................\n\n"
296
368
  return result
297
369
  end
298
370
 
371
+ # Format dependencies parameter to pass to task.
372
+ def self.format_deps(deps)
373
+ deps = [deps] unless deps.respond_to?(:to_ary)
374
+ deps.map { |d| Rake.from_pathname(d).to_s }
375
+ end
376
+
377
+ # Add order only dependencies.
378
+ def |(deps)
379
+ @order_only_prerequisites |= Task.format_deps(deps) - @prerequisites
380
+ self
381
+ end
382
+
299
383
  # ----------------------------------------------------------------
300
384
  # Rake Module Methods
301
385
  #
@@ -341,7 +425,7 @@ module Rake
341
425
  # this kind of task. Generic tasks will accept the scope as
342
426
  # part of the name.
343
427
  def scope_name(scope, task_name)
344
- (scope + [task_name]).join(':')
428
+ scope.path_with_task_name(task_name)
345
429
  end
346
430
 
347
431
  end # class << Rake::Task