novoda-buildr 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/CHANGELOG +1050 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +245 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +90 -0
  40. data/doc/extending.textile +205 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +265 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +429 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +276 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +287 -0
  68. data/doc/testing.textile +233 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +662 -0
  73. data/lib/buildr/core/build.rb +463 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +363 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +971 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +774 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +424 -0
  94. data/lib/buildr/ide/eclipse.rb~ +424 -0
  95. data/lib/buildr/ide/eclipse/java.rb +53 -0
  96. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  97. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  98. data/lib/buildr/ide/idea.ipr.template +300 -0
  99. data/lib/buildr/ide/idea.rb +190 -0
  100. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  101. data/lib/buildr/ide/idea7x.rb +212 -0
  102. data/lib/buildr/java.rb +23 -0
  103. data/lib/buildr/java/ant.rb +94 -0
  104. data/lib/buildr/java/bdd.rb +464 -0
  105. data/lib/buildr/java/cobertura.rb +274 -0
  106. data/lib/buildr/java/commands.rb +217 -0
  107. data/lib/buildr/java/compiler.rb +349 -0
  108. data/lib/buildr/java/deprecated.rb +141 -0
  109. data/lib/buildr/java/emma.rb +244 -0
  110. data/lib/buildr/java/jruby.rb +117 -0
  111. data/lib/buildr/java/jtestr_runner.rb.erb +118 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  113. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  114. data/lib/buildr/java/packaging.rb +717 -0
  115. data/lib/buildr/java/pom.rb +174 -0
  116. data/lib/buildr/java/rjb.rb +155 -0
  117. data/lib/buildr/java/test_result.rb +327 -0
  118. data/lib/buildr/java/tests.rb +341 -0
  119. data/lib/buildr/java/version_requirement.rb +172 -0
  120. data/lib/buildr/packaging.rb +24 -0
  121. data/lib/buildr/packaging/archive.rb +491 -0
  122. data/lib/buildr/packaging/artifact.rb +750 -0
  123. data/lib/buildr/packaging/artifact_namespace.rb +980 -0
  124. data/lib/buildr/packaging/artifact_search.rb +140 -0
  125. data/lib/buildr/packaging/gems.rb +106 -0
  126. data/lib/buildr/packaging/package.rb +241 -0
  127. data/lib/buildr/packaging/tar.rb +186 -0
  128. data/lib/buildr/packaging/version_requirement.rb +172 -0
  129. data/lib/buildr/packaging/zip.rb +73 -0
  130. data/lib/buildr/packaging/ziptask.rb +316 -0
  131. data/lib/buildr/resources/buildr.icns +0 -0
  132. data/lib/buildr/scala.rb +25 -0
  133. data/lib/buildr/scala/bdd.rb +114 -0
  134. data/lib/buildr/scala/compiler.rb +196 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  137. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  138. data/lib/buildr/scala/shell.rb +60 -0
  139. data/lib/buildr/scala/tests.rb +157 -0
  140. data/lib/buildr/shell.rb +180 -0
  141. data/rakelib/all-in-one.rake +84 -0
  142. data/rakelib/checks.rake +57 -0
  143. data/rakelib/doc.rake +92 -0
  144. data/rakelib/jekylltask.rb +120 -0
  145. data/rakelib/package.rake +73 -0
  146. data/rakelib/release.rake +152 -0
  147. data/rakelib/rspec.rake +73 -0
  148. data/rakelib/setup.rake +54 -0
  149. data/rakelib/stage.rake +214 -0
  150. data/spec/addon/drb_spec.rb +328 -0
  151. data/spec/core/application_spec.rb +509 -0
  152. data/spec/core/build_spec.rb +678 -0
  153. data/spec/core/checks_spec.rb +519 -0
  154. data/spec/core/common_spec.rb +670 -0
  155. data/spec/core/compile_spec.rb +624 -0
  156. data/spec/core/extension_spec.rb +201 -0
  157. data/spec/core/generate_spec.rb +33 -0
  158. data/spec/core/project_spec.rb +762 -0
  159. data/spec/core/test_spec.rb +1175 -0
  160. data/spec/core/transport_spec.rb +537 -0
  161. data/spec/core/util_spec.rb +67 -0
  162. data/spec/groovy/bdd_spec.rb +80 -0
  163. data/spec/groovy/compiler_spec.rb +240 -0
  164. data/spec/ide/eclipse_spec.rb +650 -0
  165. data/spec/ide/idea7x_spec.rb +84 -0
  166. data/spec/java/ant_spec.rb +33 -0
  167. data/spec/java/bdd_spec.rb +379 -0
  168. data/spec/java/cobertura_spec.rb +85 -0
  169. data/spec/java/compiler_spec.rb +446 -0
  170. data/spec/java/emma_spec.rb +119 -0
  171. data/spec/java/java_spec.rb +124 -0
  172. data/spec/java/packaging_spec.rb +1140 -0
  173. data/spec/java/test_coverage_helper.rb +257 -0
  174. data/spec/java/tests_spec.rb +493 -0
  175. data/spec/packaging/archive_spec.rb +538 -0
  176. data/spec/packaging/artifact_namespace_spec.rb +697 -0
  177. data/spec/packaging/artifact_spec.rb +802 -0
  178. data/spec/packaging/packaging_helper.rb +63 -0
  179. data/spec/packaging/packaging_spec.rb +684 -0
  180. data/spec/sandbox.rb +148 -0
  181. data/spec/scala/bdd_spec.rb +119 -0
  182. data/spec/scala/compiler_spec.rb +284 -0
  183. data/spec/scala/scala.rb +38 -0
  184. data/spec/scala/tests_spec.rb +263 -0
  185. data/spec/spec_helpers.rb +340 -0
  186. data/spec/version_requirement_spec.rb +143 -0
  187. metadata +384 -0
