novoda-buildr 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/CHANGELOG +1050 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +245 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +90 -0
  40. data/doc/extending.textile +205 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +265 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +429 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +276 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +287 -0
  68. data/doc/testing.textile +233 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +662 -0
  73. data/lib/buildr/core/build.rb +463 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +363 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +971 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +774 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +424 -0
  94. data/lib/buildr/ide/eclipse.rb~ +424 -0
  95. data/lib/buildr/ide/eclipse/java.rb +53 -0
  96. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  97. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  98. data/lib/buildr/ide/idea.ipr.template +300 -0
  99. data/lib/buildr/ide/idea.rb +190 -0
  100. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  101. data/lib/buildr/ide/idea7x.rb +212 -0
  102. data/lib/buildr/java.rb +23 -0
  103. data/lib/buildr/java/ant.rb +94 -0
  104. data/lib/buildr/java/bdd.rb +464 -0
  105. data/lib/buildr/java/cobertura.rb +274 -0
  106. data/lib/buildr/java/commands.rb +217 -0
  107. data/lib/buildr/java/compiler.rb +349 -0
  108. data/lib/buildr/java/deprecated.rb +141 -0
  109. data/lib/buildr/java/emma.rb +244 -0
  110. data/lib/buildr/java/jruby.rb +117 -0
  111. data/lib/buildr/java/jtestr_runner.rb.erb +118 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  113. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  114. data/lib/buildr/java/packaging.rb +717 -0
  115. data/lib/buildr/java/pom.rb +174 -0
  116. data/lib/buildr/java/rjb.rb +155 -0
  117. data/lib/buildr/java/test_result.rb +327 -0
  118. data/lib/buildr/java/tests.rb +341 -0
  119. data/lib/buildr/java/version_requirement.rb +172 -0
  120. data/lib/buildr/packaging.rb +24 -0
  121. data/lib/buildr/packaging/archive.rb +491 -0
  122. data/lib/buildr/packaging/artifact.rb +750 -0
  123. data/lib/buildr/packaging/artifact_namespace.rb +980 -0
  124. data/lib/buildr/packaging/artifact_search.rb +140 -0
  125. data/lib/buildr/packaging/gems.rb +106 -0
  126. data/lib/buildr/packaging/package.rb +241 -0
  127. data/lib/buildr/packaging/tar.rb +186 -0
  128. data/lib/buildr/packaging/version_requirement.rb +172 -0
  129. data/lib/buildr/packaging/zip.rb +73 -0
  130. data/lib/buildr/packaging/ziptask.rb +316 -0
  131. data/lib/buildr/resources/buildr.icns +0 -0
  132. data/lib/buildr/scala.rb +25 -0
  133. data/lib/buildr/scala/bdd.rb +114 -0
  134. data/lib/buildr/scala/compiler.rb +196 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  137. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  138. data/lib/buildr/scala/shell.rb +60 -0
  139. data/lib/buildr/scala/tests.rb +157 -0
  140. data/lib/buildr/shell.rb +180 -0
  141. data/rakelib/all-in-one.rake +84 -0
  142. data/rakelib/checks.rake +57 -0
  143. data/rakelib/doc.rake +92 -0
  144. data/rakelib/jekylltask.rb +120 -0
  145. data/rakelib/package.rake +73 -0
  146. data/rakelib/release.rake +152 -0
  147. data/rakelib/rspec.rake +73 -0
  148. data/rakelib/setup.rake +54 -0
  149. data/rakelib/stage.rake +214 -0
  150. data/spec/addon/drb_spec.rb +328 -0
  151. data/spec/core/application_spec.rb +509 -0
  152. data/spec/core/build_spec.rb +678 -0
  153. data/spec/core/checks_spec.rb +519 -0
  154. data/spec/core/common_spec.rb +670 -0
  155. data/spec/core/compile_spec.rb +624 -0
  156. data/spec/core/extension_spec.rb +201 -0
  157. data/spec/core/generate_spec.rb +33 -0
  158. data/spec/core/project_spec.rb +762 -0
  159. data/spec/core/test_spec.rb +1175 -0
  160. data/spec/core/transport_spec.rb +537 -0
  161. data/spec/core/util_spec.rb +67 -0
  162. data/spec/groovy/bdd_spec.rb +80 -0
  163. data/spec/groovy/compiler_spec.rb +240 -0
  164. data/spec/ide/eclipse_spec.rb +650 -0
  165. data/spec/ide/idea7x_spec.rb +84 -0
  166. data/spec/java/ant_spec.rb +33 -0
  167. data/spec/java/bdd_spec.rb +379 -0
  168. data/spec/java/cobertura_spec.rb +85 -0
  169. data/spec/java/compiler_spec.rb +446 -0
  170. data/spec/java/emma_spec.rb +119 -0
  171. data/spec/java/java_spec.rb +124 -0
  172. data/spec/java/packaging_spec.rb +1140 -0
  173. data/spec/java/test_coverage_helper.rb +257 -0
  174. data/spec/java/tests_spec.rb +493 -0
  175. data/spec/packaging/archive_spec.rb +538 -0
  176. data/spec/packaging/artifact_namespace_spec.rb +697 -0
  177. data/spec/packaging/artifact_spec.rb +802 -0
  178. data/spec/packaging/packaging_helper.rb +63 -0
  179. data/spec/packaging/packaging_spec.rb +684 -0
  180. data/spec/sandbox.rb +148 -0
  181. data/spec/scala/bdd_spec.rb +119 -0
  182. data/spec/scala/compiler_spec.rb +284 -0
  183. data/spec/scala/scala.rb +38 -0
  184. data/spec/scala/tests_spec.rb +263 -0
  185. data/spec/spec_helpers.rb +340 -0
  186. data/spec/version_requirement_spec.rb +143 -0
  187. metadata +384 -0
