assaf-buildr 1.3.3

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