Class | Rake::Task |
In: |
lib/rake.rb
|
Parent: | Object |
A Task is the basic unit of work in a Rakefile. Tasks have associated actions (possibly more than one) and a list of prerequisites. When invoked, a task will first ensure that all of its prerequisites have an opportunity to run and then it will execute its own actions.
Tasks are not usually created directly using the new method, but rather use the file and task convenience methods.
application | [RW] | Application owning this task. |
comment | [RW] | Comment for this task. |
prerequisites | [R] | List of prerequisites for a task. |
scope | [R] | Array of nested namespaces names used for task lookup by this task. |
sources | [W] | List of sources for task. |
Return a task with the given name. If the task is not currently known, try to synthesize one from the defined rules. If no rules are found, but an existing file matches the task name, assume it is a file task with no dependencies or actions.
# File lib/rake.rb, line 466 466: def [](task_name) 467: Rake.application[task_name] 468: end
Define a task given args and an option block. If a rule with the given name already exists, the prerequisites and actions are added to the existing task. Returns the defined task.
# File lib/rake.rb, line 478 478: def define_task(args, &block) 479: Rake.application.define_task(self, args, &block) 480: end
Create a task named task_name with no actions or prerequisites.. use enhance to add actions and prerequisites.
# File lib/rake.rb, line 337 337: def initialize(task_name, app) 338: @name = task_name.to_s 339: @prerequisites = FileList[] 340: @actions = [] 341: @already_invoked = false 342: @comment = nil 343: @lock = Mutex.new 344: @application = app 345: @scope = app.current_scope 346: end
Enhance a task with prerequisites or actions. Returns self.
# File lib/rake.rb, line 349 349: def enhance(deps=nil, &block) 350: @prerequisites |= deps if deps 351: @actions << block if block_given? 352: self 353: end
Execute the actions associated with this task.
# File lib/rake.rb, line 390 390: def execute 391: if application.options.dryrun 392: puts "** Execute (dry run) #{name}" 393: return 394: end 395: if application.options.trace 396: puts "** Execute #{name}" 397: end 398: application.enhance_with_matching_rule(name) if @actions.empty? 399: @actions.each { |act| result = act.call(self) } 400: end
Return a string describing the internal state of a task. Useful for debugging.
# File lib/rake.rb, line 427 427: def investigation 428: result = "------------------------------\n" 429: result << "Investigating #{name}\n" 430: result << "class: #{self.class}\n" 431: result << "task needed: #{needed?}\n" 432: result << "timestamp: #{timestamp}\n" 433: result << "pre-requisites: \n" 434: prereqs = @prerequisites.collect {|name| application[name]} 435: prereqs.sort! {|a,b| a.timestamp <=> b.timestamp} 436: prereqs.each do |p| 437: result << "--#{p.name} (#{p.timestamp})\n" 438: end 439: latest_prereq = @prerequisites.collect{|n| application[n].timestamp}.max 440: result << "latest-prerequisite time: #{latest_prereq}\n" 441: result << "................................\n\n" 442: return result 443: end
Invoke the task if it is needed. Prerequites are invoked first.
# File lib/rake.rb, line 361 361: def invoke 362: @lock.synchronize do 363: if application.options.trace 364: puts "** Invoke #{name} #{format_trace_flags}" 365: end 366: return if @already_invoked 367: @already_invoked = true 368: invoke_prerequisites 369: execute if needed? 370: end 371: end
Invoke all the prerequisites of a task.
# File lib/rake.rb, line 374 374: def invoke_prerequisites 375: @prerequisites.each { |n| 376: application[n, @scope].invoke 377: } 378: end
Name of the task, including any namespace qualifiers.
# File lib/rake.rb, line 356 356: def name 357: @name.to_s 358: end