[RW] |
application |
Application owning this task.
|
[RW] |
comment |
Comment for this task.
|
[R] |
prerequisites |
List of prerequisites for a task.
|
[R] |
scope |
Array of nested namespaces names used for task lookup by this task.
|
[W] |
sources |
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.
458: def [](task_name)
459: Rake.application[task_name]
460: end
Clear the task list. This cause rake to immediately forget all the tasks that have been assigned. (Normally used
in the unit tests.)
445: def clear
446: Rake.application.clear
447: end
Define a rule for synthesizing tasks.
475: def create_rule(args, &block)
476: Rake.application.create_rule(args, &block)
477: 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.
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.
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
Apply the scope to the task name according
to the rules for this kind of task. Generic tasks will accept the scope as part of the name.
482: def scope_name(scope, task_name)
483: (scope + [task_name]).join(':')
484: end
TRUE if the task name is already defined.
463: def task_defined?(task_name)
464: Rake.application.lookup(task_name) != nil
465: end
List of all defined tasks.
450: def tasks
451: Rake.application.tasks
452: end
Add a comment to the task. If a comment alread exists, separate the new comment with " / ".
408: def add_comment(comment)
409: return if ! comment
410: if @comment
411: @comment << " / "
412: else
413: @comment = ''
414: end
415: @comment << comment
416: end
Enhance a task with prerequisites or actions. Returns self.
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.
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.
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.
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.
367: def invoke_prerequisites
368: @prerequisites.each { |n|
369: application[n, @scope].invoke
370: }
371: end
Name of the task, including any namespace qualifiers.
349: def name
350: @name.to_s
351: end
396: def needed?
397: true
398: end
324: def source
325: @sources.first if defined?(@sources)
326: end
319: def sources
320: @sources ||= []
321: end
Timestamp for this task. Basic tasks return
the current time for their time stamp. Other tasks can be more sophisticated.
402: def timestamp
403: @prerequisites.collect { |p| application[p].timestamp }.max || Time.now
404: end
313: def to_s
314: name
315: end