Author: lacton
Date: Mon Aug 25 14:43:20 2008
New Revision: 688892

URL: http://svn.apache.org/viewvc?rev=688892&view=rev
Log:
Created a BuildfileTask to compute when the buildfile was last modified, helper 
files included (e.g., build.yaml)

Modified:
    incubator/buildr/trunk/CHANGELOG
    incubator/buildr/trunk/lib/buildr/core/application.rb
    incubator/buildr/trunk/lib/buildr/ide/eclipse.rb
    incubator/buildr/trunk/lib/buildr/ide/idea.rb
    incubator/buildr/trunk/lib/buildr/ide/idea7x.rb
    incubator/buildr/trunk/spec/application_spec.rb

Modified: incubator/buildr/trunk/CHANGELOG
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=688892&r1=688891&r2=688892&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Mon Aug 25 14:43:20 2008
@@ -9,6 +9,7 @@
           Now it has :type too (Lacton).
 * Change: Eclipse task updated to documented Scala plugin requirements
           (http://www.scala-lang.org/node/94)
+* Change: Buildr.application.buildfile returns a task instead of a String.
 * Fixed:  BUILDR-106 download(artifact(...)=>url) broken in certain cases
           (Lacton).
 * Fixed:  BUILDR-108 Trace to explain why a compile is done (Lacton).

Modified: incubator/buildr/trunk/lib/buildr/core/application.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/application.rb?rev=688892&r1=688891&r2=688892&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/application.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/application.rb Mon Aug 25 14:43:20 
2008
@@ -52,7 +52,7 @@
   # Provide settings that come from three sources.
   #
   # User settings are placed in the .buildr/settings.yaml file located in the 
user's home directory.
-  # The should only be used for settings that are specific to the user and 
applied the same way
+  # They should only be used for settings that are specific to the user and 
applied the same way
   # across all builds.  Example for user settings are preferred repositories, 
path to local repository,
   # user/name password for uploading to remote repository.
   #
@@ -124,6 +124,7 @@
       @home_dir = File.expand_path('.buildr', ENV['HOME'])
       mkpath @home_dir unless File.exist?(@home_dir)
       @environment = ENV['BUILDR_ENV'] ||= 'development'
+      @build_files = []
       @on_completion = []
       @on_failure = []
     end
@@ -138,6 +139,9 @@
     # Copied from BUILD_ENV.
     attr_reader :environment
 
+    # Files that complement the buildfile itself
+    attr_reader :build_files
+    
     # Returns the Settings associated with this build.
     def settings
       @settings ||= Settings.new(self)
@@ -145,16 +149,9 @@
 
     # :call-seq:
     #   buildfile
+    # Returns the buildfile as a task that you can use as a dependency.
     def buildfile
-      rakefile
-    end
-
-    # :call-seq:
-    #   build_files => files
-    #
-    # Returns a list of build files. These are files used by the build, 
-    def build_files
-      [buildfile].compact + Array(@build_files)
+      @buildfile_task ||= BuildfileTask.define_task(rakefile)
     end
 
     # Returns Gem::Specification for every listed and installed Gem, 
Gem::Dependency
@@ -250,20 +247,21 @@
       load_imports
     end
 
-    # Loads buildr.rake files from users home directory and project directory.
+    # Loads buildr.rb files from users home directory and project directory.
     # Loads custom tasks from .rake files in tasks directory.
     def load_tasks #:nodoc:
-      @build_files = [ File.expand_path('buildr.rb', ENV['HOME']), 'buildr.rb' 
].select { |file| File.exist?(file) }
-      @build_files += [ File.expand_path('buildr.rake', ENV['HOME']), 
File.expand_path('buildr.rake') ].
+      build_files = [ File.expand_path('buildr.rb', ENV['HOME']), 'buildr.rb' 
].select { |file| File.exist?(file) }
+      build_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}'" }
       #Load local tasks that can be used in the Buildfile.
-      @build_files += Dir["#{Dir.pwd}/tasks/*.rake"]
-      @build_files.each do |file|
+      build_files += Dir["#{Dir.pwd}/tasks/*.rake"]
+      build_files.each do |file|
         unless $LOADED_FEATURES.include?(file)
           load file
           $LOADED_FEATURES << file
         end
       end
