ittayd-buildr 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/CHANGELOG +915 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +64 -0
  7. data/_buildr +28 -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/path.rb +136 -0
  27. data/addon/buildr/xmlbeans.rb +93 -0
  28. data/bin/buildr +19 -0
  29. data/buildr.buildfile +53 -0
  30. data/buildr.gemspec +58 -0
  31. data/doc/css/default.css +228 -0
  32. data/doc/css/print.css +100 -0
  33. data/doc/css/syntax.css +52 -0
  34. data/doc/images/apache-incubator-logo.png +0 -0
  35. data/doc/images/buildr-hires.png +0 -0
  36. data/doc/images/buildr.png +0 -0
  37. data/doc/images/favicon.png +0 -0
  38. data/doc/images/growl-icon.tiff +0 -0
  39. data/doc/images/note.png +0 -0
  40. data/doc/images/project-structure.png +0 -0
  41. data/doc/images/tip.png +0 -0
  42. data/doc/images/zbuildr.tif +0 -0
  43. data/doc/pages/artifacts.textile +207 -0
  44. data/doc/pages/building.textile +240 -0
  45. data/doc/pages/contributing.textile +208 -0
  46. data/doc/pages/download.textile +62 -0
  47. data/doc/pages/extending.textile +175 -0
  48. data/doc/pages/getting_started.textile +273 -0
  49. data/doc/pages/index.textile +42 -0
  50. data/doc/pages/languages.textile +407 -0
  51. data/doc/pages/mailing_lists.textile +17 -0
  52. data/doc/pages/more_stuff.textile +314 -0
  53. data/doc/pages/packaging.textile +427 -0
  54. data/doc/pages/projects.textile +274 -0
  55. data/doc/pages/recipes.textile +103 -0
  56. data/doc/pages/settings_profiles.textile +274 -0
  57. data/doc/pages/testing.textile +212 -0
  58. data/doc/pages/troubleshooting.textile +103 -0
  59. data/doc/pages/whats_new.textile +323 -0
  60. data/doc/print.haml +51 -0
  61. data/doc/print.toc.yaml +29 -0
  62. data/doc/scripts/buildr-git.rb +412 -0
  63. data/doc/scripts/install-jruby.sh +44 -0
  64. data/doc/scripts/install-linux.sh +64 -0
  65. data/doc/scripts/install-osx.sh +52 -0
  66. data/doc/site.haml +56 -0
  67. data/doc/site.toc.yaml +47 -0
  68. data/etc/KEYS +151 -0
  69. data/etc/git-svn-authors +16 -0
  70. data/lib/buildr/core/application.rb +665 -0
  71. data/lib/buildr/core/build.rb +311 -0
  72. data/lib/buildr/core/checks.rb +254 -0
  73. data/lib/buildr/core/common.rb +150 -0
  74. data/lib/buildr/core/compile.rb +590 -0
  75. data/lib/buildr/core/environment.rb +117 -0
  76. data/lib/buildr/core/filter.rb +366 -0
  77. data/lib/buildr/core/generate.rb +195 -0
  78. data/lib/buildr/core/help.rb +119 -0
  79. data/lib/buildr/core/osx.rb +49 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +923 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +560 -0
  84. data/lib/buildr/core/util.rb +294 -0
  85. data/lib/buildr/core.rb +29 -0
  86. data/lib/buildr/groovy/bdd.rb +106 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/groovy.rb +18 -0
  89. data/lib/buildr/ide/eclipse.rb +222 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +190 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +212 -0
  94. data/lib/buildr/ide.rb +19 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +451 -0
  97. data/lib/buildr/java/cobertura.rb +236 -0
  98. data/lib/buildr/java/commands.rb +211 -0
  99. data/lib/buildr/java/compiler.rb +348 -0
  100. data/lib/buildr/java/deprecated.rb +141 -0
  101. data/lib/buildr/java/emma.rb +238 -0
  102. data/lib/buildr/java/jruby.rb +117 -0
  103. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  104. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  105. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  106. data/lib/buildr/java/packaging.rb +717 -0
  107. data/lib/buildr/java/pom.rb +174 -0
  108. data/lib/buildr/java/rjb.rb +155 -0
  109. data/lib/buildr/java/test_result.rb +307 -0
  110. data/lib/buildr/java/tests.rb +329 -0
  111. data/lib/buildr/java/version_requirement.rb +172 -0
  112. data/lib/buildr/java.rb +23 -0
  113. data/lib/buildr/packaging/archive.rb +488 -0
  114. data/lib/buildr/packaging/artifact.rb +759 -0
  115. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  116. data/lib/buildr/packaging/artifact_search.rb +140 -0
  117. data/lib/buildr/packaging/gems.rb +102 -0
  118. data/lib/buildr/packaging/package.rb +233 -0
  119. data/lib/buildr/packaging/tar.rb +186 -0
  120. data/lib/buildr/packaging/version_requirement.rb +172 -0
  121. data/lib/buildr/packaging/zip.rb +64 -0
  122. data/lib/buildr/packaging/ziptask.rb +313 -0
  123. data/lib/buildr/packaging.rb +24 -0
  124. data/lib/buildr/resources/buildr.icns +0 -0
  125. data/lib/buildr/scala/compiler.rb +109 -0
  126. data/lib/buildr/scala/tests.rb +203 -0
  127. data/lib/buildr/scala.rb +19 -0
  128. data/lib/buildr.rb +33 -0
  129. data/rakelib/apache.rake +191 -0
  130. data/rakelib/changelog.rake +57 -0
  131. data/rakelib/doc.rake +103 -0
  132. data/rakelib/package.rake +76 -0
  133. data/rakelib/release.rake +65 -0
  134. data/rakelib/rspec.rake +83 -0
  135. data/rakelib/rubyforge.rake +56 -0
  136. data/rakelib/scm.rake +49 -0
  137. data/rakelib/setup.rake +81 -0
  138. data/rakelib/stage.rake +48 -0
  139. data/spec/addon/drb_spec.rb +328 -0
  140. data/spec/core/application_spec.rb +419 -0
  141. data/spec/core/build_spec.rb +423 -0
  142. data/spec/core/checks_spec.rb +519 -0
  143. data/spec/core/common_spec.rb +670 -0
  144. data/spec/core/compile_spec.rb +582 -0
  145. data/spec/core/generate_spec.rb +33 -0
  146. data/spec/core/project_spec.rb +776 -0
  147. data/spec/core/test_spec.rb +1098 -0
  148. data/spec/core/transport_spec.rb +500 -0
  149. data/spec/groovy/bdd_spec.rb +80 -0
  150. data/spec/groovy/compiler_spec.rb +239 -0
  151. data/spec/ide/eclipse_spec.rb +311 -0
  152. data/spec/java/ant.rb +33 -0
  153. data/spec/java/bdd_spec.rb +358 -0
  154. data/spec/java/cobertura_spec.rb +77 -0
  155. data/spec/java/compiler_spec.rb +446 -0
  156. data/spec/java/emma_spec.rb +120 -0
  157. data/spec/java/java_spec.rb +96 -0
  158. data/spec/java/packaging_spec.rb +1120 -0
  159. data/spec/java/test_coverage_spec.rb +255 -0
  160. data/spec/java/tests_spec.rb +471 -0
  161. data/spec/packaging/archive_spec.rb +503 -0
  162. data/spec/packaging/artifact_namespace_spec.rb +646 -0
  163. data/spec/packaging/artifact_spec.rb +795 -0
  164. data/spec/packaging/packaging_helper.rb +63 -0
  165. data/spec/packaging/packaging_spec.rb +589 -0
  166. data/spec/sandbox.rb +139 -0
  167. data/spec/scala/compiler_spec.rb +228 -0
  168. data/spec/scala/tests_spec.rb +215 -0
  169. data/spec/spec_helpers.rb +327 -0
  170. data/spec/version_requirement_spec.rb +123 -0
  171. metadata +377 -0
