buildr 1.3.5-x86-mswin32

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