The TaskManager module is a mixin for managing tasks.
Find a matching task for task_name.
# File lib/rake/task_manager.rb, line 44 44: def [](task_name, scopes=nil) 45: task_name = task_name.to_s 46: self.lookup(task_name, scopes) or 47: enhance_with_matching_rule(task_name) or 48: synthesize_file_task(task_name) or 49: fail "Don't know how to build task '#{task_name}'" 50: end
Clear all tasks in this application.
# File lib/rake/task_manager.rb, line 153 153: def clear 154: @tasks.clear 155: @rules.clear 156: end
# File lib/rake/task_manager.rb, line 17 17: def create_rule(*args, &block) 18: pattern, arg_names, deps = resolve_args(args) 19: pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern 20: @rules << [pattern, deps, block] 21: end
Return the list of scope names currently active in the task manager.
# File lib/rake/task_manager.rb, line 193 193: def current_scope 194: @scope.dup 195: end
# File lib/rake/task_manager.rb, line 23 23: def define_task(task_class, *args, &block) 24: task_name, arg_names, deps = resolve_args(args) 25: task_name = task_class.scope_name(@scope, task_name) 26: deps = [deps] unless deps.respond_to?(:to_ary) 27: deps = deps.collect {|d| d.to_s } 28: task = intern(task_class, task_name) 29: task.set_arg_names(arg_names) unless arg_names.empty? 30: if Rake::TaskManager.record_task_metadata 31: add_location(task) 32: task.add_description(get_description(task)) 33: end 34: task.enhance(deps, &block) 35: end
If a rule can be found that matches the task name, enhance the task with the prerequisites and actions from the rule. Set the source attribute of the task appropriately for the rule. Return the enhanced task or nil of no rule was found.
# File lib/rake/task_manager.rb, line 123 123: def enhance_with_matching_rule(task_name, level=0) 124: fail Rake::RuleRecursionOverflowError, 125: "Rule Recursion Too Deep" if level >= 16 126: @rules.each do |pattern, extensions, block| 127: if md = pattern.match(task_name) 128: task = attempt_rule(task_name, extensions, block, level) 129: return task if task 130: end 131: end 132: nil 133: rescue Rake::RuleRecursionOverflowError => ex 134: ex.add_target(task_name) 135: fail ex 136: end
Evaluate the block in a nested namespace named name. Create an anonymous namespace if name is nil.
# File lib/rake/task_manager.rb, line 199 199: def in_namespace(name) 200: name ||= generate_name 201: @scope.push(name) 202: ns = NameSpace.new(self, @scope) 203: yield(ns) 204: ns 205: ensure 206: @scope.pop 207: end
Lookup a task. Return an existing task if found, otherwise create a task of the current type.
# File lib/rake/task_manager.rb, line 39 39: def intern(task_class, task_name) 40: @tasks[task_name.to_s] ||= task_class.new(task_name, self) 41: end
Lookup a task, using scope and the scope hints in the task name. This method performs straight lookups without trying to synthesize file tasks or rules. Special scope names (e.g. ’^’) are recognized. If no scope argument is supplied, use the current scope. Return nil if the task cannot be found.
# File lib/rake/task_manager.rb, line 163 163: def lookup(task_name, initial_scope=nil) 164: initial_scope ||= @scope 165: task_name = task_name.to_s 166: if task_name =~ /^rake:/ 167: scopes = [] 168: task_name = task_name.sub(/^rake:/, '') 169: elsif task_name =~ /^(\^+)/ 170: scopes = initial_scope[0, initial_scope.size - $1.size] 171: task_name = task_name.sub(/^(\^+)/, '') 172: else 173: scopes = initial_scope 174: end 175: lookup_in_scope(task_name, scopes) 176: end
Resolve the arguments for a task/rule. Returns a triplet of [task_name, arg_name_list, prerequisites].
# File lib/rake/task_manager.rb, line 59 59: def resolve_args(args) 60: if args.last.is_a?(Hash) 61: deps = args.pop 62: resolve_args_with_dependencies(args, deps) 63: else 64: resolve_args_without_dependencies(args) 65: end 66: end
# File lib/rake/task_manager.rb, line 52 52: def synthesize_file_task(task_name) 53: return nil unless File.exist?(task_name) 54: define_task(Rake::FileTask, task_name) 55: end
Add a location to the locations field of the given task.
# File lib/rake/task_manager.rb, line 212 212: def add_location(task) 213: loc = find_location 214: task.locations << loc if loc 215: task 216: end
Attempt to create a rule given the list of prerequisites.
# File lib/rake/task_manager.rb, line 241 241: def attempt_rule(task_name, extensions, block, level) 242: sources = make_sources(task_name, extensions) 243: prereqs = sources.collect { |source| 244: trace_rule level, "Attempting Rule #{task_name} => #{source}" 245: if File.exist?(source) || Rake::Task.task_defined?(source) 246: trace_rule level, "(#{task_name} => #{source} ... EXIST)" 247: source 248: elsif parent = enhance_with_matching_rule(source, level+1) 249: trace_rule level, "(#{task_name} => #{source} ... ENHANCE)" 250: parent.name 251: else 252: trace_rule level, "(#{task_name} => #{source} ... FAIL)" 253: return nil 254: end 255: } 256: task = FileTask.define_task({task_name => prereqs}, &block) 257: task.sources = prereqs 258: task 259: end
Find the location that called into the dsl layer.
# File lib/rake/task_manager.rb, line 219 219: def find_location 220: locations = caller 221: i = 0 222: while locations[i] 223: return locations[i+1] if locations[i] =~ /rake\/dsl_definition.rb/ 224: i += 1 225: end 226: nil 227: end
# File lib/rake/task_manager.rb, line 298 298: def find_preceding_comment_for_task(task) 299: loc = task.locations.last 300: file_name, line = parse_location(loc) 301: return nil unless file_name 302: comment_from_file(file_name, line) 303: end
Generate an anonymous namespace name.
# File lib/rake/task_manager.rb, line 230 230: def generate_name 231: @seed ||= 0 232: @seed += 1 233: "_anon_#{@seed}" 234: end
Return the current description. If there isn’t one, try to find it by reading in the source file and looking for a comment immediately prior to the task definition
# File lib/rake/task_manager.rb, line 292 292: def get_description(task) 293: desc = @last_description || find_preceding_comment_for_task(task) 294: @last_description = nil 295: desc 296: end
Lookup the task name
# File lib/rake/task_manager.rb, line 179 179: def lookup_in_scope(name, scope) 180: n = scope.size 181: while n >= 0 182: tn = (scope[0,n] + [name]).join(':') 183: task = @tasks[tn] 184: return task if task 185: n -= 1 186: end 187: nil 188: end
Make a list of sources from the list of file name extensions / translation procs.
# File lib/rake/task_manager.rb, line 263 263: def make_sources(task_name, extensions) 264: extensions.collect { |ext| 265: case ext 266: when /%/ 267: task_name.pathmap(ext) 268: when %{/} 269: ext 270: when /^\./ 271: task_name.ext(ext) 272: when String 273: ext 274: when Proc 275: if ext.arity == 1 276: ext.call(task_name) 277: else 278: ext.call 279: end 280: else 281: fail "Don't know how to handle rule dependent: #{ext.inspect}" 282: end 283: }.flatten 284: end
# File lib/rake/task_manager.rb, line 305 305: def parse_location(loc) 306: if loc =~ /^(.*):(\d+)/ 307: [ $1, Integer($2) ] 308: else 309: nil 310: end 311: end
Resolve task arguments for a task or rule when there are no dependencies declared.
The patterns recognized by this argument resolving function are:
task :t task :t, [:a] task :t, :a (deprecated)
# File lib/rake/task_manager.rb, line 77 77: def resolve_args_without_dependencies(args) 78: task_name = args.shift 79: if args.size == 1 && args.first.respond_to?(:to_ary) 80: arg_names = args.first.to_ary 81: else 82: arg_names = args 83: end 84: [task_name, arg_names, []] 85: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.