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.

### Methods

[] add_description arg_names clear clear clear_actions clear_prerequisites comment= create_rule define_task enhance execute inspect investigation invoke name needed? new reenable scope_name set_arg_names source sources task_defined? tasks timestamp to_s

### Attributes

actions | [R] | List of actions attached to a task.
application | [RW] | Application owning this task.
comment | [R] | Comment for this task. Restricted to a single line of no more than 50 characters.
full_comment | [R] | Full text of the (possibly multi-line) comment.
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.

### Public Class methods

[](task_name)

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.

[Source]

         # File lib/rake.rb, line 709
    709:       def [](task_name)
    710:         Rake.application[task_name]
    711:       end

clear()

Clear the task list. This cause rake to immediately forget all the tasks that have been assigned. (Normally used in the unit tests.)

[Source]

         # File lib/rake.rb, line 696
    696:       def clear
    697:         Rake.application.clear
    698:       end

create_rule(*args, &block)

Define a rule for synthesizing tasks.

[Source]

         # File lib/rake.rb, line 726
    726:       def create_rule(*args, &block)
    727:         Rake.application.create_rule(*args, &block)
    728:       end

define_task(*args, &block)

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.

[Source]

         # File lib/rake.rb, line 721
    721:       def define_task(*args, &block)
    722:         Rake.application.define_task(self, *args, &block)
    723:       end

new(task_name, app)

Create a task named `task_name` with no actions or prerequisites. Use `enhance` to add actions and prerequisites.

[Source]

         # File lib/rake.rb, line 492
    492:     def initialize(task_name, app)
    493:       @name = task_name.to_s
    494:       @prerequisites = []
    495:       @actions = []
    496:       @already_invoked = false
    497:       @full_comment = nil
    498:       @comment = nil
    499:       @lock = Monitor.new
    500:       @application = app
    501:       @scope = app.current_scope
    502:       @arg_names = nil
    503:     end

scope_name(scope, task_name)

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.

[Source]

         # File lib/rake.rb, line 733
    733:       def scope_name(scope, task_name)
    734:         (scope + [task_name]).join(':')
    735:       end

task_defined?(task_name)

TRUE if the task name is already defined.

[Source]

         # File lib/rake.rb, line 714
    714:       def task_defined?(task_name)
    715:         Rake.application.lookup(task_name) != nil
    716:       end

tasks()

List of all defined tasks.

[Source]

         # File lib/rake.rb, line 701
    701:       def tasks
    702:         Rake.application.tasks
    703:       end

### Public Instance methods

add_description(description)

Add a description to the task. The description can consist of an option argument list (enclosed brackets) and an optional comment.

[Source]

         # File lib/rake.rb, line 635
    635:     def add_description(description)
    636:       return if ! description
    637:       comment = description.strip
    638:       add_comment(comment) if comment && ! comment.empty?
    639:     end

arg_names()

Name of arguments for this task.

[Source]

         # File lib/rake.rb, line 532
    532:     def arg_names
    533:       @arg_names || []
    534:     end

clear()

Clear the existing prerequisites and actions of a rake task.

[Source]

         # File lib/rake.rb, line 543
    543:     def clear
    544:       clear_prerequisites
    545:       clear_actions
    546:       self
    547:     end

clear_actions()

Clear the existing actions on a rake task.

[Source]

         # File lib/rake.rb, line 556
    556:     def clear_actions
    557:       actions.clear
    558:       self
    559:     end

clear_prerequisites()

Clear the existing prerequisites of a rake task.

[Source]

         # File lib/rake.rb, line 550
    550:     def clear_prerequisites
    551:       prerequisites.clear
    552:       self
    553:     end

comment=(description)

Writing to the comment attribute is the same as adding a description.

[Source]

         # File lib/rake.rb, line 642
    642:     def comment=(description)
    643:       add_description(description)
    644:     end

enhance(deps=nil, &block)

Enhance a task with prerequisites or actions. Returns self.

