buildr 1.3.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +998 -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 +244 -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 +79 -0
  40. data/doc/extending.textile +186 -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 +266 -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 +430 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +271 -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 +280 -0
  68. data/doc/testing.textile +222 -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 +656 -0
  73. data/lib/buildr/core/build.rb +452 -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 +362 -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 +866 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +723 -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 +334 -0
  94. data/lib/buildr/ide/eclipse/java.rb +53 -0
  95. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  96. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  97. data/lib/buildr/ide/idea.ipr.template +300 -0
  98. data/lib/buildr/ide/idea.rb +190 -0
  99. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  100. data/lib/buildr/ide/idea7x.rb +212 -0
  101. data/lib/buildr/java.rb +23 -0
  102. data/lib/buildr/java/ant.rb +94 -0
  103. data/lib/buildr/java/bdd.rb +459 -0
  104. data/lib/buildr/java/cobertura.rb +274 -0
  105. data/lib/buildr/java/commands.rb +213 -0
  106. data/lib/buildr/java/compiler.rb +349 -0
  107. data/lib/buildr/java/deprecated.rb +141 -0
  108. data/lib/buildr/java/emma.rb +244 -0
  109. data/lib/buildr/java/jruby.rb +117 -0
  110. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  111. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +137 -0
  113. data/lib/buildr/java/packaging.rb +716 -0
  114. data/lib/buildr/java/pom.rb +174 -0
  115. data/lib/buildr/java/rjb.rb +155 -0
  116. data/lib/buildr/java/test_result.rb +353 -0
  117. data/lib/buildr/java/tests.rb +333 -0
  118. data/lib/buildr/java/version_requirement.rb +172 -0
  119. data/lib/buildr/packaging.rb +24 -0
  120. data/lib/buildr/packaging/archive.rb +488 -0
  121. data/lib/buildr/packaging/artifact.rb +749 -0
  122. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  123. data/lib/buildr/packaging/artifact_search.rb +140 -0
  124. data/lib/buildr/packaging/gems.rb +102 -0
  125. data/lib/buildr/packaging/package.rb +238 -0
  126. data/lib/buildr/packaging/tar.rb +186 -0
  127. data/lib/buildr/packaging/version_requirement.rb +172 -0
  128. data/lib/buildr/packaging/zip.rb +73 -0
  129. data/lib/buildr/packaging/ziptask.rb +316 -0
  130. data/lib/buildr/resources/buildr.icns +0 -0
  131. data/lib/buildr/scala.rb +25 -0
  132. data/lib/buildr/scala/bdd.rb +109 -0
  133. data/lib/buildr/scala/compiler.rb +195 -0
  134. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  137. data/lib/buildr/scala/shell.rb +55 -0
  138. data/lib/buildr/scala/tests.rb +157 -0
  139. data/lib/buildr/shell.rb +180 -0
  140. data/rakelib/checks.rake +57 -0
  141. data/rakelib/doc.rake +92 -0
  142. data/rakelib/jekylltask.rb +120 -0
  143. data/rakelib/package.rake +73 -0
  144. data/rakelib/release.rake +149 -0
  145. data/rakelib/rspec.rake +73 -0
  146. data/rakelib/setup.rake +54 -0
  147. data/rakelib/stage.rake +213 -0
  148. data/rakelib/stage.rake~ +213 -0
  149. data/spec/addon/drb_spec.rb +328 -0
  150. data/spec/core/application_spec.rb +502 -0
  151. data/spec/core/build_spec.rb +677 -0
  152. data/spec/core/checks_spec.rb +519 -0
  153. data/spec/core/common_spec.rb +670 -0
  154. data/spec/core/compile_spec.rb +583 -0
  155. data/spec/core/extension_spec.rb +93 -0
  156. data/spec/core/generate_spec.rb +33 -0
  157. data/spec/core/project_spec.rb +762 -0
  158. data/spec/core/test_spec.rb +1098 -0
  159. data/spec/core/transport_spec.rb +537 -0
  160. data/spec/core/util_spec.rb +67 -0
  161. data/spec/groovy/bdd_spec.rb +80 -0
  162. data/spec/groovy/compiler_spec.rb +240 -0
  163. data/spec/ide/eclipse_spec.rb +501 -0
  164. data/spec/ide/idea7x_spec.rb +84 -0
  165. data/spec/java/ant_spec.rb +33 -0
  166. data/spec/java/bdd_spec.rb +382 -0
  167. data/spec/java/cobertura_spec.rb +85 -0
  168. data/spec/java/compiler_spec.rb +446 -0
  169. data/spec/java/emma_spec.rb +119 -0
  170. data/spec/java/java_spec.rb +124 -0
  171. data/spec/java/packaging_spec.rb +1134 -0
  172. data/spec/java/test_coverage_helper.rb +257 -0
  173. data/spec/java/tests_spec.rb +493 -0
  174. data/spec/packaging/archive_spec.rb +527 -0
  175. data/spec/packaging/artifact_namespace_spec.rb +654 -0
  176. data/spec/packaging/artifact_spec.rb +795 -0
  177. data/spec/packaging/packaging_helper.rb +63 -0
  178. data/spec/packaging/packaging_spec.rb +684 -0
  179. data/spec/sandbox.rb +142 -0
  180. data/spec/scala/bdd_spec.rb +119 -0
  181. data/spec/scala/compiler_spec.rb +284 -0
  182. data/spec/scala/scala.rb +38 -0
  183. data/spec/scala/tests_spec.rb +261 -0
  184. data/spec/spec_helpers.rb +340 -0
  185. data/spec/version_requirement_spec.rb +129 -0
  186. metadata +383 -0
