In Files

Parent

Included Modules

Rake::Application

                                                                    

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

Constants

DEFAULT_RAKEFILES

Attributes

name[R]

The name of the application (typically ‘rake’)

original_dir[R]

The original directory where rake was invoked.

rakefile[R]

Name of the actual rakefile used.

top_level_tasks[R]

List of the top level task names (task names from the command line).

Public Class Methods

new() click to toggle source

Initialize a Rake::Application object.

      # File lib/rake.rb, line 1971
1971:     def initialize
1972:       super
1973:       @name = 'rake'
1974:       @rakefiles = DEFAULT_RAKEFILES.dup
1975:       @rakefile = nil
1976:       @pending_imports = []
1977:       @imported = []
1978:       @loaders = {}
1979:       @default_loader = Rake::DefaultLoader.new
1980:       @original_dir = Dir.pwd
1981:       @top_level_tasks = []
1982:       add_loader('rb', DefaultLoader.new)
1983:       add_loader('rf', DefaultLoader.new)
1984:       add_loader('rake', DefaultLoader.new)
1985:       @tty_output = STDOUT.tty?
1986:     end

Public Instance Methods

add_import(fn) click to toggle source

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

      # File lib/rake.rb, line 2438
2438:     def add_import(fn)
2439:       @pending_imports << fn
2440:     end
add_loader(ext, loader) click to toggle source

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

      # File lib/rake.rb, line 2036
2036:     def add_loader(ext, loader)
2037:       ext = ".#{ext}" unless ext =~ /^\./
2038:       @loaders[ext] = loader
2039:     end
collect_tasks() click to toggle source

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

      # File lib/rake.rb, line 2425
2425:     def collect_tasks
2426:       @top_level_tasks = []
2427:       ARGV.each do |arg|
2428:         if arg =~ /^(\w+)=(.*)$/
2429:           ENV[$1] = $2
2430:         else
2431:           @top_level_tasks << arg unless arg =~ /^-/
2432:         end
2433:       end
2434:       @top_level_tasks.push("default") if @top_level_tasks.size == 0
2435:     end
const_warning(const_name) click to toggle source

Warn about deprecated use of top level constant names.

      # File lib/rake.rb, line 2457