+      @build_files += build_files
       true
     end
     private :load_tasks
@@ -347,6 +345,17 @@
     end
     
   end
+  
+  
+  # This task stands for the buildfile and all its associated helper files 
(e.g., buildr.rb, build.yaml).
+  # By using this task as a prerequisite for other tasks, you can ensure these 
tasks will be needed
+  # whenever the buildfile changes.
+  class BuildfileTask < Rake::Task
+    
+    def timestamp
+      ([EMAIL PROTECTED] + @application.build_files).map { |f| 
File.stat(f).mtime }.max
+    end
+  end
 
 
   class << self

Modified: incubator/buildr/trunk/lib/buildr/ide/eclipse.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/eclipse.rb?rev=688892&r1=688891&r2=688892&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/eclipse.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/eclipse.rb Mon Aug 25 14:43:20 2008
@@ -38,13 +38,6 @@
       # We need paths relative to the top project's base directory.
       root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : 
p.base_dir } ; f[p] }[project]
 
-      # We want the Eclipse files changed every time the Buildfile changes, 
but also anything loaded by
-      # the Buildfile (buildr.rb, separate file listing dependencies, etc), so 
we add anything required
-      # after the Buildfile. So which don't know where Buildr shows up 
exactly, ignore files that show
-      # in $LOADED_FEATURES that we cannot resolve.
-      sources = Buildr.application.build_files.map { |file| 
File.expand_path(file) }.select { |file| File.exist?(file) }
-      sources << File.expand_path(Buildr.application.buildfile, root_path) if 
Buildr.application.buildfile
-
       # Check if project has scala facet
       scala = project.compile.language == :scala
 
@@ -56,7 +49,7 @@
         eclipse.enhance [ file(project.path_to(".classpath")), 
file(project.path_to(".project")) ]
 
         # The only thing we need to look for is a change in the Buildfile.
-        file(project.path_to(".classpath")=>sources) do |task|
+        file(project.path_to(".classpath")=>Buildr.application.buildfile) do 
|task|
           info "Writing #{task.name}"
 
           m2repo = Buildr::Repositories.instance.local
@@ -104,7 +97,7 @@
         end
 
         # The only thing we need to look for is a change in the Buildfile.
-        file(project.path_to(".project")=>sources) do |task|
+        file(project.path_to(".project")=>Buildr.application.buildfile) do 
|task|
           info "Writing #{task.name}"
           File.open(task.name, "w") do |file|
             xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)

Modified: incubator/buildr/trunk/lib/buildr/ide/idea.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/idea.rb?rev=688892&r1=688891&r2=688892&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/idea.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/idea.rb Mon Aug 25 14:43:20 2008
@@ -39,12 +39,6 @@
       idea = project.task("idea")
       # We need paths relative to the top project's base directory.
       root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : 
p.base_dir }; f[p] }[project]
-      # We want the Eclipse files changed every time the Buildfile changes, 
but also anything loaded by
-      # the Buildfile (buildr.rb, separate file listing dependencies, etc), so 
we add anything required
-      # after the Buildfile. So which don't know where Buildr shows up 
exactly, ignore files that show
-      # in $LOADED_FEATURES that we cannot resolve.
-      sources = Buildr.application.build_files.map { |file| 
File.expand_path(file) }.select { |file| File.exist?(file) }
-      sources << File.expand_path(Buildr.application.buildfile, root_path) if 
Buildr.application.buildfile
 
       # Find a path relative to the project's root directory.
       relative = lambda { |path| Util.relative_path(path.to_s, 
project.path_to) }
@@ -57,7 +51,7 @@
       idea.enhance [ file(task_name) ]
 
       # The only thing we need to look for is a change in the Buildfile.
-      file(task_name=>sources) do |task|
+      file(task_name=>Buildr.application.buildfile) do |task|
         info "Writing #{task.name}"
 
         # Idea handles modules slightly differently if they're WARs
@@ -153,7 +147,7 @@
         task_name = project.path_to("#{project.name.gsub(':', '-')}.ipr")
         idea.enhance [ file(task_name) ]
 
