ittayd-buildr 1.3.4

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