assaf-buildr 1.3.3

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 (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -0,0 +1,503 @@
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
+
20
+ describe 'ArchiveTask', :shared=>true do
21
+ before do
22
+ @dir = File.expand_path('test')
23
+ @files = %w{Test1.txt Text2.html}.map { |file| File.expand_path(file, @dir) }.
24
+ each { |file| write file, content_for(file) }
25
+ end
26
+
27
+ # Not too smart, we just create some content based on file name to make sure you read what you write.
28
+ def content_for(file)
29
+ "Content for #{File.basename(file)}"
30
+ end
31
+
32
+ # Create an archive not using the archive task, this way we do have a file in existence, but we don't
33
+ # have an already invoked task. Yield an archive task to the block which can use it to include files,
34
+ # set options, etc.
35
+ def create_without_task
36
+ archive(@archive + '.tmp').tap do |task|
37
+ yield task if block_given?
38
+ task.invoke
39
+ mv task.name, @archive
40
+ end
41
+ end
42
+
43
+ def create_for_merge
44
+ zip(@archive + '.src').include(@files).tap do |task|
45
+ yield task
46
+ end
47
+ end
48
+
49
+ it 'should point to archive file' do
50
+ archive(@archive).name.should eql(@archive)
51
+ end
52
+
53
+ it 'should create file' do
54
+ lambda { archive(@archive).invoke }.should change { File.exist?(@archive) }.to(true)
55
+ end
56
+
57
+ it 'should create empty archive if no files included' do
58
+ archive(@archive).invoke
59
+ inspect_archive { |archive| archive.should be_empty }
60
+ end
61
+
62
+ it 'should create empty archive if called #clean method' do
63
+ archive(@archive).include(@files).clean.invoke
64
+ inspect_archive { |archive| archive.should be_empty }
65
+ end
66
+
67
+ it 'should archive all included files' do
68
+ archive(@archive).include(@files).invoke
69
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
70
+ inspect_archive.size.should eql(@files.size)
71
+ end
72
+
73
+ it 'should archive file tasks' do
74
+ tasks = @files.map { |fn| file(fn) }
75
+ archive(@archive).include(tasks).invoke
76
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
77
+ inspect_archive.size.should eql(@files.size)
78
+ end
79
+
80
+ it 'should invoke and archive file tasks' do
81
+ file = file('included') { write 'included' }
82
+ lambda { archive(@archive).include(file).invoke }.should change { File.exist?(file.to_s) }.to(true)
83
+ inspect_archive.should include('included')
84
+ end
85
+
86
+ it 'should include entry for directory' do
87
+ archive(@archive).include(@dir).invoke
88
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
89
+ end
90
+
91
+ it 'should not archive any excluded files' do
92
+ archive(@archive).include(@files).exclude(@files.last).invoke
93
+ inspect_archive do |archive|
94
+ archive.keys.should include(File.basename(@files.first))
95
+ archive.keys.should_not include(File.basename(@files.last))
96
+ end
97
+ end
98
+
99
+ it 'should not archive any excluded files in included directories' do
100
+ archive(@archive).include(@dir).exclude(@files.last).invoke
101
+ inspect_archive do |archive|
102
+ archive.keys.should include('test/' + File.basename(@files.first))
103
+ archive.keys.should_not include('test/' + File.basename(@files.last))
104
+ end
105
+ end
106
+
107
+ it 'should not archive any excluded files when using :from/:as' do
108
+ archive(@archive).include(:from=>@dir).exclude(@files.last).invoke
109
+ inspect_archive do |archive|
110
+ archive.keys.should include(File.basename(@files.first))
111
+ archive.keys.should_not include(File.basename(@files.last))
112
+ end
113
+ end
114
+
115
+ it 'should exclude entire directory and all its children' do
116
+ mkpath "#{@dir}/sub"
117
+ write "#{@dir}/sub/test"
118
+ archive(@archive).include(@dir).exclude("#{@dir}/sub").invoke
119
+ inspect_archive do |archive|
120
+ archive.keys.select { |file| file =~ /sub/ }.should be_empty
121
+ end
122
+ end
123
+
124
+ it 'should not archive any excluded files when pattern is *.ext' do
125
+ write "test/file.txt"
126
+ write "test/file.swf"
127
+ archive(@archive).include(@dir).exclude('**/*.swf').invoke
128
+ inspect_archive do |archive|
129
+ archive.keys.should include('test/file.txt')
130
+ archive.keys.should_not include('test/file.swf')
131
+ end
132
+ end
133
+
134
+ it 'should archive files into specified path' do
135
+ archive(@archive).include(@files, :path=>'code').invoke
136
+ inspect_archive { |archive| @files.each { |f| archive['code/' + File.basename(f)].should eql(content_for(f)) } }
137
+ end
138
+
139
+ it 'should include entry for directory' do
140
+ archive(@archive).include(@dir).invoke
141
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
142
+ end
143
+
144
+ it 'should archive files into specified path' do
145
+ archive(@archive).include(@files, :path=>'code').invoke
146
+ inspect_archive { |archive| @files.each { |f| archive['code/' + File.basename(f)].should eql(content_for(f)) } }
147
+ end
148
+
149
+ it 'should archive directories into specified path' do
150
+ archive(@archive).include(@dir, :path=>'code').invoke
151
+ inspect_archive { |archive| @files.each { |f| archive['code/test/' + File.basename(f)].should eql(content_for(f)) } }
152
+ end
153
+
154
+ it 'should understand . in path' do
155
+ archive(@archive).path('.').should == archive(@archive).path('')
156
+ archive(@archive).path('foo').path('.').should == archive(@archive).path('foo')
157
+ end
158
+
159
+ it 'should understand .. in path' do
160
+ archive(@archive).path('..').should == archive(@archive).path('')
161
+ archive(@archive).path('foo').path('..').should == archive(@archive).path('')
162
+ archive(@archive).path('foo/bar').path('..').should == archive(@archive).path('foo')
163
+ end
164
+
165
+ it 'should understand leading / in path' do
166
+ archive(@archive).path('/').should == archive(@archive).path('')
167
+ archive(@archive).path('foo/bar').path('/').should == archive(@archive).path('')
168
+ end
169
+
170
+ it 'should archive file into specified name' do
171
+ archive(@archive).include(@files.first, :as=>'test/sample').invoke
172
+ inspect_archive { |archive| @files.each { |f| archive['test/sample'].should eql(content_for(@files.first)) } }
173
+ end
174
+
175
+ it 'should archive file into specified name/path' do
176
+ archive(@archive).include(@files.first, :as=>'test/sample', :path=>'path').invoke
177
+ inspect_archive { |archive| @files.each { |f| archive['path/test/sample'].should eql(content_for(@files.first)) } }
178
+ end
179
+
180
+ it 'should archive files starting with dot' do
181
+ write 'test/.config', '# configuration'
182
+ archive(@archive).include('test').invoke
183
+ inspect_archive { |archive| @files.each { |f| archive['test/.config'].should eql('# configuration') } }
184
+ end
185
+
186
+ it 'should archive directory into specified name' do
187
+ archive(@archive).include(@dir, :as=>'code').invoke
188
+ inspect_archive { |archive| @files.each { |f| archive['code/' + File.basename(f)].should eql(content_for(f)) } }
189
+ end
190
+
191
+ it 'should archive directory into specified name/path' do
192
+ archive(@archive).include(@dir, :as=>'code', :path=>'path').invoke
193
+ inspect_archive { |archive| @files.each { |f| archive['path/code/' + File.basename(f)].should eql(content_for(f)) } }
194
+ end
195
+
196
+ it 'should archive directory contents' do
197
+ archive(@archive).include(@dir, :as=>'.').invoke
198
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
199
+ end
200
+
201
+ it 'should archive directory contents into specified path' do
202
+ archive(@archive).include(@dir, :as=>'.', :path=>'path').invoke
203
+ inspect_archive { |archive| @files.each { |f| archive['path/' + File.basename(f)].should eql(content_for(f)) } }
204
+ end
205
+
206
+ it 'should not allow two files with the :as argument' do
207
+ lambda { archive(@archive).include(@files.first, @files.last, :as=>'test/sample') }.should raise_error(RuntimeError, /one file/)
208
+ end
209
+
210
+ it 'should expand another archive file' do
211
+ create_for_merge do |src|
212
+ archive(@archive).merge(src)
213
+ archive(@archive).invoke
214
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
215
+ end
216
+ end
217
+
218
+ it 'should expand another archive file with include pattern' do
219
+ create_for_merge do |src|
220
+ archive(@archive).merge(src).include(File.basename(@files.first))
221
+ archive(@archive).invoke
222
+ inspect_archive do |archive|
223
+ archive[File.basename(@files.first)].should eql(content_for(@files.first))
224
+ archive[File.basename(@files.last)].should be_nil
225
+ end
226
+ end
227
+ end
228
+
229
+ it 'should expand another archive file with exclude pattern' do
230
+ create_for_merge do |src|
231
+ archive(@archive).merge(src).exclude(File.basename(@files.first))
232
+ archive(@archive).invoke
233
+ inspect_archive do |archive|
234
+ @files[1..-1].each { |f| archive[File.basename(f)].should eql(content_for(f)) }
235
+ archive[File.basename(@files.first)].should be_nil
236
+ end
237
+ end
238
+ end
239
+
240
+ it 'should expand another archive file into path' do
241
+ create_for_merge do |src|
242
+ archive(@archive).path('test').merge(src)
243
+ archive(@archive).invoke
244
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
245
+ end
246
+ end
247
+
248
+ it 'should expand another archive file into path with :path option' do
249
+ create_for_merge do |src|
250
+ archive(@archive).merge(src, :path=>'test')
251
+ archive(@archive).invoke
252
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
253
+ end
254
+ end
255
+
256
+ it "should expand another archive file into path with :path=>'/'" do
257
+ create_for_merge do |src|
258
+ archive(@archive).merge(src, :path=>'/')
259
+ archive(@archive).invoke
260
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
261
+ end
262
+ end
263
+
264
+ it 'should expand another archive file into path with merge option' do
265
+ create_for_merge do |src|
266
+ archive(@archive).include(src, :merge=>true)
267
+ archive(@archive).invoke
268
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
269
+ end
270
+ end
271
+
272
+ it 'should update if one of the files is recent' do
273
+ create_without_task { |archive| archive.include(@files) }
274
+ # Touch archive file to some point in the past. This effectively makes
275
+ # all included files newer.
276
+ File.utime Time.now - 100, Time.now - 100, @archive
277
+ archive(@archive).include(@files).invoke
278
+ File.stat(@archive).mtime.should be_close(Time.now, 10)
279
+ end
280
+
281
+ it 'should do nothing if all files are uptodate' do
282
+ create_without_task { |archive| archive.include(@files) }
283
+ # By touching all files in the past, there's nothing new to update.
284
+ (@files + [@archive]).each { |f| File.utime Time.now - 100, Time.now - 100, f }
285
+ archive(@archive).include(@files).invoke
286
+ File.stat(@archive).mtime.should be_close(Time.now - 100, 10)
287
+ end
288
+
289
+ it 'should update if one of the files is recent' do
290
+ create_without_task { |archive| archive.include(@files) }
291
+ # Change files, we expect to see new content.
292
+ write @files.first, '/* Refreshed */'
293
+ File.utime(Time.now - 100, Time.now - 100, @archive) # Touch archive file to some point in the past.
294
+ archive(@archive).include(@files).invoke
295
+ inspect_archive { |archive| archive[File.basename(@files.first)].should eql('/* Refreshed */') }
296
+ end
297
+
298
+ it 'should create new archive when updating' do
299
+ create_without_task { |archive| archive.include(@files) }
300
+ File.utime(Time.now - 100, Time.now - 100, @archive) # Touch archive file to some point in the past.
301
+ archive(@archive).include(@files[1..-1]).invoke
302
+ inspect_archive.size.should be(@files.size - 1)
303
+ end
304
+
305
+ it 'should not accept invalid options' do
306
+ archive(@archive).include(@files)
307
+ lambda { archive(@archive).with :option=>true }.should raise_error
308
+ end
309
+ end
310
+
311
+
312
+ describe TarTask do
313
+ it_should_behave_like 'ArchiveTask'
314
+ before { @archive = File.expand_path('test.tar') }
315
+ define_method(:archive) { |file| tar(file) }
316
+
317
+ def inspect_archive
318
+ entries = {}
319
+ Archive::Tar::Minitar.open @archive, 'r' do |reader|
320
+ reader.each { |entry| entries[entry.directory ? "#{entry.name}/" : entry.name] = entry.read }
321
+ end
322
+ yield entries if block_given?
323
+ entries
324
+ end
325
+ end
326
+
327
+
328
+ describe TarTask, ' gzipped' do
329
+ it_should_behave_like 'ArchiveTask'
330
+ before { @archive = File.expand_path('test.tgz') }
331
+ define_method(:archive) { |file| tar(file) }
332
+
333
+ def inspect_archive
334
+ entries = {}
335
+ Zlib::GzipReader.open @archive do |gzip|
336
+ Archive::Tar::Minitar.open gzip, 'r' do |reader|
337
+ reader.each { |entry| entries[entry.directory ? "#{entry.name}/" : entry.name] = entry.read }
338
+ end
339
+ end
340
+ yield entries if block_given?
341
+ entries
342
+ end
343
+ end
344
+
345
+
346
+ describe ZipTask do
347
+ it_should_behave_like 'ArchiveTask'
348
+ before { @archive = File.expand_path('test.zip') }
349
+ define_method(:archive) { |file| zip(file) }
350
+
351
+ def inspect_archive
352
+ entries = {}
353
+ Zip::ZipFile.open @archive do |zip|
354
+ zip.entries.each do |entry|
355
+ # Ignore the / directory created for empty ZIPs when using java.util.zip.
356
+ entries[entry.to_s] = zip.read(entry) unless entry.to_s == '/'
357
+ end
358
+ end
359
+ yield entries if block_given?
360
+ entries
361
+ end
362
+
363
+ it 'should work with path object' do
364
+ archive(@archive).path('code').include(@files)
365
+ archive(@archive).invoke
366
+ inspect_archive { |archive| archive.keys.should include('code/') }
367
+ end
368
+ end
369
+
370
+
371
+ describe Unzip do
372
+ before do
373
+ @zip = File.expand_path('test.zip')
374
+ @dir = File.expand_path('test')
375
+ @files = %w{Test1.txt Text2.html}.map { |file| File.join(@dir, file) }.
376
+ each { |file| write file, content_for(file) }
377
+ @target = File.expand_path('target')
378
+ end
379
+
380
+ # Not too smart, we just create some content based on file name to
381
+ # make sure you read what you write.
382
+ def content_for(file)
383
+ "Content for #{File.basename(file)}"
384
+ end
385
+
386
+ def with_zip(*args)
387
+ zip(@zip).include(*args.empty? ? @files : args).invoke
388
+ yield
389
+ end
390
+
391
+ it 'should touch target directory' do
392
+ with_zip do
393
+ mkdir @target
394
+ File.utime(Time.now - 10, Time.now - 10, @target)
395
+ unzip(@target=>@zip).target.invoke
396
+ end
397
+ File.stat(@target).mtime.should be_close(Time.now, 2)
398
+ end
399
+
400
+ it 'should expand files' do
401
+ with_zip do
402
+ unzip(@target=>@zip).target.invoke
403
+ @files.each { |f| File.read(File.join(@target, File.basename(f))).should eql(content_for(f)) }
404
+ end
405
+ end
406
+
407
+ it 'should expand all files' do
408
+ with_zip do
409
+ unzip(@target=>@zip).target.invoke
410
+ FileList[File.join(@target, '*')].size.should be(@files.size)
411
+ end
412
+ end
413
+
414
+ it 'should expand only included files' do
415
+ with_zip do
416
+ only = File.basename(@files.first)
417
+ unzip(@target=>@zip).include(only).target.invoke
418
+ FileList[File.join(@target, '*')].should include(File.expand_path(only, @target))
419
+ FileList[File.join(@target, '*')].size.should be(1)
420
+ end
421
+ end
422
+
423
+ it 'should expand all but excluded files' do
424
+ with_zip do
425
+ except = File.basename(@files.first)
426
+ unzip(@target=>@zip).exclude(except).target.invoke
427
+ FileList[File.join(@target, '*')].should_not include(File.expand_path(except, @target))
428
+ FileList[File.join(@target, '*')].size.should be(@files.size - 1)
429
+ end
430
+ end
431
+
432
+ it 'should include with nested path patterns' do
433
+ with_zip @files, :path=>'test/path' do
434
+ only = File.basename(@files.first)
435
+ unzip(@target=>@zip).include(only).target.invoke
436
+ FileList[File.join(@target, '*')].should be_empty
437
+
438
+ Rake::Task.clear ; rm_rf @target
439
+ unzip(@target=>@zip).include('test/path/' + only).target.invoke
440
+ FileList[File.join(@target, 'test/path/*')].size.should be(1)
441
+
442
+ Rake::Task.clear ; rm_rf @target
443
+ unzip(@target=>@zip).include('test/**/*').target.invoke
444
+ FileList[File.join(@target, 'test/path/*')].size.should be(2)
445
+ end
446
+ end
447
+
448
+ it 'should include with relative path' do
449
+ with_zip @files, :path=>'test/path' do
450
+ only = File.basename(@files.first)
451
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include(only) }.target.invoke
452
+ FileList[File.join(@target, '*')].should be_empty
453
+
454
+ Rake::Task.clear ; rm_rf @target
455
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('test/*') }.target.invoke
456
+ FileList[File.join(@target, 'path/*')].should be_empty
457
+
458
+ Rake::Task.clear ; rm_rf @target
459
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('path/*' + only) }.target.invoke
460
+ FileList[File.join(@target, 'path/*')].size.should be(1)
461
+
462
+ Rake::Task.clear ; rm_rf @target
463
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('path/*') }.target.invoke
464
+ FileList[File.join(@target, 'path/*')].size.should be(2)
465
+ end
466
+ end
467
+
468
+ it 'should exclude with relative path' do
469
+ with_zip @files, :path=>'test' do
470
+ except = File.basename(@files.first)
471
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').exclude(except) }.target.invoke
472
+ FileList[File.join(@target, '*')].should include(File.join(@target, File.basename(@files[1])))
473
+ FileList[File.join(@target, '*')].size.should be(@files.size - 1)
474
+ end
475
+ end
476
+
477
+ it "should handle relative paths without any includes or excludes" do
478
+ lib_files = %w{Test3.so Test4.rb}.
479
+ map { |file| File.join(@dir, file) }.
480
+ each { |file| write file, content_for(file) }
481
+ zip(@zip).include(@files, :path => 'src').include(lib_files, :path => 'lib').invoke
482
+
483
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('lib') }.target.invoke
484
+ FileList[File.join(@target, '**/*')].should have(2).files
485
+ end
486
+
487
+ it 'should return itself from root method' do
488
+ task = unzip(@target=>@zip)
489
+ task.root.should be(task)
490
+ task.from_path('foo').root.should be(task)
491
+ end
492
+
493
+ it 'should return target task from target method' do
494
+ task = unzip(@target=>@zip)
495
+ task.target.should be(file(@target))
496
+ task.from_path('foo').target.should be(file(@target))
497
+ end
498
+
499
+ it 'should alias from_path as path' do
500
+ task = unzip(@target=>@zip)
501
+ task.from_path('foo').should be(task.path('foo'))
502
+ end
503
+ end