buildr 1.3.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +998 -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 +244 -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 +79 -0
  40. data/doc/extending.textile +186 -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 +266 -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 +430 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +271 -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 +280 -0
  68. data/doc/testing.textile +222 -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 +656 -0
  73. data/lib/buildr/core/build.rb +452 -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 +362 -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 +866 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +723 -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 +334 -0
  94. data/lib/buildr/ide/eclipse/java.rb +53 -0
  95. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  96. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  97. data/lib/buildr/ide/idea.ipr.template +300 -0
  98. data/lib/buildr/ide/idea.rb +190 -0
  99. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  100. data/lib/buildr/ide/idea7x.rb +212 -0
  101. data/lib/buildr/java.rb +23 -0
  102. data/lib/buildr/java/ant.rb +94 -0
  103. data/lib/buildr/java/bdd.rb +459 -0
  104. data/lib/buildr/java/cobertura.rb +274 -0
  105. data/lib/buildr/java/commands.rb +213 -0
  106. data/lib/buildr/java/compiler.rb +349 -0
  107. data/lib/buildr/java/deprecated.rb +141 -0
  108. data/lib/buildr/java/emma.rb +244 -0
  109. data/lib/buildr/java/jruby.rb +117 -0
  110. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  111. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +137 -0
  113. data/lib/buildr/java/packaging.rb +716 -0
  114. data/lib/buildr/java/pom.rb +174 -0
  115. data/lib/buildr/java/rjb.rb +155 -0
  116. data/lib/buildr/java/test_result.rb +353 -0
  117. data/lib/buildr/java/tests.rb +333 -0
  118. data/lib/buildr/java/version_requirement.rb +172 -0
  119. data/lib/buildr/packaging.rb +24 -0
  120. data/lib/buildr/packaging/archive.rb +488 -0
  121. data/lib/buildr/packaging/artifact.rb +749 -0
  122. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  123. data/lib/buildr/packaging/artifact_search.rb +140 -0
  124. data/lib/buildr/packaging/gems.rb +102 -0
  125. data/lib/buildr/packaging/package.rb +238 -0
  126. data/lib/buildr/packaging/tar.rb +186 -0
  127. data/lib/buildr/packaging/version_requirement.rb +172 -0
  128. data/lib/buildr/packaging/zip.rb +73 -0
  129. data/lib/buildr/packaging/ziptask.rb +316 -0
  130. data/lib/buildr/resources/buildr.icns +0 -0
  131. data/lib/buildr/scala.rb +25 -0
  132. data/lib/buildr/scala/bdd.rb +109 -0
  133. data/lib/buildr/scala/compiler.rb +195 -0
  134. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  137. data/lib/buildr/scala/shell.rb +55 -0
  138. data/lib/buildr/scala/tests.rb +157 -0
  139. data/lib/buildr/shell.rb +180 -0
  140. data/rakelib/checks.rake +57 -0
  141. data/rakelib/doc.rake +92 -0
  142. data/rakelib/jekylltask.rb +120 -0
  143. data/rakelib/package.rake +73 -0
  144. data/rakelib/release.rake +149 -0
  145. data/rakelib/rspec.rake +73 -0
  146. data/rakelib/setup.rake +54 -0
  147. data/rakelib/stage.rake +213 -0
  148. data/rakelib/stage.rake~ +213 -0
  149. data/spec/addon/drb_spec.rb +328 -0
  150. data/spec/core/application_spec.rb +502 -0
  151. data/spec/core/build_spec.rb +677 -0
  152. data/spec/core/checks_spec.rb +519 -0
  153. data/spec/core/common_spec.rb +670 -0
  154. data/spec/core/compile_spec.rb +583 -0
  155. data/spec/core/extension_spec.rb +93 -0
  156. data/spec/core/generate_spec.rb +33 -0
  157. data/spec/core/project_spec.rb +762 -0
  158. data/spec/core/test_spec.rb +1098 -0
  159. data/spec/core/transport_spec.rb +537 -0
  160. data/spec/core/util_spec.rb +67 -0
  161. data/spec/groovy/bdd_spec.rb +80 -0
  162. data/spec/groovy/compiler_spec.rb +240 -0
  163. data/spec/ide/eclipse_spec.rb +501 -0
  164. data/spec/ide/idea7x_spec.rb +84 -0
  165. data/spec/java/ant_spec.rb +33 -0
  166. data/spec/java/bdd_spec.rb +382 -0
  167. data/spec/java/cobertura_spec.rb +85 -0
  168. data/spec/java/compiler_spec.rb +446 -0
  169. data/spec/java/emma_spec.rb +119 -0
  170. data/spec/java/java_spec.rb +124 -0
  171. data/spec/java/packaging_spec.rb +1134 -0
  172. data/spec/java/test_coverage_helper.rb +257 -0
  173. data/spec/java/tests_spec.rb +493 -0
  174. data/spec/packaging/archive_spec.rb +527 -0
  175. data/spec/packaging/artifact_namespace_spec.rb +654 -0
  176. data/spec/packaging/artifact_spec.rb +795 -0
  177. data/spec/packaging/packaging_helper.rb +63 -0
  178. data/spec/packaging/packaging_spec.rb +684 -0
  179. data/spec/sandbox.rb +142 -0
  180. data/spec/scala/bdd_spec.rb +119 -0
  181. data/spec/scala/compiler_spec.rb +284 -0
  182. data/spec/scala/scala.rb +38 -0
  183. data/spec/scala/tests_spec.rb +261 -0
  184. data/spec/spec_helpers.rb +340 -0
  185. data/spec/version_requirement_spec.rb +129 -0
  186. metadata +383 -0
