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,656 @@
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
+ # Return now at the resolution that the current filesystem supports
20
+ # Avoids scenario where Time.now and Time.now + 1 have same value on filesystem
21
+ def now_at_fs_resolution
22
+ test_filename = "#{Dir.pwd}/deleteme"
23
+ FileUtils.touch test_filename
24
+ File.atime(test_filename)
25
+ end
26
+
27
+ module CompilerHelper
28
+ def compile_task
29
+ @compile_task ||= define('foo').compile.using(:javac)
30
+ end
31
+
32
+ def compile_task_without_compiler
33
+ @compile_task ||= define('foo').compile
34
+ end
35
+
36
+ def file_task
37
+ @file_taks ||= define('bar').file('src')
38
+ end
39
+
40
+ def sources
41
+ @sources ||= %w[Test1.java Test2.java].map { |f| File.join('src/main/java/thepackage', f) }.
42
+ each { |src| write src, "package thepackage; class #{src.pathmap('%n')} {}" }
43
+ end
44
+
45
+ def jars
46
+ @jars ||= begin
47
+ write 'jars/src/main/java/Dependency.java', 'class Dependency { }'
48
+ define 'jars', :version=>'1.0', :base_dir => 'jars' do
49
+ package(:jar, :id=>'jar1')
50
+ package(:jar, :id=>'jar2')
51
+ end
52
+ project('jars').packages.map(&:to_s)
53
+ end
54
+ end
55
+ end
56
+
57
+
58
+ describe Buildr::CompileTask do
59
+ include CompilerHelper
60
+
61
+ it 'should respond to from() and return self' do
62
+ compile_task.from(sources).should be(compile_task)
63
+ end
64
+
65
+ it 'should respond to from() with FileTask having no compiler set and return self' do
66
+ compile_task_without_compiler.from(file_task).should be(compile_task)
67
+ end
68
+
69
+ it 'should respond to from() and add sources' do
70
+ compile_task.from sources, File.dirname(sources.first)
71
+ compile_task.sources.should == sources + [File.dirname(sources.first)]
72
+ end
73
+
74
+ it 'should respond to with() and return self' do
75
+ compile_task.with('test.jar').should be(compile_task)
76
+ end
77
+
78
+ it 'should respond to with() and add dependencies' do
79
+ jars = (1..3).map { |i| "test#{i}.jar" }
80
+ compile_task.with *jars
81
+ compile_task.dependencies.should == artifacts(jars)
82
+ end
83
+
84
+ it 'should respond to into() and return self' do
85
+ compile_task.into('code').should be(compile_task)
86
+ end
87
+
88
+ it 'should respond to into() and create file task' do
89
+ compile_task.from(sources).into('code')
90
+ lambda { file('code').invoke }.should run_task('foo:compile')
91
+ end
92
+
93
+ it 'should respond to using() and return self' do
94
+ compile_task.using(:source=>'1.4').should eql(compile_task)
95
+ end
96
+
97
+ it 'should respond to using() and set options' do
98
+ compile_task.using(:source=>'1.4', 'target'=>'1.5')
99
+ compile_task.options.source.should eql('1.4')
100
+ compile_task.options.target.should eql('1.5')
101
+ end
102
+
103
+ it 'should attempt to identify compiler' do
104
+ Compiler.compilers.first.should_receive(:applies_to?).at_least(:once)
105
+ define('foo')
106
+ end
107
+
108
+ it 'should only support existing compilers' do
109
+ lambda { define('foo') { compile.using(:unknown) } }.should raise_error(ArgumentError, /unknown compiler/i)
110
+ end
111
+ end
112
+
113
+ describe Buildr::CompileTask, '#compiler' do
114
+ it 'should be nil if no compiler identifier' do
115
+ define('foo').compile.compiler.should be_nil
116
+ end
117
+
118
+ it 'should return the selected compiler' do
119
+ define('foo') { compile.using(:javac) }
120
+ project('foo').compile.compiler.should eql(:javac)
121
+ end
122
+
123
+ it 'should attempt to identify compiler if sources are specified' do
124
+ define 'foo' do
125
+ Compiler.compilers.first.should_receive(:applies_to?).at_least(:once)
126
+ compile.from('sources').compiler
127
+ end
128
+ end
129
+
130
+ it 'should allow suppressing compilation' do
131
+ write 'src/main/java/package/Test.java', 'class Test {}'
132
+ define 'foo' do
133
+ compile.sources.clear
134
+ end
135
+ project('foo').compile.invoke
136
+ Dir['target/classes/*'].should be_empty
137
+ end
138
+ end
139
+
140
+
141
+ describe Buildr::CompileTask, '#language' do
142
+ it 'should be nil if no compiler identifier' do
143
+ define('foo').compile.language.should be_nil
144
+ end
145
+
146
+ it 'should return the appropriate language' do
147
+ define('foo') { compile.using(:javac) }
148
+ project('foo').compile.language.should eql(:java)
149
+ end
150
+ end
151
+
152
+
153
+ describe Buildr::CompileTask, '#sources' do
154
+ include CompilerHelper
155
+
156
+ it 'should be empty if no sources in default directory' do
157
+ compile_task.sources.should be_empty
158
+ end
159
+
160
+ it 'should point to default directory if it contains sources' do
161
+ write 'src/main/java', ''
162
+ compile_task.sources.first.should point_to_path('src/main/java')
163
+ end
164
+
165
+ it 'should be an array' do
166
+ compile_task.sources += sources
167
+ compile_task.sources.should == sources
168
+ end
169
+
170
+ it 'should allow files' do
171
+ compile_task.from(sources).into('classes').invoke
172
+ sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
173
+ end
174
+
175
+ it 'should allow directories' do
176
+ compile_task.from(File.dirname(sources.first)).into('classes').invoke
177
+ sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
178
+ end
179
+
180
+ it 'should allow tasks' do
181
+ lambda { compile_task.from(file(sources.first)).into('classes').invoke }.should run_task('foo:compile')
182
+ end
183
+
184
+ it 'should act as prerequisites' do
185
+ file('src2') { |task| task('prereq').invoke ; mkpath task.name }
186
+ lambda { compile_task.from('src2').into('classes').invoke }.should run_task('prereq')
187
+ end
188
+ end
189
+
190
+
191
+ describe Buildr::CompileTask, '#dependencies' do
192
+ include CompilerHelper
193
+
194
+ it 'should be empty' do
195
+ compile_task.dependencies.should be_empty
196
+ end
197
+
198
+ it 'should be an array' do
199
+ compile_task.dependencies += jars
200
+ compile_task.dependencies.should == jars
201
+ end
202
+
203
+ it 'should allow files' do
204
+ compile_task.from(sources).with(jars).into('classes').invoke
205
+ sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
206
+ end
207
+
208
+ it 'should allow tasks' do
209
+ compile_task.from(sources).with(file(jars.first)).into('classes').invoke
210
+ end
211
+
212
+ it 'should allow artifacts' do
213
+ artifact('group:id:jar:1.0') { |task| mkpath File.dirname(task.to_s) ; cp jars.first.to_s, task.to_s }.enhance jars
214
+ compile_task.from(sources).with('group:id:jar:1.0').into('classes').invoke
215
+ end
216
+
217
+ it 'should allow projects' do
218
+ define('bar', :version=>'1', :group=>'self') { package :jar }
219
+ compile_task.with project('bar')
220
+ compile_task.dependencies.should == project('bar').packages
221
+ end
222
+
223
+ end
224
+
225
+
226
+ describe Buildr::CompileTask, '#target' do
227
+ include CompilerHelper
228
+
229
+ it 'should be a file task' do
230
+ compile_task.from(@sources).into('classes')
231
+ compile_task.target.should be_kind_of(Rake::FileTask)
232
+ end
233
+
234
+ it 'should accept a task' do
235
+ task = file('classes')
236
+ compile_task.into(task).target.should be(task)
237
+ end
238
+
239
+ it 'should create dependency in file task when set' do
240
+ compile_task.from(sources).into('classes')
241
+ lambda { file('classes').invoke }.should run_task('foo:compile')
242
+ end
243
+ end
244
+
245
+
246
+ describe Buildr::CompileTask, '#options' do
247
+ include CompilerHelper
248
+
249
+ it 'should have getter and setter methods' do
250
+ compile_task.options.foo = 'bar'
251
+ compile_task.options.foo.should eql('bar')
252
+ end
253
+
254
+ it 'should have bracket accessors' do
255
+ compile_task.options[:foo] = 'bar'
256
+ compile_task.options[:foo].should eql('bar')
257
+ end
258
+
259
+ it 'should map from bracket accessor to get/set accessor' do
260
+ compile_task.options[:foo] = 'bar'
261
+ compile_task.options.foo.should eql('bar')
262
+ end
263
+
264
+ it 'should be independent of parent' do
265
+ define 'foo' do
266
+ compile.using(:javac, :source=>'1.4')
267
+ define 'bar' do
268
+ compile.using(:javac, :source=>'1.5')
269
+ end
270
+ end
271
+ project('foo').compile.options.source.should eql('1.4')
272
+ project('foo:bar').compile.options.source.should eql('1.5')
273
+ end
274
+ end
275
+
276
+
277
+ describe Buildr::CompileTask, '#invoke' do
278
+ include CompilerHelper
279
+
280
+ it 'should compile into target directory' do
281
+ compile_task.from(sources).into('code').invoke
282
+ Dir['code/thepackage/*.class'].should_not be_empty
283
+ end
284
+
285
+ it 'should compile only once' do
286
+ compile_task.from(sources)
287
+ lambda { compile_task.target.invoke }.should run_task('foo:compile')
288
+ lambda { compile_task.invoke }.should_not run_task('foo:compile')
289
+ end
290
+
291
+ it 'should compile if there are source files to compile' do
292
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
293
+ end
294
+
295
+ it 'should not compile unless there are source files to compile' do
296
+ lambda { compile_task.invoke }.should_not run_task('foo:compile')
297
+ end
298
+
299
+ it 'should require source file or directory to exist' do
300
+ lambda { compile_task.from('empty').into('classes').invoke }.should raise_error(RuntimeError, /Don't know how to build/)
301
+ end
302
+
303
+ it 'should run all source files as prerequisites' do
304
+ mkpath 'src'
305
+ file('src').should_receive :invoke_prerequisites
306
+ compile_task.from('src').invoke
307
+ end
308
+
309
+ it 'should require dependencies to exist' do
310
+ lambda { compile_task.from(sources).with('no-such.jar').into('classes').invoke }.should \
311
+ raise_error(RuntimeError, /Don't know how to build/)
312
+ end
313
+
314
+ it 'should run all dependencies as prerequisites' do
315
+ file(File.expand_path('no-such.jar')) { |task| task('prereq').invoke }
316
+ lambda { compile_task.from(sources).with('no-such.jar').into('classes').invoke }.should run_tasks(%w[prereq foo:compile])
317
+ end
318
+
319
+ it 'should force compilation if no target' do
320
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
321
+ end
322
+
323
+ it 'should force compilation if target empty' do
324
+ time = now_at_fs_resolution
325
+ mkpath compile_task.target.to_s
326
+ File.utime(time - 1, time - 1, compile_task.target.to_s)
327
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
328
+ end
329
+
330
+ it 'should force compilation if sources newer than compiled' do
331
+ # Simulate class files that are older than source files.
332
+ time = now_at_fs_resolution
333
+ sources.each { |src| File.utime(time + 1, time + 1, src) }
334
+ sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
335
+ each { |kls| write kls ; File.utime(time, time, kls) }
336
+ File.utime(time - 1, time - 1, project('foo').compile.target.to_s)
337
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
338
+ end
339
+
340
+ it 'should not force compilation if sources older than compiled' do
341
+ # When everything has the same timestamp, nothing is compiled again.
342
+ time = now_at_fs_resolution
343
+ sources.map { |src| File.utime(time, time, src); src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
344
+ each { |kls| write kls ; File.utime(time, time, kls) }
345
+ lambda { compile_task.from(sources).invoke }.should_not run_task('foo:compile')
346
+ end
347
+
348
+ it 'should not force compilation if dependencies older than compiled' do
349
+ jars; project('jars').task("package").invoke
350
+ time = now_at_fs_resolution
351
+ jars.each { |jar| File.utime(time - 1 , time - 1, jar) }
352
+ sources.map { |src| File.utime(time, time, src); src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
353
+ each { |kls| write kls ; File.utime(time, time, kls) }
354
+ lambda { compile_task.from(sources).with(jars).invoke }.should_not run_task('foo:compile')
355
+ end
356
+
357
+ it 'should force compilation if dependencies newer than compiled' do
358
+ jars; project('jars').task("package").invoke
359
+ # On my machine the times end up the same, so need to push dependencies in the past.
360
+ time = now_at_fs_resolution
361
+ sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
362
+ each { |kls| write kls ; File.utime(time - 1, time - 1, kls) }
363
+ File.utime(time - 1, time - 1, project('foo').compile.target.to_s)
364
+ jars.each { |jar| File.utime(time + 1, time + 1, jar) }
365
+ lambda { compile_task.from(sources).with(jars).invoke }.should run_task('foo:compile')
366
+ end
367
+
368
+ it 'should timestamp target directory if specified' do
369
+ time = now_at_fs_resolution - 10
370
+ mkpath compile_task.target.to_s
371
+ File.utime(time, time, compile_task.target.to_s)
372
+ compile_task.timestamp.should be_within(1).of(time)
373
+ end
374
+
375
+ it 'should touch target if anything compiled' do
376
+ mkpath compile_task.target.to_s
377
+ File.utime(now_at_fs_resolution - 10, now_at_fs_resolution - 10, compile_task.target.to_s)
378
+ compile_task.from(sources).invoke
379
+ File.stat(compile_task.target.to_s).mtime.should be_within(2).of(now_at_fs_resolution)
380
+ end
381
+
382
+ it 'should not touch target if nothing compiled' do
383
+ mkpath compile_task.target.to_s
384
+ File.utime(now_at_fs_resolution - 10, now_at_fs_resolution - 10, compile_task.target.to_s)
385
+ compile_task.invoke
386
+ File.stat(compile_task.target.to_s).mtime.should be_within(2).of(now_at_fs_resolution - 10)
387
+ end
388
+
389
+ it 'should not touch target if failed to compile' do
390
+ mkpath compile_task.target.to_s
391
+ File.utime(now_at_fs_resolution - 10, now_at_fs_resolution - 10, compile_task.target.to_s)
392
+ write 'failed.java', 'not a class'
393
+ suppress_stdout { compile_task.from('failed.java').invoke rescue nil }
394
+ File.stat(compile_task.target.to_s).mtime.should be_within(2).of(now_at_fs_resolution - 10)
395
+ end
396
+
397
+ it 'should complain if source directories and no compiler selected' do
398
+ mkpath 'sources'
399
+ define 'bar' do
400
+ lambda { compile.from('sources').invoke }.should raise_error(RuntimeError, /no compiler selected/i)
401
+ end
402
+ end
403
+
404
+ it 'should not unnecessarily recompile files explicitly added to compile list (BUILDR-611)' do
405
+ mkpath 'src/other'
406
+ write 'src/other/Foo.java', 'package foo; public class Foo {}'
407
+ compile_task.from FileList['src/other/**.java']
408
+ mkpath 'target/classes/foo'
409
+ touch 'target/classes/foo/Foo.class'
410
+ File.utime(now_at_fs_resolution - 10, now_at_fs_resolution - 10, compile_task.target.to_s)
411
+ compile_task.invoke
412
+ File.stat(compile_task.target.to_s).mtime.should be_within(2).of(now_at_fs_resolution - 10)
413
+ end
414
+ end
415
+
416
+
417
+ RSpec.shared_examples 'accessor task' do
418
+ it 'should return a task' do
419
+ define('foo').send(@task_name).should be_kind_of(Rake::Task)
420
+ end
421
+
422
+ it 'should always return the same task' do
423
+ task_name, task = @task_name, nil
424
+ define('foo') { task = self.send(task_name) }
425
+ project('foo').send(task_name).should be(task)
426
+ end
427
+
428
+ it 'should be unique for the project' do
429
+ define('foo') { define 'bar' }
430
+ project('foo').send(@task_name).should_not eql(project('foo:bar').send(@task_name))
431
+ end
432
+
433
+ it 'should be named after the project' do
434
+ define('foo') { define 'bar' }
435
+ project('foo:bar').send(@task_name).name.should eql("foo:bar:#{@task_name}")
436
+ end
437
+ end
438
+
439
+
440
+ describe Project, '#compile' do
441
+ before { @task_name = 'compile' }
442
+ it_should_behave_like 'accessor task'
443
+
444
+ it 'should return a compile task' do
445
+ define('foo').compile.should be_instance_of(CompileTask)
446
+ end
447
+
448
+ it 'should accept sources and add to source list' do
449
+ define('foo') { compile('file1', 'file2') }
450
+ project('foo').compile.sources.should include('file1', 'file2')
451
+ end
452
+
453
+ it 'should accept block and enhance task' do
454
+ write 'src/main/java/Test.java', 'class Test {}'
455
+ action = task('action')
456
+ define('foo') { compile { action.invoke } }
457
+ lambda { project('foo').compile.invoke }.should run_tasks('foo:compile', action)
458
+ end
459
+
460
+ it 'should execute resources task' do
461
+ define 'foo'
462
+ lambda { project('foo').compile.invoke }.should run_task('foo:resources')
463
+ end
464
+
465
+ it 'should be recursive' do
466
+ write 'bar/src/main/java/Test.java', 'class Test {}'
467
+ define('foo') { define 'bar' }
468
+ lambda { project('foo').compile.invoke }.should run_task('foo:bar:compile')
469
+ end
470
+
471
+ it 'should be a local task' do
472
+ write 'bar/src/main/java/Test.java', 'class Test {}'
473
+ define('foo') { define 'bar' }
474
+ lambda do
475
+ in_original_dir project('foo:bar').base_dir do
476
+ task('compile').invoke
477
+ end
478
+ end.should run_task('foo:bar:compile').but_not('foo:compile')
479
+ end
480
+
481
+ it 'should run from build task' do
482
+ write 'bar/src/main/java/Test.java', 'class Test {}'
483
+ define('foo') { define 'bar' }
484
+ lambda { task('build').invoke }.should run_task('foo:bar:compile')
485
+ end
486
+
487
+ it 'should clean after itself' do
488
+ mkpath 'code'
489
+ define('foo') { compile.into('code') }
490
+ lambda { task('clean').invoke }.should change { File.exist?('code') }.to(false)
491
+ end
492
+ end
493
+
494
+
495
+ describe Project, '#resources' do
496
+ before { @task_name = 'resources' }
497
+ it_should_behave_like 'accessor task'
498
+
499
+ it 'should return a resources task' do
500
+ define('foo').resources.should be_instance_of(ResourcesTask)
501
+ end
502
+
503
+ it 'should provide a filter' do
504
+ define('foo').resources.filter.should be_instance_of(Filter)
505
+ end
506
+
507
+ it 'should include src/main/resources as source directory' do
508
+ write 'src/main/resources/test'
509
+ define('foo').resources.sources.first.should point_to_path('src/main/resources')
510
+ end
511
+
512
+ it 'should include src/main/resources directory only if it exists' do
513
+ define('foo').resources.sources.should be_empty
514
+ end
515
+
516
+ it 'should accept prerequisites' do
517
+ tasks = %w[task1 task2].each { |name| task(name) }
518
+ define('foo') { resources 'task1', 'task2' }
519
+ lambda { project('foo').resources.invoke }.should run_tasks('task1', 'task2')
520
+ end
521
+
522
+ it 'should respond to from and add additional sources' do
523
+ write 'src/main/resources/original'
524
+ write 'extra/spicy'
525
+ define('foo') { resources.from 'extra' }
526
+ project('foo').resources.invoke
527
+ FileList['target/resources/*'].sort.should == %w[target/resources/original target/resources/spicy]
528
+ end
529
+
530
+ it 'should pass include pattern to filter' do
531
+ 3.times { |i| write "src/main/resources/test#{i + 1}" }
532
+ define('foo') { resources.include('test2') }
533
+ project('foo').resources.invoke
534
+ FileList['target/resources/*'].should == ['target/resources/test2']
535
+ end
536
+
537
+ it 'should pass exclude pattern to filter' do
538
+ 3.times { |i| write "src/main/resources/test#{i + 1}" }
539
+ define('foo') { resources.exclude('test2') }
540
+ project('foo').resources.invoke
541
+ FileList['target/resources/*'].sort.should == %w[target/resources/test1 target/resources/test3]
542
+ end
543
+
544
+ it 'should accept block and enhance task' do
545
+ action = task('action')
546
+ define('foo') { resources { action.invoke } }
547
+ lambda { project('foo').resources.invoke }.should run_tasks('foo:resources', action)
548
+ end
549
+
550
+ it 'should set target directory to target/resources' do
551
+ write 'src/main/resources/foo'
552
+ define('foo').resources.target.to_s.should point_to_path('target/resources')
553
+ end
554
+
555
+ it 'should use provided target directoy' do
556
+ define('foo') { resources.filter.into('the_resources') }
557
+ project('foo').resources.target.to_s.should point_to_path('the_resources')
558
+ end
559
+
560
+ it 'should create file task for target directory' do
561
+ write 'src/main/resources/foo'
562
+ define 'foo'
563
+ project('foo').file('target/resources').invoke
564
+ file('target/resources/foo').should exist
565
+ end
566
+
567
+ it 'should copy resources to target directory' do
568
+ write 'src/main/resources/foo', 'Foo'
569
+ define('foo').compile.invoke
570
+ file('target/resources/foo').should contain('Foo')
571
+ end
572
+
573
+ it 'should copy new resources to target directory' do
574
+ time = now_at_fs_resolution
575
+ mkdir_p 'target/resources'
576
+ File.utime(time-10, time-10, 'target/resources')
577
+
578
+ write 'src/main/resources/foo', 'Foo'
579
+
580
+ define('foo')
581
+ project('foo').file('target/resources').invoke
582
+ file('target/resources/foo').should exist
583
+ end
584
+
585
+ it 'should copy updated resources to target directory' do
586
+ time = now_at_fs_resolution
587
+ mkdir_p 'target/resources'
588
+ write 'target/resources/foo', 'Foo'
589
+ File.utime(time-10, time-10, 'target/resources')
590
+ File.utime(time-10, time-10, 'target/resources/foo')
591
+
592
+ write 'src/main/resources/foo', 'Foo2'
593
+ define('foo')
594
+ project('foo').file('target/resources').invoke
595
+ file('target/resources/foo').should contain('Foo2')
596
+ end
597
+
598
+ it 'should not create target directory unless there are resources' do
599
+ define('foo').compile.invoke
600
+ file('target/resources').should_not exist
601
+ end
602
+
603
+ it 'should run from target/resources' do
604
+ write 'src/main/resources/test'
605
+ define('foo')
606
+ lambda { project('foo').resources.target.invoke }.should change { File.exist?('target/resources/test') }.to(true)
607
+ end
608
+
609
+ it 'should not be recursive' do
610
+ define('foo') { define 'bar' }
611
+ lambda { project('foo').resources.invoke }.should_not run_task('foo:bar:resources')
612
+ end
613
+
614
+ it 'should use current profile for filtering' do
615
+ write 'profiles.yaml', <<-YAML
616
+ development:
617
+ filter:
618
+ foo: bar
619
+ test:
620
+ filter:
621
+ foo: baz
622
+ YAML
623
+ write 'src/main/resources/foo', '${foo}'
624
+ define('foo').compile.invoke
625
+ file('target/resources/foo').should contain('bar')
626
+ end
627
+
628
+ it 'should use current profile as default for filtering' do
629
+ write 'profiles.yaml', <<-YAML
630
+ development:
631
+ filter:
632
+ foo: bar
633
+ YAML
634
+ write 'src/main/resources/foo', '${foo} ${baz}'
635
+ define('foo') do
636
+ resources.filter.using 'baz' => 'qux'
637
+ end
638
+ project('foo').compile.invoke
639
+ file('target/resources/foo').should contain('bar qux')
640
+ end
641
+
642
+ it 'should allow clearing default filter mapping' do
643
+ write 'profiles.yaml', <<-YAML
644
+ development:
645
+ filter:
646
+ foo: bar
647
+ YAML
648
+ write 'src/main/resources/foo', '${foo} ${baz}'
649
+ define('foo') do
650
+ resources.filter.mapping.clear
651
+ resources.filter.using 'baz' => 'qux'
652
+ end
653
+ project('foo').compile.invoke
654
+ file('target/resources/foo').should contain('${foo} qux')
655
+ end
656
+ end