buildr-gemjar 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. data/.braids +8 -0
  2. data/.gitignore +5 -0
  3. data/.rvmrc +1 -0
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +20 -0
  7. data/README.md +98 -0
  8. data/Rakefile +8 -0
  9. data/buildr-gemjar.gemspec +42 -0
  10. data/lib/buildr-gemjar.rb +162 -0
  11. data/lib/buildr-gemjar/version.rb +3 -0
  12. data/meta.rakefile +30 -0
  13. data/spec/buildr-gemjar/version_spec.rb +11 -0
  14. data/spec/buildr-gemjar_spec.rb +179 -0
  15. data/spec/repo_builder.rb +59 -0
  16. data/spec/spec_helper.rb +44 -0
  17. data/vendor/buildr/.gitignore +17 -0
  18. data/vendor/buildr/CHANGELOG +1283 -0
  19. data/vendor/buildr/Gemfile +4 -0
  20. data/vendor/buildr/LICENSE +176 -0
  21. data/vendor/buildr/NOTICE +26 -0
  22. data/vendor/buildr/README.rdoc +134 -0
  23. data/vendor/buildr/Rakefile +44 -0
  24. data/vendor/buildr/_buildr +35 -0
  25. data/vendor/buildr/_jbuildr +35 -0
  26. data/vendor/buildr/addon/buildr/antlr.rb +65 -0
  27. data/vendor/buildr/addon/buildr/bnd.rb +147 -0
  28. data/vendor/buildr/addon/buildr/cobertura.rb +22 -0
  29. data/vendor/buildr/addon/buildr/drb.rb +281 -0
  30. data/vendor/buildr/addon/buildr/emma.rb +22 -0
  31. data/vendor/buildr/addon/buildr/hibernate.rb +149 -0
  32. data/vendor/buildr/addon/buildr/javacc.rb +85 -0
  33. data/vendor/buildr/addon/buildr/jaxb_xjc.rb +72 -0
  34. data/vendor/buildr/addon/buildr/jdepend.rb +60 -0
  35. data/vendor/buildr/addon/buildr/jetty.rb +248 -0
  36. data/vendor/buildr/addon/buildr/jibx.rb +86 -0
  37. data/vendor/buildr/addon/buildr/nailgun.rb +221 -0
  38. data/vendor/buildr/addon/buildr/openjpa.rb +88 -0
  39. data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  40. data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  41. data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  42. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  43. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  44. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  45. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  46. data/vendor/buildr/addon/buildr/protobuf.rb +88 -0
  47. data/vendor/buildr/addon/buildr/xmlbeans.rb +93 -0
  48. data/vendor/buildr/all-in-one/_buildr +19 -0
  49. data/vendor/buildr/all-in-one/buildr +368 -0
  50. data/vendor/buildr/all-in-one/buildr.cmd +1 -0
  51. data/vendor/buildr/bin/buildr +19 -0
  52. data/vendor/buildr/buildr.buildfile +58 -0
  53. data/vendor/buildr/buildr.gemspec +74 -0
  54. data/vendor/buildr/doc/_config.yml +1 -0
  55. data/vendor/buildr/doc/_layouts/default.html +90 -0
  56. data/vendor/buildr/doc/_layouts/preface.html +22 -0
  57. data/vendor/buildr/doc/artifacts.textile +217 -0
  58. data/vendor/buildr/doc/building.textile +276 -0
  59. data/vendor/buildr/doc/contributing.textile +268 -0
  60. data/vendor/buildr/doc/css/default.css +236 -0
  61. data/vendor/buildr/doc/css/print.css +101 -0
  62. data/vendor/buildr/doc/css/syntax.css +23 -0
  63. data/vendor/buildr/doc/download.textile +138 -0
  64. data/vendor/buildr/doc/extending.textile +212 -0
  65. data/vendor/buildr/doc/images/1442160941-frontcover.jpg +0 -0
  66. data/vendor/buildr/doc/images/asf-logo.gif +0 -0
  67. data/vendor/buildr/doc/images/asf-logo.png +0 -0
  68. data/vendor/buildr/doc/images/buildr-hires.png +0 -0
  69. data/vendor/buildr/doc/images/buildr.png +0 -0
  70. data/vendor/buildr/doc/images/favicon.png +0 -0
  71. data/vendor/buildr/doc/images/growl-icon.tiff +0 -0
  72. data/vendor/buildr/doc/images/note.png +0 -0
  73. data/vendor/buildr/doc/images/project-structure.png +0 -0
  74. data/vendor/buildr/doc/images/tip.png +0 -0
  75. data/vendor/buildr/doc/images/zbuildr.png +0 -0
  76. data/vendor/buildr/doc/images/zbuildr.tif +0 -0
  77. data/vendor/buildr/doc/index.textile +69 -0
  78. data/vendor/buildr/doc/installing.textile +284 -0
  79. data/vendor/buildr/doc/languages.textile +599 -0
  80. data/vendor/buildr/doc/mailing_lists.textile +29 -0
  81. data/vendor/buildr/doc/more_stuff.textile +845 -0
  82. data/vendor/buildr/doc/packaging.textile +618 -0
  83. data/vendor/buildr/doc/preface.textile +54 -0
  84. data/vendor/buildr/doc/projects.textile +276 -0
  85. data/vendor/buildr/doc/quick_start.textile +210 -0
  86. data/vendor/buildr/doc/releasing.textile +117 -0
  87. data/vendor/buildr/doc/scripts/buildr-git.rb +512 -0
  88. data/vendor/buildr/doc/scripts/gitflow.rb +296 -0
  89. data/vendor/buildr/doc/scripts/install-jruby.sh +44 -0
  90. data/vendor/buildr/doc/scripts/install-linux.sh +73 -0
  91. data/vendor/buildr/doc/scripts/install-osx.sh +52 -0
  92. data/vendor/buildr/doc/settings_profiles.textile +287 -0
  93. data/vendor/buildr/doc/testing.textile +247 -0
  94. data/vendor/buildr/etc/KEYS +189 -0
  95. data/vendor/buildr/lib/buildr.rb +44 -0
  96. data/vendor/buildr/lib/buildr/clojure.rb +34 -0
  97. data/vendor/buildr/lib/buildr/clojure/shell.rb +52 -0
  98. data/vendor/buildr/lib/buildr/core.rb +34 -0
  99. data/vendor/buildr/lib/buildr/core/application.rb +700 -0
  100. data/vendor/buildr/lib/buildr/core/build.rb +516 -0
  101. data/vendor/buildr/lib/buildr/core/cc.rb +166 -0
  102. data/vendor/buildr/lib/buildr/core/checks.rb +253 -0
  103. data/vendor/buildr/lib/buildr/core/common.rb +151 -0
  104. data/vendor/buildr/lib/buildr/core/compile.rb +622 -0
  105. data/vendor/buildr/lib/buildr/core/doc.rb +276 -0
  106. data/vendor/buildr/lib/buildr/core/environment.rb +129 -0
  107. data/vendor/buildr/lib/buildr/core/filter.rb +404 -0
  108. data/vendor/buildr/lib/buildr/core/generate.rb +197 -0
  109. data/vendor/buildr/lib/buildr/core/help.rb +119 -0
  110. data/vendor/buildr/lib/buildr/core/jrebel.rb +42 -0
  111. data/vendor/buildr/lib/buildr/core/linux.rb +30 -0
  112. data/vendor/buildr/lib/buildr/core/osx.rb +46 -0
  113. data/vendor/buildr/lib/buildr/core/progressbar.rb +161 -0
  114. data/vendor/buildr/lib/buildr/core/project.rb +975 -0
  115. data/vendor/buildr/lib/buildr/core/run.rb +43 -0
  116. data/vendor/buildr/lib/buildr/core/shell.rb +137 -0
  117. data/vendor/buildr/lib/buildr/core/test.rb +843 -0
  118. data/vendor/buildr/lib/buildr/core/transports.rb +565 -0
  119. data/vendor/buildr/lib/buildr/core/util.rb +537 -0
  120. data/vendor/buildr/lib/buildr/groovy.rb +20 -0
  121. data/vendor/buildr/lib/buildr/groovy/bdd.rb +106 -0
  122. data/vendor/buildr/lib/buildr/groovy/compiler.rb +153 -0
  123. data/vendor/buildr/lib/buildr/groovy/doc.rb +76 -0
  124. data/vendor/buildr/lib/buildr/groovy/shell.rb +57 -0
  125. data/vendor/buildr/lib/buildr/ide.rb +19 -0
  126. data/vendor/buildr/lib/buildr/ide/eclipse.rb +427 -0
  127. data/vendor/buildr/lib/buildr/ide/eclipse/java.rb +53 -0
  128. data/vendor/buildr/lib/buildr/ide/eclipse/plugin.rb +71 -0
  129. data/vendor/buildr/lib/buildr/ide/eclipse/scala.rb +68 -0
  130. data/vendor/buildr/lib/buildr/ide/idea.rb +576 -0
  131. data/vendor/buildr/lib/buildr/java.rb +25 -0
  132. data/vendor/buildr/lib/buildr/java/ant.rb +94 -0
  133. data/vendor/buildr/lib/buildr/java/bdd.rb +460 -0
  134. data/vendor/buildr/lib/buildr/java/cobertura.rb +297 -0
  135. data/vendor/buildr/lib/buildr/java/commands.rb +223 -0
  136. data/vendor/buildr/lib/buildr/java/compiler.rb +135 -0
  137. data/vendor/buildr/lib/buildr/java/deprecated.rb +141 -0
  138. data/vendor/buildr/lib/buildr/java/doc.rb +86 -0
  139. data/vendor/buildr/lib/buildr/java/ecj.rb +69 -0
  140. data/vendor/buildr/lib/buildr/java/emma.rb +244 -0
  141. data/vendor/buildr/lib/buildr/java/external.rb +73 -0
  142. data/vendor/buildr/lib/buildr/java/jruby.rb +122 -0
  143. data/vendor/buildr/lib/buildr/java/jtestr_result.rb +295 -0
  144. data/vendor/buildr/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  145. data/vendor/buildr/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  146. data/vendor/buildr/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  147. data/vendor/buildr/lib/buildr/java/packaging.rb +734 -0
  148. data/vendor/buildr/lib/buildr/java/pom.rb +178 -0
  149. data/vendor/buildr/lib/buildr/java/rjb.rb +154 -0
  150. data/vendor/buildr/lib/buildr/java/test_result.rb +101 -0
  151. data/vendor/buildr/lib/buildr/java/tests.rb +362 -0
  152. data/vendor/buildr/lib/buildr/java/version_requirement.rb +172 -0
  153. data/vendor/buildr/lib/buildr/packaging.rb +25 -0
  154. data/vendor/buildr/lib/buildr/packaging/archive.rb +535 -0
  155. data/vendor/buildr/lib/buildr/packaging/artifact.rb +903 -0
  156. data/vendor/buildr/lib/buildr/packaging/artifact_namespace.rb +984 -0
  157. data/vendor/buildr/lib/buildr/packaging/artifact_search.rb +140 -0
  158. data/vendor/buildr/lib/buildr/packaging/gems.rb +105 -0
  159. data/vendor/buildr/lib/buildr/packaging/package.rb +249 -0
  160. data/vendor/buildr/lib/buildr/packaging/tar.rb +189 -0
  161. data/vendor/buildr/lib/buildr/packaging/version_requirement.rb +192 -0
  162. data/vendor/buildr/lib/buildr/packaging/zip.rb +178 -0
  163. data/vendor/buildr/lib/buildr/packaging/ziptask.rb +356 -0
  164. data/vendor/buildr/lib/buildr/resources/buildr.icns +0 -0
  165. data/vendor/buildr/lib/buildr/resources/completed.png +0 -0
  166. data/vendor/buildr/lib/buildr/resources/failed.png +0 -0
  167. data/vendor/buildr/lib/buildr/resources/icons-license.txt +17 -0
  168. data/vendor/buildr/lib/buildr/run.rb +195 -0
  169. data/vendor/buildr/lib/buildr/scala.rb +26 -0
  170. data/vendor/buildr/lib/buildr/scala/bdd.rb +118 -0
  171. data/vendor/buildr/lib/buildr/scala/compiler.rb +242 -0
  172. data/vendor/buildr/lib/buildr/scala/doc.rb +142 -0
  173. data/vendor/buildr/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  174. data/vendor/buildr/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  175. data/vendor/buildr/lib/buildr/scala/shell.rb +52 -0
  176. data/vendor/buildr/lib/buildr/scala/tests.rb +171 -0
  177. data/vendor/buildr/lib/buildr/shell.rb +185 -0
  178. data/vendor/buildr/lib/buildr/version.rb +18 -0
  179. data/vendor/buildr/rakelib/all-in-one.rake +113 -0
  180. data/vendor/buildr/rakelib/checks.rake +57 -0
  181. data/vendor/buildr/rakelib/doc.rake +137 -0
  182. data/vendor/buildr/rakelib/metrics.rake +39 -0
  183. data/vendor/buildr/rakelib/package.rake +73 -0
  184. data/vendor/buildr/rakelib/release.rake +161 -0
  185. data/vendor/buildr/rakelib/rspec.rake +101 -0
  186. data/vendor/buildr/rakelib/setup.rake +66 -0
  187. data/vendor/buildr/rakelib/stage.rake +220 -0
  188. data/vendor/buildr/spec/addon/bnd_spec.rb +330 -0
  189. data/vendor/buildr/spec/addon/drb_spec.rb +328 -0
  190. data/vendor/buildr/spec/addon/jaxb_xjc_spec.rb +125 -0
  191. data/vendor/buildr/spec/core/application_spec.rb +631 -0
  192. data/vendor/buildr/spec/core/build_spec.rb +837 -0
  193. data/vendor/buildr/spec/core/cc_spec.rb +224 -0
  194. data/vendor/buildr/spec/core/checks_spec.rb +519 -0
  195. data/vendor/buildr/spec/core/common_spec.rb +725 -0
  196. data/vendor/buildr/spec/core/compile_spec.rb +658 -0
  197. data/vendor/buildr/spec/core/doc_spec.rb +195 -0
  198. data/vendor/buildr/spec/core/extension_spec.rb +201 -0
  199. data/vendor/buildr/spec/core/generate_spec.rb +33 -0
  200. data/vendor/buildr/spec/core/project_spec.rb +772 -0
  201. data/vendor/buildr/spec/core/run_spec.rb +93 -0
  202. data/vendor/buildr/spec/core/shell_spec.rb +146 -0
  203. data/vendor/buildr/spec/core/test_spec.rb +1320 -0
  204. data/vendor/buildr/spec/core/transport_spec.rb +544 -0
  205. data/vendor/buildr/spec/core/util_spec.rb +141 -0
  206. data/vendor/buildr/spec/groovy/bdd_spec.rb +80 -0
  207. data/vendor/buildr/spec/groovy/compiler_spec.rb +251 -0
  208. data/vendor/buildr/spec/groovy/doc_spec.rb +65 -0
  209. data/vendor/buildr/spec/ide/eclipse_spec.rb +739 -0
  210. data/vendor/buildr/spec/ide/idea_spec.rb +1144 -0
  211. data/vendor/buildr/spec/java/ant_spec.rb +37 -0
  212. data/vendor/buildr/spec/java/bdd_spec.rb +374 -0
  213. data/vendor/buildr/spec/java/cobertura_spec.rb +112 -0
  214. data/vendor/buildr/spec/java/commands_spec.rb +93 -0
  215. data/vendor/buildr/spec/java/compiler_spec.rb +252 -0
  216. data/vendor/buildr/spec/java/doc_spec.rb +56 -0
  217. data/vendor/buildr/spec/java/ecj_spec.rb +115 -0
  218. data/vendor/buildr/spec/java/emma_spec.rb +121 -0
  219. data/vendor/buildr/spec/java/external_spec.rb +56 -0
  220. data/vendor/buildr/spec/java/java_spec.rb +132 -0
  221. data/vendor/buildr/spec/java/packaging_spec.rb +1270 -0
  222. data/vendor/buildr/spec/java/run_spec.rb +78 -0
  223. data/vendor/buildr/spec/java/test_coverage_helper.rb +257 -0
  224. data/vendor/buildr/spec/java/tests_spec.rb +497 -0
  225. data/vendor/buildr/spec/packaging/archive_spec.rb +775 -0
  226. data/vendor/buildr/spec/packaging/artifact_namespace_spec.rb +743 -0
  227. data/vendor/buildr/spec/packaging/artifact_spec.rb +1066 -0
  228. data/vendor/buildr/spec/packaging/packaging_helper.rb +63 -0
  229. data/vendor/buildr/spec/packaging/packaging_spec.rb +719 -0
  230. data/vendor/buildr/spec/sandbox.rb +165 -0
  231. data/vendor/buildr/spec/scala/bdd_spec.rb +124 -0
  232. data/vendor/buildr/spec/scala/compiler_spec.rb +289 -0
  233. data/vendor/buildr/spec/scala/doc_spec.rb +88 -0
  234. data/vendor/buildr/spec/scala/scala.rb +38 -0
  235. data/vendor/buildr/spec/scala/tests_spec.rb +283 -0
  236. data/vendor/buildr/spec/spec_helpers.rb +369 -0
  237. data/vendor/buildr/spec/version_requirement_spec.rb +143 -0
  238. data/vendor/buildr/spec/xpath_matchers.rb +121 -0
  239. data/vendor/buildr/tests/BUILDR-320/Buildfile +29 -0
  240. data/vendor/buildr/tests/JavaSystemProperty/Buildfile +18 -0
  241. data/vendor/buildr/tests/JavaSystemProperty/src/test/java/FooTest.java +24 -0
  242. data/vendor/buildr/tests/compile_with_parent/Buildfile +18 -0
  243. data/vendor/buildr/tests/compile_with_parent/child/src/main/java/Foo.java +23 -0
  244. data/vendor/buildr/tests/helloWorld/Buildfile +20 -0
  245. data/vendor/buildr/tests/helloWorld/src/main/java/HelloWorld.java +23 -0
  246. data/vendor/buildr/tests/integration_testing.rb +56 -0
  247. data/vendor/buildr/tests/junit3/Buildfile +9 -0
  248. data/vendor/buildr/tests/junit3/src/main/java/Foo.java +23 -0
  249. data/vendor/buildr/tests/junit3/src/test/java/FooTest.java +28 -0
  250. data/vendor/buildr/tests/package_war_as_jar/Buildfile +15 -0
  251. data/vendor/buildr/tests/package_war_as_jar/src/main/java/Foo.java +19 -0
  252. metadata +524 -0
