assaf-buildr 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +887 -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 +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -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(true).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(true)
30
+ buildfile.each { |line| line.should_not include('NEXT_VERSION')}
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,754 @@
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 map strings to path' do
199
+ @layout[:foo, "bar"] = 'none'
200
+ @layout.expand(:foo, :bar).should eql('none')
201
+ @layout.expand(:foo, 'bar').should eql('none')
202
+ end
203
+
204
+ it 'should ignore nil elements' do
205
+ @layout[:foo, :bar] = 'none'
206
+ @layout.expand(:foo, nil, :bar).should eql('none')
207
+ @layout.expand(nil, :foo).should eql('foo')
208
+ end
209
+
210
+ it 'should return nil if path not mapped' do
211
+ @layout[:foo].should be_nil
212
+ end
213
+
214
+ it 'should return path from symbol' do
215
+ @layout[:foo] = 'path'
216
+ @layout[:foo].should eql('path')
217
+ end
218
+
219
+ it 'should return path from symbol' do
220
+ @layout[:foo, :bar] = 'path'
221
+ @layout[:foo, :bar].should eql('path')
222
+ end
223
+
224
+ it 'should do eager mapping' do
225
+ @layout[:one] = 'none'
226
+ @layout[:one, :two] = '1..2'
227
+ @layout.expand(:one, :two, :three).should eql('1..2/three')
228
+ end
229
+
230
+ end
231
+
232
+
233
+ describe Project, '#layout' do
234
+ before :each do
235
+ @layout = Layout.new
236
+ end
237
+
238
+ it 'should exist by default' do
239
+ define('foo').layout.should respond_to(:expand)
240
+ end
241
+
242
+ it 'should be clone of default layout' do
243
+ define 'foo' do
244
+ layout.should_not be(Layout.default)
245
+ layout.expand(:test, :main).should eql(Layout.default.expand(:test, :main))
246
+ end
247
+ end
248
+
249
+ it 'should come from property, if specified' do
250
+ foo = define('foo', :layout=>@layout)
251
+ foo.layout.should eql(@layout)
252
+ end
253
+
254
+ it 'should inherit from parent project' do
255
+ define 'foo', :layout=>@layout do
256
+ layout[:foo] = 'foo'
257
+ define 'bar'
258
+ end
259
+ project('foo:bar').layout[:foo].should eql('foo')
260
+ end
261
+
262
+ it 'should clone when inheriting from parent project' do
263
+ define 'foo', :layout=>@layout do
264
+ layout[:foo] = 'foo'
265
+ define 'bar' do
266
+ layout[:foo] = 'bar'
267
+ end
268
+ end
269
+ project('foo').layout[:foo].should eql('foo')
270
+ project('foo:bar').layout[:foo].should eql('bar')
271
+ end
272
+
273
+ it 'should be settable only if not read' do
274
+ lambda { define('foo', :layout=>@layout) }.should_not raise_error
275
+ lambda { define('bar', :layout=>@layout) { self.layout = @layout.clone } }.should raise_error(Exception, /Cannot set/)
276
+ end
277
+
278
+ end
279
+
280
+
281
+ describe Project, '#path_to' do
282
+ it 'should return absolute paths as is' do
283
+ define('foo').path_to('/tmp').should eql(File.expand_path('/tmp'))
284
+ end
285
+
286
+ it 'should resolve empty path to project\'s base directory' do
287
+ define('foo').path_to.should eql(project('foo').base_dir)
288
+ end
289
+
290
+ it 'should resolve relative paths' do
291
+ define('foo').path_to('tmp').should eql(File.expand_path('tmp'))
292
+ end
293
+
294
+ it 'should accept multiple arguments' do
295
+ define('foo').path_to('foo', 'bar').should eql(File.expand_path('foo/bar'))
296
+ end
297
+
298
+ it 'should handle relative paths' do
299
+ define('foo').path_to('..', 'bar').should eql(File.expand_path('../bar'))
300
+ end
301
+
302
+ it 'should resolve symbols using layout' do
303
+ define('foo').layout[:foo] = 'bar'
304
+ project('foo').path_to(:foo).should eql(File.expand_path('bar'))
305
+ project('foo').path_to(:foo, 'tmp').should eql(File.expand_path('bar/tmp'))
306
+ end
307
+
308
+ it 'should resolve path for sub-project' do
309
+ define('foo') { define 'bar' }
310
+ project('foo:bar').path_to('foo').should eql(File.expand_path('foo', project('foo:bar').base_dir))
311
+ end
312
+
313
+ it 'should be idempotent for relative paths' do
314
+ define 'foo'
315
+ path = project('foo').path_to('bar')
316
+ project('foo').path_to(path).should eql(path)
317
+ end
318
+ end
319
+
320
+
321
+ describe Project, '#on_define' do
322
+ it 'should be called when project is defined' do
323
+ names = []
324
+ Project.on_define { |project| names << project.name }
325
+ define 'foo' ; define 'bar'
326
+ names.should eql(['foo', 'bar'])
327
+ end
328
+
329
+ it 'should be called with project object' do
330
+ Project.on_define { |project| project.name.should eql('foo') }
331
+ define('foo')
332
+ end
333
+
334
+ it 'should be called with project object and set properties' do
335
+ Project.on_define { |project| project.version.should eql('2.0') }
336
+ define('foo', :version=>'2.0')
337
+ end
338
+
339
+ it 'should execute in namespace of project' do
340
+ scopes = []
341
+ Project.on_define { |project| scopes << Buildr.application.current_scope }
342
+ define('foo') { define 'bar' }
343
+ scopes.should eql([['foo'], ['foo', 'bar']])
344
+ end
345
+
346
+ it 'should be called before project block' do
347
+ order = []
348
+ Project.on_define { |project| order << 'on_define' }
349
+ define('foo') { order << 'define' }
350
+ order.should eql(['on_define', 'define'])
351
+ end
352
+
353
+ it 'should accept enhancement and call it after project block' do
354
+ order = []
355
+ Project.on_define { |project| project.enhance { order << 'enhance' } }
356
+ define('foo') { order << 'define' }
357
+ order.should eql(['define', 'enhance'])
358
+ end
359
+
360
+ it 'should accept enhancement and call it with project' do
361
+ Project.on_define { |project| project.enhance { |project| project.name.should eql('foo') } }
362
+ define('foo')
363
+ end
364
+
365
+ it 'should execute enhancement in namespace of project' do
366
+ scopes = []
367
+ Project.on_define { |project| project.enhance { scopes << Buildr.application.current_scope } }
368
+ define('foo') { define 'bar' }
369
+ scopes.should eql([['foo'], ['foo', 'bar']])
370
+ end
371
+ end
372
+
373
+
374
+ describe Rake::Task, ' recursive' do
375
+ before do
376
+ @order = []
377
+ Project.on_define do |project|
378
+ project.recursive_task('doda') { @order << project.name }
379
+ end
380
+ define('foo') { define('bar') { define('baz') } }
381
+ end
382
+
383
+ it 'should invoke same task in child project' do
384
+ task('foo:doda').invoke
385
+ @order.should include('foo:bar:baz')
386
+ @order.should include('foo:bar')
387
+ @order.should include('foo')
388
+ end
389
+
390
+ it 'should invoke in depth-first order' do
391
+ task('foo:doda').invoke
392
+ @order.should eql([ 'foo:bar:baz', 'foo:bar', 'foo' ])
393
+ end
394
+
395
+ it 'should not invoke task in parent project' do
396
+ task('foo:bar:baz:doda').invoke
397
+ @order.should eql([ 'foo:bar:baz' ])
398
+ end
399
+ end
400
+
401
+
402
+ describe 'Sub-project' do
403
+ it 'should point at parent project' do
404
+ define('foo') { define 'bar' }
405
+ project('foo:bar').parent.should be(project('foo'))
406
+ end
407
+
408
+ it 'should be defined only within parent project' do
409
+ lambda { define('foo:bar') }.should raise_error
410
+ end
411
+
412
+ it 'should have unique name' do
413
+ lambda do
414
+ define 'foo' do
415
+ define 'bar'
416
+ define 'bar'
417
+ end
418
+ end.should raise_error
419
+ end
420
+
421
+ it 'should be findable from root' do
422
+ define('foo') { define 'bar' }
423
+ projects.map(&:name).should include('foo:bar')
424
+ end
425
+
426
+ it 'should be findable from parent project' do
427
+ define('foo') { define 'bar' }
428
+ project('foo').projects.map(&:name).should include('foo:bar')
429
+ end
430
+
431
+ it 'should be findable only if exists' do
432
+ define('foo') { define 'bar' }
433
+ lambda { project('foo').project('baz') }.should raise_error(RuntimeError, /No such project/)
434
+ end
435
+
436
+ it 'should always execute its definition ' do
437
+ ordered = []
438
+ define 'foo' do
439
+ ordered << self.name
440
+ define('bar') { ordered << self.name }
441
+ define('baz') { ordered << self.name }
442
+ end
443
+ ordered.should eql(['foo', 'foo:bar', 'foo:baz'])
444
+ end
445
+
446
+ it 'should execute in order of dependency' do
447
+ ordered = []
448
+ define 'foo' do
449
+ ordered << self.name
450
+ define('bar') { project('foo:baz') ; ordered << self.name }
451
+ define('baz') { ordered << self.name }
452
+ end
453
+ ordered.should eql(['foo', 'foo:baz', 'foo:bar'])
454
+ end
455
+
456
+ it 'should warn of circular dependency' do
457
+ lambda do
458
+ define 'foo' do
459
+ define('bar') { project('foo:baz') }
460
+ define('baz') { project('foo:bar') }
461
+ end
462
+ end.should raise_error(RuntimeError, /Circular dependency/)
463
+ end
464
+ end
465
+
466
+
467
+ describe 'Top-level project' do
468
+ it 'should have no parent' do
469
+ define('foo')
470
+ project('foo').parent.should be_nil
471
+ end
472
+ end
473
+
474
+
475
+ describe Buildr, '#project' do
476
+ it 'should raise error if no such project' do
477
+ lambda { project('foo') }.should raise_error(RuntimeError, /No such project/)
478
+ end
479
+
480
+ it 'should return a project if exists' do
481
+ foo = define('foo')
482
+ project('foo').should be(foo)
483
+ end
484
+
485
+ it 'should find a project by its full name' do
486
+ bar, baz = nil
487
+ define('foo') { bar = define('bar') { baz = define('baz') } }
488
+ project('foo:bar').should be(bar)
489
+ project('foo:bar:baz').should be(baz)
490
+ end
491
+
492
+ it 'should find a project from any context' do
493
+ bar, baz = nil
494
+ define('foo') { bar = define('bar') { baz = define('baz') } }
495
+ project('foo:bar').project('foo:bar:baz').should be(baz)
496
+ project('foo:bar:baz').project('foo:bar').should be(bar)
497
+ end
498
+
499
+ it 'should find a project from its parent or sibling project' do
500
+ define 'foo' do
501
+ define 'bar'
502
+ define 'baz'
503
+ end
504
+ project('foo').project('bar').should be(project('foo:bar'))
505
+ project('foo').project('baz').should be(project('foo:baz'))
506
+ project('foo:bar').project('baz').should be(project('foo:baz'))
507
+ end
508
+
509
+ it 'should fine a project from its parent by proximity' do
510
+ define 'foo' do
511
+ define('bar') { define 'baz' }
512
+ define 'baz'
513
+ end
514
+ project('foo').project('baz').should be(project('foo:baz'))
515
+ project('foo:bar').project('baz').should be(project('foo:bar:baz'))
516
+ end
517
+
518
+ it 'should invoke project before returning it' do
519
+ define('foo').should_receive(:invoke).once
520
+ project('foo')
521
+ end
522
+
523
+ it 'should fail if called without a project name' do
524
+ lambda { project }.should raise_error(ArgumentError)
525
+ end
526
+
527
+ it 'should return self if called on a project without a name' do
528
+ define('foo') { project.should be(self) }
529
+ end
530
+
531
+ it 'should evaluate parent project before returning' do
532
+ # Note: gets around our define that also invokes the project.
533
+ Buildr.define('foo') { define('bar'); define('baz') }
534
+ project('foo:bar').should eql(projects[1])
535
+ end
536
+ end
537
+
538
+
539
+ describe Buildr, '#projects' do
540
+ it 'should only return defined projects' do
541
+ projects.should eql([])
542
+ define 'foo'
543
+ projects.should eql([project('foo')])
544
+ end
545
+
546
+ it 'should return all defined projects' do
547
+ define 'foo'
548
+ define('bar') { define 'baz' }
549
+ projects.should include(project('foo'))
550
+ projects.should include(project('bar'))
551
+ projects.should include(project('bar:baz'))
552
+ end
553
+
554
+ it 'should return only named projects' do
555
+ define 'foo' ; define 'bar' ; define 'baz'
556
+ projects('foo', 'bar').should include(project('foo'))
557
+ projects('foo', 'bar').should include(project('bar'))
558
+ projects('foo', 'bar').should_not include(project('baz'))
559
+ end
560
+
561
+ it 'should complain if named project does not exist' do
562
+ define 'foo'
563
+ projects('foo').should include(project('foo'))
564
+ lambda { projects('bar') }.should raise_error(RuntimeError, /No such project/)
565
+ end
566
+
567
+ it 'should find a project from its parent or sibling project' do
568
+ define 'foo' do
569
+ define 'bar'
570
+ define 'baz'
571
+ end
572
+ project('foo').projects('bar').should eql(projects('foo:bar'))
573
+ project('foo').projects('baz').should eql(projects('foo:baz'))
574
+ project('foo:bar').projects('baz').should eql(projects('foo:baz'))
575
+ end
576
+
577
+ it 'should fine a project from its parent by proximity' do
578
+ define 'foo' do
579
+ define('bar') { define 'baz' }
580
+ define 'baz'
581
+ end
582
+ project('foo').projects('baz').should eql(projects('foo:baz'))
583
+ project('foo:bar').projects('baz').should eql(projects('foo:bar:baz'))
584
+ end
585
+
586
+ it 'should evaluate all projects before returning' do
587
+ # Note: gets around our define that also invokes the project.
588
+ Buildr.define('foo') { define('bar'); define('baz') }
589
+ projects.should eql(projects('foo', 'foo:bar', 'foo:baz'))
590
+ end
591
+ end
592
+
593
+
594
+ describe Rake::Task, ' local directory' do
595
+ before do
596
+ @task = Project.local_task(task(('doda')))
597
+ Project.on_define { |project| task('doda') { |task| @task.from project.name } }
598
+ end
599
+
600
+ it 'should execute project in local directory' do
601
+ define 'foo'
602
+ @task.should_receive(:from).with('foo')
603
+ @task.invoke
604
+ end
605
+
606
+ it 'should execute sub-project in local directory' do
607
+ @task.should_receive(:from).with('foo:bar')
608
+ define('foo') { define 'bar' }
609
+ in_original_dir(project('foo:bar').base_dir) { @task.invoke }
610
+ end
611
+
612
+ it 'should do nothing if no project in local directory' do
613
+ @task.should_not_receive(:from)
614
+ define('foo') { define 'bar' }
615
+ in_original_dir('../not_foo') { @task.invoke }
616
+ end
617
+
618
+ it 'should find closest project that matches current directory' do
619
+ mkpath 'bar/src/main'
620
+ define('foo') { define 'bar' }
621
+ @task.should_receive(:from).with('foo:bar')
622
+ in_original_dir('bar/src/main') { @task.invoke }
623
+ end
624
+ end
625
+
626
+
627
+ describe Project, '#task' do
628
+ it 'should create a regular task' do
629
+ define('foo') { task('bar') }
630
+ Buildr.application.lookup('foo:bar').should_not be_nil
631
+ end
632
+
633
+ it 'should return a task defined in the project' do
634
+ define('foo') { task('bar') }
635
+ project('foo').task('bar').should be_instance_of(Rake::Task)
636
+ end
637
+
638
+ it 'should not create task outside project definition' do
639
+ define 'foo'
640
+ lambda { project('foo').task('bar') }.should raise_error(RuntimeError, /no task foo:bar/)
641
+ end
642
+
643
+ it 'should include project name as prefix' do
644
+ define('foo') { task('bar') }
645
+ project('foo').task('bar').name.should eql('foo:bar')
646
+ end
647
+
648
+ it 'should ignore namespace if starting with color' do
649
+ define 'foo' do
650
+ task(':bar').name.should == 'bar'
651
+ end
652
+ Rake::Task.task_defined?('bar').should be_true
653
+ end
654
+
655
+ it 'should accept single dependency' do
656
+ define('foo') { task('bar'=>'baz') }
657
+ project('foo').task('bar').prerequisites.should include('baz')
658
+ end
659
+
660
+ it 'should accept multiple dependencies' do
661
+ define('foo') { task('bar'=>['baz1', 'baz2']) }
662
+ project('foo').task('bar').prerequisites.should include('baz1')
663
+ project('foo').task('bar').prerequisites.should include('baz2')
664
+ end
665
+
666
+ it 'should execute task exactly once' do
667
+ define('foo') do
668
+ task 'baz'
669
+ task 'bar'=>'baz'
670
+ end
671
+ lambda { project('foo').task('bar').invoke }.should run_tasks(['foo:baz', 'foo:bar'])
672
+ end
673
+
674
+ it 'should create a file task' do
675
+ define('foo') { file('bar') }
676
+ Buildr.application.lookup(File.expand_path('bar')).should_not be_nil
677
+ end
678
+
679
+ it 'should create file task with absolute path' do
680
+ define('foo') { file('/tmp') }
681
+ Buildr.application.lookup(File.expand_path('/tmp')).should_not be_nil
682
+ end
683
+
684
+ it 'should create file task relative to project base directory' do
685
+ define('foo', :base_dir=>'tmp') { file('bar') }
686
+ Buildr.application.lookup(File.expand_path('tmp/bar')).should_not be_nil
687
+ end
688
+
689
+ it 'should accept single dependency' do
690
+ define('foo') { file('bar'=>'baz') }
691
+ project('foo').file('bar').prerequisites.should include('baz')
692
+ end
693
+
694
+ it 'should accept multiple dependencies' do
695
+ define('foo') { file('bar'=>['baz1', 'baz2']) }
696
+ project('foo').file('bar').prerequisites.should include('baz1')
697
+ project('foo').file('bar').prerequisites.should include('baz2')
698
+ end
699
+
700
+ it 'should accept hash arguments' do
701
+ define('foo') do
702
+ task 'bar'=>'bar_dep'
703
+ file 'baz'=>'baz_dep'
704
+ end
705
+ project('foo').task('bar').prerequisites.should include('bar_dep')
706
+ project('foo').file('baz').prerequisites.should include('baz_dep')
707
+ end
708
+
709
+ it 'should return a file task defined in the project' do
710
+ define('foo') { file('bar') }
711
+ project('foo').file('bar').should be_instance_of(Rake::FileTask)
712
+ end
713
+
714
+ it 'should create file task relative to project definition' do
715
+ define('foo') { define 'bar' }
716
+ project('foo:bar').file('baz').name.should point_to_path('bar/baz')
717
+ end
718
+
719
+ it 'should execute task exactly once' do
720
+ define('foo') do
721
+ task 'baz'
722
+ file 'bar'=>'baz'
723
+ end
724
+ lambda { project('foo').file('bar').invoke }.should run_tasks(['foo:baz', project('foo').path_to('bar')])
725
+ end
726
+ end
727
+
728
+
729
+ =begin
730
+ describe Buildr::Generate do
731
+ it 'should be able to create buildfile from directory structure' do
732
+ write 'src/main/java/Foo.java', ''
733
+ write 'one/two/src/main/java/Foo.java', ''
734
+ write 'one/three/src/main/java/Foo.java', ''
735
+ write 'four/src/main/java/Foo.java', ''
736
+ script = Buildr::Generate.from_directory(Dir.pwd)
737
+ instance_eval(script.join("\n"), "generated buildfile")
738
+ # projects should have been defined
739
+ root = Dir.pwd.pathmap('%n')
740
+ names = [root, "#{root}:one:two", "#{root}:one:three", "#{root}:four"]
741
+ # the top level project has the directory name.
742
+ names.each { |name| lambda { project(name) }.should_not raise_error }
743
+ end
744
+ end
745
+ =end
746
+
747
+
748
+ describe Rake::Task, 'buildr:initialize' do
749
+ it 'should evaluate all project definitions' do
750
+ defined = false
751
+ Buildr.define('foo') { defined = true }
752
+ lambda { task('buildr:initialize').invoke }.should change { defined }.to(true)
753
+ end
754
+ end