buildr 1.4.7-x86-mswin32 → 1.4.8-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/CHANGELOG +41 -0
  2. data/Rakefile +0 -6
  3. data/addon/buildr/bnd.rb +13 -3
  4. data/addon/buildr/checkstyle.rb +1 -1
  5. data/addon/buildr/git_auto_version.rb +33 -0
  6. data/addon/buildr/{gwt.rake → gwt.rb} +0 -0
  7. data/addon/buildr/jacoco.rb +194 -0
  8. data/buildr.buildfile +1 -1
  9. data/buildr.gemspec +23 -16
  10. data/doc/_layouts/default.html +0 -2
  11. data/doc/contributing.textile +47 -0
  12. data/doc/download.textile +24 -0
  13. data/doc/index.textile +43 -23
  14. data/doc/languages.textile +65 -6
  15. data/doc/more_stuff.textile +12 -0
  16. data/doc/packaging.textile +2 -0
  17. data/doc/settings_profiles.textile +1 -1
  18. data/lib/buildr.rb +0 -4
  19. data/lib/buildr/core/application.rb +41 -8
  20. data/lib/buildr/core/build.rb +102 -1
  21. data/lib/buildr/core/cc.rb +14 -8
  22. data/lib/buildr/core/generate.rb +148 -7
  23. data/lib/buildr/core/util.rb +3 -3
  24. data/lib/buildr/ide/eclipse.rb +114 -0
  25. data/lib/buildr/ide/idea.rb +95 -1
  26. data/lib/buildr/java/commands.rb +1 -1
  27. data/lib/buildr/java/rjb.rb +5 -4
  28. data/lib/buildr/packaging/artifact.rb +1 -1
  29. data/lib/buildr/packaging/ziptask.rb +2 -2
  30. data/lib/buildr/scala.rb +1 -1
  31. data/lib/buildr/scala/bdd.rb +9 -2
  32. data/lib/buildr/scala/compiler.rb +94 -4
  33. data/lib/buildr/scala/doc.rb +17 -5
  34. data/lib/buildr/scala/tests.rb +15 -4
  35. data/lib/buildr/version.rb +1 -1
  36. data/rakelib/all-in-one.rake +50 -47
  37. data/rakelib/checks.rake +4 -4
  38. data/rakelib/doc.rake +85 -88
  39. data/rakelib/metrics.rake +9 -9
  40. data/rakelib/package.rake +13 -34
  41. data/rakelib/release.rake +11 -12
  42. data/rakelib/rspec.rake +71 -76
  43. data/rakelib/stage.rake +25 -51
  44. data/spec/addon/bnd_spec.rb +61 -7
  45. data/spec/core/build_spec.rb +117 -0
  46. data/spec/core/cc_spec.rb +36 -22
  47. data/spec/core/common_spec.rb +3 -2
  48. data/spec/core/compile_spec.rb +3 -3
  49. data/spec/core/generate_from_eclipse_spec.rb +280 -0
  50. data/spec/java/bdd_spec.rb +2 -2
  51. data/spec/java/packaging_spec.rb +2 -1
  52. data/spec/packaging/archive_spec.rb +25 -2
  53. data/spec/packaging/artifact_spec.rb +2 -2
  54. data/spec/sandbox.rb +3 -2
  55. data/spec/scala/compiler_spec.rb +41 -0
  56. data/spec/scala/doc_spec.rb +22 -3
  57. data/spec/scala/scala.rb +2 -2
  58. data/spec/scala/tests_spec.rb +2 -2
  59. metadata +223 -194
  60. data/addon/buildr/jdepend.rb.orig +0 -178
  61. data/doc/installing.textile.orig +0 -282
  62. data/doc/more_stuff.textile.orig +0 -1004
  63. data/lib/buildr/ide/eclipse/java.rb +0 -49
  64. data/lib/buildr/ide/eclipse/plugin.rb +0 -67
  65. data/lib/buildr/ide/eclipse/scala.rb +0 -64
data/rakelib/stage.rake CHANGED
@@ -19,31 +19,33 @@ require 'digest/sha1'
19
19
 
20
20
  gpg_cmd = 'gpg2'
21
21
 
