buildr 1.3.0-java

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 (138) hide show
  1. data/CHANGELOG +780 -0
  2. data/DISCLAIMER +7 -0
  3. data/KEYS +151 -0
  4. data/LICENSE +176 -0
  5. data/NOTICE +31 -0
  6. data/README +173 -0
  7. data/Rakefile +63 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +232 -0
  10. data/addon/buildr/hibernate.rb +142 -0
  11. data/addon/buildr/javacc.rb +85 -0
  12. data/addon/buildr/jdepend.rb +60 -0
  13. data/addon/buildr/jetty.rb +248 -0
  14. data/addon/buildr/nailgun.rb +892 -0
  15. data/addon/buildr/openjpa.rb +90 -0
  16. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  17. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  18. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  19. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  20. data/addon/buildr/xmlbeans.rb +93 -0
  21. data/bin/buildr +21 -0
  22. data/buildr.gemspec +50 -0
  23. data/doc/css/default.css +225 -0
  24. data/doc/css/print.css +95 -0
  25. data/doc/css/syntax.css +43 -0
  26. data/doc/images/apache-incubator-logo.png +0 -0
  27. data/doc/images/buildr-hires.png +0 -0
  28. data/doc/images/buildr.png +0 -0
  29. data/doc/images/note.png +0 -0
  30. data/doc/images/tip.png +0 -0
  31. data/doc/images/zbuildr.tif +0 -0
  32. data/doc/pages/artifacts.textile +317 -0
  33. data/doc/pages/building.textile +501 -0
  34. data/doc/pages/contributing.textile +178 -0
  35. data/doc/pages/download.textile +25 -0
  36. data/doc/pages/extending.textile +229 -0
  37. data/doc/pages/getting_started.textile +337 -0
  38. data/doc/pages/index.textile +63 -0
  39. data/doc/pages/mailing_lists.textile +17 -0
  40. data/doc/pages/more_stuff.textile +367 -0
  41. data/doc/pages/packaging.textile +592 -0
  42. data/doc/pages/projects.textile +449 -0
  43. data/doc/pages/recipes.textile +127 -0
  44. data/doc/pages/settings_profiles.textile +339 -0
  45. data/doc/pages/testing.textile +475 -0
  46. data/doc/pages/troubleshooting.textile +121 -0
  47. data/doc/pages/whats_new.textile +389 -0
  48. data/doc/print.haml +52 -0
  49. data/doc/print.toc.yaml +28 -0
  50. data/doc/scripts/buildr-git.rb +411 -0
  51. data/doc/scripts/install-jruby.sh +44 -0
  52. data/doc/scripts/install-linux.sh +64 -0
  53. data/doc/scripts/install-osx.sh +52 -0
  54. data/doc/site.haml +55 -0
  55. data/doc/site.toc.yaml +44 -0
  56. data/lib/buildr.rb +47 -0
  57. data/lib/buildr/core.rb +27 -0
  58. data/lib/buildr/core/application.rb +373 -0
  59. data/lib/buildr/core/application_cli.rb +134 -0
  60. data/lib/buildr/core/build.rb +262 -0
  61. data/lib/buildr/core/checks.rb +382 -0
  62. data/lib/buildr/core/common.rb +155 -0
  63. data/lib/buildr/core/compile.rb +594 -0
  64. data/lib/buildr/core/environment.rb +120 -0
  65. data/lib/buildr/core/filter.rb +258 -0
  66. data/lib/buildr/core/generate.rb +195 -0
  67. data/lib/buildr/core/help.rb +118 -0
  68. data/lib/buildr/core/progressbar.rb +156 -0
  69. data/lib/buildr/core/project.rb +890 -0
  70. data/lib/buildr/core/test.rb +690 -0
  71. data/lib/buildr/core/transports.rb +486 -0
  72. data/lib/buildr/core/util.rb +235 -0
  73. data/lib/buildr/ide.rb +19 -0
  74. data/lib/buildr/ide/eclipse.rb +181 -0
  75. data/lib/buildr/ide/idea.ipr.template +300 -0
  76. data/lib/buildr/ide/idea.rb +194 -0
  77. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  78. data/lib/buildr/ide/idea7x.rb +210 -0
  79. data/lib/buildr/java.rb +26 -0
  80. data/lib/buildr/java/ant.rb +71 -0
  81. data/lib/buildr/java/bdd_frameworks.rb +267 -0
  82. data/lib/buildr/java/commands.rb +210 -0
  83. data/lib/buildr/java/compilers.rb +432 -0
  84. data/lib/buildr/java/deprecated.rb +141 -0
  85. data/lib/buildr/java/groovyc.rb +137 -0
  86. data/lib/buildr/java/jruby.rb +99 -0
  87. data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
  88. data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
  89. data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
  90. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  91. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
  92. data/lib/buildr/java/packaging.rb +706 -0
  93. data/lib/buildr/java/pom.rb +178 -0
  94. data/lib/buildr/java/rjb.rb +142 -0
  95. data/lib/buildr/java/test_frameworks.rb +290 -0
  96. data/lib/buildr/java/version_requirement.rb +172 -0
  97. data/lib/buildr/packaging.rb +21 -0
  98. data/lib/buildr/packaging/artifact.rb +729 -0
  99. data/lib/buildr/packaging/artifact_namespace.rb +957 -0
  100. data/lib/buildr/packaging/artifact_search.rb +140 -0
  101. data/lib/buildr/packaging/gems.rb +102 -0
  102. data/lib/buildr/packaging/package.rb +233 -0
  103. data/lib/buildr/packaging/tar.rb +104 -0
  104. data/lib/buildr/packaging/zip.rb +719 -0
  105. data/rakelib/apache.rake +126 -0
  106. data/rakelib/changelog.rake +56 -0
  107. data/rakelib/doc.rake +103 -0
  108. data/rakelib/package.rake +44 -0
  109. data/rakelib/release.rake +53 -0
  110. data/rakelib/rspec.rake +81 -0
  111. data/rakelib/rubyforge.rake +45 -0
  112. data/rakelib/scm.rake +49 -0
  113. data/rakelib/setup.rake +59 -0
  114. data/rakelib/stage.rake +45 -0
  115. data/spec/application_spec.rb +316 -0
  116. data/spec/archive_spec.rb +494 -0
  117. data/spec/artifact_namespace_spec.rb +635 -0
  118. data/spec/artifact_spec.rb +738 -0
  119. data/spec/build_spec.rb +193 -0
  120. data/spec/checks_spec.rb +537 -0
  121. data/spec/common_spec.rb +579 -0
  122. data/spec/compile_spec.rb +561 -0
  123. data/spec/groovy_compilers_spec.rb +239 -0
  124. data/spec/java_bdd_frameworks_spec.rb +238 -0
  125. data/spec/java_compilers_spec.rb +446 -0
  126. data/spec/java_packaging_spec.rb +1042 -0
  127. data/spec/java_test_frameworks_spec.rb +414 -0
  128. data/spec/packaging_helper.rb +63 -0
  129. data/spec/packaging_spec.rb +589 -0
  130. data/spec/project_spec.rb +739 -0
  131. data/spec/sandbox.rb +116 -0
  132. data/spec/scala_compilers_spec.rb +239 -0
  133. data/spec/spec.opts +6 -0
  134. data/spec/spec_helpers.rb +283 -0
  135. data/spec/test_spec.rb +871 -0
  136. data/spec/transport_spec.rb +300 -0
  137. data/spec/version_requirement_spec.rb +115 -0
  138. metadata +324 -0
