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,635 @@
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
+ require File.join(File.dirname(__FILE__), 'spec_helpers')
17
+
18
+ describe Buildr::ArtifactNamespace do
19
+
20
+ before(:each) { Buildr::ArtifactNamespace.clear }
21
+
22
+ def abc_module
23
+ Object.module_eval 'module A; module B; module C; end; end; end'
24
+ yield
25
+ ensure
26
+ Object.send :remove_const, :A
27
+ end
28
+
29
+ describe '.root' do
30
+ it 'should return the top level namespace' do
31
+ Buildr::ArtifactNamespace.root.should be_root
32
+ end
33
+
34
+ it 'should yield the namespace if a block is given' do
35
+ Buildr::ArtifactNamespace.root { |ns| ns.should be_root }
36
+ end
37
+ end
38
+
39
+ describe '.instance' do
40
+ it 'should return the top level namespace when invoked outside a project definition' do
41
+ artifact_ns.should be_root
42
+ end
43
+
44
+ it 'should return the namespace for the receiving project' do
45
+ define('foo') { }
46
+ project('foo').artifact_ns.name.should == 'foo'
47
+ end
48
+
49
+ it 'should return the current project namespace when invoked inside a project' do
50
+ define 'foo' do
51
+ artifact_ns.should_not be_root
52
+ artifact_ns.name.should == 'foo'
53
+ task :doit do
54
+ artifact_ns.should_not be_root
55
+ artifact_ns.name.should == 'foo'
56
+ end.invoke
57
+ end
58
+ end
59
+
60
+ it 'should return the root namespace if given :root' do
61
+ artifact_ns(:root).should be_root
62
+ end
63
+
64
+ it 'should return the namespace for the given name' do
65
+ artifact_ns(:foo).name.should == 'foo'
66
+ artifact_ns('foo:bar').name.should == 'foo:bar'
67
+ artifact_ns(['foo', 'bar', 'baz']).name.should == 'foo:bar:baz'
68
+ abc_module do
69
+ artifact_ns(A::B::C).name.should == 'A::B::C'
70
+ end
71
+ artifact_ns(:root).should be_root
72
+ artifact_ns(:current).should be_root
73
+ define 'foo' do
74
+ artifact_ns(:current).name.should == 'foo'
75
+ define 'baz' do
76
+ artifact_ns(:current).name.should == 'foo:baz'
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '#parent' do
83
+ it 'should be nil for root namespace' do
84
+ artifact_ns(:root).parent.should be_nil
85
+ end
86
+
87
+ it 'should be the parent namespace for nested modules' do
88
+ abc_module do
89
+ artifact_ns(A::B::C).parent.should == artifact_ns(A::B)
90
+ artifact_ns(A::B).parent.should == artifact_ns(A)
91
+ artifact_ns(A).parent.should == artifact_ns(:root)
92
+ end
93
+ end
94
+
95
+ it 'should be the parent namespace for nested projects' do
96
+ define 'a' do
97
+ define 'b' do
98
+ define 'c' do
99
+ artifact_ns.parent.should == artifact_ns(parent)
100
+ end
101
+ artifact_ns.parent.should == artifact_ns(parent)
102
+ end
103
+ artifact_ns.parent.should == artifact_ns(:root)
104
+ end
105
+ end
106
+ end
107
+
108
+ describe '#parent=' do
109
+ it 'should reject to set parent for root namespace' do
110
+ lambda { artifact_ns(:root).parent = :foo }.should raise_error(Exception, /cannot set parent/i)
111
+ end
112
+
113
+ it 'should allow to set parent' do
114
+ artifact_ns(:bar).parent = :foo
115
+ artifact_ns(:bar).parent.should == artifact_ns(:foo)
116
+ artifact_ns(:bar).parent = artifact_ns(:baz)
117
+ artifact_ns(:bar).parent.should == artifact_ns(:baz)
118
+ end
119
+
120
+ it 'should allow to set parent to :current' do
121
+ abc_module do
122
+ mod = A::B
123
+ artifact_ns(mod).parent = :current
124
+ def mod.stuff
125
+ Buildr::artifact_ns(self)
126
+ end
127
+ define 'a' do
128
+ define 'b' do
129
+ mod.stuff.parent.should == artifact_ns
130
+ end
131
+ mod.stuff.parent.should == artifact_ns
132
+ end
133
+ end
134
+ end
135
+ end
136
+
137
+ describe '#need' do
138
+ it 'should accept an artifact spec' do
139
+ define 'one' do
140
+ artifact_ns.need 'a:b:c:1'
141
+ # referenced by spec
142
+ artifact_ns['a:b:c'].should_not be_selected
143
+
144
+ # referenced by name
145
+ artifact_ns[:b].should_not be_selected
146
+ artifact_ns[:b].should be_satisfied_by('a:b:c:1')
147
+ artifact_ns[:b].should_not be_satisfied_by('a:b:c:2')
148
+ artifact_ns[:b].should_not be_satisfied_by('d:b:c:1')
149
+ artifact_ns[:b].version.should == '1'
150
+ end
151
+ end
152
+
153
+ it 'should accept a requirement_spec' do
154
+ define 'one' do
155
+ artifact_ns.need 'thing -> a:b:c:2.1 -> ~>2.0'
156
+ # referenced by spec
157
+ artifact_ns['a:b:c'].should_not be_selected
158
+
159
+ # referenced by name
160
+ artifact_ns.key?(:b).should be_false
161
+ artifact_ns[:thing].should_not be_selected
162
+ artifact_ns[:thing].should be_satisfied_by('a:b:c:2.5')
163
+ artifact_ns[:thing].should_not be_satisfied_by('a:b:c:3')
164
+ artifact_ns[:thing].version.should == '2.1'
165
+ end
166
+ end
167
+
168
+ it 'should accept a hash :name -> requirement_spec' do
169
+ define 'one' do
170
+ artifact_ns.need :thing => 'a:b:c:2.1 -> ~>2.0'
171
+ artifact_ns[:thing].should be_satisfied_by('a:b:c:2.5')
172
+ artifact_ns[:thing].should_not be_satisfied_by('a:b:c:3')
173
+ artifact_ns[:thing].version.should == '2.1'
174
+ end
175
+
176
+ define 'two' do
177
+ artifact_ns.need :thing => 'a:b:c:(~>2.0 | 2.1)'
178
+ artifact_ns[:thing].should be_satisfied_by('a:b:c:2.5')
179
+ artifact_ns[:thing].should_not be_satisfied_by('a:b:c:3')
180
+ artifact_ns[:thing].version.should == '2.1'
181
+ end
182
+ end
183
+
184
+ it 'should take a hash :name -> specs_array' do
185
+ define 'one' do
186
+ artifact_ns.need :things => ['foo:bar:jar:1.0',
187
+ 'foo:baz:jar:2.0',]
188
+ artifact_ns['foo:bar:jar'].should_not be_selected
189
+ artifact_ns['foo:baz:jar'].should_not be_selected
190
+ artifact_ns[:bar, :baz].should == [nil, nil]
191
+ artifact_ns[:things].map(&:unversioned_spec).should include('foo:bar:jar', 'foo:baz:jar')
192
+ artifact_ns.alias :baz, 'foo:baz:jar'
193
+ artifact_ns[:baz].should == artifact_ns['foo:baz:jar']
194
+ end
195
+ end
196
+
197
+ it 'should select best matching version if defined' do
198
+ define 'one' do
199
+ artifact_ns.use :a => 'foo:bar:jar:1.5'
200
+ artifact_ns.use :b => 'foo:baz:jar:2.0'
201
+ define 'two' do
202
+ artifact_ns[:a].requirement.should be_nil
203
+ artifact_ns[:a].should be_selected
204
+
205
+ artifact_ns.need :c => 'foo:bat:jar:3.0'
206
+ artifact_ns['foo:bat:jar'].should_not be_selected
207
+ artifact_ns[:c].should_not be_selected
208
+
209
+ artifact_ns.need :one => 'foo:bar:jar:>=1.0'
210
+ artifact_ns[:one].version.should == '1.5'
211
+ artifact_ns[:one].should be_selected
212
+ artifact_ns[:a].requirement.should be_nil
213
+
214
+ artifact_ns.need :two => 'foo:baz:jar:>2'
215
+ artifact_ns[:two].version.should be_nil
216
+ artifact_ns[:two].should_not be_selected
217
+ artifact_ns[:b].requirement.should be_nil
218
+ end
219
+ end
220
+ end
221
+ end
222
+
223
+ describe '#use' do
224
+ it 'should register the artifact on namespace' do
225
+ define 'one' do
226
+ artifact_ns.use :thing => 'a:b:c:1'
227
+ artifact_ns[:thing].requirement.should be_nil
228
+ artifact_ns[:thing].version.should == '1'
229
+ artifact_ns[:thing].id.should == 'b'
230
+ define 'one' do
231
+ artifact_ns.use :thing => 'a:d:c:2'
232
+ artifact_ns[:thing].requirement.should be_nil
233
+ artifact_ns[:thing].version.should == '2'
234
+ artifact_ns[:thing].id.should == 'd'
235
+
236
+ artifact_ns.use :copied => artifact_ns.parent[:thing]
237
+ artifact_ns[:copied].should_not == artifact_ns.parent[:thing]
238
+ artifact_ns[:copied].requirement.should be_nil
239
+ artifact_ns[:copied].version.should == '1'
240
+ artifact_ns[:copied].id.should == 'b'
241
+
242
+ artifact_ns.use :aliased => :copied
243
+ artifact_ns[:aliased].should == artifact_ns[:copied]
244
+
245
+ lambda { artifact_ns.use :invalid => :unknown }.should raise_error(NameError, /undefined/i)
246
+ end
247
+ artifact_ns[:copied].should be_nil
248
+ end
249
+ end
250
+
251
+ it 'should complain if namespace requirement is not satisfied' do
252
+ define 'one' do
253
+ artifact_ns.need :bar => 'foo:bar:baz:~>1.5'
254
+ lambda { artifact_ns.use :bar => '1.4' }.should raise_error(Exception, /unsatisfied/i)
255
+ end
256
+ end
257
+
258
+ it 'should be able to register a group' do
259
+ specs = ['its:me:here:1', 'its:you:there:2']
260
+ artifact_ns.use :them => specs
261
+ artifact_ns[:them].map(&:to_spec).should == specs
262
+ artifact_ns['its:me:here'].should_not be_nil
263
+ artifact_ns[:you].should be_nil
264
+ end
265
+
266
+ it 'should be able to assign sub namespaces' do
267
+ artifact_ns(:foo).bar = "foo:bar:baz:0"
268
+ artifact_ns(:moo).foo = artifact_ns(:foo)
269
+ artifact_ns(:moo).foo.should == artifact_ns(:foo)
270
+ artifact_ns(:moo).foo_bar.should == artifact_ns(:foo).bar
271
+ end
272
+
273
+ end
274
+
275
+ describe '#values' do
276
+ it 'returns the artifacts defined on namespace' do
277
+ define 'foo' do
278
+ artifact_ns.use 'foo:one:baz:1.0'
279
+ define 'bar' do
280
+ artifact_ns.use 'foo:two:baz:1.0'
281
+
282
+ specs = artifact_ns.values.map(&:to_spec)
283
+ specs.should include('foo:two:baz:1.0')
284
+ specs.should_not include('foo:one:baz:1.0')
285
+
286
+ specs = artifact_ns.values(true).map(&:to_spec)
287
+ specs.should include('foo:two:baz:1.0', 'foo:one:baz:1.0')
288
+ end
289
+ end
290
+ end
291
+ end
292
+
293
+ describe '#values_at' do
294
+ it 'returns the named artifacts' do
295
+ define 'foo' do
296
+ artifact_ns.use 'foo:one:baz:1.0'
297
+ define 'bar' do
298
+ artifact_ns.use :foo_baz => 'foo:two:baz:1.0'
299
+
300
+ specs = artifact_ns.values_at('one').map(&:to_spec)
301
+ specs.should include('foo:one:baz:1.0')
302
+ specs.should_not include('foo:two:baz:1.0')
303
+
304
+ specs = artifact_ns.values_at('foo_baz').map(&:to_spec)
305
+ specs.should include('foo:two:baz:1.0')
306
+ specs.should_not include('foo:one:baz:1.0')
307
+ end
308
+ end
309
+ end
310
+
311
+ it 'returns first artifacts by their unversioned spec' do
312
+ define 'foo' do
313
+ artifact_ns.use 'foo:one:baz:2.0'
314
+ define 'bar' do
315
+ artifact_ns.use :older => 'foo:one:baz:1.0'
316
+
317
+ specs = artifact_ns.values_at('foo:one:baz').map(&:to_spec)
318
+ specs.should include('foo:one:baz:1.0')
319
+ specs.should_not include('foo:one:baz:2.0')
320
+ end
321
+ specs = artifact_ns.values_at('foo:one:baz').map(&:to_spec)
322
+ specs.should include('foo:one:baz:2.0')
323
+ specs.should_not include('foo:one:baz:1.0')
324
+ end
325
+ end
326
+
327
+ it 'return first artifact satisfying a dependency' do
328
+ define 'foo' do
329
+ artifact_ns.use 'foo:one:baz:2.0'
330
+ define 'bar' do
331
+ artifact_ns.use :older => 'foo:one:baz:1.0'
332
+
333
+ specs = artifact_ns.values_at('foo:one:baz:>1.0').map(&:to_spec)
334
+ specs.should include('foo:one:baz:2.0')
335
+ specs.should_not include('foo:one:baz:1.0')
336
+ end
337
+ end
338
+ end
339
+ end
340
+
341
+ describe '#method_missing' do
342
+ it 'should use cool_aid! to create a requirement' do
343
+ define 'foo' do
344
+ artifact_ns.cool_aid!('cool:aid:jar:2').should be_kind_of(ArtifactNamespace::ArtifactRequirement)
345
+ artifact_ns[:cool_aid].version.should == '2'
346
+ artifact_ns[:cool_aid].should_not be_selected
347
+ define 'bar' do
348
+ artifact_ns.cool_aid! 'cool:aid:man:3', '>2'
349
+ artifact_ns[:cool_aid].version.should == '3'
350
+ artifact_ns[:cool_aid].requirement.should be_satisfied_by('2.5')
351
+ artifact_ns[:cool_aid].should_not be_selected
352
+ end
353
+ end
354
+ end
355
+
356
+ it 'should use cool_aid= as shorhand for [:cool_aid]=' do
357
+ artifact_ns.cool_aid = 'cool:aid:jar:1'
358
+ artifact_ns[:cool_aid].should be_selected
359
+ end
360
+
361
+ it 'should use cool_aid as shorthand for [:cool_aid]' do
362
+ artifact_ns.need :cool_aid => 'cool:aid:jar:1'
363
+ artifact_ns.cool_aid.should_not be_selected
364
+ end
365
+
366
+ it 'should use cool_aid? to test if artifact has been defined and selected' do
367
+ artifact_ns.need :cool_aid => 'cool:aid:jar:>1'
368
+ artifact_ns.should_not have_cool_aid
369
+ artifact_ns.should_not have_unknown
370
+ artifact_ns.cool_aid = '2'
371
+ artifact_ns.should have_cool_aid
372
+ end
373
+ end
374
+
375
+ describe '#ns' do
376
+ it 'should create a sub namespace' do
377
+ artifact_ns.ns :foo
378
+ artifact_ns[:foo].should be_kind_of(ArtifactNamespace)
379
+ artifact_ns(:foo).should_not === artifact_ns.foo
380
+ artifact_ns.foo.parent.should == artifact_ns
381
+ end
382
+
383
+ it 'should take any use arguments' do
384
+ artifact_ns.ns :foo, :bar => 'foo:bar:jar:0', :baz => 'foo:baz:jar:0'
385
+ artifact_ns.foo.bar.should be_selected
386
+ artifact_ns.foo[:baz].should be_selected
387
+ end
388
+
389
+ it 'should access sub artifacts using with foo_bar like syntax' do
390
+ artifact_ns.ns :foo, :bar => 'foo:bar:jar:0', :baz => 'foo:baz:jar:0'
391
+ artifact_ns[:foo_baz].should be_selected
392
+ artifact_ns.foo_bar.should be_selected
393
+
394
+ artifact_ns.foo.ns :bat, 'bat:man:jar:>1'
395
+ batman = artifact_ns.foo.bat.man
396
+ batman.should be_selected
397
+ artifact_ns[:foo_bat_man] = '3'
398
+ artifact_ns[:foo_bat_man].should == batman
399
+ artifact_ns[:foo_bat_man].version.should == '3'
400
+ end
401
+
402
+ it 'should include sub artifacts when calling #values' do
403
+ artifact_ns.ns :bat, 'bat:man:jar:>1'
404
+ artifact_ns.values.should_not be_empty
405
+ artifact_ns.values.first.unversioned_spec.should == 'bat:man:jar'
406
+ end
407
+
408
+ it 'should reopen a sub-namespace' do
409
+ artifact_ns.ns :bat, 'bat:man:jar:>1'
410
+ bat = artifact_ns[:bat]
411
+ bat.should == artifact_ns.ns(:bat)
412
+ end
413
+
414
+ it 'should fail reopening if not a sub-namespace' do
415
+ artifact_ns.foo = 'foo:bar:baz:0'
416
+ lambda { artifact_ns.ns(:foo) }.should raise_error(TypeError, /not a sub/i)
417
+ end
418
+
419
+ it 'should clone artifacts when assigned' do
420
+ artifact_ns(:foo).bar = "foo:bar:jar:0"
421
+ artifact_ns(:moo).ns :muu, :miu => artifact_ns(:foo).bar
422
+ artifact_ns(:moo).muu.miu.should_not == artifact_ns(:foo).bar
423
+ artifact_ns(:moo).muu.miu.to_spec.should == artifact_ns(:foo).bar.to_spec
424
+ end
425
+
426
+ it 'should clone parent artifacts by name' do
427
+ define 'foo' do
428
+ artifact_ns.bar = "foo:bar:jar:0"
429
+ define 'moo' do
430
+ artifact_ns.ns(:muu).use :bar
431
+ artifact_ns.muu_bar.should be_selected
432
+ artifact_ns.muu.bar.should_not == artifact_ns.bar
433
+ end
434
+ end
435
+ end
436
+ end
437
+
438
+ it 'should be an Enumerable' do
439
+ artifact_ns.should be_kind_of(Enumerable)
440
+ artifact_ns.use 'foo:bar:baz:1.0'
441
+ artifact_ns.map(&:artifact).should include(artifact('foo:bar:baz:1.0'))
442
+ end
443
+
444
+ end # ArtifactNamespace
445
+
446
+ describe Buildr do
447
+ before(:each) { Buildr::ArtifactNamespace.clear }
448
+
449
+ describe '.artifacts' do
450
+ it 'should take ruby symbols and ask the current namespace for them' do
451
+ define 'foo' do
452
+ artifact_ns.cool = 'cool:aid:jar:1.0'
453
+ artifact_ns.use 'some:other:jar:1.0'
454
+ artifact_ns.use 'bat:man:jar:1.0'
455
+ compile.with :cool, :other, :'bat:man:jar'
456
+ compile.classpath.map(&:to_spec).should include('cool:aid:jar:1.0', 'some:other:jar:1.0', 'bat:man:jar:1.0')
457
+ end
458
+ end
459
+
460
+ it 'should take a namespace' do
461
+ artifact_ns(:moo).muu = 'moo:muu:jar:1.0'
462
+ define 'foo' do
463
+ compile.with artifact_ns(:moo)
464
+ compile.classpath.map(&:to_spec).should include('moo:muu:jar:1.0')
465
+ end
466
+ end
467
+ end
468
+
469
+ describe '.artifact' do
470
+ it 'should search current namespace if given a symbol' do
471
+ define 'foo' do
472
+ artifact_ns.use :cool => 'cool:aid:jar:1.0'
473
+ define 'bar' do
474
+ artifact(:cool).should == artifact_ns[:cool].artifact
475
+ end
476
+ end
477
+ end
478
+
479
+ it 'should search current namespace if given a symbol spec' do
480
+ define 'foo' do
481
+ artifact_ns.use 'cool:aid:jar:1.0'
482
+ define 'bar' do
483
+ artifact(:'cool:aid:jar').should == artifact_ns[:aid].artifact
484
+ end
485
+ end
486
+ end
487
+
488
+ it 'should fail when no artifact by that name is found' do
489
+ define 'foo' do
490
+ artifact_ns.use 'cool:aid:jar:1.0'
491
+ define 'bar' do
492
+ lambda { artifact(:cool) }.should raise_error(IndexError, /artifact/)
493
+ end
494
+ end
495
+ end
496
+ end
497
+ end
498
+
499
+ describe "Extension using ArtifactNamespace" do
500
+ before(:each) { Buildr::ArtifactNamespace.clear }
501
+
502
+ def abc_module
503
+ Object.module_eval 'module A; module B; module C; end; end; end'
504
+ yield
505
+ ensure
506
+ Object.send :remove_const, :A
507
+ end
508
+
509
+ it 'can register namespace listeners' do
510
+ abc_module do
511
+ # An example extension to illustrate namespace listeners and method forwarding
512
+ class A::Example
513
+
514
+ module Ext
515
+ include Buildr::Extension
516
+ def example; @example ||= A::Example.new; end
517
+ before_define do |p|
518
+ Rake::Task.define_task('example') { p.example.doit }
519
+ end
520
+ end
521
+
522
+ REQUIRES = ArtifactNamespace.for(self) do |ns|
523
+ ns.xmlbeans! 'org.apache.xmlbeans:xmlbeans:jar:2.3.0', '>2'
524
+ ns.stax_api! 'stax:stax-api:jar:>=1.0.1'
525
+ end
526
+
527
+ attr_reader :options, :requires
528
+
529
+ def initialize
530
+ # We could actually use the REQUIRES namespace, but to make things
531
+ # a bit more interesting, suppose each Example instance can have its
532
+ # own artifact requirements in adition to those specified on REQUIRES.
533
+ # To achieve this we create an anonymous namespace.
534
+ @requires = ArtifactNamespace.new # a namespace per instance
535
+ REQUIRES.each { |requirement| @requires.need requirement }
536
+
537
+ # For user convenience, we make the options object respond to
538
+ # :xmlbeans, :xmlbeans=, :xmlbeans?
539
+ # forwarding them to the namespace.
540
+ @options = OpenObject.new.extend(@requires.accessor(:xmlbeans, :stax_api))
541
+ # Register callbacks so we can perform some logic when an artifact
542
+ # is selected by the user.
543
+ options.xmlbeans.add_listener &method(:selected_xmlbeans)
544
+ options.stax_api.add_listener do |stax|
545
+ # Now using a proc
546
+ stax.should be_selected
547
+ stax.version.should == '1.6180'
548
+ options[:math] = :golden # customize our options for this version
549
+ # In this example we set the stax version when running outside
550
+ # a project definition. This means we have no access to the project
551
+ # namespace unless we had a reference to the project or knew it's name
552
+ Buildr.artifact_ns(:current).name.should == 'root'
553
+ end
554
+ end
555
+
556
+ include Spec::Matchers # for assertions
557
+
558
+ # Called with the ArtifactRequirement that has just been selected
559
+ # by a user. This allows extension author to selectively perform
560
+ # some action by inspecting the requirement state.
561
+ def selected_xmlbeans(xmlbeans)
562
+ xmlbeans.should be_selected
563
+ xmlbeans.version.should == '3.1415'
564
+ options[:math] = :pi
565
+ # This example just sets xmlbeans for foo:bar project
566
+ # So the currently running namespace should have the foo:bar name
567
+ Buildr.artifact_ns(:current).name.should == 'foo:bar'
568
+ end
569
+
570
+ # Suppose we invoke an ant task here or something else.
571
+ def doit
572
+ # Now call ant task with our selected artifact and options
573
+ classpath = requires.map(&:artifact).map(&:to_s).join(File::PATH_SEPARATOR)
574
+ lambda { ant('thing') { |ant| ant.classpath classpath, :math => options[:math] } }
575
+
576
+ # We are not a Project instance, hence we have no artifact_ns
577
+ lambda { artifact_ns }.should raise_error(NameError)
578
+
579
+ # Extension authors may NOT rely project's namespaces.
580
+ # However the ruby-way gives you power and at the same time
581
+ # makes you dangerous, (think open-modules, monkey-patching)
582
+ # Given that buildr is pure ruby, consider it a sharp-edged sword.
583
+ # Having said that, you may actually inspect a project's
584
+ # namespace, but don't write on it without letting your users
585
+ # know you will.
586
+ # This example obtains the current project namespace to make
587
+ # some assertions.
588
+
589
+ # To obtain a project's namespace we need either
590
+ # 1) a reference to the project, and call artifact_ns on it
591
+ # project.artifact_ns # the namespace for project
592
+ # 2) know the project name
593
+ # Buildr.artifact_ns('the:project')
594
+ # 3) Use :current to reference the currently running project
595
+ # Buildr.artifact_ns(:current)
596
+ name = Buildr.artifact_ns(:current).name
597
+ case name
598
+ when 'foo:bar'
599
+ options[:math].should == :pi
600
+ requires.xmlbeans.version.should == '3.1415'
601
+ requires.stax_api.version.should == '1.0.1'
602
+ when 'foo:baz'
603
+ options[:math].should == :golden
604
+ requires.xmlbeans.version.should == '2.3.0'
605
+ requires.stax_api.version.should == '1.6180'
606
+ else
607
+ fail "This example expects foo:bar or foo:baz projects not #{name.inspect}"
608
+ end
609
+ end
610
+ end
611
+
612
+ define 'foo' do
613
+ define 'bar' do
614
+ extend A::Example::Ext
615
+ task('setup') do
616
+ example.options.xmlbeans = '3.1415'
617
+ end
618
+ task('run' => [:setup, :example])
619
+ end
620
+ define 'baz' do
621
+ extend A::Example::Ext
622
+ end
623
+ end
624
+
625
+ project('foo:bar').example.requires.should_not == project('foo:baz').example.requires
626
+ project('foo:bar').example.requires.xmlbeans.should_not == project('foo:baz').example.requires.xmlbeans
627
+
628
+ # current namespace outside a project is :root, see the stax callback
629
+ project('foo:baz').example.options.stax_api = '1.6180'
630
+ # we call the task outside the project, see #doit
631
+ lambda { task('foo:bar:run').invoke }.should run_task('foo:bar:example')
632
+ lambda { task('foo:baz:example').invoke }.should run_task('foo:baz:example')
633
+ end
634
+ end
635
+ end