2457:     def const_warning(const_name)
2458:       @const_warning ||= false
2459:       if ! @const_warning
2460:         $stderr.puts %{WARNING: Deprecated reference to top-level constant '#{const_name}' } +
2461:           %{found at: #{rakefile_location}} # '
2462:         $stderr.puts %{    Use --classic-namespace on rake command}
2463:         $stderr.puts %{    or 'require "rake/classic_namespace"' in Rakefile}
2464:       end
2465:       @const_warning = true
2466:     end
display_prerequisites() click to toggle source

Display the tasks and prerequisites

      # File lib/rake.rb, line 2183
2183:     def display_prerequisites
2184:       tasks.each do |t|
2185:         puts "#{name} #{t.name}"
2186:         t.prerequisites.each { |pre| puts "    #{pre}" }
2187:       end
2188:     end
display_tasks_and_comments() click to toggle source

Display the tasks and comments.

      # File lib/rake.rb, line 2120
2120:     def display_tasks_and_comments
2121:       displayable_tasks = tasks.select { |t|
2122:         t.comment && t.name =~ options.show_task_pattern
2123:       }
2124:       if options.full_description
2125:         displayable_tasks.each do |t|
2126:           puts "#{name} #{t.name_with_args}"
2127:           t.full_comment.split("\n").each do |line|
2128:             puts "    #{line}"
2129:           end
2130:           puts
2131:         end
2132:       else
2133:         width = displayable_tasks.collect { |t| t.name_with_args.length }.max || 10
2134:         max_column = truncate_output? ? terminal_width - name.size - width - 7 : nil
2135:         displayable_tasks.each do |t|
2136:           printf "#{name} %-#{width}s  # %s\n",
2137:             t.name_with_args, max_column ? truncate(t.comment, max_column) : t.comment
2138:         end
2139:       end
2140:     end
dynamic_width() click to toggle source

Calculate the dynamic width of the

      # File lib/rake.rb, line 2154
2154:     def dynamic_width
2155:       @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
2156:     end
dynamic_width_stty() click to toggle source
      # File lib/rake.rb, line 2158
2158:     def dynamic_width_stty
2159:       %{stty size 2>/dev/null}.split[1].to_i
2160:     end
dynamic_width_tput() click to toggle source
      # File lib/rake.rb, line 2162
2162:     def dynamic_width_tput
2163:       %{tput cols 2>/dev/null}.to_i
2164:     end
find_rakefile_location() click to toggle source
      # File lib/rake.rb, line 2353
2353:     def find_rakefile_location
2354:       here = Dir.pwd
2355:       while ! (fn = have_rakefile)
2356:         Dir.chdir("..")
2357:         if Dir.pwd == here || options.nosearch
2358:           return nil
2359:         end
2360:         here = Dir.pwd
2361:       end
2362:       [fn, here]
2363:     ensure
2364:       Dir.chdir(Rake.original_dir)
2365:     end
handle_options() click to toggle source

Read and handle the command line options.

      # File lib/rake.rb, line 2310
2310:     def handle_options
2311:       options.rakelib = ['rakelib']
2312: 
2313:       OptionParser.new do |opts|
2314:         opts.banner = "rake [-f rakefile] {options} targets..."
2315:         opts.separator ""
2316:         opts.separator "Options are ..."
2317: 
2318:         opts.on_tail("-h", "--help", "-H", "Display this help message.") do
2319:           puts opts
2320:           exit
2321:         end
2322: 
2323:         standard_rake_options.each { |args| opts.on(*args) }
2324:       end.parse!
2325: 
2326:       # If class namespaces are requested, set the global options
2327:       # according to the values in the options structure.
2328:       if options.classic_namespace
2329:         $show_tasks = options.show_tasks
2330:         $show_prereqs = options.show_prereqs
2331:         $trace = options.trace
2332:         $dryrun = options.dryrun
2333:         $silent = options.silent
2334:       end
2335:     end
have_rakefile() click to toggle source

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 2091
2091:     def have_rakefile
2092:       @rakefiles.each do |fn|
2093:         if File.exist?(fn)
2094:           others = Dir.glob(fn, File::FNM_CASEFOLD)
2095:           return others.size == 1 ? others.first : fn
2096:         elsif fn == ''
2097:           return fn
2098:         end
2099:       end
2100:       return nil
2101:     end
init(app_name='rake') click to toggle source

Initialize the command line parameters and app name.

      # File lib/rake.rb, line 2006
2006:     def init(app_name='rake')
2007:       standard_exception_handling do
2008:         @name = app_name
2009:         handle_options
2010:         collect_tasks
2011:       end
2012:     end
invoke_task(task_string) click to toggle source

private —————————————————————-

      # File lib/rake.rb, line 2048
2048:     def invoke_task(task_string)
2049:       name, args = parse_task_string(task_string)
2050:       t = self[name]
2051:       t.invoke(*args)
2052:     end
load_imports() click to toggle source

Load the pending list of imported files.

      # File lib/rake.rb, line 2443
2443:     def load_imports
2444:       while fn = @pending_imports.shift
2445:         next if @imported.member?(fn)
2446:         if fn_task = lookup(fn)
2447:           fn_task.invoke
2448:         end
2449:         ext = File.extname(fn)
2450:         loader = @loaders[ext] || @default_loader
2451:         loader.load(fn)
2452:         @imported << fn
2453:       end
2454:     end
load_rakefile() click to toggle source

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

      # File lib/rake.rb, line 2015
2015:     def load_rakefile
2016:       standard_exception_handling do
2017:         raw_load_rakefile
2018:       end
2019:     end
options() click to toggle source

Application options from the command line

      # File lib/rake.rb, line 2042
2042:     def options
2043:       @options ||= OpenStruct.new
2044:     end
parse_task_string(string) click to toggle source
      # File lib/rake.rb, line 2054
2054:     def parse_task_string(string)
2055:       if string =~ /^([^\[]+)(\[(.*)\])$/
2056:         name = $1
2057:         args = $3.split(/\s*,\s*/)
2058:       else
2059:         name = string
2060:         args = []
2061:       end
2062:       [name, args]
2063:     end
rake_require(file_name, paths=$LOAD_PATH, loaded=$") click to toggle source

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

      # File lib/rake.rb, line 2339
2339:     def rake_require(file_name, paths=$LOAD_PATH, loaded=$")
2340:       return false if loaded.include?(file_name)
2341:       paths.each do |path|
2342:         fn = file_name + ".rake"
2343:         full_path = File.join(path, fn)
2344:         if File.exist?(full_path)
2345:           load full_path
2346:           loaded << fn
2347:           return true
2348:         end
2349:       end
2350:       fail LoadError, "Can't find #{file_name}"
2351:     end
rakefile_location() click to toggle source
      # File lib/rake.rb, line 2468
2468:     def rakefile_location
2469:       begin
2470:         fail
2471:       rescue RuntimeError => ex
2472:         ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
2473:       end
2474:     end
run() click to toggle source

Run the Rake application. The run method performs the following three steps:

  • Initialize the command line options (init).

  • Define the tasks (load_rakefile).

  • Run the top level tasks (run_tasks).

If you wish to build a custom rake command, you should call init on your application. The define any tasks. Finally, call top_level to run your top level tasks.

      # File lib/rake.rb, line 1997
1997:     def run
1998:       standard_exception_handling do
1999:         init
2000:         load_rakefile
2001:         top_level
2002:       end
2003:     end
standard_exception_handling() click to toggle source

Provide standard execption handling for the given block.

      # File lib/rake.rb, line 2066
2066:     def standard_exception_handling
2067:       begin
2068:         yield
2069:       rescue SystemExit => ex
2070:         # Exit silently with current status
2071:         raise
2072:       rescue OptionParser::InvalidOption => ex
2073:         # Exit silently
2074:         exit(false)
2075:       rescue Exception => ex
2076:         # Exit with error message
2077:         $stderr.puts "#{name} aborted!"
2078:         $stderr.puts ex.message
2079:         if options.trace
2080:           $stderr.puts ex.backtrace.join("\n")
2081:         else
2082:           $stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
2083:           $stderr.puts "(See full trace by running task with --trace)"
2084:         end
2085:         exit(false)
2086:       end
2087:     end
standard_rake_options() click to toggle source

A list of all the standard options used in rake, suitable for passing to OptionParser.

      # File lib/rake.rb, line 2192
2192:     def standard_rake_options
2193:       [
2194:         ['--classic-namespace', '-C', "Put Task and FileTask in the top level namespace",
2195:           lambda { |value|
2196:             require 'rake/classic_namespace'
2197:             options.classic_namespace = true
2198:           }
2199:         ],
2200:         ['--describe', '-D [PATTERN]', "Describe the tasks (matching optional PATTERN), then exit.",
2201:           lambda { |value|
2202:             options.show_tasks = true
2203:             options.full_description = true
2204:             options.show_task_pattern = Regexp.new(value || '')
2205:           }
2206:         ],
2207:         ['--dry-run', '-n', "Do a dry run without executing actions.",
2208:           lambda { |value|
2209:             verbose(true)
2210:             nowrite(true)
2211:             options.dryrun = true
2212:             options.trace = true
2213:           }
2214:         ],
2215:         ['--execute',  '-e CODE', "Execute some Ruby code and exit.",
2216:           lambda { |value|
2217:             eval(value)
2218:             exit
2219:           }
2220:         ],
2221:         ['--execute-print',  '-p CODE', "Execute some Ruby code, print the result, then exit.",
2222:           lambda { |value|
2223:             puts eval(value)
2224:             exit
2225:           }
2226:         ],
2227:         ['--execute-continue',  '-E CODE',
2228:           "Execute some Ruby code, then continue with normal task processing.",
2229:           lambda { |value| eval(value) }            
2230:         ],
2231:         ['--libdir', '-I LIBDIR', "Include LIBDIR in the search path for required modules.",
2232:           lambda { |value| $:.push(value) }
2233:         ],
2234:         ['--prereqs', '-P', "Display the tasks and dependencies, then exit.",
2235:           lambda { |value| options.show_prereqs = true }
2236:         ],
2237:         ['--quiet', '-q', "Do not log messages to standard output.",
2238:           lambda { |value| verbose(false) }
2239:         ],
2240:         ['--rakefile', '-f [FILE]', "Use FILE as the rakefile.",
2241:           lambda { |value| 
2242:             value ||= ''
2243:             @rakefiles.clear 
2244:             @rakefiles << value
2245:           }
2246:         ],
2247:         ['--rakelibdir', '--rakelib', '-R RAKELIBDIR',
2248:           "Auto-import any .rake files in RAKELIBDIR. (default is 'rakelib')",
2249:           lambda { |value| options.rakelib = value.split(':') }
2250:         ],
2251:         ['--require', '-r MODULE', "Require MODULE before executing rakefile.",
2252:           lambda { |value|
2253:             begin
2254:               require value
2255:             rescue LoadError => ex
2256:               begin
2257:                 rake_require value
2258:               rescue LoadError => ex2
2259:                 raise ex
2260:               end
2261:             end
2262:           }
2263:         ],
2264:         ['--rules', "Trace the rules resolution.",
2265:           lambda { |value| options.trace_rules = true }
2266:         ],
2267:         ['--no-search', '--nosearch', '-N', "Do not search parent directories for the Rakefile.",
2268:           lambda { |value| options.nosearch = true }
2269:         ],
2270:         ['--silent', '-s', "Like --quiet, but also suppresses the 'in directory' announcement.",
2271:           lambda { |value|
2272:             verbose(false)
2273:             options.silent = true
2274:           }
2275:         ],
2276:         ['--system',  '-g',
2277:           "Using system wide (global) rakefiles (usually '~/.rake/*.rake').",
2278:           lambda { |value| options.load_system = true }
2279:         ],
2280:         ['--no-system', '--nosystem', '-G',
2281:           "Use standard project Rakefile search paths, ignore system wide rakefiles.",
2282:           lambda { |value| options.ignore_system = true }
2283:         ],
2284:         ['--tasks', '-T [PATTERN]', "Display the tasks (matching optional PATTERN) with descriptions, then exit.",
2285:           lambda { |value|
2286:             options.show_tasks = true
2287:             options.show_task_pattern = Regexp.new(value || '')
2288:             options.full_description = false
2289:           }
2290:         ],
2291:         ['--trace', '-t', "Turn on invoke/execute tracing, enable full backtrace.",
2292:           lambda { |value|
2293:             options.trace = true
2294:             verbose(true)
2295:           }
2296:         ],
2297:         ['--verbose', '-v', "Log message to standard output.",
2298:           lambda { |value| verbose(true) }
2299:         ],
2300:         ['--version', '-V', "Display the program version.",
2301:           lambda { |value|
2302:             puts "rake, version #{RAKEVERSION}"
2303:             exit
2304:           }
2305:         ]
2306:       ]
2307:     end
system_dir() click to toggle source

The directory path containing the system wide rakefiles.

      # File lib/rake.rb, line 2399
2399:     def system_dir
2400:       @system_dir ||=
2401:         begin
2402:           if ENV['RAKE_SYSTEM']
2403:             ENV['RAKE_SYSTEM']
2404:           else
2405:             standard_system_dir
2406:           end
2407:         end
2408:     end
terminal_width() click to toggle source
      # File lib/rake.rb, line 2142
2142:     def terminal_width
2143:       if ENV['RAKE_COLUMNS']
2144:         result = ENV['RAKE_COLUMNS'].to_i
2145:       else
2146:         result = unix? ? dynamic_width : 80
2147:       end
2148:       (result < 10) ? 80 : result
2149:     rescue
2150:       80
2151:     end
top_level() click to toggle source

Run the top level tasks of a Rake application.

      # File lib/rake.rb, line 2022
2022:     def top_level
2023:       standard_exception_handling do
2024:         if options.show_tasks
2025:           display_tasks_and_comments
2026:         elsif options.show_prereqs
2027:           display_prerequisites
2028:         else
2029:           top_level_tasks.each { |task_name| invoke_task(task_name) }
2030:         end
2031:       end
2032:     end
truncate(string, width) click to toggle source
      # File lib/rake.rb, line 2174
2174:     def truncate(string, width)
2175:       if string.length <= width
2176:         string
2177:       else
2178:         ( string[0, width-3] || "" ) + "..."
2179:       end
2180:     end
truncate_output?() click to toggle source

We will truncate output if we are outputting to a TTY or if we’ve been given an explicit column width to honor

      # File lib/rake.rb, line 2115
2115:     def truncate_output?
2116:       tty_output? || ENV['RAKE_COLUMNS']
2117:     end
tty_output=( tty_output_state ) click to toggle source

Override the detected TTY output state (mostly for testing)

      # File lib/rake.rb, line 2109
2109:     def tty_output=( tty_output_state )
2110:       @tty_output = tty_output_state
2111:     end
tty_output?() click to toggle source

True if we are outputting to TTY, false otherwise

      # File lib/rake.rb, line 2104
2104:     def tty_output?
2105:       @tty_output
2106:     end
unix?() click to toggle source
      # File lib/rake.rb, line 2166
2166:     def unix?
2167:       RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/
2168:     end
windows?() click to toggle source
      # File lib/rake.rb, line 2170
2170:     def windows?
2171:       Win32.windows?
2172:     end

Private Instance Methods

glob(path, &block) click to toggle source
      # File lib/rake.rb, line 2393
2393:     def glob(path, &block)
2394:       Dir[path.gsub("\\", '/')].each(&block)
2395:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.