######################################################################### 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.
- []
- 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
[R] | actions | List of actions attached to a task. |
[RW] | application | Application owning this task. |
[R] | comment | Comment for this task. Restricted to a single line of no more than 50 characters. |
[R] | full_comment | Full text of the (possibly multi-line) comment. |
[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.
[ show source ]
# File lib/rake.rb, line 709 709: def [](task_name) 710: Rake.application[task_name] 711: end
Clear the task list. This cause rake to immediately forget all the tasks that have been assigned. (Normally used in the unit tests.)
[ show source ]
# File lib/rake.rb, line 696 696: def clear 697: Rake.application.clear 698: end
Define a rule for synthesizing tasks.
[ show source ]
# File lib/rake.rb, line 726 726: def create_rule(*args, &block) 727: Rake.application.create_rule(*args, &block) 728: 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.
[ show source ]
# File lib/rake.rb, line 721 721: def define_task(*args, &block) 722: Rake.application.define_task(self, *args, &block) 723: end
Create a task named task_name with no actions or prerequisites. Use enhance to add actions and prerequisites.
[ show 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
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.
[ show source ]
# File lib/rake.rb, line 733 733: def scope_name(scope, task_name) 734: (scope + [task_name]).join(':') 735: end
TRUE if the task name is already defined.
[ show source ]
# File lib/rake.rb, line 714 714: def task_defined?(task_name) 715: Rake.application.lookup(task_name) != nil 716: end
List of all defined tasks.
[ show source ]
# File lib/rake.rb, line 701 701: def tasks 702: Rake.application.tasks 703: end
Add a description to the task. The description can consist of an option argument list (enclosed brackets) and an optional comment.
[ show 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
Name of arguments for this task.
[ show source ]
# File lib/rake.rb, line 532 532: def arg_names 533: @arg_names || [] 534: end
Clear the existing prerequisites and actions of a rake task.
[ show source ]
# File lib/rake.rb, line 543 543: def clear 544: clear_prerequisites 545: clear_actions 546: self 547: end
Clear the existing actions on a rake task.
[ show source ]
# File lib/rake.rb, line 556 556: def clear_actions 557: actions.clear 558: self 559: end
Clear the existing prerequisites of a rake task.
[ show source ]
# File lib/rake.rb, line 550 550: def clear_prerequisites 551: prerequisites.clear 552: self 553: end
Writing to the comment attribute is the same as adding a description.
[ show source ]
# File lib/rake.rb, line 642 642: def comment=(description) 643: add_description(description) 644: end
Enhance a task with prerequisites or actions. Returns self.
[ show 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 the actions associated with this task.
[ show 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
[ show source ]
# File lib/rake.rb, line 475 475: def inspect 476: "<#{self.class} #{name} => [#{prerequisites.join(', ')}]>" 477: end
Return a string describing the internal state of a task. Useful for debugging.
[ show 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 the task if it is needed. Prerequites are invoked first.
[ show 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 of the task, including any namespace qualifiers.
[ show source ]
# File lib/rake.rb, line 513 513: def name 514: @name.to_s 515: end
Is this task needed?
[ show source ]
# File lib/rake.rb, line 623 623: def needed? 624: true 625: end
Reenable the task, allowing its tasks to be executed if the task is invoked again.
[ show source ]
# File lib/rake.rb, line 538 538: def reenable 539: @already_invoked = false 540: end
Set the names of the arguments for this task. args should be an array of symbols, one for each argument name.
[ show source ]
# File lib/rake.rb, line 665 665: def set_arg_names(args) 666: @arg_names = args.map { |a| a.to_sym } 667: end
[ show source ]
# File lib/rake.rb, line 486 486: def source 487: @sources.first if defined?(@sources) 488: end
[ show source ]
# File lib/rake.rb, line 481 481: def sources 482: @sources ||= [] 483: end
Timestamp for this task. Basic tasks return the current time for their time stamp. Other tasks can be more sophisticated.
[ show source ]
# File lib/rake.rb, line 629 629: def timestamp 630: @prerequisites.collect { |p| application[p].timestamp }.max || Time.now 631: end
Return task name
[ show source ]
# File lib/rake.rb, line 471 471: def to_s 472: name 473: end