assaf-buildr 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -0,0 +1,754 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.join(File.dirname(__FILE__), '../spec_helpers')
18
+
19
+
20
+ describe Artifact do
21
+ before do
22
+ @spec = { :group=>'com.example', :id=>'library', :type=>:jar, :version=>'2.0' }
23
+ @artifact = artifact(@spec)
24
+ @classified = artifact(@spec.merge(:classifier=>'all'))
25
+ @snapshot = artifact(@spec.merge({ :version=>'2.1-SNAPSHOT' }))
26
+ end
27
+
28
+ it 'should act as one' do
29
+ @artifact.should respond_to(:to_spec)
30
+ end
31
+
32
+ it 'should have an artifact identifier' do
33
+ @artifact.id.should eql('library')
34
+ end
35
+
36
+ it 'should have a group identifier' do
37
+ @artifact.group.should eql('com.example')
38
+ end
39
+
40
+ it 'should have a version number' do
41
+ @artifact.version.should eql('2.0')
42
+ end
43
+
44
+ it 'should know if it is a snapshot' do
45
+ @artifact.should_not be_snapshot
46
+ @classified.should_not be_snapshot
47
+ @snapshot.should be_snapshot
48
+ end
49
+
50
+ it 'should have a file type' do
51
+ @artifact.type.should eql(:jar)
52
+ end
53
+
54
+ it 'should understand classifier' do
55
+ @artifact.classifier.should be_nil
56
+ @classified.classifier.should eql('all')
57
+ end
58
+
59
+ it 'should return hash specification' do
60
+ @artifact.to_hash.should == @spec
61
+ @artifact.to_spec_hash.should == @spec
62
+ @classified.to_hash.should == @spec.merge(:classifier=>'all')
63
+ end
64
+
65
+ it 'should return string specification' do
66
+ @artifact.to_spec.should eql('com.example:library:jar:2.0')
67
+ @classified.to_spec.should eql('com.example:library:jar:all:2.0')
68
+ end
69
+
70
+ it 'should have associated POM artifact' do
71
+ @artifact.pom.to_hash.should == @artifact.to_hash.merge(:type=>:pom)
72
+ end
73
+
74
+ it 'should have one artifact for all classifiers' do
75
+ @classified.pom.to_hash.should == @classified.to_hash.merge(:type=>:pom).except(:classifier)
76
+ end
77
+
78
+ it 'should download file if file does not exist' do
79
+ lambda { @artifact.invoke }.should raise_error(Exception, /No remote repositories/)
80
+ lambda { @classified.invoke }.should raise_error(Exception, /No remote repositories/)
81
+ end
82
+
83
+ it 'should not download file if file exists' do
84
+ write repositories.locate(@artifact)
85
+ lambda { @artifact.invoke }.should_not raise_error
86
+ write repositories.locate(@classified)
87
+ lambda { @classified.invoke }.should_not raise_error
88
+ end
89
+
90
+ it 'should handle lack of POM gracefully' do
91
+ repositories.remote = 'http://example.com'
92
+ URI.should_receive(:download).twice { |uri, target, options| raise URI::NotFoundError if uri.to_s.ends_with('.pom') }
93
+ lambda { @artifact.invoke }.should_not raise_error
94
+ end
95
+
96
+ it 'should pass if POM provided' do
97
+ repositories.remote = 'http://example.com'
98
+ @artifact.pom.enhance { |task| write task.name, @artifact.pom_xml }
99
+ write repositories.locate(@artifact)
100
+ lambda { @artifact.invoke }.should_not raise_error
101
+ end
102
+
103
+ it 'should pass if POM not required' do
104
+ repositories.remote = 'http://example.com'
105
+ class << @artifact ; def pom() ; end ; end
106
+ write repositories.locate(@artifact)
107
+ lambda { @artifact.invoke }.should_not raise_error
108
+ end
109
+
110
+ it 'should not download file if dry-run' do
111
+ dryrun do
112
+ lambda { @artifact.invoke }.should_not raise_error
113
+ lambda { @classified.invoke }.should_not raise_error
114
+ end
115
+ end
116
+
117
+ it 'should resolve to path in local repository' do
118
+ @artifact.to_s.should == File.join(repositories.local, 'com/example/library/2.0/library-2.0.jar')
119
+ @classified.to_s.should == File.join(repositories.local, 'com/example/library/2.0/library-2.0-all.jar')
120
+ end
121
+
122
+ it 'should return a list of all registered artifact specifications' do
123
+ define('foo', :version=>'1.0') { package :jar }
124
+ Artifact.list.should include(@artifact.to_spec)
125
+ Artifact.list.should include(@classified.to_spec)
126
+ Artifact.list.should include('foo:foo:jar:1.0')
127
+ end
128
+ end
129
+
130
+
131
+ describe Repositories, 'local' do
132
+ it 'should default to .m2 path' do
133
+ # For convenience, sandbox actually sets the local repository to a temp directory
134
+ repositories.local = nil
135
+ repositories.local.should eql(File.expand_path('.m2/repository', ENV['HOME']))
136
+ end
137
+
138
+ it 'should be settable' do
139
+ repositories.local = '.m2/local'
140
+ repositories.local.should eql(File.expand_path('.m2/local'))
141
+ end
142
+
143
+ it 'should reset to default' do
144
+ repositories.local = '.m2/local'
145
+ repositories.local = nil
146
+ repositories.local.should eql(File.expand_path('~/.m2/repository'))
147
+ end
148
+
149
+ it 'should locate file from string specification' do
150
+ repositories.local = nil
151
+ repositories.locate('com.example:library:jar:2.0').should eql(
152
+ File.expand_path('~/.m2/repository/com/example/library/2.0/library-2.0.jar'))
153
+ end
154
+
155
+ it 'should locate file from hash specification' do
156
+ repositories.local = nil
157
+ repositories.locate(:group=>'com.example', :id=>'library', :version=>'2.0').should eql(
158
+ File.expand_path('~/.m2/repository/com/example/library/2.0/library-2.0.jar'))
159
+ end
160
+
161
+ it 'should load path from settings file' do
162
+ write 'home/.buildr/settings.yaml', <<-YAML
163
+ repositories:
164
+ local: my_repo
165
+ YAML
166
+ repositories.local.should eql(File.expand_path('my_repo'))
167
+ end
168
+ end
169
+
170
+
171
+ describe Repositories, 'remote' do
172
+ before do
173
+ @repos = [ 'http://www.ibiblio.org/maven2', 'http://repo1.maven.org/maven2' ]
174
+ end
175
+
176
+ it 'should be empty initially' do
177
+ repositories.remote.should be_empty
178
+ end
179
+
180
+ it 'should be settable' do
181
+ repositories.remote = @repos.first
182
+ repositories.remote.should eql([@repos.first])
183
+ end
184
+
185
+ it 'should be settable from array' do
186
+ repositories.remote = @repos
187
+ repositories.remote.should eql(@repos)
188
+ end
189
+
190
+ it 'should add and return repositories in order' do
191
+ @repos.each { |url| repositories.remote << url }
192
+ repositories.remote.should eql(@repos)
193
+ end
194
+
195
+ it 'should be used to download artifact' do
196
+ repositories.remote = 'http://example.com'
197
+ URI.should_receive(:download).twice.and_return { |uri, target, options| write target }
198
+ lambda { artifact('com.example:library:jar:2.0').invoke }.
199
+ should change { File.exist?(File.join(repositories.local, 'com/example/library/2.0/library-2.0.jar')) }.to(true)
200
+ end
201
+
202
+ it 'should lookup in array order' do
203
+ repositories.remote = [ 'http://example.com', 'http://example.org' ]
204
+ order = ['com', 'org']
205
+ URI.should_receive(:download).any_number_of_times do |uri, target, options|
206
+ order.shift if order.first && uri.to_s[order.first]
207
+ fail URI::NotFoundError unless order.empty?
208
+ write target
209
+ end
210
+ lambda { artifact('com.example:library:jar:2.0').invoke }.should change { order.empty? }
211
+ end
212
+
213
+ it 'should fail if artifact not found' do
214
+ repositories.remote = 'http://example.com'
215
+ URI.should_receive(:download).once.ordered.and_return { fail URI::NotFoundError }
216
+ lambda { artifact('com.example:library:jar:2.0').invoke }.should raise_error(RuntimeError, /Failed to download/)
217
+ File.exist?(File.join(repositories.local, 'com/example/library/2.0/library-2.0.jar')).should be_false
218
+ end
219
+
220
+ it 'should support artifact classifier' do
221
+ repositories.remote = 'http://example.com'
222
+ URI.should_receive(:download).twice.and_return { |uri, target, options| write target }
223
+ lambda { artifact('com.example:library:jar:all:2.0').invoke }.
224
+ should change { File.exist?(File.join(repositories.local, 'com/example/library/2.0/library-2.0-all.jar')) }.to(true)
225
+ end
226
+
227
+ it 'should deal well with repositories URL that lack the last slash' do
228
+ repositories.remote = 'http://example.com/base'
229
+ uri = nil
230
+ URI.should_receive(:download).twice.and_return { |uri, target, options| }
231
+ artifact('group:id:jar:1.0').invoke
232
+ uri.to_s.should eql('http://example.com/base/group/id/1.0/id-1.0.pom')
233
+ end
234
+
235
+ it 'should deal well with repositories URL that have the last slash' do
236
+ repositories.remote = 'http://example.com/base/'
237
+ uri = nil
238
+ URI.should_receive(:download).twice.and_return { |uri, target, options| }
239
+ artifact('group:id:jar:1.0').invoke
240
+ uri.to_s.should eql('http://example.com/base/group/id/1.0/id-1.0.pom')
241
+ end
242
+
243
+ it 'should resolve m2-style deployed snapshots' do
244
+ metadata = <<-XML
245
+ <?xml version='1.0' encoding='UTF-8'?>
246
+ <metadata>
247
+ <groupId>com.example</groupId>
248
+ <artifactId>library</artifactId>
249
+ <version>2.1-SNAPSHOT</version>
250
+ <versioning>
251
+ <snapshot>
252
+ <timestamp>20071012.190008</timestamp>
253
+ <buildNumber>8</buildNumber>
254
+ </snapshot>
255
+ <lastUpdated>20071012190008</lastUpdated>
256
+ </versioning>
257
+ </metadata>
258
+ XML
259
+ repositories.remote = 'http://example.com'
260
+ URI.should_receive(:download).twice.with(uri(/2.1-SNAPSHOT\/library-2.1-SNAPSHOT.(jar|pom)$/), anything()).
261
+ and_return { fail URI::NotFoundError }
262
+ URI.should_receive(:download).twice.with(uri(/2.1-SNAPSHOT\/maven-metadata.xml$/), duck_type(:write)).
263
+ and_return { |uri, target, options| target.write(metadata) }
264
+ URI.should_receive(:download).twice.with(uri(/2.1-SNAPSHOT\/library-2.1-20071012.190008-8.(jar|pom)$/), /2.1-SNAPSHOT\/library-2.1-SNAPSHOT.(jar|pom)$/).
265
+ and_return { |uri, target, options| write target }
266
+ lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.
267
+ should change { File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')) }.to(true)
268
+ end
269
+
270
+ it 'should handle missing maven metadata by reporting the artifact unavailable' do
271
+ repositories.remote = 'http://example.com'
272
+ URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/library-2.1-SNAPSHOT.jar$/), anything()).
273
+ and_return { fail URI::NotFoundError }
274
+ URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/maven-metadata.xml$/), duck_type(:write)).
275
+ and_return { fail URI::NotFoundError }
276
+ lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.should raise_error(RuntimeError, /Failed to download/)
277
+ File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')).should be_false
278
+ end
279
+
280
+ it 'should handle missing m2 snapshots by reporting the artifact unavailable' do
281
+ metadata = <<-XML
282
+ <?xml version='1.0' encoding='UTF-8'?>
283
+ <metadata>
284
+ <groupId>com.example</groupId>
285
+ <artifactId>library</artifactId>
286
+ <version>2.1-SNAPSHOT</version>
287
+ <versioning>
288
+ <snapshot>
289
+ <timestamp>20071012.190008</timestamp>
290
+ <buildNumber>8</buildNumber>
291
+ </snapshot>
292
+ <lastUpdated>20071012190008</lastUpdated>
293
+ </versioning>
294
+ </metadata>
295
+ XML
296
+ repositories.remote = 'http://example.com'
297
+ URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/library-2.1-SNAPSHOT.jar$/), anything()).
298
+ and_return { fail URI::NotFoundError }
299
+ URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/maven-metadata.xml$/), duck_type(:write)).
300
+ and_return { |uri, target, options| target.write(metadata) }
301
+ URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/library-2.1-20071012.190008-8.jar$/), anything()).
302
+ and_return { fail URI::NotFoundError }
303
+ lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.should raise_error(RuntimeError, /Failed to download/)
304
+ File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')).should be_false
305
+ end
306
+
307
+ it 'should load with all repositories specified in settings file' do
308
+ write 'home/.buildr/settings.yaml', <<-YAML
309
+ repositories:
310
+ remote:
311
+ - http://example.com
312
+ - http://example.org
313
+ YAML
314
+ repositories.remote.should include('http://example.com', 'http://example.org')
315
+ end
316
+
317
+ it 'should load with all repositories specified in build.yaml file' do
318
+ write 'build.yaml', <<-YAML
319
+ repositories:
320
+ remote:
321
+ - http://example.com
322
+ - http://example.org
323
+ YAML
324
+ repositories.remote.should include('http://example.com', 'http://example.org')
325
+ end
326
+
327
+ it 'should load with all repositories specified in settings and build.yaml files' do
328
+ write 'home/.buildr/settings.yaml', <<-YAML
329
+ repositories:
330
+ remote:
331
+ - http://example.com
332
+ YAML
333
+ write 'build.yaml', <<-YAML
334
+ repositories:
335
+ remote:
336
+ - http://example.org
337
+ YAML
338
+ repositories.remote.should include('http://example.com', 'http://example.org')
339
+ end
340
+ end
341
+
342
+
343
+ describe Repositories, 'release_to' do
344
+ it 'should accept URL as first argument' do
345
+ repositories.release_to = 'http://example.com'
346
+ repositories.release_to.should == { :url=>'http://example.com' }
347
+ end
348
+
349
+ it 'should accept hash with options' do
350
+ repositories.release_to = { :url=>'http://example.com', :username=>'john' }
351
+ repositories.release_to.should == { :url=>'http://example.com', :username=>'john' }
352
+ end
353
+
354
+ it 'should allow the hash to be manipulated' do
355
+ repositories.release_to = 'http://example.com'
356
+ repositories.release_to.should == { :url=>'http://example.com' }
357
+ repositories.release_to[:username] = 'john'
358
+ repositories.release_to.should == { :url=>'http://example.com', :username=>'john' }
359
+ end
360
+
361
+ it 'should load URL from settings file' do
362
+ write 'home/.buildr/settings.yaml', <<-YAML
363
+ repositories:
364
+ release_to: http://john:secret@example.com
365
+ YAML
366
+ repositories.release_to.should == { :url=>'http://john:secret@example.com' }
367
+ end
368
+
369
+ it 'should load URL, username and password from settings file' do
370
+ write 'home/.buildr/settings.yaml', <<-YAML
371
+ repositories:
372
+ release_to:
373
+ url: http://example.com
374
+ username: john
375
+ password: secret
376
+ YAML
377
+ repositories.release_to.should == { :url=>'http://example.com', :username=>'john', :password=>'secret' }
378
+ end
379
+ end
380
+
381
+
382
+ describe Buildr, '#artifact' do
383
+ before { @spec = { :group=>'com.example', :id=>'library', :type=>'jar', :version=>'2.0' } }
384
+
385
+ it 'should accept hash specification' do
386
+ artifact(:group=>'com.example', :id=>'library', :type=>'jar', :version=>'2.0').should respond_to(:invoke)
387
+ end
388
+
389
+ it 'should reject partial hash specifier' do
390
+ lambda { artifact(@spec.merge(:group=>nil)) }.should raise_error
391
+ lambda { artifact(@spec.merge(:id=>nil)) }.should raise_error
392
+ lambda { artifact(@spec.merge(:version=>nil)) }.should raise_error
393
+ end
394
+
395
+ it 'should complain about invalid key' do
396
+ lambda { artifact(@spec.merge(:error=>true)) }.should raise_error(ArgumentError, /no such option/i)
397
+ end
398
+
399
+ it 'should use JAR type by default' do
400
+ artifact(@spec.merge(:type=>nil)).should respond_to(:invoke)
401
+ end
402
+
403
+ it 'should accept string specification' do
404
+ artifact('com.example:library:jar:2.0').should respond_to(:invoke)
405
+ end
406
+
407
+ it 'should reject partial string specifier' do
408
+ artifact('com.example:library::2.0')
409
+ lambda { artifact('com.example:library:jar') }.should raise_error
410
+ lambda { artifact('com.example:library:jar:') }.should raise_error
411
+ lambda { artifact('com.example:library::2.0') }.should_not raise_error
412
+ lambda { artifact('com.example::jar:2.0') }.should raise_error
413
+ lambda { artifact(':library:jar:2.0') }.should raise_error
414
+ end
415
+
416
+ it 'should create a task naming the artifact in the local repository' do
417
+ file = File.join(repositories.local, 'com', 'example', 'library', '2.0', 'library-2.0.jar')
418
+ Rake::Task.task_defined?(file).should be_false
419
+ artifact('com.example:library:jar:2.0').name.should eql(file)
420
+ end
421
+
422
+ it 'should use from method to install artifact from existing file' do
423
+ write 'test.jar'
424
+ artifact = artifact('group:id:jar:1.0').from('test.jar')
425
+ lambda { artifact.invoke }.should change { File.exist?(artifact.to_s) }.to(true)
426
+ end
427
+
428
+ it 'should reference artifacts defined on build.yaml by using ruby symbols' do
429
+ write 'build.yaml', <<-YAML
430
+ artifacts:
431
+ j2ee: geronimo-spec:geronimo-spec-j2ee:jar:1.4-rc4
432
+ YAML
433
+ Buildr.application.send :load_artifacts
434
+ artifact(:j2ee).to_s.pathmap('%f').should == 'geronimo-spec-j2ee-1.4-rc4.jar'
435
+ end
436
+ end
437
+
438
+
439
+ describe Buildr, '#artifacts' do
440
+ it 'should return a list of artifacts from all its arguments' do
441
+ specs = [ 'saxon:saxon:jar:8.4', 'saxon:saxon-dom:jar:8.4', 'saxon:saxon-xpath:jar:8.4' ]
442
+ artifacts(*specs).should eql(specs.map { |spec| artifact(spec) })
443
+ end
444
+
445
+ it 'should accept nested arrays' do
446
+ specs = [ 'saxon:saxon:jar:8.4', 'saxon:saxon-dom:jar:8.4', 'saxon:saxon-xpath:jar:8.4' ]
447
+ artifacts([[specs[0]]], [[specs[1]], specs[2]]).should eql(specs.map { |spec| artifact(spec) })
448
+ end
449
+
450
+ it 'should accept struct' do
451
+ specs = struct(:main=>'saxon:saxon:jar:8.4', :dom=>'saxon:saxon-dom:jar:8.4', :xpath=>'saxon:saxon-xpath:jar:8.4')
452
+ artifacts(specs).should eql(specs.values.map { |spec| artifact(spec) })
453
+ end
454
+
455
+ it 'should ignore duplicates' do
456
+ artifacts('saxon:saxon:jar:8.4', 'saxon:saxon:jar:8.4').size.should be(1)
457
+ end
458
+
459
+ it 'should accept and return existing tasks' do
460
+ artifacts(task('foo'), task('bar')).should eql([task('foo'), task('bar')])
461
+ end
462
+
463
+ it 'should accept filenames and expand them' do
464
+ artifacts('test').map(&:to_s).should eql([File.expand_path('test')])
465
+ end
466
+
467
+ it 'should accept filenames and return filenames' do
468
+ artifacts('c:test').first.should be_kind_of(String)
469
+ end
470
+
471
+ it 'should accept project and return all its packaging tasks' do
472
+ define 'foobar', :group=>'group', :version=>'1.0' do
473
+ package :jar, :id=>'code'
474
+ package :war, :id=>'webapp'
475
+ end
476
+ foobar = project('foobar')
477
+ artifacts(foobar).should eql([
478
+ task(foobar.path_to('target/code-1.0.jar')),
479
+ task(foobar.path_to('target/webapp-1.0.war'))
480
+ ])
481
+ end
482
+
483
+ it 'should complain about an invalid specification' do
484
+ lambda { artifacts(5) }.should raise_error
485
+ lambda { artifacts('group:no:version:') }.should raise_error
486
+ end
487
+ end
488
+
489
+
490
+ describe Buildr, '#group' do
491
+ it 'should accept list of artifact identifiers' do
492
+ list = group('saxon', 'saxon-dom', 'saxon-xpath', :under=>'saxon', :version=>'8.4')
493
+ list.should include(artifact('saxon:saxon:jar:8.4'))
494
+ list.should include(artifact('saxon:saxon-dom:jar:8.4'))
495
+ list.should include(artifact('saxon:saxon-xpath:jar:8.4'))
496
+ list.size.should be(3)
497
+ end
498
+
499
+ it 'should accept array with artifact identifiers' do
500
+ list = group(%w{saxon saxon-dom saxon-xpath}, :under=>'saxon', :version=>'8.4')
501
+ list.should include(artifact('saxon:saxon:jar:8.4'))
502
+ list.should include(artifact('saxon:saxon-dom:jar:8.4'))
503
+ list.should include(artifact('saxon:saxon-xpath:jar:8.4'))
504
+ list.size.should be(3)
505
+ end
506
+
507
+ it 'should accept a type' do
508
+ list = group('struts-bean', 'struts-html', :under=>'struts', :type=>'tld', :version=>'1.1')
509
+ list.should include(artifact('struts:struts-bean:tld:1.1'))
510
+ list.should include(artifact('struts:struts-html:tld:1.1'))
511
+ list.size.should be(2)
512
+ end
513
+
514
+ end
515
+
516
+ describe Buildr, '#install' do
517
+ before do
518
+ @spec = 'group:id:jar:1.0'
519
+ write @file = 'test.jar'
520
+ end
521
+
522
+ it 'should return the install task' do
523
+ install.should be(task('install'))
524
+ end
525
+
526
+ it 'should accept artifacts to install' do
527
+ install artifact(@spec)
528
+ lambda { install @file }.should raise_error(ArgumentError)
529
+ end
530
+
531
+ it 'should install artifact when install task is run' do
532
+ write @file
533
+ install artifact(@spec).from(@file)
534
+ lambda { install.invoke }.should change { File.exist?(artifact(@spec).to_s) }.to(true)
535
+ end
536
+
537
+ it 'should install POM alongside artifact' do
538
+ write @file
539
+ install artifact(@spec).from(@file)
540
+ lambda { install.invoke }.should change { File.exist?(artifact(@spec).pom.to_s) }.to(true)
541
+ end
542
+ end
543
+
544
+
545
+ describe Buildr, '#upload' do
546
+ before do
547
+ @spec = 'group:id:jar:1.0'
548
+ write @file = 'test.jar'
549
+ repositories.release_to = 'sftp://example.com/base'
550
+ end
551
+
552
+ it 'should return the upload task' do
553
+ upload.should be(task('upload'))
554
+ end
555
+
556
+ it 'should accept artifacts to upload' do
557
+ upload artifact(@spec)
558
+ lambda { upload @file }.should raise_error(ArgumentError)
559
+ end
560
+
561
+ it 'should upload artifact when upload task is run' do
562
+ write @file
563
+ upload artifact(@spec).from(@file)
564
+ URI.should_receive(:upload).once.
565
+ with(URI.parse('sftp://example.com/base/group/id/1.0/id-1.0.jar'), artifact(@spec).to_s, anything)
566
+ URI.should_receive(:upload).once.
567
+ with(URI.parse('sftp://example.com/base/group/id/1.0/id-1.0.pom'), artifact(@spec).pom.to_s, anything)
568
+ upload.invoke
569
+ end
570
+ end
571
+
572
+
573
+ describe ActsAsArtifact, '#upload' do
574
+ it 'should be used to upload artifact' do
575
+ artifact = artifact('com.example:library:jar:2.0')
576
+ # Prevent artifact from downloading anything.
577
+ write repositories.locate(artifact)
578
+ write repositories.locate(artifact.pom)
579
+ URI.should_receive(:upload).once.
580
+ with(URI.parse('sftp://example.com/base/com/example/library/2.0/library-2.0.pom'), artifact.pom.to_s, anything)
581
+ URI.should_receive(:upload).once.
582
+ with(URI.parse('sftp://example.com/base/com/example/library/2.0/library-2.0.jar'), artifact.to_s, anything)
583
+ verbose(false) { artifact.upload(:url=>'sftp://example.com/base') }
584
+ end
585
+
586
+ it 'should support artifact classifier' do
587
+ artifact = artifact('com.example:library:jar:all:2.0')
588
+ # Prevent artifact from downloading anything.
589
+ write repositories.locate(artifact)
590
+ write repositories.locate(artifact.pom)
591
+ URI.should_receive(:upload).at_least(:once).
592
+ with(URI.parse('sftp://example.com/base/com/example/library/2.0/library-2.0.pom'), artifact.pom.to_s, anything)
593
+ URI.should_receive(:upload).at_least(:once).
594
+ with(URI.parse('sftp://example.com/base/com/example/library/2.0/library-2.0-all.jar'), artifact.to_s, anything)
595
+ verbose(false) { artifact.upload(:url=>'sftp://example.com/base') }
596
+ end
597
+
598
+ it 'should complain without any repository configuration' do
599
+ artifact = artifact('com.example:library:jar:2.0')
600
+ # Prevent artifact from downloading anything.
601
+ write repositories.locate(artifact)
602
+ write repositories.locate(artifact.pom)
603
+ lambda { artifact.upload }.should raise_error(Exception, /where to upload/)
604
+ end
605
+
606
+ it 'should accept repositories.upload setting' do
607
+ artifact = artifact('com.example:library:jar:2.0')
608
+ # Prevent artifact from downloading anything.
609
+ write repositories.locate(artifact)
610
+ write repositories.locate(artifact.pom)
611
+ URI.should_receive(:upload).at_least(:once)
612
+ repositories.release_to = 'sftp://example.com/base'
613
+ artifact.upload
614
+ lambda { artifact.upload }.should_not raise_error
615
+ end
616
+ end
617
+
618
+
619
+ describe Rake::Task, ' artifacts' do
620
+ it 'should download all specified artifacts' do
621
+ artifact 'group:id:jar:1.0'
622
+ repositories.remote = 'http://example.com'
623
+ URI.should_receive(:download).twice.and_return { |uri, target, options| write target }
624
+ task('artifacts').invoke
625
+ end
626
+
627
+ it 'should fail if failed to download an artifact' do
628
+ artifact 'group:id:jar:1.0'
629
+ lambda { task('artifacts').invoke }.should raise_error(RuntimeError, /No remote repositories/)
630
+ end
631
+
632
+ it 'should succeed if artifact already exists' do
633
+ write repositories.locate(artifact('group:id:jar:1.0'))
634
+ suppress_stdout do
635
+ lambda { task('artifacts').invoke }.should_not raise_error
636
+ end
637
+ end
638
+ end
639
+
640
+
641
+ describe Buildr, '#transitive' do
642
+ before do
643
+ repositories.remote = 'http://example.com'
644
+ @simple = [ 'saxon:saxon:jar:8.4', 'saxon:saxon-dom:jar:8.4', 'saxon:saxon-xpath:jar:8.4' ]
645
+ @simple.map { |spec| artifact(spec).pom }.each { |task| write task.name, task.pom_xml }
646
+ @provided = @simple.first
647
+ @complex = 'group:app:jar:1.0'
648
+ write artifact(@complex).pom.to_s, <<-XML
649
+ <project>
650
+ <artifactId>app</artifactId>
651
+ <groupId>group</groupId>
652
+ <dependencies>
653
+ <dependency>
654
+ <artifactId>saxon</artifactId>
655
+ <groupId>saxon</groupId>
656
+ <version>8.4</version>
657
+ <scope>provided</scope>
658
+ </dependency>
659
+ <dependency>
660
+ <artifactId>saxon-dom</artifactId>
661
+ <groupId>saxon</groupId>
662
+ <version>8.4</version>
663
+ <scope>runtime</scope>
664
+ </dependency>
665
+ <dependency>
666
+ <artifactId>saxon-xpath</artifactId>
667
+ <groupId>saxon</groupId>
668
+ <version>8.4</version>
669
+ </dependency>
670
+ <dependency>
671
+ <artifactId>saxon-nosuch</artifactId>
672
+ <groupId>saxon</groupId>
673
+ <version>8.4</version>
674
+ <scope>test</scope>
675
+ </dependency>
676
+ </dependencies>
677
+ </project>
678
+ XML
679
+ @transitive = 'master:app:war:1.0'
680
+ write artifact(@transitive).pom.to_s, <<-XML
681
+ <project>
682
+ <artifactId>app</artifactId>
683
+ <groupId>group</groupId>
684
+ <dependencies>
685
+ <dependency>
686
+ <artifactId>app</artifactId>
687
+ <groupId>group</groupId>
688
+ <version>1.0</version>
689
+ </dependency>
690
+ </dependencies>
691
+ </project>
692
+ XML
693
+ end
694
+
695
+ it 'should return a list of artifacts from all its arguments' do
696
+ specs = [ 'saxon:saxon:jar:8.4', 'saxon:saxon-dom:jar:8.4', 'saxon:saxon-xpath:jar:8.4' ]
697
+ transitive(*specs).should eql(specs.map { |spec| artifact(spec) })
698
+ end
699
+
700
+ it 'should accept nested arrays' do
701
+ specs = [ 'saxon:saxon:jar:8.4', 'saxon:saxon-dom:jar:8.4', 'saxon:saxon-xpath:jar:8.4' ]
702
+ transitive([[specs[0]]], [[specs[1]], specs[2]]).should eql(specs.map { |spec| artifact(spec) })
703
+ end
704
+
705
+ it 'should accept struct' do
706
+ specs = struct(:main=>'saxon:saxon:jar:8.4', :dom=>'saxon:saxon-dom:jar:8.4', :xpath=>'saxon:saxon-xpath:jar:8.4')
707
+ transitive(specs).should eql(specs.values.map { |spec| artifact(spec) })
708
+ end
709
+
710
+ it 'should ignore duplicates' do
711
+ transitive('saxon:saxon:jar:8.4', 'saxon:saxon:jar:8.4').size.should be(1)
712
+ end
713
+
714
+ it 'should accept and return existing tasks' do
715
+ transitive(task('foo'), task('bar')).should eql([task('foo'), task('bar')])
716
+ end
717
+
718
+ it 'should accept filenames and expand them' do
719
+ transitive('test').map(&:to_s).should eql([File.expand_path('test')])
720
+ end
721
+
722
+ it 'should accept filenames and return file task' do
723
+ transitive('c:test').first.should be_kind_of(Rake::FileTask)
724
+ end
725
+
726
+ it 'should accept project and return all its packaging tasks' do
727
+ define 'foobar', :group=>'group', :version=>'1.0' do
728
+ package :jar, :id=>'code'
729
+ package :war, :id=>'webapp'
730
+ end
731
+ foobar = project('foobar')
732
+ transitive(foobar).should eql([
733
+ task(foobar.path_to('target/code-1.0.jar')),
734
+ task(foobar.path_to('target/webapp-1.0.war'))
735
+ ])
736
+ end
737
+
738
+ it 'should complain about an invalid specification' do
739
+ lambda { transitive(5) }.should raise_error
740
+ lambda { transitive('group:no:version:') }.should raise_error
741
+ end
742
+
743
+ it 'should bring artifact and its dependencies' do
744
+ transitive(@complex).should eql(artifacts(@complex, @simple))
745
+ end
746
+
747
+ it 'should bring dependencies of POM without artifact itself' do
748
+ transitive(@complex.sub(/jar/, 'pom')).should eql(artifacts(@simple))
749
+ end
750
+
751
+ it 'should bring artifact and transitive depenencies' do
752
+ transitive(@transitive).should eql(artifacts(@transitive, @complex, @simple - [@provided]))
753
+ end
754
+ end