You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by dj...@apache.org on 2009/08/25 17:47:40 UTC
svn commit: r807677 - in /buildr/trunk: lib/buildr/core/application.rb
spec/core/application_spec.rb
Author: djspiewak
Date: Tue Aug 25 15:47:40 2009
New Revision: 807677
URL: http://svn.apache.org/viewvc?rev=807677&view=rev
Log:
Move rakelib loading into load_tasks so the the files are loaded before the buildfile and are automatically added as prereqs of the buildfile task. (Rhett Sutphin)
Modified:
buildr/trunk/lib/buildr/core/application.rb
buildr/trunk/spec/core/application_spec.rb
Modified: buildr/trunk/lib/buildr/core/application.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/application.rb?rev=807677&r1=807676&r2=807677&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/application.rb (original)
+++ buildr/trunk/lib/buildr/core/application.rb Tue Aug 25 15:47:40 2009
@@ -396,11 +396,6 @@
def raw_load_buildfile # replaces raw_load_rakefile
puts "(in #{Dir.pwd}, #{environment})" unless options.silent
load File.expand_path(@rakefile) if @rakefile && @rakefile != ''
- options.rakelib.each do |rlib|
- glob("#{rlib}/*.rake") do |name|
- add_import name
- end
- end
load_imports
Buildr.projects
end
@@ -456,6 +451,8 @@
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 "Please use '#{file.ext('rb')}' instead of '#{file}'" }
+ files += (options.rakelib || []).collect { |rlib| Dir["#{rlib}/*.rake"] }.flatten
+
files.each do |file|
unless $LOADED_FEATURES.include?(file)
load file
Modified: buildr/trunk/spec/core/application_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/application_spec.rb?rev=807677&r1=807676&r2=807677&view=diff
==============================================================================
--- buildr/trunk/spec/core/application_spec.rb (original)
+++ buildr/trunk/spec/core/application_spec.rb Tue Aug 25 15:47:40 2009
@@ -80,6 +80,13 @@
lambda { Buildr.application.send :load_buildfile }.should show(%r{(in .*, spec)})
end
end
+
+ describe 'options' do
+ it "should have 'tasks' as the sole default rakelib" do
+ Buildr.application.send(:handle_options)
+ Buildr.application.options.rakelib.should == ['tasks']
+ end
+ end
describe 'gems' do
before do
@@ -123,7 +130,6 @@
end
end
-
describe 'load_gems' do
before do
class << Buildr.application
@@ -234,6 +240,82 @@
end
end
+ describe 'load_tasks' do
+ before do
+ class << Buildr.application
+ public :load_tasks
+ end
+ @original_loaded_features = $LOADED_FEATURES.dup
+ Buildr.application.options.rakelib = ["tasks"]
+ end
+
+ after do
+ $taskfiles = nil
+ ($LOADED_FEATURES - @original_loaded_features).each do |new_load|
+ $LOADED_FEATURES.delete(new_load)
+ end
+ end
+
+ def write_task(filename)
+ write filename, <<-RUBY
+ $taskfiles ||= []
+ $taskfiles << __FILE__
+ RUBY
+ end
+
+ def loaded_tasks
+ @loaded ||= Buildr.application.load_tasks
+ $taskfiles
+ end
+
+ it "should load {options.rakelib}/foo.rake" do
+ write_task 'tasks/foo.rake'
+ loaded_tasks.should have(1).task
+ loaded_tasks.first.should =~ %r{tasks/foo\.rake$}
+ end
+
+ it 'should load all *.rake files from the rakelib' do
+ write_task 'tasks/bar.rake'
+ write_task 'tasks/quux.rake'
+ loaded_tasks.should have(2).tasks
+ end
+
+ it 'should not load files which do not have the .rake extension' do
+ write_task 'tasks/foo.rb'
+ write_task 'tasks/bar.rake'
+ loaded_tasks.should have(1).task
+ loaded_tasks.first.should =~ %r{tasks/bar\.rake$}
+ end
+
+ it 'should load files only from the directory specified in the rakelib option' do
+ Buildr.application.options.rakelib = ['extensions']
+ write_task 'extensions/amp.rake'
+ write_task 'tasks/bar.rake'
+ write_task 'extensions/foo.rake'
+ loaded_tasks.should have(2).tasks
+ loaded_tasks[0].should =~ %r{extensions/amp\.rake$}
+ loaded_tasks[1].should =~ %r{extensions/foo\.rake$}
+ end
+
+ it 'should load files from all the directories specified in the rakelib option' do
+ Buildr.application.options.rakelib = ['ext', 'more', 'tasks']
+ write_task 'ext/foo.rake'
+ write_task 'tasks/bar.rake'
+ write_task 'tasks/zeb.rake'
+ write_task 'more/baz.rake'
+ loaded_tasks.should have(4).tasks
+ end
+
+ it 'should not load files from the rakelib more than once' do
+ write_task 'tasks/new_one.rake'
+ write_task 'tasks/already.rake'
+ $LOADED_FEATURES << 'tasks/already.rake'
+
+ loaded_tasks.should have(1).task
+ loaded_tasks.first.should =~ %r{tasks/new_one\.rake$}
+ end
+ end
+
end