realityforge-buildr 1.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.md +3 -0
  6. data/Rakefile +50 -0
  7. data/addon/buildr/checkstyle-report.xsl +104 -0
  8. data/addon/buildr/checkstyle.rb +254 -0
  9. data/addon/buildr/git_auto_version.rb +36 -0
  10. data/addon/buildr/gpg.rb +90 -0
  11. data/addon/buildr/gwt.rb +413 -0
  12. data/addon/buildr/jacoco.rb +161 -0
  13. data/addon/buildr/pmd.rb +185 -0
  14. data/addon/buildr/single_intermediate_layout.rb +71 -0
  15. data/addon/buildr/spotbugs.rb +265 -0
  16. data/addon/buildr/top_level_generate_dir.rb +37 -0
  17. data/addon/buildr/wsgen.rb +192 -0
  18. data/bin/buildr +20 -0
  19. data/buildr.gemspec +61 -0
  20. data/lib/buildr.rb +86 -0
  21. data/lib/buildr/core/application.rb +705 -0
  22. data/lib/buildr/core/assets.rb +96 -0
  23. data/lib/buildr/core/build.rb +587 -0
  24. data/lib/buildr/core/common.rb +167 -0
  25. data/lib/buildr/core/compile.rb +599 -0
  26. data/lib/buildr/core/console.rb +124 -0
  27. data/lib/buildr/core/doc.rb +275 -0
  28. data/lib/buildr/core/environment.rb +128 -0
  29. data/lib/buildr/core/filter.rb +405 -0
  30. data/lib/buildr/core/help.rb +114 -0
  31. data/lib/buildr/core/progressbar.rb +161 -0
  32. data/lib/buildr/core/project.rb +994 -0
  33. data/lib/buildr/core/test.rb +776 -0
  34. data/lib/buildr/core/transports.rb +456 -0
  35. data/lib/buildr/core/util.rb +77 -0
  36. data/lib/buildr/ide/idea.rb +1664 -0
  37. data/lib/buildr/java/commands.rb +230 -0
  38. data/lib/buildr/java/compiler.rb +85 -0
  39. data/lib/buildr/java/custom_pom.rb +300 -0
  40. data/lib/buildr/java/doc.rb +62 -0
  41. data/lib/buildr/java/packaging.rb +393 -0
  42. data/lib/buildr/java/pom.rb +191 -0
  43. data/lib/buildr/java/test_result.rb +54 -0
  44. data/lib/buildr/java/tests.rb +111 -0
  45. data/lib/buildr/packaging/archive.rb +586 -0
  46. data/lib/buildr/packaging/artifact.rb +1113 -0
  47. data/lib/buildr/packaging/artifact_namespace.rb +1010 -0
  48. data/lib/buildr/packaging/artifact_search.rb +138 -0
  49. data/lib/buildr/packaging/package.rb +237 -0
  50. data/lib/buildr/packaging/version_requirement.rb +189 -0
  51. data/lib/buildr/packaging/zip.rb +189 -0
  52. data/lib/buildr/packaging/ziptask.rb +387 -0
  53. data/lib/buildr/version.rb +18 -0
  54. data/rakelib/release.rake +99 -0
  55. data/spec/addon/checkstyle_spec.rb +58 -0
  56. data/spec/core/application_spec.rb +576 -0
  57. data/spec/core/build_spec.rb +922 -0
  58. data/spec/core/common_spec.rb +670 -0
  59. data/spec/core/compile_spec.rb +656 -0
  60. data/spec/core/console_spec.rb +65 -0
  61. data/spec/core/doc_spec.rb +194 -0
  62. data/spec/core/extension_spec.rb +200 -0
  63. data/spec/core/project_spec.rb +736 -0
  64. data/spec/core/test_spec.rb +1131 -0
  65. data/spec/core/transport_spec.rb +452 -0
  66. data/spec/core/util_spec.rb +154 -0
  67. data/spec/ide/idea_spec.rb +1952 -0
  68. data/spec/java/commands_spec.rb +79 -0
  69. data/spec/java/compiler_spec.rb +274 -0
  70. data/spec/java/custom_pom_spec.rb +165 -0
  71. data/spec/java/doc_spec.rb +55 -0
  72. data/spec/java/packaging_spec.rb +786 -0
  73. data/spec/java/pom_spec.rb +162 -0
  74. data/spec/java/test_coverage_helper.rb +257 -0
  75. data/spec/java/tests_spec.rb +224 -0
  76. data/spec/packaging/archive_spec.rb +686 -0
  77. data/spec/packaging/artifact_namespace_spec.rb +757 -0
  78. data/spec/packaging/artifact_spec.rb +1351 -0
  79. data/spec/packaging/packaging_helper.rb +63 -0
  80. data/spec/packaging/packaging_spec.rb +690 -0
  81. data/spec/sandbox.rb +166 -0
  82. data/spec/spec_helpers.rb +420 -0
  83. data/spec/version_requirement_spec.rb +145 -0
  84. data/spec/xpath_matchers.rb +123 -0
  85. metadata +295 -0
