Class: SC::Buildfile::Task
- Inherits:
-
Object
- Object
- SC::Buildfile::Task
- Includes:
- Cloneable
- Defined in:
- lib/sproutcore/buildfile/task.rb
Overview
Buildfile tasks are rake tasks with a few extras added to support unique buildfile constraints. Much of this source code is borrowed from Rake 0.8.3
Direct Known Subclasses
Constant Summary collapse
- IGNORE =
%w(@lock @application)
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
List of actions attached to a task.
-
#application ⇒ Object
Application owning this task.
-
#comment ⇒ Object
Comment for this task.
-
#execute_count ⇒ Object
readonly
The number of times the task was actually executed.
-
#full_comment ⇒ Object
readonly
Full text of the (possibly multi-line) comment.
-
#invoke_count ⇒ Object
readonly
The number of times this task has been invoked.
-
#prerequisites ⇒ Object
readonly
List of prerequisites for a task.
-
#scope ⇒ Object
readonly
Array of nested namespaces names used for task lookup by this task.
- #sources ⇒ Object
-
#task_options ⇒ Object
readonly
Various options you can set on the task to control log level, etc.
Class Method Summary collapse
-
.scope_name(scope, task_name) ⇒ Object
Apply the scope to the task name according to the rules for this kind of task.
Instance Method Summary collapse
-
#add_description(description) ⇒ Object
Add a description to the task.
-
#add_options(task_options) ⇒ Object
Add task options.
-
#arg_description ⇒ Object
Argument description (nil if none).
-
#arg_names ⇒ Object
Name of arguments for this task.
-
#clear ⇒ Object
Clear the existing prerequisites and actions of a rake task.
-
#clear_actions ⇒ Object
Clear the existing actions on a rake task.
-
#clear_prerequisites ⇒ Object
Clear the existing prerequisites of a rake task.
- #dup(app = nil) ⇒ Object
-
#enhance(deps = nil, &block) ⇒ Object
Enhance a task with prerequisites or actions.
-
#execute(args = nil) ⇒ Object
Execute the actions associated with this task.
-
#initialize(task_name, app) ⇒ Task
constructor
Create a task named
task_name
with no actions or prerequisites. - #inspect ⇒ Object
-
#investigation ⇒ Object
Return a string describing the internal state of a task.
-
#invoke(*args) ⇒ Object
Invoke the task if it is needed.
-
#invoke_prerequisites(task_args, invocation_chain) ⇒ Object
Invoke all the prerequisites of a task.
-
#name ⇒ Object
Name of the task, including any namespace qualifiers.
-
#name_with_args ⇒ Object
Name of task with argument list description.
-
#needed? ⇒ Boolean
Is this task needed?.
-
#set_arg_names(args) ⇒ Object
Set the names of the arguments for this task.
-
#source ⇒ Object
First source from a rule (nil if no sources).
-
#timestamp ⇒ Object
Timestamp for this task.
-
#to_s ⇒ Object
Return task name.
Methods included from Cloneable
Constructor Details
#initialize(task_name, app) ⇒ Task
Create a task named task_name
with no actions or prerequisites. Use enhance
to add actions and prerequisites.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sproutcore/buildfile/task.rb', line 81 def initialize(task_name, app) @name = task_name.to_s @prerequisites = [] @actions = [] @full_comment = nil @comment = nil @lock = Monitor.new @application = app @scope = app.current_scope @arg_names = nil @invoke_count = @execute_count = 0 @task_options = {} end |
Instance Attribute Details
#actions ⇒ Object (readonly)
List of actions attached to a task.
21 22 23 |
# File 'lib/sproutcore/buildfile/task.rb', line 21 def actions @actions end |
#application ⇒ Object
Application owning this task.
24 25 26 |
# File 'lib/sproutcore/buildfile/task.rb', line 24 def application @application end |
#comment ⇒ Object
Comment for this task. Restricted to a single line of no more than 50 characters.
28 29 30 |
# File 'lib/sproutcore/buildfile/task.rb', line 28 def comment @comment end |
#execute_count ⇒ Object (readonly)
The number of times the task was actually executed. This may differ from the invoke_count if the task was invoked but was not needed.
42 43 44 |
# File 'lib/sproutcore/buildfile/task.rb', line 42 def execute_count @execute_count end |
#full_comment ⇒ Object (readonly)
Full text of the (possibly multi-line) comment.
31 32 33 |
# File 'lib/sproutcore/buildfile/task.rb', line 31 def full_comment @full_comment end |
#invoke_count ⇒ Object (readonly)
The number of times this task has been invoked. Use to ensure that the task was invoked during some call chain…
38 39 40 |
# File 'lib/sproutcore/buildfile/task.rb', line 38 def invoke_count @invoke_count end |
#prerequisites ⇒ Object (readonly)
List of prerequisites for a task.
18 19 20 |
# File 'lib/sproutcore/buildfile/task.rb', line 18 def prerequisites @prerequisites end |
#scope ⇒ Object (readonly)
Array of nested namespaces names used for task lookup by this task.
34 35 36 |
# File 'lib/sproutcore/buildfile/task.rb', line 34 def scope @scope end |
#sources ⇒ Object
58 59 60 |
# File 'lib/sproutcore/buildfile/task.rb', line 58 def sources @sources ||= [] end |
#task_options ⇒ Object (readonly)
Various options you can set on the task to control log level, etc.
45 46 47 |
# File 'lib/sproutcore/buildfile/task.rb', line 45 def @task_options end |
Class Method Details
.scope_name(scope, task_name) ⇒ Object
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.
294 295 296 |
# File 'lib/sproutcore/buildfile/task.rb', line 294 def scope_name(scope, task_name) (scope + [task_name]).join(':') end |
Instance Method Details
#add_description(description) ⇒ Object
Add a description to the task. The description can consist of an option argument list (enclosed brackets) and an optional comment.
229 230 231 232 233 |
# File 'lib/sproutcore/buildfile/task.rb', line 229 def add_description(description) return if ! description comment = description.strip add_comment(comment) if comment && ! comment.empty? end |
#add_options(task_options) ⇒ Object
Add task options.
236 237 238 239 |
# File 'lib/sproutcore/buildfile/task.rb', line 236 def () return if ! @task_options = end |
#arg_description ⇒ Object
Argument description (nil if none).
117 118 119 |
# File 'lib/sproutcore/buildfile/task.rb', line 117 def arg_description # :nodoc: @arg_names ? "[#{(arg_names || []).join(',')}]" : nil end |
#arg_names ⇒ Object
Name of arguments for this task.
122 123 124 |
# File 'lib/sproutcore/buildfile/task.rb', line 122 def arg_names @arg_names || [] end |
#clear ⇒ Object
Clear the existing prerequisites and actions of a rake task.
127 128 129 130 131 |
# File 'lib/sproutcore/buildfile/task.rb', line 127 def clear clear_prerequisites clear_actions self end |
#clear_actions ⇒ Object
Clear the existing actions on a rake task.
140 141 142 143 |
# File 'lib/sproutcore/buildfile/task.rb', line 140 def clear_actions actions.clear self end |
#clear_prerequisites ⇒ Object
Clear the existing prerequisites of a rake task.
134 135 136 137 |
# File 'lib/sproutcore/buildfile/task.rb', line 134 def clear_prerequisites prerequisites.clear self end |
#dup(app = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sproutcore/buildfile/task.rb', line 68 def dup(app=nil) app = application if app.nil? sibling = self.class.new(name, app) self.instance_variables.each do |key| next if IGNORE.include?(key) sibling.instance_variable_set(key, self.instance_variable_get(key)) end sibling.taint if tainted? sibling end |
#enhance(deps = nil, &block) ⇒ Object
Enhance a task with prerequisites or actions. Returns self.
96 97 98 99 100 |
# File 'lib/sproutcore/buildfile/task.rb', line 96 def enhance(deps=nil, &block) @prerequisites |= deps if deps @actions << block if block_given? self end |
#execute(args = nil) ⇒ Object
Execute the actions associated with this task.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/sproutcore/buildfile/task.rb', line 201 def execute(args=nil) @execute_count += 1 args ||= EMPTY_TASK_ARGS return if SC.env.dryrun @actions.each do |act| case act.arity when 1 act.call(self) else act.call(self, args) end end end |
#inspect ⇒ Object
52 53 54 |
# File 'lib/sproutcore/buildfile/task.rb', line 52 def inspect "<#{self.class} #{name} => [#{prerequisites.join(', ')}]>" end |
#investigation ⇒ Object
Return a string describing the internal state of a task. Useful for debugging.
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/sproutcore/buildfile/task.rb', line 271 def investigation result = "------------------------------\n" result << "Investigating #{name}\n" result << "class: #{self.class}\n" result << "task needed: #{needed?}\n" result << "timestamp: #{}\n" result << "pre-requisites: \n" prereqs = @prerequisites.collect {|name| application[name]} prereqs.sort! {|a,b| a. <=> b.} prereqs.each do |p| result << "--#{p.name} (#{p.})\n" end latest_prereq = @prerequisites.collect{|n| application[n].}.max result << "latest-prerequisite time: #{latest_prereq}\n" result << "................................\n\n" return result end |
#invoke(*args) ⇒ Object
Invoke the task if it is needed. Prerequites are invoked first.
146 147 148 149 |
# File 'lib/sproutcore/buildfile/task.rb', line 146 def invoke(*args) task_args = TaskArguments.new(arg_names, args) invoke_with_call_chain(task_args, InvocationChain::EMPTY) end |
#invoke_prerequisites(task_args, invocation_chain) ⇒ Object
Invoke all the prerequisites of a task.
182 183 184 185 186 187 188 189 |
# File 'lib/sproutcore/buildfile/task.rb', line 182 def invoke_prerequisites(task_args, invocation_chain) # :nodoc: @prerequisites.each { |n| prereq = application[n, @scope] prereq_args = task_args.new_scope(prereq.arg_names) invocation_chain = prereq.invoke_with_call_chain(prereq_args, invocation_chain) } return invocation_chain end |
#name ⇒ Object
Name of the task, including any namespace qualifiers.
103 104 105 |
# File 'lib/sproutcore/buildfile/task.rb', line 103 def name @name.to_s end |
#name_with_args ⇒ Object
Name of task with argument list description.
108 109 110 111 112 113 114 |
# File 'lib/sproutcore/buildfile/task.rb', line 108 def name_with_args # :nodoc: if arg_description "#{name}#{arg_description}" else name end end |
#needed? ⇒ Boolean
Is this task needed?
217 218 219 |
# File 'lib/sproutcore/buildfile/task.rb', line 217 def needed? true end |
#set_arg_names(args) ⇒ Object
Set the names of the arguments for this task. args
should be an array of symbols, one for each argument name.
265 266 267 |
# File 'lib/sproutcore/buildfile/task.rb', line 265 def set_arg_names(args) @arg_names = args.map { |a| a.to_sym } end |
#source ⇒ Object
First source from a rule (nil if no sources)
63 64 65 |
# File 'lib/sproutcore/buildfile/task.rb', line 63 def source @sources.first if defined?(@sources) end |
#timestamp ⇒ Object
Timestamp for this task. Basic tasks return the current time for their time stamp. Other tasks can be more sophisticated.
223 224 225 |
# File 'lib/sproutcore/buildfile/task.rb', line 223 def @prerequisites.collect { |p| application[p]. }.max || Time.now end |
#to_s ⇒ Object
Return task name
48 49 50 |
# File 'lib/sproutcore/buildfile/task.rb', line 48 def to_s name end |