22
- task :prepare do |task, args|
22
+ task 'prepare' do |task, args|
23
23
  gpg_arg = args.gpg || ENV['gpg']
24
-
24
+
25
+ if false
25
26
  # Make sure we're doing a release from checked code.
26
27
  lambda do
27
- puts "Checking there are no local changes ... "
28
+ puts 'Checking there are no local changes ... '
28
29
  svn = `svn status`
29
30
  fail "Cannot release unless all local changes are in SVN:\n#{svn}" unless svn.empty?
30
31
  git = `git status -s`
31
32
  fail "Cannot release unless all local changes are in Git:\n#{git}" if git[/^ M/] && ENV["IGNORE_GIT"].nil?
32
- puts "[X] There are no local changes, everything is in source control"
33
+ puts '[X] There are no local changes, everything is in source control'
33
34
  end.call
34
35
 
35
36
  # Make sure we have a valid CHANGELOG entry for this release.
36
37
  lambda do
37
- puts "Checking that CHANGELOG indicates most recent version and today's date ... "
38
+ puts 'Checking that CHANGELOG indicates most recent version and today''s date ... '
38
39
  expecting = "#{spec.version} (#{Time.now.strftime('%Y-%m-%d')})"
39
40
  header = File.readlines('CHANGELOG').first.chomp
40
41
  fail "Expecting CHANGELOG to start with #{expecting}, but found #{header} instead" unless expecting == header
41
- puts "[x] CHANGELOG indicates most recent version and today's date"
42
+ puts '[x] CHANGELOG indicates most recent version and today''s date'
42
43
  end.call
44
+ end
43
45
 
44
46
  # Need GPG to sign the packages.
45
47
  lambda do
46
- gpg_arg or fail "Please run with gpg=<argument for gpg --local-user>"
48
+ gpg_arg or fail 'Please run with gpg=<argument for gpg --local-user>'
47
49
  gpg_ok = `gpg2 --list-keys #{gpg_arg}` rescue nil
48
50
  if !$?.success?
49
51
  gpg_ok = `gpg --list-keys #{gpg_arg}`
@@ -52,45 +54,26 @@ task :prepare do |task, args|
52
54
  fail "No GPG user #{gpg_arg}" if gpg_ok.empty?
53
55
  end.call
54
56
 
55
- task(:license).invoke
56
-
57
- # Need JRuby, Scala and Groovy installed to run all the specs.
58
- lambda do
59
- puts "Checking that we have Scala and Groovy available ... "
60
- `scala -version`
61
- $?.exitstatus == 1 or fail "Scala is not installed"
62
- sh 'groovy -version'
63
- puts "[X] We have Scala and Groovy"
64
- end.call
57
+ task('license').invoke
65
58
 
66
59
  # Need Prince to generate PDF
67
60
  lambda do
68
- puts "Checking that we have prince available ... "
61
+ puts 'Checking that we have prince available ... '
69
62
  sh 'prince --version'
70
- puts "[X] We have prince available"
71
- end.call
72
-
73
- # Need RubyForge to upload new release files.
74
- lambda do
75
- puts "[!] Make sure you have admin privileges to make a release on RubyForge"
76
- rubyforge = RubyForge.new.configure
77
- rubyforge.login
78
- rubyforge.scrape_project(spec.name)
63
+ puts '[X] We have prince available'
79
64
  end.call
80
65
 
81
- # We will be speccing in one platform, so also spec the other one.
82
- task('spec:ruby_1_9').invoke unless RUBY_VERSION >= '1.9' && !RUBY_PLATFORM[/java/]
83
- task('spec:ruby_1_8').invoke unless RUBY_VERSION >= '1.8.7' && !RUBY_PLATFORM[/java/]
84
- task('spec:jruby').invoke unless RUBY_PLATFORM[/java/]
66
+ raise "Can not run stage process under jruby" if RUBY_PLATFORM[/java/]
67
+ raise "Can not run staging process under older rubies" unless RUBY_VERSION >= '1.9'
85
68
  end
86
69
 
87
- task :stage=>[:clobber, :prepare] do |task, args|
70
+ task 'stage' => %w(clobber prepare) do |task, args|
88
71
  gpg_arg = args.gpg || ENV['gpg']
