mguymon-buildr 1.4.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/CHANGELOG +1291 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +44 -0
  6. data/_buildr +35 -0
  7. data/_jbuildr +35 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/bnd.rb +147 -0
  10. data/addon/buildr/cobertura.rb +22 -0
  11. data/addon/buildr/drb.rb +281 -0
  12. data/addon/buildr/emma.rb +22 -0
  13. data/addon/buildr/hibernate.rb +149 -0
  14. data/addon/buildr/javacc.rb +85 -0
  15. data/addon/buildr/jaxb_xjc.rb +72 -0
  16. data/addon/buildr/jdepend.rb +60 -0
  17. data/addon/buildr/jetty.rb +248 -0
  18. data/addon/buildr/jibx.rb +86 -0
  19. data/addon/buildr/nailgun.rb +221 -0
  20. data/addon/buildr/openjpa.rb +88 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  23. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  27. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  28. data/addon/buildr/protobuf.rb +88 -0
  29. data/addon/buildr/xmlbeans.rb +93 -0
  30. data/bin/buildr +19 -0
  31. data/buildr.buildfile +58 -0
  32. data/buildr.gemspec +78 -0
  33. data/doc/_config.yml +1 -0
  34. data/doc/_layouts/default.html +90 -0
  35. data/doc/_layouts/preface.html +22 -0
  36. data/doc/artifacts.textile +217 -0
  37. data/doc/building.textile +276 -0
  38. data/doc/contributing.textile +268 -0
  39. data/doc/css/default.css +236 -0
  40. data/doc/css/print.css +101 -0
  41. data/doc/css/syntax.css +23 -0
  42. data/doc/download.textile +151 -0
  43. data/doc/extending.textile +212 -0
  44. data/doc/images/1442160941-frontcover.jpg +0 -0
  45. data/doc/images/asf-logo.gif +0 -0
  46. data/doc/images/asf-logo.png +0 -0
  47. data/doc/images/buildr-hires.png +0 -0
  48. data/doc/images/buildr.png +0 -0
  49. data/doc/images/favicon.png +0 -0
  50. data/doc/images/growl-icon.tiff +0 -0
  51. data/doc/images/note.png +0 -0
  52. data/doc/images/project-structure.png +0 -0
  53. data/doc/images/tip.png +0 -0
  54. data/doc/images/zbuildr.png +0 -0
  55. data/doc/images/zbuildr.tif +0 -0
  56. data/doc/index.textile +109 -0
  57. data/doc/installing.textile +284 -0
  58. data/doc/languages.textile +599 -0
  59. data/doc/mailing_lists.textile +29 -0
  60. data/doc/more_stuff.textile +845 -0
  61. data/doc/packaging.textile +618 -0
  62. data/doc/preface.textile +54 -0
  63. data/doc/projects.textile +276 -0
  64. data/doc/quick_start.textile +210 -0
  65. data/doc/releasing.textile +117 -0
  66. data/doc/scripts/buildr-git.rb +512 -0
  67. data/doc/scripts/gitflow.rb +296 -0
  68. data/doc/scripts/install-jruby.sh +44 -0
  69. data/doc/scripts/install-linux.sh +73 -0
  70. data/doc/scripts/install-osx.sh +52 -0
  71. data/doc/settings_profiles.textile +287 -0
  72. data/doc/testing.textile +247 -0
  73. data/etc/KEYS +189 -0
  74. data/lib/buildr.rb +44 -0
  75. data/lib/buildr/clojure.rb +34 -0
  76. data/lib/buildr/clojure/shell.rb +52 -0
  77. data/lib/buildr/core.rb +34 -0
  78. data/lib/buildr/core/application.rb +700 -0
  79. data/lib/buildr/core/build.rb +516 -0
  80. data/lib/buildr/core/cc.rb +166 -0
  81. data/lib/buildr/core/checks.rb +253 -0
  82. data/lib/buildr/core/common.rb +151 -0
  83. data/lib/buildr/core/compile.rb +622 -0
  84. data/lib/buildr/core/doc.rb +276 -0
  85. data/lib/buildr/core/environment.rb +129 -0
  86. data/lib/buildr/core/filter.rb +404 -0
  87. data/lib/buildr/core/generate.rb +197 -0
  88. data/lib/buildr/core/help.rb +119 -0
  89. data/lib/buildr/core/jrebel.rb +42 -0
  90. data/lib/buildr/core/linux.rb +30 -0
  91. data/lib/buildr/core/osx.rb +46 -0
  92. data/lib/buildr/core/progressbar.rb +161 -0
  93. data/lib/buildr/core/project.rb +975 -0
  94. data/lib/buildr/core/run.rb +43 -0
  95. data/lib/buildr/core/shell.rb +137 -0
  96. data/lib/buildr/core/test.rb +843 -0
  97. data/lib/buildr/core/transports.rb +575 -0
  98. data/lib/buildr/core/util.rb +537 -0
  99. data/lib/buildr/groovy.rb +20 -0
  100. data/lib/buildr/groovy/bdd.rb +106 -0
  101. data/lib/buildr/groovy/compiler.rb +153 -0
  102. data/lib/buildr/groovy/doc.rb +76 -0
  103. data/lib/buildr/groovy/shell.rb +57 -0
  104. data/lib/buildr/ide.rb +19 -0
  105. data/lib/buildr/ide/eclipse.rb +427 -0
  106. data/lib/buildr/ide/eclipse/java.rb +53 -0
  107. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  108. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  109. data/lib/buildr/ide/idea.rb +576 -0
  110. data/lib/buildr/java.rb +25 -0
  111. data/lib/buildr/java/ant.rb +94 -0
  112. data/lib/buildr/java/bdd.rb +460 -0
  113. data/lib/buildr/java/cobertura.rb +297 -0
  114. data/lib/buildr/java/commands.rb +223 -0
  115. data/lib/buildr/java/compiler.rb +135 -0
  116. data/lib/buildr/java/deprecated.rb +141 -0
  117. data/lib/buildr/java/doc.rb +86 -0
  118. data/lib/buildr/java/ecj.rb +69 -0
  119. data/lib/buildr/java/emma.rb +244 -0
  120. data/lib/buildr/java/external.rb +73 -0
  121. data/lib/buildr/java/jruby.rb +122 -0
  122. data/lib/buildr/java/jtestr_result.rb +295 -0
  123. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  124. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  125. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  126. data/lib/buildr/java/packaging.rb +734 -0
  127. data/lib/buildr/java/pom.rb +178 -0
  128. data/lib/buildr/java/rjb.rb +154 -0
  129. data/lib/buildr/java/test_result.rb +101 -0
  130. data/lib/buildr/java/tests.rb +362 -0
  131. data/lib/buildr/java/version_requirement.rb +172 -0
  132. data/lib/buildr/packaging.rb +25 -0
  133. data/lib/buildr/packaging/archive.rb +535 -0
  134. data/lib/buildr/packaging/artifact.rb +904 -0
  135. data/lib/buildr/packaging/artifact_namespace.rb +984 -0
  136. data/lib/buildr/packaging/artifact_search.rb +140 -0
  137. data/lib/buildr/packaging/gems.rb +105 -0
  138. data/lib/buildr/packaging/package.rb +249 -0
  139. data/lib/buildr/packaging/repository_array.rb +108 -0
  140. data/lib/buildr/packaging/tar.rb +189 -0
  141. data/lib/buildr/packaging/version_requirement.rb +192 -0
  142. data/lib/buildr/packaging/zip.rb +178 -0
  143. data/lib/buildr/packaging/ziptask.rb +356 -0
  144. data/lib/buildr/resources/buildr.icns +0 -0
  145. data/lib/buildr/resources/completed.png +0 -0
  146. data/lib/buildr/resources/failed.png +0 -0
  147. data/lib/buildr/resources/icons-license.txt +17 -0
  148. data/lib/buildr/run.rb +195 -0
  149. data/lib/buildr/scala.rb +26 -0
  150. data/lib/buildr/scala/bdd.rb +118 -0
  151. data/lib/buildr/scala/compiler.rb +242 -0
  152. data/lib/buildr/scala/doc.rb +142 -0
  153. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  154. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  155. data/lib/buildr/scala/shell.rb +52 -0
  156. data/lib/buildr/scala/tests.rb +171 -0
  157. data/lib/buildr/shell.rb +185 -0
  158. data/lib/buildr/version.rb +18 -0
  159. data/rakelib/all-in-one.rake +113 -0
  160. data/rakelib/checks.rake +57 -0
  161. data/rakelib/doc.rake +137 -0
  162. data/rakelib/metrics.rake +39 -0
  163. data/rakelib/package.rake +73 -0
  164. data/rakelib/release.rake +160 -0
  165. data/rakelib/rspec.rake +91 -0
  166. data/rakelib/setup.rake +66 -0
  167. data/rakelib/stage.rake +220 -0
  168. data/spec/addon/bnd_spec.rb +330 -0
  169. data/spec/addon/drb_spec.rb +328 -0
  170. data/spec/addon/jaxb_xjc_spec.rb +125 -0
  171. data/spec/core/application_spec.rb +631 -0
  172. data/spec/core/build_spec.rb +837 -0
  173. data/spec/core/cc_spec.rb +224 -0
  174. data/spec/core/checks_spec.rb +519 -0
  175. data/spec/core/common_spec.rb +725 -0
  176. data/spec/core/compile_spec.rb +658 -0
  177. data/spec/core/doc_spec.rb +195 -0
  178. data/spec/core/extension_spec.rb +201 -0
  179. data/spec/core/generate_spec.rb +33 -0
  180. data/spec/core/project_spec.rb +772 -0
  181. data/spec/core/run_spec.rb +93 -0
  182. data/spec/core/shell_spec.rb +146 -0
  183. data/spec/core/test_spec.rb +1320 -0
  184. data/spec/core/transport_spec.rb +544 -0
  185. data/spec/core/util_spec.rb +141 -0
  186. data/spec/groovy/bdd_spec.rb +80 -0
  187. data/spec/groovy/compiler_spec.rb +251 -0
  188. data/spec/groovy/doc_spec.rb +65 -0
  189. data/spec/ide/eclipse_spec.rb +739 -0
  190. data/spec/ide/idea_spec.rb +1145 -0
  191. data/spec/java/ant_spec.rb +37 -0
  192. data/spec/java/bdd_spec.rb +374 -0
  193. data/spec/java/cobertura_spec.rb +112 -0
  194. data/spec/java/commands_spec.rb +93 -0
  195. data/spec/java/compiler_spec.rb +252 -0
  196. data/spec/java/doc_spec.rb +56 -0
  197. data/spec/java/ecj_spec.rb +115 -0
  198. data/spec/java/emma_spec.rb +121 -0
  199. data/spec/java/external_spec.rb +56 -0
  200. data/spec/java/java_spec.rb +132 -0
  201. data/spec/java/packaging_spec.rb +1266 -0
  202. data/spec/java/run_spec.rb +78 -0
  203. data/spec/java/test_coverage_helper.rb +257 -0
  204. data/spec/java/tests_spec.rb +497 -0
  205. data/spec/packaging/archive_spec.rb +775 -0
  206. data/spec/packaging/artifact_namespace_spec.rb +743 -0
  207. data/spec/packaging/artifact_spec.rb +1074 -0
  208. data/spec/packaging/packaging_helper.rb +63 -0
  209. data/spec/packaging/packaging_spec.rb +719 -0
  210. data/spec/packaging/repository_array_spec.rb +109 -0
  211. data/spec/sandbox.rb +165 -0
  212. data/spec/scala/bdd_spec.rb +124 -0
  213. data/spec/scala/compiler_spec.rb +289 -0
  214. data/spec/scala/doc_spec.rb +88 -0
  215. data/spec/scala/scala.rb +38 -0
  216. data/spec/scala/tests_spec.rb +283 -0
  217. data/spec/spec_helpers.rb +369 -0
  218. data/spec/version_requirement_spec.rb +143 -0
  219. data/spec/xpath_matchers.rb +121 -0
  220. metadata +600 -0
