buildr 1.3.0-java

Sign up to get free protection for your applications and to get access to all the features.
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,739 @@
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 Project do
21
+ it 'should be findable' do
22
+ foo = define('foo')
23
+ project('foo').should be(foo)
24
+ end
25
+
26
+ it 'should not exist unless defined' do
27
+ lambda { project('foo') }.should raise_error(RuntimeError, /No such project/)
28
+ end
29
+
30
+ it 'should fail to be defined if its name is already used for a task' do
31
+ lambda { define('test') }.should raise_error(RuntimeError, /Invalid project name/i)
32
+ define 'valid' do
33
+ lambda { define('build') }.should raise_error(RuntimeError, /Invalid project name/i)
34
+ end
35
+ end
36
+
37
+ it 'should exist once defined' do
38
+ define 'foo'
39
+ lambda { project('foo') }.should_not raise_error
40
+ end
41
+
42
+ it 'should always return same project for same name' do
43
+ foo, bar = define('foo'), define('bar')
44
+ foo.should_not be(bar)
45
+ foo.should be(project('foo'))
46
+ bar.should be(project('bar'))
47
+ end
48
+
49
+ it 'should show up in projects list if defined' do
50
+ define('foo')
51
+ projects.map(&:name).should include('foo')
52
+ end
53
+
54
+ it 'should not show up in projects list unless defined' do
55
+ projects.map(&:name).should_not include('foo')
56
+ end
57
+
58
+ it 'should be findable from within a project' do
59
+ define('foo')
60
+ project('foo').project('foo').should be(project('foo'))
61
+ end
62
+
63
+ it 'should cease to exist when project list cleared' do
64
+ define 'foo'
65
+ projects.map(&:name).should include('foo')
66
+ Project.clear
67
+ projects.map(&:name).should be_empty
68
+ end
69
+
70
+ it 'should be defined only once' do
71
+ lambda { define 'foo' }.should_not raise_error
72
+ lambda { define 'foo' }.should raise_error
73
+ end
74
+
75
+ it 'should be definable in any order' do
76
+ Buildr.define('baz') { define('bar') { project('foo:bar') } }
77
+ Buildr.define('foo') { define('bar') }
78
+ lambda { project('foo') }.should_not raise_error
79
+ end
80
+
81
+ it 'should detect circular dependency' do
82
+ Buildr.define('baz') { define('bar') { project('foo:bar') } }
83
+ Buildr.define('foo') { define('bar') { project('baz:bar') } }
84
+ lambda { project('foo') }.should raise_error(RuntimeError, /Circular dependency/)
85
+ end
86
+ end
87
+
88
+ describe Project, ' property' do
89
+ it 'should be set if passed as argument' do
90
+ define 'foo', 'version'=>'1.1'
91
+ project('foo').version.should eql('1.1')
92
+ end
93
+
94
+ it 'should be set if assigned in body' do
95
+ define('foo') { self.version = '1.2' }
96
+ project('foo').version.should eql('1.2')
97
+ end
98
+
99
+ it 'should take precedence when assigned in body' do
100
+ define('foo', 'version'=>'1.1') { self.version = '1.2' }
101
+ project('foo').version.should eql('1.2')
102
+ end
103
+
104
+ it 'should inherit from parent (for some properties)' do
105
+ define('foo', 'version'=>'1.2', :group=>'foobar') { define 'bar' }
106
+ project('foo:bar').version.should eql('1.2')
107
+ project('foo:bar').group.should eql('foobar')
108
+ end
109
+
110
+ it 'should have different value if set in sub-project' do
111
+ define 'foo', 'version'=>'1.2', :group=>'foobar' do
112
+ define 'bar', :version=>'1.3' do
113
+ self.group = 'barbaz'
114
+ end
115
+ end
116
+ project('foo:bar').version.should eql('1.3')
117
+ project('foo:bar').group.should eql('barbaz')
118
+ end
119
+ end
120
+
121
+
122
+ describe Project, ' block' do
123
+ it 'should execute once' do
124
+ define('foo') { self.name.should eql('foo') }
125
+ end
126
+
127
+ it 'should execute in describe of project' do
128
+ define('foo') { self.version = '1.3' }
129
+ project('foo').version.should eql('1.3')
130
+ end
131
+
132
+ it 'should execute by passing project' do
133
+ define('foo') { |project| project.version = '1.3' }
134
+ project('foo').version.should eql('1.3')
135
+ end
136
+
137
+ it 'should execute in namespace of project' do
138
+ define('foo') { define('bar') { Buildr.application.current_scope.should eql(['foo', 'bar']) } }
139
+ end
140
+ end
141
+
142
+
143
+ describe Project, '#base_dir' do
144
+ it 'should be pwd if not specified' do
145
+ define('foo').base_dir.should eql(Dir.pwd)
146
+ end
147
+
148
+ it 'should come from property, if specified' do
149
+ foo = define('foo', :base_dir=>'tmp')
150
+ foo.base_dir.should point_to_path('tmp')
151
+ end
152
+
153
+ it 'should be expanded path' do
154
+ foo = define('foo', :base_dir=>'tmp')
155
+ foo.base_dir.should eql(File.expand_path('tmp'))
156
+ end
157
+
158
+ it 'should be relative to parent project' do
159
+ define('foo') { define('bar') { define 'baz' } }
160
+ project('foo:bar:baz').base_dir.should point_to_path('bar/baz')
161
+ end
162
+
163
+ it 'should be settable only if not read' do
164
+ lambda { define('foo', :base_dir=>'tmp') }.should_not raise_error
165
+ lambda { define('bar', :base_dir=>'tmp') { self.base_dir = 'bar' } }.should raise_error(Exception, /Cannot set/)
166
+ end
167
+ end
168
+
169
+
170
+ describe Layout do
171
+ before :each do
172
+ @layout = Layout.new
173
+ end
174
+
175
+ it 'should expand empty to itself' do
176
+ @layout.expand.should eql('')
177
+ @layout.expand('').should eql('')
178
+ end
179
+
180
+ it 'should expand array of symbols' do
181
+ @layout.expand(:foo, :bar).should eql('foo/bar')
182
+ end
183
+
184
+ it 'should expand array of names' do
185
+ @layout.expand('foo', 'bar').should eql('foo/bar')
186
+ end
187
+
188
+ it 'should map symbol to path' do
189
+ @layout[:foo] = 'baz'
190
+ @layout.expand(:foo, :bar).should eql('baz/bar')
191
+ end
192
+
193
+ it 'should map symbols to path' do
194
+ @layout[:foo, :bar] = 'none'
195
+ @layout.expand(:foo, :bar).should eql('none')
196
+ end
197
+
198
+ it 'should return nil if path not mapped' do
199
+ @layout[:foo].should be_nil
200
+ end
201
+
202
+ it 'should return path from symbol' do
203
+ @layout[:foo] = 'path'
204
+ @layout[:foo].should eql('path')
205
+ end
206
+
207
+ it 'should return path from symbol' do
208
+ @layout[:foo, :bar] = 'path'
209
+ @layout[:foo, :bar].should eql('path')
210
+ end
211
+
212
+ it 'should do eager mapping' do
213
+ @layout[:one] = 'none'
214
+ @layout[:one, :two] = '1..2'
215
+ @layout.expand(:one, :two, :three).should eql('1..2/three')
216
+ end
217
+
218
+ end
219
+
220
+
221
+ describe Project, '#layout' do
222
+ before :each do
223
+ @layout = Layout.new
224
+ end
225
+
226
+ it 'should exist by default' do
227
+ define('foo').layout.should respond_to(:expand)
228
+ end
229
+
230
+ it 'should be clone of default layout' do
231
+ define 'foo' do
232
+ layout.should_not be(Layout.default)
233
+ layout.expand(:test, :main).should eql(Layout.default.expand(:test, :main))
234
+ end
235
+ end
236
+
237
+ it 'should come from property, if specified' do
238
+ foo = define('foo', :layout=>@layout)
239
+ foo.layout.should eql(@layout)
240
+ end
241
+
242
+ it 'should inherit from parent project' do
243
+ define 'foo', :layout=>@layout do
244
+ layout[:foo] = 'foo'
245
+ define 'bar'
246
+ end
247
+ project('foo:bar').layout[:foo].should eql('foo')
248
+ end
249
+
250
+ it 'should clone when inheriting from parent project' do
251
+ define 'foo', :layout=>@layout do
252
+ layout[:foo] = 'foo'
253
+ define 'bar' do
254
+ layout[:foo] = 'bar'
255
+ end
256
+ end
257
+ project('foo').layout[:foo].should eql('foo')
258
+ project('foo:bar').layout[:foo].should eql('bar')
259
+ end
260
+
261
+ it 'should be settable only if not read' do
262
+ lambda { define('foo', :layout=>@layout) }.should_not raise_error
263
+ lambda { define('bar', :layout=>@layout) { self.layout = @layout.clone } }.should raise_error(Exception, /Cannot set/)
264
+ end
265
+
266
+ end
267
+
268
+
269
+ describe Project, '#path_to' do
270
+ it 'should return absolute paths as is' do
271
+ define('foo').path_to('/tmp').should eql(File.expand_path('/tmp'))
272
+ end
273
+
274
+ it 'should resolve empty path to project\'s base directory' do
275
+ define('foo').path_to.should eql(project('foo').base_dir)
276
+ end
277
+
278
+ it 'should resolve relative paths' do
279
+ define('foo').path_to('tmp').should eql(File.expand_path('tmp'))
280
+ end
281
+
282
+ it 'should accept multiple arguments' do
283
+ define('foo').path_to('foo', 'bar').should eql(File.expand_path('foo/bar'))
284
+ end
285
+
286
+ it 'should handle relative paths' do
287
+ define('foo').path_to('..', 'bar').should eql(File.expand_path('../bar'))
288
+ end
289
+
290
+ it 'should resolve symbols using layout' do
291
+ define('foo').layout[:foo] = 'bar'
292
+ project('foo').path_to(:foo).should eql(File.expand_path('bar'))
293
+ project('foo').path_to(:foo, 'tmp').should eql(File.expand_path('bar/tmp'))
294
+ end
295
+
296
+ it 'should resolve path for sub-project' do
297
+ define('foo') { define 'bar' }
298
+ project('foo:bar').path_to('foo').should eql(File.expand_path('foo', project('foo:bar').base_dir))
299
+ end
300
+
301
+ it 'should be idempotent for relative paths' do
302
+ define 'foo'
303
+ path = project('foo').path_to('bar')
304
+ project('foo').path_to(path).should eql(path)
305
+ end
306
+ end
307
+
308
+
309
+ describe Project, '#on_define' do
310
+ it 'should be called when project is defined' do
311
+ names = []
312
+ Project.on_define { |project| names << project.name }
313
+ define 'foo' ; define 'bar'
314
+ names.should eql(['foo', 'bar'])
315
+ end
316
+
317
+ it 'should be called with project object' do
318
+ Project.on_define { |project| project.name.should eql('foo') }
319
+ define('foo')
320
+ end
321
+
322
+ it 'should be called with project object and set properties' do
323
+ Project.on_define { |project| project.version.should eql('2.0') }
324
+ define('foo', :version=>'2.0')
325
+ end
326
+
327
+ it 'should execute in namespace of project' do
328
+ scopes = []
329
+ Project.on_define { |project| scopes << Buildr.application.current_scope }
330
+ define('foo') { define 'bar' }
331
+ scopes.should eql([['foo'], ['foo', 'bar']])
332
+ end
333
+
334
+ it 'should be called before project block' do
335
+ order = []
336
+ Project.on_define { |project| order << 'on_define' }
337
+ define('foo') { order << 'define' }
338
+ order.should eql(['on_define', 'define'])
339
+ end
340
+
341
+ it 'should accept enhancement and call it after project block' do
342
+ order = []
343
+ Project.on_define { |project| project.enhance { order << 'enhance' } }
344
+ define('foo') { order << 'define' }
345
+ order.should eql(['define', 'enhance'])
346
+ end
347
+
348
+ it 'should accept enhancement and call it with project' do
349
+ Project.on_define { |project| project.enhance { |project| project.name.should eql('foo') } }
350
+ define('foo')
351
+ end
352
+
353
+ it 'should execute enhancement in namespace of project' do
354
+ scopes = []
355
+ Project.on_define { |project| project.enhance { scopes << Buildr.application.current_scope } }
356
+ define('foo') { define 'bar' }
357
+ scopes.should eql([['foo'], ['foo', 'bar']])
358
+ end
359
+ end
360
+
361
+
362
+ describe Rake::Task, ' recursive' do
363
+ before do
364
+ @order = []
365
+ Project.on_define do |project|
366
+ project.recursive_task('doda') { @order << project.name }
367
+ end
368
+ define('foo') { define('bar') { define('baz') } }
369
+ end
370
+
371
+ it 'should invoke same task in child project' do
372
+ task('foo:doda').invoke
373
+ @order.should include('foo:bar:baz')
374
+ @order.should include('foo:bar')
375
+ @order.should include('foo')
376
+ end
377
+
378
+ it 'should invoke in depth-first order' do
379
+ task('foo:doda').invoke
380
+ @order.should eql([ 'foo:bar:baz', 'foo:bar', 'foo' ])
381
+ end
382
+
383
+ it 'should not invoke task in parent project' do
384
+ task('foo:bar:baz:doda').invoke
385
+ @order.should eql([ 'foo:bar:baz' ])
386
+ end
387
+ end
388
+
389
+
390
+ describe 'Sub-project' do
391
+ it 'should point at parent project' do
392
+ define('foo') { define 'bar' }
393
+ project('foo:bar').parent.should be(project('foo'))
394
+ end
395
+
396
+ it 'should be defined only within parent project' do
397
+ lambda { define('foo:bar') }.should raise_error
398
+ end
399
+
400
+ it 'should have unique name' do
401
+ lambda do
402
+ define 'foo' do
403
+ define 'bar'
404
+ define 'bar'
405
+ end
406
+ end.should raise_error
407
+ end
408
+
409
+ it 'should be findable from root' do
410
+ define('foo') { define 'bar' }
411
+ projects.map(&:name).should include('foo:bar')
412
+ end
413
+
414
+ it 'should be findable from parent project' do
415
+ define('foo') { define 'bar' }
416
+ project('foo').projects.map(&:name).should include('foo:bar')
417
+ end
418
+
419
+ it 'should be findable only if exists' do
420
+ define('foo') { define 'bar' }
421
+ lambda { project('foo').project('baz') }.should raise_error(RuntimeError, /No such project/)
422
+ end
423
+
424
+ it 'should always execute its definition ' do
425
+ ordered = []
426
+ define 'foo' do
427
+ ordered << self.name
428
+ define('bar') { ordered << self.name }
429
+ define('baz') { ordered << self.name }
430
+ end
431
+ ordered.should eql(['foo', 'foo:bar', 'foo:baz'])
432
+ end
433
+
434
+ it 'should execute in order of dependency' do
435
+ ordered = []
436
+ define 'foo' do
437
+ ordered << self.name
438
+ define('bar') { project('foo:baz') ; ordered << self.name }
439
+ define('baz') { ordered << self.name }
440
+ end
441
+ ordered.should eql(['foo', 'foo:baz', 'foo:bar'])
442
+ end
443
+
444
+ it 'should warn of circular dependency' do
445
+ lambda do
446
+ define 'foo' do
447
+ define('bar') { project('foo:baz') }
448
+ define('baz') { project('foo:bar') }
449
+ end
450
+ end.should raise_error(RuntimeError, /Circular dependency/)
451
+ end
452
+ end
453
+
454
+
455
+ describe 'Top-level project' do
456
+ it 'should have no parent' do
457
+ define('foo')
458
+ project('foo').parent.should be_nil
459
+ end
460
+ end
461
+
462
+
463
+ describe Buildr, '#project' do
464
+ it 'should raise error if no such project' do
465
+ lambda { project('foo') }.should raise_error(RuntimeError, /No such project/)
466
+ end
467
+
468
+ it 'should return a project if exists' do
469
+ foo = define('foo')
470
+ project('foo').should be(foo)
471
+ end
472
+
473
+ it 'should find a project by its full name' do
474
+ bar, baz = nil
475
+ define('foo') { bar = define('bar') { baz = define('baz') } }
476
+ project('foo:bar').should be(bar)
477
+ project('foo:bar:baz').should be(baz)
478
+ end
479
+
480
+ it 'should find a project from any context' do
481
+ bar, baz = nil
482
+ define('foo') { bar = define('bar') { baz = define('baz') } }
483
+ project('foo:bar').project('foo:bar:baz').should be(baz)
484
+ project('foo:bar:baz').project('foo:bar').should be(bar)
485
+ end
486
+
487
+ it 'should find a project from its parent or sibling project' do
488
+ define 'foo' do
489
+ define 'bar'
490
+ define 'baz'
491
+ end
492
+ project('foo').project('bar').should be(project('foo:bar'))
493
+ project('foo').project('baz').should be(project('foo:baz'))
494
+ project('foo:bar').project('baz').should be(project('foo:baz'))
495
+ end
496
+
497
+ it 'should fine a project from its parent by proximity' do
498
+ define 'foo' do
499
+ define('bar') { define 'baz' }
500
+ define 'baz'
501
+ end
502
+ project('foo').project('baz').should be(project('foo:baz'))
503
+ project('foo:bar').project('baz').should be(project('foo:bar:baz'))
504
+ end
505
+
506
+ it 'should invoke project before returning it' do
507
+ define('foo').should_receive(:invoke).once
508
+ project('foo')
509
+ end
510
+
511
+ it 'should fail if called without a project name' do
512
+ lambda { project }.should raise_error(ArgumentError)
513
+ end
514
+
515
+ it 'should return self if called on a project without a name' do
516
+ define('foo') { project.should be(self) }
517
+ end
518
+
519
+ it 'should evaluate parent project before returning' do
520
+ # Note: gets around our define that also invokes the project.
521
+ Buildr.define('foo') { define('bar'); define('baz') }
522
+ project('foo:bar').should eql(projects[1])
523
+ end
524
+ end
525
+
526
+
527
+ describe Buildr, '#projects' do
528
+ it 'should only return defined projects' do
529
+ projects.should eql([])
530
+ define 'foo'
531
+ projects.should eql([project('foo')])
532
+ end
533
+
534
+ it 'should return all defined projects' do
535
+ define 'foo'
536
+ define('bar') { define 'baz' }
537
+ projects.should include(project('foo'))
538
+ projects.should include(project('bar'))
539
+ projects.should include(project('bar:baz'))
540
+ end
541
+
542
+ it 'should return only named projects' do
543
+ define 'foo' ; define 'bar' ; define 'baz'
544
+ projects('foo', 'bar').should include(project('foo'))
545
+ projects('foo', 'bar').should include(project('bar'))
546
+ projects('foo', 'bar').should_not include(project('baz'))
547
+ end
548
+
549
+ it 'should complain if named project does not exist' do
550
+ define 'foo'
551
+ projects('foo').should include(project('foo'))
552
+ lambda { projects('bar') }.should raise_error(RuntimeError, /No such project/)
553
+ end
554
+
555
+ it 'should find a project from its parent or sibling project' do
556
+ define 'foo' do
557
+ define 'bar'
558
+ define 'baz'
559
+ end
560
+ project('foo').projects('bar').should eql(projects('foo:bar'))
561
+ project('foo').projects('baz').should eql(projects('foo:baz'))
562
+ project('foo:bar').projects('baz').should eql(projects('foo:baz'))
563
+ end
564
+
565
+ it 'should fine a project from its parent by proximity' do
566
+ define 'foo' do
567
+ define('bar') { define 'baz' }
568
+ define 'baz'
569
+ end
570
+ project('foo').projects('baz').should eql(projects('foo:baz'))
571
+ project('foo:bar').projects('baz').should eql(projects('foo:bar:baz'))
572
+ end
573
+
574
+ it 'should evaluate all projects before returning' do
575
+ # Note: gets around our define that also invokes the project.
576
+ Buildr.define('foo') { define('bar'); define('baz') }
577
+ projects.should eql(projects('foo', 'foo:bar', 'foo:baz'))
578
+ end
579
+ end
580
+
581
+
582
+ describe Rake::Task, ' local directory' do
583
+ before do
584
+ @task = Project.local_task(task(('doda')))
585
+ Project.on_define { |project| task('doda') { |task| @task.from project.name } }
586
+ end
587
+
588
+ it 'should execute project in local directory' do
589
+ define 'foo'
590
+ @task.should_receive(:from).with('foo')
591
+ @task.invoke
592
+ end
593
+
594
+ it 'should execute sub-project in local directory' do
595
+ @task.should_receive(:from).with('foo:bar')
596
+ define('foo') { define 'bar' }
597
+ in_original_dir(project('foo:bar').base_dir) { @task.invoke }
598
+ end
599
+
600
+ it 'should do nothing if no project in local directory' do
601
+ @task.should_not_receive(:from)
602
+ define('foo') { define 'bar' }
603
+ in_original_dir('../not_foo') { @task.invoke }
604
+ end
605
+
606
+ it 'should find closest project that matches current directory' do
607
+ mkpath 'bar/src/main'
608
+ define('foo') { define 'bar' }
609
+ @task.should_receive(:from).with('foo:bar')
610
+ in_original_dir('bar/src/main') { @task.invoke }
611
+ end
612
+ end
613
+
614
+
615
+ describe Project, '#task' do
616
+ it 'should create a regular task' do
617
+ define('foo') { task('bar') }
618
+ Buildr.application.lookup('foo:bar').should_not be_nil
619
+ end
620
+
621
+ it 'should return a task defined in the project' do
622
+ define('foo') { task('bar') }
623
+ project('foo').task('bar').should be_instance_of(Rake::Task)
624
+ end
625
+
626
+ it 'should not create task outside project definition' do
627
+ define 'foo'
628
+ lambda { project('foo').task('bar') }.should raise_error(RuntimeError, /no task foo:bar/)
629
+ end
630
+
631
+ it 'should include project name as prefix' do
632
+ define('foo') { task('bar') }
633
+ project('foo').task('bar').name.should eql('foo:bar')
634
+ end
635
+
636
+ it 'should accept single dependency' do
637
+ define('foo') { task('bar'=>'baz') }
638
+ project('foo').task('bar').prerequisites.should include('baz')
639
+ end
640
+
641
+ it 'should accept multiple dependencies' do
642
+ define('foo') { task('bar'=>['baz1', 'baz2']) }
643
+ project('foo').task('bar').prerequisites.should include('baz1')
644
+ project('foo').task('bar').prerequisites.should include('baz2')
645
+ end
646
+
647
+ it 'should execute task exactly once' do
648
+ define('foo') do
649
+ task 'baz'
650
+ task 'bar'=>'baz'
651
+ end
652
+ lambda { project('foo').task('bar').invoke }.should run_tasks(['foo:baz', 'foo:bar'])
653
+ end
654
+
655
+ it 'should create a file task' do
656
+ define('foo') { file('bar') }
657
+ Buildr.application.lookup(File.expand_path('bar')).should_not be_nil
658
+ end
659
+
660
+ it 'should create file task with absolute path' do
661
+ define('foo') { file('/tmp') }
662
+ Buildr.application.lookup(File.expand_path('/tmp')).should_not be_nil
663
+ end
664
+
665
+ it 'should create file task relative to project base directory' do
666
+ define('foo', :base_dir=>'tmp') { file('bar') }
667
+ Buildr.application.lookup(File.expand_path('tmp/bar')).should_not be_nil
668
+ end
669
+
670
+ it 'should accept single dependency' do
671
+ define('foo') { file('bar'=>'baz') }
672
+ project('foo').file('bar').prerequisites.should include('baz')
673
+ end
674
+
675
+ it 'should accept multiple dependencies' do
676
+ define('foo') { file('bar'=>['baz1', 'baz2']) }
677
+ project('foo').file('bar').prerequisites.should include('baz1')
678
+ project('foo').file('bar').prerequisites.should include('baz2')
679
+ end
680
+
681
+ it 'should accept hash arguments' do
682
+ define('foo') do
683
+ task 'bar'=>'bar_dep'
684
+ file 'baz'=>'baz_dep'
685
+ end
686
+ project('foo').task('bar').prerequisites.should include('bar_dep')
687
+ project('foo').file('baz').prerequisites.should include('baz_dep')
688
+ end
689
+
690
+ it 'should return a file task defined in the project' do
691
+ define('foo') { file('bar') }
692
+ project('foo').file('bar').should be_instance_of(Rake::FileTask)
693
+ end
694
+
695
+ it 'should create file task relative to project definition' do
696
+ define('foo') { define 'bar' }
697
+ project('foo:bar').file('baz').name.should point_to_path('bar/baz')
698
+ end
699
+
700
+ it 'should execute task exactly once' do
701
+ define('foo') do
702
+ task 'baz'
703
+ file 'bar'=>'baz'
704
+ end
705
+ lambda { project('foo').file('bar').invoke }.should run_tasks(['foo:baz', project('foo').path_to('bar')])
706
+ end
707
+ end
708
+
709
+
710
+ =begin
711
+ describe Buildr::Generate do
712
+ it 'should be able to create buildfile from directory structure' do
713
+ write 'src/main/java/Foo.java', ''
714
+ write 'one/two/src/main/java/Foo.java', ''
715
+ write 'one/three/src/main/java/Foo.java', ''
716
+ write 'four/src/main/java/Foo.java', ''
717
+ script = Buildr::Generate.from_directory(Dir.pwd)
718
+ instance_eval(script.join("\n"), "generated buildfile")
719
+ # projects should have been defined
720
+ root = Dir.pwd.pathmap('%n')
721
+ names = [root, "#{root}:one:two", "#{root}:one:three", "#{root}:four"]
722
+ # the top level project has the directory name.
723
+ names.each { |name| lambda { project(name) }.should_not raise_error }
724
+ end
725
+ end
726
+ =end
727
+
728
+
729
+ describe Rake::Task, 'buildr:initialize' do
730
+ it 'should be ready to run as the first task' do
731
+ Buildr.application.top_level_tasks.first.should eql('buildr:initialize')
732
+ end
733
+
734
+ it 'should evaluate all project definitions' do
735
+ defined = false
736
+ Buildr.define('foo') { defined = true }
737
+ lambda { task('buildr:initialize').invoke }.should change { defined }.to(true)
738
+ end
739
+ end