@@ -0,0 +1,697 @@
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 register two artifacts with different version on namespace' do
252
+ define 'one' do
253
+ artifact_ns.use :foo => 'a:b:c:1'
254
+ artifact_ns.use :bar => 'a:b:c:2'
255
+ artifact_ns[:foo].version.should == '1'
256
+ artifact_ns[:bar].version.should == '2'
257
+ # unversioned references the last version set.
258
+ artifact_ns['a:b:c'].version.should == '2'
259
+ end
260
+ end
261
+
262
+ it 'should complain if namespace requirement is not satisfied' do
263
+ define 'one' do
264
+ artifact_ns.need :bar => 'foo:bar:baz:~>1.5'
265
+ lambda { artifact_ns.use :bar => '1.4' }.should raise_error(Exception, /unsatisfied/i)
266
+ end
267
+ end
268
+
269
+ it 'should be able to register a group' do
270
+ specs = ['its:me:here:1', 'its:you:there:2']
271
+ artifact_ns.use :them => specs
272
+ artifact_ns[:them].map(&:to_spec).should == specs
273
+ artifact_ns['its:me:here'].should_not be_nil
274
+ artifact_ns[:you].should be_nil
275
+ end
276
+
277
+ it 'should be able to assign sub namespaces' do
278
+ artifact_ns(:foo).bar = "foo:bar:baz:0"
279
+ artifact_ns(:moo).foo = artifact_ns(:foo)
280
+ artifact_ns(:moo).foo.should == artifact_ns(:foo)
281
+ artifact_ns(:moo).foo_bar.should == artifact_ns(:foo).bar
282
+ end
283
+
284
+ it 'should handle symbols with dashes and periods' do
285
+ [:'a-b', :'a.b'].each do |symbol|
286
+ artifact_ns.use symbol => 'a:b:c:1'
287
+ artifact_ns[symbol].version.should == '1'
288
+ artifact_ns[symbol].id.should == 'b'
289
+ end
290
+ end
291
+
292
+ end
293
+
294
+ describe '#values' do
295
+ it 'returns the artifacts defined on namespace' do
296
+ define 'foo' do
297
+ artifact_ns.use 'foo:one:baz:1.0'
298
+ define 'bar' do
299
+ artifact_ns.use 'foo:two:baz:1.0'
300
+
301
+ specs = artifact_ns.values.map(&:to_spec)
302
+ specs.should include('foo:two:baz:1.0')
303
+ specs.should_not include('foo:one:baz:1.0')
304
+
305
+ specs = artifact_ns.values(true).map(&:to_spec)
306
+ specs.should include('foo:two:baz:1.0', 'foo:one:baz:1.0')
307
+ end
308
+ end
309
+ end
310
+ end
311
+
312
+ describe '#values_at' do
313
+ it 'returns the named artifacts' do
314
+ define 'foo' do
315
+ artifact_ns.use 'foo:one:baz:1.0'
316
+ define 'bar' do
317
+ artifact_ns.use :foo_baz => 'foo:two:baz:1.0'
318
+
319
+ specs = artifact_ns.values_at('one').map(&:to_spec)
320
+ specs.should include('foo:one:baz:1.0')
321
+ specs.should_not include('foo:two:baz:1.0')
322
+
323
+ specs = artifact_ns.values_at('foo_baz').map(&:to_spec)
324
+ specs.should include('foo:two:baz:1.0')
325
+ specs.should_not include('foo:one:baz:1.0')
326
+ end
327
+ end
328
+ end
329
+
330
+ it 'returns first artifacts by their unversioned spec' do
331
+ define 'foo' do
332
+ artifact_ns.use 'foo:one:baz:2.0'
333
+ define 'bar' do
334
+ artifact_ns.use :older => 'foo:one:baz:1.0'
335
+
336
+ specs = artifact_ns.values_at('foo:one:baz').map(&:to_spec)
337
+ specs.should include('foo:one:baz:1.0')
338
+ specs.should_not include('foo:one:baz:2.0')
339
+ end
340
+ specs = artifact_ns.values_at('foo:one:baz').map(&:to_spec)
341
+ specs.should include('foo:one:baz:2.0')
342
+ specs.should_not include('foo:one:baz:1.0')
343
+ end
344
+ end
345
+
346
+ it 'return first artifact satisfying a dependency' do
347
+ define 'foo' do
348
+ artifact_ns.use 'foo:one:baz:2.0'
349
+ define 'bar' do
350
+ artifact_ns.use :older => 'foo:one:baz:1.0'
351
+
352
+ specs = artifact_ns.values_at('foo:one:baz:>1.0').map(&:to_spec)
353
+ specs.should include('foo:one:baz:2.0')
354
+ specs.should_not include('foo:one:baz:1.0')
355
+ end
356
+ end
357
+ end
358
+ end
359
+
360
+ describe '#artifacts' do
361
+ it 'returns artifacts in namespace' do
362
+ define 'one' do
363
+ artifact_ns[:foo] = 'group:foo:jar:1'
364
+ artifact_ns[:bar] = 'group:bar:jar:1'
365
+ artifact_ns.artifacts.map{|a| a.to_spec}.should include('group:foo:jar:1', 'group:bar:jar:1')
366
+ end
367
+ end
368
+ end
369
+
370
+ describe '#keys' do
371
+ it 'returns names in namespace' do
372
+ define 'one' do
373
+ artifact_ns[:foo] = 'group:foo:jar:1'
374
+ artifact_ns[:bar] = 'group:bar:jar:1'
375
+ artifact_ns.keys.should include('foo', 'bar')
376
+ end
377
+ end
378
+ end
379
+
380
+ describe '#delete' do
381
+ it 'deletes corresponding artifact requirement' do
382
+ define 'one' do
383
+ artifact_ns[:foo] = 'group:foo:jar:1'
384
+ artifact_ns[:bar] = 'group:bar:jar:1'
385
+ artifact_ns.delete :bar
386
+ artifact_ns.artifacts.map{|a| a.to_spec}.should include('group:foo:jar:1')
387
+ artifact_ns[:foo].to_spec.should eql('group:foo:jar:1')
388
+ end
389
+ end
390
+ end
391
+
392
+ describe '#clear' do
393
+ it 'clears all artifact requirements in namespace' do
394
+ define 'one' do
395
+ artifact_ns[:foo] = 'group:foo:jar:1'
396
+ artifact_ns[:bar] = 'group:bar:jar:1'
397
+ artifact_ns.clear
398
+ artifact_ns.artifacts.should be_empty
399
+ end
400
+ end
401
+ end
402
+
403
+ describe '#method_missing' do
404
+ it 'should use cool_aid! to create a requirement' do
405
+ define 'foo' do
406
+ artifact_ns.cool_aid!('cool:aid:jar:2').should be_kind_of(ArtifactNamespace::ArtifactRequirement)
407
+ artifact_ns[:cool_aid].version.should == '2'
408
+ artifact_ns[:cool_aid].should_not be_selected
409
+ define 'bar' do
410
+ artifact_ns.cool_aid! 'cool:aid:man:3', '>2'
411
+ artifact_ns[:cool_aid].version.should == '3'
412
+ artifact_ns[:cool_aid].requirement.should be_satisfied_by('2.5')
413
+ artifact_ns[:cool_aid].should_not be_selected
414
+ end
415
+ end
416
+ end
417
+
418
+ it 'should use cool_aid= as shorhand for [:cool_aid]=' do
419
+ artifact_ns.cool_aid = 'cool:aid:jar:1'
420
+ artifact_ns[:cool_aid].should be_selected
421
+ end
422
+
423
+ it 'should use cool_aid as shorthand for [:cool_aid]' do
424
+ artifact_ns.need :cool_aid => 'cool:aid:jar:1'
425
+ artifact_ns.cool_aid.should_not be_selected
426
+ end
427
+
428
+ it 'should use cool_aid? to test if artifact has been defined and selected' do
429
+ artifact_ns.need :cool_aid => 'cool:aid:jar:>1'
430
+ artifact_ns.should_not have_cool_aid
431
+ artifact_ns.should_not have_unknown
432
+ artifact_ns.cool_aid = '2'
433
+ artifact_ns.should have_cool_aid
434
+ end
435
+ end
436
+
437
+ describe '#ns' do
438
+ it 'should create a sub namespace' do
439
+ artifact_ns.ns :foo
440
+ artifact_ns[:foo].should be_kind_of(ArtifactNamespace)
441
+ artifact_ns(:foo).should_not === artifact_ns.foo
442
+ artifact_ns.foo.parent.should == artifact_ns
443
+ end
444
+
445
+ it 'should take any use arguments' do
446
+ artifact_ns.ns :foo, :bar => 'foo:bar:jar:0', :baz => 'foo:baz:jar:0'
447
+ artifact_ns.foo.bar.should be_selected
448
+ artifact_ns.foo[:baz].should be_selected
449
+ end
450
+
451
+ it 'should access sub artifacts using with foo_bar like syntax' do
452
+ artifact_ns.ns :foo, :bar => 'foo:bar:jar:0', :baz => 'foo:baz:jar:0'
453
+ artifact_ns[:foo_baz].should be_selected
454
+ artifact_ns.foo_bar.should be_selected
455
+
456
+ artifact_ns.foo.ns :bat, 'bat:man:jar:>1'
457
+ batman = artifact_ns.foo.bat.man
458
+ batman.should be_selected
459
+ artifact_ns[:foo_bat_man] = '3'
460
+ artifact_ns[:foo_bat_man].should == batman
461
+ artifact_ns[:foo_bat_man].version.should == '3'
462
+ end
463
+
464
+ it 'should include sub artifacts when calling #values' do
465
+ artifact_ns.ns :bat, 'bat:man:jar:>1'
466
+ artifact_ns.values.should_not be_empty
467
+ artifact_ns.values.first.unversioned_spec.should == 'bat:man:jar'
468
+ end
469
+
470
+ it 'should reopen a sub-namespace' do
471
+ artifact_ns.ns :bat, 'bat:man:jar:>1'
472
+ bat = artifact_ns[:bat]
473
+ bat.should == artifact_ns.ns(:bat)
474
+ end
475
+
476
+ it 'should fail reopening if not a sub-namespace' do
477
+ artifact_ns.foo = 'foo:bar:baz:0'
478
+ lambda { artifact_ns.ns(:foo) }.should raise_error(TypeError, /not a sub/i)
479
+ end
480
+
481
+ it 'should clone artifacts when assigned' do
482
+ artifact_ns(:foo).bar = "foo:bar:jar:0"
483
+ artifact_ns(:moo).ns :muu, :miu => artifact_ns(:foo).bar
484
+ artifact_ns(:moo).muu.miu.should_not == artifact_ns(:foo).bar
485
+ artifact_ns(:moo).muu.miu.to_spec.should == artifact_ns(:foo).bar.to_spec
486
+ end
487
+
488
+ it 'should clone parent artifacts by name' do
489
+ define 'foo' do
490
+ artifact_ns.bar = "foo:bar:jar:0"
491
+ define 'moo' do
492
+ artifact_ns.ns(:muu).use :bar
493
+ artifact_ns.muu_bar.should be_selected
494
+ artifact_ns.muu.bar.should_not == artifact_ns.bar
495
+ end
496
+ end
497
+ end
498
+ end
499
+
500
+ it 'should be an Enumerable' do
501
+ artifact_ns.should be_kind_of(Enumerable)
502
+ artifact_ns.use 'foo:bar:baz:1.0'
503
+ artifact_ns.map(&:artifact).should include(artifact('foo:bar:baz:1.0'))
504
+ end
505
+
506
+ end # ArtifactNamespace
507
+
508
+ describe Buildr do
509
+ before(:each) { Buildr::ArtifactNamespace.clear }
510
+
511
+ describe '.artifacts' do
512
+ it 'should take ruby symbols and ask the current namespace for them' do
513
+ define 'foo' do
514
+ artifact_ns.cool = 'cool:aid:jar:1.0'
515
+ artifact_ns.use 'some:other:jar:1.0'
516
+ artifact_ns.use 'bat:man:jar:1.0'
517
+ compile.with :cool, :other, :'bat:man:jar'
518
+ compile.dependencies.map(&:to_spec).should include('cool:aid:jar:1.0', 'some:other:jar:1.0', 'bat:man:jar:1.0')
519
+ end
520
+ end
521
+
522
+ it 'should take a namespace' do
523
+ artifact_ns(:moo).muu = 'moo:muu:jar:1.0'
524
+ define 'foo' do
525
+ compile.with artifact_ns(:moo)
526
+ compile.dependencies.map(&:to_spec).should include('moo:muu:jar:1.0')
527
+ end
528
+ end
529
+ end
530
+
531
+ describe '.artifact' do
532
+ it 'should search current namespace if given a symbol' do
533
+ define 'foo' do
534
+ artifact_ns.use :cool => 'cool:aid:jar:1.0'
535
+ define 'bar' do
536
+ artifact(:cool).should == artifact_ns[:cool].artifact
537
+ end
538
+ end
539
+ end
540
+
541
+ it 'should search current namespace if given a symbol spec' do
542
+ define 'foo' do
543
+ artifact_ns.use 'cool:aid:jar:1.0'
544
+ define 'bar' do
545
+ artifact(:'cool:aid:jar').should == artifact_ns[:aid].artifact
546
+ end
547
+ end
548
+ end
549
+
550
+ it 'should fail when no artifact by that name is found' do
551
+ define 'foo' do
552
+ artifact_ns.use 'cool:aid:jar:1.0'
553
+ define 'bar' do
554
+ lambda { artifact(:cool) }.should raise_error(IndexError, /artifact/)
555
+ end
556
+ end
557
+ end
558
+ end
559
+ end
560
+
561
+ describe "Extension using ArtifactNamespace" do
562
+ before(:each) { Buildr::ArtifactNamespace.clear }
563
+
564
+ def abc_module
565
+ Object.module_eval 'module A; module B; module C; end; end; end'
566
+ yield
567
+ ensure
568
+ Object.send :remove_const, :A
569
+ end
570
+
571
+ it 'can register namespace listeners' do
572
+ abc_module do
573
+ # An example extension to illustrate namespace listeners and method forwarding
574
+ class A::Example
575
+
576
+ module Ext
577
+ include Buildr::Extension
578
+ def example; @example ||= A::Example.new; end
579
+ before_define do |p|
580
+ Rake::Task.define_task('example') { p.example.doit }
581
+ end
582
+ end
583
+
584
+ REQUIRES = ArtifactNamespace.for(self) do |ns|
585
+ ns.xmlbeans! 'org.apache.xmlbeans:xmlbeans:jar:2.3.0', '>2'
586
+ ns.stax_api! 'stax:stax-api:jar:>=1.0.1'
587
+ end
588
+
589
+ attr_reader :options, :requires
590
+
591
+ def initialize
592
+ # We could actually use the REQUIRES namespace, but to make things
593
+ # a bit more interesting, suppose each Example instance can have its
594
+ # own artifact requirements in adition to those specified on REQUIRES.
595
+ # To achieve this we create an anonymous namespace.
596
+ @requires = ArtifactNamespace.new # a namespace per instance
597
+ REQUIRES.each { |requirement| @requires.need requirement }
598
+
599
+ # For user convenience, we make the options object respond to
600
+ # :xmlbeans, :xmlbeans=, :xmlbeans?
601
+ # forwarding them to the namespace.
602
+ @options = OpenObject.new.extend(@requires.accessor(:xmlbeans, :stax_api))
603
+ # Register callbacks so we can perform some logic when an artifact
604
+ # is selected by the user.
605
+ options.xmlbeans.add_listener &method(:selected_xmlbeans)
606
+ options.stax_api.add_listener do |stax|
607
+ # Now using a proc
608
+ stax.should be_selected
609
+ stax.version.should == '1.6180'
610
+ options[:math] = :golden # customize our options for this version
611
+ # In this example we set the stax version when running outside
612
+ # a project definition. This means we have no access to the project
613
+ # namespace unless we had a reference to the project or knew it's name
614
+ Buildr.artifact_ns(:current).name.should == 'root'
615
+ end
616
+ end
617
+
618
+ include Spec::Matchers # for assertions
619
+
620
+ # Called with the ArtifactRequirement that has just been selected
621
+ # by a user. This allows extension author to selectively perform
622
+ # some action by inspecting the requirement state.
623
+ def selected_xmlbeans(xmlbeans)
624
+ xmlbeans.should be_selected
625
+ xmlbeans.version.should == '3.1415'
626
+ options[:math] = :pi
627
+ # This example just sets xmlbeans for foo:bar project
628
+ # So the currently running namespace should have the foo:bar name
629
+ Buildr.artifact_ns(:current).name.should == 'foo:bar'
630
+ end
631
+
632
+ # Suppose we invoke an ant task here or something else.
633
+ def doit
634
+ # Now call ant task with our selected artifact and options
635
+ classpath = requires.map(&:artifact).map(&:to_s).join(File::PATH_SEPARATOR)
636
+ lambda { ant('thing') { |ant| ant.classpath classpath, :math => options[:math] } }
637
+
638
+ # We are not a Project instance, hence we have no artifact_ns
639
+ lambda { artifact_ns }.should raise_error(NameError)
640
+
641
+ # Extension authors may NOT rely project's namespaces.
642
+ # However the ruby-way gives you power and at the same time
643
+ # makes you dangerous, (think open-modules, monkey-patching)
644
+ # Given that buildr is pure ruby, consider it a sharp-edged sword.
645
+ # Having said that, you may actually inspect a project's
646
+ # namespace, but don't write on it without letting your users
647
+ # know you will.
648
+ # This example obtains the current project namespace to make
649
+ # some assertions.
650
+
651
+ # To obtain a project's namespace we need either
652
+ # 1) a reference to the project, and call artifact_ns on it
653
+ # project.artifact_ns # the namespace for project
654
+ # 2) know the project name
655
+ # Buildr.artifact_ns('the:project')
656
+ # 3) Use :current to reference the currently running project
657
+ # Buildr.artifact_ns(:current)
658
+ name = Buildr.artifact_ns(:current).name
659
+ case name
660
+ when 'foo:bar'
661
+ options[:math].should == :pi
662
+ requires.xmlbeans.version.should == '3.1415'
663
+ requires.stax_api.version.should == '1.0.1'
664
+ when 'foo:baz'
665
+ options[:math].should == :golden
666
+ requires.xmlbeans.version.should == '2.3.0'
667
+ requires.stax_api.version.should == '1.6180'
668
+ else
669
+ fail "This example expects foo:bar or foo:baz projects not #{name.inspect}"
670
+ end
671
+ end
672
+ end
673
+
674
+ define 'foo' do
675
+ define 'bar' do
676
+ extend A::Example::Ext
677
+ task('setup') do
678
+ example.options.xmlbeans = '3.1415'
679
+ end
680
+ task('run' => [:setup, :example])
681
+ end
682
+ define 'baz' do
683
+ extend A::Example::Ext
684
+ end
685
+ end
686
+
687
+ project('foo:bar').example.requires.should_not == project('foo:baz').example.requires
688
+ project('foo:bar').example.requires.xmlbeans.should_not == project('foo:baz').example.requires.xmlbeans
689
+
690
+ # current namespace outside a project is :root, see the stax callback
691
+ project('foo:baz').example.options.stax_api = '1.6180'
692
+ # we call the task outside the project, see #doit
693
+ lambda { task('foo:bar:run').invoke }.should run_task('foo:bar:example')
694
+ lambda { task('foo:baz:example').invoke }.should run_task('foo:baz:example')
695
+ end
696
+ end
697
+ end