@@ -0,0 +1,775 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18
+
19
+
20
+ module ArchiveTaskHelpers
21
+ # Not too smart, we just create some content based on file name to make sure you read what you write.
22
+ def content_for(file)
23
+ "Content for #{File.basename(file)}"
24
+ end
25
+
26
+ # Qualify a filename
27
+ #
28
+ # e.g. qualify("file.zip", "src") => "file-src.zip"
29
+ def qualify(filename, qualifier)
30
+ ext = (filename =~ /\.$/) ? "." : File.extname(filename)
31
+ base = filename[0..0-ext.size-1]
32
+ base + "-" + qualifier + ext
33
+ end
34
+
35
+ # Create an archive not using the archive task, this way we do have a file in existence, but we don't
36
+ # have an already invoked task. Yield an archive task to the block which can use it to include files,
37
+ # set options, etc.
38
+ def create_without_task
39
+ archive(qualify(@archive, "tmp")).tap do |task|
40
+ yield task if block_given?
41
+ task.invoke
42
+ mv task.name, @archive
43
+ end
44
+ end
45
+
46
+ def create_for_merge
47
+ zip(qualify(@archive, "src")).include(@files).tap do |task|
48
+ yield task
49
+ end
50
+ end
51
+
52
+ def init_dir
53
+ unless @dir
54
+ @dir = File.expand_path('test')
55
+ @files = %w{Test1.txt Text2.html}.map { |file| File.expand_path(file, @dir) }.
56
+ each { |file| write file, content_for(file) }
57
+ @empty_dirs = %w{EmptyDir1 EmptyDir2}.map { |file| File.expand_path(file, @dir) }.
58
+ each { |file| mkdir file }
59
+ end
60
+ end
61
+ end
62
+
63
+ shared_examples_for 'ArchiveTask' do
64
+ include ArchiveTaskHelpers
65
+
66
+ before(:each) do
67
+ init_dir
68
+ end
69
+
70
+ it 'should point to archive file' do
71
+ archive(@archive).name.should eql(@archive)
72
+ end
73
+
74
+ it 'should create file' do
75
+ lambda { archive(@archive).invoke }.should change { File.exist?(@archive) }.to(true)
76
+ end
77
+
78
+ it 'should create empty archive if no files included' do
79
+ archive(@archive).invoke
80
+ inspect_archive { |archive| archive.should be_empty }
81
+ end
82
+
83
+ it 'should raise error when include() is called with nil values' do
84
+ lambda { archive(@archive).include(nil) }.should raise_error
85
+ lambda { archive(@archive).include([nil]) }.should raise_error
86
+ end
87
+
88
+ it 'should create empty archive if called #clean method' do
89
+ archive(@archive).include(@files).clean.invoke
90
+ inspect_archive { |archive| archive.should be_empty }
91
+ end
92
+
93
+ it 'should archive all included files' do
94
+ archive(@archive).include(@files).invoke
95
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
96
+ inspect_archive.size.should eql(@files.size)
97
+ end
98
+
99
+ it 'should archive file tasks' do
100
+ tasks = @files.map { |fn| file(fn) }
101
+ archive(@archive).include(tasks).invoke
102
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
103
+ inspect_archive.size.should eql(@files.size)
104
+ end
105
+
106
+ it 'should invoke and archive file tasks' do
107
+ file = file('included') { write 'included' }
108
+ lambda { archive(@archive).include(file).invoke }.should change { File.exist?(file.to_s) }.to(true)
109
+ inspect_archive.keys.should include('included')
110
+ end
111
+
112
+ it 'should archive artifacts' do
113
+ write 'library-1.0.txt', 'library-1.0'
114
+ artifact("org.example:library:txt:1.0").from 'library-1.0.txt'
115
+ archive(@archive).include("org.example:library:txt:1.0").invoke
116
+ inspect_archive.keys.should include('library-1.0.txt')
117
+ end
118
+
119
+ it 'should archive project artifacts' do
120
+ define 'p1' do
121
+ project.version = '1.0'
122
+ package(:zip)
123
+ end
124
+ archive(@archive).include(project('p1')).invoke
125
+ inspect_archive.keys.should include('p1-1.0.zip')
126
+ end
127
+
128
+ it 'should include entry for directory' do
129
+ archive(@archive).include(@dir).invoke
130
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
131
+ end
132
+
133
+ it 'should not archive any excluded files' do
134
+ archive(@archive).include(@files).exclude(@files.last).invoke
135
+ inspect_archive do |archive|
136
+ archive.keys.should include(File.basename(@files.first))
137
+ archive.keys.should_not include(File.basename(@files.last))
138
+ end
139
+ end
140
+
141
+ it 'should not archive any excluded files in included directories' do
142
+ archive(@archive).include(@dir).exclude(@files.last).invoke
143
+ inspect_archive do |archive|
144
+ archive.keys.should include('test/' + File.basename(@files.first))
145
+ archive.keys.should_not include('test/' + File.basename(@files.last))
146
+ end
147
+ end
148
+
149
+ it 'should not archive any excluded files when using :from/:as' do
150
+ archive(@archive).include(:from=>@dir).exclude(@files.last).invoke
151
+ inspect_archive do |archive|
152
+ archive.keys.should include(File.basename(@files.first))
153
+ archive.keys.should_not include(File.basename(@files.last))
154
+ end
155
+ end
156
+
157
+ it 'should raise error when using :from with nil value' do
158
+ lambda {
159
+ archive(@archive).include(:from=>nil)
160
+ }.should raise_error
161
+ end
162
+
163
+ it 'should exclude entire directory and all its children' do
164
+ mkpath "#{@dir}/sub"
165
+ write "#{@dir}/sub/test"
166
+ archive(@archive).include(@dir).exclude("#{@dir}/sub").invoke
167
+ inspect_archive do |archive|
168
+ archive.keys.select { |file| file =~ /sub/ }.should be_empty
169
+ end
170
+ end
171
+
172
+ it 'should not archive any excluded files when pattern is *.ext' do
173
+ write "test/file.txt"
174
+ write "test/file.swf"
175
+ archive(@archive).include(@dir).exclude('**/*.swf').invoke
176
+ inspect_archive do |archive|
177
+ archive.keys.should include('test/file.txt')
178
+ archive.keys.should_not include('test/file.swf')
179
+ end
180
+ end
181
+
182
+ it 'should archive files into specified path' do
183
+ archive(@archive).include(@files, :path=>'code').invoke
184
+ inspect_archive { |archive| @files.each { |f| archive['code/' + File.basename(f)].should eql(content_for(f)) } }
185
+ end
186
+
187
+ it 'should include entry for directory' do
188
+ archive(@archive).include(@dir).invoke
189
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
190
+ end
191
+
192
+ it 'should archive files into specified path' do
193
+ archive(@archive).include(@files, :path=>'code').invoke
194
+ inspect_archive { |archive| @files.each { |f| archive['code/' + File.basename(f)].should eql(content_for(f)) } }
195
+ end
196
+
197
+ it 'should archive directories into specified path' do
198
+ archive(@archive).include(@dir, :path=>'code').invoke
199
+ inspect_archive { |archive| @files.each { |f| archive['code/test/' + File.basename(f)].should eql(content_for(f)) } }
200
+ end
201
+
202
+ it 'should understand . in path' do
203
+ archive(@archive).path('.').should == archive(@archive).path('')
204
+ archive(@archive).path('foo').path('.').should == archive(@archive).path('foo')
205
+ end
206
+
207
+ it 'should understand .. in path' do
208
+ archive(@archive).path('..').should == archive(@archive).path('')
209
+ archive(@archive).path('foo').path('..').should == archive(@archive).path('')
210
+ archive(@archive).path('foo/bar').path('..').should == archive(@archive).path('foo')
211
+ end
212
+
213
+ it 'should understand leading / in path' do
214
+ archive(@archive).path('/').should == archive(@archive).path('')
215
+ archive(@archive).path('foo/bar').path('/').should == archive(@archive).path('')
216
+ end
217
+
218
+ it 'should archive file into specified name' do
219
+ archive(@archive).include(@files.first, :as=>'test/sample').invoke
220
+ inspect_archive { |archive| @files.each { |f| archive['test/sample'].should eql(content_for(@files.first)) } }
221
+ end
222
+
223
+ it 'should archive directory into specified alias, without using "."' do
224
+ archive(@archive).include(@dir, :as=>'.').invoke
225
+ inspect_archive { |archive| archive.keys.should_not include(".") }
226
+ end
227
+
228
+ it 'should archive directories into specified alias, even if it has the same name' do
229
+ archive(@archive).include(@dir, :as=>File.basename(@dir)).invoke
230
+ inspect_archive { |archive|
231
+ archive.keys.should_not include "#{File.basename(@dir)}"
232
+ }
233
+ end
234
+
235
+ it 'should archive file into specified name/path' do
236
+ archive(@archive).include(@files.first, :as=>'test/sample', :path=>'path').invoke
237
+ inspect_archive { |archive| @files.each { |f| archive['path/test/sample'].should eql(content_for(@files.first)) } }
238
+ end
239
+
240
+ it 'should archive files starting with dot' do
241
+ write 'test/.config', '# configuration'
242
+ archive(@archive).include('test').invoke
243
+ inspect_archive { |archive| @files.each { |f| archive['test/.config'].should eql('# configuration') } }
244
+ end
245
+
246
+ it 'should archive directory into specified name' do
247
+ archive(@archive).include(@dir, :as=>'code').invoke
248
+ inspect_archive { |archive| @files.each { |f| archive['code/' + File.basename(f)].should eql(content_for(f)) } }
249
+ end
250
+
251
+ it 'should archive directory into specified name/path' do
252
+ archive(@archive).include(@dir, :as=>'code', :path=>'path').invoke
253
+ inspect_archive { |archive| @files.each { |f| archive['path/code/' + File.basename(f)].should eql(content_for(f)) } }
254
+ end
255
+
256
+ it 'should archive directory contents' do
257
+ archive(@archive).include(@dir, :as=>'.').invoke
258
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
259
+ end
260
+
261
+ it 'should archive directory contents into specified path' do
262
+ archive(@archive).include(@dir, :as=>'.', :path=>'path').invoke
263
+ inspect_archive { |archive| @files.each { |f| archive['path/' + File.basename(f)].should eql(content_for(f)) } }
264
+ end
265
+
266
+ it 'should not allow two files with the :as argument' do
267
+ lambda { archive(@archive).include(@files.first, @files.last, :as=>'test/sample') }.should raise_error(RuntimeError, /one file/)
268
+ end
269
+
270
+ it 'should expand another archive file' do
271
+ create_for_merge do |src|
272
+ archive(@archive).merge(src)
273
+ archive(@archive).invoke
274
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
275
+ end
276
+ end
277
+
278
+ it 'should expand another archive file with include pattern' do
279
+ create_for_merge do |src|
280
+ archive(@archive).merge(src).include(File.basename(@files.first))
281
+ archive(@archive).invoke
282
+ inspect_archive do |archive|
283
+ archive[File.basename(@files.first)].should eql(content_for(@files.first))
284
+ archive[File.basename(@files.last)].should be_nil
285
+ end
286
+ end
287
+ end
288
+
289
+ it 'should expand another archive file with exclude pattern' do
290
+ create_for_merge do |src|
291
+ archive(@archive).merge(src).exclude(File.basename(@files.first))
292
+ archive(@archive).invoke
293
+ inspect_archive do |archive|
294
+ @files[1..-1].each { |f| archive[File.basename(f)].should eql(content_for(f)) }
295
+ archive[File.basename(@files.first)].should be_nil
296
+ end
297
+ end
298
+ end
299
+
300
+ it 'should expand another archive file with nested exclude pattern' do
301
+ @files = %w{Test1.txt Text2.html}.map { |file| File.join(@dir, "foo", file) }.
302
+ each { |file| write file, content_for(file) }
303
+ zip(qualify(@archive, "src")).include(@dir).tap do |task|
304
+ archive(@archive).merge(task).exclude('test/*')
305
+ archive(@archive).invoke
306
+ inspect_archive.should be_empty
307
+ end
308
+ end
309
+
310
+ it 'should expand another archive file into path' do
311
+ create_for_merge do |src|
312
+ archive(@archive).path('test').merge(src)
313
+ archive(@archive).invoke
314
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
315
+ end
316
+ end
317
+
318
+ it 'should expand another archive file into path with :path option' do
319
+ create_for_merge do |src|
320
+ archive(@archive).merge(src, :path=>'test')
321
+ archive(@archive).invoke
322
+ inspect_archive { |archive| @files.each { |f| archive['test/' + File.basename(f)].should eql(content_for(f)) } }
323
+ end
324
+ end
325
+
326
+ it "should expand another archive file into path with :path=>'/'" do
327
+ create_for_merge do |src|
328
+ archive(@archive).merge(src, :path=>'/')
329
+ archive(@archive).invoke
330
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
331
+ end
332
+ end
333
+
334
+ it 'should expand another archive file into path with merge option' do
335
+ create_for_merge do |src|
336
+ archive(@archive).include(src, :merge=>true)
337
+ archive(@archive).invoke
338
+ inspect_archive { |archive| @files.each { |f| archive[File.basename(f)].should eql(content_for(f)) } }
339
+ end
340
+ end
341
+
342
+ it 'should update if one of the files is recent' do
343
+ create_without_task { |archive| archive.include(@files) }
344
+ # Touch archive file to some point in the past. This effectively makes
345
+ # all included files newer.
346
+ File.utime Time.now - 100, Time.now - 100, @archive
347
+ archive(@archive).include(@files).invoke
348
+ File.stat(@archive).mtime.should be_close(Time.now, 10)
349
+ end
350
+
351
+ it 'should update if a file in a subdir is more recent' do
352
+ subdir = File.expand_path("subdir", @dir)
353
+ test3 = File.expand_path("test3.css", subdir)
354
+
355
+ mkdir_p subdir
356
+ write test3, '/* Original */'
357
+
358
+ create_without_task { |archive| archive.include(:from => @dir) }
359
+ inspect_archive { |archive| archive["subdir/test3.css"].should eql('/* Original */') }
360
+
361
+ write test3, '/* Refreshed */'
362
+ File.utime(Time.now + 100, Time.now + 100, test3)
363
+ archive(@archive).include(:from => @dir).invoke
364
+ inspect_archive { |archive| archive["subdir/test3.css"].should eql('/* Refreshed */') }
365
+ end
366
+
367
+ it 'should do nothing if all files are uptodate' do
368
+ create_without_task { |archive| archive.include(@files) }
369
+ # By touching all files in the past, there's nothing new to update.
370
+ (@files + [@archive]).each { |f| File.utime Time.now - 100, Time.now - 100, f }
371
+ archive(@archive).include(@files).invoke
372
+ File.stat(@archive).mtime.should be_close(Time.now - 100, 10)
373
+ end
374
+
375
+ it 'should update if one of the files is recent' do
376
+ create_without_task { |archive| archive.include(@files) }
377
+ # Change files, we expect to see new content.
378
+ write @files.first, '/* Refreshed */'
379
+ File.utime(Time.now - 100, Time.now - 100, @archive) # Touch archive file to some point in the past.
380
+ archive(@archive).include(@files).invoke
381
+ inspect_archive { |archive| archive[File.basename(@files.first)].should eql('/* Refreshed */') }
382
+ end
383
+
384
+ it 'should create new archive when updating' do
385
+ create_without_task { |archive| archive.include(@files) }
386
+ File.utime(Time.now - 100, Time.now - 100, @archive) # Touch archive file to some point in the past.
387
+ archive(@archive).include(@files[1..-1]).invoke
388
+ inspect_archive.size.should be(@files.size - 1)
389
+ end
390
+
391
+ it 'should not accept invalid options' do
392
+ archive(@archive).include(@files)
393
+ lambda { archive(@archive).with :option=>true }.should raise_error
394
+ end
395
+ end
396
+
397
+ describe TarTask do
398
+ it_should_behave_like 'ArchiveTask'
399
+
400
+ before(:each) do
401
+ @archive = File.expand_path('test.tar')
402
+ end
403
+
404
+ define_method(:archive) { |file| tar(file) }
405
+
406
+ def inspect_archive
407
+ entries = {}
408
+ Archive::Tar::Minitar.open @archive, 'r' do |reader|
409
+ reader.each { |entry| entries[entry.directory ? "#{entry.name}/" : entry.name] = entry.read }
410
+ end
411
+ yield entries if block_given?
412
+ entries
413
+ end
414
+ end
415
+
416
+
417
+ describe TarTask, ' gzipped' do
418
+ it_should_behave_like 'ArchiveTask'
419
+
420
+ before(:each) do
421
+ @archive = File.expand_path('test.tgz')
422
+ end
423
+
424
+ define_method(:archive) { |file| tar(file) }
425
+
426
+ def inspect_archive
427
+ entries = {}
428
+ Zlib::GzipReader.open @archive do |gzip|
429
+ Archive::Tar::Minitar.open gzip, 'r' do |reader|
430
+ reader.each { |entry| entries[entry.directory ? "#{entry.name}/" : entry.name] = entry.read }
431
+ end
432
+ end
433
+ yield entries if block_given?
434
+ entries
435
+ end
436
+ end
437
+
438
+ describe "ZipTask" do
439
+ include ArchiveTaskHelpers
440
+
441
+ it_should_behave_like 'ArchiveTask'
442
+
443
+ before(:each) do
444
+ init_dir
445
+ @archive = File.expand_path('test.zip')
446
+ end
447
+
448
+ define_method(:archive) { |file| zip(file) }
449
+
450
+ after(:each) do
451
+ checkZip(@archive)
452
+ end
453
+
454
+ # Check for possible corruption using Java's ZipInputStream and Java's "jar" command since
455
+ # they are stricter than rubyzip
456
+ def checkZip(file)
457
+ return unless File.exist?(file)
458
+ zip = Java.java.util.zip.ZipInputStream.new(Java.java.io.FileInputStream.new(file))
459
+ zip_entry_count = 0
460
+ while entry = zip.getNextEntry do
461
+ # just iterate over all entries
462
+ zip_entry_count = zip_entry_count + 1
463
+ end
464
+ zip.close()
465
+
466
+ # jar tool fails with "ZipException: error in opening zip file" if empty
467
+ if zip_entry_count > 0
468
+ sh "#{File.join(ENV['JAVA_HOME'], 'bin', 'jar')} tvf #{file}"
469
+ end
470
+ end
471
+
472
+ def inspect_archive
473
+ entries = {}
474
+ Zip::ZipFile.open @archive do |zip|
475
+ zip.entries.each do |entry|
476
+ # Ignore the / directory created for empty ZIPs when using java.util.zip.
477
+ entries[entry.to_s] = zip.read(entry) unless entry.to_s == '/'
478
+ end
479
+ end
480
+ yield entries if block_given?
481
+ entries
482
+ end
483
+
484
+ it 'should include empty dirs' do
485
+ archive(@archive).include(@dir)
486
+ archive(@archive).invoke
487
+ inspect_archive do |archive|
488
+ archive.keys.should include('test/EmptyDir1/')
489
+ end
490
+ end
491
+
492
+ it 'should include empty dirs from Dir' do
493
+ archive(@archive).include(Dir["#{@dir}/*"])
494
+ archive(@archive).invoke
495
+ inspect_archive do |archive|
496
+ archive.keys.should include('EmptyDir1/')
497
+ end
498
+ end
499
+
500
+ it 'should work with path object' do
501
+ archive(@archive).path('code').include(@files)
502
+ archive(@archive).invoke
503
+ inspect_archive { |archive| archive.keys.should include('code/') }
504
+ end
505
+
506
+ it 'should have path object that includes empty dirs' do
507
+ archive(@archive).path('code').include(Dir["#{@dir}/*"])
508
+ archive(@archive).invoke
509
+ inspect_archive do |archive|
510
+ archive.keys.should include('code/EmptyDir1/')
511
+ end
512
+ end
513
+
514
+ # chmod is not reliable on Windows
515
+ unless Buildr::Util.win_os?
516
+ it 'should preserve file permissions' do
517
+ # with JRuby it's important to use absolute paths with File.chmod()
518
+ # http://jira.codehaus.org/browse/JRUBY-3300
519
+ hello = File.expand_path('src/main/bin/hello')
520
+ write hello, 'echo hi'
521
+ File.chmod(0777, hello)
522
+ fail("Failed to set permission on #{hello}") unless (File.stat(hello).mode & 0777) == 0777
523
+
524
+ zip('foo.zip').include('src/main/bin/*').invoke
525
+ unzip('target' => 'foo.zip').extract
526
+ (File.stat('target/hello').mode & 0777).should == 0777
527
+ end
528
+ end
529
+
530
+ end
531
+
532
+ describe Unzip do
533
+ before(:each) do
534
+ @zip = File.expand_path('test.zip')
535
+ @dir = File.expand_path('test')
536
+ @files = %w{Test1.txt Text2.html}.map { |file| File.join(@dir, file) }.
537
+ each { |file| write file, content_for(file) }
538
+ @target = File.expand_path('target')
539
+ @targz = File.expand_path('test.tar.gz')
540
+ @targz2 = File.expand_path('test.tgz')
541
+ end
542
+
543
+ # Not too smart, we just create some content based on file name to
544
+ # make sure you read what you write.
545
+ def content_for(file)
546
+ "Content for #{File.basename(file)}"
547
+ end
548
+
549
+ def with_tar(*args)
550
+ tar(@targz).include(*args.empty? ? @files : args).invoke
551
+ yield
552
+ end
553
+
554
+ def with_tar_too(*args)
555
+ tar(@targz2).include(*args.empty? ? @files : args).invoke
556
+ yield
557
+ end
558
+
559
+ def with_zip(*args)
560
+ zip(@zip).include(*args.empty? ? @files : args).invoke
561
+ yield
562
+ end
563
+
564
+ it 'should touch target directory' do
565
+ with_zip do
566
+ mkdir @target
567
+ File.utime(Time.now - 10, Time.now - 10, @target)
568
+ unzip(@target=>@zip).target.invoke
569
+ end
570
+ File.stat(@target).mtime.should be_close(Time.now, 2)
571
+ end
572
+
573
+ it 'should expand files' do
574
+ with_zip do
575
+ unzip(@target=>@zip).target.invoke
576
+ @files.each { |f| File.read(File.join(@target, File.basename(f))).should eql(content_for(f)) }
577
+ end
578
+ end
579
+
580
+ it 'should expand files from a tar.gz file' do
581
+ with_tar do
582
+ unzip(@target=>@targz).target.invoke
583
+ @files.each { |f| File.read(File.join(@target, File.basename(f))).should eql(content_for(f)) }
584
+ end
585
+ end
586
+
587
+ it 'should expand files from a .tgz file' do
588
+ with_tar_too do
589
+ unzip(@target=>@targz2).target.invoke
590
+ @files.each { |f| File.read(File.join(@target, File.basename(f))).should eql(content_for(f)) }
591
+ end
592
+ end
593
+
594
+ it 'should expand all files' do
595
+ with_zip do
596
+ unzip(@target=>@zip).target.invoke
597
+ FileList[File.join(@target, '*')].size.should be(@files.size)
598
+ end
599
+ end
600
+
601
+ it 'should expand all files from a .tar.gz file' do
602
+ with_tar do
603
+ unzip(@target=>@targz).target.invoke
604
+ FileList[File.join(@target, '*')].size.should be(@files.size)
605
+ end
606
+ end
607
+
608
+ it 'should expand only included files' do
609
+ with_zip do
610
+ only = File.basename(@files.first)
611
+ unzip(@target=>@zip).include(only).target.invoke
612
+ FileList[File.join(@target, '*')].should include(File.expand_path(only, @target))
613
+ FileList[File.join(@target, '*')].size.should be(1)
614
+ end
615
+ end
616
+
617
+ it 'should expand only included files from a .tar.gz file' do
618
+ with_tar do
619
+ only = File.basename(@files.first)
620
+ unzip(@target=>@targz).include(only).target.invoke
621
+ FileList[File.join(@target, '*')].should include(File.expand_path(only, @target))
622
+ FileList[File.join(@target, '*')].size.should be(1)
623
+ end
624
+ end
625
+
626
+ it 'should expand all but excluded files' do
627
+ with_zip do
628
+ except = File.basename(@files.first)
629
+ unzip(@target=>@zip).exclude(except).target.invoke
630
+ FileList[File.join(@target, '*')].should_not include(File.expand_path(except, @target))
631
+ FileList[File.join(@target, '*')].size.should be(@files.size - 1)
632
+ end
633
+ end
634
+
635
+ it 'should expand all but excluded files with a .tar.gz file' do
636
+ with_tar do
637
+ except = File.basename(@files.first)
638
+ unzip(@target=>@targz).exclude(except).target.invoke
639
+ FileList[File.join(@target, '*')].should_not include(File.expand_path(except, @target))
640
+ FileList[File.join(@target, '*')].size.should be(@files.size - 1)
641
+ end
642
+ end
643
+
644
+ it 'should include with nested path patterns' do
645
+ with_zip @files, :path=>'test/path' do
646
+ only = File.basename(@files.first)
647
+ unzip(@target=>@zip).include(only).target.invoke
648
+ FileList[File.join(@target, '*')].should be_empty
649
+
650
+ Rake::Task.clear ; rm_rf @target
651
+ unzip(@target=>@zip).include('test/path/' + only).target.invoke
652
+ FileList[File.join(@target, 'test/path/*')].size.should be(1)
653
+
654
+ Rake::Task.clear ; rm_rf @target
655
+ unzip(@target=>@zip).include('test/**/*').target.invoke
656
+ FileList[File.join(@target, 'test/path/*')].size.should be(2)
657
+
658
+ Rake::Task.clear ; rm_rf @target
659
+ unzip(@target=>@zip).include('test/*').target.invoke
660
+ FileList[File.join(@target, 'test/path/*')].size.should be(2)
661
+ end
662
+ end
663
+
664
+ it 'should include with nested path patterns with a .tar.gz file' do
665
+ with_tar @files, :path=>'test/path' do
666
+ only = File.basename(@files.first)
667
+ unzip(@target=>@targz).include(only).target.invoke
668
+ FileList[File.join(@target, '*')].should be_empty
669
+
670
+ Rake::Task.clear ; rm_rf @target
671
+ unzip(@target=>@targz).include('test/path/' + only).target.invoke
672
+ FileList[File.join(@target, 'test/path/*')].size.should be(1)
673
+
674
+ Rake::Task.clear ; rm_rf @target
675
+ unzip(@target=>@targz).include('test/**/*').target.invoke
676
+ FileList[File.join(@target, 'test/path/*')].size.should be(2)
677
+ end
678
+ end
679
+
680
+ it 'should include with relative path' do
681
+ with_zip @files, :path=>'test/path' do
682
+ only = File.basename(@files.first)
683
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include(only) }.target.invoke
684
+ FileList[File.join(@target, '*')].should be_empty
685
+
686
+ Rake::Task.clear ; rm_rf @target
687
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('test/*') }.target.invoke
688
+ FileList[File.join(@target, 'path/*')].should be_empty
689
+
690
+ Rake::Task.clear ; rm_rf @target
691
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('path/*' + only) }.target.invoke
692
+ FileList[File.join(@target, 'path/*')].size.should be(1)
693
+
694
+ Rake::Task.clear ; rm_rf @target
695
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').include('path/*') }.target.invoke
696
+ FileList[File.join(@target, 'path/*')].size.should be(2)
697
+ end
698
+ end
699
+
700
+ it 'should include with relative path with a .tar.gz file' do
701
+ with_tar @files, :path=>'test/path' do
702
+ only = File.basename(@files.first)
703
+ unzip(@target=>@targz).tap { |unzip| unzip.from_path('test').include(only) }.target.invoke
704
+ FileList[File.join(@target, '*')].should be_empty
705
+
706
+ Rake::Task.clear ; rm_rf @target
707
+ unzip(@target=>@targz).tap { |unzip| unzip.from_path('test').include('test/*') }.target.invoke
708
+ FileList[File.join(@target, 'path/*')].should be_empty
709
+
710
+ Rake::Task.clear ; rm_rf @target
711
+ unzip(@target=>@targz).tap { |unzip| unzip.from_path('test').include('path/*' + only) }.target.invoke
712
+ FileList[File.join(@target, 'path/*')].size.should be(1)
713
+
714
+ Rake::Task.clear ; rm_rf @target
715
+ unzip(@target=>@targz).tap { |unzip| unzip.from_path('test').include('path/*') }.target.invoke
716
+ FileList[File.join(@target, 'path/*')].size.should be(2)
717
+ end
718
+ end
719
+
720
+ it 'should exclude with relative path' do
721
+ with_zip @files, :path=>'test' do
722
+ except = File.basename(@files.first)
723
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('test').exclude(except) }.target.invoke
724
+ FileList[File.join(@target, '*')].should include(File.join(@target, File.basename(@files[1])))
725
+ FileList[File.join(@target, '*')].size.should be(@files.size - 1)
726
+ end
727
+ end
728
+
729
+ it 'should exclude with relative path on a tar.gz file' do
730
+ with_tar @files, :path=>'test' do
731
+ except = File.basename(@files.first)
732
+ unzip(@target=>@targz).tap { |unzip| unzip.from_path('test').exclude(except) }.target.invoke
733
+ FileList[File.join(@target, '*')].should include(File.join(@target, File.basename(@files[1])))
734
+ FileList[File.join(@target, '*')].size.should be(@files.size - 1)
735
+ end
736
+ end
737
+
738
+ it "should handle relative paths without any includes or excludes" do
739
+ lib_files = %w{Test3.so Test4.rb}.
740
+ map { |file| File.join(@dir, file) }.
741
+ each { |file| write file, content_for(file) }
742
+ zip(@zip).include(@files, :path => 'src').include(lib_files, :path => 'lib').invoke
743
+
744
+ unzip(@target=>@zip).tap { |unzip| unzip.from_path('lib') }.target.invoke
745
+ FileList[File.join(@target, '**/*')].should have(2).files
746
+ end
747
+
748
+ it "should handle relative paths without any includes or excludes with a tar.gz file" do
749
+ lib_files = %w{Test3.so Test4.rb}.
750
+ map { |file| File.join(@dir, file) }.
751
+ each { |file| write file, content_for(file) }
752
+ tar(@targz).include(@files, :path => 'src').include(lib_files, :path => 'lib').invoke
753
+
754
+ unzip(@target=>@targz).tap { |unzip| unzip.from_path('lib') }.target.invoke
755
+ FileList[File.join(@target, '**/*')].should have(2).files
756
+ end
757
+
758
+ it 'should return itself from root method' do
759
+ task = unzip(@target=>@zip)
760
+ task.root.should be(task)
761
+ task.from_path('foo').root.should be(task)
762
+ end
763
+
764
+ it 'should return target task from target method' do
765
+ task = unzip(@target=>@zip)
766
+ task.target.should be(file(@target))
767
+ task.from_path('foo').target.should be(file(@target))
768
+ end
769
+
770
+ it 'should alias from_path as path' do
771
+ task = unzip(@target=>@zip)
772
+ task.from_path('foo').should be(task.path('foo'))
773
+ end
774
+
775
+ end