mguymon-buildr 1.4.5-java

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