The TaskManager module is a mixin for managing tasks.
Find a matching task for task_name.
# File lib/rake.rb, line 1723 1723: def [](task_name, scopes=nil) 1724: task_name = task_name.to_s 1725: self.lookup(task_name, scopes) or 1726: enhance_with_matching_rule(task_name) or 1727: synthesize_file_task(task_name) or 1728: fail "Don't know how to build task '#{task_name}'" 1729: end
Clear all tasks in this application.
# File lib/rake.rb, line 1832 1832: def clear 1833: @tasks.clear 1834: @rules.clear 1835: end
# File lib/rake.rb, line 1697 1697: def create_rule(*args, &block) 1698: pattern, arg_names, deps = resolve_args(args) 1699: pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern 1700: @rules << [pattern, deps, block] 1701: end
Return the list of scope names currently active in the task manager.
# File lib/rake.rb, line 1872 1872: def current_scope 1873: @scope.dup 1874: end
# File lib/rake.rb, line 1703 1703: def define_task(task_class, *args, &block) 1704: task_name, arg_names, deps = resolve_args(args) 1705: task_name = task_class.scope_name(@scope, task_name) 1706: deps = [deps] unless deps.respond_to?(:to_ary) 1707: deps = deps.collect {|d| d.to_s } 1708: task = intern(task_class, task_name) 1709: task.set_arg_names(arg_names) unless arg_names.empty? 1710: task.add_description(@last_description) 1711: @last_description = nil 1712: task.enhance(deps, &block) 1713: task 1714: 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.rb, line 1802 1802: def enhance_with_matching_rule(task_name, level=0) 1803: fail Rake::RuleRecursionOverflowError, 1804: "Rule Recursion Too Deep" if level >= 16 1805: @rules.each do |pattern, extensions, block| 1806: if md = pattern.match(task_name) 1807: task = attempt_rule(task_name, extensions, block, level) 1808: return task if task 1809: end 1810: end 1811: nil 1812: rescue Rake::RuleRecursionOverflowError => ex 1813: ex.add_target(task_name) 1814: fail ex 1815: end
Evaluate the block in a nested namespace named name. Create an anonymous namespace if name is nil.
# File lib/rake.rb, line 1878 1878: def in_namespace(name) 1879: name ||= generate_name 1880: @scope.push(name) 1881: ns = NameSpace.new(self, @scope) 1882: yield(ns) 1883: ns 1884: ensure 1885: @scope.pop 1886: end
Lookup a task. Return an existing task if found, otherwise create a task of the current type.
# File lib/rake.rb, line 1718 1718: def intern(task_class, task_name) 1719: @tasks[task_name.to_s] ||= task_class.new(task_name, self) 1720: 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.rb, line 1842 1842: def lookup(task_name, initial_scope=nil) 1843: initial_scope ||= @scope 1844: task_name = task_name.to_s 1845: if task_name =~ /^rake:/ 1846: scopes = [] 1847: task_name = task_name.sub(/^rake:/, '') 1848: elsif task_name =~ /^(\^+)/ 1849: scopes = initial_scope[0, initial_scope.size - $1.size] 1850: task_name = task_name.sub(/^(\^+)/, '') 1851: else 1852: scopes = initial_scope 1853: end 1854: lookup_in_scope(task_name, scopes) 1855: end
Resolve the arguments for a task/rule. Returns a triplet of [task_name, arg_name_list, prerequisites].
# File lib/rake.rb, line 1738 1738: def resolve_args(args) 1739: if args.last.is_a?(Hash) 1740: deps = args.pop 1741: resolve_args_with_dependencies(args, deps) 1742: else 1743: resolve_args_without_dependencies(args) 1744: end 1745: end
# File lib/rake.rb, line 1731 1731: def synthesize_file_task(task_name) 1732: return nil unless File.exist?(task_name) 1733: define_task(Rake::FileTask, task_name) 1734: end
Attempt to create a rule given the list of prerequisites.
# File lib/rake.rb, line 1902 1902: def attempt_rule(task_name, extensions, block, level) 1903: sources = make_sources(task_name, extensions) 1904: prereqs = sources.collect { |source| 1905: trace_rule level, "Attempting Rule #{task_name} => #{source}" 1906: if File.exist?(source) || Rake::Task.task_defined?(source) 1907: trace_rule level, "(#{task_name} => #{source} ... EXIST)" 1908: source 1909: elsif parent = enhance_with_matching_rule(source, level+1) 1910: trace_rule level, "(#{task_name} => #{source} ... ENHANCE)" 1911: parent.name 1912: else 1913: trace_rule level, "(#{task_name} => #{source} ... FAIL)" 1914: return nil 1915: end 1916: } 1917: task = FileTask.define_task({task_name => prereqs}, &block) 1918: task.sources = prereqs 1919: task 1920: end
Generate an anonymous namespace name.
# File lib/rake.rb, line 1891 1891: def generate_name 1892: @seed ||= 0 1893: @seed += 1 1894: "_anon_#{@seed}" 1895: end
Lookup the task name
# File lib/rake.rb, line 1858 1858: def lookup_in_scope(name, scope) 1859: n = scope.size 1860: while n >= 0 1861: tn = (scope[0,n] + [name]).join(':') 1862: task = @tasks[tn] 1863: return task if task 1864: n -= 1 1865: end 1866: nil 1867: end
Make a list of sources from the list of file name extensions / translation procs.
# File lib/rake.rb, line 1924 1924: def make_sources(task_name, extensions) 1925: extensions.collect { |ext| 1926: case ext 1927: when /%/ 1928: task_name.pathmap(ext) 1929: when %{/} 1930: ext 1931: when /^\./ 1932: task_name.ext(ext) 1933: when String 1934: ext 1935: when Proc 1936: if ext.arity == 1 1937: ext.call(task_name) 1938: else 1939: ext.call 1940: end 1941: else 1942: fail "Don't know how to handle rule dependent: #{ext.inspect}" 1943: end 1944: }.flatten 1945: 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.rb, line 1756 1756: def resolve_args_without_dependencies(args) 1757: task_name = args.shift 1758: if args.size == 1 && args.first.respond_to?(:to_ary) 1759: arg_names = args.first.to_ary 1760: else 1761: arg_names = args 1762: end 1763: [task_name, arg_names, []] 1764: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.