@@ -0,0 +1,624 @@
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 compile_task_without_compiler
26
+ @compile_task ||= define('foo').compile
27
+ end
28
+
29
+ def file_task
30
+ @file_taks ||= define('bar').file('src')
31
+ end
32
+
33
+ def sources
34
+ @sources ||= ['Test1.java', 'Test2.java'].map { |f| File.join('src/main/java/thepackage', f) }.
35
+ each { |src| write src, "package thepackage; class #{src.pathmap('%n')} {}" }
36
+ end
37
+
38
+ def jars
39
+ @jars ||= begin
40
+ write 'jars/src/main/java/Dependency.java', 'class Dependency { }'
41
+ define 'jars', :version=>'1.0', :base_dir => 'jars' do
42
+ package(:jar, :id=>'jar1')
43
+ package(:jar, :id=>'jar2')
44
+ end
45
+ project('jars').packages.map(&:to_s)
46
+ end
47
+ end
48
+ end
49
+
50
+
51
+ describe Buildr::CompileTask do
52
+ include CompilerHelper
53
+
54
+ it 'should respond to from() and return self' do
55
+ compile_task.from(sources).should be(compile_task)
56
+ end
57
+
58
+ it 'should respond to from() with FileTask having no compiler set and return self' do
59
+ compile_task_without_compiler.from(file_task).should be(compile_task)
60
+ end
61
+
62
+ it 'should respond to from() and add sources' do
63
+ compile_task.from sources, File.dirname(sources.first)
64
+ compile_task.sources.should == sources + [File.dirname(sources.first)]
65
+ end
66
+
67
+ it 'should respond to with() and return self' do
68
+ compile_task.with('test.jar').should be(compile_task)
69
+ end
70
+
71
+ it 'should respond to with() and add dependencies' do
72
+ jars = (1..3).map { |i| "test#{i}.jar" }
73
+ compile_task.with *jars
74
+ compile_task.dependencies.should == artifacts(jars)
75
+ end
76
+
77
+ it 'should respond to into() and return self' do
78
+ compile_task.into('code').should be(compile_task)
79
+ end
80
+
81
+ it 'should respond to into() and create file task' do
82
+ compile_task.from(sources).into('code')
83
+ lambda { file('code').invoke }.should run_task('foo:compile')
84
+ end
85
+
86
+ it 'should respond to using() and return self' do
87
+ compile_task.using(:source=>'1.4').should eql(compile_task)
88
+ end
89
+
90
+ it 'should respond to using() and set options' do
91
+ compile_task.using(:source=>'1.4', 'target'=>'1.5')
92
+ compile_task.options.source.should eql('1.4')
93
+ compile_task.options.target.should eql('1.5')
94
+ end
95
+
96
+ it 'should attempt to identify compiler' do
97
+ Compiler.compilers.first.should_receive(:applies_to?).at_least(:once)
98
+ define('foo')
99
+ end
100
+
101
+ it 'should only support existing compilers' do
102
+ lambda { define('foo') { compile.using(:unknown) } }.should raise_error(ArgumentError, /unknown compiler/i)
103
+ end
104
+
105
+ it 'should only allow setting the compiler once' do
106
+ lambda { define('foo') { compile.using(:javac).using(:scalac) } }.should raise_error(RuntimeError, /already selected/i)
107
+ end
108
+ end
109
+
110
+
111
+ describe Buildr::CompileTask, '#compiler' do
112
+ it 'should be nil if no compiler identifier' do
113
+ define('foo').compile.compiler.should be_nil
114
+ end
115
+
116
+ it 'should return the selected compiler' do
117
+ define('foo') { compile.using(:javac) }
118
+ project('foo').compile.compiler.should eql(:javac)
119
+ end
120
+
121
+ it 'should attempt to identify compiler if sources are specified' do
122
+ define 'foo' do
123
+ Compiler.compilers.first.should_receive(:applies_to?).at_least(:once)
124
+ compile.from('sources').compiler
125
+ end
126
+ end
127
+
128
+ it 'should allow supressing compilation' do
129
+ write 'src/main/java/package/Test.java', 'class Test {}'
130
+ define 'foo' do
131
+ compile.sources.clear
132
+ end
133
+ project('foo').compile.invoke
134
+ Dir['target/classes/*'].should be_empty
135
+ end
136
+ end
137
+
138
+
139
+ describe Buildr::CompileTask, '#language' do
140
+ it 'should be nil if no compiler identifier' do
141
+ define('foo').compile.language.should be_nil
142
+ end
143
+
144
+ it 'should return the appropriate language' do
145
+ define('foo') { compile.using(:javac) }
146
+ project('foo').compile.language.should eql(:java)
147
+ end
148
+ end
149
+
150
+
151
+ describe Buildr::CompileTask, '#sources' do
152
+ include CompilerHelper
153
+
154
+ it 'should be empty if no sources in default directory' do
155
+ compile_task.sources.should be_empty
156
+ end
157
+
158
+ it 'should point to default directory if it contains sources' do
159
+ write 'src/main/java', ''
160
+ compile_task.sources.first.should point_to_path('src/main/java')
161
+ end
162
+
163
+ it 'should be an array' do
164
+ compile_task.sources += sources
165
+ compile_task.sources.should == sources
166
+ end
167
+
168
+ it 'should allow files' do
169
+ compile_task.from(sources).into('classes').invoke
170
+ sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
171
+ end
172
+
173
+ it 'should allow directories' do
174
+ compile_task.from(File.dirname(sources.first)).into('classes').invoke
175
+ sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
176
+ end
177
+
178
+ it 'should allow tasks' do
179
+ lambda { compile_task.from(file(sources.first)).into('classes').invoke }.should run_task('foo:compile')
180
+ end
181
+
182
+ it 'should act as prerequisites' do
183
+ file('src2') { |task| task('prereq').invoke ; mkpath task.name }
184
+ lambda { compile_task.from('src2').into('classes').invoke }.should run_task('prereq')
185
+ end
186
+ end
187
+
188
+
189
+ describe Buildr::CompileTask, '#dependencies' do
190
+ include CompilerHelper
191
+
192
+ it 'should be empty' do
193
+ compile_task.dependencies.should be_empty
194
+ end
195
+
196
+ it 'should be an array' do
197
+ compile_task.dependencies += jars
198
+ compile_task.dependencies.should == jars
199
+ end
200
+
201
+ it 'should allow files' do
202
+ compile_task.from(sources).with(jars).into('classes').invoke
203
+ sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
204
+ end
205
+
206
+ it 'should allow tasks' do
207
+ compile_task.from(sources).with(file(jars.first)).into('classes').invoke
208
+ end
209
+
210
+ it 'should allow artifacts' do
211
+ artifact('group:id:jar:1.0') { |task| mkpath File.dirname(task.to_s) ; cp jars.first.to_s, task.to_s }.enhance jars
212
+ compile_task.from(sources).with('group:id:jar:1.0').into('classes').invoke
213
+ end
214
+
215
+ it 'should allow projects' do
216
+ define('bar', :version=>'1', :group=>'self') { package :jar }
217
+ compile_task.with project('bar')
218
+ compile_task.dependencies.should == project('bar').packages
219
+ end
220
+
221
+ it 'should be accessible as classpath up to version 1.5 since it was deprecated in version 1.3' do
222
+ Buildr::VERSION.should < '1.5'
223
+ lambda { compile_task.classpath = jars }.should change(compile_task, :dependencies).to(jars)
224
+ lambda { compile_task.dependencies = [] }.should change(compile_task, :classpath).to([])
225
+ end
226
+
227
+ end
228
+
229
+
230
+ describe Buildr::CompileTask, '#target' do
231
+ include CompilerHelper
232
+
233
+ it 'should be a file task' do
234
+ compile_task.from(@sources).into('classes')
235
+ compile_task.target.should be_kind_of(Rake::FileTask)
236
+ end
237
+
238
+ it 'should accept a task' do
239
+ task = file('classes')
240
+ compile_task.into(task).target.should be(task)
241
+ end
242
+
243
+ it 'should create dependency in file task when set' do
244
+ compile_task.from(sources).into('classes')
245
+ lambda { file('classes').invoke }.should run_task('foo:compile')
246
+ end
247
+ end
248
+
249
+
250
+ describe Buildr::CompileTask, '#options' do
251
+ include CompilerHelper
252
+
253
+ it 'should have getter and setter methods' do
254
+ compile_task.options.foo = 'bar'
255
+ compile_task.options.foo.should eql('bar')
256
+ end
257
+
258
+ it 'should have bracket accessors' do
259
+ compile_task.options[:foo] = 'bar'
260
+ compile_task.options[:foo].should eql('bar')
261
+ end
262
+
263
+ it 'should map from bracket accessor to get/set accessor' do
264
+ compile_task.options[:foo] = 'bar'
265
+ compile_task.options.foo.should eql('bar')
266
+ end
267
+
268
+ it 'should be independent of parent' do
269
+ define 'foo' do
270
+ compile.using(:javac, :source=>'1.4')
271
+ define 'bar' do
272
+ compile.using(:javac, :source=>'1.5')
273
+ end
274
+ end
275
+ project('foo').compile.options.source.should eql('1.4')
276
+ project('foo:bar').compile.options.source.should eql('1.5')
277
+ end
278
+ end
279
+
280
+
281
+ describe Buildr::CompileTask, '#invoke' do
282
+ include CompilerHelper
283
+
284
+ it 'should compile into target directory' do
285
+ compile_task.from(sources).into('code').invoke
286
+ Dir['code/thepackage/*.class'].should_not be_empty
287
+ end
288
+
289
+ it 'should compile only once' do
290
+ compile_task.from(sources)
291
+ lambda { compile_task.target.invoke }.should run_task('foo:compile')
292
+ lambda { compile_task.invoke }.should_not run_task('foo:compile')
293
+ end
294
+
295
+ it 'should compile if there are source files to compile' do
296
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
297
+ end
298
+
299
+ it 'should not compile unless there are source files to compile' do
300
+ lambda { compile_task.invoke }.should_not run_task('foo:compile')
301
+ end
302
+
303
+ it 'should require source file or directory to exist' do
304
+ lambda { compile_task.from('empty').into('classes').invoke }.should raise_error(RuntimeError, /Don't know how to build/)
305
+ end
306
+
307
+ it 'should run all source files as prerequisites' do
308
+ mkpath 'src'
309
+ file('src').should_receive :invoke_prerequisites
310
+ compile_task.from('src').invoke
311
+ end
312
+
313
+ it 'should require dependencies to exist' do
314
+ lambda { compile_task.from(sources).with('no-such.jar').into('classes').invoke }.should \
315
+ raise_error(RuntimeError, /Don't know how to build/)
316
+ end
317
+
318
+ it 'should run all dependencies as prerequisites' do
319
+ file(File.expand_path('no-such.jar')) { |task| task('prereq').invoke }
320
+ lambda { compile_task.from(sources).with('no-such.jar').into('classes').invoke }.should run_tasks(['prereq', 'foo:compile'])
321
+ end
322
+
323
+ it 'should force compilation if no target' do
324
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
325
+ end
326
+
327
+ it 'should force compilation if target empty' do
328
+ time = Time.now
329
+ mkpath compile_task.target.to_s
330
+ File.utime(time - 1, time - 1, compile_task.target.to_s)
331
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
332
+ end
333
+
334
+ it 'should force compilation if sources newer than compiled' do
335
+ # Simulate class files that are older than source files.
336
+ time = Time.now
337
+ sources.each { |src| File.utime(time + 1, time + 1, src) }
338
+ sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
339
+ each { |kls| write kls ; File.utime(time, time, kls) }
340
+ File.utime(time - 1, time - 1, project('foo').compile.target.to_s)
341
+ lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
342
+ end
343
+
344
+ it 'should not force compilation if sources older than compiled' do
345
+ # When everything has the same timestamp, nothing is compiled again.
346
+ time = Time.now
347
+ sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
348
+ each { |kls| write kls ; File.utime(time, time, kls) }
349
+ lambda { compile_task.from(sources).invoke }.should_not run_task('foo:compile')
350
+ end
351
+
352
+ it 'should force compilation if dependencies newer than compiled' do
353
+ jars; project('jars').task("package").invoke
354
+ # On my machine the times end up the same, so need to push dependencies in the past.
355
+ time = Time.now
356
+ sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
357
+ each { |kls| write kls ; File.utime(time - 1, time - 1, kls) }
358
+ File.utime(time - 1, time - 1, project('foo').compile.target.to_s)
359
+ jars.each { |jar| File.utime(time + 1, time + 1, jar) }
360
+ lambda { compile_task.from(sources).with(jars).invoke }.should run_task('foo:compile')
361
+ end
362
+
363
+ it 'should not force compilation if dependencies older than compiled' do
364
+ jars; project('jars').task("package").invoke
365
+ time = Time.now
366
+ jars.each { |jar| File.utime(time - 1 , time - 1, jar) }
367
+ sources.map { |src| File.utime(time, time, src); src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
368
+ each { |kls| write kls ; File.utime(time, time, kls) }
369
+ lambda { compile_task.from(sources).with(jars).invoke }.should_not run_task('foo:compile')
370
+ end
371
+
372
+ it 'should timestamp target directory if specified' do
373
+ time = Time.now - 10
374
+ mkpath compile_task.target.to_s
375
+ File.utime(time, time, compile_task.target.to_s)
376
+ compile_task.timestamp.should be_close(time, 1)
377
+ end
378
+
379
+ it 'should touch target if anything compiled' do
380
+ mkpath compile_task.target.to_s
381
+ File.utime(Time.now - 10, Time.now - 10, compile_task.target.to_s)
382
+ compile_task.from(sources).invoke
383
+ File.stat(compile_task.target.to_s).mtime.should be_close(Time.now, 2)
384
+ end
385
+
386
+ it 'should not touch target if nothing compiled' do
387
+ mkpath compile_task.target.to_s
388
+ File.utime(Time.now - 10, Time.now - 10, compile_task.target.to_s)
389
+ compile_task.invoke
390
+ File.stat(compile_task.target.to_s).mtime.should be_close(Time.now - 10, 2)
391
+ end
392
+
393
+ it 'should not touch target if failed to compile' do
394
+ mkpath compile_task.target.to_s
395
+ File.utime(Time.now - 10, Time.now - 10, compile_task.target.to_s)
396
+ write 'failed.java', 'not a class'
397
+ suppress_stdout { compile_task.from('failed.java').invoke rescue nil }
398
+ File.stat(compile_task.target.to_s).mtime.should be_close(Time.now - 10, 2)
399
+ end
400
+
401
+ it 'should complain if source directories and no compiler selected' do
402
+ mkpath 'sources'
403
+ define 'bar' do
404
+ lambda { compile.from('sources').invoke }.should raise_error(RuntimeError, /no compiler selected/i)
405
+ end
406
+ end
407
+ end
408
+
409
+
410
+ describe 'accessor task', :shared=>true do
411
+ it 'should return a task' do
412
+ define('foo').send(@task_name).should be_kind_of(Rake::Task)
413
+ end
414
+
415
+ it 'should always return the same task' do
416
+ task_name, task = @task_name, nil
417
+ define('foo') { task = self.send(task_name) }
418
+ project('foo').send(task_name).should be(task)
419
+ end
420
+
421
+ it 'should be unique for the project' do
422
+ define('foo') { define 'bar' }
423
+ project('foo').send(@task_name).should_not eql(project('foo:bar').send(@task_name))
424
+ end
425
+
426
+ it 'should be named after the project' do
427
+ define('foo') { define 'bar' }
428
+ project('foo:bar').send(@task_name).name.should eql("foo:bar:#{@task_name}")
429
+ end
430
+ end
431
+
432
+
433
+ describe Project, '#compile' do
434
+ before { @task_name = 'compile' }
435
+ it_should_behave_like 'accessor task'
436
+
437
+ it 'should return a compile task' do
438
+ define('foo').compile.should be_instance_of(CompileTask)
439
+ end
440
+
441
+ it 'should accept sources and add to source list' do
442
+ define('foo') { compile('file1', 'file2') }
443
+ project('foo').compile.sources.should include('file1', 'file2')
444
+ end
445
+
446
+ it 'should accept block and enhance task' do
447
+ write 'src/main/java/Test.java', 'class Test {}'
448
+ action = task('action')
449
+ define('foo') { compile { action.invoke } }
450
+ lambda { project('foo').compile.invoke }.should run_tasks('foo:compile', action)
451
+ end
452
+
453
+ it 'should execute resources task' do
454
+ define 'foo'
455
+ lambda { project('foo').compile.invoke }.should run_task('foo:resources')
456
+ end
457
+
458
+ it 'should be recursive' do
459
+ write 'bar/src/main/java/Test.java', 'class Test {}'
460
+ define('foo') { define 'bar' }
461
+ lambda { project('foo').compile.invoke }.should run_task('foo:bar:compile')
462
+ end
463
+
464
+ it 'should be a local task' do
465
+ write 'bar/src/main/java/Test.java', 'class Test {}'
466
+ define('foo') { define 'bar' }
467
+ lambda do
468
+ in_original_dir project('foo:bar').base_dir do
469
+ task('compile').invoke
470
+ end
471
+ end.should run_task('foo:bar:compile').but_not('foo:compile')
472
+ end
473
+
474
+ it 'should run from build task' do
475
+ write 'bar/src/main/java/Test.java', 'class Test {}'
476
+ define('foo') { define 'bar' }
477
+ lambda { task('build').invoke }.should run_task('foo:bar:compile')
478
+ end
479
+
480
+ it 'should clean after itself' do
481
+ mkpath 'code'
482
+ define('foo') { compile.into('code') }
483
+ lambda { task('clean').invoke }.should change { File.exist?('code') }.to(false)
484
+ end
485
+ end
486
+
487
+
488
+ describe Project, '#resources' do
489
+ before { @task_name = 'resources' }
490
+ it_should_behave_like 'accessor task'
491
+
492
+ it 'should return a resources task' do
493
+ define('foo').resources.should be_instance_of(ResourcesTask)
494
+ end
495
+
496
+ it 'should provide a filter' do
497
+ define('foo').resources.filter.should be_instance_of(Filter)
498
+ end
499
+
500
+ it 'should include src/main/resources as source directory' do
501
+ write 'src/main/resources/test'
502
+ define('foo').resources.sources.first.should point_to_path('src/main/resources')
503
+ end
504
+
505
+ it 'should include src/main/resources directory only if it exists' do
506
+ define('foo').resources.sources.should be_empty
507
+ end
508
+
509
+ it 'should accept prerequisites' do
510
+ tasks = ['task1', 'task2'].each { |name| task(name) }
511
+ define('foo') { resources 'task1', 'task2' }
512
+ lambda { project('foo').resources.invoke }.should run_tasks('task1', 'task2')
513
+ end
514
+
515
+ it 'should respond to from and add additional sources' do
516
+ write 'src/main/resources/original'
517
+ write 'extra/spicy'
518
+ define('foo') { resources.from 'extra' }
519
+ project('foo').resources.invoke
520
+ FileList['target/resources/*'].sort.should == ['target/resources/original', 'target/resources/spicy']
521
+ end
522
+
523
+ it 'should pass include pattern to filter' do
524
+ 3.times { |i| write "src/main/resources/test#{i + 1}" }
525
+ define('foo') { resources.include('test2') }
526
+ project('foo').resources.invoke
527
+ FileList['target/resources/*'].should == ['target/resources/test2']
528
+ end
529
+
530
+ it 'should pass exclude pattern to filter' do
531
+ 3.times { |i| write "src/main/resources/test#{i + 1}" }
532
+ define('foo') { resources.exclude('test2') }
533
+ project('foo').resources.invoke
534
+ FileList['target/resources/*'].sort.should == ['target/resources/test1', 'target/resources/test3']
535
+ end
536
+
537
+ it 'should accept block and enhance task' do
538
+ action = task('action')
539
+ define('foo') { resources { action.invoke } }
540
+ lambda { project('foo').resources.invoke }.should run_tasks('foo:resources', action)
541
+ end
542
+
543
+ it 'should set target directory to target/resources' do
544
+ write 'src/main/resources/foo'
545
+ define('foo').resources.target.to_s.should point_to_path('target/resources')
546
+ end
547
+
548
+ it 'should use provided target directoy' do
549
+ define('foo') { resources.filter.into('the_resources') }
550
+ project('foo').resources.target.to_s.should point_to_path('the_resources')
551
+ end
552
+
553
+ it 'should create file task for target directory' do
554
+ write 'src/main/resources/foo'
555
+ define 'foo'
556
+ project('foo').file('target/resources').invoke
557
+ file('target/resources/foo').should exist
558
+ end
559
+
560
+ it 'should copy resources to target directory' do
561
+ write 'src/main/resources/foo', 'Foo'
562
+ define('foo').compile.invoke
563
+ file('target/resources/foo').should contain('Foo')
564
+ end
565
+
566
+ it 'should not create target directory unless there are resources' do
567
+ define('foo').compile.invoke
568
+ file('target/resources').should_not exist
569
+ end
570
+
571
+ it 'should run from target/resources' do
572
+ write 'src/main/resources/test'
573
+ define('foo')
574
+ lambda { project('foo').resources.target.invoke }.should change { File.exist?('target/resources/test') }.to(true)
575
+ end
576
+
577
+ it 'should not be recursive' do
578
+ define('foo') { define 'bar' }
579
+ lambda { project('foo').resources.invoke }.should_not run_task('foo:bar:resources')
580
+ end
581
+
582
+ it 'should use current profile for filtering' do
583
+ write 'profiles.yaml', <<-YAML
584
+ development:
585
+ filter:
586
+ foo: bar
587
+ test:
588
+ filter:
589
+ foo: baz
590
+ YAML
591
+ write 'src/main/resources/foo', '${foo}'
592
+ define('foo').compile.invoke
593
+ file('target/resources/foo').should contain('bar')
594
+ end
595
+
596
+ it 'should use current profile as default for filtering' do
597
+ write 'profiles.yaml', <<-YAML
598
+ development:
599
+ filter:
600
+ foo: bar
601
+ YAML
602
+ write 'src/main/resources/foo', '${foo} ${baz}'
603
+ define('foo') do
604
+ resources.filter.using 'baz' => 'qux'
605
+ end
606
+ project('foo').compile.invoke
607
+ file('target/resources/foo').should contain('bar qux')
608
+ end
609
+
610
+ it 'should allow clearing default filter mapping' do
611
+ write 'profiles.yaml', <<-YAML
612
+ development:
613
+ filter:
614
+ foo: bar
615
+ YAML
616
+ write 'src/main/resources/foo', '${foo} ${baz}'
617
+ define('foo') do
618
+ resources.filter.mapping.clear
619
+ resources.filter.using 'baz' => 'qux'
620
+ end
621
+ project('foo').compile.invoke
622
+ file('target/resources/foo').should contain('${foo} qux')
623
+ end
624
+ end