buildr 1.3.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. data/CHANGELOG +780 -0
  2. data/DISCLAIMER +7 -0
  3. data/KEYS +151 -0
  4. data/LICENSE +176 -0
  5. data/NOTICE +31 -0
  6. data/README +173 -0
  7. data/Rakefile +63 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +232 -0
  10. data/addon/buildr/hibernate.rb +142 -0
  11. data/addon/buildr/javacc.rb +85 -0
  12. data/addon/buildr/jdepend.rb +60 -0
  13. data/addon/buildr/jetty.rb +248 -0
  14. data/addon/buildr/nailgun.rb +892 -0
  15. data/addon/buildr/openjpa.rb +90 -0
  16. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  17. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  18. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  19. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  20. data/addon/buildr/xmlbeans.rb +93 -0
  21. data/bin/buildr +21 -0
  22. data/buildr.gemspec +50 -0
  23. data/doc/css/default.css +225 -0
  24. data/doc/css/print.css +95 -0
  25. data/doc/css/syntax.css +43 -0
  26. data/doc/images/apache-incubator-logo.png +0 -0
  27. data/doc/images/buildr-hires.png +0 -0
  28. data/doc/images/buildr.png +0 -0
  29. data/doc/images/note.png +0 -0
  30. data/doc/images/tip.png +0 -0
  31. data/doc/images/zbuildr.tif +0 -0
  32. data/doc/pages/artifacts.textile +317 -0
  33. data/doc/pages/building.textile +501 -0
  34. data/doc/pages/contributing.textile +178 -0
  35. data/doc/pages/download.textile +25 -0
  36. data/doc/pages/extending.textile +229 -0
  37. data/doc/pages/getting_started.textile +337 -0
  38. data/doc/pages/index.textile +63 -0
  39. data/doc/pages/mailing_lists.textile +17 -0
  40. data/doc/pages/more_stuff.textile +367 -0
  41. data/doc/pages/packaging.textile +592 -0
  42. data/doc/pages/projects.textile +449 -0
  43. data/doc/pages/recipes.textile +127 -0
  44. data/doc/pages/settings_profiles.textile +339 -0
  45. data/doc/pages/testing.textile +475 -0
  46. data/doc/pages/troubleshooting.textile +121 -0
  47. data/doc/pages/whats_new.textile +389 -0
  48. data/doc/print.haml +52 -0
  49. data/doc/print.toc.yaml +28 -0
  50. data/doc/scripts/buildr-git.rb +411 -0
  51. data/doc/scripts/install-jruby.sh +44 -0
  52. data/doc/scripts/install-linux.sh +64 -0
  53. data/doc/scripts/install-osx.sh +52 -0
  54. data/doc/site.haml +55 -0
  55. data/doc/site.toc.yaml +44 -0
  56. data/lib/buildr.rb +47 -0
  57. data/lib/buildr/core.rb +27 -0
  58. data/lib/buildr/core/application.rb +373 -0
  59. data/lib/buildr/core/application_cli.rb +134 -0
  60. data/lib/buildr/core/build.rb +262 -0
  61. data/lib/buildr/core/checks.rb +382 -0
  62. data/lib/buildr/core/common.rb +155 -0
  63. data/lib/buildr/core/compile.rb +594 -0
  64. data/lib/buildr/core/environment.rb +120 -0
  65. data/lib/buildr/core/filter.rb +258 -0
  66. data/lib/buildr/core/generate.rb +195 -0
  67. data/lib/buildr/core/help.rb +118 -0
  68. data/lib/buildr/core/progressbar.rb +156 -0
  69. data/lib/buildr/core/project.rb +890 -0
  70. data/lib/buildr/core/test.rb +690 -0
  71. data/lib/buildr/core/transports.rb +486 -0
  72. data/lib/buildr/core/util.rb +235 -0
  73. data/lib/buildr/ide.rb +19 -0
  74. data/lib/buildr/ide/eclipse.rb +181 -0
  75. data/lib/buildr/ide/idea.ipr.template +300 -0
  76. data/lib/buildr/ide/idea.rb +194 -0
  77. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  78. data/lib/buildr/ide/idea7x.rb +210 -0
  79. data/lib/buildr/java.rb +26 -0
  80. data/lib/buildr/java/ant.rb +71 -0
  81. data/lib/buildr/java/bdd_frameworks.rb +267 -0
  82. data/lib/buildr/java/commands.rb +210 -0
  83. data/lib/buildr/java/compilers.rb +432 -0
  84. data/lib/buildr/java/deprecated.rb +141 -0
  85. data/lib/buildr/java/groovyc.rb +137 -0
  86. data/lib/buildr/java/jruby.rb +99 -0
  87. data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
  88. data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
  89. data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
  90. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  91. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
  92. data/lib/buildr/java/packaging.rb +706 -0
  93. data/lib/buildr/java/pom.rb +178 -0
  94. data/lib/buildr/java/rjb.rb +142 -0
  95. data/lib/buildr/java/test_frameworks.rb +290 -0
  96. data/lib/buildr/java/version_requirement.rb +172 -0
  97. data/lib/buildr/packaging.rb +21 -0
  98. data/lib/buildr/packaging/artifact.rb +729 -0
  99. data/lib/buildr/packaging/artifact_namespace.rb +957 -0
  100. data/lib/buildr/packaging/artifact_search.rb +140 -0
  101. data/lib/buildr/packaging/gems.rb +102 -0
  102. data/lib/buildr/packaging/package.rb +233 -0
  103. data/lib/buildr/packaging/tar.rb +104 -0
  104. data/lib/buildr/packaging/zip.rb +719 -0
  105. data/rakelib/apache.rake +126 -0
  106. data/rakelib/changelog.rake +56 -0
  107. data/rakelib/doc.rake +103 -0
  108. data/rakelib/package.rake +44 -0
  109. data/rakelib/release.rake +53 -0
  110. data/rakelib/rspec.rake +81 -0
  111. data/rakelib/rubyforge.rake +45 -0
  112. data/rakelib/scm.rake +49 -0
  113. data/rakelib/setup.rake +59 -0
  114. data/rakelib/stage.rake +45 -0
  115. data/spec/application_spec.rb +316 -0
  116. data/spec/archive_spec.rb +494 -0
  117. data/spec/artifact_namespace_spec.rb +635 -0
  118. data/spec/artifact_spec.rb +738 -0
  119. data/spec/build_spec.rb +193 -0
  120. data/spec/checks_spec.rb +537 -0
  121. data/spec/common_spec.rb +579 -0
  122. data/spec/compile_spec.rb +561 -0
  123. data/spec/groovy_compilers_spec.rb +239 -0
  124. data/spec/java_bdd_frameworks_spec.rb +238 -0
  125. data/spec/java_compilers_spec.rb +446 -0
  126. data/spec/java_packaging_spec.rb +1042 -0
  127. data/spec/java_test_frameworks_spec.rb +414 -0
  128. data/spec/packaging_helper.rb +63 -0
  129. data/spec/packaging_spec.rb +589 -0
  130. data/spec/project_spec.rb +739 -0
  131. data/spec/sandbox.rb +116 -0
  132. data/spec/scala_compilers_spec.rb +239 -0
  133. data/spec/spec.opts +6 -0
  134. data/spec/spec_helpers.rb +283 -0
  135. data/spec/test_spec.rb +871 -0
  136. data/spec/transport_spec.rb +300 -0
  137. data/spec/version_requirement_spec.rb +115 -0
  138. metadata +324 -0
