Rake main application object. When invoking rake from the command line, a Rake::Application object is created and run.

Methods
Included Modules
Constants
RAKEFILES = ['rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb']
OPTIONS = [ ['--dry-run', '-n', GetoptLong::NO_ARGUMENT, "Do a dry run without executing actions."], ['--help', '-H', GetoptLong::NO_ARGUMENT, "Display this help message."], ['--libdir', '-I', GetoptLong::REQUIRED_ARGUMENT, "Include LIBDIR in the search path for required modules."], ['--rakelibdir', '-R', GetoptLong::REQUIRED_ARGUMENT, "Auto-import any .rake files in RAKELIBDIR. (default is 'rakelib')"], ['--nosearch', '-N', GetoptLong::NO_ARGUMENT, "Do not search parent directories for the Rakefile."], ['--prereqs', '-P', GetoptLong::NO_ARGUMENT, "Display the tasks and dependencies, then exit."], ['--quiet', '-q', GetoptLong::NO_ARGUMENT, "Do not log messages to standard output."], ['--rakefile', '-f', GetoptLong::OPTIONAL_ARGUMENT, "Use FILE as the rakefile."], ['--require', '-r', GetoptLong::REQUIRED_ARGUMENT, "Require MODULE before executing rakefile."], ['--silent', '-s', GetoptLong::NO_ARGUMENT, "Like --quiet, but also suppresses the 'in directory' announcement."], ['--tasks', '-T', GetoptLong::OPTIONAL_ARGUMENT, "Display the tasks (matching optional PATTERN) with descriptions, then exit."], ['--trace', '-t', GetoptLong::NO_ARGUMENT, "Turn on invoke/execute tracing, enable full backtrace."], ['--usage', '-h', GetoptLong::NO_ARGUMENT, "Display usage."], ['--verbose', '-v', GetoptLong::NO_ARGUMENT, "Log message to standard output (default)."], ['--version', '-V', GetoptLong::NO_ARGUMENT, "Display the program version."], ['--classic-namespace', '-C', GetoptLong::NO_ARGUMENT, "Put Task and FileTask in the top level namespace"], ]
Attributes
[R] original_dir The original directory where rake was invoked.
Public Class methods
new()

Create a Rake::Application object.

      # File lib/rake.rb, line 1664
1664:     def initialize
1665:       super
1666:       @rakefile = nil
1667:       @pending_imports = []
1668:       @imported = []
1669:       @loaders = {}
1670:       @default_loader = Rake::DefaultLoader.new
1671:       @original_dir = Dir.pwd
1672:       add_loader('rf', DefaultLoader.new)
1673:       add_loader('rake', DefaultLoader.new)
1674:     end
Public Instance methods
add_import(fn)

Add a file to the list of files to be imported.

      # File lib/rake.rb, line 1871
1871:     def add_import(fn)
1872:       @pending_imports << fn
1873:     end
add_loader(ext, loader)

Add a loader to handle imported files ending in the extension ext.

      # File lib/rake.rb, line 1889
1889:     def add_loader(ext, loader)
1890:       ext = ".#{ext}" unless ext =~ /^\./
1891:       @loaders[ext] = loader
1892:     end
collect_tasks()

Collect the list of tasks on the command line. If no tasks are give, return a list containing only the default task. Environmental assignments are processed at this time as well.

      # File lib/rake.rb, line 1857
1857:     def collect_tasks
1858:       tasks = []
1859:       ARGV.each do |arg|
1860:         if arg =~ /^(\w+)=(.*)$/
1861:           ENV[$1] = $2
1862:         else
1863:           tasks << arg
1864:         end
1865:       end
1866:       tasks.push("default") if tasks.size == 0
1867:       tasks
1868:     end
command_line_options()

Return a list of the command line options supported by the program.

      # File lib/rake.rb, line 1738
1738:     def command_line_options
1739:       OPTIONS.collect { |lst| lst[0..-2] }
1740:     end
const_warning(const_name)

Warn about deprecated use of top level constant names.

      # File lib/rake.rb, line 1895