@@ -0,0 +1,1120 @@
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
+ require File.join(File.dirname(__FILE__), '../packaging/packaging_helper')
19
+
20
+
21
+ describe Project, '#manifest' do
22
+ it 'should include user name' do
23
+ ENV['USER'] = 'MysteriousJoe'
24
+ define('foo').manifest['Build-By'].should eql('MysteriousJoe')
25
+ end
26
+
27
+ it 'should include JDK version' do
28
+ define('foo').manifest['Build-Jdk'].should =~ /^1\.\d+\.\w+$/
29
+ end
30
+
31
+ it 'should include project comment' do
32
+ desc 'My Project'
33
+ define('foo').manifest['Implementation-Title'].should eql('My Project')
34
+ end
35
+
36
+ it 'should include project name if no comment' do
37
+ define('foo').manifest['Implementation-Title'].should eql('foo')
38
+ end
39
+
40
+ it 'should include project version' do
41
+ define('foo', :version=>'2.1').manifest['Implementation-Version'].should eql('2.1')
42
+ end
43
+
44
+ it 'should not include project version unless specified' do
45
+ define('foo').manifest['Implementation-Version'].should be_nil
46
+ end
47
+
48
+ it 'should inherit from parent project' do
49
+ define('foo', :version=>'2.1') { define 'bar' }
50
+ project('foo:bar').manifest['Implementation-Version'].should eql('2.1')
51
+ end
52
+
53
+ end
54
+
55
+
56
+ shared_examples_for 'package with manifest' do
57
+ before do
58
+ @long_line = 'No line may be longer than 72 bytes (not characters), in its UTF8-encoded form. If a value would make the initial line longer than this, it should be continued on extra lines (each starting with a single SPACE).'
59
+ end
60
+
61
+ def package_with_manifest(manifest = nil)
62
+ packaging = @packaging
63
+ @project = define('foo', :version=>'1.2') do
64
+ package packaging
65
+ package(packaging).with(:manifest=>manifest) unless manifest.nil?
66
+ end
67
+ end
68
+
69
+ def inspect_manifest(package = nil)
70
+ package ||= project('foo').package(@packaging)
71
+ package.invoke
72
+ yield Buildr::Packaging::Java::Manifest.from_zip(package)
73
+ end
74
+
75
+ it 'should include default header when no options specified' do
76
+ ENV['USER'] = 'MysteriousJoe'
77
+ package_with_manifest # Nothing for default.
78
+ inspect_manifest do |manifest|
79
+ manifest.sections.size.should be(1)
80
+ manifest.main.should == {
81
+ 'Manifest-Version' =>'1.0',
82
+ 'Created-By' =>'Buildr',
83
+ 'Implementation-Title' =>@project.name,
84
+ 'Implementation-Version' =>'1.2',
85
+ 'Build-Jdk' =>ENV_JAVA['java.version'],
86
+ 'Build-By' =>'MysteriousJoe'
87
+ }
88
+ end
89
+ end
90
+
91
+ it 'should not exist when manifest=false' do
92
+ package_with_manifest false
93
+ @project.package(@packaging).invoke
94
+ Zip::ZipFile.open(@project.package(@packaging).to_s) do |zip|
95
+ zip.file.exist?('META-INF/MANIFEST.MF').should be_false
96
+ end
97
+ end
98
+
99
+ it 'should map manifest from hash' do
100
+ package_with_manifest 'Foo'=>1, :bar=>'Bar'
101
+ inspect_manifest do |manifest|
102
+ manifest.sections.size.should be(1)
103
+ manifest.main['Manifest-Version'].should eql('1.0')
104
+ manifest.main['Created-By'].should eql('Buildr')
105
+ manifest.main['Foo'].should eql('1')
106
+ manifest.main['bar'].should eql('Bar')
107
+ end
108
+ end
109
+
110
+ it 'should end hash manifest with EOL' do
111
+ package_with_manifest 'Foo'=>1, :bar=>'Bar'
112
+ package = project('foo').package(@packaging)
113
+ package.invoke
114
+ Zip::ZipFile.open(package.to_s) { |zip| zip.file.read('META-INF/MANIFEST.MF').should =~ /#{Buildr::Packaging::Java::Manifest::LINE_SEPARATOR}$/ }
115
+ end
116
+
117
+ it 'should break hash manifest lines longer than 72 characters using continuations' do
118
+ package_with_manifest 'foo'=>@long_line
119
+ package = project('foo').package(@packaging)
120
+ inspect_manifest do |manifest|
121
+ manifest.main['foo'].should == @long_line
122
+ end
123
+ end
124
+
125
+ it 'should map manifest from array' do
126
+ package_with_manifest [ { :foo=>'first' }, { :bar=>'second' } ]
127
+ inspect_manifest do |manifest|
128
+ manifest.sections.size.should be(2)
129
+ manifest.main['Manifest-Version'].should eql('1.0')
130
+ manifest.main['foo'].should eql('first')
131
+ manifest.sections.last['bar'].should eql('second')
132
+ end
133
+ end
134
+
135
+ it 'should end array manifest with EOL' do
136
+ package_with_manifest [ { :foo=>'first' }, { :bar=>'second' } ]
137
+ package = project('foo').package(@packaging)
138
+ package.invoke
139
+ Zip::ZipFile.open(package.to_s) { |zip| zip.file.read('META-INF/MANIFEST.MF')[-1].should == ?\n }
140
+ end
141
+
142
+ it 'should break array manifest lines longer than 72 characters using continuations' do
143
+ package_with_manifest ['foo'=>@long_line]
144
+ package = project('foo').package(@packaging)
145
+ inspect_manifest do |manifest|
146
+ manifest.main['foo'].should == @long_line
147
+ end
148
+ end
149
+
150
+ it 'should put Name: at beginning of section' do
151
+ package_with_manifest [ {}, { 'Name'=>'first', :Foo=>'first', :bar=>'second' } ]
152
+ package = project('foo').package(@packaging)
153
+ package.invoke
154
+ inspect_manifest do |manifest|
155
+ manifest.sections[1]["Name"].should == "first"
156
+ end
157
+ end
158
+
159
+ it 'should create manifest from proc' do
160
+ package_with_manifest lambda { 'Meta: data' }
161
+ inspect_manifest do |manifest|
162
+ manifest.sections.size.should be(1)
163
+ manifest.main['Manifest-Version'].should eql('1.0')
164
+ manifest.main['Meta'].should eql('data')
165
+ end
166
+ end
167
+
168
+ it 'should create manifest from file' do
169
+ write 'MANIFEST.MF', 'Meta: data'
170
+ package_with_manifest 'MANIFEST.MF'
171
+ inspect_manifest do |manifest|
172
+ manifest.sections.size.should be(1)
173
+ manifest.main['Meta'].should eql('data')
174
+ end
175
+ end
176
+
177
+ it 'should not add manifest version twice' do
178
+ write 'MANIFEST.MF', 'Manifest-Version: 1.9'
179
+ package_with_manifest 'MANIFEST.MF'
180
+ package ||= project('foo').package(@packaging)
181
+ package.invoke
182
+ Zip::ZipFile.open(package.to_s) do |zip|
183
+ zip.read('META-INF/MANIFEST.MF').scan(/(Manifest-Version)/m).size.should == 1
184
+ end
185
+ end
186
+
187
+ it 'should give precedence to version specified in manifest file' do
188
+ write 'MANIFEST.MF', 'Manifest-Version: 1.9'
189
+ package_with_manifest 'MANIFEST.MF'
190
+ inspect_manifest do |manifest|
191
+ manifest.main['Manifest-Version'].should == '1.9'
192
+ end
193
+ end
194
+
195
+ it 'should create manifest from task' do
196
+ file 'MANIFEST.MF' do |task|
197
+ write task.to_s, 'Meta: data'
198
+ end
199
+ package_with_manifest 'MANIFEST.MF'
200
+ inspect_manifest do |manifest|
201
+ manifest.sections.size.should be(1)
202
+ manifest.main['Manifest-Version'].should eql('1.0')
203
+ manifest.main['Meta'].should eql('data')
204
+ end
205
+ end
206
+
207
+ it 'should respond to with() and accept manifest' do
208
+ write 'DISCLAIMER'
209
+ mkpath 'target/classes'
210
+ packaging = @packaging
211
+ define('foo', :version=>'1.0') { package(packaging).with :manifest=>{'Foo'=>'data'} }
212
+ inspect_manifest { |manifest| manifest.main['Foo'].should eql('data') }
213
+ end
214
+
215
+ it 'should include META-INF directory' do
216
+ packaging = @packaging
217
+ package = define('foo', :version=>'1.0') { package(packaging) }.packages.first
218
+ package.invoke
219
+ Zip::ZipFile.open(package.to_s) do |zip|
220
+ zip.entries.map(&:to_s).should include('META-INF/')
221
+ end
222
+ end
223
+
224
+ it 'should inherit manifest from parent project' do
225
+ packaging = @packaging
226
+ package = nil
227
+ define('foo', :version => '1.0') do
228
+ manifest['Foo'] = '1'
229
+ package(packaging)
230
+ define('bar', :version => '1.0') do
231
+ manifest['bar'] = 'Bar'
232
+ package(:jar)
233
+ package = packages.first
234
+ end
235
+ end
236
+ inspect_manifest(package) do |manifest|
237
+ manifest.sections.size.should be(1)
238
+ manifest.main['Manifest-Version'].should eql('1.0')
239
+ manifest.main['Created-By'].should eql('Buildr')
240
+ manifest.main['Foo'].should eql('1')
241
+ manifest.main['bar'].should eql('Bar')
242
+ end
243
+ end
244
+
245
+ it 'should not modify manifest of parent project' do
246
+ packaging = @packaging
247
+ define('foo', :version => '1.0') do
248
+ manifest['Foo'] = '1'
249
+ package(packaging)
250
+ define('bar', :version => '1.0') do
251
+ manifest['bar'] = 'Bar'
252
+ package(:jar)
253
+ end
254
+ define('baz', :version => '1.0') do
255
+ manifest['baz'] = 'Baz'
256
+ package(:jar)
257
+ end
258
+ end
259
+ inspect_manifest(project('foo').packages.first) do |manifest|
260
+ manifest.sections.size.should be(1)
261
+ manifest.main['Manifest-Version'].should eql('1.0')
262
+ manifest.main['Created-By'].should eql('Buildr')
263
+ manifest.main['Foo'].should eql('1')
264
+ manifest.main['bar'].should be_nil
265
+ manifest.main['baz'].should be_nil
266
+ end
267
+ inspect_manifest(project('foo:bar').packages.first) do |manifest|
268
+ manifest.sections.size.should be(1)
269
+ manifest.main['Manifest-Version'].should eql('1.0')
270
+ manifest.main['Created-By'].should eql('Buildr')
271
+ manifest.main['Foo'].should eql('1')
272
+ manifest.main['bar'].should eql('Bar')
273
+ manifest.main['baz'].should be_nil
274
+ end
275
+ inspect_manifest(project('foo:baz').packages.first) do |manifest|
276
+ manifest.sections.size.should be(1)
277
+ manifest.main['Manifest-Version'].should eql('1.0')
278
+ manifest.main['Created-By'].should eql('Buildr')
279
+ manifest.main['Foo'].should eql('1')
280
+ manifest.main['baz'].should eql('Baz')
281
+ manifest.main['bar'].should be_nil
282
+ end
283
+ end
284
+ end
285
+
286
+
287
+ describe Project, '#meta_inf' do
288
+ it 'should by an array' do
289
+ define('foo').meta_inf.should be_kind_of(Array)
290
+ end
291
+
292
+ it 'should include LICENSE file if found' do
293
+ write 'LICENSE'
294
+ define('foo').meta_inf.first.should point_to_path('LICENSE')
295
+ end
296
+
297
+ it 'should be empty unless LICENSE exists' do
298
+ define('foo').meta_inf.should be_empty
299
+ end
300
+
301
+ it 'should inherit from parent project' do
302
+ write 'LICENSE'
303
+ define('foo') { define 'bar' }
304
+ project('foo:bar').meta_inf.first.should point_to_path('LICENSE')
305
+ end
306
+
307
+ it 'should expect LICENSE file parent project' do
308
+ write 'bar/LICENSE'
309
+ define('foo') { define 'bar' }
310
+ project('foo:bar').meta_inf.should be_empty
311
+ end
312
+ end
313
+
314
+
315
+ describe 'package with meta_inf', :shared=>true do
316
+
317
+ def package_with_meta_inf(meta_inf = nil)
318
+ packaging = @packaging
319
+ @project = Buildr.define('foo', :version=>'1.2') do
320
+ package packaging
321
+ package(packaging).with(:meta_inf=>meta_inf) if meta_inf
322
+ end
323
+ end
324
+
325
+ def inspect_meta_inf
326
+ package = project('foo').package(@packaging)
327
+ package.invoke
328
+ assumed = Array(@meta_inf_ignore)
329
+ Zip::ZipFile.open(package.to_s) do |zip|
330
+ entries = zip.entries.map(&:to_s).select { |f| File.dirname(f) == 'META-INF' }.map { |f| File.basename(f) }
331
+ assumed.each { |f| entries.should include(f) }
332
+ yield entries - assumed if block_given?
333
+ end
334
+ end
335
+
336
+ it 'should default to LICENSE file' do
337
+ write 'LICENSE'
338
+ package_with_meta_inf
339
+ inspect_meta_inf { |files| files.should eql(['LICENSE']) }
340
+ end
341
+
342
+ it 'should be empty if no LICENSE file' do
343
+ package_with_meta_inf
344
+ inspect_meta_inf { |files| files.should be_empty }
345
+ end
346
+
347
+ it 'should include file specified by :meta_inf option' do
348
+ write 'README'
349
+ package_with_meta_inf 'README'
350
+ inspect_meta_inf { |files| files.should eql(['README']) }
351
+ end
352
+
353
+ it 'should include files specified by :meta_inf option' do
354
+ files = ['README', 'DISCLAIMER'].each { |file| write file }
355
+ package_with_meta_inf files
356
+ inspect_meta_inf { |files| files.should eql(files) }
357
+ end
358
+
359
+ it 'should include file task specified by :meta_inf option' do
360
+ file('README') { |task| write task.to_s }
361
+ package_with_meta_inf file('README')
362
+ inspect_meta_inf { |files| files.should eql(['README']) }
363
+ end
364
+
365
+ it 'should include file tasks specified by :meta_inf option' do
366
+ files = ['README', 'DISCLAIMER'].each { |file| file(file) { |task| write task.to_s } }
367
+ package_with_meta_inf files.map { |f| file(f) }
368
+ inspect_meta_inf { |files| files.should eql(files) }
369
+ end
370
+
371
+ it 'should complain if cannot find file' do
372
+ package_with_meta_inf 'README'
373
+ lambda { inspect_meta_inf }.should raise_error(RuntimeError, /README/)
374
+ end
375
+
376
+ it 'should complain if cannot build task' do
377
+ file('README') { fail 'Failed' }
378
+ package_with_meta_inf 'README'
379
+ lambda { inspect_meta_inf }.should raise_error(RuntimeError, /Failed/)
380
+ end
381
+
382
+ it 'should respond to with() and accept manifest and meta_inf' do
383
+ write 'DISCLAIMER'
384
+ mkpath 'target/classes'
385
+ packaging = @packaging
386
+ define('foo', :version=>'1.0') { package(packaging).with :meta_inf=>'DISCLAIMER' }
387
+ inspect_meta_inf { |files| files.should eql(['DISCLAIMER']) }
388
+ end
389
+ end
390
+
391
+
392
+ describe Packaging, 'jar' do
393
+ it_should_behave_like 'packaging'
394
+ before { @packaging = :jar }
395
+ it_should_behave_like 'package with manifest'
396
+ it_should_behave_like 'package with meta_inf'
397
+ before { @meta_inf_ignore = 'MANIFEST.MF' }
398
+
399
+ it 'should use files from compile directory if nothing included' do
400
+ write 'src/main/java/Test.java', 'class Test {}'
401
+ define('foo', :version=>'1.0') { package(:jar) }
402
+ project('foo').package(:jar).invoke
403
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
404
+ jar.entries.map(&:to_s).sort.should include('META-INF/MANIFEST.MF', 'Test.class')
405
+ end
406
+ end
407
+
408
+ it 'should use files from resources directory if nothing included' do
409
+ write 'src/main/resources/test/important.properties'
410
+ define('foo', :version=>'1.0') { package(:jar) }
411
+ project('foo').package(:jar).invoke
412
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
413
+ jar.entries.map(&:to_s).sort.should include('test/important.properties')
414
+ end
415
+ end
416
+
417
+ it 'should include class directories' do
418
+ write 'src/main/java/code/Test.java', 'package code ; class Test {}'
419
+ define('foo', :version=>'1.0') { package(:jar) }
420
+ project('foo').package(:jar).invoke
421
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
422
+ jar.entries.map(&:to_s).sort.should include('code/')
423
+ end
424
+ end
425
+
426
+ it 'should include resource files starting with dot' do
427
+ write 'src/main/resources/test/.config'
428
+ define('foo', :version=>'1.0') { package(:jar) }
429
+ project('foo').package(:jar).invoke
430
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
431
+ jar.entries.map(&:to_s).sort.should include('test/.config')
432
+ end
433
+ end
434
+
435
+ it 'should include empty resource directories' do
436
+ mkpath 'src/main/resources/empty'
437
+ define('foo', :version=>'1.0') { package(:jar) }
438
+ project('foo').package(:jar).invoke
439
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
440
+ jar.entries.map(&:to_s).sort.should include('empty/')
441
+ end
442
+ end
443
+ end
444
+
445
+
446
+ describe Packaging, 'war' do
447
+ it_should_behave_like 'packaging'
448
+ before { @packaging = :war }
449
+ it_should_behave_like 'package with manifest'
450
+ it_should_behave_like 'package with meta_inf'
451
+ before { @meta_inf_ignore = 'MANIFEST.MF' }
452
+
453
+ def make_jars
454
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
455
+ artifact('group:id:jar:2.0') { |t| write t.to_s }
456
+ end
457
+
458
+ def inspect_war
459
+ project('foo').package(:war).invoke
460
+ Zip::ZipFile.open(project('foo').package(:war).to_s) do |war|
461
+ yield war.entries.map(&:to_s).sort
462
+ end
463
+ end
464
+
465
+ it 'should use files from webapp directory if nothing included' do
466
+ write 'src/main/webapp/test.html'
467
+ define('foo', :version=>'1.0') { package(:war) }
468
+ inspect_war { |files| files.should include('test.html') }
469
+ end
470
+
471
+ it 'should accept files from :classes option' do
472
+ write 'src/main/java/Test.java', 'class Test {}'
473
+ write 'classes/test'
474
+ define('foo', :version=>'1.0') { package(:war).with(:classes=>'classes') }
475
+ inspect_war { |files| files.should include('WEB-INF/classes/test') }
476
+ end
477
+
478
+ it 'should use files from compile directory if nothing included' do
479
+ write 'src/main/java/Test.java', 'class Test {}'
480
+ define('foo', :version=>'1.0') { package(:war) }
481
+ inspect_war { |files| files.should include('WEB-INF/classes/Test.class') }
482
+ end
483
+
484
+ it 'should ignore compile directory if no source files to compile' do
485
+ define('foo', :version=>'1.0') { package(:war) }
486
+ inspect_war { |files| files.should_not include('target/classes') }
487
+ end
488
+
489
+ it 'should include only specified classes directories' do
490
+ write 'src/main/java'
491
+ define('foo', :version=>'1.0') { package(:war).with :classes=>_('additional') }
492
+ project('foo').package(:war).classes.should_not include(project('foo').file('target/classes'))
493
+ project('foo').package(:war).classes.should include(project('foo').file('additional'))
494
+ end
495
+
496
+ it 'should use files from resources directory if nothing included' do
497
+ write 'src/main/resources/test/important.properties'
498
+ define('foo', :version=>'1.0') { package(:war) }
499
+ inspect_war { |files| files.should include('WEB-INF/classes/test/important.properties') }
500
+ end
501
+
502
+ it 'should include empty resource directories' do
503
+ mkpath 'src/main/resources/empty'
504
+ define('foo', :version=>'1.0') { package(:war) }
505
+ inspect_war { |files| files.should include('WEB-INF/classes/empty/') }
506
+ end
507
+
508
+ it 'should accept file from :libs option' do
509
+ make_jars
510
+ define('foo', :version=>'1.0') { package(:war).with(:libs=>'group:id:jar:1.0') }
511
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
512
+ end
513
+
514
+ it 'should accept file from :libs option' do
515
+ make_jars
516
+ define('foo', :version=>'1.0') { package(:war).with(:libs=>['group:id:jar:1.0', 'group:id:jar:2.0']) }
517
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar', 'WEB-INF/lib/id-2.0.jar') }
518
+ end
519
+
520
+ it 'should use artifacts from compile classpath if no libs specified' do
521
+ make_jars
522
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war) }
523
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar', 'WEB-INF/lib/id-2.0.jar') }
524
+ end
525
+
526
+ it 'should include only specified libraries' do
527
+ define 'foo', :version=>'1.0' do
528
+ compile.with 'group:id:jar:1.0'
529
+ package(:war).with :libs=>'additional:id:jar:1.0'
530
+ end
531
+ project('foo').package(:war).libs.should_not include(artifact('group:id:jar:1.0'))
532
+ project('foo').package(:war).libs.should include(artifact('additional:id:jar:1.0'))
533
+ end
534
+
535
+ end
536
+
537
+
538
+ describe Packaging, 'aar' do
539
+ it_should_behave_like 'packaging'
540
+ before { @packaging = :aar }
541
+ it_should_behave_like 'package with manifest'
542
+ it_should_behave_like 'package with meta_inf'
543
+ before do
544
+ write 'src/main/axis2/services.xml'
545
+ @meta_inf_ignore = ['MANIFEST.MF', 'services.xml']
546
+ end
547
+
548
+ def make_jars
549
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
550
+ artifact('group:id:jar:2.0') { |t| write t.to_s }
551
+ end
552
+
553
+ def inspect_aar
554
+ project('foo').package(:aar).invoke
555
+ Zip::ZipFile.open(project('foo').package(:aar).to_s) do |aar|
556
+ yield aar.entries.map(&:to_s).sort
557
+ end
558
+ end
559
+
560
+ it 'should automatically include services.xml and any *.wsdl files under src/main/axis2' do
561
+ write 'src/main/axis2/my-service.wsdl'
562
+ define('foo', :version=>'1.0') { package(:aar) }
563
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'META-INF/services.xml', 'META-INF/my-service.wsdl') }
564
+ end
565
+
566
+ it 'should accept files from :include option' do
567
+ write 'test'
568
+ define('foo', :version=>'1.0') { package(:aar).include 'test' }
569
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'test') }
570
+ end
571
+
572
+ it 'should use files from compile directory if nothing included' do
573
+ write 'src/main/java/Test.java', 'class Test {}'
574
+ define('foo', :version=>'1.0') { package(:aar) }
575
+ inspect_aar { |files| files.should include('Test.class') }
576
+ end
577
+
578
+ it 'should use files from resources directory if nothing included' do
579
+ write 'src/main/resources/test/important.properties'
580
+ define('foo', :version=>'1.0') { package(:aar) }
581
+ inspect_aar { |files| files.should include('test/important.properties') }
582
+ end
583
+
584
+ it 'should include empty resource directories' do
585
+ mkpath 'src/main/resources/empty'
586
+ define('foo', :version=>'1.0') { package(:aar) }
587
+ inspect_aar { |files| files.should include('empty/') }
588
+ end
589
+
590
+ it 'should accept file from :libs option' do
591
+ make_jars
592
+ define('foo', :version=>'1.0') { package(:aar).with :libs=>'group:id:jar:1.0' }
593
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'lib/id-1.0.jar') }
594
+ end
595
+
596
+ it 'should accept file from :libs option' do
597
+ make_jars
598
+ define('foo', :version=>'1.0') { package(:aar).with :libs=>['group:id:jar:1.0', 'group:id:jar:2.0'] }
599
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'lib/id-1.0.jar', 'lib/id-2.0.jar') }
600
+ end
601
+
602
+ it 'should NOT use artifacts from compile classpath if no libs specified' do
603
+ make_jars
604
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:aar) }
605
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF') }
606
+ end
607
+
608
+ it 'should return all libraries from libs attribute' do
609
+ define 'foo', :version=>'1.0' do
610
+ compile.with 'group:id:jar:1.0'
611
+ package(:aar).with :libs=>'additional:id:jar:1.0'
612
+ end
613
+ project('foo').package(:aar).libs.should_not include(artifact('group:id:jar:1.0'))
614
+ project('foo').package(:aar).libs.should include(artifact('additional:id:jar:1.0'))
615
+ end
616
+
617
+ end
618
+
619
+
620
+ describe Packaging, 'ear' do
621
+ it_should_behave_like 'packaging'
622
+ before { @packaging = :ear }
623
+ it_should_behave_like 'package with manifest'
624
+ it_should_behave_like 'package with meta_inf'
625
+ before { @meta_inf_ignore = ['MANIFEST.MF', 'application.xml'] }
626
+
627
+ def inspect_ear
628
+ project('foo').package(:ear).invoke
629
+ Zip::ZipFile.open(project('foo').package(:ear).to_s) do |ear|
630
+ yield ear.entries.map(&:to_s).sort
631
+ end
632
+ end
633
+
634
+ def inspect_application_xml
635
+ project('foo').package(:ear).invoke
636
+ Zip::ZipFile.open(project('foo').package(:ear).to_s) do |ear|
637
+ yield REXML::Document.new(ear.read('META-INF/application.xml')).root
638
+ end
639
+ end
640
+
641
+ def inspect_classpath(package)
642
+ project('foo').package(:ear).invoke
643
+ Zip::ZipFile.open(project('foo').package(:ear).to_s) do |ear|
644
+ File.open('tmp.zip', 'wb') do |tmp|
645
+ tmp.write ear.file.read(package)
646
+ end
647
+ manifest = Buildr::Packaging::Java::Manifest.from_zip('tmp.zip')
648
+ yield manifest.main['Class-Path'].to_s.split(' ')
649
+ end
650
+ end
651
+
652
+ it 'should set display name from project id' do
653
+ define 'foo', :version=>'1.0' do
654
+ package(:ear).display_name.should eql('foo')
655
+ define 'bar' do
656
+ package(:ear).display_name.should eql('foo-bar')
657
+ end
658
+ end
659
+ end
660
+
661
+ it 'should set display name in application.xml' do
662
+ define 'foo', :version=>'1.0' do
663
+ package(:ear)
664
+ end
665
+ inspect_application_xml { |xml| xml.get_text('/application/display-name').should == 'foo' }
666
+ end
667
+
668
+ it 'should accept different display name' do
669
+ define 'foo', :version=>'1.0' do
670
+ package(:ear).display_name = 'bar'
671
+ end
672
+ inspect_application_xml { |xml| xml.get_text('/application/display-name').should == 'bar' }
673
+ end
674
+
675
+ it 'should map WARs to /war directory' do
676
+ define 'foo', :version=>'1.0' do
677
+ package(:ear) << package(:war)
678
+ end
679
+ inspect_ear { |files| files.should include('war/foo-1.0.war') }
680
+ end
681
+
682
+ it 'should map EJBs to /ejb directory' do
683
+ define 'foo', :version=>'1.0' do
684
+ package(:ear).add :ejb=>package(:jar)
685
+ end
686
+ inspect_ear { |files| files.should include('ejb/foo-1.0.jar') }
687
+ end
688
+
689
+ it 'should not modify original artifact for its components' do
690
+ define 'one', :version => '1.0' do
691
+ write 'src/main/resources/one.txt', '1'
692
+ package(:jar)
693
+ end
694
+
695
+ define 'two', :version => '1.0' do
696
+ write 'src/main/resources/two.txt', '2'
697
+ package(:jar)
698
+ end
699
+
700
+ define 'foo', :version => '1.0' do
701
+ package(:ear).add project(:one).package(:jar)
702
+ package(:ear).add :ejb => project(:two).package(:jar)
703
+ end
704
+
705
+ inspect_ear { |files| files.should include('lib/one-1.0.jar', 'ejb/two-1.0.jar') }
706
+
707
+ Buildr::Packaging::Java::Manifest.from_zip(project('one').package(:jar)).main['Class-Path'].should be_nil
708
+ Buildr::Packaging::Java::Manifest.from_zip(project('two').package(:jar)).main['Class-Path'].should be_nil
709
+
710
+ inspect_classpath 'ejb/two-1.0.jar' do |classpath|
711
+ classpath.should include('../lib/one-1.0.jar')
712
+ end
713
+ end
714
+
715
+ it 'should map JARs to /lib directory' do
716
+ define 'foo', :version=>'1.0' do
717
+ package(:ear) << package(:jar)
718
+ end
719
+ inspect_ear { |files| files.should include('lib/foo-1.0.jar') }
720
+ end
721
+
722
+ it 'should accept component type with :type option' do
723
+ define 'foo', :version=>'1.0' do
724
+ package(:ear).add package(:jar), :type=>:ejb
725
+ end
726
+ inspect_ear { |files| files.should include('ejb/foo-1.0.jar') }
727
+ end
728
+
729
+ it 'should accept component and its type as type=>artifact' do
730
+ define 'foo', :version=>'1.0' do
731
+ package(:ear).add :ejb=>package(:jar)
732
+ end
733
+ inspect_ear { |files| files.should include('ejb/foo-1.0.jar') }
734
+ end
735
+
736
+ it 'should map typed JARs to /jar directory' do
737
+ define 'foo', :version=>'1.0' do
738
+ package(:ear).add :jar=>package(:jar)
739
+ end
740
+ inspect_ear { |files| files.should include('jar/foo-1.0.jar') }
741
+ end
742
+
743
+ it 'should add multiple components at a time using the type=>component style' do
744
+ define 'bar', :version => '1.5' do
745
+ package(:war) # must be added as a webapp
746
+ package(:jar) # must be added as a shared lib
747
+ package(:zip) # this one should be excluded
748
+ end
749
+ define 'baz', :version => '1.5' do
750
+ package(:jar, :id => 'one')
751
+ package(:jar, :id => 'two')
752
+ end
753
+ define 'foo', :version => '1.0' do
754
+ package(:ear).add :lib => project('baz'),
755
+ :war => project('bar').package(:war),
756
+ :ejb => project('bar').package(:jar)
757
+ end
758
+ inspect_ear do |files|
759
+ files.should include(*%w{ lib/one-1.5.jar lib/two-1.5.jar war/bar-1.5.war ejb/bar-1.5.jar })
760
+ files.should_not satisfy { files.any? { |f| f =~ /\.zip$/ } }
761
+ end
762
+ end
763
+
764
+ it 'should add all EAR supported packages when given a project argument' do
765
+ define 'bar', :version => '1.5' do
766
+ package(:war) # must be added as a webapp
767
+ package(:jar) # must be added as a shared lib
768
+ package(:zip) # this one should be excluded
769
+ end
770
+ define 'baz', :version => '1.5' do
771
+ package(:war)
772
+ package(:jar)
773
+ end
774
+ define 'foo', :version => '1.0' do
775
+ package(:ear).add projects(:bar, :baz)
776
+ end
777
+ inspect_ear do |files|
778
+ files.should include('war/bar-1.5.war', 'lib/bar-1.5.jar', 'lib/baz-1.5.jar', 'war/baz-1.5.war')
779
+ files.should_not satisfy { files.any? { |f| f =~ /\.zip$/ } }
780
+ end
781
+ end
782
+
783
+ it 'should complain about unknown component type' do
784
+ define 'foo', :version=>'1.0' do
785
+ lambda { package(:ear).add package(:zip) }.should raise_error(RuntimeError, /ear component/i)
786
+ end
787
+ end
788
+
789
+ it 'should allow unknown component types with explicit type' do
790
+ define 'foo', :version=>'1.0' do
791
+ package(:ear).add :lib=>package(:zip)
792
+ end
793
+ inspect_ear { |files| files.should include('lib/foo-1.0.zip') }
794
+ end
795
+
796
+ it 'should accept alternative directory name' do
797
+ define 'foo', :version=>'1.0' do
798
+ package(:ear).add package(:jar), :path=>'trash'
799
+ end
800
+ inspect_ear { |files| files.should include('trash/foo-1.0.jar') }
801
+ end
802
+
803
+ it 'should accept customization of directory map' do
804
+ define 'foo', :version=>'1.0' do
805
+ package(:ear).dirs[:jar] = 'jarred'
806
+ package(:ear).add :jar=>package(:jar)
807
+ end
808
+ inspect_ear { |files| files.should include('jarred/foo-1.0.jar') }
809
+ end
810
+
811
+ it 'should accept customization of directory map with nil paths in application.xml' do
812
+ define 'foo', :version=>'1.0' do
813
+ package(:ear).dirs[:war] = nil
814
+ package(:ear).add :war=>package(:war)
815
+ package(:ear).add package(:jar)
816
+ end
817
+ inspect_ear { |files| files.should include('foo-1.0.war') }
818
+ inspect_application_xml do |xml|
819
+ xml.get_text("/application/module[@id='foo']/web/web-uri").to_s.should eql('foo-1.0.war')
820
+ end
821
+ end
822
+
823
+ it 'should accept customization of directory map with nil paths in the classpath' do
824
+ define 'foo', :version=>'1.0' do
825
+ package(:ear).dirs[:lib] = nil
826
+ package(:ear).add :war=>package(:war)
827
+ package(:ear) << package(:jar)
828
+ end
829
+ inspect_classpath 'war/foo-1.0.war' do |classpath|
830
+ classpath.should include('../foo-1.0.jar')
831
+ end
832
+ end
833
+
834
+ it 'should list WAR components in application.xml' do
835
+ define 'foo', :version=>'1.0' do
836
+ package(:ear) << package(:war) << package(:war, :id=>'bar')
837
+ end
838
+ inspect_application_xml do |xml|
839
+ xml.get_elements("/application/module[@id='foo'][web]").should_not be_empty
840
+ xml.get_elements("/application/module[@id='bar'][web]").should_not be_empty
841
+ end
842
+ end
843
+
844
+ it 'should specify web-uri for WAR components in application.xml' do
845
+ define 'foo', :version=>'1.0' do
846
+ package(:ear) << package(:war)
847
+ package(:ear).add package(:war, :id=>'bar'), :path=>'ws'
848
+ end
849
+ inspect_application_xml do |xml|
850
+ xml.get_text("/application/module[@id='foo']/web/web-uri").to_s.should eql('war/foo-1.0.war')
851
+ xml.get_text("/application/module[@id='bar']/web/web-uri").to_s.should eql('ws/bar-1.0.war')
852
+ end
853
+ end
854
+
855
+ it 'should specify context-root for WAR components in application.xml' do
856
+ define 'foo', :version=>'1.0' do
857
+ package(:ear) << package(:war)
858
+ package(:ear).add package(:war, :id=>'bar')
859
+ end
860
+ inspect_application_xml do |xml|
861
+ xml.get_text("/application/module[@id='foo']/web/context-root").to_s.should eql('/foo')
862
+ xml.get_text("/application/module[@id='bar']/web/context-root").to_s.should eql('/bar')
863
+ end
864
+ end
865
+
866
+ it 'should accept context-root for WAR components in application.xml' do
867
+ define 'foo', :version=>'1.0' do
868
+ package(:ear).add package(:war), :context_root=>'rooted'
869
+ end
870
+ inspect_application_xml do |xml|
871
+ xml.get_text("/application/module[@id='foo']/web/context-root").to_s.should eql('/rooted')
872
+ end
873
+ end
874
+
875
+ it 'should allow disabling the context root' do
876
+ define 'foo', :version=>'1.0' do
877
+ package(:ear).add package(:war), :context_root=>false
878
+ end
879
+ inspect_application_xml do |xml|
880
+ xml.get_elements("/application/module[@id='foo']/web/context-root").should be_empty
881
+ end
882
+ end
883
+
884
+ it 'should list EJB components in application.xml' do
885
+ define 'foo', :version=>'1.0' do
886
+ package(:ear).add :ejb=>package(:jar)
887
+ package(:ear).add :ejb=>package(:jar, :id=>'bar')
888
+ end
889
+ inspect_application_xml do |xml|
890
+ xml.get_text("/application/module[@id='foo']/ejb").to_s.should eql('ejb/foo-1.0.jar')
891
+ xml.get_text("/application/module[@id='bar']/ejb").to_s.should eql('ejb/bar-1.0.jar')
892
+ end
893
+ end
894
+
895
+ it 'should list JAR components in application.xml' do
896
+ define 'foo', :version=>'1.0' do
897
+ package(:ear) << { :jar=>package(:jar) } << { :jar=>package(:jar, :id=>'bar') }
898
+ end
899
+ inspect_application_xml do |xml|
900
+ jars = xml.get_elements('/application/jar').map(&:texts).map(&:to_s)
901
+ jars.should include('jar/foo-1.0.jar', 'jar/bar-1.0.jar')
902
+ end
903
+ end
904
+
905
+ it 'should update WAR component classpath to include libraries' do
906
+ define 'foo', :version=>'1.0' do
907
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
908
+ package(:ear).add package(:war)
909
+ end
910
+ inspect_classpath 'war/foo-1.0.war' do |classpath|
911
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
912
+ end
913
+ end
914
+
915
+ it 'should update WAR component classpath but skip internal libraries' do
916
+ define 'foo', :version=>'1.0' do
917
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
918
+ package(:war).with(:libs=>package(:jar, :id=>'lib1'))
919
+ package(:ear).add package(:war)
920
+ end
921
+ inspect_classpath 'war/foo-1.0.war' do |classpath|
922
+ classpath.should_not include('../lib/lib1-1.0.jar')
923
+ classpath.should include('../lib/lib2-1.0.jar')
924
+ end
925
+ end
926
+
927
+ it 'should update EJB component classpath to include libraries' do
928
+ define 'foo', :version=>'1.0' do
929
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
930
+ package(:ear).add :ejb=>package(:jar)
931
+ end
932
+ inspect_classpath 'ejb/foo-1.0.jar' do |classpath|
933
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
934
+ end
935
+ end
936
+
937
+ it 'should update JAR component classpath to include libraries' do
938
+ define 'foo', :version=>'1.0' do
939
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
940
+ package(:ear).add :jar=>package(:jar)
941
+ end
942
+ inspect_classpath 'jar/foo-1.0.jar' do |classpath|
943
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
944
+ end
945
+ end
946
+
947
+ it 'should deal with very long classpaths' do
948
+ define 'foo', :version=>'1.0' do
949
+ 20.times { |i| package(:ear) << package(:jar, :id=>"lib#{i}") }
950
+ package(:ear).add :jar=>package(:jar)
951
+ end
952
+ inspect_classpath 'jar/foo-1.0.jar' do |classpath|
953
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
954
+ end
955
+ end
956
+
957
+
958
+ it 'should generate relative classpaths for top level EJB' do
959
+ define 'foo', :version => '1.0' do
960
+ package(:ear).add package(:jar, :id => 'one'), :path => '.'
961
+ package(:ear).add package(:jar, :id => 'two'), :path => 'dos'
962
+ package(:ear).add package(:jar, :id => 'three'), :path => 'tres'
963
+ package(:ear).add :ejb => package(:jar, :id => 'ejb1'), :path => '.'
964
+ end
965
+ inspect_classpath 'ejb1-1.0.jar' do |classpath|
966
+ classpath.should include(*%w{ one-1.0.jar dos/two-1.0.jar tres/three-1.0.jar })
967
+ end
968
+ end
969
+
970
+ it 'should generate relative classpaths for second level EJB' do
971
+ define 'foo', :version => '1.0' do
972
+ package(:ear).add package(:jar, :id => 'one'), :path => '.'
973
+ package(:ear).add package(:jar, :id => 'two'), :path => 'dos'
974
+ package(:ear).add package(:jar, :id => 'three'), :path => 'tres'
975
+ package(:ear).add :ejb => package(:jar, :id => 'ejb2'), :path => 'dos'
976
+ end
977
+ inspect_classpath 'dos/ejb2-1.0.jar' do |classpath|
978
+ classpath.should include(*%w{ ../one-1.0.jar two-1.0.jar ../tres/three-1.0.jar })
979
+ end
980
+ end
981
+
982
+ it 'should generate relative classpaths for nested EJB' do
983
+ define 'foo', :version => '1.0' do
984
+ package(:ear).add package(:jar, :id => 'one'), :path => '.'
985
+ package(:ear).add package(:jar, :id => 'two'), :path => 'dos'
986
+ package(:ear).add package(:jar, :id => 'three'), :path => 'dos/tres'
987
+ package(:ear).add package(:jar, :id => 'four'), :path => 'dos/cuatro'
988
+ package(:ear).add :ejb => package(:jar, :id => 'ejb4'), :path => 'dos/cuatro'
989
+ end
990
+ inspect_classpath 'dos/cuatro/ejb4-1.0.jar' do |classpath|
991
+ classpath.should include(*%w{ ../../one-1.0.jar ../two-1.0.jar ../tres/three-1.0.jar four-1.0.jar })
992
+ end
993
+ end
994
+
995
+ end
996
+
997
+
998
+ describe Packaging, 'sources' do
999
+ it_should_behave_like 'packaging'
1000
+ before { @packaging, @package_type = :sources, :zip }
1001
+
1002
+ it 'should create package of type :zip and classifier \'sources\'' do
1003
+ define 'foo', :version=>'1.0' do
1004
+ package(:sources).type.should eql(:zip)
1005
+ package(:sources).classifier.should eql('sources')
1006
+ package(:sources).name.should match(/foo-1.0-sources.zip$/)
1007
+ end
1008
+ end
1009
+
1010
+ it 'should contain source files' do
1011
+ write 'src/main/java/Source.java'
1012
+ define('foo', :version=>'1.0') { package(:sources) }
1013
+ project('foo').task('package').invoke
1014
+ project('foo').packages.first.should contain('Source.java')
1015
+ end
1016
+
1017
+ it 'should be a ZipTask' do
1018
+ define 'foo', :version=>'1.0' do
1019
+ package(:javadoc).should be_kind_of(ZipTask)
1020
+ end
1021
+ end
1022
+ end
1023
+
1024
+
1025
+ describe Packaging, 'javadoc' do
1026
+ it_should_behave_like 'packaging'
1027
+ before { @packaging, @package_type = :javadoc, :zip }
1028
+
1029
+ it 'should create package of type :zip and classifier \'javadoc\'' do
1030
+ define 'foo', :version=>'1.0' do
1031
+ package(:javadoc).type.should eql(:zip)
1032
+ package(:javadoc).classifier.should eql('javadoc')
1033
+ package(:javadoc).name.pathmap('%f').should eql('foo-1.0-javadoc.zip')
1034
+ end
1035
+ end
1036
+
1037
+ it 'should contain Javadocs' do
1038
+ write 'src/main/java/Source.java', 'public class Source {}'
1039
+ define('foo', :version=>'1.0') { package(:javadoc) }
1040
+ project('foo').task('package').invoke
1041
+ project('foo').packages.first.should contain('Source.html', 'index.html')
1042
+ end
1043
+
1044
+ it 'should use project description in window title' do
1045
+ write 'src/main/java/Source.java', 'public class Source {}'
1046
+ desc 'My Project'
1047
+ define('foo', :version=>'1.0') { package(:javadoc) }
1048
+ project('foo').task('package').invoke
1049
+ project('foo').packages.first.entry('index.html').should contain('My Project')
1050
+ end
1051
+
1052
+ it 'should be a ZipTask' do
1053
+ define 'foo', :version=>'1.0' do
1054
+ package(:javadoc).should be_kind_of(ZipTask)
1055
+ end
1056
+ end
1057
+ end
1058
+
1059
+
1060
+ shared_examples_for 'package_with_' do
1061
+
1062
+ def prepare(options = {})
1063
+ packager = "package_with_#{@packaging}"
1064
+ write 'src/main/java/Source.java'
1065
+ write 'baz/src/main/java/Source.java'
1066
+ define 'foo', :version=>'1.0' do
1067
+ send packager, options
1068
+ define 'bar' ; define 'baz'
1069
+ end
1070
+ end
1071
+
1072
+ def applied_to
1073
+ projects.select { |project| project.packages.first }.map(&:name)
1074
+ end
1075
+
1076
+ it 'should create package of type zip with classifier' do
1077
+ prepare
1078
+ project('foo').packages.first.to_s.should =~ /foo-1.0-#{@packaging}.zip/
1079
+ end
1080
+
1081
+ it 'should create package for projects that have source files' do
1082
+ prepare
1083
+ applied_to.should include('foo', 'foo:baz')
1084
+ end
1085
+
1086
+ it 'should not create package for projects that have no source files' do
1087
+ prepare
1088
+ applied_to.should_not include('foo:bar')
1089
+ end
1090
+
1091
+ it 'should limit to projects specified by :only' do
1092
+ prepare :only=>'baz'
1093
+ applied_to.should eql(['foo:baz'])
1094
+ end
1095
+
1096
+ it 'should limit to projects specified by :only array' do
1097
+ prepare :only=>['baz']
1098
+ applied_to.should eql(['foo:baz'])
1099
+ end
1100
+
1101
+ it 'should ignore project specified by :except' do
1102
+ prepare :except=>'baz'
1103
+ applied_to.should eql(['foo'])
1104
+ end
1105
+
1106
+ it 'should ignore projects specified by :except array' do
1107
+ prepare :except=>['baz']
1108
+ applied_to.should eql(['foo'])
1109
+ end
1110
+ end
1111
+
1112
+ describe 'package_with_sources' do
1113
+ it_should_behave_like 'package_with_'
1114
+ before { @packaging = :sources }
1115
+ end
1116
+
1117
+ describe 'package_with_javadoc' do
1118
+ it_should_behave_like 'package_with_'
1119
+ before { @packaging = :javadoc }
1120
+ end