@@ -0,0 +1,527 @@
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.keys.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 with nested exclude pattern' do
241
+ @files = %w{Test1.txt Text2.html}.map { |file| File.join(@dir, "foo", file) }.
242
+ each { |file| write file, content_for(file) }
243
+ zip(@archive + '.src').include(@dir).tap do |task|
244
+ archive(@archive).merge(task).exclude('test/*')
245
+ archive(@archive).invoke
246
+ inspect_archive.should be_empty
247
+ end
248
+ end
249
+
250
+ it 'should expand another archive file into path' do
251
+ create_for_merge do |src|
252
+ archive(@archive).path('test').merge(src)
253
+ archive(@archive).invoke
254
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
255
+ end
256
+ end
257
+
258
+ it 'should expand another archive file into path with :path option' do
259
+ create_for_merge do |src|
260
+ archive(@archive).merge(src, :path=>'test')
261
+ archive(@archive).invoke
262
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
263
+ end
264
+ end
265
+
266
+ it "should expand another archive file into path with :path=>'/'" do
267
+ create_for_merge do |src|
268
+ archive(@archive).merge(src, :path=>'/')
269
+ archive(@archive).invoke
270
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
271
+ end
272
+ end
273
+
274
+ it 'should expand another archive file into path with merge option' do
275
+ create_for_merge do |src|
276
+ archive(@archive).include(src, :merge=>true)
277
+ archive(@archive).invoke
278
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
279
+ end
280
+ end
281
+
282
+ it 'should update if one of the files is recent' do
283
+ create_without_task { |archive| archive.include(@files) }
284
+ # Touch archive file to some point in the past. This effectively makes
285
+ # all included files newer.
286
+ File.utime Time.now - 100, Time.now - 100, @archive
287
+ archive(@archive).include(@files).invoke
288
+ File.stat(@archive).mtime.should be_close(Time.now, 10)
289
+ end
290
+
291
+ it 'should do nothing if all files are uptodate' do
292
+ create_without_task { |archive| archive.include(@files) }
293
+ # By touching all files in the past, there's nothing new to update.
294
+ (@files + [@archive]).each { |f| File.utime Time.now - 100, Time.now - 100, f }
295
+ archive(@archive).include(@files).invoke
296
+ File.stat(@archive).mtime.should be_close(Time.now - 100, 10)
297
+ end
298
+
299
+ it 'should update if one of the files is recent' do
300
+ create_without_task { |archive| archive.include(@files) }
301
+ # Change files, we expect to see new content.
302
+ write @files.first, '/* Refreshed */'
303
+ File.utime(Time.now - 100, Time.now - 100, @archive) # Touch archive file to some point in the past.
304
+ archive(@archive).include(@files).invoke
305
+ inspect_archive { |archive| archive[File.basename(@files.first)].should eql('/* Refreshed */') }
306
+ end
307
+
308
+ it 'should create new archive when updating' do
309
+ create_without_task { |archive| archive.include(@files) }
310
+ File.utime(Time.now - 100, Time.now - 100, @archive) # Touch archive file to some point in the past.
311
+ archive(@archive).include(@files[1..-1]).invoke
312
+ inspect_archive.size.should be(@files.size - 1)
313
+ end
314
+
315
+ it 'should not accept invalid options' do
316
+ archive(@archive).include(@files)
317
+ lambda { archive(@archive).with :option=>true }.should raise_error
318
+ end
319
+ end
320
+
321
+
322
+ describe TarTask do
323
+ it_should_behave_like 'ArchiveTask'
324
+ before { @archive = File.expand_path('test.tar') }
325
+ define_method(:archive) { |file| tar(file) }
326
+
327
+ def inspect_archive
328
+ entries = {}
329
+ Archive::Tar::Minitar.open @archive, 'r' do |reader|
330
+ reader.each { |entry| entries[entry.directory ? "#{entry.name}/" : entry.name] = entry.read }
331
+ end
332
+ yield entries if block_given?
333
+ entries
334
+ end
335
+ end
336
+
337
+
338
+ describe TarTask, ' gzipped' do
339
+ it_should_behave_like 'ArchiveTask'
340
+ before { @archive = File.expand_path('test.tgz') }
341
+ define_method(:archive) { |file| tar(file) }
342
+
343
+ def inspect_archive
344
+ entries = {}
345
+ Zlib::GzipReader.open @archive do |gzip|
346
+ Archive::Tar::Minitar.open gzip, 'r' do |reader|
347
+ reader.each { |entry| entries[entry.directory ? "#{entry.name}/" : entry.name] = entry.read }
348
+ end
349
+ end
350
+ yield entries if block_given?
351
+ entries
352
+ end
353
+ end
354
+
355
+
356
+ describe ZipTask do
357
+ it_should_behave_like 'ArchiveTask'
358
+ before { @archive = File.expand_path('test.zip') }
359
+ define_method(:archive) { |file| zip(file) }
360
+
361
+ def inspect_archive
362
+ entries = {}
363
+ Zip::ZipFile.open @archive do |zip|
364
+ zip.entries.each do |entry|
365
+ # Ignore the / directory created for empty ZIPs when using java.util.zip.
366
+ entries[entry.to_s] = zip.read(entry) unless entry.to_s == '/'
367
+ end
368
+ end
369
+ yield entries if block_given?
370
+ entries
371
+ end
372
+
373
+ it 'should work with path object' do
374
+ archive(@archive).path('code').include(@files)
375
+ archive(@archive).invoke
376
+ inspect_archive { |archive| archive.keys.should include('code/') }
377
+ end
378
+
379
+ it 'should preserve file permissions' do
380
+ # with JRuby it's important to use absolute paths with File.chmod()
381
+ # http://jira.codehaus.org/browse/JRUBY-3300
382
+ hello = File.expand_path('src/main/bin/hello')
383
+ write hello, 'echo hi'
384
+ File.chmod(0777, hello) ||
385
+ fail("Failed to set permission on #{hello}") unless (File.stat(hello).mode & 0777) == 0777
386
+
387
+ zip('foo.zip').include('src/main/bin/*').invoke
388
+ unzip('target' => 'foo.zip').extract
389
+ (File.stat('target/hello').mode & 0777).should == 0777
390
+ end
391
+
392
+ end
393
+
394
+
395
+ describe Unzip do
396
+ before do
397
+ @zip = File.expand_path('test.zip')
398
+ @dir = File.expand_path('test')
399
+ @files = %w{Test1.txt Text2.html}.map { |file| File.join(@dir, file) }.
400
+ each { |file| write file, content_for(file) }
401
+ @target = File.expand_path('target')
402
+ end
403
+
404
+ # Not too smart, we just create some content based on file name to
405
+ # make sure you read what you write.
406
+ def content_for(file)
407
+ "Content for #{File.basename(file)}"
408
+ end
409
+
410
+ def with_zip(*args)
411
+ zip(@zip).include(*args.empty? ? @files : args).invoke
412
+ yield
413
+ end
414
+
415
+ it 'should touch target directory' do
416
+ with_zip do
417
+ mkdir @target
418
+ File.utime(Time.now - 10, Time.now - 10, @target)
419
+ unzip(@target=>@zip).target.invoke
420
+ end
421
+ File.stat(@target).mtime.should be_close(Time.now, 2)
422
+ end
423
+
424
+ it 'should expand files' do
425
+ with_zip do
426
+ unzip(@target=>@zip).target.invoke
427
+ @files.each { |f| File.read(File.join(@target, File.basename(f))).should eql(content_for(f)) }
428
+ end
429
+ end
430
+
431
+ it 'should expand all files' do
432
+ with_zip do
433
+ unzip(@target=>@zip).target.invoke
434
+ FileList[File.join(@target, '*')].size.should be(@files.size)
435
+ end
436
+ end
437
+
438
+ it 'should expand only included files' do
439
+ with_zip do
440
+ only = File.basename(@files.first)
441
+ unzip(@target=>@zip).include(only).target.invoke
442
+ FileList[File.join(@target, '*')].should include(File.expand_path(only, @target))
443
+ FileList[File.join(@target, '*')].size.should be(1)
444
+ end
445
+ end
446
+
447
+ it 'should expand all but excluded files' do
448
+ with_zip do
449
+ except = File.basename(@files.first)
450
+ unzip(@target=>@zip).exclude(except).target.invoke
451
+ FileList[File.join(@target, '*')].should_not include(File.expand_path(except, @target))
452
+ FileList[File.join(@target, '*')].size.should be(@files.size - 1)
453
+ end
454
+ end
455
+
456
+ it 'should include with nested path patterns' do
457
+ with_zip @files, :path=>'test/path' do
458
+ only = File.basename(@files.first)
459
+ unzip(@target=>@zip).include(only).target.invoke
460
+ FileList[File.join(@target, '*')].should be_empty
461
+
462
+ Rake::Task.clear ; rm_rf @target
463
+ unzip(@target=>@zip).include('test/path/' + only).target.invoke
464
+ FileList[File.join(@target, 'test/path/*')].size.should be(1)
465
+
466
+ Rake::Task.clear ; rm_rf @target
467
+ unzip(@target=>@zip).include('test/**/*').target.invoke
468
+ FileList[File.join(@target, 'test/path/*')].size.should be(2)
469
+ end
470
+ end
471
+
472
+ it 'should include with relative path' do
473
+ with_zip @files, :path=>'test/path' do
474
+ only = File.basename(@files.first)
475
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include(only) }.target.invoke
476
+ FileList[File.join(@target, '*')].should be_empty
477
+
478
+ Rake::Task.clear ; rm_rf @target
479
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('test/*') }.target.invoke
480
+ FileList[File.join(@target, 'path/*')].should be_empty
481
+
482
+ Rake::Task.clear ; rm_rf @target
483
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('path/*' + only) }.target.invoke
484
+ FileList[File.join(@target, 'path/*')].size.should be(1)
485
+
486
+ Rake::Task.clear ; rm_rf @target
487
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('path/*') }.target.invoke
488
+ FileList[File.join(@target, 'path/*')].size.should be(2)
489
+ end
490
+ end
491
+
492
+ it 'should exclude with relative path' do
493
+ with_zip @files, :path=>'test' do
494
+ except = File.basename(@files.first)
495
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').exclude(except) }.target.invoke
496
+ FileList[File.join(@target, '*')].should include(File.join(@target, File.basename(@files[1])))
497
+ FileList[File.join(@target, '*')].size.should be(@files.size - 1)
498
+ end
499
+ end
500
+
501
+ it "should handle relative paths without any includes or excludes" do
502
+ lib_files = %w{Test3.so Test4.rb}.
503
+ map { |file| File.join(@dir, file) }.
504
+ each { |file| write file, content_for(file) }
505
+ zip(@zip).include(@files, :path => 'src').include(lib_files, :path => 'lib').invoke
506
+
507
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('lib') }.target.invoke
508
+ FileList[File.join(@target, '**/*')].should have(2).files
509
+ end
510
+
511
+ it 'should return itself from root method' do
512
+ task = unzip(@target=>@zip)
513
+ task.root.should be(task)
514
+ task.from_path('foo').root.should be(task)
515
+ end
516
+
517
+ it 'should return target task from target method' do
518
+ task = unzip(@target=>@zip)
519
+ task.target.should be(file(@target))
520
+ task.from_path('foo').target.should be(file(@target))
521
+ end
522
+
523
+ it 'should alias from_path as path' do
524
+ task = unzip(@target=>@zip)
525
+ task.from_path('foo').should be(task.path('foo'))
526
+ end
527
+ end