@@ -0,0 +1,1066 @@
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.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
17
+ require 'fileutils'
18
+
19
+ describe Artifact do
20
+ before do
21
+ @spec = { :group=>'com.example', :id=>'library', :type=>:jar, :version=>'2.0' }
22
+ @artifact = artifact(@spec)
23
+ @classified = artifact(@spec.merge(:classifier=>'all'))
24
+ @snapshot = artifact(@spec.merge({ :version=>'2.1-SNAPSHOT' }))
25
+ end
26
+
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 POM 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 have associated sources artifact' do
79
+ @artifact.sources_artifact.to_hash.should == @artifact.to_hash.merge(:classifier=>'sources')
80
+ end
81
+
82
+ it 'should have associated javadoc artifact' do
83
+ @artifact.javadoc_artifact.to_hash.should == @artifact.to_hash.merge(:classifier=>'javadoc')
84
+ end
85
+
86
+ it 'should download file if file does not exist' do
87
+ lambda { @artifact.invoke }.should raise_error(Exception, /No remote repositories/)
88
+ lambda { @classified.invoke }.should raise_error(Exception, /No remote repositories/)
89
+ end
90
+
91
+ it 'should not download file if file exists' do
92
+ write repositories.locate(@artifact)
93
+ lambda { @artifact.invoke }.should_not raise_error
94
+ write repositories.locate(@classified)
95
+ lambda { @classified.invoke }.should_not raise_error
96
+ end
97
+
98
+ it 'should handle lack of POM gracefully' do
99
+ repositories.remote = 'http://example.com'
100
+ URI.should_receive(:download).twice { |uri, target, options| raise URI::NotFoundError if uri.to_s.ends_with('.pom') }
101
+ lambda { @artifact.invoke }.should_not raise_error
102
+ end
103
+
104
+ it 'should pass if POM provided' do
105
+ repositories.remote = 'http://example.com'
106
+ @artifact.pom.enhance { |task| write task.name, @artifact.pom_xml }
107
+ write repositories.locate(@artifact)
108
+ lambda { @artifact.invoke }.should_not raise_error
109
+ end
110
+
111
+ it 'should pass if POM not required' do
112
+ repositories.remote = 'http://example.com'
113
+ class << @artifact ; def pom() ; end ; end
114
+ write repositories.locate(@artifact)
115
+ lambda { @artifact.invoke }.should_not raise_error
116
+ end
117
+
118
+ it 'should not download file if dry-run' do
119
+ dryrun do
120
+ lambda { @artifact.invoke }.should_not raise_error
121
+ lambda { @classified.invoke }.should_not raise_error
122
+ end
123
+ end
124
+
125
+ it 'should resolve to path in local repository' do
126
+ @artifact.to_s.should == File.join(repositories.local, 'com/example/library/2.0/library-2.0.jar')
127
+ @classified.to_s.should == File.join(repositories.local, 'com/example/library/2.0/library-2.0-all.jar')
128
+ end
129
+
130
+ it 'should return a list of all registered artifact specifications' do
131
+ define('foo', :version=>'1.0') { package :jar }
132
+ Artifact.list.should include(@artifact.to_spec)
133
+ Artifact.list.should include(@classified.to_spec)
134
+ Artifact.list.should include('foo:foo:jar:1.0')
135
+ end
136
+
137
+ it 'should accept user-defined string content' do
138
+ a = artifact(@spec)
139
+ a.content 'foo'
140
+ install a
141
+ lambda { install.invoke }.should change { File.exist?(a.to_s) && File.exist?(repositories.locate(a)) }.to(true)
142
+ read(repositories.locate(a)).should eql('foo')
143
+ end
144
+ end
145
+
146
+
147
+ describe Repositories, 'local' do
148
+ it 'should default to .m2 path' do
149
+ # For convenience, sandbox actually sets the local repository to a temp directory
150
+ repositories.local = nil
151
+ repositories.local.should eql(File.expand_path('.m2/repository', ENV['HOME']))
152
+ end
153
+
154
+ it 'should be settable' do
155
+ repositories.local = '.m2/local'
156
+ repositories.local.should eql(File.expand_path('.m2/local'))
157
+ end
158
+
159
+ it 'should reset to default' do
160
+ repositories.local = '.m2/local'
161
+ repositories.local = nil
162
+ repositories.local.should eql(File.expand_path('~/.m2/repository'))
163
+ end
164
+
165
+ it 'should locate file from string specification' do
166
+ repositories.local = nil
167
+ repositories.locate('com.example:library:jar:2.0').should eql(
168
+ File.expand_path('~/.m2/repository/com/example/library/2.0/library-2.0.jar'))
169
+ end
170
+
171
+ it 'should locate file from hash specification' do
172
+ repositories.local = nil
173
+ repositories.locate(:group=>'com.example', :id=>'library', :version=>'2.0').should eql(
174
+ File.expand_path('~/.m2/repository/com/example/library/2.0/library-2.0.jar'))
175
+ end
176
+
177
+ it 'should load path from settings file' do
178
+ write 'home/.buildr/settings.yaml', <<-YAML
179
+ repositories:
180
+ local: my_repo
181
+ YAML
182
+ repositories.local.should eql(File.expand_path('my_repo'))
183
+ end
184
+
185
+ it 'should not override custom install methods defined when extending an object' do
186
+ class MyOwnInstallTask
187
+
188
+ attr_accessor :result
189
+
190
+ def install
191
+ result = true
192
+ end
193
+
194
+ end
195
+ task = MyOwnInstallTask.new
196
+ task.result = "maybe"
197
+ task.extend ActsAsArtifact
198
+ task.install
199
+ task.result.should be_true
200
+ end
201
+ end
202
+
203
+
204
+ describe Repositories, 'remote' do
205
+ before do
206
+ @repos = [ 'http://www.ibiblio.org/maven2', 'http://repo1.maven.org/maven2' ]
207
+ end
208
+
209
+ it 'should be empty initially' do
210
+ repositories.remote.should be_empty
211
+ end
212
+
213
+ it 'should be settable' do
214
+ repositories.remote = @repos.first
215
+ repositories.remote.should eql([@repos.first])
216
+ end
217
+
218
+ it 'should be settable from array' do
219
+ repositories.remote = @repos
220
+ repositories.remote.should eql(@repos)
221
+ end
222
+
223
+ it 'should add and return repositories in order' do
224
+ @repos.each { |url| repositories.remote << url }
225
+ repositories.remote.should eql(@repos)
226
+ end
227
+
228
+ it 'should be used to download artifact' do
229
+ repositories.remote = 'http://example.com'
230
+ URI.should_receive(:download).twice.and_return { |uri, target, options| write target }
231
+ lambda { artifact('com.example:library:jar:2.0').invoke }.
232
+ should change { File.exist?(File.join(repositories.local, 'com/example/library/2.0/library-2.0.jar')) }.to(true)
233
+ end
234
+
235
+ it 'should lookup in array order' do
236
+ repositories.remote = [ 'http://example.com', 'http://example.org' ]
237
+ order = ['com', 'org']
238
+ URI.should_receive(:download).any_number_of_times do |uri, target, options|
239
+ order.shift if order.first && uri.to_s[order.first]
240
+ fail URI::NotFoundError unless order.empty?
241
+ write target
242
+ end
243
+ lambda { artifact('com.example:library:jar:2.0').invoke }.should change { order.empty? }
244
+ end
245
+
246
+ it 'should fail if artifact not found' do
247
+ repositories.remote = 'http://example.com'
248
+ URI.should_receive(:download).once.ordered.and_return { fail URI::NotFoundError }
249
+ lambda { artifact('com.example:library:jar:2.0').invoke }.should raise_error(RuntimeError, /Failed to download/)
250
+ File.exist?(File.join(repositories.local, 'com/example/library/2.0/library-2.0.jar')).should be_false
251
+ end
252
+
253
+ it 'should support artifact classifier' do
254
+ repositories.remote = 'http://example.com'
255
+ URI.should_receive(:download).once.and_return { |uri, target, options| write target }
256
+ lambda { artifact('com.example:library:jar:all:2.0').invoke }.
257
+ should change { File.exist?(File.join(repositories.local, 'com/example/library/2.0/library-2.0-all.jar')) }.to(true)
258
+ end
259
+
260
+ it 'should deal well with repositories URL that lack the last slash' do
261
+ repositories.remote = 'http://example.com/base'
262
+ uri = nil
263
+ URI.should_receive(:download).twice.and_return { |_uri, args| uri = _uri }
264
+ artifact('group:id:jar:1.0').invoke
265
+ uri.to_s.should eql('http://example.com/base/group/id/1.0/id-1.0.pom')
266
+ end
267
+
268
+ it 'should deal well with repositories URL that have the last slash' do
269
+ repositories.remote = 'http://example.com/base/'
270
+ uri = nil
271
+ URI.should_receive(:download).twice.and_return { |_uri, args| uri = _uri }
272
+ artifact('group:id:jar:1.0').invoke
273
+ uri.to_s.should eql('http://example.com/base/group/id/1.0/id-1.0.pom')
274
+ end
275
+
276
+ it 'should resolve m2-style deployed snapshots' do
277
+ metadata = <<-XML
278
+ <?xml version='1.0' encoding='UTF-8'?>
279
+ <metadata>
280
+ <groupId>com.example</groupId>
281
+ <artifactId>library</artifactId>
282
+ <version>2.1-SNAPSHOT</version>
283
+ <versioning>
284
+ <snapshot>
285
+ <timestamp>20071012.190008</timestamp>
286
+ <buildNumber>8</buildNumber>
287
+ </snapshot>
288
+ <lastUpdated>20071012190008</lastUpdated>
289
+ </versioning>
290
+ </metadata>
291
+ XML
292
+ repositories.remote = 'http://example.com'
293
+ URI.should_receive(:download).twice.with(uri(/2.1-SNAPSHOT\/library-2.1-SNAPSHOT.(jar|pom)$/), anything()).
294
+ and_return { fail URI::NotFoundError }
295
+ URI.should_receive(:download).twice.with(uri(/2.1-SNAPSHOT\/maven-metadata.xml$/), duck_type(:write)).
296
+ and_return { |uri, target, options| target.write(metadata) }
297
+ 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).(\d){1,}$/).
298
+ and_return { |uri, target, options| write target }
299
+ lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.
300
+ should change { File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')) }.to(true)
301
+ end
302
+
303
+ it 'should fail resolving m2-style deployed snapshots if a timestamp is missing' do
304
+ metadata = <<-XML
305
+ <?xml version='1.0' encoding='UTF-8'?>
306
+ <metadata>
307
+ <groupId>com.example</groupId>
308
+ <artifactId>library</artifactId>
309
+ <version>2.1-SNAPSHOT</version>
310
+ <versioning>
311
+ <snapshot>
312
+ <buildNumber>8</buildNumber>
313
+ </snapshot>
314
+ <lastUpdated>20071012190008</lastUpdated>
315
+ </versioning>
316
+ </metadata>
317
+ XML
318
+ repositories.remote = 'http://example.com'
319
+ URI.should_receive(:download).once.with(uri(/2.1-SNAPSHOT\/library-2.1-SNAPSHOT.(jar|pom)$/), anything()).
320
+ and_return { fail URI::NotFoundError }
321
+ URI.should_receive(:download).once.with(uri(/2.1-SNAPSHOT\/maven-metadata.xml$/), duck_type(:write)).
322
+ and_return { |uri, target, options| target.write(metadata) }
323
+ lambda {
324
+ lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.should raise_error(RuntimeError, /Failed to download/)
325
+ }.should show_error "No timestamp provided for the snapshot com.example:library:jar:2.1-SNAPSHOT"
326
+ File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')).should be_false
327
+ end
328
+
329
+ it 'should fail resolving m2-style deployed snapshots if a build number is missing' do
330
+ metadata = <<-XML
331
+ <?xml version='1.0' encoding='UTF-8'?>
332
+ <metadata>
333
+ <groupId>com.example</groupId>
334
+ <artifactId>library</artifactId>
335
+ <version>2.1-SNAPSHOT</version>
336
+ <versioning>
337
+ <snapshot>
338
+ <timestamp>20071012.190008</timestamp>
339
+ </snapshot>
340
+ <lastUpdated>20071012190008</lastUpdated>
341
+ </versioning>
342
+ </metadata>
343
+ XML
344
+ repositories.remote = 'http://example.com'
345
+ URI.should_receive(:download).once.with(uri(/2.1-SNAPSHOT\/library-2.1-SNAPSHOT.(jar|pom)$/), anything()).
346
+ and_return { fail URI::NotFoundError }
347
+ URI.should_receive(:download).once.with(uri(/2.1-SNAPSHOT\/maven-metadata.xml$/), duck_type(:write)).
348
+ and_return { |uri, target, options| target.write(metadata) }
349
+ lambda {
350
+ lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.should raise_error(RuntimeError, /Failed to download/)
351
+ }.should show_error "No build number provided for the snapshot com.example:library:jar:2.1-SNAPSHOT"
352
+ File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')).should be_false
353
+ end
354
+
355
+ it 'should handle missing maven metadata by reporting the artifact unavailable' do
356
+ repositories.remote = 'http://example.com'
357
+ URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/library-2.1-SNAPSHOT.jar$/), anything()).
358
+ and_return { fail URI::NotFoundError }
359
+ URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/maven-metadata.xml$/), duck_type(:write)).
360
+ and_return { fail URI::NotFoundError }
361
+ lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.should raise_error(RuntimeError, /Failed to download/)
362
+ File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')).should be_false
363
+ end
364
+
365
+ it 'should handle missing m2 snapshots by reporting the artifact unavailable' do
366
+ metadata = <<-XML
367
+ <?xml version='1.0' encoding='UTF-8'?>
368
+ <metadata>
369
+ <groupId>com.example</groupId>
370
+ <artifactId>library</artifactId>
371
+ <version>2.1-SNAPSHOT</version>
372
+ <versioning>
373
+ <snapshot>
374
+ <timestamp>20071012.190008</timestamp>
375
+ <buildNumber>8</buildNumber>
376
+ </snapshot>
377
+ <lastUpdated>20071012190008</lastUpdated>
378
+ </versioning>
379
+ </metadata>
380
+ XML
381
+ repositories.remote = 'http://example.com'
382
+ URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/library-2.1-SNAPSHOT.jar$/), anything()).
383
+ and_return { fail URI::NotFoundError }
384
+ URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/maven-metadata.xml$/), duck_type(:write)).
385
+ and_return { |uri, target, options| target.write(metadata) }
386
+ URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/library-2.1-20071012.190008-8.jar$/), anything()).
387
+ and_return { fail URI::NotFoundError }
388
+ lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.should raise_error(RuntimeError, /Failed to download/)
389
+ File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')).should be_false
390
+ end
391
+
392
+ it 'should load with all repositories specified in settings file' do
393
+ write 'home/.buildr/settings.yaml', <<-YAML
394
+ repositories:
395
+ remote:
396
+ - http://example.com
397
+ - http://example.org
398
+ YAML
399
+ repositories.remote.should include('http://example.com', 'http://example.org')
400
+ end
401
+
402
+ it 'should load with all repositories specified in build.yaml file' do
403
+ write 'build.yaml', <<-YAML
404
+ repositories:
405
+ remote:
406
+ - http://example.com
407
+ - http://example.org
408
+ YAML
409
+ repositories.remote.should include('http://example.com', 'http://example.org')
410
+ end
411
+
412
+ it 'should load with all repositories specified in settings and build.yaml files' do
413
+ write 'home/.buildr/settings.yaml', <<-YAML
414
+ repositories:
415
+ remote:
416
+ - http://example.com
417
+ YAML
418
+ write 'build.yaml', <<-YAML
419
+ repositories:
420
+ remote:
421
+ - http://example.org
422
+ YAML
423
+ repositories.remote.should include('http://example.com', 'http://example.org')
424
+ end
425
+ end
426
+
427
+
428
+ describe Repositories, 'release_to' do
429
+ it 'should accept URL as first argument' do
430
+ repositories.release_to = 'http://example.com'
431
+ repositories.release_to.should == { :url=>'http://example.com' }
432
+ end
433
+
434
+ it 'should accept hash with options' do
435
+ repositories.release_to = { :url=>'http://example.com', :username=>'john' }
436
+ repositories.release_to.should == { :url=>'http://example.com', :username=>'john' }
437
+ end
438
+
439
+ it 'should allow the hash to be manipulated' do
440
+ repositories.release_to = 'http://example.com'
441
+ repositories.release_to.should == { :url=>'http://example.com' }
442
+ repositories.release_to[:username] = 'john'
443
+ repositories.release_to.should == { :url=>'http://example.com', :username=>'john' }
444
+ end
445
+
446
+ it 'should load URL from settings file' do
447
+ write 'home/.buildr/settings.yaml', <<-YAML
448
+ repositories:
449
+ release_to: http://john:secret@example.com
450
+ YAML
451
+ repositories.release_to.should == { :url=>'http://john:secret@example.com' }
452
+ end
453
+
454
+ it 'should load URL from build settings file' do
455
+ write 'build.yaml', <<-YAML
456
+ repositories:
457
+ release_to: http://john:secret@example.com
458
+ YAML
459
+ repositories.release_to.should == { :url=>'http://john:secret@example.com' }
460
+ end
461
+
462
+ it 'should load URL, username and password from settings file' do
463
+ write 'home/.buildr/settings.yaml', <<-YAML
464
+ repositories:
465
+ release_to:
466
+ url: http://example.com
467
+ username: john
468
+ password: secret
469
+ YAML
470
+ repositories.release_to.should == { :url=>'http://example.com', :username=>'john', :password=>'secret' }
471
+ end
472
+ end
473
+
474
+
475
+ describe Buildr, '#artifact' do
476
+ before do
477
+ @spec = { :group=>'com.example', :id=>'library', :type=>'jar', :version=>'2.0' }
478
+ @snapshot_spec = 'group:id:jar:1.0-SNAPSHOT'
479
+ write @file = 'testartifact.jar'
480
+ end
481
+
482
+ it 'should accept hash specification' do
483
+ artifact(:group=>'com.example', :id=>'library', :type=>'jar', :version=>'2.0').should respond_to(:invoke)
484
+ end
485
+
486
+ it 'should reject partial hash specifier' do
487
+ lambda { artifact(@spec.merge(:group=>nil)) }.should raise_error
488
+ lambda { artifact(@spec.merge(:id=>nil)) }.should raise_error
489
+ lambda { artifact(@spec.merge(:version=>nil)) }.should raise_error
490
+ end
491
+
492
+ it 'should complain about invalid key' do
493
+ lambda { artifact(@spec.merge(:error=>true)) }.should raise_error(ArgumentError, /no such option/i)
494
+ end
495
+
496
+ it 'should use JAR type by default' do
497
+ artifact(@spec.merge(:type=>nil)).should respond_to(:invoke)
498
+ end
499
+
500
+ it 'should accept string specification' do
501
+ artifact('com.example:library:jar:2.0').should respond_to(:invoke)
502
+ end
503
+
504
+ it 'should reject partial string specifier' do
505
+ artifact('com.example:library::2.0')
506
+ lambda { artifact('com.example:library:jar') }.should raise_error
507
+ lambda { artifact('com.example:library:jar:') }.should raise_error
508
+ lambda { artifact('com.example:library::2.0') }.should_not raise_error
509
+ lambda { artifact('com.example::jar:2.0') }.should raise_error
510
+ lambda { artifact(':library:jar:2.0') }.should raise_error
511
+ end
512
+
513
+ it 'should create a task naming the artifact in the local repository' do
514
+ file = File.join(repositories.local, 'com', 'example', 'library', '2.0', 'library-2.0.jar')
515
+ Rake::Task.task_defined?(file).should be_false
516
+ artifact('com.example:library:jar:2.0').name.should eql(file)
517
+ end
518
+
519
+ it 'should use from method to install artifact from existing file' do
520
+ write 'test.jar'
521
+ artifact = artifact('group:id:jar:1.0').from('test.jar')
522
+ lambda { artifact.invoke }.should change { File.exist?(artifact.to_s) }.to(true)
523
+ end
524
+
525
+ it 'should use from method to install artifact from a file task' do
526
+ test_jar = file('test.jar')
527
+ test_jar.enhance do
528
+ #nothing...
529
+ end
530
+ write 'test.jar'
531
+ artifact = artifact('group:id:jar:1.0').from(test_jar)
532
+ lambda { artifact.invoke }.should change { File.exist?(artifact.to_s) }.to(true)
533
+ end
534
+
535
+ it 'should invoke the artifact associated file task if the file doesnt exist' do
536
+ test_jar = file('test.jar')
537
+ called = false
538
+ test_jar.enhance do
539
+ write 'test.jar'
540
+ called = true
541
+ end
542
+ artifact = artifact('group:id:jar:1.0').from(test_jar)
543
+ artifact.invoke
544
+ unless called
545
+ raise "The file task was not called."
546
+ end
547
+ end
548
+
549
+ it 'should not invoke the artifact associated file task if the file already exists' do
550
+ test_jar = file('test.jar')
551
+ test_jar.enhance do
552
+ raise 'the test.jar file is created again!'
553
+ end
554
+ write 'test.jar'
555
+ artifact = artifact('group:id:jar:1.0').from(test_jar)
556
+ artifact.invoke
557
+ end
558
+
559
+ it 'should reference artifacts defined on build.yaml by using ruby symbols' do
560
+ write 'build.yaml', <<-YAML
561
+ artifacts:
562
+ j2ee: geronimo-spec:geronimo-spec-j2ee:jar:1.4-rc4
563
+ YAML
564
+ Buildr.application.send(:load_artifact_ns)
565
+ artifact(:j2ee).to_s.pathmap('%f').should == 'geronimo-spec-j2ee-1.4-rc4.jar'
566
+ end
567
+
568
+ it 'should try to download snapshot artifact' do
569
+ run_with_repo
570
+ snapshot = artifact(@snapshot_spec)
571
+
572
+ URI.should_receive(:download).at_least(:twice).and_return { |uri, target, options| write target }
573
+ FileUtils.should_receive(:mv).at_least(:twice)
574
+ snapshot.invoke
575
+ end
576
+
577
+ it 'should not try to update snapshot in offline mode if it exists' do
578
+ run_with_repo
579
+ snapshot = artifact(@snapshot_spec)
580
+ write snapshot.to_s
581
+ Buildr.application.options.work_offline = true
582
+ URI.should_receive(:download).exactly(0).times
583
+ snapshot.invoke
584
+ end
585
+
586
+ it 'should download snapshot even in offline mode if it doesn''t exist' do
587
+ run_with_repo
588
+ snapshot = artifact(@snapshot_spec)
589
+ Buildr.application.options.work_offline = true
590
+ URI.should_receive(:download).exactly(2).times
591
+ snapshot.invoke
592
+ end
593
+
594
+ it 'should update snapshots if --update-snapshots' do
595
+ run_with_repo
596
+ snapshot = artifact(@snapshot_spec)
597
+ write snapshot.to_s
598
+ Buildr.application.options.update_snapshots = true
599
+
600
+ URI.should_receive(:download).at_least(:twice).and_return { |uri, target, options| write target }
601
+ FileUtils.should_receive(:mv).at_least(:twice)
602
+ snapshot.invoke
603
+ end
604
+
605
+ it 'should update snapshot if it''s older than 24 hours' do
606
+ run_with_repo
607
+ snapshot = artifact(@snapshot_spec)
608
+ write snapshot.to_s
609
+ time = Time.at((Time.now - (60 * 60 * 24) - 10 ).to_i)
610
+ File.utime(time, time, snapshot.to_s)
611
+ URI.should_receive(:download).at_least(:once).and_return { |uri, target, options| write target }
612
+ snapshot.invoke
613
+ end
614
+
615
+ def run_with_repo
616
+ repositories.remote = 'http://example.com'
617
+ end
618
+
619
+ end
620
+
621
+
622
+ describe Buildr, '#artifacts' do
623
+ it 'should return a list of artifacts from all its arguments' do
624
+ specs = [ 'saxon:saxon:jar:8.4', 'saxon:saxon-dom:jar:8.4', 'saxon:saxon-xpath:jar:8.4' ]
625
+ artifacts(*specs).should eql(specs.map { |spec| artifact(spec) })
626
+ end
627
+
628
+ it 'should accept nested arrays' do
629
+ specs = [ 'saxon:saxon:jar:8.4', 'saxon:saxon-dom:jar:8.4', 'saxon:saxon-xpath:jar:8.4' ]
630
+ artifacts([[specs[0]]], [[specs[1]], specs[2]]).should eql(specs.map { |spec| artifact(spec) })
631
+ end
632
+
633
+ it 'should accept struct' do
634
+ specs = struct(:main=>'saxon:saxon:jar:8.4', :dom=>'saxon:saxon-dom:jar:8.4', :xpath=>'saxon:saxon-xpath:jar:8.4')
635
+ artifacts(specs).should eql(specs.values.map { |spec| artifact(spec) })
636
+ end
637
+
638
+ it 'should ignore duplicates' do
639
+ artifacts('saxon:saxon:jar:8.4', 'saxon:saxon:jar:8.4').size.should be(1)
640
+ end
641
+
642
+ it 'should accept and return existing tasks' do
643
+ artifacts(task('foo'), task('bar')).should eql([task('foo'), task('bar')])
644
+ end
645
+
646
+ it 'should accept filenames and expand them' do
647
+ artifacts('test').map(&:to_s).should eql([File.expand_path('test')])
648
+ end
649
+
650
+ it 'should accept filenames and return filenames' do
651
+ artifacts('c:test').first.should be_kind_of(String)
652
+ end
653
+
654
+ it 'should accept project and return all its packaging tasks' do
655
+ define 'foobar', :group=>'group', :version=>'1.0' do
656
+ package :jar, :id=>'code'
657
+ package :war, :id=>'webapp'
658
+ end
659
+ foobar = project('foobar')
660
+ artifacts(foobar).should eql([
661
+ task(foobar.path_to('target/code-1.0.jar')),
662
+ task(foobar.path_to('target/webapp-1.0.war'))
663
+ ])
664
+ end
665
+
666
+ it 'should complain about an invalid specification' do
667
+ lambda { artifacts(5) }.should raise_error
668
+ lambda { artifacts('group:no:version:') }.should raise_error
669
+ end
670
+ end
671
+
672
+
673
+ describe Buildr, '#group' do
674
+ it 'should accept list of artifact identifiers' do
675
+ list = group('saxon', 'saxon-dom', 'saxon-xpath', :under=>'saxon', :version=>'8.4')
676
+ list.should include(artifact('saxon:saxon:jar:8.4'))
677
+ list.should include(artifact('saxon:saxon-dom:jar:8.4'))
678
+ list.should include(artifact('saxon:saxon-xpath:jar:8.4'))
679
+ list.size.should be(3)
680
+ end
681
+
682
+ it 'should accept array with artifact identifiers' do
683
+ list = group(%w{saxon saxon-dom saxon-xpath}, :under=>'saxon', :version=>'8.4')
684
+ list.should include(artifact('saxon:saxon:jar:8.4'))
685
+ list.should include(artifact('saxon:saxon-dom:jar:8.4'))
686
+ list.should include(artifact('saxon:saxon-xpath:jar:8.4'))
687
+ list.size.should be(3)
688
+ end
689
+
690
+ it 'should accept a type' do
691
+ list = group('struts-bean', 'struts-html', :under=>'struts', :type=>'tld', :version=>'1.1')
692
+ list.should include(artifact('struts:struts-bean:tld:1.1'))
693
+ list.should include(artifact('struts:struts-html:tld:1.1'))
694
+ list.size.should be(2)
695
+ end
696
+
697
+ it 'should accept a classifier' do
698
+ list = group('camel-core', :under=>'org.apache.camel', :version=>'2.2.0', :classifier=>'spring3')
699
+ list.should include(artifact('org.apache.camel:camel-core:jar:spring3:2.2.0'))
700
+ list.size.should be(1)
701
+ end
702
+
703
+ end
704
+
705
+ describe Buildr, '#install' do
706
+ before do
707
+ @spec = 'group:id:jar:1.0'
708
+ write @file = 'test.jar'
709
+ @snapshot_spec = 'group:id:jar:1.0-SNAPSHOT'
710
+ end
711
+
712
+ it 'should return the install task' do
713
+ install.should be(task('install'))
714
+ end
715
+
716
+ it 'should accept artifacts to install' do
717
+ install artifact(@spec)
718
+ lambda { install @file }.should raise_error(ArgumentError)
719
+ end
720
+
721
+ it 'should install artifact when install task is run' do
722
+ write @file
723
+ install artifact(@spec).from(@file)
724
+ lambda { install.invoke }.should change { File.exist?(artifact(@spec).to_s) }.to(true)
725
+ end
726
+
727
+ it 'should re-install artifact when "from" is newer' do
728
+ install artifact(@spec).from(@file)
729
+ write artifact(@spec).to_s # install a version of the artifact
730
+ old_mtime = File.mtime(artifact(@spec).to_s)
731
+ sleep 1; write @file # make sure the "from" file has newer modification time
732
+ lambda { install.invoke }.should change { modified?(old_mtime, @spec) }.to(true)
733
+ end
734
+
735
+ it 'should re-install snapshot artifact when "from" is newer' do
736
+ install artifact(@snapshot_spec).from(@file)
737
+ write artifact(@snapshot_spec).to_s # install a version of the artifact
738
+ old_mtime = File.mtime(artifact(@snapshot_spec).to_s)
739
+ sleep 1; write @file # make sure the "from" file has newer modification time
740
+ lambda { install.invoke }.should change { modified?(old_mtime, @snapshot_spec) }.to(true)
741
+ end
742
+
743
+ it 'should download snapshot to temporary location' do
744
+ repositories.remote = 'http://example.com'
745
+ snapshot = artifact(@snapshot_spec)
746
+ same_time = Time.new
747
+ download_file = "#{Dir.tmpdir}/#{File.basename(snapshot.name)}#{same_time.to_i}"
748
+
749
+ Time.should_receive(:new).twice.and_return(same_time)
750
+ URI.should_receive(:download).at_least(:twice).and_return { |uri, target, options| write target }
751
+ FileUtils.should_receive(:mv).at_least(:twice)
752
+ snapshot.invoke
753
+ end
754
+
755
+ it 'should install POM alongside artifact (if artifact has no classifier)' do
756
+ pom = artifact(@spec).pom
757
+ write @file
758
+ install artifact(@spec).from(@file)
759
+ lambda { install.invoke }.should change { File.exist?(repositories.locate(pom)) }.to(true)
760
+ end
761
+
762
+ it 'should not install POM alongside artifact if artifact has classifier' do
763
+ @spec = 'group:id:jar:all:1.0'
764
+ pom = artifact(@spec).pom
765
+ write @file
766
+ p method(:install)
767
+ install artifact(@spec).from(@file)
768
+ lambda { install.invoke }.should_not change { File.exist?(repositories.locate(pom)) }.to(true)
769
+ end
770
+
771
+ it 'should reinstall POM alongside artifact' do
772
+ pom = artifact(@spec).pom
773
+ write @file
774
+ write repositories.locate(pom)
775
+ sleep 1
776
+
777
+ install artifact(@spec).from(@file)
778
+ lambda { install.invoke }.should change { File.mtime(repositories.locate(pom)) }
779
+ end
780
+ end
781
+
782
+
783
+ describe Buildr, '#upload' do
784
+ before do
785
+ @spec = 'group:id:jar:1.0'
786
+ write @file = 'test.jar'
787
+ repositories.release_to = 'sftp://example.com/base'
788
+ end
789
+
790
+ it 'should return the upload task' do
791
+ upload.should be(task('upload'))
792
+ end
793
+
794
+ it 'should accept artifacts to upload' do
795
+ upload artifact(@spec)
796
+ lambda { upload @file }.should raise_error(ArgumentError)
797
+ end
798
+
799
+ it 'should upload artifact when upload task is run' do
800
+ write @file
801
+ upload artifact(@spec).from(@file)
802
+ URI.should_receive(:upload).once.
803
+ with(URI.parse('sftp://example.com/base/group/id/1.0/id-1.0.jar'), artifact(@spec).to_s, anything)
804
+ URI.should_receive(:upload).once.
805
+ with(URI.parse('sftp://example.com/base/group/id/1.0/id-1.0.pom'), artifact(@spec).pom.to_s, anything)
806
+ upload.invoke
807
+ end
808
+ end
809
+
810
+
811
+ describe ActsAsArtifact, '#upload' do
812
+ it 'should be used to upload artifact' do
813
+ artifact = artifact('com.example:library:jar:2.0')
814
+ # Prevent artifact from downloading anything.
815
+ write repositories.locate(artifact)
816
+ write repositories.locate(artifact.pom)
817
+ URI.should_receive(:upload).once.
818
+ with(URI.parse('sftp://example.com/base/com/example/library/2.0/library-2.0.pom'), artifact.pom.to_s, anything)
819
+ URI.should_receive(:upload).once.
820
+ with(URI.parse('sftp://example.com/base/com/example/library/2.0/library-2.0.jar'), artifact.to_s, anything)
821
+ verbose(false) { artifact.upload(:url=>'sftp://example.com/base') }
822
+ end
823
+
824
+ it 'should support artifact classifier and should not upload pom if artifact has classifier' do
825
+ artifact = artifact('com.example:library:jar:all:2.0')
826
+ # Prevent artifact from downloading anything.
827
+ write repositories.locate(artifact)
828
+ URI.should_receive(:upload).exactly(:once).
829
+ with(URI.parse('sftp://example.com/base/com/example/library/2.0/library-2.0-all.jar'), artifact.to_s, anything)
830
+ verbose(false) { artifact.upload(:url=>'sftp://example.com/base') }
831
+ end
832
+
833
+ it 'should complain without any repository configuration' do
834
+ artifact = artifact('com.example:library:jar:2.0')
835
+ # Prevent artifact from downloading anything.
836
+ write repositories.locate(artifact)
837
+ write repositories.locate(artifact.pom)
838
+ lambda { artifact.upload }.should raise_error(Exception, /where to upload/)
839
+ end
840
+
841
+ it 'should accept repositories.upload setting' do
842
+ artifact = artifact('com.example:library:jar:2.0')
843
+ # Prevent artifact from downloading anything.
844
+ write repositories.locate(artifact)
845
+ write repositories.locate(artifact.pom)
846
+ URI.should_receive(:upload).at_least(:once)
847
+ repositories.release_to = 'sftp://example.com/base'
848
+ artifact.upload
849
+ lambda { artifact.upload }.should_not raise_error
850
+ end
851
+
852
+ end
853
+
854
+
855
+ describe Rake::Task, ' artifacts' do
856
+ it 'should download all specified artifacts' do
857
+ artifact 'group:id:jar:1.0'
858
+ repositories.remote = 'http://example.com'
859
+ URI.should_receive(:download).twice.and_return { |uri, target, options| write target }
860
+ task('artifacts').invoke
861
+ end
862
+
863
+ it 'should fail if failed to download an artifact' do
864
+ artifact 'group:id:jar:1.0'
865
+ lambda { task('artifacts').invoke }.should raise_error(RuntimeError, /No remote repositories/)
866
+ end
867
+
868
+ it 'should succeed if artifact already exists' do
869
+ write repositories.locate(artifact('group:id:jar:1.0'))
870
+ suppress_stdout do
871
+ lambda { task('artifacts').invoke }.should_not raise_error
872
+ end
873
+ end
874
+ end
875
+
876
+
877
+ describe Rake::Task, ' artifacts:sources' do
878
+
879
+ before do
880
+ task('artifacts:sources').clear
881
+ repositories.remote = 'http://example.com'
882
+ end
883
+
884
+ it 'should download sources for all specified artifacts' do
885
+ artifact 'group:id:jar:1.0'
886
+ URI.should_receive(:download).any_number_of_times.and_return { |uri, target| write target }
887
+ lambda { task('artifacts:sources').invoke }.should change { File.exist?('home/.m2/repository/group/id/1.0/id-1.0-sources.jar') }.to(true)
888
+ end
889
+
890
+ it "should not try to download sources for the project's artifacts" do
891
+ define('foo', :version=>'1.0') { package(:jar) }
892
+ URI.should_not_receive(:download)
893
+ task('artifacts:sources').invoke
894
+ end
895
+
896
+ describe 'when the source artifact does not exist' do
897
+
898
+ before do
899
+ artifact 'group:id:jar:1.0'
900
+ URI.should_receive(:download).any_number_of_times.and_raise(URI::NotFoundError)
901
+ end
902
+
903
+ it 'should not fail' do
904
+ lambda { task('artifacts:sources').invoke }.should_not raise_error
905
+ end
906
+
907
+ it 'should inform the user' do
908
+ lambda { task('artifacts:sources').invoke }.should show_info('Failed to download group:id:jar:sources:1.0. Skipping it.')
909
+ end
910
+ end
911
+ end
912
+
913
+ describe Rake::Task, ' artifacts:javadoc' do
914
+
915
+ before do
916
+ task('artifacts:javadoc').clear
917
+ repositories.remote = 'http://example.com'
918
+ end
919
+
920
+ it 'should download javadoc for all specified artifacts' do
921
+ artifact 'group:id:jar:1.0'
922
+ URI.should_receive(:download).any_number_of_times.and_return { |uri, target| write target }
923
+ lambda { task('artifacts:javadoc').invoke }.should change { File.exist?('home/.m2/repository/group/id/1.0/id-1.0-javadoc.jar') }.to(true)
924
+ end
925
+
926
+ it "should not try to download javadoc for the project's artifacts" do
927
+ define('foo', :version=>'1.0') { package(:jar) }
928
+ URI.should_not_receive(:download)
929
+ task('artifacts:javadoc').invoke
930
+ end
931
+
932
+ describe 'when the javadoc artifact does not exist' do
933
+
934
+ before do
935
+ artifact 'group:id:jar:1.0'
936
+ URI.should_receive(:download).any_number_of_times.and_raise(URI::NotFoundError)
937
+ end
938
+
939
+ it 'should not fail' do
940
+ lambda { task('artifacts:javadoc').invoke }.should_not raise_error
941
+ end
942
+
943
+ it 'should inform the user' do
944
+ lambda { task('artifacts:javadoc').invoke }.should show_info('Failed to download group:id:jar:javadoc:1.0. Skipping it.')
945
+ end
946
+ end
947
+ end
948
+
949
+ describe Buildr, '#transitive' do
950
+ before do
951
+ repositories.remote = 'http://example.com'
952
+ @simple = [ 'saxon:saxon:jar:8.4', 'saxon:saxon-dom:jar:8.4', 'saxon:saxon-xpath:jar:8.4' ]
953
+ @simple.map { |spec| artifact(spec).pom }.each { |task| write task.name, task.pom_xml }
954
+ @provided = @simple.first
955
+ @complex = 'group:app:jar:1.0'
956
+ write artifact(@complex).pom.to_s, <<-XML
957
+ <project>
958
+ <artifactId>app</artifactId>
959
+ <groupId>group</groupId>
960
+ <dependencies>
961
+ <dependency>
962
+ <artifactId>saxon</artifactId>
963
+ <groupId>saxon</groupId>
964
+ <version>8.4</version>
965
+ <scope>provided</scope>
966
+ </dependency>
967
+ <dependency>
968
+ <artifactId>saxon-dom</artifactId>
969
+ <groupId>saxon</groupId>
970
+ <version>8.4</version>
971
+ <scope>runtime</scope>
972
+ </dependency>
973
+ <dependency>
974
+ <artifactId>saxon-xpath</artifactId>
975
+ <groupId>saxon</groupId>
976
+ <version>8.4</version>
977
+ </dependency>
978
+ <dependency>
979
+ <artifactId>saxon-nosuch</artifactId>
980
+ <groupId>saxon</groupId>
981
+ <version>8.4</version>
982
+ <scope>test</scope>
983
+ </dependency>
984
+ </dependencies>
985
+ </project>
986
+ XML
987
+ @transitive = 'master:app:war:1.0'
988
+ write artifact(@transitive).pom.to_s, <<-XML
989
+ <project>
990
+ <artifactId>app</artifactId>
991
+ <groupId>group</groupId>
992
+ <dependencies>
993
+ <dependency>
994
+ <artifactId>app</artifactId>
995
+ <groupId>group</groupId>
996
+ <version>1.0</version>
997
+ </dependency>
998
+ </dependencies>
999
+ </project>
1000
+ XML
1001
+ end
1002
+
1003
+ it 'should return a list of artifacts from all its arguments' do
1004
+ specs = [ 'saxon:saxon:jar:8.4', 'saxon:saxon-dom:jar:8.4', 'saxon:saxon-xpath:jar:8.4' ]
1005
+ transitive(*specs).should eql(specs.map { |spec| artifact(spec) })
1006
+ end
1007
+
1008
+ it 'should accept nested arrays' do
1009
+ specs = [ 'saxon:saxon:jar:8.4', 'saxon:saxon-dom:jar:8.4', 'saxon:saxon-xpath:jar:8.4' ]
1010
+ transitive([[specs[0]]], [[specs[1]], specs[2]]).should eql(specs.map { |spec| artifact(spec) })
1011
+ end
1012
+
1013
+ it 'should accept struct' do
1014
+ specs = struct(:main=>'saxon:saxon:jar:8.4', :dom=>'saxon:saxon-dom:jar:8.4', :xpath=>'saxon:saxon-xpath:jar:8.4')
1015
+ transitive(specs).should eql(specs.values.map { |spec| artifact(spec) })
1016
+ end
1017
+
1018
+ it 'should ignore duplicates' do
1019
+ transitive('saxon:saxon:jar:8.4', 'saxon:saxon:jar:8.4').size.should be(1)
1020
+ end
1021
+
1022
+ it 'should accept and return existing tasks' do
1023
+ transitive(task('foo'), task('bar')).should eql([task('foo'), task('bar')])
1024
+ end
1025
+
1026
+ it 'should accept filenames and expand them' do
1027
+ transitive('test').map(&:to_s).should eql([File.expand_path('test')])
1028
+ end
1029
+
1030
+ it 'should accept filenames and return file task' do
1031
+ transitive('c:test').first.should be_kind_of(Rake::FileTask)
1032
+ end
1033
+
1034
+ it 'should accept project and return all its packaging tasks' do
1035
+ define 'foobar', :group=>'group', :version=>'1.0' do
1036
+ package :jar, :id=>'code'
1037
+ package :war, :id=>'webapp'
1038
+ end
1039
+ foobar = project('foobar')
1040
+ transitive(foobar).should eql([
1041
+ task(foobar.path_to('target/code-1.0.jar')),
1042
+ task(foobar.path_to('target/webapp-1.0.war'))
1043
+ ])
1044
+ end
1045
+
1046
+ it 'should complain about an invalid specification' do
1047
+ lambda { transitive(5) }.should raise_error
1048
+ lambda { transitive('group:no:version:') }.should raise_error
1049
+ end
1050
+
1051
+ it 'should bring artifact and its dependencies' do
1052
+ transitive(@complex).should eql(artifacts(@complex, @simple))
1053
+ end
1054
+
1055
+ it 'should bring dependencies of POM without artifact itself' do
1056
+ transitive(@complex.sub(/jar/, 'pom')).should eql(artifacts(@simple))
1057
+ end
1058
+
1059
+ it 'should bring artifact and transitive depenencies' do
1060
+ transitive(@transitive).should eql(artifacts(@transitive, @complex, @simple - [@provided]))
1061
+ end
1062
+ end
1063
+
1064
+ def modified?(old_mtime, spec)
1065
+ File.exist?(artifact(spec).to_s) && old_mtime < File.mtime(artifact(spec).to_s)
1066
+ end