lib/core/application.rb in buildr-1.2.4 vs lib/core/application.rb in buildr-1.2.5
- old
+ new
@@ -1,11 +1,14 @@
module Buildr
# When running from +rake+, we already have an Application setup and must plug into it,
# since the top-level tasks come from there. When running from +buildr+, we get to load
# Rake and set everything up, and we use our own Application full of cool Buildr features.
- unless defined?(Rake)
+ if defined?(Rake)
+ Rake.application.top_level_tasks.unshift task("buildr:initialize")
+ else
+
require "rake"
class Application < Rake::Application #:nodoc:
DEFAULT_BUILDFILES = ["buildfile", "Buildfile"] + DEFAULT_RAKEFILES
@@ -39,10 +42,11 @@
@name = "Buildr"
@requires = []
opts = GetoptLong.new(*command_line_options)
opts.each { |opt, value| do_option(opt, value) }
collect_tasks
+ top_level_tasks.unshift "buildr:initialize"
end
def run()
standard_exception_handling do
find_buildfile
@@ -63,11 +67,10 @@
puts "Buildr, version #{Buildr::VERSION}"
exit
when "--freeze"
find_buildfile
puts "Freezing the Buildfile so it always uses Buildr version #{Buildr::VERSION}"
- gem =
original = File.read(rakefile)
if original =~ /gem\s*(["'])buildr\1/
modified = original.sub(/gem\s*(["'])buildr\1\s*,\s*(["']).*\2/, %{gem "buildr", "#{Buildr::VERSION}"})
else
modified = %{gem "buildr", "#{Buildr::VERSION}"\n} + original
@@ -86,24 +89,23 @@
super
end
end
def find_buildfile()
- unless have_rakefile
- here = Dir.pwd
- Dir.chdir("..") do
- if Dir.pwd == here || options.nosearch
- error = "No Buildfile found (looking for: #{@rakefiles.join(', ')})"
- if STDIN.isatty
- chdir(original_dir) { task("generate").invoke }
- exit 1
- else
- raise error
- end
+ here = Dir.pwd
+ while ! have_rakefile
+ Dir.chdir("..")
+ if Dir.pwd == here || options.nosearch
+ error = "No Buildfile found (looking for: #{@rakefiles.join(', ')})"
+ if STDIN.isatty
+ chdir(original_dir) { task("generate").invoke }
+ exit 1
+ else
+ raise error
end
- find_buildfile
end
+ here = Dir.pwd
end
end
def load_buildfile()
@requires.each { |name| require name }
@@ -141,11 +143,10 @@
OPTIONS.collect { |lst| lst[0..-2] }
end
end
Rake.application = Buildr::Application.new
-
end
class << self
@@ -174,7 +175,12 @@
# Returns a list of build files. These are files used by the build,
def build_files()
[Rake.application.rakefile].compact + @build_files
end
+ task "buildr:initialize" do
+ Buildr.load_tasks_and_local_files
+ end
+
end
+
end