@@ -0,0 +1,654 @@
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 '#method_missing' do
361
+ it 'should use cool_aid! to create a requirement' do
362
+ define 'foo' do
363
+ artifact_ns.cool_aid!('cool:aid:jar:2').should be_kind_of(ArtifactNamespace::ArtifactRequirement)
364
+ artifact_ns[:cool_aid].version.should == '2'
365
+ artifact_ns[:cool_aid].should_not be_selected
366
+ define 'bar' do
367
+ artifact_ns.cool_aid! 'cool:aid:man:3', '>2'
368
+ artifact_ns[:cool_aid].version.should == '3'
369
+ artifact_ns[:cool_aid].requirement.should be_satisfied_by('2.5')
370
+ artifact_ns[:cool_aid].should_not be_selected
371
+ end
372
+ end
373
+ end
374
+
375
+ it 'should use cool_aid= as shorhand for [:cool_aid]=' do
376
+ artifact_ns.cool_aid = 'cool:aid:jar:1'
377
+ artifact_ns[:cool_aid].should be_selected
378
+ end
379
+
380
+ it 'should use cool_aid as shorthand for [:cool_aid]' do
381
+ artifact_ns.need :cool_aid => 'cool:aid:jar:1'
382
+ artifact_ns.cool_aid.should_not be_selected
383
+ end
384
+
385
+ it 'should use cool_aid? to test if artifact has been defined and selected' do
386
+ artifact_ns.need :cool_aid => 'cool:aid:jar:>1'
387
+ artifact_ns.should_not have_cool_aid
388
+ artifact_ns.should_not have_unknown
389
+ artifact_ns.cool_aid = '2'
390
+ artifact_ns.should have_cool_aid
391
+ end
392
+ end
393
+
394
+ describe '#ns' do
395
+ it 'should create a sub namespace' do
396
+ artifact_ns.ns :foo
397
+ artifact_ns[:foo].should be_kind_of(ArtifactNamespace)
398
+ artifact_ns(:foo).should_not === artifact_ns.foo
399
+ artifact_ns.foo.parent.should == artifact_ns
400
+ end
401
+
402
+ it 'should take any use arguments' do
403
+ artifact_ns.ns :foo, :bar => 'foo:bar:jar:0', :baz => 'foo:baz:jar:0'
404
+ artifact_ns.foo.bar.should be_selected
405
+ artifact_ns.foo[:baz].should be_selected
406
+ end
407
+
408
+ it 'should access sub artifacts using with foo_bar like syntax' do
409
+ artifact_ns.ns :foo, :bar => 'foo:bar:jar:0', :baz => 'foo:baz:jar:0'
410
+ artifact_ns[:foo_baz].should be_selected
411
+ artifact_ns.foo_bar.should be_selected
412
+
413
+ artifact_ns.foo.ns :bat, 'bat:man:jar:>1'
414
+ batman = artifact_ns.foo.bat.man
415
+ batman.should be_selected
416
+ artifact_ns[:foo_bat_man] = '3'
417
+ artifact_ns[:foo_bat_man].should == batman
418
+ artifact_ns[:foo_bat_man].version.should == '3'
419
+ end
420
+
421
+ it 'should include sub artifacts when calling #values' do
422
+ artifact_ns.ns :bat, 'bat:man:jar:>1'
423
+ artifact_ns.values.should_not be_empty
424
+ artifact_ns.values.first.unversioned_spec.should == 'bat:man:jar'
425
+ end
426
+
427
+ it 'should reopen a sub-namespace' do
428
+ artifact_ns.ns :bat, 'bat:man:jar:>1'
429
+ bat = artifact_ns[:bat]
430
+ bat.should == artifact_ns.ns(:bat)
431
+ end
432
+
433
+ it 'should fail reopening if not a sub-namespace' do
434
+ artifact_ns.foo = 'foo:bar:baz:0'
435
+ lambda { artifact_ns.ns(:foo) }.should raise_error(TypeError, /not a sub/i)
436
+ end
437
+
438
+ it 'should clone artifacts when assigned' do
439
+ artifact_ns(:foo).bar = "foo:bar:jar:0"
440
+ artifact_ns(:moo).ns :muu, :miu => artifact_ns(:foo).bar
441
+ artifact_ns(:moo).muu.miu.should_not == artifact_ns(:foo).bar
442
+ artifact_ns(:moo).muu.miu.to_spec.should == artifact_ns(:foo).bar.to_spec
443
+ end
444
+
445
+ it 'should clone parent artifacts by name' do
446
+ define 'foo' do
447
+ artifact_ns.bar = "foo:bar:jar:0"
448
+ define 'moo' do
449
+ artifact_ns.ns(:muu).use :bar
450
+ artifact_ns.muu_bar.should be_selected
451
+ artifact_ns.muu.bar.should_not == artifact_ns.bar
452
+ end
453
+ end
454
+ end
455
+ end
456
+
457
+ it 'should be an Enumerable' do
458
+ artifact_ns.should be_kind_of(Enumerable)
459
+ artifact_ns.use 'foo:bar:baz:1.0'
460
+ artifact_ns.map(&:artifact).should include(artifact('foo:bar:baz:1.0'))
461
+ end
462
+
463
+ end # ArtifactNamespace
464
+
465
+ describe Buildr do
466
+ before(:each) { Buildr::ArtifactNamespace.clear }
467
+
468
+ describe '.artifacts' do
469
+ it 'should take ruby symbols and ask the current namespace for them' do
470
+ define 'foo' do
471
+ artifact_ns.cool = 'cool:aid:jar:1.0'
472
+ artifact_ns.use 'some:other:jar:1.0'
473
+ artifact_ns.use 'bat:man:jar:1.0'
474
+ compile.with :cool, :other, :'bat:man:jar'
475
+ compile.dependencies.map(&:to_spec).should include('cool:aid:jar:1.0', 'some:other:jar:1.0', 'bat:man:jar:1.0')
476
+ end
477
+ end
478
+
479
+ it 'should take a namespace' do
480
+ artifact_ns(:moo).muu = 'moo:muu:jar:1.0'
481
+ define 'foo' do
482
+ compile.with artifact_ns(:moo)
483
+ compile.dependencies.map(&:to_spec).should include('moo:muu:jar:1.0')
484
+ end
485
+ end
486
+ end
487
+
488
+ describe '.artifact' do
489
+ it 'should search current namespace if given a symbol' do
490
+ define 'foo' do
491
+ artifact_ns.use :cool => 'cool:aid:jar:1.0'
492
+ define 'bar' do
493
+ artifact(:cool).should == artifact_ns[:cool].artifact
494
+ end
495
+ end
496
+ end
497
+
498
+ it 'should search current namespace if given a symbol spec' do
499
+ define 'foo' do
500
+ artifact_ns.use 'cool:aid:jar:1.0'
501
+ define 'bar' do
502
+ artifact(:'cool:aid:jar').should == artifact_ns[:aid].artifact
503
+ end
504
+ end
505
+ end
506
+
507
+ it 'should fail when no artifact by that name is found' do
508
+ define 'foo' do
509
+ artifact_ns.use 'cool:aid:jar:1.0'
510
+ define 'bar' do
511
+ lambda { artifact(:cool) }.should raise_error(IndexError, /artifact/)
512
+ end
513
+ end
514
+ end
515
+ end
516
+ end
517
+
518
+ describe "Extension using ArtifactNamespace" do
519
+ before(:each) { Buildr::ArtifactNamespace.clear }
520
+
521
+ def abc_module
522
+ Object.module_eval 'module A; module B; module C; end; end; end'
523
+ yield
524
+ ensure
525
+ Object.send :remove_const, :A
526
+ end
527
+
528
+ it 'can register namespace listeners' do
529
+ abc_module do
530
+ # An example extension to illustrate namespace listeners and method forwarding
531
+ class A::Example
532
+
533
+ module Ext
534
+ include Buildr::Extension
535
+ def example; @example ||= A::Example.new; end
536
+ before_define do |p|
537
+ Rake::Task.define_task('example') { p.example.doit }
538
+ end
539
+ end
540
+
541
+ REQUIRES = ArtifactNamespace.for(self) do |ns|
542
+ ns.xmlbeans! 'org.apache.xmlbeans:xmlbeans:jar:2.3.0', '>2'
543
+ ns.stax_api! 'stax:stax-api:jar:>=1.0.1'
544
+ end
545
+
546
+ attr_reader :options, :requires
547
+
548
+ def initialize
549
+ # We could actually use the REQUIRES namespace, but to make things
550
+ # a bit more interesting, suppose each Example instance can have its
551
+ # own artifact requirements in adition to those specified on REQUIRES.
552
+ # To achieve this we create an anonymous namespace.
553
+ @requires = ArtifactNamespace.new # a namespace per instance
554
+ REQUIRES.each { |requirement| @requires.need requirement }
555
+
556
+ # For user convenience, we make the options object respond to
557
+ # :xmlbeans, :xmlbeans=, :xmlbeans?
558
+ # forwarding them to the namespace.
559
+ @options = OpenObject.new.extend(@requires.accessor(:xmlbeans, :stax_api))
560
+ # Register callbacks so we can perform some logic when an artifact
561
+ # is selected by the user.
562
+ options.xmlbeans.add_listener &method(:selected_xmlbeans)
563
+ options.stax_api.add_listener do |stax|
564
+ # Now using a proc
565
+ stax.should be_selected
566
+ stax.version.should == '1.6180'
567
+ options[:math] = :golden # customize our options for this version
568
+ # In this example we set the stax version when running outside
569
+ # a project definition. This means we have no access to the project
570
+ # namespace unless we had a reference to the project or knew it's name
571
+ Buildr.artifact_ns(:current).name.should == 'root'
572
+ end
573
+ end
574
+
575
+ include Spec::Matchers # for assertions
576
+
577
+ # Called with the ArtifactRequirement that has just been selected
578
+ # by a user. This allows extension author to selectively perform
579
+ # some action by inspecting the requirement state.
580
+ def selected_xmlbeans(xmlbeans)
581
+ xmlbeans.should be_selected
582
+ xmlbeans.version.should == '3.1415'
583
+ options[:math] = :pi
584
+ # This example just sets xmlbeans for foo:bar project
585
+ # So the currently running namespace should have the foo:bar name
586
+ Buildr.artifact_ns(:current).name.should == 'foo:bar'
587
+ end
588
+
589
+ # Suppose we invoke an ant task here or something else.
590
+ def doit
591
+ # Now call ant task with our selected artifact and options
592
+ classpath = requires.map(&:artifact).map(&:to_s).join(File::PATH_SEPARATOR)
593
+ lambda { ant('thing') { |ant| ant.classpath classpath, :math => options[:math] } }
594
+
595
+ # We are not a Project instance, hence we have no artifact_ns
596
+ lambda { artifact_ns }.should raise_error(NameError)
597
+
598
+ # Extension authors may NOT rely project's namespaces.
599
+ # However the ruby-way gives you power and at the same time
600
+ # makes you dangerous, (think open-modules, monkey-patching)
601
+ # Given that buildr is pure ruby, consider it a sharp-edged sword.
602
+ # Having said that, you may actually inspect a project's
603
+ # namespace, but don't write on it without letting your users
604
+ # know you will.
605
+ # This example obtains the current project namespace to make
606
+ # some assertions.
607
+
608
+ # To obtain a project's namespace we need either
609
+ # 1) a reference to the project, and call artifact_ns on it
610
+ # project.artifact_ns # the namespace for project
611
+ # 2) know the project name
612
+ # Buildr.artifact_ns('the:project')
613
+ # 3) Use :current to reference the currently running project
614
+ # Buildr.artifact_ns(:current)
615
+ name = Buildr.artifact_ns(:current).name
616
+ case name
617
+ when 'foo:bar'
618
+ options[:math].should == :pi
619
+ requires.xmlbeans.version.should == '3.1415'
620
+ requires.stax_api.version.should == '1.0.1'
621
+ when 'foo:baz'
622
+ options[:math].should == :golden
623
+ requires.xmlbeans.version.should == '2.3.0'
624
+ requires.stax_api.version.should == '1.6180'
625
+ else
626
+ fail "This example expects foo:bar or foo:baz projects not #{name.inspect}"
627
+ end
628
+ end
629
+ end
630
+
631
+ define 'foo' do
632
+ define 'bar' do
633
+ extend A::Example::Ext
634
+ task('setup') do
635
+ example.options.xmlbeans = '3.1415'
636
+ end
637
+ task('run' => [:setup, :example])
638
+ end
639
+ define 'baz' do
640
+ extend A::Example::Ext
641
+ end
642
+ end
643
+
644
+ project('foo:bar').example.requires.should_not == project('foo:baz').example.requires
645
+ project('foo:bar').example.requires.xmlbeans.should_not == project('foo:baz').example.requires.xmlbeans
646
+
647
+ # current namespace outside a project is :root, see the stax callback
648
+ project('foo:baz').example.options.stax_api = '1.6180'
649
+ # we call the task outside the project, see #doit
650
+ lambda { task('foo:bar:run').invoke }.should run_task('foo:bar:example')
651
+ lambda { task('foo:baz:example').invoke }.should run_task('foo:baz:example')
652
+ end
653
+ end
654
+ end