You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by to...@apache.org on 2010/04/05 16:56:55 UTC

svn commit: r930872 - in /buildr/trunk: lib/buildr/core/cc.rb spec/core/cc_spec.rb

Author: toulmean
Date: Mon Apr  5 14:56:54 2010
New Revision: 930872

URL: http://svn.apache.org/viewvc?rev=930872&view=rev
Log:
fix for BUILDR-388 Continuous Compilation Support for Sub-Projects

Modified:
    buildr/trunk/lib/buildr/core/cc.rb
    buildr/trunk/spec/core/cc_spec.rb

Modified: buildr/trunk/lib/buildr/core/cc.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/cc.rb?rev=930872&r1=930871&r2=930872&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/cc.rb (original)
+++ buildr/trunk/lib/buildr/core/cc.rb Mon Apr  5 14:56:54 2010
@@ -52,9 +52,9 @@ module Buildr
       main_dirs = project.compile.sources.map(&:to_s)
       test_dirs = project.task('test:compile').sources.map(&:to_s)
       res_dirs = project.resources.sources.map(&:to_s)
-
-      main_ext = Buildr::Compiler.select(project.compile.compiler).source_ext.map(&:to_s)
-      test_ext = Buildr::Compiler.select(project.task('test:compile').compiler).source_ext.map(&:to_s)
+      
+      main_ext = Buildr::Compiler.select(project.compile.compiler).source_ext.map(&:to_s) unless project.compile.compiler.nil?
+      test_ext = Buildr::Compiler.select(project.task('test:compile').compiler).source_ext.map(&:to_s) unless project.task('test:compile').compiler.nil?
 
       test_tail = if test_dirs.empty? then '' else ",{#{test_dirs.join ','}}/**/*.{#{test_ext.join ','}}" end
       res_tail = if res_dirs.empty? then '' else ",{#{res_dirs.join ','}}/**/*" end
@@ -151,12 +151,14 @@ module Buildr
     include Extension
 
     first_time do
-      Project.local_task :cc
+      desc 'Execute continuous compilation, listening to changes'
+      Project.local_task('cc') { |name|  "Executing continuous compilation for #{name}" }
     end
 
     before_define do |project|
       cc = CCTask.define_task :cc
       cc.send :associate_with, project
+      project.recursive_task(:cc)
     end
 
     def cc

Modified: buildr/trunk/spec/core/cc_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/cc_spec.rb?rev=930872&r1=930871&r2=930872&view=diff
==============================================================================
--- buildr/trunk/spec/core/cc_spec.rb (original)
+++ buildr/trunk/spec/core/cc_spec.rb Mon Apr  5 14:56:54 2010
@@ -51,12 +51,12 @@ module CCHelper
   end
 
   def tests
-    @sources ||= ['Test1.java', 'Test2.java'].map { |f| File.join('src/test/java/thepackage', f) }.
+    @tests ||= ['Test1.java', 'Test2.java'].map { |f| File.join('src/test/java/thepackage', f) }.
       each { |src| write src, "package thepackage; class #{src.pathmap('%n')} {}" }
   end
 
   def resources
-    @sources ||= ['Test1.html', 'Test2.html'].map { |f| File.join('src/main/resources', f) }.
+    @resources ||= ['Test1.html', 'Test2.html'].map { |f| File.join('src/main/resources', f) }.
       each { |src| write src, '<html></html>' }
   end
 end
@@ -84,28 +84,91 @@ describe Buildr::CCTask do
     thread.exit
   end
 
-  it 'should detect change to a file (pending)' do
-    pending
-
-    project, compile, test_compile, filter = setup_cc
-
+  it 'should detect a file change' do |spec|
+    
+    write 'src/main/java/Example.java', "public class Example {}"
+    write 'src/test/java/ExampleTest.java', "public class ExampleTest {}"
+    
+    project = define("foo")
+    cc = project.cc
+    
+    compile = project.compile
+    
+
+    test_compile = project.test.compile
+
+    filter = project.resources
+    
+    # After first period:
+    compile.should_receive :invoke
+    test_compile.should_receive :invoke
+    filter.should_not_receive :run
+    
     thread = Thread.new do
       project.cc.invoke
     end
-
+    
     sleep 0.5
-
+    
     compile.should_receive :reenable
     compile.should_receive :invoke
 
-    test_compile.should_not_receive :reenable
-    test_compile.should_not_receive :invoke
+    test_compile.should_receive :reenable
+    test_compile.should_receive :invoke
 
     filter.should_not_receive :run
+    
+    sleep 1 # Wait one sec as the timestamp needs to be different.
+    touch File.join(Dir.pwd, 'src/main/java/Example.java')
+    sleep 0.2# Wait one standard delay
+    
+    thread.exit
+  end
+  
+  
+  it 'should support subprojects' do |spec|
+    
+    write 'foo/src/main/java/Example.java', "public class Example {}"
+    write 'foo/src/test/java/ExampleTest.java', "public class ExampleTest {}"
+    
+    define 'container' do
+      define('foo')
+    end
+    
+    project = project("container:foo")
+    cc = project.cc
+    
+    compile = project.compile
+
+    test_compile = project.test.compile
+
+    filter = project.resources
+    
+    
+    # After first period:
+    compile.should_receive :invoke
+    test_compile.should_receive :invoke
+    filter.should_not_receive :run
+    
+    thread = Thread.new do
+      project("container").cc.invoke
+    end
+    
+    sleep 0.5
+    
+    # After we changed the file:
+    compile.should_receive :reenable
+    compile.should_receive :invoke
 
-    touch sources.first
-    sleep(project.cc.delay * 5)
-
+    test_compile.should_receive :reenable
+    test_compile.should_receive :invoke
+    
+    filter.should_not_receive :run
+    
+    sleep 1 # Wait one sec as the timestamp needs to be different.
+    touch File.join(Dir.pwd, 'foo/src/main/java/Example.java')
+    sleep 0.2 # Wait one standard delay
+    
     thread.exit
   end
 end