novoda-buildr 1.4.0

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