1895:     def const_warning(const_name)
1896:       @const_warning ||= false
1897:       if ! @const_warning
1898:         puts %{WARNING: Deprecated reference to top-level constant '#{const_name}'} +
1899:           %{found at: #{rakefile_location}} # '
1900:         puts %{    Use --classic-namespace on rake command}
1901:         puts %{    or 'require "rake/classic_namespace"' in Rakefile}
1902:       end
1903:       @const_warning = true
1904:     end
display_prerequisites()

Display the tasks and prerequisites

      # File lib/rake.rb, line 1729
1729:     def display_prerequisites
1730:       Rake::Task.tasks.each do |t|
1731:         puts "rake #{t.name}"
1732:         t.prerequisites.each { |pre| puts "    #{pre}" }
1733:       end
1734:     end
display_tasks_and_comments()

Display the tasks and dependencies.

      # File lib/rake.rb, line 1716
1716:     def display_tasks_and_comments
1717:       displayable_tasks = Rake::Task.tasks.select { |t|
1718:         t.comment && t.name =~ options.show_task_pattern
1719:       }
1720:       width = displayable_tasks.collect { |t|
1721:         t.name.length
1722:       }.max
1723:       displayable_tasks.each do |t|
1724:         printf "rake %-#{width}s  # %s\n", t.name, t.comment
1725:       end
1726:     end
do_option(opt, value)

Do the option defined by opt and value.

      # File lib/rake.rb, line 1743
1743:     def do_option(opt, value)
1744:       case opt
1745:       when '--dry-run'
1746:         verbose(true)
1747:         nowrite(true)
1748:         options.dryrun = true
1749:         options.trace = true
1750:       when '--help'
1751:         help
1752:         exit
1753:       when '--libdir'
1754:         $:.push(value)
1755:       when '--nosearch'
1756:         options.nosearch = true
1757:       when '--prereqs'
1758:         options.show_prereqs = true
1759:       when '--quiet'
1760:         verbose(false)
1761:       when '--rakefile'
1762:         RAKEFILES.clear
1763:         RAKEFILES << value
1764:       when '--rakelibdir'
1765:         options.rakelib = value.split(':')
1766:       when '--require'
1767:         begin
1768:           require value
1769:         rescue LoadError => ex
1770:           begin
1771:             rake_require value
1772:           rescue LoadError => ex2
1773:             raise ex
1774:           end
1775:         end
1776:       when '--silent'
1777:         verbose(false)
1778:         options.silent = true
1779:       when '--tasks'
1780:         options.show_tasks = true
1781:         options.show_task_pattern = Regexp.new(value || '.')
1782:       when '--trace'
1783:         options.trace = true
1784:         verbose(true)
1785:       when '--usage'
1786:         usage
1787:         exit
1788:       when '--verbose'
1789:         verbose(true)
1790:       when '--version'
1791:         puts "rake, version #{RAKEVERSION}"
1792:         exit
1793:       when '--classic-namespace'
1794:         require 'rake/classic_namespace'
1795:         options.classic_namespace = true
1796:       else
1797:         fail "Unknown option: #{opt}"
1798:       end
1799:     end
handle_options()

Read and handle the command line options.

      # File lib/rake.rb, line 1802
1802:     def handle_options
1803:       options.rakelib = 'rakelib'
1804: 
1805:       opts = GetoptLong.new(*command_line_options)
1806:       opts.each { |opt, value| do_option(opt, value) }
1807: 
1808:       # If class namespaces are requested, set the global options
1809:       # according to the values in the options structure.
1810:       if options.classic_namespace
1811:         $show_tasks = options.show_tasks
1812:         $show_prereqs = options.show_prereqs
1813:         $trace = options.trace
1814:         $dryrun = options.dryrun
1815:         $silent = options.silent
1816:       end
1817:     end
have_rakefile()

True if one of the files in RAKEFILES is in the current directory. If a match is found, it is copied into @rakefile.

      # File lib/rake.rb, line 1683
1683:     def have_rakefile
1684:       RAKEFILES.each do |fn|
1685:         if File.exist?(fn) || fn == ''
1686:           @rakefile = fn
1687:           return true
1688:         end
1689:       end
1690:       return false
1691:     end
help()

Display the rake command line help.

      # File lib/rake.rb, line 1699
1699:     def help
1700:       usage
1701:       puts
1702:       puts "Options are ..."
1703:       puts
1704:       OPTIONS.sort.each do |long, short, mode, desc|
1705:         if mode == GetoptLong::REQUIRED_ARGUMENT
1706:           if desc =~ /\b([A-Z]{2,})\b/
1707:             long = long + "=#{$1}"
1708:           end
1709:         end
1710:         printf "  %-20s (%s)\n", long, short
1711:         printf "      %s\n", desc
1712:       end
1713:     end
load_imports()

Load the pending list of imported files.

      # File lib/rake.rb, line 1876
1876:     def load_imports
1877:       while fn = @pending_imports.shift
1878:         next if @imported.member?(fn)
1879:         Rake::Task[fn].invoke if Rake::Task.task_defined?(fn)
1880:         ext = File.extname(fn)
1881:         loader = @loaders[ext] || @default_loader
1882:         loader.load(fn)
1883:         @imported << fn
1884:       end
1885:     end
load_rakefile()

Find the rakefile and then load it and any pending imports.

      # File lib/rake.rb, line 1836
1836:     def load_rakefile
1837:       here = Dir.pwd
1838:       while ! have_rakefile
1839:         Dir.chdir("..")
1840:         if Dir.pwd == here || options.nosearch
1841:           fail "No Rakefile found (looking for: #{RAKEFILES.join(', ')})"
1842:         end
1843:         here = Dir.pwd
1844:       end
1845:       puts "(in #{Dir.pwd})" unless options.silent
1846:       $rakefile = @rakefile
1847:       load File.expand_path(@rakefile) if @rakefile != ''
1848:       options.rakelib.each do |rlib|
1849:         Dir["#{rlib}/*.rake"].each do |name| add_import name end
1850:       end
1851:       load_imports
1852:     end
options()

Application options from the command line

      # File lib/rake.rb, line 1677
1677:     def options
1678:       @options ||= OpenStruct.new
1679:     end
rake_require(file_name, paths=$LOAD_PATH, loaded=$")

Similar to the regular Ruby require command, but will check for .rake files in addition to .rb files.

      # File lib/rake.rb, line 1821
1821:     def rake_require(file_name, paths=$LOAD_PATH, loaded=$")
1822:       return false if loaded.include?(file_name)
1823:       paths.each do |path|
1824:         fn = file_name + ".rake"
1825:         full_path = File.join(path, fn)
1826:         if File.exist?(full_path)
1827:           load full_path
1828:           loaded << fn
1829:           return true
1830:         end
1831:       end
1832:       fail LoadError, "Can't find #{file_name}"
1833:     end
rakefile_location()
      # File lib/rake.rb, line 1906
1906:     def rakefile_location
1907:       begin
1908:         fail
1909:       rescue RuntimeError => ex
1910:         ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
1911:       end
1912:     end
run()

Run the rake application.

      # File lib/rake.rb, line 1915
1915:     def run
1916:       handle_options
1917:       begin
1918:         tasks = collect_tasks
1919:         load_rakefile
1920:         if options.show_tasks
1921:           display_tasks_and_comments
1922:         elsif options.show_prereqs
1923:           display_prerequisites
1924:         else
1925:           tasks.each { |task_name| Rake::Task[task_name].invoke }
1926:         end
1927:       rescue Exception => ex
1928:         puts "rake aborted!"
1929:         puts ex.message
1930:         if options.trace
1931:           puts ex.backtrace.join("\n")
1932:         else
1933:           puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
1934:           puts "(See full trace by running task with --trace)"
1935:         end
1936:         exit(1)
1937:       end    
1938:     end
usage()

Display the program usage line.

      # File lib/rake.rb, line 1694
1694:     def usage
1695:       puts "rake [-f rakefile] {options} targets..."
1696:     end