mguymon-buildr 1.4.5-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,544 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18
+
19
+
20
+ describe URI, '#download' do
21
+ before do
22
+ write @source = 'source', @content = 'Just a file'
23
+ @uri = URI(URI.escape("file://#{File.expand_path(@source)}"))
24
+ @target = 'target'
25
+ end
26
+
27
+ it 'should download file if found' do
28
+ @uri.download @target
29
+ file(@target).should contain(@content)
30
+ end
31
+
32
+ it 'should fail if file not found' do
33
+ lambda { (@uri + 'missing').download @target }.should raise_error(URI::NotFoundError)
34
+ file(@target).should_not exist
35
+ end
36
+
37
+ it 'should work the same way from static method with URI' do
38
+ URI.download @uri, @target
39
+ file(@target).should contain(@content)
40
+ end
41
+
42
+ it 'should work the same way from static method with String' do
43
+ URI.download @uri.to_s, @target
44
+ file(@target).should contain(@content)
45
+ end
46
+
47
+ it 'should download to a task' do
48
+ @uri.download file(@target)
49
+ file(@target).should contain(@content)
50
+ end
51
+
52
+ it 'should download to a file' do
53
+ File.open(@target, 'w') { |file| @uri.download file }
54
+ file(@target).should contain(@content)
55
+ end
56
+ end
57
+
58
+
59
+ describe URI, '#upload' do
60
+ before do
61
+ write @source = 'source', @content = 'Just a file'
62
+ @target = 'target'
63
+ @uri = URI(URI.escape("file://#{File.expand_path(@target)}"))
64
+ end
65
+
66
+ it 'should preserve file permissions if uploading to a file' do
67
+ File.chmod(0666, @source)
68
+ s = File.stat(@source).mode
69
+ @uri.upload @source
70
+ File.stat(@target).mode.should eql(s)
71
+ end
72
+
73
+ it 'should upload file if found' do
74
+ @uri.upload @source
75
+ file(@target).should contain(@content)
76
+ end
77
+
78
+ it 'should fail if file not found' do
79
+ lambda { @uri.upload @source.ext('missing') }.should raise_error(URI::NotFoundError)
80
+ file(@target).should_not exist
81
+ end
82
+
83
+ it 'should work the same way from static method with URI' do
84
+ URI.upload @uri, @source
85
+ file(@target).should contain(@content)
86
+ end
87
+
88
+ it 'should work the same way from static method with String' do
89
+ URI.upload @uri.to_s, @source
90
+ file(@target).should contain(@content)
91
+ end
92
+
93
+ it 'should upload from a task' do
94
+ @uri.upload file(@source)
95
+ file(@target).should contain(@content)
96
+ end
97
+
98
+ it 'should create MD5 hash' do
99
+ @uri.upload file(@source)
100
+ file(@target.ext('.md5')).should contain(Digest::MD5.hexdigest(@content))
101
+ end
102
+
103
+ it 'should create SHA1 hash' do
104
+ @uri.upload file(@source)
105
+ file(@target.ext('.sha1')).should contain(Digest::SHA1.hexdigest(@content))
106
+ end
107
+
108
+ it 'should upload an entire directory' do
109
+ mkpath 'dir' ; write 'dir/test', 'in directory'
110
+ mkpath 'dir/nested' ; write 'dir/nested/test', 'in nested directory'
111
+ @uri.upload 'dir'
112
+ file(@target).should contain('test', 'nested/test')
113
+ file(@target + '/test').should contain('in directory')
114
+ file(@target + '/nested/test').should contain('in nested directory')
115
+ end
116
+ end
117
+
118
+
119
+ describe URI::FILE do
120
+ it 'should complain about file:' do
121
+ lambda { URI('file:') }.should raise_error(URI::InvalidURIError)
122
+ end
123
+
124
+ it 'should accept file:something as file:///something' do
125
+ URI('file:something').should eql(URI('file:///something'))
126
+ end
127
+
128
+ it 'should accept file:/ as file:///' do
129
+ URI('file:/').should eql(URI('file:///'))
130
+ end
131
+
132
+ it 'should accept file:/something as file:///something' do
133
+ URI('file:/something').should eql(URI('file:///something'))
134
+ end
135
+
136
+ it 'should complain about file://' do
137
+ lambda { URI('file://').should eql(URI('file:///')) }.should raise_error(URI::InvalidURIError)
138
+ end
139
+
140
+ it 'should accept file://something as file://something/' do
141
+ URI('file://something').should eql(URI('file://something/'))
142
+ end
143
+
144
+ it 'should accept file:///something' do
145
+ URI('file:///something').should be_kind_of(URI::FILE)
146
+ URI('file:///something').to_s.should eql('file:///something')
147
+ URI('file:///something').path.should eql('/something')
148
+ end
149
+
150
+ it 'should treat host as path when host name is a Windows drive' do
151
+ URI('file://c:/something').should eql(URI('file:///c:/something'))
152
+ end
153
+ end
154
+
155
+
156
+ describe URI::FILE, '#read' do
157
+ before do
158
+ @filename = 'readme'
159
+ @uri = URI(URI.escape("file:///#{File.expand_path(@filename)}"))
160
+ @content = 'Readme. Please!'
161
+ write 'readme', @content
162
+ end
163
+
164
+ it 'should not complain about excessive options' do
165
+ @uri.read :proxy=>[], :lovely=>true
166
+ end
167
+
168
+ it 'should read the file' do
169
+ @uri.read.should eql(@content)
170
+ end
171
+
172
+ it 'should read the file and yield to block' do
173
+ @uri.read { |content| content.should eql(@content) }
174
+ end
175
+
176
+ it 'should raise NotFoundError if file doesn\'t exist' do
177
+ lambda { (@uri + 'notme').read }.should raise_error(URI::NotFoundError)
178
+ end
179
+
180
+ it 'should raise NotFoundError if file is actually a directory' do
181
+ mkpath 'dir'
182
+ lambda { (@uri + 'dir').read }.should raise_error(URI::NotFoundError)
183
+ end
184
+ end
185
+
186
+
187
+ describe URI::FILE, '#write' do
188
+ before do
189
+ @filename = 'readme'
190
+ @uri = URI(URI.escape("file:///#{File.expand_path(@filename)}"))
191
+ @content = 'Readme. Please!'
192
+ end
193
+
194
+ it 'should not complain about excessive options' do
195
+ @uri.write @content, :proxy=>[], :lovely=>true
196
+ end
197
+
198
+ it 'should write the file from a string' do
199
+ @uri.write @content
200
+ read(@filename).should eql(@content)
201
+ end
202
+
203
+ it 'should write the file from a reader' do
204
+ reader = Object.new
205
+ class << reader
206
+ def read(bytes) ; @array.pop ; end
207
+ end
208
+ reader.instance_variable_set :@array, [@content]
209
+ @uri.write reader
210
+ read(@filename).should eql(@content)
211
+ end
212
+
213
+ it 'should write the file from a block' do
214
+ array = [@content]
215
+ @uri.write { array.pop }
216
+ read(@filename).should eql(@content)
217
+ end
218
+
219
+ it 'should not create file if read fails' do
220
+ @uri.write { fail } rescue nil
221
+ file(@filename).should_not exist
222
+ end
223
+ end
224
+
225
+
226
+ describe URI::HTTP, '#read' do
227
+ before do
228
+ @proxy = 'http://john:smith@myproxy:8080'
229
+ @domain = 'domain'
230
+ @host_domain = "host.#{@domain}"
231
+ @path = "/foo/bar/baz"
232
+ @query = "?query"
233
+ @uri = URI("http://#{@host_domain}#{@path}#{@query}")
234
+ @no_proxy_args = [@host_domain, 80]
235
+ @proxy_args = @no_proxy_args + ['myproxy', 8080, 'john', 'smith']
236
+ @http = mock('http')
237
+ @http.stub!(:request).and_yield(Net::HTTPNotModified.new(nil, nil, nil))
238
+ end
239
+
240
+ it 'should not use proxy unless proxy is set' do
241
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
242
+ @uri.read
243
+ end
244
+
245
+ it 'should use HTTPS if applicable' do
246
+ Net::HTTP.should_receive(:new).with(@host_domain, 443).and_return(@http)
247
+ @http.should_receive(:use_ssl=).with(true)
248
+ URI(@uri.to_s.sub(/http/, 'https')).read
249
+ end
250
+
251
+ it 'should use proxy from environment variable HTTP_PROXY when using http' do
252
+ ENV['HTTP_PROXY'] = @proxy
253
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
254
+ @uri.read
255
+ end
256
+
257
+ it 'should use proxy from environment variable HTTPS_PROXY when using https' do
258
+ ENV['HTTPS_PROXY'] = @proxy
259
+ Net::HTTP.should_receive(:new).with(@host_domain, 443, 'myproxy', 8080, 'john', 'smith').and_return(@http)
260
+ @http.should_receive(:use_ssl=).with(true)
261
+ URI(@uri.to_s.sub(/http/, 'https')).read
262
+ end
263
+
264
+ it 'should not use proxy for hosts from environment variable NO_PROXY' do
265
+ ENV['HTTP_PROXY'] = @proxy
266
+ ENV['NO_PROXY'] = @host_domain
267
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
268
+ @uri.read
269
+ end
270
+
271
+ it 'should use proxy for hosts other than those specified by NO_PROXY' do
272
+ ENV['HTTP_PROXY'] = @proxy
273
+ ENV['NO_PROXY'] = 'whatever'
274
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
275
+ @uri.read
276
+ end
277
+
278
+ it 'should support comma separated list in environment variable NO_PROXY' do
279
+ ENV['HTTP_PROXY'] = @proxy
280
+ ENV['NO_PROXY'] = 'optimus,prime'
281
+ Net::HTTP.should_receive(:new).with('optimus', 80).and_return(@http)
282
+ URI('http://optimus').read
283
+ Net::HTTP.should_receive(:new).with('prime', 80).and_return(@http)
284
+ URI('http://prime').read
285
+ Net::HTTP.should_receive(:new).with('bumblebee', *@proxy_args[1..-1]).and_return(@http)
286
+ URI('http://bumblebee').read
287
+ end
288
+
289
+ it 'should support glob pattern in NO_PROXY' do
290
+ ENV['HTTP_PROXY'] = @proxy
291
+ ENV['NO_PROXY'] = "*.#{@domain}"
292
+ Net::HTTP.should_receive(:new).once.with(*@no_proxy_args).and_return(@http)
293
+ @uri.read
294
+ end
295
+
296
+ it 'should support specific port in NO_PROXY' do
297
+ ENV['HTTP_PROXY'] = @proxy
298
+ ENV['NO_PROXY'] = "#{@host_domain}:80"
299
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
300
+ @uri.read
301
+ ENV['NO_PROXY'] = "#{@host_domain}:800"
302
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
303
+ @uri.read
304
+ end
305
+
306
+ it 'should not die if content size is zero' do
307
+ ok = Net::HTTPOK.new(nil, nil, nil)
308
+ ok.stub!(:read_body)
309
+ @http.stub!(:request).and_yield(ok)
310
+ Net::HTTP.should_receive(:new).and_return(@http)
311
+ $stdout.should_receive(:isatty).and_return(false)
312
+ @uri.read :progress=>true
313
+ end
314
+
315
+ it 'should use HTTP Basic authentication' do
316
+ Net::HTTP.should_receive(:new).and_return(@http)
317
+ request = mock('request')
318
+ Net::HTTP::Get.should_receive(:new).and_return(request)
319
+ request.should_receive(:basic_auth).with('john', 'secret')
320
+ URI("http://john:secret@#{@host_domain}").read
321
+ end
322
+
323
+ it 'should preseve authentication information during a redirect' do
324
+ Net::HTTP.should_receive(:new).twice.and_return(@http)
325
+
326
+ # The first request will produce a redirect
327
+ redirect = Net::HTTPRedirection.new(nil, nil, nil)
328
+ redirect['Location'] = "http://#{@host_domain}/asdf"
329
+
330
+ request1 = mock('request1')
331
+ Net::HTTP::Get.should_receive(:new).once.with('/', nil).and_return(request1)
332
+ request1.should_receive(:basic_auth).with('john', 'secret')
333
+ @http.should_receive(:request).with(request1).and_yield(redirect)
334
+
335
+ # The second request will be ok
336
+ ok = Net::HTTPOK.new(nil, nil, nil)
337
+ ok.stub!(:read_body)
338
+
339
+ request2 = mock('request2')
340
+ Net::HTTP::Get.should_receive(:new).once.with("/asdf", nil).and_return(request2)
341
+ request2.should_receive(:basic_auth).with('john', 'secret')
342
+ @http.should_receive(:request).with(request2).and_yield(ok)
343
+
344
+ URI("http://john:secret@#{@host_domain}").read
345
+ end
346
+
347
+ it 'should include the query part when performing HTTP GET' do
348
+ # should this test be generalized or shared with any other URI subtypes?
349
+ Net::HTTP.stub!(:new).and_return(@http)
350
+ Net::HTTP::Get.should_receive(:new).with(/#{Regexp.escape(@query)}$/, nil)
351
+ @uri.read
352
+ end
353
+
354
+ end
355
+
356
+
357
+ describe URI::HTTP, '#write' do
358
+ before do
359
+ @content = 'Readme. Please!'
360
+ @uri = URI('http://john:secret@host.domain/foo/bar/baz.jar')
361
+ @http = mock('Net::HTTP')
362
+ @http.stub!(:request).and_return(Net::HTTPOK.new(nil, nil, nil))
363
+ Net::HTTP.stub!(:new).and_return(@http)
364
+ end
365
+
366
+ it 'should open connection to HTTP server' do
367
+ Net::HTTP.should_receive(:new).with('host.domain', 80).and_return(@http)
368
+ @uri.write @content
369
+ end
370
+
371
+ it 'should use HTTP basic authentication' do
372
+ @http.should_receive(:request) do |request|
373
+ request['authorization'].should == ('Basic ' + ['john:secret'].pack('m').delete("\r\n"))
374
+ Net::HTTPOK.new(nil, nil, nil)
375
+ end
376
+ @uri.write @content
377
+ end
378
+
379
+ it 'should use HTTPS if applicable' do
380
+ Net::HTTP.should_receive(:new).with('host.domain', 443).and_return(@http)
381
+ @http.should_receive(:use_ssl=).with(true)
382
+ URI(@uri.to_s.sub(/http/, 'https')).write @content
383
+ end
384
+
385
+ it 'should upload file with PUT request' do
386
+ @http.should_receive(:request) do |request|
387
+ request.should be_kind_of(Net::HTTP::Put)
388
+ Net::HTTPOK.new(nil, nil, nil)
389
+ end
390
+ @uri.write @content
391
+ end
392
+
393
+ it 'should set Content-Length header' do
394
+ @http.should_receive(:request) do |request|
395
+ request.content_length.should == @content.size
396
+ Net::HTTPOK.new(nil, nil, nil)
397
+ end
398
+ @uri.write @content
399
+ end
400
+
401
+ it 'should set Content-MD5 header' do
402
+ @http.should_receive(:request) do |request|
403
+ request['Content-MD5'].should == Digest::MD5.hexdigest(@content)
404
+ Net::HTTPOK.new(nil, nil, nil)
405
+ end
406
+ @uri.write @content
407
+ end
408
+
409
+ it 'should send entire content' do
410
+ @http.should_receive(:request) do |request|
411
+ body_stream = request.body_stream
412
+ body_stream.read(1024).should == @content
413
+ body_stream.read(1024).should be_nil
414
+ Net::HTTPOK.new(nil, nil, nil)
415
+ end
416
+ @uri.write @content
417
+ end
418
+
419
+ it 'should fail on 4xx response' do
420
+ @http.should_receive(:request).and_return(Net::HTTPBadRequest.new(nil, nil, nil))
421
+ lambda { @uri.write @content }.should raise_error(RuntimeError, /failed to upload/i)
422
+ end
423
+
424
+ it 'should fail on 5xx response' do
425
+ @http.should_receive(:request).and_return(Net::HTTPServiceUnavailable.new(nil, nil, nil))
426
+ lambda { @uri.write @content }.should raise_error(RuntimeError, /failed to upload/i)
427
+ end
428
+
429
+ end
430
+
431
+
432
+ describe URI::SFTP, '#read' do
433
+ before do
434
+ @uri = URI('sftp://john:secret@localhost/root/path/readme')
435
+ @content = 'Readme. Please!'
436
+
437
+ @ssh_session = mock('Net::SSH::Session')
438
+ @sftp_session = mock('Net::SFTP::Session')
439
+ @file_factory = mock('Net::SFTP::Operations::FileFactory')
440
+ Net::SSH.stub!(:start).with('localhost', 'john', :password=>'secret', :port=>22).and_return(@ssh_session) do
441
+ Net::SFTP::Session.should_receive(:new).with(@ssh_session).and_yield(@sftp_session).and_return(@sftp_session)
442
+ @sftp_session.should_receive(:connect!).and_return(@sftp_session)
443
+ @sftp_session.should_receive(:loop)
444
+ @sftp_session.should_receive(:file).with.and_return(@file_factory)
445
+ @file_factory.stub!(:open)
446
+ @ssh_session.should_receive(:close)
447
+ @ssh_session
448
+ end
449
+ end
450
+
451
+ it 'should open connection to SFTP server' do
452
+ @uri.read
453
+ end
454
+
455
+ it 'should open file for reading' do
456
+ @file_factory.should_receive(:open).with('/root/path/readme', 'r')
457
+ @uri.read
458
+ end
459
+
460
+ it 'should read contents of file and return it' do
461
+ file = mock('Net::SFTP::Operations::File')
462
+ file.should_receive(:read).with(URI::RW_CHUNK_SIZE).once.and_return(@content)
463
+ @file_factory.should_receive(:open).with('/root/path/readme', 'r').and_yield(file)
464
+ @uri.read.should eql(@content)
465
+ end
466
+
467
+ it 'should read contents of file and pass it to block' do
468
+ file = mock('Net::SFTP::Operations::File')
469
+ file.should_receive(:read).with(URI::RW_CHUNK_SIZE).once.and_return(@content)
470
+ @file_factory.should_receive(:open).with('/root/path/readme', 'r').and_yield(file)
471
+ content = ''
472
+ @uri.read do |chunk|
473
+ content << chunk
474
+ end
475
+ content.should eql(@content)
476
+ end
477
+ end
478
+
479
+
480
+ describe URI::SFTP, '#write' do
481
+ before do
482
+ @uri = URI('sftp://john:secret@localhost/root/path/readme')
483
+ @content = 'Readme. Please!'
484
+
485
+ @ssh_session = mock('Net::SSH::Session')
486
+ @sftp_session = mock('Net::SFTP::Session')
487
+ @file_factory = mock('Net::SFTP::Operations::FileFactory')
488
+ Net::SSH.stub!(:start).with('localhost', 'john', :password=>'secret', :port=>22).and_return(@ssh_session) do
489
+ Net::SFTP::Session.should_receive(:new).with(@ssh_session).and_yield(@sftp_session).and_return(@sftp_session)
490
+ @sftp_session.should_receive(:connect!).and_return(@sftp_session)
491
+ @sftp_session.should_receive(:loop)
492
+ @sftp_session.stub!(:opendir!).and_return { fail }
493
+ @sftp_session.stub!(:close)
494
+ @sftp_session.stub!(:mkdir!)
495
+ @sftp_session.should_receive(:file).with.and_return(@file_factory)
496
+ @file_factory.stub!(:open)
497
+ @ssh_session.should_receive(:close)
498
+ @ssh_session
499
+ end
500
+ end
501
+
502
+ it 'should open connection to SFTP server' do
503
+ @uri.write @content
504
+ end
505
+
506
+ it 'should check that path exists on server' do
507
+ paths = ['/root', '/root/path']
508
+ @sftp_session.should_receive(:opendir!).with(anything()).twice { |path| paths.shift.should == path }
509
+ @uri.write @content
510
+ end
511
+
512
+ it 'should close all opened directories' do
513
+ @sftp_session.should_receive(:opendir!).with(anything()).twice do |path|
514
+ @sftp_session.should_receive(:close).with(handle = Object.new)
515
+ handle
516
+ end
517
+ @uri.write @content
518
+ end
519
+
520
+ it 'should create missing paths on server' do
521
+ @sftp_session.should_receive(:opendir!) { |path| fail unless path == '/root' }
522
+ @sftp_session.should_receive(:mkdir!).once.with('/root/path', {})
523
+ @uri.write @content
524
+ end
525
+
526
+ it 'should create missing directories recursively' do
527
+ paths = ['/root', '/root/path']
528
+ @sftp_session.should_receive(:mkdir!).with(anything(), {}).twice { |path, options| paths.shift.should == path }
529
+ @uri.write @content
530
+ end
531
+
532
+ it 'should open file for writing' do
533
+ @file_factory.should_receive(:open).with('/root/path/readme', 'w')
534
+ @uri.write @content
535
+ end
536
+
537
+ it 'should write contents to file' do
538
+ file = mock('Net::SFTP::Operations::File')
539
+ file.should_receive(:write).with(@content)
540
+ @file_factory.should_receive(:open).with('/root/path/readme', 'w').and_yield(file)
541
+ @uri.write @content
542
+ end
543
+
544
+ end