@@ -0,0 +1,55 @@
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
+ describe 'Javadoc' do
20
+ def sources
21
+ @sources ||= (1..3).map { |i| "Test#{i}" }.
22
+ each { |name| write "src/main/java/foo/#{name}.java", "package foo; public class #{name}{}" }.
23
+ map { |name| "src/main/java/foo/#{name}.java" }
24
+ end
25
+
26
+ it 'should pick -windowtitle from project name by default' do
27
+ define 'foo' do
28
+ compile.using(:javac)
29
+
30
+ define 'bar' do
31
+ compile.using(:javac)
32
+ end
33
+ end
34
+
35
+ project('foo').doc.options[:windowtitle].should eql('foo')
36
+ project('foo:bar').doc.options[:windowtitle].should eql('foo:bar')
37
+ end
38
+
39
+ it 'should pick -windowtitle from project description by default, if available' do
40
+ desc 'My App'
41
+ define 'foo' do
42
+ compile.using(:javac)
43
+ end
44
+ project('foo').doc.options[:windowtitle].should eql('My App')
45
+ end
46
+
47
+ it 'should not override explicit :windowtitle' do
48
+ define 'foo' do
49
+ compile.using(:javac)
50
+ doc.using :windowtitle => 'explicit'
51
+ end
52
+ project('foo').doc.options[:windowtitle].should eql('explicit')
53
+ end
54
+
55
+ end
@@ -0,0 +1,786 @@
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
+ require File.expand_path(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 project comment' do
28
+ desc 'My Project'
29
+ define('foo').manifest['Implementation-Title'].should eql('My Project')
30
+ end
31
+
32
+ it 'should include project name if no comment' do
33
+ define('foo').manifest['Implementation-Title'].should eql('foo')
34
+ end
35
+
36
+ it 'should include project version' do
37
+ define('foo', :version=>'2.1').manifest['Implementation-Version'].should eql('2.1')
38
+ end
39
+
40
+ it 'should not include project version unless specified' do
41
+ define('foo').manifest['Implementation-Version'].should be_nil
42
+ end
43
+
44
+ it 'should inherit from parent project' do
45
+ define('foo', :version=>'2.1') { define 'bar' }
46
+ project('foo:bar').manifest['Implementation-Version'].should eql('2.1')
47
+ end
48
+
49
+ end
50
+
51
+
52
+ RSpec.shared_examples 'package with manifest' do
53
+ before do
54
+ @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).'
55
+ end
56
+
57
+ def package_with_manifest(manifest = nil)
58
+ packaging = @packaging
59
+ @project = define('foo', :version=>'1.2') do
60
+ package packaging
61
+ package(packaging).with(:manifest=>manifest) unless manifest.nil?
62
+ end
63
+ end
64
+
65
+ def inspect_manifest(package = nil)
66
+ package ||= project('foo').package(@packaging)
67
+ package.invoke
68
+ yield Buildr::Packaging::Java::Manifest.from_zip(package)
69
+ end
70
+
71
+ it 'should include default header when no options specified' do
72
+ ENV['USER'] = 'MysteriousJoe'
73
+ package_with_manifest # Nothing for default.
74
+ inspect_manifest do |manifest|
75
+ manifest.sections.size.should be(1)
76
+ manifest.main.should == {
77
+ 'Manifest-Version' =>'1.0',
78
+ 'Created-By' =>'Buildr',
79
+ 'Implementation-Title' =>@project.name,
80
+ 'Implementation-Version' =>'1.2',
81
+ 'Build-By' =>'MysteriousJoe'
82
+ }
83
+ end
84
+ end
85
+
86
+ it 'should not exist when manifest=false' do
87
+ package_with_manifest false
88
+ @project.package(@packaging).invoke
89
+ Zip::File.open(@project.package(@packaging).to_s) do |zip|
90
+ zip.exist?('META-INF/MANIFEST.MF').should be_false
91
+ end
92
+ end
93
+
94
+ it 'should generate a new manifest for a file that does not have one' do
95
+ Zip::OutputStream.open 'tmp.zip' do |zip|
96
+ zip.put_next_entry 'empty.txt'
97
+ end
98
+ begin
99
+ manifest = Buildr::Packaging::Java::Manifest.from_zip('tmp.zip')
100
+ manifest.each do |key, val|
101
+ Buildr::Packaging::Java::Manifest::STANDARD_HEADER.should include(key)
102
+ end
103
+ ensure
104
+ rm 'tmp.zip'
105
+ end
106
+ end
107
+
108
+ it 'should map manifest from hash' do
109
+ package_with_manifest 'Foo'=>1, :bar=>'Bar'
110
+ inspect_manifest do |manifest|
111
+ manifest.sections.size.should be(1)
112
+ manifest.main['Manifest-Version'].should eql('1.0')
113
+ manifest.main['Created-By'].should eql('Buildr')
114
+ manifest.main['Foo'].should eql('1')
115
+ manifest.main['bar'].should eql('Bar')
116
+ end
117
+ end
118
+
119
+ it 'should close the temporary file used for packaging the MANIFEST.MF file' do
120
+ package_with_manifest 'Foo'=>1, :bar=>'Bar'
121
+ package = project('foo').package(@packaging)
122
+ package.invoke
123
+ module AccessManifestTMP
124
+ attr_reader :manifest_tmp
125
+ end
126
+ (package.dup.extend(AccessManifestTMP).manifest_tmp.closed?).should be_true
127
+ end
128
+
129
+ it 'should end hash manifest with EOL' do
130
+ package_with_manifest 'Foo'=>1, :bar=>'Bar'
131
+ package = project('foo').package(@packaging)
132
+ package.invoke
133
+ Zip::File.open(package.to_s) { |zip| zip.read('META-INF/MANIFEST.MF').should =~ /#{Buildr::Packaging::Java::Manifest::LINE_SEPARATOR}$/ }
134
+ end
135
+
136
+ it 'should break hash manifest lines longer than 72 characters using continuations' do
137
+ package_with_manifest 'foo'=>@long_line
138
+ package = project('foo').package(@packaging)
139
+ inspect_manifest do |manifest|
140
+ manifest.main['foo'].should == @long_line
141
+ end
142
+ end
143
+
144
+ it 'should map manifest from array' do
145
+ package_with_manifest [ { :foo=>'first' }, { :bar=>'second' } ]
146
+ inspect_manifest do |manifest|
147
+ manifest.sections.size.should be(2)
148
+ manifest.main['Manifest-Version'].should eql('1.0')
149
+ manifest.main['foo'].should eql('first')
150
+ manifest.sections.last['bar'].should eql('second')
151
+ end
152
+ end
153
+
154
+ it 'should end array manifest with EOL' do
155
+ package_with_manifest [ { :foo=>'first' }, { :bar=>'second' } ]
156
+ package = project('foo').package(@packaging)
157
+ package.invoke
158
+ Zip::File.open(package.to_s) { |zip| zip.read('META-INF/MANIFEST.MF')[-1].should == ?\n }
159
+ end
160
+
161
+ it 'should break array manifest lines longer than 72 characters using continuations' do
162
+ package_with_manifest ['foo'=>@long_line]
163
+ package = project('foo').package(@packaging)
164
+ inspect_manifest do |manifest|
165
+ manifest.main['foo'].should == @long_line
166
+ end
167
+ end
168
+
169
+ it 'should put Name: at beginning of section' do
170
+ package_with_manifest [ {}, { 'Name'=>'first', :Foo=>'first', :bar=>'second' } ]
171
+ package = project('foo').package(@packaging)
172
+ package.invoke
173
+ inspect_manifest do |manifest|
174
+ manifest.sections[1]["Name"].should == "first"
175
+ end
176
+ end
177
+
178
+ it 'should create manifest from proc' do
179
+ package_with_manifest lambda { 'Meta: data' }
180
+ inspect_manifest do |manifest|
181
+ manifest.sections.size.should be(1)
182
+ manifest.main['Manifest-Version'].should eql('1.0')
183
+ manifest.main['Meta'].should eql('data')
184
+ end
185
+ end
186
+
187
+ it 'should create manifest from file' do
188
+ write 'MANIFEST.MF', 'Meta: data'
189
+ package_with_manifest 'MANIFEST.MF'
190
+ inspect_manifest do |manifest|
191
+ manifest.sections.size.should be(1)
192
+ manifest.main['Meta'].should eql('data')
193
+ end
194
+ end
195
+
196
+ it 'should give 644 permissions to the manifest' do
197
+ package_with_manifest [ {}, { 'Name'=>'first', :Foo=>'first', :bar=>'second' } ]
198
+ package ||= project('foo').package(@packaging)
199
+ package.invoke
200
+ Zip::File.open(package.to_s) do |zip|
201
+ permissions = format("%o", zip.find_entry('META-INF/MANIFEST.MF').unix_perms)
202
+ permissions.should match /644$/
203
+ end
204
+ end
205
+
206
+ it 'should not add manifest version twice' do
207
+ write 'MANIFEST.MF', 'Manifest-Version: 1.9'
208
+ package_with_manifest 'MANIFEST.MF'
209
+ package ||= project('foo').package(@packaging)
210
+ package.invoke
211
+ Zip::File.open(package.to_s) do |zip|
212
+ zip.read('META-INF/MANIFEST.MF').scan(/(Manifest-Version)/m).size.should == 1
213
+ end
214
+ end
215
+
216
+ it 'should give precedence to version specified in manifest file' do
217
+ write 'MANIFEST.MF', 'Manifest-Version: 1.9'
218
+ package_with_manifest 'MANIFEST.MF'
219
+ inspect_manifest do |manifest|
220
+ manifest.main['Manifest-Version'].should == '1.9'
221
+ end
222
+ end
223
+
224
+ it 'should create manifest from task' do
225
+ file 'MANIFEST.MF' do |task|
226
+ write task.to_s, 'Meta: data'
227
+ end
228
+ package_with_manifest 'MANIFEST.MF'
229
+ inspect_manifest do |manifest|
230
+ manifest.sections.size.should be(1)
231
+ manifest.main['Manifest-Version'].should eql('1.0')
232
+ manifest.main['Meta'].should eql('data')
233
+ end
234
+ end
235
+
236
+ it 'should respond to with() and accept manifest' do
237
+ write 'DISCLAIMER'
238
+ mkpath 'target/classes'
239
+ packaging = @packaging
240
+ define('foo', :version=>'1.0') { package(packaging).with :manifest=>{'Foo'=>'data'} }
241
+ inspect_manifest { |manifest| manifest.main['Foo'].should eql('data') }
242
+ end
243
+
244
+ it 'should include META-INF directory' do
245
+ packaging = @packaging
246
+ package = define('foo', :version=>'1.0') { package(packaging) }.packages.first
247
+ package.invoke
248
+ Zip::File.open(package.to_s) do |zip|
249
+ zip.entries.map(&:to_s).should include('META-INF/')
250
+ end
251
+ end
252
+
253
+ it 'should inherit manifest from parent project' do
254
+ packaging = @packaging
255
+ package = nil
256
+ define('foo', :version => '1.0') do
257
+ manifest['Foo'] = '1'
258
+ package(packaging)
259
+ define('bar', :version => '1.0') do
260
+ manifest['bar'] = 'Bar'
261
+ package(:jar)
262
+ package = packages.first
263
+ end
264
+ end
265
+ inspect_manifest(package) do |manifest|
266
+ manifest.sections.size.should be(1)
267
+ manifest.main['Manifest-Version'].should eql('1.0')
268
+ manifest.main['Created-By'].should eql('Buildr')
269
+ manifest.main['Foo'].should eql('1')
270
+ manifest.main['bar'].should eql('Bar')
271
+ end
272
+ end
273
+
274
+ it 'should not modify manifest of parent project' do
275
+ packaging = @packaging
276
+ define('foo', :version => '1.0') do
277
+ manifest['Foo'] = '1'
278
+ package(packaging)
279
+ define('bar', :version => '1.0') do
280
+ manifest['bar'] = 'Bar'
281
+ package(:jar)
282
+ end
283
+ define('baz', :version => '1.0') do
284
+ manifest['baz'] = 'Baz'
285
+ package(:jar)
286
+ end
287
+ end
288
+ inspect_manifest(project('foo').packages.first) do |manifest|
289
+ manifest.sections.size.should be(1)
290
+ manifest.main['Manifest-Version'].should eql('1.0')
291
+ manifest.main['Created-By'].should eql('Buildr')
292
+ manifest.main['Foo'].should eql('1')
293
+ manifest.main['bar'].should be_nil
294
+ manifest.main['baz'].should be_nil
295
+ end
296
+ inspect_manifest(project('foo:bar').packages.first) do |manifest|
297
+ manifest.sections.size.should be(1)
298
+ manifest.main['Manifest-Version'].should eql('1.0')
299
+ manifest.main['Created-By'].should eql('Buildr')
300
+ manifest.main['Foo'].should eql('1')
301
+ manifest.main['bar'].should eql('Bar')
302
+ manifest.main['baz'].should be_nil
303
+ end
304
+ inspect_manifest(project('foo:baz').packages.first) do |manifest|
305
+ manifest.sections.size.should be(1)
306
+ manifest.main['Manifest-Version'].should eql('1.0')
307
+ manifest.main['Created-By'].should eql('Buildr')
308
+ manifest.main['Foo'].should eql('1')
309
+ manifest.main['baz'].should eql('Baz')
310
+ manifest.main['bar'].should be_nil
311
+ end
312
+ end
313
+ end
314
+
315
+
316
+ describe Project, '#meta_inf' do
317
+ it 'should by an array' do
318
+ define('foo').meta_inf.should be_kind_of(Array)
319
+ end
320
+
321
+ it 'should include LICENSE file if found' do
322
+ write 'LICENSE'
323
+ define('foo').meta_inf.first.should point_to_path('LICENSE')
324
+ end
325
+
326
+ it 'should be empty unless LICENSE exists' do
327
+ define('foo').meta_inf.should be_empty
328
+ end
329
+
330
+ it 'should inherit from parent project' do
331
+ write 'LICENSE'
332
+ define('foo') { define 'bar' }
333
+ project('foo:bar').meta_inf.first.should point_to_path('LICENSE')
334
+ end
335
+
336
+ it 'should expect LICENSE file parent project' do
337
+ write 'bar/LICENSE'
338
+ define('foo') { define 'bar' }
339
+ project('foo:bar').meta_inf.should be_empty
340
+ end
341
+ end
342
+
343
+
344
+ RSpec.shared_examples 'package with meta_inf' do
345
+
346
+ def package_with_meta_inf(meta_inf = nil)
347
+ packaging = @packaging
348
+ @project = Buildr.define('foo', :version=>'1.2') do
349
+ package packaging
350
+ package(packaging).with(:meta_inf=>meta_inf) if meta_inf
351
+ end
352
+ end
353
+
354
+ def inspect_meta_inf
355
+ package = project('foo').package(@packaging)
356
+ package.invoke
357
+ assumed = Array(@meta_inf_ignore)
358
+ Zip::File.open(package.to_s) do |zip|
359
+ entries = zip.entries.map(&:name).select { |f| File.dirname(f) == 'META-INF' }.map { |f| File.basename(f) }
360
+ assumed.each { |f| entries.should include(f) }
361
+ yield entries - assumed if block_given?
362
+ end
363
+ end
364
+
365
+ it 'should default to LICENSE file' do
366
+ write 'LICENSE'
367
+ package_with_meta_inf
368
+ inspect_meta_inf { |files| files.should eql(['LICENSE']) }
369
+ end
370
+
371
+ it 'should be empty if no LICENSE file' do
372
+ package_with_meta_inf
373
+ inspect_meta_inf { |files| files.should be_empty }
374
+ end
375
+
376
+ it 'should include file specified by :meta_inf option' do
377
+ write 'README'
378
+ package_with_meta_inf 'README'
379
+ inspect_meta_inf { |files| files.should eql(['README']) }
380
+ end
381
+
382
+ it 'should include files specified by :meta_inf option' do
383
+ files = %w[README DISCLAIMER].each { |file| write file }
384
+ package_with_meta_inf files
385
+ inspect_meta_inf { |files| files.should eql(files) }
386
+ end
387
+
388
+ it 'should include file task specified by :meta_inf option' do
389
+ file('README') { |task| write task.to_s }
390
+ package_with_meta_inf file('README')
391
+ inspect_meta_inf { |files| files.should eql(['README']) }
392
+ end
393
+
394
+ it 'should include file tasks specified by :meta_inf option' do
395
+ files = %w[README DISCLAIMER].each { |file| file(file) { |task| write task.to_s } }
396
+ package_with_meta_inf files.map { |f| file(f) }
397
+ inspect_meta_inf { |files| files.should eql(files) }
398
+ end
399
+
400
+ it 'should complain if cannot find file' do
401
+ package_with_meta_inf 'README'
402
+ lambda { inspect_meta_inf }.should raise_error(RuntimeError, /README/)
403
+ end
404
+
405
+ it 'should complain if cannot build task' do
406
+ file('README') { fail 'Failed' }
407
+ package_with_meta_inf 'README'
408
+ lambda { inspect_meta_inf }.should raise_error(RuntimeError, /Failed/)
409
+ end
410
+
411
+ it 'should respond to with() and accept manifest and meta_inf' do
412
+ write 'DISCLAIMER'
413
+ mkpath 'target/classes'
414
+ packaging = @packaging
415
+ define('foo', :version=>'1.0') { package(packaging).with :meta_inf=>'DISCLAIMER' }
416
+ inspect_meta_inf { |files| files.should eql(['DISCLAIMER']) }
417
+ end
418
+ end
419
+
420
+
421
+ describe Packaging, 'jar' do
422
+ it_should_behave_like 'packaging'
423
+ before { @packaging = :jar }
424
+ it_should_behave_like 'package with manifest'
425
+ it_should_behave_like 'package with meta_inf'
426
+ before { @meta_inf_ignore = 'MANIFEST.MF' }
427
+
428
+ it 'should place the manifest as the first entry of the file' do
429
+ write 'src/main/java/Test.java', 'class Test {}'
430
+ define('foo', :version=>'1.0') { package(:jar) }
431
+ project('foo').package(:jar).invoke
432
+ Zip::File.open(project('foo').package(:jar).to_s) do |jar|
433
+ entries_to_s = jar.entries.map(&:to_s).delete_if {|entry| entry[-1,1] == "/"}
434
+ # Sometimes META-INF/ is counted as first entry, which is fair game.
435
+ (entries_to_s.first == 'META-INF/MANIFEST.MF' || entries_to_s[1] == 'META-INF/MANIFEST.MF').should be_true
436
+ end
437
+ end
438
+
439
+ it 'should use files from compile directory if nothing included' do
440
+ write 'src/main/java/Test.java', 'class Test {}'
441
+ define('foo', :version=>'1.0') { package(:jar) }
442
+ project('foo').package(:jar).invoke
443
+ Zip::File.open(project('foo').package(:jar).to_s) do |jar|
444
+ jar.entries.map(&:to_s).sort.should include('META-INF/MANIFEST.MF', 'Test.class')
445
+ end
446
+ end
447
+
448
+ it 'should use files from resources directory if nothing included' do
449
+ write 'src/main/resources/test/important.properties'
450
+ define('foo', :version=>'1.0') { package(:jar) }
451
+ project('foo').package(:jar).invoke
452
+ Zip::File.open(project('foo').package(:jar).to_s) do |jar|
453
+ jar.entries.map(&:to_s).sort.should include('test/important.properties')
454
+ end
455
+ end
456
+
457
+ it 'should include class directories' do
458
+ write 'src/main/java/code/Test.java', 'package code ; class Test {}'
459
+ define('foo', :version=>'1.0') { package(:jar) }
460
+ project('foo').package(:jar).invoke
461
+ Zip::File.open(project('foo').package(:jar).to_s) do |jar|
462
+ jar.entries.map(&:to_s).sort.should include('code/')
463
+ end
464
+ end
465
+
466
+ it 'should include resource files starting with dot' do
467
+ write 'src/main/resources/test/.config'
468
+ define('foo', :version=>'1.0') { package(:jar) }
469
+ project('foo').package(:jar).invoke
470
+ Zip::File.open(project('foo').package(:jar).to_s) do |jar|
471
+ jar.entries.map(&:to_s).sort.should include('test/.config')
472
+ end
473
+ end
474
+
475
+ it 'should include empty resource directories' do
476
+ mkpath 'src/main/resources/empty'
477
+ define('foo', :version=>'1.0') { package(:jar) }
478
+ project('foo').package(:jar).invoke
479
+ Zip::File.open(project('foo').package(:jar).to_s) do |jar|
480
+ jar.entries.map(&:to_s).sort.should include('empty/')
481
+ end
482
+ end
483
+
484
+ it 'should raise error when calling with() with nil value' do
485
+ lambda {
486
+ define('foo', :version=>'1.0') { package(:jar).with(nil) }
487
+ }.should raise_error
488
+ end
489
+
490
+ it 'should exclude resources when ordered to do so' do
491
+ write 'src/main/resources/foo.xml', ''
492
+ foo = define('foo', :version => '1.0') { package(:jar).exclude('foo.xml')}
493
+ foo.package(:jar).invoke
494
+ Zip::File.open(foo.package(:jar).to_s) do |jar|
495
+ jar.entries.map(&:to_s).sort.should_not include('foo.xml')
496
+ end
497
+ end
498
+
499
+ end
500
+
501
+
502
+ describe Packaging, 'war' do
503
+ it_should_behave_like 'packaging'
504
+ before { @packaging = :war }
505
+ it_should_behave_like 'package with manifest'
506
+ it_should_behave_like 'package with meta_inf'
507
+ before { @meta_inf_ignore = 'MANIFEST.MF' }
508
+
509
+ def make_jars
510
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
511
+ artifact('group:id:jar:2.0') { |t| write t.to_s }
512
+ end
513
+
514
+ def inspect_war
515
+ project('foo').package(:war).invoke
516
+ Zip::File.open(project('foo').package(:war).to_s) do |war|
517
+ yield war.entries.map(&:to_s).sort
518
+ end
519
+ end
520
+
521
+ it 'should use files from webapp directory if nothing included' do
522
+ write 'src/main/webapp/test.html'
523
+ define('foo', :version=>'1.0') { package(:war) }
524
+ inspect_war { |files| files.should include('test.html') }
525
+ end
526
+
527
+ it 'should use files from added assets directory if nothing included' do
528
+ write 'generated/main/webapp/test.html'
529
+ define('foo', :version => '1.0') { assets.paths << 'generated/main/webapp/'; package(:war) }
530
+ inspect_war { |files| files.should include('test.html') }
531
+ end
532
+
533
+ it 'should use files from generated assets directory if nothing included' do
534
+ write 'generated/main/webapp/test.html'
535
+ define('foo', :version => '1.0') do
536
+ target_dir = _('generated/main/webapp')
537
+ assets.paths << project.file(target_dir) do
538
+ mkdir_p target_dir
539
+ touch "#{target_dir}/test.html"
540
+ touch target_dir
541
+ end
542
+ package(:war)
543
+ end
544
+ inspect_war { |files| files.should include('test.html') }
545
+ end
546
+
547
+ it 'should accept files from :classes option' do
548
+ write 'classes/test'
549
+ define('foo', :version=>'1.0') { package(:war).with(:classes=>'classes') }
550
+ inspect_war { |files| files.should include('WEB-INF/classes/test') }
551
+ end
552
+
553
+ it 'should use files from compile directory if nothing included' do
554
+ write 'src/main/java/Test.java', 'class Test {}'
555
+ define('foo', :version=>'1.0') { package(:war) }
556
+ inspect_war { |files| files.should include('WEB-INF/classes/Test.class') }
557
+ end
558
+
559
+ it 'should ignore compile directory if no source files to compile' do
560
+ define('foo', :version=>'1.0') { package(:war) }
561
+ inspect_war { |files| files.should_not include('target/classes') }
562
+ end
563
+
564
+ it 'should include only specified classes directories' do
565
+ write 'src/main/java'
566
+ define('foo', :version=>'1.0') { package(:war).with :classes=>_('additional') }
567
+ project('foo').package(:war).classes.should_not include(project('foo').file('target/classes'))
568
+ project('foo').package(:war).classes.should include(project('foo').file('additional'))
569
+ end
570
+
571
+ it 'should use files from resources directory if nothing included' do
572
+ write 'src/main/resources/test/important.properties'
573
+ define('foo', :version=>'1.0') { package(:war) }
574
+ inspect_war { |files| files.should include('WEB-INF/classes/test/important.properties') }
575
+ end
576
+
577
+ it 'should include empty resource directories' do
578
+ mkpath 'src/main/resources/empty'
579
+ define('foo', :version=>'1.0') { package(:war) }
580
+ inspect_war { |files| files.should include('WEB-INF/classes/empty/') }
581
+ end
582
+
583
+ it 'should accept file from :libs option' do
584
+ write 'lib/foo.jar'
585
+ define('foo', :version=>'1.0') { package(:war).libs << 'lib/foo.jar' }
586
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/foo.jar') }
587
+ end
588
+
589
+
590
+ it 'should accept artifacts from :libs option' do
591
+ make_jars
592
+ define('foo', :version=>'1.0') { package(:war).with(:libs=>'group:id:jar:1.0') }
593
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
594
+ end
595
+
596
+ it 'should accept artifacts from :libs option' do
597
+ make_jars
598
+ define('foo', :version=>'1.0') { package(:war).with(:libs=>%w[group:id:jar:1.0 group:id:jar:2.0]) }
599
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar', 'WEB-INF/lib/id-2.0.jar') }
600
+ end
601
+
602
+ it 'should 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(:war) }
605
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar', 'WEB-INF/lib/id-2.0.jar') }
606
+ end
607
+
608
+ it 'should use artifacts from compile classpath if no libs specified, leaving the user specify which to exclude as files' do
609
+ make_jars
610
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war).path('WEB-INF/lib').exclude('id-2.0.jar') }
611
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
612
+ end
613
+
614
+ it 'should use artifacts from compile classpath if no libs specified, leaving the user specify which to exclude as files with glob expressions' do
615
+ make_jars
616
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war).path('WEB-INF/lib').exclude('**/id-2.0.jar') }
617
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
618
+ end
619
+
620
+ it 'should exclude files regardless of the path where they are included, using wildcards' do
621
+ make_jars
622
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war).exclude('**/id-2.0.jar') }
623
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
624
+ end
625
+
626
+ it 'should exclude files regardless of the path where they are included, specifying target path entirely' do
627
+ make_jars
628
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war).exclude('WEB-INF/lib/id-2.0.jar') }
629
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
630
+ end
631
+
632
+ it 'should exclude files regardless of the path where they are included for war files' do
633
+ write 'src/main/java/com/example/included/Test.java', 'package com.example.included; class Test {}'
634
+ write 'src/main/java/com/example/excluded/Test.java', 'package com.example.excluded; class Test {}'
635
+ define('foo', :version=>'1.0') do
636
+ package(:war).enhance do |war|
637
+ war.exclude('WEB-INF/classes/com/example/excluded/**.class')
638
+ end
639
+ end
640
+ inspect_war do |files|
641
+ files.should include('WEB-INF/classes/com/example/included/Test.class')
642
+ files.should_not include('WEB-INF/classes/com/example/excluded/Test.class')
643
+ end
644
+ end
645
+
646
+ it 'should include only specified libraries' do
647
+ define 'foo', :version=>'1.0' do
648
+ compile.with 'group:id:jar:1.0'
649
+ package(:war).with :libs=>'additional:id:jar:1.0'
650
+ end
651
+ project('foo').package(:war).libs.should_not include(artifact('group:id:jar:1.0'))
652
+ project('foo').package(:war).libs.should include(artifact('additional:id:jar:1.0'))
653
+ end
654
+
655
+ end
656
+
657
+ describe Packaging, 'sources' do
658
+ it_should_behave_like 'packaging'
659
+ before { @packaging, @package_type = :sources, :jar }
660
+
661
+ it 'should create package of type :jar and classifier \'sources\'' do
662
+ define 'foo', :version=>'1.0' do
663
+ package(:sources).type.should eql(:jar)
664
+ package(:sources).classifier.should eql('sources')
665
+ package(:sources).name.should match(/foo-1.0-sources.jar$/)
666
+ end
667
+ end
668
+
669
+ it 'should contain source and resource files' do
670
+ write 'src/main/java/Source.java'
671
+ write 'src/main/resources/foo.properties', 'foo=bar'
672
+ define('foo', :version=>'1.0') { package(:sources) }
673
+ project('foo').task('package').invoke
674
+ project('foo').packages.first.should contain('Source.java')
675
+ project('foo').packages.first.should contain('foo.properties')
676
+ end
677
+
678
+ it 'should create sources jar if resources exists (but not sources)' do
679
+ write 'src/main/resources/foo.properties', 'foo=bar'
680
+ define('foo', :version=>'1.0') { package(:sources) }
681
+ project('foo').package(:sources).invoke
682
+ project('foo').packages.first.should contain('foo.properties')
683
+ end
684
+
685
+ it 'should be a ZipTask' do
686
+ define 'foo', :version=>'1.0' do
687
+ package(:sources).should be_kind_of(ZipTask)
688
+ end
689
+ end
690
+ end
691
+
692
+ describe Packaging, 'javadoc' do
693
+ it_should_behave_like 'packaging'
694
+ before { @packaging, @package_type = :javadoc, :jar }
695
+
696
+ it 'should create package of type :zip and classifier \'javadoc\'' do
697
+ define 'foo', :version=>'1.0' do
698
+ package(:javadoc).type.should eql(:jar)
699
+ package(:javadoc).classifier.should eql('javadoc')
700
+ package(:javadoc).name.pathmap('%f').should eql('foo-1.0-javadoc.jar')
701
+ end
702
+ end
703
+
704
+ it 'should contain Javadocs' do
705
+ write 'src/main/java/Source.java', 'public class Source {}'
706
+ define('foo', :version=>'1.0') { package(:javadoc) }
707
+ project('foo').task('package').invoke
708
+ project('foo').packages.first.should contain('Source.html', 'index.html')
709
+ end
710
+
711
+ it 'should use project description in window title' do
712
+ write 'src/main/java/Source.java', 'public class Source {}'
713
+ desc 'My Project'
714
+ define('foo', :version=>'1.0') { package(:javadoc) }
715
+ project('foo').task('package').invoke
716
+ project('foo').packages.first.entry('index.html').should contain('My Project')
717
+ end
718
+
719
+ it 'should be a ZipTask' do
720
+ define 'foo', :version=>'1.0' do
721
+ package(:javadoc).should be_kind_of(ZipTask)
722
+ end
723
+ end
724
+ end
725
+
726
+ RSpec.shared_examples 'package_with_' do
727
+
728
+ def prepare(options = {})
729
+ packager = "package_with_#{@packaging}"
730
+ write 'src/main/java/Source.java'
731
+ write 'baz/src/main/java/Source.java'
732
+ define 'foo', :version=>'1.0' do
733
+ send packager, options
734
+ define 'bar' ; define 'baz'
735
+ end
736
+ end
737
+
738
+ def applied_to
739
+ projects.select { |project| project.packages.first }.map(&:name)
740
+ end
741
+
742
+ it 'should create package of the right packaging with classifier' do
743
+ prepare
744
+ project('foo').packages.first.to_s.should =~ /foo-1.0-#{@packaging}.#{@ext}/
745
+ end
746
+
747
+ it 'should create package for projects that have source files' do
748
+ prepare
749
+ applied_to.should include('foo', 'foo:baz')
750
+ end
751
+
752
+ it 'should not create package for projects that have no source files' do
753
+ prepare
754
+ applied_to.should_not include('foo:bar')
755
+ end
756
+
757
+ it 'should limit to projects specified by :only' do
758
+ prepare :only=>'baz'
759
+ applied_to.should eql(['foo:baz'])
760
+ end
761
+
762
+ it 'should limit to projects specified by :only array' do
763
+ prepare :only=>['baz']
764
+ applied_to.should eql(['foo:baz'])
765
+ end
766
+
767
+ it 'should ignore project specified by :except' do
768
+ prepare :except=>'baz'
769
+ applied_to.should eql(['foo'])
770
+ end
771
+
772
+ it 'should ignore projects specified by :except array' do
773
+ prepare :except=>['baz']
774
+ applied_to.should eql(['foo'])
775
+ end
776
+ end
777
+
778
+ describe 'package_with_sources' do
779
+ it_should_behave_like 'package_with_'
780
+ before { @packaging, @ext = :sources, 'jar' }
781
+ end
782
+
783
+ describe 'package_with_javadoc' do
784
+ it_should_behave_like 'package_with_'
785
+ before { @packaging, @ext = :javadoc, 'jar' }
786
+ end