89
72
  mkpath '_staged'
90
73
 
91
74
  # Start by figuring out what has changed.
92
75
  lambda do
93
- puts "Looking for changes between this release and previous one ..."
76
+ puts 'Looking for changes between this release and previous one ...'
94
77
  pattern = /(^(\d+\.\d+(?:\.\d+)?)\s+\(\d{4}-\d{2}-\d{2}\)\s*((:?^[^\n]+\n)*))/
95
78
  changes = File.read('CHANGELOG').scan(pattern).inject({}) { |hash, set| hash[set[1]] = set[2] ; hash }
96
79
  current = changes[spec.version.to_s]
@@ -99,14 +82,14 @@ task :stage=>[:clobber, :prepare] do |task, args|
99
82
  file.write "#{spec.version} (#{Time.now.strftime('%Y-%m-%d')})\n"
100
83
  file.write current
101
84
  end
102
- puts "[X] Listed most recent changed in _staged/CHANGES"
85
+ puts '[X] Listed most recent changed in _staged/CHANGES'
103
86
  end.call
104
87
 
105
88
  # Create the packages (gem, tarball) and sign them. This requires user
106
89
  # intervention so the earlier we do it the better.
107
90
  lambda do
108
- puts "Creating and signing release packages ..."
109
- task(:package).invoke
91
+ puts 'Creating and signing release packages ...'
92
+ task('package').invoke
110
93
  mkpath '_staged/dist'
111
94
  FileList['pkg/*.{gem,zip,tgz}'].each do |source|
112
95
  pkg = source.pathmap('_staged/dist/%n%x')
@@ -117,13 +100,13 @@ task :stage=>[:clobber, :prepare] do |task, args|
117
100
  sh gpg_cmd, '--local-user', gpg_arg, '--armor', '--output', pkg + '.asc', '--detach-sig', pkg, :verbose=>true
118
101
  end
119
102
  cp 'etc/KEYS', '_staged/dist'
120
- puts "[X] Created and signed release packages in _staged/dist"
103
+ puts '[X] Created and signed release packages in _staged/dist'
121
104
  end.call
122
105
 
123
106
  # The download page should link to the new binaries/sources, and we
124
107
  # want to do that before generating the site/documentation.
125
108
  lambda do
126
- puts "Updating download page with links to release packages ... "
109
+ puts 'Updating download page with links to release packages ... '
127
110
  mirror = "http://www.apache.org/dyn/closer.cgi/#{spec.name}/#{spec.version}"
128
111
  official = "http://www.apache.org/dist/#{spec.name}/#{spec.version}"