@@ -0,0 +1,561 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.join(File.dirname(__FILE__), 'spec_helpers')
18
+
19
+
20
+ module CompilerHelper
21
+ def compile_task
22
+ @compile_task ||= define('foo').compile.using(:javac)
23
+ end
24
+
25
+ def sources
26
+ @sources ||= ['Test1.java', 'Test2.java'].map { |f| File.join('src/java', f) }.
27
+ each { |src| write src, "class #{src.pathmap('%n')} {}" }
28
+ end
29
+
30
+ def jars
31
+ @jars ||= begin
32
+ write 'src/main/java/Dependency.java', 'class Dependency { }'
33
+ define 'jars', :version=>'1.0' do
34
+ compile.into('dependency')
35
+ package(:jar, :id=>'jar1')
36
+ package(:jar, :id=>'jar2')
37
+ end
38
+ project('jars').packages.each(&:invoke).map(&:to_s)
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+ describe Buildr::CompileTask do
45
+ include CompilerHelper
46
+
47
+ it 'should respond to from() and return self' do
48
+ compile_task.from(sources).should be(compile_task)
49
+ end
50
+
51
+ it 'should respond to from() and add sources' do
52
+ compile_task.from sources, File.dirname(sources.first)
53
+ compile_task.sources.should == sources + [File.dirname(sources.first)]
54
+ end
55
+
56
+ it 'should respond to with() and return self' do
57
+ compile_task.with('test.jar').should be(compile_task)
58
+ end
59
+
60
+ it 'should respond to with() and add dependencies' do
61
+ jars = (1..3).map { |i| "test#{i}.jar" }
62
+ compile_task.with *jars
63
+ compile_task.dependencies.should == artifacts(jars)
64
+ end
65
+
66
+ it 'should respond to into() and return self' do
67
+ compile_task.into('code').should be(compile_task)
68
+ end
69
+
70
+ it 'should respond to into() and create file task' do
71
+ compile_task.from(sources).into('code')
72
+ lambda { file('code').invoke }.should run_task('foo:compile')
73
+ end
74
+
75
+ it 'should respond to using() and return self' do
76
+ compile_task.using(:source=>'1.4').should eql(compile_task)
77
+ end
78
+
79
+ it 'should respond to using() and set options' do
80
+ compile_task.using(:source=>'1.4', 'target'=>'1.5')
81
+ compile_task.options.source.should eql('1.4')
82
+ compile_task.options.target.should eql('1.5')
83
+ end
84
+
85
+ it 'should attempt to identify compiler' do
86
+ Compiler.compilers.first.should_receive(:applies_to?).at_least(:once)
87
+ define('foo')
88
+ end
89
+
90
+ it 'should only support existing compilers' do
91
+ lambda { define('foo') { compile.using(:unknown) } }.should raise_error(ArgumentError, /unknown compiler/i)
92
+ end
93
+
94
+ it 'should only allow setting the compiler once' do
95
+ lambda { define('foo') { compile.using(:javac).using(:scalac) } }.should raise_error(RuntimeError, /already selected/i)
96
+ end
97
+ end
98
+
99
+
100
+ describe Buildr::CompileTask, '#compiler' do
101
+ it 'should be nil if no compiler identifier' do
102
+ define('foo').compile.compiler.should be_nil
103
+ end
104
+
105
+ it 'should return the selected compiler' do
106
+ define('foo') { compile.using(:javac) }
107
+ project('foo').compile.compiler.should eql(:javac)
108
+ end
109
+
110
+ it 'should attempt to identify compiler if sources are specified' do
111
+ define 'foo' do
112
+ Compiler.compilers.first.should_receive(:applies_to?).at_least(:once)
113
+ compile.from('sources').compiler
114
+ end
115
+ end
116
+ end
117
+
118
+
119
+ describe Buildr::CompileTask, '#language' do
120
+ it 'should be nil if no compiler identifier' do
121
+ define('foo').compile.language.should be_nil
122
+ end
123
+
124
+ it 'should return the appropriate language' do
125
+ define('foo') { compile.using(:javac) }
126
+ project('foo').compile.language.should eql(:java)
127
+ end
128
+ end
129
+
130
+
131
+ describe Buildr::CompileTask, '#sources' do
132
+ include CompilerHelper
133
+
134
+ it 'should be empty if no sources in default directory' do
135
+ compile_task.sources.should be_empty
136
+ end
137
+
138
+ it 'should point to default directory if it contains sources' do
139
+ write 'src/main/java', ''
140
+ compile_task.sources.first.should point_to_path('src/main/java')
141
+ end
142
+
143
+ it 'should be an array' do
144
+ compile_task.sources += sources
145
+ compile_task.sources.should == sources
146
+ end
147
+
148
+ it 'should allow files' do
149
+ compile_task.from(sources).into('classes').invoke
150
+ sources.each { |src| file(src.pathmap('classes/%n.class')).should exist }
151
+ end
152
+
153
+ it 'should allow directories' do
154
+ compile_task.from(File.dirname(sources.first)).into('classes').invoke
155
+ sources.each { |src| file(src.pathmap('classes/%n.class')).should exist }
156
+ end
157
+
158
+ it 'should allow tasks' do
159
+ lambda { compile_task.from(file(sources.first)).into('classes').invoke }.should run_task('foo:compile')
160
+ end
161
+
162
+ it 'should act as prerequisites' do
163
+ file('src2') { |task| task('prereq').invoke ; mkpath task.name }
164
+ lambda { compile_task.from('src2').into('classes').invoke }.should run_task('prereq')
165
+ end
166
+ end
167
+
168
+
169
+ describe Buildr::CompileTask, '#dependencies' do
170
+ include CompilerHelper
171
+
172
+ it 'should be empty' do
173
+ compile_task.dependencies.should be_empty
174
+ end
175
+
176
+ it 'should be an array' do
177
+ compile_task.dependencies += jars
178
+ compile_task.dependencies.should == jars
179
+ end
180
+
181
+ it 'should allow files' do
182
+ compile_task.from(sources).with(jars).into('classes').invoke
183
+ sources.each { |src| file(src.pathmap('classes/%n.class')).should exist }
184
+ end
185
+
186
+ it 'should allow tasks' do
187
+ compile_task.from(sources).with(file(jars.first)).into('classes').invoke
188
+ end
189
+
190
+ it 'should allow artifacts' do
191
+ artifact('group:id:jar:1.0') { |task| mkpath File.dirname(task.to_s) ; cp jars.first.to_s, task.to_s }
192
+ compile_task.from(sources).with('group:id:jar:1.0').into('classes').invoke
193
+ end
194
+
195
+ it 'should allow projects' do
196
+ define('bar', :version=>'1', :group=>'self') { package :jar }
197
+ compile_task.with project('bar')
198
+ compile_task.dependencies.should == project('bar').packages
199
+ end
200
+
201
+ it 'should be accessible as classpath' do
202
+ lambda { compile_task.classpath = jars }.should change(compile_task, :dependencies).to(jars)
203
+ lambda { compile_task.dependencies = [] }.should change(compile_task, :classpath).to([])
204
+ end
205
+
206
+ end
207
+
208
+
209
+ describe Buildr::CompileTask, '#target' do
210
+ include CompilerHelper
211
+
212
+ it 'should be a file task' do
213
+ compile_task.from(@sources).into('classes')
214
+ compile_task.target.should be_kind_of(Rake::FileTask)
215
+ end
216
+
217
+ it 'should accept a task' do
218
+ task = file('classes')
219
+ compile_task.into(task).target.should be(task)
220
+ end
221
+
222
+ it 'should create dependency in file task when set' do
223
+ compile_task.from(sources).into('classes')
224
+ lambda { file('classes').invoke }.should run_task('foo:compile')
225
+ end
226
+ end
227
+
228
+
229
+ describe Buildr::CompileTask, '#options' do
230
+ include CompilerHelper
231
+
232
+ it 'should have getter and setter methods' do
233
+ compile_task.options.foo = 'bar'
234
+ compile_task.options.foo.should eql('bar')
235
+ end
236
+
237
+ it 'should have bracket accessors' do
238
+ compile_task.options[:foo] = 'bar'
239
+ compile_task.options[:foo].should eql('bar')
240
+ end
241
+
242
+ it 'should map from bracket accessor to get/set accessor' do
243
+ compile_task.options[:foo] = 'bar'
244
+ compile_task.options.foo.should eql('bar')
245
+ end
246
+
247
+ it 'should be independent of parent' do
248
+ define 'foo' do
249
+ compile.using(:javac, :source=>'1.4')
250
+ define 'bar' do
251
+ compile.using(:javac, :source=>'1.5')
252
+ end
253
+ end
254
+ project('foo').compile.options.source.should eql('1.4')
255
+ project('foo:bar').compile.options.source.should eql('1.5')
256
+ end
257
+ end
258
+
259
+
260
+ describe Buildr::CompileTask, '#invoke' do
261
+ include CompilerHelper
262
+
263
+ it 'should compile into target directory' do
264
+ compile_task.from(sources).into('code').invoke
265
+ Dir['code/*.class'].should_not be_empty
266
+ end
267
+
268
+ it 'should compile only once' do
269
+ compile_task.from(sources)
270
+ lambda { compile_task.target.invoke }.should run_task('foo:compile')
271
+ lambda { compile_task.invoke }.should_not run_task('foo:compile')
272
+ end
273
+
274
+ it 'should compile if there are source files to compile' do
275
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
276
+ end
277
+
278
+ it 'should not compile unless there are source files to compile' do
279
+ lambda { compile_task.invoke }.should_not run_task('foo:compile')
280
+ end
281
+
282
+ it 'should require source file or directory to exist' do
283
+ lambda { compile_task.from('empty').into('classes').invoke }.should raise_error(RuntimeError, /Don't know how to build/)
284
+ end
285
+
286
+ it 'should run all source files as prerequisites' do
287
+ file(mkpath('src')).should_receive :invoke_prerequisites
288
+ compile_task.from('src').invoke
289
+ end
290
+
291
+ it 'should require dependencies to exist' do
292
+ lambda { compile_task.from(sources).with('no-such.jar').into('classes').invoke }.should \
293
+ raise_error(RuntimeError, /Don't know how to build/)
294
+ end
295
+
296
+ it 'should run all dependencies as prerequisites' do
297
+ file(File.expand_path('no-such.jar')) { |task| task('prereq').invoke }
298
+ lambda { compile_task.from(sources).with('no-such.jar').into('classes').invoke }.should run_tasks(['prereq', 'foo:compile'])
299
+ end
300
+
301
+ it 'should force compilation if no target' do
302
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
303
+ end
304
+
305
+ it 'should force compilation if target empty' do
306
+ mkpath compile_task.target.to_s
307
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
308
+ end
309
+
310
+ it 'should force compilation if sources newer than compiled' do
311
+ # Simulate class files that are older than source files.
312
+ time = Time.now
313
+ sources.each { |src| File.utime(time + 1, time + 1, src) }
314
+ sources.map { |src| src.pathmap("#{compile_task.target}/%n.class") }.
315
+ each { |kls| write kls ; File.utime(time, time, kls) }
316
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
317
+ end
318
+
319
+ it 'should not force compilation if sources older than compiled' do
320
+ # When everything has the same timestamp, nothing is compiled again.
321
+ time = Time.now
322
+ sources.map { |src| src.pathmap("#{compile_task.target}/%n.class") }.
323
+ each { |kls| write kls ; File.utime(time, time, kls) }
324
+ lambda { compile_task.from(sources).invoke }.should_not run_task('foo:compile')
325
+ end
326
+
327
+ it 'should force compilation if dependencies newer than compiled' do
328
+ # On my machine the times end up the same, so need to push dependencies in the past.
329
+ time = Time.now
330
+ sources.map { |src| src.pathmap("#{compile_task.target}/%n.class") }.
331
+ each { |kls| write kls ; File.utime(time, time, kls) }
332
+ jars.each { |jar| File.utime(time + 1, time + 1, jar) }
333
+ lambda { compile_task.from(sources).with(jars).invoke }.should run_task('foo:compile')
334
+ end
335
+
336
+ it 'should not force compilation if dependencies older than compiled' do
337
+ time = Time.now
338
+ sources.map { |src| src.pathmap("#{compile_task.target}/%n.class") }.
339
+ each { |kls| write kls ; File.utime(time, time, kls) }
340
+ jars.each { |jar| File.utime(time - 1, time - 1, jar) }
341
+ lambda { compile_task.from(sources).with(jars).invoke }.should_not run_task('foo:compile')
342
+ end
343
+
344
+ it 'should timestamp target directory if specified' do
345
+ time = Time.now - 10
346
+ mkpath compile_task.target.to_s
347
+ File.utime(time, time, compile_task.target.to_s)
348
+ compile_task.timestamp.should be_close(time, 1)
349
+ end
350
+
351
+ it 'should touch target if anything compiled' do
352
+ mkpath compile_task.target.to_s
353
+ File.utime(Time.now - 10, Time.now - 10, compile_task.target.to_s)
354
+ compile_task.from(sources).invoke
355
+ File.stat(compile_task.target.to_s).mtime.should be_close(Time.now, 2)
356
+ end
357
+
358
+ it 'should not touch target if nothing compiled' do
359
+ mkpath compile_task.target.to_s
360
+ File.utime(Time.now - 10, Time.now - 10, compile_task.target.to_s)
361
+ compile_task.invoke
362
+ File.stat(compile_task.target.to_s).mtime.should be_close(Time.now - 10, 2)
363
+ end
364
+
365
+ it 'should not touch target if failed to compile' do
366
+ mkpath compile_task.target.to_s
367
+ File.utime(Time.now - 10, Time.now - 10, compile_task.target.to_s)
368
+ write 'failed.java', 'not a class'
369
+ suppress_stdout { compile_task.from('failed.java').invoke rescue nil }
370
+ File.stat(compile_task.target.to_s).mtime.should be_close(Time.now - 10, 2)
371
+ end
372
+
373
+ it 'should complain if source directories and no compiler selected' do
374
+ mkpath 'sources'
375
+ define 'bar' do
376
+ lambda { compile.from('sources').invoke }.should raise_error(RuntimeError, /no compiler selected/i)
377
+ end
378
+ end
379
+ end
380
+
381
+
382
+ describe 'accessor task', :shared=>true do
383
+ it 'should return a task' do
384
+ define('foo').send(@task_name).should be_kind_of(Rake::Task)
385
+ end
386
+
387
+ it 'should always return the same task' do
388
+ task_name, task = @task_name, nil
389
+ define('foo') { task = self.send(task_name) }
390
+ project('foo').send(task_name).should be(task)
391
+ end
392
+
393
+ it 'should be unique for the project' do
394
+ define('foo') { define 'bar' }
395
+ project('foo').send(@task_name).should_not eql(project('foo:bar').send(@task_name))
396
+ end
397
+
398
+ it 'should be named after the project' do
399
+ define('foo') { define 'bar' }
400
+ project('foo:bar').send(@task_name).name.should eql("foo:bar:#{@task_name}")
401
+ end
402
+ end
403
+
404
+
405
+ describe Project, '#compile' do
406
+ before { @task_name = 'compile' }
407
+ it_should_behave_like 'accessor task'
408
+
409
+ it 'should return a compile task' do
410
+ define('foo').compile.should be_instance_of(CompileTask)
411
+ end
412
+
413
+ it 'should accept sources and add to source list' do
414
+ define('foo') { compile('file1', 'file2') }
415
+ project('foo').compile.sources.should include('file1', 'file2')
416
+ end
417
+
418
+ it 'should accept block and enhance task' do
419
+ write 'src/main/java/Test.java', 'class Test {}'
420
+ action = task('action')
421
+ define('foo') { compile { action.invoke } }
422
+ lambda { project('foo').compile.invoke }.should run_tasks('foo:compile', action)
423
+ end
424
+
425
+ it 'should execute resources task' do
426
+ define 'foo'
427
+ lambda { project('foo').compile.invoke }.should run_task('foo:resources')
428
+ end
429
+
430
+ it 'should be recursive' do
431
+ write 'bar/src/main/java/Test.java', 'class Test {}'
432
+ define('foo') { define 'bar' }
433
+ lambda { project('foo').compile.invoke }.should run_task('foo:bar:compile')
434
+ end
435
+
436
+ it 'sould be a local task' do
437
+ write 'bar/src/main/java/Test.java', 'class Test {}'
438
+ define('foo') { define 'bar' }
439
+ lambda do
440
+ in_original_dir project('foo:bar').base_dir do
441
+ task('compile').invoke
442
+ end
443
+ end.should run_task('foo:bar:compile').but_not('foo:compile')
444
+ end
445
+
446
+ it 'should run from build task' do
447
+ write 'bar/src/main/java/Test.java', 'class Test {}'
448
+ define('foo') { define 'bar' }
449
+ lambda { task('build').invoke }.should run_task('foo:bar:compile')
450
+ end
451
+
452
+ it 'should clean after itself' do
453
+ mkpath 'code'
454
+ define('foo') { compile.into('code') }
455
+ lambda { task('clean').invoke }.should change { File.exist?('code') }.to(false)
456
+ end
457
+ end
458
+
459
+
460
+ describe Project, '#resources' do
461
+ before { @task_name = 'resources' }
462
+ it_should_behave_like 'accessor task'
463
+
464
+ it 'should return a resources task' do
465
+ define('foo').resources.should be_instance_of(ResourcesTask)
466
+ end
467
+
468
+ it 'should provide a filter' do
469
+ define('foo').resources.filter.should be_instance_of(Filter)
470
+ end
471
+
472
+ it 'should include src/main/resources as source directory' do
473
+ write 'src/main/resources/test'
474
+ define('foo').resources.sources.first.should point_to_path('src/main/resources')
475
+ end
476
+
477
+ it 'should include src/main/resources directory only if it exists' do
478
+ define('foo').resources.sources.should be_empty
479
+ end
480
+
481
+ it 'should accept prerequisites' do
482
+ tasks = ['task1', 'task2'].each { |name| task(name) }
483
+ define('foo') { resources 'task1', 'task2' }
484
+ lambda { project('foo').resources.invoke }.should run_tasks('task1', 'task2')
485
+ end
486
+
487
+ it 'should respond to from and add additional sources' do
488
+ write 'src/main/resources/original'
489
+ write 'extra/spicy'
490
+ define('foo') { resources.from 'extra' }
491
+ project('foo').resources.invoke
492
+ FileList['target/resources/*'].sort.should == ['target/resources/original', 'target/resources/spicy']
493
+ end
494
+
495
+ it 'should pass include pattern to filter' do
496
+ 3.times { |i| write "src/main/resources/test#{i + 1}" }
497
+ define('foo') { resources.include('test2') }
498
+ project('foo').resources.invoke
499
+ FileList['target/resources/*'].should == ['target/resources/test2']
500
+ end
501
+
502
+ it 'should pass exclude pattern to filter' do
503
+ 3.times { |i| write "src/main/resources/test#{i + 1}" }
504
+ define('foo') { resources.exclude('test2') }
505
+ project('foo').resources.invoke
506
+ FileList['target/resources/*'].sort.should == ['target/resources/test1', 'target/resources/test3']
507
+ end
508
+
509
+ it 'should accept block and enhance task' do
510
+ action = task('action')
511
+ define('foo') { resources { action.invoke } }
512
+ lambda { project('foo').resources.invoke }.should run_tasks('foo:resources', action)
513
+ end
514
+
515
+ it 'should set target directory to target/resources' do
516
+ write 'src/main/resources/foo'
517
+ define('foo').resources.target.to_s.should point_to_path('target/resources')
518
+ end
519
+
520
+ it 'should use provided target directoy' do
521
+ define('foo') { resources.filter.into('the_resources') }
522
+ project('foo').resources.target.to_s.should point_to_path('the_resources')
523
+ end
524
+
525
+ it 'should create file task for target directory' do
526
+ write 'src/main/resources/foo'
527
+ define 'foo'
528
+ project('foo').file('target/resources').invoke
529
+ file('target/resources/foo').should exist
530
+ end
531
+
532
+ it 'should copy resources to target directory' do
533
+ write 'src/main/resources/foo', 'Foo'
534
+ define('foo').compile.invoke
535
+ file('target/resources/foo').should contain('Foo')
536
+ end
537
+
538
+ it 'should not create target directory unless there are resources' do
539
+ define('foo').compile.invoke
540
+ file('target/resources').should_not exist
541
+ end
542
+
543
+ it 'should not be recursive' do
544
+ define('foo') { define 'bar' }
545
+ lambda { project('foo').resources.invoke }.should_not run_task('foo:bar:resources')
546
+ end
547
+
548
+ it 'should use current profile for filtering' do
549
+ write 'profiles.yaml', <<-YAML
550
+ development:
551
+ filter:
552
+ foo: bar
553
+ test:
554
+ filter:
555
+ foo: baz
556
+ YAML
557
+ write 'src/main/resources/foo', '${foo}'
558
+ define('foo').compile.invoke
559
+ file('target/resources/foo').should contain('bar')
560
+ end
561
+ end