realityforge-buildr 1.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.md +3 -0
  6. data/Rakefile +50 -0
  7. data/addon/buildr/checkstyle-report.xsl +104 -0
  8. data/addon/buildr/checkstyle.rb +254 -0
  9. data/addon/buildr/git_auto_version.rb +36 -0
  10. data/addon/buildr/gpg.rb +90 -0
  11. data/addon/buildr/gwt.rb +413 -0
  12. data/addon/buildr/jacoco.rb +161 -0
  13. data/addon/buildr/pmd.rb +185 -0
  14. data/addon/buildr/single_intermediate_layout.rb +71 -0
  15. data/addon/buildr/spotbugs.rb +265 -0
  16. data/addon/buildr/top_level_generate_dir.rb +37 -0
  17. data/addon/buildr/wsgen.rb +192 -0
  18. data/bin/buildr +20 -0
  19. data/buildr.gemspec +61 -0
  20. data/lib/buildr.rb +86 -0
  21. data/lib/buildr/core/application.rb +705 -0
  22. data/lib/buildr/core/assets.rb +96 -0
  23. data/lib/buildr/core/build.rb +587 -0
  24. data/lib/buildr/core/common.rb +167 -0
  25. data/lib/buildr/core/compile.rb +599 -0
  26. data/lib/buildr/core/console.rb +124 -0
  27. data/lib/buildr/core/doc.rb +275 -0
  28. data/lib/buildr/core/environment.rb +128 -0
  29. data/lib/buildr/core/filter.rb +405 -0
  30. data/lib/buildr/core/help.rb +114 -0
  31. data/lib/buildr/core/progressbar.rb +161 -0
  32. data/lib/buildr/core/project.rb +994 -0
  33. data/lib/buildr/core/test.rb +776 -0
  34. data/lib/buildr/core/transports.rb +456 -0
  35. data/lib/buildr/core/util.rb +77 -0
  36. data/lib/buildr/ide/idea.rb +1664 -0
  37. data/lib/buildr/java/commands.rb +230 -0
  38. data/lib/buildr/java/compiler.rb +85 -0
  39. data/lib/buildr/java/custom_pom.rb +300 -0
  40. data/lib/buildr/java/doc.rb +62 -0
  41. data/lib/buildr/java/packaging.rb +393 -0
  42. data/lib/buildr/java/pom.rb +191 -0
  43. data/lib/buildr/java/test_result.rb +54 -0
  44. data/lib/buildr/java/tests.rb +111 -0
  45. data/lib/buildr/packaging/archive.rb +586 -0
  46. data/lib/buildr/packaging/artifact.rb +1113 -0
  47. data/lib/buildr/packaging/artifact_namespace.rb +1010 -0
  48. data/lib/buildr/packaging/artifact_search.rb +138 -0
  49. data/lib/buildr/packaging/package.rb +237 -0
  50. data/lib/buildr/packaging/version_requirement.rb +189 -0
  51. data/lib/buildr/packaging/zip.rb +189 -0
  52. data/lib/buildr/packaging/ziptask.rb +387 -0
  53. data/lib/buildr/version.rb +18 -0
  54. data/rakelib/release.rake +99 -0
  55. data/spec/addon/checkstyle_spec.rb +58 -0
  56. data/spec/core/application_spec.rb +576 -0
  57. data/spec/core/build_spec.rb +922 -0
  58. data/spec/core/common_spec.rb +670 -0
  59. data/spec/core/compile_spec.rb +656 -0
  60. data/spec/core/console_spec.rb +65 -0
  61. data/spec/core/doc_spec.rb +194 -0
  62. data/spec/core/extension_spec.rb +200 -0
  63. data/spec/core/project_spec.rb +736 -0
  64. data/spec/core/test_spec.rb +1131 -0
  65. data/spec/core/transport_spec.rb +452 -0
  66. data/spec/core/util_spec.rb +154 -0
  67. data/spec/ide/idea_spec.rb +1952 -0
  68. data/spec/java/commands_spec.rb +79 -0
  69. data/spec/java/compiler_spec.rb +274 -0
  70. data/spec/java/custom_pom_spec.rb +165 -0
  71. data/spec/java/doc_spec.rb +55 -0
  72. data/spec/java/packaging_spec.rb +786 -0
  73. data/spec/java/pom_spec.rb +162 -0
  74. data/spec/java/test_coverage_helper.rb +257 -0
  75. data/spec/java/tests_spec.rb +224 -0
  76. data/spec/packaging/archive_spec.rb +686 -0
  77. data/spec/packaging/artifact_namespace_spec.rb +757 -0
  78. data/spec/packaging/artifact_spec.rb +1351 -0
  79. data/spec/packaging/packaging_helper.rb +63 -0
  80. data/spec/packaging/packaging_spec.rb +690 -0
  81. data/spec/sandbox.rb +166 -0
  82. data/spec/spec_helpers.rb +420 -0
  83. data/spec/version_requirement_spec.rb +145 -0
  84. data/spec/xpath_matchers.rb +123 -0
  85. metadata +295 -0
