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 458 458: def [](task_name) 459: Rake.application[task_name] 460: 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 470 470: def define_task(args, &block) 471: Rake.application.define_task(self, args, &block) 472: end
Create a task named task_name with no actions or prerequisites. Use enhance to add actions and prerequisites.
# File lib/rake.rb, line 330 330: def initialize(task_name, app) 331: @name = task_name.to_s 332: @prerequisites = FileList[] 333: @actions = [] 334: @already_invoked = false 335: @comment = nil 336: @lock = Mutex.new 337: @application = app 338: @scope = app.current_scope 339: end
Enhance a task with prerequisites or actions. Returns self.
# File lib/rake.rb, line 342 342: def enhance(deps=nil, &block) 343: @prerequisites |= deps if deps 344: @actions << block if block_given? 345: self 346: end
Execute the actions associated with this task.
# File lib/rake.rb, line 383 383: def execute 384: if application.options.dryrun 385: puts "** Execute (dry run) #{name}" 386: return 387: end 388: if application.options.trace 389: puts "** Execute #{name}" 390: end 391: application.enhance_with_matching_rule(name) if @actions.empty? 392: @actions.each { |act| result = act.call(self) } 393: end
Return a string describing the internal state of a task. Useful for debugging.
# File lib/rake.rb, line 420 420: def investigation 421: result = "------------------------------\n" 422: result << "Investigating #{name}\n" 423: result << "class: #{self.class}\n" 424: result << "task needed: #{needed?}\n" 425: result << "timestamp: #{timestamp}\n" 426: result << "pre-requisites: \n" 427: prereqs = @prerequisites.collect {|name| application[name]} 428: prereqs.sort! {|a,b| a.timestamp <=> b.timestamp} 429: prereqs.each do |p| 430: result << "--#{p.name} (#{p.timestamp})\n" 431: end 432: latest_prereq = @prerequisites.collect{|n| application[n].timestamp}.max 433: result << "latest-prerequisite time: #{latest_prereq}\n" 434: result << "................................\n\n" 435: return result 436: end
Invoke the task if it is needed. Prerequites are invoked first.
# File lib/rake.rb, line 354 354: def invoke 355: @lock.synchronize do 356: if application.options.trace 357: puts "** Invoke #{name} #{format_trace_flags}" 358: end 359: return if @already_invoked 360: @already_invoked = true 361: invoke_prerequisites 362: execute if needed? 363: end 364: end
Invoke all the prerequisites of a task.
# File lib/rake.rb, line 367 367: def invoke_prerequisites 368: @prerequisites.each { |n| 369: application[n, @scope].invoke 370: } 371: end
Name of the task, including any namespace qualifiers.
# File lib/rake.rb, line 349 349: def name 350: @name.to_s 351: end