129
112
  rows = FileList['_staged/dist/*.{gem,tgz,zip}'].map { |pkg|
@@ -151,10 +134,10 @@ p>. ("Release signing keys":#{official}/KEYS)
151
134
  # Now we can create the Web site, this includes running specs, coverage report, etc.
152
135
  # This will take a while, so we want to do it as last step before upload.
153
136
  lambda do
154
- puts "Creating new Web site"
137
+ puts 'Creating new Web site'
155
138
  task(:site).invoke
156
139
  cp_r '_site', '_staged/site'
157
- puts "[X] Created new Web site in _staged/site"
140
+ puts '[X] Created new Web site in _staged/site'
158
141
  end.call
159
142
 
160
143
 
@@ -193,13 +176,6 @@ The documentation generated for this release is available here:
193
176
  #{base_url}/site/
194
177
  #{base_url}/site/buildr.pdf
195
178
 
196
- The official specification against which this release was tested:
197
- #{base_url}/site/specs.html
198
-
199
- Test coverage report:
200
- #{base_url}/site/coverage/index.html
201
-
202
-
203
179
  The following changes were made since #{previous_version}:
204
180
 
205
181
  #{changes.gsub(/^/, ' ')}
@@ -207,11 +183,9 @@ The following changes were made since #{previous_version}:
207
183
  File.open 'vote-email.txt', 'w' do |file|
208
184
  file.write email
209
185
  end
210
- puts "[X] Created release vote email template in 'vote-email.txt'"
186
+ puts '[X] Created release vote email template in ''vote-email.txt'''
211
187
  puts email
212
188
  end.call
213
-
214
189
  end
215
190
 
216
-
217
- task(:clobber) { rm_rf '_staged' }
191
+ task('clobber') { rm_rf '_staged' }
@@ -32,6 +32,59 @@ def open_main_manifest_section(file = 'target/foo-2.1.3.jar')
32
32
  end
33
33
 
34
34
  describe Buildr::Bnd do
35
+ before do
36
+ repositories.remote << Buildr::Bnd.remote_repository
37
+ end
38
+
39
+ describe "project.bnd version (assure backward compatibility)" do
40
+
41
+ after do
42
+ STDERR.puts("backward compatibility: used #{Buildr::Bnd.version} restoring #{@savedVersion}")
43
+ Buildr::Bnd.version = @savedVersion
44
+ end
45
+
46
+ before do
47
+ @savedVersion = Buildr::Bnd.version
48
+ Buildr::Bnd.version = '0.0.384'
49
+ write "src/main/java/com/biz/Foo.java", <<SRC
50
+ package com.biz;
51
+ public class Foo {}
52
+ SRC
53
+ write "bar/src/main/java/com/biz/bar/Bar.java", <<SRC
54
+ package com.biz.bar;
55
+ public class Bar {}
56
+ SRC
57
+
58
+ @foo = define "foo" do
59
+ project.version = "2.1.3"
60
+ project.group = "mygroup"
61
+ manifest["Magic-Food"] = "Chocolate"
62
+ manifest["Magic-Drink"] = "Wine"
63
+ package(:bundle).tap do |bnd|
64
+ bnd["Export-Package"] = "com.*"
65
+ end
66
+
67
+ define "bar" do
68
+ project.version = "2.2"
69
+ package(:bundle).tap do |bnd|
70
+ bnd["Magic-Food"] = "Cheese"
71
+ bnd["Export-Package"] = "com.*"
72
+ end
73
+ end
74
+ end
75
+ task('package').invoke
76
+ end
77
+
78
+ it "version 0.0.384 does not export the version and wrong import-package" do
79
+ open_main_manifest_section do |attribs|
80
+ attribs['Bundle-Name'].should eql('foo')
81
+ attribs['Bundle-Version'].should eql('2.1.3')
82
+ attribs['Bundle-SymbolicName'].should eql('mygroup.foo')
83
+ attribs['Export-Package'].should eql('com.biz')
84
+ attribs['Import-Package'].should eql('com.biz')
85
+ end
86
+ end
87
+ end
35
88
 
36
89
  describe "package :bundle" do
37
90
  describe "with a valid bundle" do
@@ -92,8 +145,8 @@ SRC
92
145
  attribs['Bundle-Name'].should eql('foo')
93
146
  attribs['Bundle-Version'].should eql('2.1.3')
94
147
  attribs['Bundle-SymbolicName'].should eql('mygroup.foo')
95
- attribs['Export-Package'].should eql('com.biz')
96
- attribs['Import-Package'].should eql('com.biz')
148
+ attribs['Export-Package'].should eql('com.biz;version="2.1.3"')
149
+ attribs['Import-Package'].should be_nil
97
150
  end
98
151
  end
99
152
 
@@ -123,8 +176,8 @@ SRC
123
176
  attribs['Bundle-Name'].should eql('foo:bar')
124
177
  attribs['Bundle-Version'].should eql('2.2')
125
178
  attribs['Bundle-SymbolicName'].should eql('mygroup.foo.bar')
126
- attribs['Export-Package'].should eql('com.biz.bar')
127
- attribs['Import-Package'].should eql('com.biz.bar')
179
+ attribs['Export-Package'].should eql('com.biz.bar;version="2.2"')
180
+ attribs['Import-Package'].should be_nil
128
181
  end
129
182
  end
130
183
 
@@ -179,7 +232,7 @@ SRC
179
232
  it "should generate package with files exported from dependency" do
180
233
  task('package').invoke
181
234
  open_main_manifest_section do |attribs|
182
- attribs['Export-Package'].should eql('org.apache.tools.zip')
235
+ attribs['Export-Package'].should eql('org.apache.tools.zip;version="2.1.3"')
183
236
  end
184
237
  end
185
238
  end
@@ -211,7 +264,7 @@ SRC
211
264
  it "should generate package with files exported from dependency" do
212
265
  task('package').invoke
213
266
  open_main_manifest_section do |attribs|
214
- attribs['Export-Package'].should eql('org.apache.tools.zip')
267
+ attribs['Export-Package'].should eql('org.apache.tools.zip;version="2.1.3"')
215
268
  end
216
269
  end
217
270
  end
@@ -235,7 +288,7 @@ SRC
235
288
  it "should generate package with files exported from dependency" do
236
289
  task('package').invoke
237
290
  open_main_manifest_section do |attribs|
238
- attribs['Export-Package'].should eql('org.apache.tools.zip')
291
+ attribs['Export-Package'].should eql('org.apache.tools.zip;version="2.1.3"')
239
292
  end
240
293
  end
241
294
  end
@@ -327,4 +380,5 @@ SRC
327
380
  Rake::Task.tasks.detect { |task| task.to_s == "bnd:print" }.comment.should_not be_nil
328
381
  end
329
382
  end
383
+
330
384
  end
@@ -200,6 +200,66 @@ describe Project, '#reports' do
200
200
  end
201
201
 
202
202
 
203
+ describe Hg do
204
+ describe '#current_branch' do
205
+ it 'should return the correct branch' do
206
+ Hg.should_receive(:hg).with('branch').and_return("default\n")
207
+ Hg.send(:current_branch).should == 'default'
208
+ end
209
+ end
210
+
211
+ describe '#uncommitted_files' do
212
+ it 'should return an array of modified files' do
213
+ Hg.should_receive(:`).with('hg status').and_return <<-EOF
214
+ M abc.txt
215
+ M xyz.txt
216
+ R hello
217
+ R removed
218
+ ! conflict
219
+ A README
220
+ ? ignore.txt
221
+ EOF
222
+ Hg.uncommitted_files.should include('abc.txt', 'xyz.txt', 'hello', 'README', 'conflict', 'ignore.txt')
223
+ end
224
+ end
225
+
226
+ describe '#uncommitted_files' do
227
+ it 'should return an empty array on a clean repository' do
228
+ Hg.should_receive(:`).with('hg status').and_return "\n"
229
+ Hg.uncommitted_files.should be_empty
230
+ end
231
+ end
232
+
233
+ describe '#remote' do
234
+ it 'should return the aliases of the default remote repositories' do
235
+ Hg.should_receive(:hg).with('paths').and_return <<-EOF
236
+ default = https://hg.apache.org/repo/my-repo
237
+ EOF
238
+ Hg.send(:remote).should include('https://hg.apache.org/repo/my-repo')
239
+ end
240
+
241
+ it 'should return the aliases of the default push remote repositories' do
242
+ Hg.should_receive(:hg).with('paths').and_return <<-EOF
243
+ default-push = https://hg.apache.org/repo/my-repo
244
+ EOF
245
+ Hg.send(:remote).should include('https://hg.apache.org/repo/my-repo')
246
+ end
247
+
248
+ it 'should return empty array when no remote repositories found' do
249
+ Hg.should_receive(:hg).with('paths').and_return "\n"
250
+ Hg.send(:remote).should be_empty
251
+ end
252
+
253
+ it 'should return empty array when no default-push remote repository found' do
254
+ Hg.should_receive(:hg).with('paths').and_return <<-EOF
255
+ blah = https://bitbucket.org/sample-repo
256
+ EOF
257
+ Hg.send(:remote).should be_empty
258
+ end
259
+ end
260
+ end # end of Hg
261
+
262
+
203
263
  describe Git do
204
264
  describe '#uncommitted_files' do
205
265
  it 'should return an empty array on a clean repository' do
@@ -346,6 +406,11 @@ end # of Buildr::Svn
346
406
 
347
407
  describe Release do
348
408
  describe 'find' do
409
+ it 'should return HgRelease if project uses Hg' do
410
+ write '.hg/requires'
411
+ Release.find.should be_instance_of(HgRelease)
412
+ end
413
+
349
414
  it 'should return GitRelease if project uses Git' do
350
415
  write '.git/config'
351
416
  Release.find.should be_instance_of(GitRelease)
@@ -679,6 +744,58 @@ shared_examples_for 'a release process' do
679
744
  end
680
745
 
681
746
 
747
+ describe HgRelease do
748
+ it_should_behave_like 'a release process'
749
+
750
+ before do
751
+ write 'buildfile', "VERSION_NUMBER = '1.0.0-SNAPSHOT'"
752
+ @release = HgRelease.new
753
+ Hg.stub!(:hg)
754
+ Hg.stub!(:remote).and_return('https://bitbucket.org/sample-repo')
755
+ Hg.stub!(:current_branch).and_return('default')
756
+ end
757
+
758
+ describe '#applies_to?' do
759
+ it 'should reject a non-hg repo' do
760
+ Dir.chdir(Dir.tmpdir) do
761
+ HgRelease.applies_to?.should be_false
762
+ end
763
+ end
764
+
765
+ it 'should accept a hg repo' do
766
+ FileUtils.mkdir '.hg'
767
+ FileUtils.touch File.join('.hg', 'requires')
768
+ HgRelease.applies_to?.should be_true
769
+ end
770
+ end
771
+
772
+ describe '#check' do
773
+ before do
774
+ @release = HgRelease.new
775
+ @release.send(:this_version=, '1.0.0-SNAPSHOT')
776
+ end
777
+
778
+ it 'should accept a clean repo' do
779
+ Hg.should_receive(:uncommitted_files).and_return([])
780
+ Hg.should_receive(:remote).and_return(["http://bitbucket.org/sample-repo"])
781
+ lambda { @release.check }.should_not raise_error
782
+ end
783
+
784
+ it 'should reject a dirty repo' do
785
+ Hg.should_receive(:uncommitted_files).and_return(['dirty_file.txt'])
786
+ lambda { @release.check }.should raise_error(RuntimeError, /uncommitted files/i)
787
+ end
788
+
789
+ it 'should reject a local branch not tracking a remote repo' do
790
+ Hg.should_receive(:uncommitted_files).and_return([])
791
+ Hg.should_receive(:remote).and_return([])
792
+ lambda{ @release.check }.should raise_error(RuntimeError,
793
+ "You are releasing from a local branch that does not track a remote!")
794
+ end
795
+ end
796
+ end
797
+
798
+
682
799
  describe GitRelease do
683
800
  it_should_behave_like 'a release process'
684
801
 
data/spec/core/cc_spec.rb CHANGED
@@ -72,7 +72,7 @@ describe Buildr::CCTask do
72
72
  foo.cc.invoke
73
73
  end
74
74
 
75
- sleep 1
75
+ wait_while { foo.test.compile.run_count != 1 }
76
76
 
77
77
  foo.compile.run_count.should == 1
78
78
  foo.test.compile.run_count.should == 1
@@ -96,25 +96,15 @@ describe Buildr::CCTask do
96
96
  end
97
97
  end
98
98
 
99
- #Ick! Try to get the sleeping enough on each platform that the tests reliably pass
100
- sleep 1 if RUBY_VERSION >= '1.9' && !RUBY_PLATFORM[/java/]
101
- sleep 5 if RUBY_VERSION >= '1.8.7' && !RUBY_PLATFORM[/java/]
102
- sleep 1 if RUBY_PLATFORM[/java/]
99
+ wait_while { foo.test.compile.run_count != 1 }
103
100
 
104
101
  foo.compile.run_count.should == 1
105
102
  foo.test.compile.run_count.should == 1
106
103
  foo.resources.run_count.should == 1
107
104
 
108
- # Wait some time as the timestamp needs to be different on files.
109
- sleep 3 if Buildr::Util.win_os?
110
- sleep 1 unless Buildr::Util.win_os?
105
+ modify_file_times(File.join(Dir.pwd, 'src/main/java/Example.java'))
111
106
 
112
- touch File.join(Dir.pwd, 'src/main/java/Example.java')
113
-
114
- #Ick! Try to get the sleeping enough on each platform that the tests reliably pass
115
- sleep 1 if RUBY_VERSION >= '1.9' && !RUBY_PLATFORM[/java/]
116
- sleep 5 if RUBY_VERSION >= '1.8.7' && !RUBY_PLATFORM[/java/]
117
- sleep 1 if RUBY_PLATFORM[/java/]
107
+ wait_while { foo.test.compile.run_count != 2 }
118
108
 
119
109
  foo.compile.run_count.should == 2
120
110
  foo.test.compile.run_count.should == 2
@@ -142,17 +132,18 @@ describe Buildr::CCTask do
142
132
  end
143
133
  end
144
134
 
145
- sleep 1
135
+ wait_while { foo.test.compile.run_count != 1 }
146
136
 
147
137
  foo.compile.run_count.should == 1
148
138
  foo.test.compile.run_count.should == 1
149
139
  foo.resources.run_count.should == 1
150
140
 
151
141
  file("foo/target/classes/Example.class").should exist
142
+
152
143
  tstamp = File.mtime("foo/target/classes/Example.class")
153
- touch File.join(Dir.pwd, 'foo/src/main/java/Example.java')
154
144
 
155
- sleep 1
145
+ modify_file_times(File.join(Dir.pwd, 'foo/src/main/java/Example.java'))
146
+ wait_while { foo.test.compile.run_count != 2 }
156
147
 
157
148
  foo.compile.run_count.should == 2
158
149
  foo.test.compile.run_count.should == 2
@@ -162,6 +153,23 @@ describe Buildr::CCTask do
162
153
  thread.exit
163
154
  end
164
155
 
156
+ def modify_file_times(filename)
157
+ # Sleep prior to touch so works with filesystems with low resolutions
158
+ t1 = File.mtime(filename)
159
+ while t1 == File.mtime(filename)
160
+ sleep 1
161
+ touch filename
162
+ end
163
+ end
164
+
165
+ def wait_while(&block)
166
+ sleep_count = 0
167
+ while block.call && sleep_count < 15
168
+ sleep 1
169
+ sleep_count += 1
170
+ end
171
+ end
172
+
165
173
  it 'should support parent and subprojects' do |spec|
166
174
  write 'foo/src/main/java/Example.java', "public class Example {}"
167
175
  write 'foo/src/test/java/ExampleTest.java', "public class ExampleTest {}"
@@ -179,6 +187,8 @@ describe Buildr::CCTask do
179
187
  define('bar')
180
188
  end
181
189
 
190
+ time = Time.now
191
+
182
192
  all = projects("container", "container:foo", "container:bar")
183
193
  all.each { |p| instrument_project(p) }
184
194
 
@@ -191,7 +201,7 @@ describe Buildr::CCTask do
191
201
  end
192
202
  end
193
203
 
194
- sleep 2
204
+ wait_while { all.any? { |p| p.test.compile.run_count != 1 } }
195
205
 
196
206
  all.each do |p|
197
207
  p.compile.run_count.should == 1
@@ -202,14 +212,17 @@ describe Buildr::CCTask do
202
212
  file("foo/target/classes/Example.class").should exist
203
213
  tstamp = File.mtime("foo/target/classes/Example.class")
204
214
 
205
- touch 'foo/src/main/java/Example.java'
206
- sleep 2
215
+ modify_file_times('foo/src/main/java/Example.java')
216
+ wait_while { project("container:foo").test.compile.run_count != 2 }
207
217
 
208
218
  project("container:foo").tap do |p|
209
219
  p.compile.run_count.should == 2
210
220
  p.test.compile.run_count.should == 2
211
221
  p.resources.run_count.should == 2
212
222
  end
223
+
224
+ wait_while { project("container").resources.run_count != 2 }
225
+
213
226
  project("container").tap do |p|
214
227
  p.compile.run_count.should == 1 # not_needed
215
228
  p.test.compile.run_count.should == 1 # not_needed
@@ -217,8 +230,9 @@ describe Buildr::CCTask do
217
230
  end
218
231
  File.mtime("foo/target/classes/Example.class").should_not == tstamp
219
232
 
220
- touch 'src/main/java/Example.java'
221
- sleep 2
233
+ modify_file_times('src/main/java/Example.java')
234
+
235
+ wait_while { project("container").resources.run_count != 3 }
222
236
 
223
237
  project("container").tap do |p|
224
238
  p.compile.run_count.should == 2