[Source]

         # File lib/rake.rb, line 506
    506:     def enhance(deps=nil, &block)
    507:       @prerequisites |= deps if deps
    508:       @actions << block if block_given?
    509:       self
    510:     end

execute(args=nil)

Execute the actions associated with this task.

[Source]

         # File lib/rake.rb, line 602
    602:     def execute(args=nil)
    603:       args ||= EMPTY_TASK_ARGS
    604:       if application.options.dryrun
    605:         puts "** Execute (dry run) #{name}"
    606:         return
    607:       end
    608:       if application.options.trace
    609:         puts "** Execute #{name}"
    610:       end
    611:       application.enhance_with_matching_rule(name) if @actions.empty?
    612:       @actions.each do |act|
    613:         case act.arity
    614:         when 1
    615:           act.call(self)
    616:         else
    617:           act.call(self, args)
    618:         end
    619:       end
    620:     end

inspect()

[Source]

         # File lib/rake.rb, line 475
    475:     def inspect
    476:       "<#{self.class} #{name} => [#{prerequisites.join(', ')}]>"
    477:     end

investigation()

Return a string describing the internal state of a task. Useful for debugging.

[Source]

         # File lib/rake.rb, line 671
    671:     def investigation
    672:       result = "------------------------------\n"
    673:       result << "Investigating #{name}\n"
    674:       result << "class: #{self.class}\n"
    675:       result <<  "task needed: #{needed?}\n"
    676:       result <<  "timestamp: #{timestamp}\n"
    677:       result << "pre-requisites: \n"
    678:       prereqs = @prerequisites.collect {|name| application[name]}
    679:       prereqs.sort! {|a,b| a.timestamp <=> b.timestamp}
    680:       prereqs.each do |p|
    681:         result << "--#{p.name} (#{p.timestamp})\n"
    682:       end
    683:       latest_prereq = @prerequisites.collect{|n| application[n].timestamp}.max
    684:       result <<  "latest-prerequisite time: #{latest_prereq}\n"
    685:       result << "................................\n\n"
    686:       return result
    687:     end

invoke(*args)

Invoke the task if it is needed. Prerequites are invoked first.

[Source]

         # File lib/rake.rb, line 562
    562:     def invoke(*args)
    563:       task_args = TaskArguments.new(arg_names, args)
    564:       invoke_with_call_chain(task_args, InvocationChain::EMPTY)
    565:     end

name()

Name of the task, including any namespace qualifiers.

[Source]

         # File lib/rake.rb, line 513
    513:     def name
    514:       @name.to_s
    515:     end

needed?()

Is this task needed?

[Source]

         # File lib/rake.rb, line 623
    623:     def needed?
    624:       true
    625:     end

reenable()

Reenable the task, allowing its tasks to be executed if the task is invoked again.

[Source]

         # File lib/rake.rb, line 538
    538:     def reenable
    539:       @already_invoked = false
    540:     end

set_arg_names(args)

Set the names of the arguments for this task. `args` should be an array of symbols, one for each argument name.

[Source]

         # File lib/rake.rb, line 665
    665:     def set_arg_names(args)
    666:       @arg_names = args.map { |a| a.to_sym }
    667:     end

source()

First source from a rule (nil if no sources)

[Source]

         # File lib/rake.rb, line 486
    486:     def source
    487:       @sources.first if defined?(@sources)
    488:     end

sources()

[Source]

         # File lib/rake.rb, line 481
    481:     def sources
    482:       @sources ||= []
    483:     end

timestamp()

Timestamp for this task. Basic tasks return the current time for their time stamp. Other tasks can be more sophisticated.

[Source]

         # File lib/rake.rb, line 629
    629:     def timestamp
    630:       @prerequisites.collect { |p| application[p].timestamp }.max || Time.now
    631:     end

to_s()

Return task name

[Source]

         # File lib/rake.rb, line 471
    471:     def to_s
    472:       name
    473:     end

[Validate]