buildr 1.2.10 → 1.3.0

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