Author: assaf
Date: Mon Oct 20 16:04:53 2008
New Revision: 706447

URL: http://svn.apache.org/viewvc?rev=706447&view=rev
Log:
It is now possible to call Buildr.settings.user anytime, but .profile and 
.build only after buildfile has been located.
This allows Buildr to use repositories and other settings early on before 
buildfile is loaded, or even located.

Modified:
    incubator/buildr/trunk/lib/buildr/core/application.rb
    incubator/buildr/trunk/lib/buildr/core/generate.rb
    incubator/buildr/trunk/spec/core/generate_spec.rb

Modified: incubator/buildr/trunk/lib/buildr/core/application.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/application.rb?rev=706447&r1=706446&r2=706447&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/application.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/application.rb Mon Oct 20 16:04:53 
2008
@@ -69,19 +69,22 @@
 
     def initialize(application) #:nodoc:
       @application = application
-      @user = load_from('settings', @application.home_dir)
-      @build = load_from('build')
-      @profiles = load_from('profiles')
     end
 
     # User settings loaded from setting.yaml file in user's home directory.
-    attr_reader :user
+    def user
+      @user ||= load_from('settings', @application.home_dir)
+    end
 
     # Build settings loaded from build.yaml file in build directory.
-    attr_reader :build
+    def build
+      @build ||= load_from('build')
+    end
 
     # Profiles loaded from profiles.yaml file in build directory.
-    attr_reader :profiles
+    def profiles
+      @profiles ||= load_from('profiles')
+    end
 
     # :call-seq:
     #    profile => hash
@@ -93,9 +96,12 @@
 
   private
 
-    def load_from(base_name, dir = nil)
-      base_name = File.expand_path(base_name, dir) if dir
-      file_name = ['yaml', 'yml'].map { |ext| "#{base_name}.#{ext}" }.find { 
|fn| File.exist?(fn) }
+    def load_from(name, path = nil)
+      unless path
+        fail "Internal error: attempting to access local setting before 
buildfile located" unless @application.rakefile
+        path = File.dirname(@application.rakefile)
+      end
+      file_name = ['yaml', 'yml'].map { |ext| File.join(path, 
"#{name}.#{ext}") }.find { |fn| File.exist?(fn) }
       return {} unless file_name
       yaml = YAML.load(File.read(file_name)) || {}
       fail "Expecting #{file_name} to be a map (name: value)!" unless Hash === 
yaml
@@ -120,6 +126,7 @@
       @top_level_tasks = []
       @home_dir = File.expand_path('.buildr', ENV['HOME'])
       mkpath @home_dir, :verbose=>false unless File.exist?(@home_dir)
+      @settings = Settings.new(self)
       @on_completion = []
       @on_failure = []
     end
@@ -155,10 +162,7 @@
     end
 
     # Returns the Settings associated with this build.
-    def settings
-      fail "Internal error: Called Buildr.settings before buildfile located" 
unless rakefile
-      @settings ||= Settings.new(self)
-    end
+    attr_reader :settings
 
     # :call-seq:
     #   buildfile

Modified: incubator/buildr/trunk/lib/buildr/core/generate.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/generate.rb?rev=706447&r1=706446&r2=706447&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/generate.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/generate.rb Mon Oct 20 16:04:53 2008
@@ -25,8 +25,8 @@
       choose do |menu|
         menu.header = "To use Buildr you need a buildfile. Do you want me to 
create one?"
 
-        menu.choice("From maven2 pom file") { script = 
Generate.from_maven2_pom(true).join("\n") } if File.exists?("pom.xml")
-        menu.choice("From directory structure") { script = 
Generate.from_directory(true).join("\n") }
+        menu.choice("From maven2 pom file") { script = 
Generate.from_maven2_pom('pom.xml').join("\n") } if File.exists?("pom.xml")
+        menu.choice("From directory structure") { script = 
Generate.from_directory(Dir.pwd).join("\n") }
         menu.choice("Skip") { }
       end
        

Modified: incubator/buildr/trunk/spec/core/generate_spec.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/core/generate_spec.rb?rev=706447&r1=706446&r2=706447&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/core/generate_spec.rb (original)
+++ incubator/buildr/trunk/spec/core/generate_spec.rb Mon Oct 20 16:04:53 2008
@@ -21,13 +21,13 @@
   
   describe 'Generated buildfile' do
     it 'should be a legal buildfile' do
-      File.open('buildfile', 'w') { |file| file.write 
Generate.from_directory(true).join("\n") }
+      File.open('buildfile', 'w') { |file| file.write 
Generate.from_directory(Dir.pwd).join("\n") }
       lambda { Buildr.application.run }.should_not raise_error
     end
     
     it 'should not contain NEXT_VERSION because it was removed in buildr 
1.3.3' do
-      buildfile = Generate.from_directory(true)
+      buildfile = Generate.from_directory(Dir.pwd)
       buildfile.each { |line| line.should_not include('NEXT_VERSION')}
     end
   end
-end
\ No newline at end of file
+end


Reply via email to