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,63 @@
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
+ RSpec.shared_examples 'packaging' do
18
+ it 'should create artifact of proper type' do
19
+ packaging = @packaging
20
+ package_type = @package_type || @packaging
21
+ define 'foo', :version=>'1.0' do
22
+ package(packaging).type.should eql(package_type) rescue exit!
23
+ end
24
+ end
25
+
26
+ it 'should create file with proper extension' do
27
+ packaging = @packaging
28
+ package_type = @package_type || @packaging
29
+ define 'foo', :version=>'1.0' do
30
+ package(packaging).to_s.should match(/.#{package_type}$/)
31
+ end
32
+ end
33
+
34
+ it 'should always return same task for the same package' do
35
+ packaging = @packaging
36
+ define 'foo', :version=>'1.0' do
37
+ package(packaging)
38
+ package(packaging, :id=>'other')
39
+ end
40
+ project('foo').packages.uniq.size.should eql(2)
41
+ end
42
+
43
+ it 'should complain if option not known' do
44
+ packaging = @packaging
45
+ define 'foo', :version=>'1.0' do
46
+ lambda { package(packaging, :unknown_option=>true) }.should raise_error(ArgumentError, /no such option/)
47
+ end
48
+ end
49
+
50
+ it 'should respond to with() and return self' do
51
+ packaging = @packaging
52
+ define 'foo', :version=>'1.0' do
53
+ package(packaging).with({}).should be(package(packaging))
54
+ end
55
+ end
56
+
57
+ it 'should respond to with() and complain if unknown option' do
58
+ packaging = @packaging
59
+ define 'foo', :version=>'1.0' do
60
+ lambda { package(packaging).with(:unknown_option=>true) }.should raise_error(ArgumentError, /does not support the option/)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,690 @@
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
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
17
+ require File.expand_path(File.join(File.dirname(__FILE__), 'packaging_helper'))
18
+
19
+ describe Project, '#group' do
20
+ it 'should default to project name' do
21
+ desc 'My Project'
22
+ define('foo').group.should eql('foo')
23
+ end
24
+
25
+ it 'should be settable' do
26
+ define('foo', :group=>'bar').group.should eql('bar')
27
+ end
28
+
29
+ it 'should inherit from parent project' do
30
+ define('foo', :group=>'groupie') { define 'bar' }
31
+ project('foo:bar').group.should eql('groupie')
32
+ end
33
+ end
34
+
35
+ describe Project, '#version' do
36
+ it 'should default to nil' do
37
+ define('foo').version.should be_nil
38
+ end
39
+
40
+ it 'should be settable' do
41
+ define('foo', :version=>'2.1').version.should eql('2.1')
42
+ end
43
+
44
+ it 'should inherit from parent project' do
45
+ define('foo', :version=>'2.1') { define 'bar' }
46
+ project('foo:bar').version.should eql('2.1')
47
+ end
48
+ end
49
+
50
+ describe Project, '#id' do
51
+ it 'should be same as project name' do
52
+ define('foo').id.should eql('foo')
53
+ end
54
+
55
+ it 'should replace colons with dashes' do
56
+ define('foo', :version=>'2.1') { define 'bar' }
57
+ project('foo:bar').id.should eql('foo-bar')
58
+ end
59
+
60
+ it 'should not be settable' do
61
+ lambda { define 'foo', :id=>'bar' }.should raise_error(NoMethodError)
62
+ end
63
+ end
64
+
65
+
66
+ describe Project, '#package' do
67
+ it 'should default to id from project' do
68
+ define('foo', :version=>'1.0') do
69
+ package(:jar).id.should eql('foo')
70
+ end
71
+ end
72
+
73
+ it 'should default to composed id for nested projects' do
74
+ define('foo', :version=>'1.0') do
75
+ define 'bar' do
76
+ package(:jar).id.should eql('foo-bar')
77
+ end
78
+ end
79
+ end
80
+
81
+ it 'should take id from option if specified' do
82
+ define 'foo', :version=>'1.0' do
83
+ package(:jar, :id=>'bar').id.should eql('bar')
84
+ define 'bar' do
85
+ package(:jar, :id=>'baz').id.should eql('baz')
86
+ end
87
+ end
88
+ end
89
+
90
+ it 'should default to group from project' do
91
+ define 'foo', :version=>'1.0' do
92
+ package(:jar).group.should eql('foo')
93
+ define 'bar' do
94
+ package(:jar).group.should eql('foo')
95
+ end
96
+ end
97
+ end
98
+
99
+ it 'should take group from option if specified' do
100
+ define 'foo', :version=>'1.0' do
101
+ package(:jar, :group=>'foos').group.should eql('foos')
102
+ define 'bar' do
103
+ package(:jar, :group=>'bars').group.should eql('bars')
104
+ end
105
+ end
106
+ end
107
+
108
+ it 'should default to version from project' do
109
+ define 'foo', :version=>'1.0' do
110
+ package(:jar).version.should eql('1.0')
111
+ define 'bar' do
112
+ package(:jar).version.should eql('1.0')
113
+ end
114
+ end
115
+ end
116
+
117
+ it 'should take version from option if specified' do
118
+ define 'foo', :version=>'1.0' do
119
+ package(:jar, :version=>'1.1').version.should eql('1.1')
120
+ define 'bar' do
121
+ package(:jar, :version=>'1.2').version.should eql('1.2')
122
+ end
123
+ end
124
+ end
125
+
126
+ it 'should accept package type as first argument' do
127
+ define 'foo', :version=>'1.0' do
128
+ package(:war).type.should eql(:war)
129
+ define 'bar' do
130
+ package(:jar).type.should eql(:jar)
131
+ end
132
+ end
133
+ end
134
+
135
+ it 'should support optional type' do
136
+ define 'foo', :version=>'1.0' do
137
+ package.type.should eql(:zip)
138
+ package(:classifier=>'srcs').type.should eql(:zip)
139
+ end
140
+ define 'bar', :version=>'1.0' do
141
+ compile.using :javac
142
+ package(:classifier=>'srcs').type.should eql(:jar)
143
+ end
144
+ end
145
+
146
+ it 'should assume :zip package type unless specified' do
147
+ define 'foo', :version=>'1.0' do
148
+ package.type.should eql(:zip)
149
+ define 'bar' do
150
+ package.type.should eql(:zip)
151
+ end
152
+ end
153
+ end
154
+
155
+ it 'should infer packaging type from compiler' do
156
+ define 'foo', :version=>'1.0' do
157
+ compile.using :javac
158
+ package.type.should eql(:jar)
159
+ end
160
+ end
161
+
162
+ it 'should fail if packaging not supported' do
163
+ lambda { define('foo') { package(:weirdo) } }.should raise_error(RuntimeError, /Don't know how to create a package/)
164
+ end
165
+
166
+ it 'should call package_as_foo when using package(:foo)' do
167
+ class Buildr::Project
168
+ def package_as_foo(file_name)
169
+ file(file_name) do |t|
170
+ mkdir_p File.dirname(t.to_s)
171
+ File.open(t.to_s, 'w') {|f| f.write('foo') }
172
+ end
173
+ end
174
+ end
175
+ define('foo', :version => '1.0') do |project|
176
+ package(:foo).invoke
177
+ package(:foo).should exist
178
+ package(:foo).should contain('foo')
179
+ end
180
+ end
181
+
182
+ it 'should allow to respec package(:sources) using package_as_sources_spec()' do
183
+ class Buildr::Project
184
+ def package_as_sources_spec(spec)
185
+ spec.merge({ :type=>:jar, :classifier=>'sources' })
186
+ end
187
+ end
188
+ define('foo', :version => '1.0') do
189
+ package(:sources).type.should eql(:jar)
190
+ package(:sources).classifier.should eql('sources')
191
+ end
192
+ end
193
+
194
+ it 'should produce different packages for different specs' do
195
+ class Buildr::Project
196
+ def package_as_foo(file_name)
197
+ file(file_name)
198
+ end
199
+
200
+ def package_as_foo_spec(spec)
201
+ spec.merge(:type => :zip)
202
+ end
203
+
204
+ def package_as_bar(file_name)
205
+ file(file_name)
206
+ end
207
+
208
+ def package_as_bar_spec(spec)
209
+ spec.merge(:type => :zip, :classifier => "foobar")
210
+ end
211
+
212
+ end
213
+ define('foo', :version => '1.0') do
214
+ package(:foo).type.should eql(:zip)
215
+ package(:foo).classifier.should be_nil
216
+ package(:bar).type.should eql(:zip)
217
+ package(:bar).classifier.should eql('foobar')
218
+ package(:foo).equal?(package(:bar)).should be_false
219
+ end
220
+ end
221
+
222
+ it 'should default to no classifier' do
223
+ define 'foo', :version=>'1.0' do
224
+ package.classifier.should be_nil
225
+ define 'bar' do
226
+ package.classifier.should be_nil
227
+ end
228
+ end
229
+ end
230
+
231
+ it 'should accept classifier from option' do
232
+ define 'foo', :version=>'1.0' do
233
+ package(:classifier=>'srcs').classifier.should eql('srcs')
234
+ define 'bar' do
235
+ package(:classifier=>'docs').classifier.should eql('docs')
236
+ end
237
+ end
238
+ end
239
+
240
+ it 'should return a file task' do
241
+ define('foo', :version=>'1.0') { package(:jar) }
242
+ project('foo').package(:jar).should be_kind_of(Rake::FileTask)
243
+ end
244
+
245
+ it 'should return a task that acts as artifact' do
246
+ define('foo', :version=>'1.0') { package(:jar) }
247
+ project('foo').package(:jar).should respond_to(:to_spec)
248
+ project('foo').package(:jar).to_spec.should eql('foo:foo:jar:1.0')
249
+ end
250
+
251
+ it 'should create different tasks for each spec' do
252
+ define 'foo', :version=>'1.0' do
253
+ package(:jar)
254
+ package(:war)
255
+ package(:jar, :id=>'bar')
256
+ package(:jar, :classifier=>'srcs')
257
+ package(:jar, :classifier=>'doc')
258
+ end
259
+ project('foo').packages.uniq.size.should be(5)
260
+ end
261
+
262
+ it 'should create different tasks for package with different ids' do
263
+ define 'foo', :version=>'1.0' do
264
+ package(:jar, :id=>'bar')
265
+ package(:jar)
266
+ end
267
+ project('foo').packages.uniq.size.should be(2)
268
+ end
269
+
270
+ it 'should create different tasks for package with classifier' do
271
+ define 'foo', :version=>'1.0' do
272
+ package(:jar)
273
+ package(:jar, :classifier=>'foo')
274
+ end
275
+ project('foo').packages.uniq.size.should be(2)
276
+ end
277
+
278
+ it 'should not create multiple packages for the same spec' do
279
+ define 'foo', :version=>'1.0' do
280
+ package(:war)
281
+ package(:war)
282
+ package(:jar, :id=>'bar')
283
+ package(:jar, :id=>'bar')
284
+ package(:jar, :id=>'baz')
285
+ end
286
+ project('foo').packages.uniq.size.should be(3)
287
+ end
288
+
289
+ it 'should create different tasks for specs with matching type' do
290
+ define 'foo', :version=>'1.0' do
291
+ doc("foo").into( "foo" )
292
+ package(:javadoc)
293
+ package(:zip)
294
+ end
295
+ project('foo').packages.uniq.size.should be(2)
296
+ end
297
+
298
+ it 'should return the same task for subsequent calls' do
299
+ define 'foo', :version=>'1.0' do
300
+ package.should eql(package)
301
+ package(:jar, :classifier=>'resources').should be(package(:jar, :classifier=>'resources'))
302
+ end
303
+ end
304
+
305
+ it 'should return a packaging task even if file already exists' do
306
+ write 'target/foo-1.0.zip', ''
307
+ define 'foo', :version=>'1.0' do
308
+ package.should be_kind_of(ZipTask)
309
+ end
310
+ end
311
+
312
+ it 'should register task as artifact' do
313
+ define 'foo', :version=>'1.0' do
314
+ package(:jar, :id=>'bar')
315
+ package(:war)
316
+ end
317
+ project('foo').packages.should eql(artifacts('foo:bar:jar:1.0', 'foo:foo:war:1.0'))
318
+ end
319
+
320
+ it 'should create in target path' do
321
+ define 'foo', :version=>'1.0' do
322
+ package(:war).should point_to_path('target/foo-1.0.war')
323
+ package(:jar, :id=>'bar').should point_to_path('target/bar-1.0.jar')
324
+ package(:zip, :classifier=>'srcs').should point_to_path('target/foo-1.0-srcs.zip')
325
+ end
326
+ end
327
+
328
+ it 'should create prerequisite for package task' do
329
+ define 'foo', :version=>'1.0' do
330
+ package(:war)
331
+ package(:jar, :id=>'bar')
332
+ package(:jar, :classifier=>'srcs')
333
+ end
334
+ project('foo').task('package').prerequisites.should include(*project('foo').packages)
335
+ end
336
+
337
+ it 'should create task requiring a build' do
338
+ define 'foo', :version=>'1.0' do
339
+ package(:war).prerequisites.should include(build)
340
+ package(:jar, :id=>'bar').prerequisites.should include(build)
341
+ package(:jar, :classifier=>'srcs').prerequisites.should include(build)
342
+ end
343
+ end
344
+
345
+ it 'should create a POM artifact in target directory' do
346
+ define 'foo', :version=>'1.0' do
347
+ package.pom.should be(artifact('foo:foo:pom:1.0'))
348
+ package.pom.to_s.should point_to_path('target/foo-1.0.pom')
349
+ end
350
+ end
351
+
352
+ it 'should create POM artifact ignoring classifier' do
353
+ define 'foo', :version=>'1.0' do
354
+ package(:jar, :classifier=>'srcs').pom.should be(artifact('foo:foo:pom:1.0'))
355
+ end
356
+ end
357
+
358
+ it 'should create POM artifact that creates its own POM' do
359
+ define('foo', :group=>'bar', :version=>'1.0') { package(:jar) }
360
+ pom = project('foo').packages.first.pom
361
+ pom.invoke
362
+ read(pom.to_s).should eql(<<-POM
363
+ <?xml version="1.0" encoding="UTF-8"?>
364
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
365
+ <modelVersion>4.0.0</modelVersion>
366
+ <groupId>bar</groupId>
367
+ <artifactId>foo</artifactId>
368
+ <version>1.0</version>
369
+ <packaging>jar</packaging>
370
+ <name>foo</name>
371
+ <description>foo</description>
372
+ </project>
373
+ POM
374
+ )
375
+ end
376
+
377
+ it 'should not require downloading artifact or POM' do
378
+ #task('artifacts').instance_eval { @actions.clear }
379
+ define('foo', :group=>'bar', :version=>'1.0') { package(:jar) }
380
+ lambda { task('artifacts').invoke }.should_not raise_error
381
+ end
382
+
383
+ describe "existing package access" do
384
+ it "should return the same instance for identical optionless invocations" do
385
+ define 'foo', :version => '1.0' do
386
+ package(:zip).should equal(package(:zip))
387
+ end
388
+ project('foo').packages.size.should == 1
389
+ end
390
+
391
+ it "should return the exactly matching package identical invocations with options" do
392
+ define 'foo', :version => '1.0' do
393
+ package(:zip, :id => 'src')
394
+ package(:zip, :id => 'bin')
395
+ end
396
+ project('foo').package(:zip, :id => 'src').should equal(project('foo').packages.first)
397
+ project('foo').package(:zip, :id => 'bin').should equal(project('foo').packages.last)
398
+ project('foo').packages.size.should == 2
399
+ end
400
+
401
+ it "should return the first of the same type for subsequent optionless invocations" do
402
+ define 'foo', :version => '1.0' do
403
+ package(:zip, :file => 'override.zip')
404
+ package(:jar, :file => 'another.jar')
405
+ end
406
+ project('foo').package(:zip).name.should == 'override.zip'
407
+ project('foo').package(:jar).name.should == 'another.jar'
408
+ project('foo').packages.size.should == 2
409
+ end
410
+ end
411
+ end
412
+
413
+ describe Project, '#package file' do
414
+ it 'should be a file task' do
415
+ define 'foo' do
416
+ package(:zip, :file=>'foo.zip').should be_kind_of(Rake::FileTask)
417
+ end
418
+ end
419
+
420
+ it 'should not require id, project or version' do
421
+ define 'foo', :group=>nil do
422
+ lambda { package(:zip, :file=>'foo.zip') }.should_not raise_error
423
+ lambda { package(:zip, :file=>'bar.zip', :id=>'error') }.should raise_error
424
+ lambda { package(:zip, :file=>'bar.zip', :group=>'error') }.should raise_error
425
+ lambda { package(:zip, :file=>'bar.zip', :version=>'error') }.should raise_error
426
+ end
427
+ end
428
+
429
+ it 'should not provide project or version' do
430
+ define 'foo' do
431
+ package(:zip, :file=>'foo.zip').tap do |pkg|
432
+ pkg.should_not respond_to(:group)
433
+ pkg.should_not respond_to(:version)
434
+ end
435
+ end
436
+ end
437
+
438
+ it 'should provide packaging type' do
439
+ define 'foo', :version=>'1.0' do
440
+ zip = package(:zip, :file=>'foo.zip')
441
+ jar = package(:jar, :file=>'bar.jar')
442
+ zip.type.should eql(:zip)
443
+ jar.type.should eql(:jar)
444
+ end
445
+ end
446
+
447
+ it 'should assume packaging type from extension if unspecified' do
448
+ define 'foo', :version=>'1.0' do
449
+ package(:file=>'foo.zip').class.should be(Buildr::ZipTask)
450
+ define 'bar' do
451
+ package(:file=>'bar.jar').class.should be(Buildr::Packaging::Java::JarTask)
452
+ end
453
+ end
454
+ end
455
+
456
+ it 'should support different packaging types' do
457
+ define 'foo', :version=>'1.0' do
458
+ package(:jar, :file=>'foo.jar').class.should be(Buildr::Packaging::Java::JarTask)
459
+ end
460
+ define 'bar' do
461
+ package(:type=>:war, :file=>'bar.war').class.should be(Buildr::Packaging::Java::WarTask)
462
+ end
463
+ end
464
+
465
+ it 'should fail if packaging not supported' do
466
+ lambda { define('foo') { package(:weirdo, :file=>'foo.zip') } }.should raise_error(RuntimeError, /Don't know how to create a package/)
467
+ end
468
+
469
+ it 'should create different tasks for each file' do
470
+ define 'foo', :version=>'1.0' do
471
+ package(:zip, :file=>'foo.zip')
472
+ package(:jar, :file=>'foo.jar')
473
+ end
474
+ project('foo').packages.uniq.size.should be(2)
475
+ end
476
+
477
+ it 'should return the same task for subsequent calls' do
478
+ define 'foo', :version=>'1.0' do
479
+ package(:zip, :file=>'foo.zip').should eql(package(:file=>'foo.zip'))
480
+ end
481
+ end
482
+
483
+ it 'should point to specified file' do
484
+ define 'foo', :version=>'1.0' do
485
+ package(:zip, :file=>'foo.zip').should point_to_path('foo.zip')
486
+ package(:zip, :file=>'target/foo-1.0.zip').should point_to_path('target/foo-1.0.zip')
487
+ end
488
+ end
489
+
490
+ it 'should create prerequisite for package task' do
491
+ define 'foo', :version=>'1.0' do
492
+ package(:zip, :file=>'foo.zip')
493
+ end
494
+ project('foo').task('package').prerequisites.should include(*project('foo').packages)
495
+ end
496
+
497
+ it 'should create task requiring a build' do
498
+ define 'foo', :version=>'1.0' do
499
+ package(:zip, :file=>'foo.zip').prerequisites.should include(build)
500
+ end
501
+ end
502
+
503
+ it 'should create specified file during build' do
504
+ define 'foo', :version=>'1.0' do
505
+ package(:zip, :file=>'foo.zip')
506
+ end
507
+ lambda { project('foo').task('package').invoke }.should change { File.exist?('foo.zip') }.to(true)
508
+ end
509
+
510
+ it 'should do nothing for installation/upload' do
511
+ define 'foo', :version=>'1.0' do
512
+ package(:zip, :file=>'foo.zip')
513
+ end
514
+ lambda do
515
+ task('install').invoke
516
+ task('upload').invoke
517
+ task('uninstall').invoke
518
+ end.should_not raise_error
519
+ end
520
+
521
+ end
522
+
523
+ describe Rake::Task, ' package' do
524
+ it 'should be local task' do
525
+ define 'foo', :version=>'1.0' do
526
+ package
527
+ define('bar') { package }
528
+ end
529
+ in_original_dir project('foo:bar').base_dir do
530
+ task('package').invoke
531
+ project('foo').package.should_not exist
532
+ project('foo:bar').package.should exist
533
+ end
534
+ end
535
+
536
+ it 'should be recursive task' do
537
+ define 'foo', :version=>'1.0' do
538
+ package
539
+ define('bar') { package }
540
+ end
541
+ task('package').invoke
542
+ project('foo').package.should exist
543
+ project('foo:bar').package.should exist
544
+ end
545
+
546
+ it 'should create package in target directory' do
547
+ define 'foo', :version=>'1.0' do
548
+ package
549
+ define('bar') { package }
550
+ end
551
+ task('package').invoke
552
+ FileList['**/target/*.zip'].map.sort.should == %w[bar/target/foo-bar-1.0.zip target/foo-1.0.zip]
553
+ end
554
+ end
555
+
556
+ describe Rake::Task, ' install' do
557
+ it 'should be local task' do
558
+ define 'foo', :version=>'1.0' do
559
+ package
560
+ define('bar') { package }
561
+ end
562
+ in_original_dir project('foo:bar').base_dir do
563
+ task('install').invoke
564
+ artifacts('foo:foo:zip:1.0', 'foo:foo:pom:1.0').each { |t| t.should_not exist }
565
+ artifacts('foo:foo-bar:zip:1.0', 'foo:foo-bar:pom:1.0').each { |t| t.should exist }
566
+ end
567
+ end
568
+
569
+ it 'should be recursive task' do
570
+ define 'foo', :version=>'1.0' do
571
+ package
572
+ define('bar') { package }
573
+ end
574
+ task('install').invoke
575
+ artifacts('foo:foo:zip:1.0', 'foo:foo:pom:1.0', 'foo:foo-bar:zip:1.0', 'foo:foo-bar:pom:1.0').each { |t| t.should exist }
576
+ end
577
+
578
+ it 'should create package in local repository' do
579
+ define 'foo', :version=>'1.0' do
580
+ package
581
+ define('bar') { package }
582
+ end
583
+ task('install').invoke
584
+ FileList[repositories.local + '/**/*'].reject { |f| File.directory?(f) }.sort.should == [
585
+ File.expand_path('foo/foo/1.0/foo-1.0.zip', repositories.local),
586
+ File.expand_path('foo/foo/1.0/foo-1.0.pom', repositories.local),
587
+ File.expand_path('foo/foo-bar/1.0/foo-bar-1.0.zip', repositories.local),
588
+ File.expand_path('foo/foo-bar/1.0/foo-bar-1.0.pom', repositories.local)].sort
589
+ end
590
+ end
591
+
592
+ describe Rake::Task, ' uninstall' do
593
+ it 'should be local task' do
594
+ define 'foo', :version=>'1.0' do
595
+ package
596
+ define('bar') { package }
597
+ end
598
+ task('install').invoke
599
+ in_original_dir project('foo:bar').base_dir do
600
+ task('uninstall').invoke
601
+ FileList[repositories.local + '/**/*'].reject { |f| File.directory?(f) }.sort.should == [
602
+ File.expand_path('foo/foo/1.0/foo-1.0.zip', repositories.local),
603
+ File.expand_path('foo/foo/1.0/foo-1.0.pom', repositories.local)].sort
604
+ end
605
+ end
606
+
607
+ it 'should be recursive task' do
608
+ define 'foo', :version=>'1.0' do
609
+ package
610
+ define('bar') { package }
611
+ end
612
+ task('install').invoke
613
+ task('uninstall').invoke
614
+ FileList[repositories.local + '/**/*'].reject { |f| File.directory?(f) }.sort.should be_empty
615
+ end
616
+ end
617
+
618
+ describe Rake::Task, ' upload' do
619
+ before do
620
+ repositories.release_to = URI.escape("file://#{File.expand_path('remote')}")
621
+ end
622
+
623
+ it 'should be local task' do
624
+ define 'foo', :version=>'1.0' do
625
+ package
626
+ define('bar') { package }
627
+ end
628
+ in_original_dir project('foo:bar').base_dir do
629
+ lambda { task('upload').invoke }.should run_task('foo:bar:upload').but_not('foo:upload')
630
+ end
631
+ end
632
+
633
+ it 'should be recursive task' do
634
+ define 'foo', :version=>'1.0' do
635
+ package
636
+ define('bar') { package }
637
+ end
638
+ lambda { task('upload').invoke }.should run_tasks('foo:upload', 'foo:bar:upload')
639
+ end
640
+
641
+ it 'should upload artifact and POM' do
642
+ define('foo', :version=>'1.0') { package :jar }
643
+ task('upload').invoke
644
+ { 'remote/foo/foo/1.0/foo-1.0.jar'=>project('foo').package(:jar),
645
+ 'remote/foo/foo/1.0/foo-1.0.pom'=>project('foo').package(:jar).pom }.each do |upload, package|
646
+ read(upload).should eql(read(package))
647
+ end
648
+ end
649
+
650
+ it 'should not upload twice the pom when artifacts are uploaded from a project' do
651
+ write 'src/main/java/Foo.java', 'public class Foo {}'
652
+ repositories.release_to = 'https://buildr.apache.org/repository/noexist/base'
653
+ define 'foo' do
654
+ project.group = "attached"
655
+ project.version = "1.0"
656
+ package(:jar)
657
+ package(:sources)
658
+ end
659
+ URI.should_receive(:upload).exactly(:once).
660
+ with(URI.parse('https://buildr.apache.org/repository/noexist/base/attached/foo/1.0/foo-1.0-sources.jar'), project("foo").package(:sources).to_s, anything)
661
+ URI.should_receive(:upload).exactly(:once).
662
+ with(URI.parse('https://buildr.apache.org/repository/noexist/base/attached/foo/1.0/foo-1.0.jar'), project("foo").package(:jar).to_s, anything)
663
+ URI.should_receive(:upload).exactly(:once).
664
+ with(URI.parse('https://buildr.apache.org/repository/noexist/base/attached/foo/1.0/foo-1.0.pom'), project("foo").package(:jar).pom.to_s, anything)
665
+ verbose(false) { project("foo").upload.invoke }
666
+ end
667
+
668
+ it 'should upload signatures for artifact and POM' do
669
+ define('foo', :version=>'1.0') { package :jar }
670
+ task('upload').invoke
671
+ { 'remote/foo/foo/1.0/foo-1.0.jar'=>project('foo').package(:jar),
672
+ 'remote/foo/foo/1.0/foo-1.0.pom'=>project('foo').package(:jar).pom }.each do |upload, package|
673
+ read("#{upload}.md5").split.first.should eql(Digest::MD5.hexdigest(read(package, "rb")))
674
+ read("#{upload}.sha1").split.first.should eql(Digest::SHA1.hexdigest(read(package, "rb")))
675
+ end
676
+ end
677
+ end
678
+
679
+ describe Packaging, 'zip' do
680
+ it_should_behave_like 'packaging'
681
+ before { @packaging = :zip }
682
+
683
+ it 'should not include META-INF directory' do
684
+ define('foo', :version=>'1.0') { package(:zip) }
685
+ project('foo').package(:zip).invoke
686
+ Zip::File.open(project('foo').package(:zip).to_s) do |zip|
687
+ zip.entries.map(&:to_s).should_not include('META-INF/')
688
+ end
689
+ end
690
+ end