<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,7 @@
 1.3.4 (Pending)
 * Change: Upgraded to use Rake 0.8.3, RSpec 1.1.8.
+* Change: Introduced new options from Rake 0.8.3: -I (libdir), -R (rakelib),
+          --rules, --no-search, --silent.
 * Fixed:  BUILDR-172 Scala compiler not loaded by default.
 * Fixed:  Removed double complete/fail messages showing up on console.
 </diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -19,7 +19,6 @@
 # For example to use jruby:
 #   export _BUILDR_RB=/path/to/jruby
 
-start = Time.now
 require 'rubygems'
 $LOAD_PATH &lt;&lt; File.join(File.dirname(__FILE__), 'lib') &lt;&lt; File.join(File.dirname(__FILE__), 'addon')
 spec = Gem::Specification.load(File.join(File.dirname(__FILE__), 'buildr.gemspec'))
@@ -28,11 +27,3 @@ spec.dependencies.each do |dep|
 end
 require 'buildr'
 Buildr.application.run
-if verbose
-  elapsed = Time.now - start
-  real = []
-  real &lt;&lt; (&quot;%ih&quot; % (elapsed / 3600)) if elapsed &gt;= 3600
-  real &lt;&lt; (&quot;%im&quot; % ((elapsed / 60) % 60)) if elapsed &gt;= 60
-  real &lt;&lt; (&quot;%.3fs&quot; % (elapsed % 60))
-  puts $terminal.color(&quot;Completed in #{real.join}&quot;, :green)
-end</diff>
      <filename>_buildr</filename>
    </modified>
    <modified>
      <diff>@@ -14,15 +14,6 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-start = Time.now
 require 'rubygems'
 require 'buildr'
 Buildr.application.run
-if verbose
-  elapsed = Time.now - start
-  real = []
-  real &lt;&lt; (&quot;%ih&quot; % (elapsed / 3600)) if elapsed &gt;= 3600
-  real &lt;&lt; (&quot;%im&quot; % ((elapsed / 60) % 60)) if elapsed &gt;= 60
-  real &lt;&lt; (&quot;%.3fs&quot; % (elapsed % 60))
-  puts $terminal.color(&quot;Completed in #{real.join}&quot;, :green)
-end</diff>
      <filename>bin/buildr</filename>
    </modified>
    <modified>
      <diff>@@ -13,6 +13,7 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+
 # Portion of this file derived from Rake.
 # Copyright (c) 2003, 2004 Jim Weirich
 #
@@ -35,15 +36,14 @@
 # SOFTWARE.
 
 
-require 'highline/import'
 require 'rake'
+require 'highline/import'
 require 'rubygems/source_info_cache'
-require 'buildr/core/application_cli'
 require 'buildr/core/util'
 
 
 # Gem::user_home is nice, but ENV['HOME'] lets you override from the environment.
-ENV[&quot;HOME&quot;] ||= File.expand_path(Gem::user_home)
+ENV['HOME'] ||= File.expand_path(Gem::user_home)
 ENV['BUILDR_ENV'] ||= 'development'
 
 
@@ -107,28 +107,42 @@ module Buildr
 
   class Application &lt; Rake::Application #:nodoc:
 
+    # Deprecated: rakefile/Rakefile, removed in 1.5
     DEFAULT_BUILDFILES = ['buildfile', 'Buildfile'] + DEFAULT_RAKEFILES
     
-    include CommandLineInterface
+    #include CommandLineInterface
 
     attr_reader :rakefiles, :requires
     private :rakefiles, :requires
 
     def initialize
       super
-      @rakefiles = DEFAULT_BUILDFILES
-      @name = 'Buildr'
-      @requires = []
+      @rakefiles = DEFAULT_BUILDFILES.dup
       @top_level_tasks = []
-      parse_options
-      collect_tasks
       @home_dir = File.expand_path('.buildr', ENV['HOME'])
       mkpath @home_dir, :verbose=&gt;false unless File.exist?(@home_dir)
-      @environment = ENV['BUILDR_ENV'] ||= 'development'
       @on_completion = []
       @on_failure = []
     end
 
+    def run
+      standard_exception_handling do
+        init 'Buildr'
+        load_buildfile
+        top_level
+      end
+    end
+
+    # Not for external consumption.
+    def switch_to_namespace(names) #:nodoc:
+      current, @scope = @scope, names
+      begin
+        yield
+      ensure
+        @scope = current
+      end
+    end
+
     # Returns list of Gems associated with this buildfile, as listed in build.yaml.
     # Each entry is of type Gem::Specification.
     attr_reader :gems
@@ -151,28 +165,13 @@ module Buildr
     def buildfile
       @buildfile_task ||= BuildfileTask.define_task(File.expand_path(rakefile))
     end
-    
+
     # Files that complement the buildfile itself
     def build_files #:nodoc:
+      deprecated 'Please call buildfile.prerequisites instead' 
       buildfile.prerequisites
     end
 
-    def run
-      standard_exception_handling do
-        find_buildfile
-        load_gems
-        load_artifacts
-        load_tasks
-        load_requires
-        load_buildfile
-        load_imports
-        task('buildr:initialize').invoke
-        top_level
-      end
-      title, message = 'Your build has completed', &quot;#{Dir.pwd}\nbuildr #{@top_level_tasks.join(' ')}&quot;
-      @on_completion.each { |block| block.call(title, message) rescue nil }
-    end
-
     # Yields to block on successful completion. Primarily used for notifications.
     def on_completion(&amp;block)
       @on_completion &lt;&lt; block
@@ -183,16 +182,6 @@ module Buildr
       @on_failure &lt;&lt; block
     end
 
-    # Not for external consumption.
-    def switch_to_namespace(names) #:nodoc:
-      current, @scope = @scope, names
-      begin
-        yield
-      ensure
-        @scope = current
-      end
-    end
-
     # :call-seq:
     #   deprecated(message)
     #
@@ -213,30 +202,172 @@ module Buildr
       end
     end
 
-  private
-
-    # Returns Gem::Specification for every listed and installed Gem, Gem::Dependency
-    # for listed and uninstalled Gem, which is the installed before loading the buildfile.
-    def listed_gems #:nodoc:
-      Array(settings.build['gems']).map do |dep|
-        name, trail = dep.scan(/^\s*(\S*)\s*(.*)\s*$/).first
-        versions = trail.scan(/[=&gt;&lt;~!]{0,2}\s*[\d\.]+/)
-        versions = ['&gt;= 0'] if versions.empty?
-        dep = Gem::Dependency.new(name, versions)
-        Gem::SourceIndex.from_installed_gems.search(dep).last || dep
+  protected
+    
+    def load_buildfile # replaces load_rakefile
+      standard_exception_handling do
+        find_buildfile
+        load_gems
+        load_artifact_ns
+        load_tasks
+        raw_load_buildfile
       end
     end
 
-    # Load artifact specs from the build.yaml file, making them available 
-    # by name ( ruby symbols ).
-    def load_artifacts #:nodoc:
-      hash = settings.build['artifacts']
-      return unless hash
-      raise &quot;Expected 'artifacts' element to be a hash&quot; unless Hash === hash
-      # Currently we only use one artifact namespace to rule them all. (the root NS)
-      Buildr::ArtifactNamespace.load(:root =&gt; hash)
+    def top_level # adds on_completion hook
+      standard_exception_handling do
+        if options.show_tasks
+          display_tasks_and_comments
+        elsif options.show_prereqs
+          display_prerequisites
+        elsif options.execute
+          eval options.execute
+        else
+          @start = Time.now
+          top_level_tasks.each { |task_name| invoke_task(task_name) }
+          title, message = &quot;Your build has completed&quot;, &quot;#{Dir.pwd}\nbuildr #{@top_level_tasks.join(' ')}&quot;
+          @on_completion.each do |block|
+            block.call(title, message) rescue nil
+          end
+          if verbose
+            elapsed = Time.now - @start
+            real = []
+            real &lt;&lt; ('%ih' % (elapsed / 3600)) if elapsed &gt;= 3600
+            real &lt;&lt; ('%im' % ((elapsed / 60) % 60)) if elapsed &gt;= 60
+            real &lt;&lt; ('%.3fs' % (elapsed % 60))
+            puts $terminal.color(&quot;Completed in #{real.join}&quot;, :green)
+          end
+        end
+      end
     end
+
+    def handle_options
+      options.rakelib = ['tasks']
+
+      opts = OptionParser.new
+      opts.banner = &quot;buildr [-f rakefile] {options} targets...&quot;
+      opts.separator &quot;&quot;
+      opts.separator &quot;Options are ...&quot;
       
+      opts.on_tail(&quot;-h&quot;, &quot;--help&quot;, &quot;-H&quot;, &quot;Display this help message.&quot;) do
+        puts opts
+        exit
+      end
+      
+      standard_buildr_options.each { |args| opts.on(*args) }
+      parsed_argv = opts.parse(ARGV)
+      @environment = ENV['BUILDR_ENV'] ||= 'development'
+      parsed_argv
+    end
+
+    def standard_buildr_options # replaces standard_rake_options
+      [
+        ['--describe', '-D [PATTERN]', &quot;Describe the tasks (matching optional PATTERN), then exit.&quot;,
+          lambda { |value|
+            options.show_tasks = true
+            options.full_description = true
+            options.show_task_pattern = Regexp.new(value || '')
+          }
+        ],
+        ['--execute',  '-E CODE',
+          &quot;Execute some Ruby code after loading the buildfile&quot;,
+          lambda { |value| options.execute = value }            
+        ],
+        ['--environment',  '-e ENV',
+          &quot;Environment name (e.g. development, test, production).&quot;,
+          lambda { |value| ENV['BUILDR_ENV'] = value }            
+        ],
+        ['--libdir', '-I LIBDIR', &quot;Include LIBDIR in the search path for required modules.&quot;,
+          lambda { |value| $:.push(value) }
+        ],
+        ['--prereqs', '-P [PATTERN]', &quot;Display the tasks and dependencies (matching optional PATTERN), then exit.&quot;,
+          lambda { |value|
+            options.show_prereqs = true
+            options.show_task_pattern = Regexp.new(value || '')
+          }
+        ],
+        ['--quiet', '-q', &quot;Do not log messages to standard output.&quot;,
+          lambda { |value| verbose(false) }
+        ],
+        ['--buildfile', '-f FILE', &quot;Use FILE as the buildfile.&quot;,
+          lambda { |value| 
+            @rakefiles.clear 
+            @rakefiles &lt;&lt; value
+          }
+        ],
+        ['--rakelibdir', '--rakelib', '-R PATH',
+          &quot;Auto-import any .rake files in PATH. (default is 'tasks')&quot;,
+          lambda { |value| options.rakelib = value.split(':') }
+        ],
+        ['--require', '-r MODULE', &quot;Require MODULE before executing rakefile.&quot;,
+          lambda { |value|
+            begin
+              require value
+            rescue LoadError =&gt; ex
+              begin
+                rake_require value
+              rescue LoadError =&gt; ex2
+                raise ex
+              end
+            end
+          }
+        ],
+        ['--rules', &quot;Trace the rules resolution.&quot;,
+          lambda { |value| options.trace_rules = true }
+        ],
+        ['--no-search', '--nosearch', '-N', &quot;Do not search parent directories for the Rakefile.&quot;,
+          lambda { |value| options.nosearch = true }
+        ],
+        ['--silent', '-s', &quot;Like --quiet, but also suppresses the 'in directory' announcement.&quot;,
+          lambda { |value|
+            verbose(false)
+            options.silent = true
+          }
+        ],
+        ['--tasks', '-T [PATTERN]', &quot;Display the tasks (matching optional PATTERN) with descriptions, then exit.&quot;,
+          lambda { |value|
+            options.show_tasks = true
+            options.show_task_pattern = Regexp.new(value || '')
+            options.full_description = false
+          }
+        ],
+        ['--trace', '-t', &quot;Turn on invoke/execute tracing, enable full backtrace.&quot;,
+          lambda { |value|
+            options.trace = true
+            verbose(true)
+          }
+        ],
+        ['--verbose', '-v', &quot;Log message to standard output (default).&quot;,
+          lambda { |value| verbose(true) }
+        ],
+        ['--version', '-V', &quot;Display the program version.&quot;,
+          lambda { |value|
+            puts &quot;Buildr #{Buildr::VERSION} #{RUBY_PLATFORM[/java/] &amp;&amp; '(JRuby '+JRUBY_VERSION+')'}&quot;
+            exit
+          }
+        ]
+      ]
+    end
+
+    def find_buildfile
+      buildfile, location = find_rakefile_location
+      fail &quot;No Buildfile found (looking for: #{@rakefiles.join(', ')})&quot; if buildfile.nil?
+      @rakefile = buildfile
+      Dir.chdir(location)
+    end
+
+    def raw_load_buildfile # replaces raw_load_rakefile
+      puts &quot;(in #{Dir.pwd}, #{environment})&quot; unless options.silent
+      load File.expand_path(@rakefile) if @rakefile &amp;&amp; @rakefile != ''
+      options.rakelib.each do |rlib|
+        glob(&quot;#{rlib}/*.rake&quot;) do |name|
+          add_import name
+        end
+      end
+      load_imports
+      Buildr.projects
+    end
+
     # Load/install all Gems specified in build.yaml file.
     def load_gems #:nodoc:
       missing_deps, installed = listed_gems.partition { |gem| gem.is_a?(Gem::Dependency) }
@@ -259,37 +390,32 @@ module Buildr
       @gems = installed
     end
 
-    def find_buildfile #:nodoc:
-      here = original_dir
-      Dir.chdir(here) unless Dir.pwd == here
-      while !(@rakefile = have_rakefile)
-        Dir.chdir('..')
-        if Dir.pwd == here || options.nosearch
-          error = &quot;No Buildfile found (looking for: #{@rakefiles.join(', ')})&quot;
-          if STDIN.isatty
-            chdir(original_dir) { task('generate').invoke }
-            exit 1
-          else
-            raise error
-          end
-        end
-        here = Dir.pwd
+    # Returns Gem::Specification for every listed and installed Gem, Gem::Dependency
+    # for listed and uninstalled Gem, which is the installed before loading the buildfile.
+    def listed_gems #:nodoc:
+      Array(settings.build['gems']).map do |dep|
+        name, trail = dep.scan(/^\s*(\S*)\s*(.*)\s*$/).first
+        versions = trail.scan(/[=&gt;&lt;~!]{0,2}\s*[\d\.]+/)
+        versions = ['&gt;= 0'] if versions.empty?
+        dep = Gem::Dependency.new(name, versions)
+        Gem::SourceIndex.from_installed_gems.search(dep).last || dep
       end
     end
 
-    def load_buildfile #:nodoc:
-      info &quot;(in #{Dir.pwd}, #{environment})&quot;
-      load File.expand_path(@rakefile) if @rakefile != ''
-      buildfile.enhance @requires.select { |f| File.file?(f) }.map{ |f| File.expand_path(f) }
-    end
-
-    def load_requires #:nodoc:
-      @requires.each { |name| require name }
+    # Load artifact specs from the build.yaml file, making them available 
+    # by name ( ruby symbols ).
+    def load_artifact_ns #:nodoc:
+      hash = settings.build['artifacts']
+      return unless hash
+      raise &quot;Expected 'artifacts' element to be a hash&quot; unless Hash === hash
+      # Currently we only use one artifact namespace to rule them all. (the root NS)
+      Buildr::ArtifactNamespace.load(:root =&gt; hash)
     end
-
+    
     # Loads buildr.rb files from users home directory and project directory.
     # Loads custom tasks from .rake files in tasks directory.
     def load_tasks #:nodoc:
+      # TODO: this might need to be split up, look for deprecated features, better method name.
       files = [ File.expand_path('buildr.rb', ENV['HOME']), 'buildr.rb' ].select { |file| File.exist?(file) }
       files += [ File.expand_path('buildr.rake', ENV['HOME']), File.expand_path('buildr.rake') ].
         select { |file| File.exist?(file) }.each { |file| warn &quot;Please use '#{file.ext('rb')}' instead of '#{file}'&quot; }
@@ -305,42 +431,61 @@ module Buildr
       true
     end
 
-    def display_prerequisites
-      invoke_task('buildr:initialize')
-      tasks.each do |task|
-        if task.name =~ options.show_task_pattern
-          puts &quot;buildr #{task.name}&quot;
-          task.prerequisites.each { |prereq| puts &quot;    #{prereq}&quot; }
+    def display_tasks_and_comments
+      displayable_tasks = tasks.select { |t| t.comment &amp;&amp; t.name =~ options.show_task_pattern }
+      if options.full_description
+        displayable_tasks.each do |t|
+          puts &quot;buildr #{t.name_with_args}&quot;
+          t.full_comment.split(&quot;\n&quot;).each do |line|
+            puts &quot;    #{line}&quot;
+          end
+          puts
+        end
+      else
+        width = displayable_tasks.collect { |t| t.name_with_args.length }.max || 10
+        max_column = truncate_output? ? terminal_width - name.size - width - 7 : nil
+        displayable_tasks.each do |t|
+          printf &quot;#{name} %-#{width}s  # %s\n&quot;,
+            t.name_with_args, max_column ? truncate(t.comment, max_column) : t.comment
         end
       end
     end
-    
-    # Provide standard execption handling for the given block.
-    def standard_exception_handling
+
+    def display_prerequisites
+      displayable_tasks = tasks.select { |t| t.name =~ options.show_task_pattern }
+      displayable_tasks.each do |t|
+        puts &quot;buildr #{t.name}&quot;
+        t.prerequisites.each { |pre| puts &quot;    #{pre}&quot; }
+      end
+    end
+
+    def standard_exception_handling # adds on_failure hook
       begin
         yield
       rescue SystemExit =&gt; ex
         # Exit silently with current status
         exit(ex.status)
-      rescue SystemExit, GetoptLong::InvalidOption =&gt; ex
-        # Exit silently
+      rescue OptionParser::ParseError =&gt; ex
+        $stderr.puts $terminal.color(ex.message, :red)
         exit(1)
       rescue Exception =&gt; ex
-        title, message = 'Your build failed with an error', &quot;#{Dir.pwd}:\n#{ex.message}&quot;
-        @on_failure.each { |block| block.call(title, message, ex) rescue nil }
+        title, message = &quot;Your build failed with an error&quot;, &quot;#{Dir.pwd}:\n#{ex.message}&quot;
+        @on_failure.each do |block|
+          block.call(title, message, ex) rescue nil
+        end
         # Exit with error message
-        $stderr.puts &quot;buildr aborted!&quot;
+        $stderr.puts &quot;Buildr aborted!&quot;
         $stderr.puts $terminal.color(ex.message, :red)
         if options.trace
           $stderr.puts ex.backtrace.join(&quot;\n&quot;)
         else
-          $stderr.puts ex.backtrace.select { |str| str =~ /#{buildfile}/ }.map { |line| $terminal.color(line, :red) }.join(&quot;\n&quot;)
+          $stderr.puts ex.backtrace.select { |str| str =~ /#{rakefile}/ }.map { |line| $terminal.color(line, :red) }.join(&quot;\n&quot;)
           $stderr.puts &quot;(See full trace by running task with --trace)&quot;
         end
         exit(1)
       end
     end
-    
+
   end
   
   
@@ -357,10 +502,6 @@ module Buildr
 
   class &lt;&lt; self
 
-    task 'buildr:initialize' do
-      Buildr.load_tasks_and_local_files
-    end
-
     # Returns the Buildr::Application object.
     def application
       Rake.application</diff>
      <filename>lib/buildr/core/application.rb</filename>
    </modified>
    <modified>
      <diff>@@ -864,9 +864,6 @@ module Buildr
   # Forces all the projects to be evaluated before executing any other task.
   # If we don't do that, we don't get to have tasks available when running Rake.
   namespace 'buildr' do
-    task 'initialize' do
-      projects
-    end
 
     desc &quot;Freeze the Buildfile so it always uses Buildr version #{Buildr::VERSION}&quot;
     task 'freeze' do</diff>
      <filename>lib/buildr/core/project.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>6d6e0466f9a905ac1e16b8fdc034a65f2edc169c</id>
    </parent>
  </parents>
  <author>
    <name>Assaf Arkin</name>
    <email>assaf@apache.org</email>
  </author>
  <url>http://github.com/vic/buildr/commit/6e13cc9e664c50d2d930dd66d3e6c5fa588a4d9a</url>
  <id>6e13cc9e664c50d2d930dd66d3e6c5fa588a4d9a</id>
  <committed-date>2008-10-16T18:02:09-07:00</committed-date>
  <authored-date>2008-10-16T18:02:09-07:00</authored-date>
  <message>Bringing Buildr::Application to better extend Rake::Application from Rake 0.8.3, along introduction of a few new options from Rake.

No longer using buildr:initialize task, calling Buildr.projects instead, so this would break Nailgun.

git-svn-id: https://svn.apache.org/repos/asf/incubator/buildr/trunk@705438 13f79535-47bb-0310-9956-ffa450edef68</message>
  <tree>8515ef3c52f203027aa4d7ebce49b1bfa19f4aed</tree>
  <committer>
    <name>Assaf Arkin</name>
    <email>assaf@apache.org</email>
  </committer>
</commit>