@@ -0,0 +1,579 @@
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.join(File.dirname(__FILE__), 'spec_helpers')
18
+
19
+ describe Buildr.method(:struct) do
20
+ before do
21
+ @hash = { :foo=>'foo:jar', :bar=>'bar:jar' }
22
+ @struct = struct(@hash)
23
+ end
24
+
25
+ it 'should be object with key-value pairs' do
26
+ @struct.foo.should eql('foo:jar')
27
+ @struct.bar.should eql('bar:jar')
28
+ end
29
+
30
+ it 'should fail when requesting non-existent key' do
31
+ lambda { @struct.foobar }.should raise_error(NoMethodError)
32
+ end
33
+
34
+ it 'should return members when requested' do
35
+ @struct.members.sort.should eql(@hash.keys.map(&:to_s).sort)
36
+ end
37
+
38
+ it 'should return valued when requested' do
39
+ @struct.values.sort.should eql(@hash.values.sort)
40
+ end
41
+ end
42
+
43
+
44
+ describe Buildr.method(:write) do
45
+ it 'should create path' do
46
+ write 'foo/test'
47
+ File.directory?('foo').should be_true
48
+ File.exist?('foo/test').should be_true
49
+ end
50
+
51
+ it 'should write content to file' do
52
+ write 'test', 'content'
53
+ File.read('test').should eql('content')
54
+ end
55
+
56
+ it 'should retrieve content from block, if block given' do
57
+ write('test') { 'block' }
58
+ File.read('test').should eql('block')
59
+ end
60
+
61
+ it 'should write empty file if no content provided' do
62
+ write 'test'
63
+ File.read('test').should eql('')
64
+ end
65
+
66
+ it 'should return content as a string' do
67
+ write('test', 'content').should eql('content')
68
+ end
69
+
70
+ it 'should return empty string if no content provided' do
71
+ write('test').should eql('')
72
+ end
73
+ end
74
+
75
+
76
+ describe Buildr.method(:read) do
77
+ before do
78
+ write @file = 'test', @content = 'content'
79
+ end
80
+
81
+ it 'should return contents of named file' do
82
+ read(@file).should eql(@content)
83
+ end
84
+
85
+ it 'should yield to block if block given' do
86
+ read @file do |content|
87
+ content.should eql(@content)
88
+ end
89
+ end
90
+
91
+ it 'should return block response if block given' do
92
+ read(@file) { 5 }.should be(5)
93
+ end
94
+ end
95
+
96
+
97
+ describe Buildr.method(:download) do
98
+ before do
99
+ @content = 'we has download!'
100
+ @http = mock('http')
101
+ @http.stub!(:request).and_return(Net::HTTPNotModified.new(nil, nil, nil))
102
+ end
103
+
104
+ def tasks()
105
+ [ download('http://localhost/download'), download('downloaded'=>'http://localhost/download') ]
106
+ end
107
+
108
+ it 'should be a file task' do
109
+ tasks.each { |task| task.should be_kind_of(Rake::FileTask) }
110
+ end
111
+
112
+ it 'should accept a String and download from that URL' do
113
+ download('http://localhost/download').tap do |task|
114
+ task.source.should_receive(:read).and_yield [@content]
115
+ task.invoke
116
+ task.should contain(@content)
117
+ end
118
+ end
119
+
120
+ it 'should accept a URI and download from that URL' do
121
+ download(URI.parse('http://localhost/download')).tap do |task|
122
+ task.source.should_receive(:read).and_yield [@content]
123
+ task.invoke
124
+ task.should contain(@content)
125
+ end
126
+ end
127
+
128
+ it 'should accept a path and String and download from that URL' do
129
+ download('downloaded'=>'http://localhost/download').tap do |task|
130
+ task.source.should_receive(:read).and_yield [@content]
131
+ task.invoke
132
+ task.should contain(@content)
133
+ end
134
+ end
135
+
136
+ it 'should accept a path and URI and download from that URL' do
137
+ download('downloaded'=>URI.parse('http://localhost/download')).tap do |task|
138
+ task.source.should_receive(:read).and_yield [@content]
139
+ task.invoke
140
+ task.should contain(@content)
141
+ end
142
+ end
143
+
144
+ it 'should create path for download' do
145
+ download('path/downloaded'=>URI.parse('http://localhost/download')).tap do |task|
146
+ task.source.should_receive(:read).and_yield [@content]
147
+ task.invoke
148
+ task.should contain(@content)
149
+ end
150
+ end
151
+
152
+ it 'should fail if resource not found' do
153
+ tasks.each do |task|
154
+ task.source.should_receive(:read).and_raise URI::NotFoundError
155
+ lambda { task.invoke }.should raise_error(URI::NotFoundError)
156
+ end
157
+ tasks.last.should_not exist
158
+ end
159
+
160
+ it 'should fail on any other error' do
161
+ tasks.each do |task|
162
+ task.source.should_receive(:read).and_raise RuntimeError
163
+ lambda { task.invoke }.should raise_error(RuntimeError)
164
+ end
165
+ tasks.last.should_not exist
166
+ end
167
+
168
+ it 'should execute only if file does not already exist' do
169
+ download('downloaded'=>'http://localhost/download').tap do |task|
170
+ task.source.should_not_receive(:read)
171
+ write task.to_s, 'not really'
172
+ task.invoke
173
+ end
174
+ end
175
+
176
+ it 'should execute without a proxy if none specified' do
177
+ Net::HTTP.should_receive(:new).with('localhost', 80).twice.and_return(@http)
178
+ tasks.each(&:invoke)
179
+ end
180
+
181
+ it 'should pass Buildr proxy options' do
182
+ Buildr.options.proxy.http = 'http://proxy:8080'
183
+ Net::HTTP.should_receive(:new).with('localhost', 80, 'proxy', 8080, nil, nil).twice.and_return(@http)
184
+ tasks.each(&:invoke)
185
+ end
186
+
187
+ it 'should set HTTP proxy from HTTP_PROXY environment variable' do
188
+ ENV['HTTP_PROXY'] = 'http://proxy:8080'
189
+ Net::HTTP.should_receive(:new).with('localhost', 80, 'proxy', 8080, nil, nil).twice.and_return(@http)
190
+ tasks.each(&:invoke)
191
+ end
192
+ end
193
+
194
+
195
+ describe Buildr.method(:filter) do
196
+ def source
197
+ File.expand_path('src')
198
+ end
199
+
200
+ it 'should return a Filter for the source' do
201
+ filter(source).should be_kind_of(Filter)
202
+ end
203
+
204
+ it 'should use the source directory' do
205
+ filter(source).sources.should include(file(source))
206
+ end
207
+
208
+ it 'should use the source directories' do
209
+ dirs = ['first', 'second']
210
+ filter('first', 'second').sources.should include(*dirs.map { |dir| file(File.expand_path(dir)) })
211
+ end
212
+
213
+ it 'should accept a file task' do
214
+ task = file(source)
215
+ filter(task).sources.each { |source| source.should be(task) }
216
+ end
217
+ end
218
+
219
+
220
+ describe Buildr::Filter do
221
+ before do
222
+ @filter = Filter.new
223
+ 1.upto(4) { |i| write "src/file#{i}", "file#{i} raw" } # with ${key1} and ${key2}" }
224
+ @early = Time.now - 1000
225
+ end
226
+
227
+ it 'should respond to :from and return self' do
228
+ @filter.from('src').should be(@filter)
229
+ end
230
+
231
+ it 'should respond to :from and add source directory' do
232
+ lambda { @filter.from('src') }.should change { @filter.sources }
233
+ end
234
+
235
+ it 'should respond to :from and add source directories' do
236
+ dirs = ['first', 'second']
237
+ @filter.from(*dirs)
238
+ @filter.sources.should include(*dirs.map { |dir| file(File.expand_path(dir)) })
239
+ end
240
+
241
+ it 'should return source directories as file task' do
242
+ @filter.from('src').sources.each { |source| source.should be_kind_of(Rake::FileTask) }
243
+ end
244
+
245
+ it 'should return source directories as expanded path' do
246
+ @filter.from('src').sources.each { |source| source.to_s.should eql(File.expand_path('src')) }
247
+ end
248
+
249
+ it 'should respond to :into and return self' do
250
+ @filter.into('target').should be(@filter)
251
+ end
252
+
253
+ it 'should respond to :into and set target directory' do
254
+ lambda { @filter.into('src') }.should change { @filter.target }
255
+ @filter.into('target').target.should be(file(File.expand_path('target')))
256
+ end
257
+
258
+ it 'should return target directory as file task' do
259
+ @filter.into('target').target.should be_kind_of(Rake::FileTask)
260
+ end
261
+
262
+ it 'should return target directory as expanded path' do
263
+ @filter.into('target').target.to_s.should eql(File.expand_path('target'))
264
+ end
265
+
266
+ it 'should respond to :using and return self' do
267
+ @filter.using().should be(@filter)
268
+ end
269
+
270
+ it 'should respond to :using and set mapping from the argument' do
271
+ mapping = { 'foo'=>'bar' }
272
+ lambda { @filter.using mapping }.should change { @filter.mapping }.to(mapping)
273
+ end
274
+
275
+ it 'should respond to :using and set mapping from the block' do
276
+ @filter.using { 5 }.mapping.call.should be(5)
277
+ end
278
+
279
+ it 'should respond to :include and return self' do
280
+ @filter.include('file').should be(@filter)
281
+ end
282
+
283
+ it 'should respond to :include and use these inclusion patterns' do
284
+ @filter.from('src').into('target').include('file2', 'file3').run
285
+ Dir['target/*'].should eql(['target/file2', 'target/file3'])
286
+ end
287
+
288
+ it 'should respond to :exclude and return self' do
289
+ @filter.exclude('file').should be(@filter)
290
+ end
291
+
292
+ it 'should respond to :exclude and use these exclusion patterns' do
293
+ @filter.from('src').into('target').exclude('file2', 'file3').run
294
+ Dir['target/*'].sort.should eql(['target/file1', 'target/file4'])
295
+ end
296
+
297
+ it 'should copy files over' do
298
+ @filter.from('src').into('target').run
299
+ Dir['target/*'].sort.each do |file|
300
+ read(file).should eql("#{File.basename(file)} raw")
301
+ end
302
+ end
303
+
304
+ it 'should copy dot files over' do
305
+ write 'src/.config', '# configuration'
306
+ @filter.from('src').into('target').run
307
+ read('target/.config').should eql('# configuration')
308
+ end
309
+
310
+ it 'should copy empty directories as well' do
311
+ mkpath 'src/empty'
312
+ @filter.from('src').into('target').run
313
+ File.directory?('target/empty').should be_true
314
+ end
315
+
316
+ it 'should copy files from multiple source directories' do
317
+ 4.upto(6) { |i| write "src2/file#{i}", "file#{i} raw" }
318
+ @filter.from('src', 'src2').into('target').run
319
+ Dir['target/*'].each do |file|
320
+ read(file).should eql("#{File.basename(file)} raw")
321
+ end
322
+ Dir['target/*'].should include(*(1..6).map { |i| "target/file#{i}" })
323
+ end
324
+
325
+ it 'should copy files recursively' do
326
+ mkpath 'src/path1' ; write 'src/path1/left'
327
+ mkpath 'src/path2' ; write 'src/path2/right'
328
+ @filter.from('src').into('target').run
329
+ Dir['target/**/*'].should include(*(1..4).map { |i| "target/file#{i}" })
330
+ Dir['target/**/*'].should include('target/path1/left', 'target/path2/right')
331
+ end
332
+
333
+ it 'should apply hash mapping using Maven style' do
334
+ 1.upto(4) { |i| write "src/file#{i}", "file#{i} with ${key1} and ${key2}" }
335
+ @filter.from('src').into('target').using('key1'=>'value1', 'key2'=>'value2').run
336
+ Dir['target/*'].each do |file|
337
+ read(file).should eql("#{File.basename(file)} with value1 and value2")
338
+ end
339
+ end
340
+
341
+ it 'should apply hash mapping using Ant style' do
342
+ 1.upto(4) { |i| write "src/file#{i}", "file#{i} with @key1@ and @key2@" }
343
+ @filter.from('src').into('target').using(:ant, 'key1'=>'value1', 'key2'=>'value2').run
344
+ Dir['target/*'].each do |file|
345
+ read(file).should eql("#{File.basename(file)} with value1 and value2")
346
+ end
347
+ end
348
+
349
+ it 'should apply hash mapping using Ruby style' do
350
+ 1.upto(4) { |i| write "src/file#{i}", "file#{i} with \#{key1} and \#{key2}" }
351
+ @filter.from('src').into('target').using(:ruby, 'key1'=>'value1', 'key2'=>'value2').run
352
+ Dir['target/*'].each do |file|
353
+ read(file).should eql("#{File.basename(file)} with value1 and value2")
354
+ end
355
+ end
356
+
357
+ it 'should using Maven mapper by default' do
358
+ @filter.using('key1'=>'value1', 'key2'=>'value2').mapper.should eql(:maven)
359
+ end
360
+
361
+ it 'should apply hash mapping using regular expression' do
362
+ 1.upto(4) { |i| write "src/file#{i}", "file#{i} with #key1# and #key2#" }
363
+ @filter.from('src').into('target').using(/#(.*?)#/, 'key1'=>'value1', 'key2'=>'value2').run
364
+ Dir['target/*'].each do |file|
365
+ read(file).should eql("#{File.basename(file)} with value1 and value2")
366
+ end
367
+ end
368
+
369
+ it 'should apply proc mapping' do
370
+ @filter.from('src').into('target').using { |file, content| 'proc mapped' }.run
371
+ Dir['target/*'].each do |file|
372
+ read(file).should eql('proc mapped')
373
+ end
374
+ end
375
+
376
+ it 'should apply proc mapping with relative file name' do
377
+ @filter.from('src').into('target').using { |file, content| file.should =~ /^file\d$/ }.run
378
+ end
379
+
380
+ it 'should apply proc mapping with file content' do
381
+ @filter.from('src').into('target').using { |file, content| content.should =~ /^file\d raw/ }.run
382
+ end
383
+
384
+ it 'should make target directory' do
385
+ lambda { @filter.from('src').into('target').run }.should change { File.exist?('target') }.to(true)
386
+ end
387
+
388
+ it 'should touch target directory' do
389
+ mkpath 'target' ; File.utime @early, @early, 'target'
390
+ @filter.from('src').into('target').run
391
+ File.stat('target').mtime.should be_close(Time.now, 10)
392
+ end
393
+
394
+ it 'should not touch target directory unless running' do
395
+ mkpath 'target' ; File.utime @early, @early, 'target'
396
+ @filter.from('src').into('target').exclude('*').run
397
+ File.mtime('target').should be_close(@early, 10)
398
+ end
399
+
400
+ it 'should run only one new files' do
401
+ @filter.from('src').into('target').run
402
+ @filter.from('src').into('target').using { |file, content| file.should eql('file2') }.run
403
+ end
404
+
405
+ it 'should return true when run copies any files' do
406
+ @filter.from('src').into('target').run.should be(true)
407
+ end
408
+
409
+ it 'should return false when run does not copy any files' do
410
+ @filter.from('src').into('target').run
411
+ @filter.from('src').into('target').run.should be(false)
412
+ end
413
+
414
+ it 'should fail is source directory not set' do
415
+ lambda { Filter.new.into('target').run }.should raise_error(RuntimeError, /No source directory/)
416
+ end
417
+
418
+ it 'should fail if source directory doesn\'t exist' do
419
+ lambda { Filter.new.from('srced').into('target').run }.should raise_error(RuntimeError, /doesn't exist/)
420
+ end
421
+
422
+ it 'should fail is target directory not set' do
423
+ lambda { Filter.new.from('src').run }.should raise_error(RuntimeError, /No target directory/)
424
+ end
425
+
426
+ it 'should copy read-only files as writeable' do
427
+ Dir['src/*'].each { |file| File.chmod(0444, file) }
428
+ @filter.from('src').into('target').run
429
+ Dir['target/*'].sort.each do |file|
430
+ File.readable?(file).should be_true
431
+ File.writable?(file).should be_true
432
+ (File.stat(file).mode & 0o200).should == 0o200
433
+ end
434
+ end
435
+ end
436
+
437
+
438
+ describe Buildr.method(:options) do
439
+ it 'should return an Options object' do
440
+ options.should be_kind_of(Options)
441
+ end
442
+
443
+ it 'should return an Options object each time' do
444
+ options.should be(options)
445
+ end
446
+
447
+ it 'should return the same Options object when called on Object, Buildr or Project' do
448
+ options.should be(Buildr.options)
449
+ define('foo') { options.should be(Buildr.options) }
450
+ end
451
+ end
452
+
453
+
454
+ describe Buildr::Options, 'proxy.exclude' do
455
+ before do
456
+ options.proxy.http = 'http://myproxy:8080'
457
+ @domain = 'domain'
458
+ @host = "host.#{@domain}"
459
+ @uri = URI("http://#{@host}")
460
+ @no_proxy_args = [@host, 80]
461
+ @proxy_args = @no_proxy_args + ['myproxy', 8080, nil, nil]
462
+ @http = mock('http')
463
+ @http.stub!(:request).and_return(Net::HTTPNotModified.new(nil, nil, nil))
464
+ end
465
+
466
+ it 'should be an array' do
467
+ options.proxy.exclude.should be_empty
468
+ options.proxy.exclude = @domain
469
+ options.proxy.exclude.should include(@domain)
470
+ end
471
+
472
+ it 'should support adding to array' do
473
+ options.proxy.exclude << @domain
474
+ options.proxy.exclude.should include(@domain)
475
+ end
476
+
477
+ it 'should support resetting array' do
478
+ options.proxy.exclude = @domain
479
+ options.proxy.exclude = nil
480
+ options.proxy.exclude.should be_empty
481
+ end
482
+
483
+ it 'should use proxy when not excluded' do
484
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
485
+ @uri.read :proxy=>options.proxy
486
+ end
487
+
488
+ it 'should use proxy unless excluded' do
489
+ options.proxy.exclude = "not.#{@domain}"
490
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
491
+ @uri.read :proxy=>options.proxy
492
+ end
493
+
494
+ it 'should not use proxy if excluded' do
495
+ options.proxy.exclude = @host
496
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
497
+ @uri.read :proxy=>options.proxy
498
+ end
499
+
500
+ it 'should support multiple host names' do
501
+ options.proxy.exclude = ['optimus', 'prime']
502
+ Net::HTTP.should_receive(:new).with('optimus', 80).and_return(@http)
503
+ URI('http://optimus').read :proxy=>options.proxy
504
+ Net::HTTP.should_receive(:new).with('prime', 80).and_return(@http)
505
+ URI('http://prime').read :proxy=>options.proxy
506
+ Net::HTTP.should_receive(:new).with('bumblebee', *@proxy_args[1..-1]).and_return(@http)
507
+ URI('http://bumblebee').read :proxy=>options.proxy
508
+ end
509
+
510
+ it 'should support glob pattern on host name' do
511
+ options.proxy.exclude = "*.#{@domain}"
512
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
513
+ @uri.read :proxy=>options.proxy
514
+ end
515
+ end
516
+
517
+
518
+ describe Hash, '::from_java_properties' do
519
+ it 'should return hash' do
520
+ hash = Hash.from_java_properties(<<-PROPS)
521
+ name1=value1
522
+ name2=value2
523
+ PROPS
524
+ hash.should == {'name1'=>'value1', 'name2'=>'value2'}
525
+ end
526
+
527
+ it 'should ignore comments and empty lines' do
528
+ hash = Hash.from_java_properties(<<-PROPS)
529
+
530
+ name1=value1
531
+
532
+ name2=value2
533
+
534
+ PROPS
535
+ hash.should == {'name1'=>'value1', 'name2'=>'value2'}
536
+ end
537
+
538
+ it 'should allow multiple lines' do
539
+ hash = Hash.from_java_properties(<<-PROPS)
540
+ name1=start\
541
+ end
542
+
543
+ name2=first\
544
+ second\
545
+ third
546
+
547
+ PROPS
548
+ hash.should == {'name1'=>'start end', 'name2'=>'first second third'}
549
+ end
550
+
551
+ it 'should handle \t, \r, \n and \f' do
552
+ hash = Hash.from_java_properties(<<-PROPS)
553
+
554
+ name1=with\tand\r
555
+
556
+ name2=with\\nand\f
557
+
558
+ name3=double\\hash
559
+ PROPS
560
+ hash.should == {'name1'=>"with\tand\r", 'name2'=>"with\nand\f", 'name3'=>"double\\hash"}
561
+ end
562
+ end
563
+
564
+
565
+ describe Hash, '#to_java_properties' do
566
+ it 'should return name/value pairs' do
567
+ props = {'name1'=>'value1', 'name2'=>'value2'}.to_java_properties
568
+ props.split("\n").size.should be(2)
569
+ props.split("\n").should include('name1=value1')
570
+ props.split("\n").should include('name2=value2')
571
+ end
572
+
573
+ it 'should handle \t, \r, \n and \f' do
574
+ props = {'name1'=>"with\tand\r", 'name2'=>"with\nand\f", 'name3'=>"double\\hash"}.to_java_properties
575
+ props.split("\n").should include("name1=with\\tand\\r")
576
+ props.split("\n").should include("name2=with\\nand\\f")
577
+ props.split("\n").should include("name3=double\\\\hash")
578
+ end
579
+ end