-        file(task_name=>sources) do |task|
+        file(task_name=>Buildr.application.buildfile) do |task|
           info "Writing #{task.name}"
 
           # Generating just the little stanza that chanages from one project 
to another

Modified: incubator/buildr/trunk/lib/buildr/ide/idea7x.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/idea7x.rb?rev=688892&r1=688891&r2=688892&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/idea7x.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/idea7x.rb Mon Aug 25 14:43:20 2008
@@ -49,9 +49,6 @@
       # We need paths relative to the top project's base directory.
       root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : 
p.base_dir }; f[p] }[project]
 
-      sources = Buildr.application.build_files.map { |file| 
File.expand_path(file) }.select { |file| File.exist?(file) }
-      sources << File.expand_path(Buildr.application.buildfile, root_path) if 
Buildr.application.buildfile
-
       # Find a path relative to the project's root directory.
       relative = lambda { |path| 
Util.relative_path(File.expand_path(path.to_s), project.path_to) }
 
@@ -63,7 +60,7 @@
       idea7x.enhance [ file(task_name) ]
 
       # The only thing we need to look for is a change in the Buildfile.
-      file(task_name=>sources) do |task|
+      file(task_name=>Buildr.application.buildfile) do |task|
         # Note: Use the test classpath since Eclipse compiles both "main" and 
"test" classes using the same classpath
         deps = project.test.compile.dependencies.map(&:to_s) - [ 
project.compile.target.to_s ]
 
@@ -104,7 +101,7 @@
 
       # Root project aggregates all the subprojects.
       if project.parent == nil
-        Buildr::Idea7x.generate_ipr(project, idea7x, sources)
+        Buildr::Idea7x.generate_ipr(project, idea7x, 
Buildr.application.buildfile)
       end
 
     end # after_define

Modified: incubator/buildr/trunk/spec/application_spec.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/application_spec.rb?rev=688892&r1=688891&r2=688892&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/application_spec.rb (original)
+++ incubator/buildr/trunk/spec/application_spec.rb Mon Aug 25 14:43:20 2008
@@ -67,7 +67,7 @@
     end
 
     it 'should return empty array if no gems specified' do
-      Buildr.application.load_gems 
+      Buildr.application.load_gems
       Buildr.application.gems.should be_empty
     end
 
@@ -312,9 +312,44 @@
       YAML
       Buildr.settings.profile.should == { 'foo'=>'bar' }
     end
-
   end
 
+  describe 'buildfile task' do
+    before do
+      @buildfile_time = Time.now - 10
+      write 'buildfile'; File.utime(@buildfile_time, @buildfile_time, 
'buildfile')
+    end
+    
+    it 'should point to the buildfile' do
+      Buildr.application.buildfile.should point_to_path('buildfile')
+    end
+    
+    it 'should be a defined task' do
+      Buildr.application.buildfile.should == 
file(File.expand_path('buildfile'))
+    end
+    
+    it 'should have the same timestamp as the buildfile' do
+      Buildr.application.buildfile.timestamp.should be_close(@buildfile_time, 
1)
+    end
+    
+    it 'should have the same timestamp as build.yaml if the latter is newer' do
+      write 'build.yaml'; File.utime(@buildfile_time + 5, @buildfile_time + 5, 
'build.yaml')
+      Buildr.application.run
+      Buildr.application.buildfile.timestamp.should be_close(@buildfile_time + 
5, 1)
+    end
+    
+    it 'should have the same timestamp as the buildfile if build.yaml is 
older' do
+      write 'build.yaml'; File.utime(@buildfile_time - 5, @buildfile_time - 5, 
'build.yaml')
+      Buildr.application.run
+      Buildr.application.buildfile.timestamp.should be_close(@buildfile_time, 
1)
+    end
+    
+    it 'should have the same timestamp as build.rb in home dir if the latter 
is newer' do
+      write 'home/buildr.rb'; File.utime(@buildfile_time + 5, @buildfile_time 
+ 5, 'home/buildr.rb')
+      Buildr.application.send :load_tasks
+      Buildr.application.buildfile.timestamp.should be_close(@buildfile_time + 
5, 1)
+    end
+  end
 end
 
 


Reply via email to