@@ -0,0 +1,452 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18
+
19
+
20
+ describe URI, '#download' do
21
+ before do
22
+ write @source = File.expand_path('source'), @content = 'A file to download'
23
+ @uri = URI(URI.escape("file://#{@source}"))
24
+ @target = File.expand_path('target')
25
+ rm_f @target
26
+ end
27
+
28
+ it 'should download file if found' do
29
+ @uri.download @target
30
+ file(@target).should contain(@content)
31
+ end
32
+
33
+ it 'should fail if file not found' do
34
+ lambda { (@uri + 'missing').download @target }.should raise_error(URI::NotFoundError)
35
+ file(@target).should_not exist
36
+ end
37
+
38
+ it 'should work the same way from static method with URI' do
39
+ URI.download @uri, @target
40
+ file(@target).should contain(@content)
41
+ end
42
+
43
+ it 'should work the same way from static method with String' do
44
+ URI.download @uri.to_s, @target
45
+ file(@target).should contain(@content)
46
+ end
47
+
48
+ it 'should download to a task' do
49
+ @uri.download file(@target)
50
+ file(@target).should contain(@content)
51
+ end
52
+
53
+ it 'should download to a file' do
54
+ File.open(@target, 'w') { |file| @uri.download file }
55
+ file(@target).should contain(@content)
56
+ end
57
+ end
58
+
59
+
60
+ describe URI, '#upload' do
61
+ before do
62
+ write @source = 'source', @content = 'Just a file'
63
+ @target = File.expand_path('target')
64
+ rm_rf @target
65
+ @uri = URI(URI.escape("file://#{@target}"))
66
+ end
67
+
68
+ it 'should preserve file permissions if uploading to a file' do
69
+ File.chmod(0666, @source)
70
+ s = File.stat(@source).mode
71
+ @uri.upload @source
72
+ File.stat(@target).mode.should eql(s)
73
+ end
74
+
75
+ it 'should upload file if found' do
76
+ @uri.upload @source
77
+ file(@target).should contain(@content)
78
+ end
79
+
80
+ it 'should fail if file not found' do
81
+ lambda { @uri.upload @source.ext('missing') }.should raise_error(URI::NotFoundError)
82
+ file(@target).should_not exist
83
+ end
84
+
85
+ it 'should work the same way from static method with URI' do
86
+ URI.upload @uri, @source
87
+ file(@target).should contain(@content)
88
+ end
89
+
90
+ it 'should work the same way from static method with String' do
91
+ URI.upload @uri.to_s, @source
92
+ file(@target).should contain(@content)
93
+ end
94
+
95
+ it 'should upload from a task' do
96
+ @uri.upload file(@source)
97
+ file(@target).should contain(@content)
98
+ end
99
+
100
+ it 'should create MD5 hash' do
101
+ @uri.upload file(@source)
102
+ file(@target.ext('.md5')).should contain(Digest::MD5.hexdigest(@content))
103
+ end
104
+
105
+ it 'should create SHA1 hash' do
106
+ @uri.upload file(@source)
107
+ file(@target.ext('.sha1')).should contain(Digest::SHA1.hexdigest(@content))
108
+ end
109
+
110
+ it 'should upload an entire directory' do
111
+ mkpath 'dir' ; write 'dir/test', 'in directory'
112
+ mkpath 'dir/nested' ; write 'dir/nested/test', 'in nested directory'
113
+ @uri.upload 'dir'
114
+ file(@target + '/test').should contain('in directory')
115
+ file(@target + '/nested/test').should contain('in nested directory')
116
+ end
117
+ end
118
+
119
+
120
+ describe URI::FILE do
121
+
122
+ it 'should accept file:something as file:///something' do
123
+ URI('file:something').should eql(URI('file:///something'))
124
+ end
125
+
126
+ it 'should accept file:/ as file:///' do
127
+ URI('file:/').should eql(URI('file:///'))
128
+ end
129
+
130
+ it 'should accept file:/something as file:///something' do
131
+ URI('file:/something').should eql(URI('file:///something'))
132
+ end
133
+
134
+ it 'should accept file://something as file://something/' do
135
+ URI('file://something').should eql(URI('file://something/'))
136
+ end
137
+
138
+ it 'should accept file:///something' do
139
+ URI('file:///something').should be_kind_of(URI::FILE)
140
+ URI('file:///something').to_s.should eql('file:///something')
141
+ URI('file:///something').path.should eql('/something')
142
+ end
143
+
144
+ it 'should treat host as path when host name is a Windows drive' do
145
+ URI('file://c:/something').should eql(URI('file:///c:/something'))
146
+ end
147
+ end
148
+
149
+
150
+ describe URI::FILE, '#read' do
151
+ before do
152
+ @filename = 'readme'
153
+ @uri = URI(URI.escape("file:///#{File.expand_path(@filename)}"))
154
+ @content = 'Readme. Please!'
155
+ write 'readme', @content
156
+ end
157
+
158
+ it 'should not complain about excessive options' do
159
+ @uri.read :proxy=>[], :lovely=>true
160
+ end
161
+
162
+ it 'should read the file' do
163
+ @uri.read.should eql(@content)
164
+ end
165
+
166
+ it 'should read the file and yield to block' do
167
+ @uri.read { |content| content.should eql(@content) }
168
+ end
169
+
170
+ it 'should raise NotFoundError if file doesn\'t exist' do
171
+ lambda { (@uri + 'notme').read }.should raise_error(URI::NotFoundError)
172
+ end
173
+
174
+ it 'should raise NotFoundError if file is actually a directory' do
175
+ mkpath 'dir'
176
+ lambda { (@uri + 'dir').read }.should raise_error(URI::NotFoundError)
177
+ end
178
+ end
179
+
180
+
181
+ describe URI::FILE, '#write' do
182
+ before do
183
+ @filename = 'readme'
184
+ @uri = URI(URI.escape("file:///#{File.expand_path(@filename)}"))
185
+ @content = 'Readme. Please!'
186
+ end
187
+
188
+ it 'should not complain about excessive options' do
189
+ @uri.write @content, :proxy=>[], :lovely=>true
190
+ end
191
+
192
+ it 'should write the file from a string' do
193
+ @uri.write @content
194
+ read(@filename).should eql(@content)
195
+ end
196
+
197
+ it 'should write the file from a reader' do
198
+ reader = Object.new
199
+ class << reader
200
+ def read(bytes) ; @array.pop ; end
201
+ end
202
+ reader.instance_variable_set :@array, [@content]
203
+ @uri.write reader
204
+ read(@filename).should eql(@content)
205
+ end
206
+
207
+ it 'should write the file from a block' do
208
+ array = [@content]
209
+ @uri.write { array.pop }
210
+ read(@filename).should eql(@content)
211
+ end
212
+
213
+ it 'should not create file if read fails' do
214
+ @uri.write { fail } rescue nil
215
+ file(@filename).should_not exist
216
+ end
217
+ end
218
+
219
+
220
+ def default_http_headers
221
+ {"Cache-Control" => "no-cache", "User-Agent" => "Buildr-#{Buildr::VERSION}"}
222
+ end
223
+
224
+ describe URI::HTTP, '#read' do
225
+ before do
226
+ @proxy = 'http://john:smith@myproxy:8080'
227
+ @domain = 'domain'
228
+ @host_domain = "host.#{@domain}"
229
+ @path = "/foo/bar/baz"
230
+ @query = "?query"
231
+ @uri = URI("http://#{@host_domain}#{@path}#{@query}")
232
+ @no_proxy_args = [@host_domain, 80]
233
+ @proxy_args = @no_proxy_args + ['myproxy', 8080, 'john', 'smith']
234
+ @http = double('http')
235
+ @http.stub(:request).and_yield(Net::HTTPNotModified.new(nil, nil, nil))
236
+ end
237
+
238
+ it 'should not use proxy unless proxy is set' do
239
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
240
+ @uri.read
241
+ end
242
+
243
+ it 'should use HTTPS if applicable' do
244
+ Net::HTTP.should_receive(:new).with(@host_domain, 443).and_return(@http)
245
+ @http.should_receive(:use_ssl=).with(true)
246
+ URI(@uri.to_s.sub(/http/, 'https')).read
247
+ end
248
+
249
+ it 'should use custom SSL CA certificates if provided through the environment variable SSL_CA_CERTS' do
250
+ ENV['SSL_VERIFY_MODE'] = 'VERIFY_PEER'
251
+ Net::HTTP.should_receive(:new).with(@host_domain, 443).and_return(@http)
252
+ @http.should_receive(:use_ssl=).with(true)
253
+ @http.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
254
+ URI(@uri.to_s.sub(/http/, 'https')).read
255
+ end
256
+
257
+ it 'should use custom verify mode if provided through the environment variable SSL_VERIFY_MODE' do
258
+ ENV['SSL_CA_CERTS'] = 'tmp/certs'
259
+ Net::HTTP.should_receive(:new).with(@host_domain, 443).and_return(@http)
260
+ @http.should_receive(:use_ssl=).with(true)
261
+ @http.should_receive(:ca_path=).with('tmp/certs')
262
+ URI(@uri.to_s.sub(/http/, 'https')).read
263
+ end
264
+
265
+ it 'should use proxy from environment variable HTTP_PROXY when using http' do
266
+ ENV['HTTP_PROXY'] = @proxy
267
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
268
+ @uri.read
269
+ end
270
+
271
+ it 'should use proxy from environment variable HTTPS_PROXY when using https' do
272
+ ENV['HTTPS_PROXY'] = @proxy
273
+ Net::HTTP.should_receive(:new).with(@host_domain, 443, 'myproxy', 8080, 'john', 'smith').and_return(@http)
274
+ @http.should_receive(:use_ssl=).with(true)
275
+ URI(@uri.to_s.sub(/http/, 'https')).read
276
+ end
277
+
278
+ it 'should not use proxy for hosts from environment variable NO_PROXY' do
279
+ ENV['HTTP_PROXY'] = @proxy
280
+ ENV['NO_PROXY'] = @host_domain
281
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
282
+ @uri.read
283
+ end
284
+
285
+ it 'should use proxy for hosts other than those specified by NO_PROXY' do
286
+ ENV['HTTP_PROXY'] = @proxy
287
+ ENV['NO_PROXY'] = 'whatever'
288
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
289
+ @uri.read
290
+ end
291
+
292
+ it 'should support comma separated list in environment variable NO_PROXY' do
293
+ ENV['HTTP_PROXY'] = @proxy
294
+ ENV['NO_PROXY'] = 'optimus,prime'
295
+ Net::HTTP.should_receive(:new).with('optimus', 80).and_return(@http)
296
+ URI('http://optimus').read
297
+ Net::HTTP.should_receive(:new).with('prime', 80).and_return(@http)
298
+ URI('http://prime').read
299
+ Net::HTTP.should_receive(:new).with('bumblebee', *@proxy_args[1..-1]).and_return(@http)
300
+ URI('http://bumblebee').read
301
+ end
302
+
303
+ it 'should support glob pattern in NO_PROXY' do
304
+ ENV['HTTP_PROXY'] = @proxy
305
+ ENV['NO_PROXY'] = "*.#{@domain}"
306
+ Net::HTTP.should_receive(:new).once.with(*@no_proxy_args).and_return(@http)
307
+ @uri.read
308
+ end
309
+
310
+ it 'should support specific port in NO_PROXY' do
311
+ ENV['HTTP_PROXY'] = @proxy
312
+ ENV['NO_PROXY'] = "#{@host_domain}:80"
313
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
314
+ @uri.read
315
+ ENV['NO_PROXY'] = "#{@host_domain}:800"
316
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
317
+ @uri.read
318
+ end
319
+
320
+ it 'should not die if content size is zero' do
321
+ ok = Net::HTTPOK.new(nil, nil, nil)
322
+ ok.stub(:read_body)
323
+ @http.stub(:request).and_yield(ok)
324
+ Net::HTTP.should_receive(:new).and_return(@http)
325
+ $stdout.should_receive(:isatty).and_return(false)
326
+ @uri.read :progress=>true
327
+ end
328
+
329
+ it 'should use HTTP Basic authentication' do
330
+ Net::HTTP.should_receive(:new).and_return(@http)
331
+ request = double('request')
332
+ Net::HTTP::Get.should_receive(:new).and_return(request)
333
+ request.should_receive(:basic_auth).with('john', 'secret')
334
+ URI("http://john:secret@#{@host_domain}").read
335
+ end
336
+
337
+ it 'should preseve authentication information during a redirect' do
338
+ Net::HTTP.should_receive(:new).twice.and_return(@http)
339
+
340
+ # The first request will produce a redirect
341
+ redirect = Net::HTTPRedirection.new(nil, nil, nil)
342
+ redirect['Location'] = "http://#{@host_domain}/asdf"
343
+
344
+ request1 = double('request1')
345
+ Net::HTTP::Get.should_receive(:new).once.with('/', default_http_headers).and_return(request1)
346
+ request1.should_receive(:basic_auth).with('john', 'secret')
347
+ @http.should_receive(:request).with(request1).and_yield(redirect)
348
+
349
+ # The second request will be ok
350
+ ok = Net::HTTPOK.new(nil, nil, nil)
351
+ ok.stub(:read_body)
352
+
353
+ request2 = double('request2')
354
+ Net::HTTP::Get.should_receive(:new).once.with("/asdf", default_http_headers).and_return(request2)
355
+ request2.should_receive(:basic_auth).with('john', 'secret')
356
+ @http.should_receive(:request).with(request2).and_yield(ok)
357
+
358
+ URI("http://john:secret@#{@host_domain}").read
359
+ end
360
+
361
+ it 'should include the query part when performing HTTP GET' do
362
+ # should this test be generalized or shared with any other URI subtypes?
363
+ Net::HTTP.stub(:new).and_return(@http)
364
+ Net::HTTP::Get.should_receive(:new).with(/#{Regexp.escape(@query)}$/, default_http_headers)
365
+ @uri.read
366
+ end
367
+
368
+ end
369
+
370
+
371
+ describe URI::HTTP, '#write' do
372
+ before do
373
+ @content = 'Readme. Please!'
374
+ @uri = URI('http://john:secret@host.domain/foo/bar/baz.jar')
375
+ @http = double('Net::HTTP')
376
+ @http.stub(:request).and_return(Net::HTTPOK.new(nil, nil, nil))
377
+ @http.should_receive(:read_timeout=).with(500)
378
+ Net::HTTP.stub(:new).and_return(@http)
379
+ end
380
+
381
+ it 'should open connection to HTTP server' do
382
+ Net::HTTP.should_receive(:new).with('host.domain', 80).and_return(@http)
383
+ @uri.write @content
384
+ end
385
+
386
+ it 'should use HTTP basic authentication' do
387
+ @http.should_receive(:request) do |request|
388
+ request['authorization'].should == ('Basic ' + ['john:secret'].pack('m').delete("\r\n"))
389
+ Net::HTTPOK.new(nil, nil, nil)
390
+ end
391
+ @uri.write @content
392
+ end
393
+
394
+ it 'should use HTTPS if applicable' do
395
+ Net::HTTP.should_receive(:new).with('host.domain', 443).and_return(@http)
396
+ @http.should_receive(:use_ssl=).with(true)
397
+ URI(@uri.to_s.sub(/http/, 'https')).write @content
398
+ end
399
+
400
+ it 'should upload file with PUT request' do
401
+ @http.should_receive(:request) do |request|
402
+ request.should be_kind_of(Net::HTTP::Put)
403
+ Net::HTTPOK.new(nil, nil, nil)
404
+ end
405
+ @uri.write @content
406
+ end
407
+
408
+ it 'should set Content-Length header' do
409
+ @http.should_receive(:request) do |request|
410
+ request.content_length.should == @content.size
411
+ Net::HTTPOK.new(nil, nil, nil)
412
+ end
413
+ @uri.write @content
414
+ end
415
+
416
+ it 'should set Content-MD5 header' do
417
+ @http.should_receive(:request) do |request|
418
+ request['Content-MD5'].should == Digest::MD5.hexdigest(@content)
419
+ Net::HTTPOK.new(nil, nil, nil)
420
+ end
421
+ @uri.write @content
422
+ end
423
+
424
+ it 'should set User-Agent header' do
425
+ @http.should_receive(:request) do |request|
426
+ request['User-Agent'].should == "Buildr-#{Buildr::VERSION}"
427
+ Net::HTTPOK.new(nil, nil, nil)
428
+ end
429
+ @uri.write @content
430
+ end
431
+
432
+ it 'should send entire content' do
433
+ @http.should_receive(:request) do |request|
434
+ body_stream = request.body_stream
435
+ body_stream.read(1024).should == @content
436
+ body_stream.read(1024).should be_nil
437
+ Net::HTTPOK.new(nil, nil, nil)
438
+ end
439
+ @uri.write @content
440
+ end
441
+
442
+ it 'should fail on 4xx response' do
443
+ @http.should_receive(:request).and_return(Net::HTTPBadRequest.new(nil, nil, nil))
444
+ lambda { @uri.write @content }.should raise_error(RuntimeError, /failed to upload/i)
445
+ end
446
+
447
+ it 'should fail on 5xx response' do
448
+ @http.should_receive(:request).and_return(Net::HTTPServiceUnavailable.new(nil, nil, nil))
449
+ lambda { @uri.write @content }.should raise_error(RuntimeError, /failed to upload/i)
450
+ end
451
+
452
+ end
@@ -0,0 +1,154 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18
+
19
+ describe OpenObject do
20
+ before do
21
+ @obj = OpenObject.new({:a => 1, :b => 2, :c => 3})
22
+ end
23
+
24
+ it "should be kind of Hash" do
25
+ Hash.should === @obj
26
+ end
27
+
28
+ it "should accept block that supplies default value" do
29
+ obj = OpenObject.new { |hash, key| hash[key] = "New #{key}" }
30
+ obj[:foo].should == "New foo"
31
+ obj.keys.should == [:foo]
32
+ end
33
+
34
+ it "should combine initial values from hash argument and from block" do
35
+ obj = OpenObject.new(:a => 6, :b => 2) { |h, k| h[k] = k.to_s * 2 }
36
+ obj[:a].should == 6
37
+ obj[:c].should == 'cc'
38
+ end
39
+
40
+ it "should allow reading a value by calling its name method" do
41
+ @obj.b.should == 2
42
+ end
43
+
44
+ it "should allow setting a value by calling its name= method" do
45
+ lambda { @obj.f = 32 }.should change { @obj.f }.to(32)
46
+ end
47
+
48
+ it "should allow changing a value by calling its name= method" do
49
+ lambda { @obj.c = 17 }.should change { @obj.c }.to(17)
50
+ end
51
+ end
52
+
53
+ describe File do
54
+ # Quite a few of the other specs depend on File#utime working correctly.
55
+ # These specs validate that utime is working as expected.
56
+ describe "#utime" do
57
+ it "should update mtime of directories" do
58
+ mkpath 'tmp'
59
+ begin
60
+ creation_time = File.mtime('tmp')
61
+
62
+ sleep 1
63
+ File.utime(nil, nil, 'tmp')
64
+
65
+ File.mtime('tmp').should > creation_time
66
+ ensure
67
+ Dir.rmdir 'tmp'
68
+ end
69
+ end
70
+
71
+ it "should update mtime of files" do
72
+ FileUtils.touch('tmp')
73
+ begin
74
+ creation_time = File.mtime('tmp')
75
+
76
+ sleep 1
77
+ File.utime(nil, nil, 'tmp')
78
+
79
+ File.mtime('tmp').should > creation_time
80
+ ensure
81
+ File.delete 'tmp'
82
+ end
83
+ end
84
+
85
+ it "should be able to set mtime in the past" do
86
+ FileUtils.touch('tmp')
87
+ begin
88
+ time = Time.at((Time.now - 10).to_i)
89
+ File.utime(time, time, 'tmp')
90
+
91
+ File.mtime('tmp').should == time
92
+ ensure
93
+ File.delete 'tmp'
94
+ end
95
+ end
96
+
97
+ it "should be able to set mtime in the future" do
98
+ FileUtils.touch('tmp')
99
+ begin
100
+ time = Time.at((Time.now + 10).to_i)
101
+ File.utime(time, time, 'tmp')
102
+
103
+ File.mtime('tmp').should == time
104
+ ensure
105
+ File.delete 'tmp'
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ describe 'Buildr::Util.tools_jar' do
112
+ before do
113
+ @old_home = ENV['JAVA_HOME']
114
+ end
115
+
116
+ describe 'when JAVA_HOME points to a JDK' do
117
+ before do
118
+ Buildr::Util.instance_eval { @tools_jar = nil }
119
+ write 'jdk/lib/tools.jar'
120
+ ENV['JAVA_HOME'] = File.expand_path('jdk')
121
+ end
122
+
123
+ it 'should return the path to tools.jar' do
124
+ Buildr::Util.tools_jar.should point_to_path('jdk/lib/tools.jar')
125
+ end
126
+ end
127
+
128
+ describe 'when JAVA_HOME points to a JRE inside a JDK' do
129
+ before do
130
+ Buildr::Util.instance_eval { @tools_jar = nil }
131
+ write 'jdk/lib/tools.jar'
132
+ ENV['JAVA_HOME'] = File.expand_path('jdk/jre')
133
+ end
134
+
135
+ it 'should return the path to tools.jar' do
136
+ Buildr::Util.tools_jar.should point_to_path('jdk/lib/tools.jar')
137
+ end
138
+ end
139
+
140
+ describe 'when there is no tools.jar' do
141
+ before do
142
+ Buildr::Util.instance_eval { @tools_jar = nil }
143
+ ENV['JAVA_HOME'] = File.expand_path('jdk')
144
+ end
145
+
146
+ it 'should return nil' do
147
+ Buildr::Util.tools_jar.should be_nil
148
+ end
149
+ end
150
+
151
+ after do
152
+ ENV['JAVA_HOME'] = @old_home
153
+ end
154
+ end