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,903 @@
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 'buildr/core/project'
18
+ require 'buildr/core/transports'
19
+ require 'buildr/packaging/artifact_namespace'
20
+ require 'fileutils'
21
+
22
+
23
+ module Buildr
24
+
25
+ desc 'Download all artifacts'
26
+ task 'artifacts'
27
+
28
+ desc "Download all artifacts' sources"
29
+ task 'artifacts:sources'
30
+
31
+ desc "Download all artifacts' javadoc"
32
+ task 'artifacts:javadoc'
33
+
34
+ # Mixin with a task to make it behave like an artifact. Implemented by the packaging tasks.
35
+ #
36
+ # An artifact has an identifier, group identifier, type, version number and
37
+ # optional classifier. All can be used to locate it in the local repository,
38
+ # download from or upload to a remote repository.
39
+ #
40
+ # The #to_spec and #to_hash methods allow it to be used everywhere an artifact is
41
+ # accepted.
42
+ module ActsAsArtifact
43
+
44
+ ARTIFACT_ATTRIBUTES = [:group, :id, :type, :classifier, :version]
45
+
46
+ class << self
47
+ private
48
+
49
+ # :stopdoc:
50
+ def included(mod)
51
+ mod.extend self
52
+ end
53
+
54
+ def extend_object(base)
55
+ base.instance_eval { alias :install_old :install } if base.respond_to? :install
56
+ base.instance_eval { alias :uninstall_old :uninstall } if base.respond_to? :uninstall
57
+ base.instance_eval { alias :upload_old :upload } if base.respond_to? :upload
58
+ super
59
+ end
60
+
61
+ def extended(base)
62
+ #We try to keep the previous instance methods defined on the base instance if there were ones.
63
+ base.instance_eval { alias :install :install_old } if base.respond_to? :install_old
64
+ base.instance_eval { alias :uninstall :uninstall_old } if base.respond_to? :uninstall_old
65
+ base.instance_eval { alias :upload :upload_old } if base.respond_to? :upload_old
66
+ end
67
+
68
+ # :startdoc:
69
+ end
70
+
71
+ # The artifact identifier.
72
+ attr_reader :id
73
+ # The group identifier.
74
+ attr_reader :group
75
+ # The file type. (Symbol)
76
+ attr_reader :type
77
+ # The version number.
78
+ attr_reader :version
79
+ # Optional artifact classifier.
80
+ attr_reader :classifier
81
+
82
+ def snapshot?
83
+ version =~ /-SNAPSHOT$/
84
+ end
85
+
86
+ # :call-seq:
87
+ # to_spec_hash => Hash
88
+ #
89
+ # Returns the artifact specification as a hash. For example:
90
+ # com.example:app:jar:1.2
91
+ # becomes:
92
+ # { :group=>'com.example',
93
+ # :id=>'app',
94
+ # :type=>:jar,
95
+ # :version=>'1.2' }
96
+ def to_spec_hash
97
+ base = { :group=>group, :id=>id, :type=>type, :version=>version }
98
+ classifier ? base.merge(:classifier=>classifier) : base
99
+ end
100
+ alias_method :to_hash, :to_spec_hash
101
+
102
+ # :call-seq:
103
+ # to_spec => String
104
+ #
105
+ # Returns the artifact specification, in the structure:
106
+ # <group>:<artifact>:<type>:<version>
107
+ # or
108
+ # <group>:<artifact>:<type>:<classifier>:<version>
109
+ def to_spec
110
+ classifier ? "#{group}:#{id}:#{type}:#{classifier}:#{version}" : "#{group}:#{id}:#{type}:#{version}"
111
+ end
112
+
113
+ # :call-seq:
114
+ # pom => Artifact
115
+ #
116
+ # Convenience method that returns a POM artifact.
117
+ def pom
118
+ return self if type == :pom
119
+ Buildr.artifact(:group=>group, :id=>id, :version=>version, :type=>:pom)
120
+ end
121
+
122
+ # :call-seq:
123
+ # sources_artifact => Artifact
124
+ #
125
+ # Convenience method that returns a sources artifact.
126
+ def sources_artifact
127
+ sources_spec = to_spec_hash.merge(:classifier=>'sources')
128
+ sources_task = OptionalArtifact.define_task(Buildr.repositories.locate(sources_spec))
129
+ sources_task.send :apply_spec, sources_spec
130
+ sources_task
131
+ end
132
+
133
+ # :call-seq:
134
+ # javadoc_artifact => Artifact
135
+ #
136
+ # Convenience method that returns the associated javadoc artifact
137
+ def javadoc_artifact
138
+ javadoc_spec = to_spec_hash.merge(:classifier=>'javadoc')
139
+ javadoc_task = OptionalArtifact.define_task(Buildr.repositories.locate(javadoc_spec))
140
+ javadoc_task.send :apply_spec, javadoc_spec
141
+ javadoc_task
142
+ end
143
+
144
+ # :call-seq:
145
+ # pom_xml => string
146
+ #
147
+ # Creates POM XML for this artifact.
148
+ def pom_xml
149
+ xml = Builder::XmlMarkup.new(:indent=>2)
150
+ xml.instruct!
151
+ xml.project do
152
+ xml.modelVersion '4.0.0'
153
+ xml.groupId group
154
+ xml.artifactId id
155
+ xml.version version
156
+ xml.classifier classifier if classifier
157
+ end
158
+ end
159
+
160
+ def install
161
+ invoke
162
+ in_local_repository = Buildr.repositories.locate(self)
163
+ if pom && pom != self && classifier.nil?
164
+ pom.invoke
165
+ pom.install
166
+ end
167
+ if name != in_local_repository
168
+ mkpath File.dirname(in_local_repository)
169
+ cp name, in_local_repository, :preserve => false
170
+ info "Installed #{name} to #{in_local_repository}"
171
+ end
172
+ end
173
+
174
+ def uninstall
175
+ installed = Buildr.repositories.locate(self)
176
+ rm installed if File.exist?(installed)
177
+ pom.uninstall if pom && pom != self && classifier.nil?
178
+ end
179
+
180
+ # :call-seq:
181
+ # upload
182
+ # upload(url)
183
+ # upload(options)
184
+ #
185
+ # Uploads the artifact, its POM and digital signatures to remote server.
186
+ #
187
+ # In the first form, uses the upload options specified by repositories.release_to.
188
+ # In the second form, uses a URL that includes all the relevant information.
189
+ # In the third form, uses a hash with the options :url, :username, :password,
190
+ # and :permissions. All but :url are optional.
191
+ def upload(upload_to = nil)
192
+ upload_task(upload_to).invoke
193
+ end
194
+
195
+ def upload_task(upload_to = nil)
196
+ upload_to ||= Buildr.repositories.release_to
197
+ upload_to = { :url=>upload_to } unless Hash === upload_to
198
+ raise ArgumentError, 'Don\'t know where to upload, perhaps you forgot to set repositories.release_to' unless upload_to[:url]
199
+
200
+ # Set the upload URI, including mandatory slash (we expect it to be the base directory).
201
+ # Username/password may be part of URI, or separate entities.
202
+ uri = URI.parse(upload_to[:url].clone)
203
+ uri.path = uri.path + '/' unless uri.path[-1] == '/'
204
+ uri.user = upload_to[:username] if upload_to[:username]
205
+ uri.password = upload_to[:password] if upload_to[:password]
206
+
207
+ path = group.gsub('.', '/') + "/#{id}/#{version}/#{File.basename(name)}"
208
+
209
+ unless task = Buildr.application.lookup(uri+path)
210
+ deps = [self]
211
+ deps << pom.upload_task( upload_to ) if pom && pom != self && classifier.nil?
212
+
213
+ task = Rake::Task.define_task uri + path => deps do
214
+ # Upload artifact relative to base URL, need to create path before uploading.
215
+ info "Deploying #{to_spec}"
216
+ URI.upload uri + path, name, :permissions=>upload_to[:permissions]
217
+ end
218
+ end
219
+ task
220
+ end
221
+
222
+ protected
223
+
224
+ # Apply specification to this artifact.
225
+ def apply_spec(spec)
226
+ spec = Artifact.to_hash(spec)
227
+ ARTIFACT_ATTRIBUTES.each { |key| instance_variable_set("@#{key}", spec[key]) }
228
+ self
229
+ end
230
+
231
+ def group_path
232
+ group.gsub('.', '/')
233
+ end
234
+
235
+ end
236
+
237
+
238
+ # A file task referencing an artifact in the local repository.
239
+ #
240
+ # This task includes all the artifact attributes (group, id, version, etc). It points
241
+ # to the artifact's path in the local repository. When invoked, it will download the
242
+ # artifact into the local repository if the artifact does not already exist.
243
+ #
244
+ # Note: You can enhance this task to create the artifact yourself, e.g. download it from
245
+ # a site that doesn't have a remote repository structure, copy it from a different disk, etc.
246
+ class Artifact < Rake::FileTask
247
+
248
+ # The default artifact type.
249
+ DEFAULT_TYPE = :jar
250
+
251
+ include ActsAsArtifact, Buildr
252
+
253
+ class << self
254
+
255
+ # :call-seq:
256
+ # lookup(spec) => Artifact
257
+ #
258
+ # Lookup a previously registered artifact task based on its specification (String or Hash).
259
+ def lookup(spec)
260
+ @artifacts ||= {}
261
+ @artifacts[to_spec(spec)]
262
+ end
263
+
264
+ # :call-seq:
265
+ # list => specs
266
+ #
267
+ # Returns an array of specs for all the registered artifacts. (Anything created from artifact, or package).
268
+ def list
269
+ @artifacts ||= {}
270
+ @artifacts.keys
271
+ end
272
+
273
+ # :call-seq:
274
+ # register(artifacts) => artifacts
275
+ #
276
+ # Register an artifact task(s) for later lookup (see #lookup).
277
+ def register(*tasks)
278
+ @artifacts ||= {}
279
+ fail 'You can only register an artifact task, one of the arguments is not a Task that responds to to_spec' unless
280
+ tasks.all? { |task| task.respond_to?(:to_spec) && task.respond_to?(:invoke) }
281
+ tasks.each { |task| @artifacts[task.to_spec] = task }
282
+ tasks
283
+ end
284
+
285
+ # :call-seq:
286
+ # to_hash(spec_hash) => spec_hash
287
+ # to_hash(spec_string) => spec_hash
288
+ # to_hash(artifact) => spec_hash
289
+ #
290
+ # Turn a spec into a hash. This method accepts a String, Hash or any object that responds to
291
+ # the method to_spec. There are several reasons to use this method:
292
+ # * You can pass anything that could possibly be a spec, and get a hash.
293
+ # * It will check that the spec includes the group identifier, artifact
294
+ # identifier and version number and set the file type, if missing.
295
+ # * It will always return a new specs hash.
296
+ def to_hash(spec)
297
+ if spec.respond_to?(:to_spec)
298
+ to_hash spec.to_spec
299
+ elsif Hash === spec
300
+ rake_check_options spec, :id, :group, :type, :classifier, :version
301
+ # Sanitize the hash and check it's valid.
302
+ spec = ARTIFACT_ATTRIBUTES.inject({}) { |h, k| h[k] = spec[k].to_s if spec[k] ; h }
303
+ fail "Missing group identifier for #{spec.inspect}" unless spec[:group]
304
+ fail "Missing artifact identifier for #{spec.inspect}" unless spec[:id]
305
+ fail "Missing version for #{spec.inspect}" unless spec[:version]
306
+ spec[:type] = (spec[:type] || DEFAULT_TYPE).to_sym
307
+ spec
308
+ elsif String === spec
309
+ group, id, type, version, *rest = spec.split(':').map { |part| part.empty? ? nil : part }
310
+ unless rest.empty?
311
+ # Optional classifier comes before version.
312
+ classifier, version = version, rest.shift
313
+ fail "Expecting <group:id:type:version> or <group:id:type:classifier:version>, found <#{spec}>" unless rest.empty?
314
+ end
315
+ to_hash :group=>group, :id=>id, :type=>type, :version=>version, :classifier=>classifier
316
+ else
317
+ fail 'Expecting a String, Hash or object that responds to to_spec'
318
+ end
319
+ end
320
+
321
+ # :call-seq:
322
+ # to_spec(spec_hash) => spec_string
323
+ #
324
+ # Convert a hash back to a spec string. This method accepts
325
+ # a string, hash or any object that responds to to_spec.
326
+ def to_spec(hash)
327
+ hash = to_hash(hash) unless Hash === hash
328
+ version = ":#{hash[:version]}" if hash[:version]
329
+ classifier = ":#{hash[:classifier]}" if hash[:classifier]
330
+ "#{hash[:group]}:#{hash[:id]}:#{hash[:type] || DEFAULT_TYPE}#{classifier}#{version}"
331
+ end
332
+
333
+ # :call-seq:
334
+ # hash_to_file_name(spec_hash) => file_name
335
+ #
336
+ # Convert a hash spec to a file name.
337
+ def hash_to_file_name(hash)
338
+ version = "-#{hash[:version]}" if hash[:version]
339
+ classifier = "-#{hash[:classifier]}" if hash[:classifier]
340
+ "#{hash[:id]}#{version}#{classifier}.#{hash[:type] || DEFAULT_TYPE}"
341
+ end
342
+
343
+ end
344
+
345
+ def initialize(*args) #:nodoc:
346
+ super
347
+ enhance do |task|
348
+ # Default behavior: download the artifact from one of the remote repositories
349
+ # if the file does not exist. But this default behavior is counter productive
350
+ # if the artifact knows how to build itself (e.g. download from a different location),
351
+ # so don't perform it if the task found a different way to create the artifact.
352
+ task.enhance do
353
+ if download_needed? task
354
+ info "Downloading #{to_spec}"
355
+ download
356
+ pom.invoke rescue nil if pom && pom != self && classifier.nil?
357
+ end
358
+ end
359
+ end
360
+ end
361
+
362
+ # :call-seq:
363
+ # from(path) => self
364
+ #
365
+ # Use this when you want to install or upload an artifact from a given file, for example:
366
+ # test = artifact('group:id:jar:1.0').from('test.jar')
367
+ # install test
368
+ # See also Buildr#install and Buildr#upload.
369
+ def from(path)
370
+ @from = path.is_a?(Rake::Task) ? path : File.expand_path(path.to_s)
371
+ enhance [@from] do
372
+ mkpath File.dirname(name)
373
+ cp @from.to_s, name
374
+ end
375
+ pom.content pom_xml unless pom == self || pom.has_content?
376
+ self
377
+ end
378
+
379
+ # :call-seq:
380
+ # content(string) => self
381
+ #
382
+ # Use this when you want to install or upload an artifact from a given content, for example:
383
+ # readme = artifact('com.example:readme:txt:1.0').content(<<-EOF
384
+ # Please visit our website at http://example.com/readme
385
+ # <<EOF
386
+ # install readme
387
+ #
388
+ # If the argument is not a string, it will be converted to a string using to_s
389
+ def content(string = nil)
390
+ return @content unless string
391
+
392
+ unless @content
393
+ enhance do
394
+ write name, @content
395
+ end
396
+
397
+ class << self
398
+ # Force overwriting target since we don't have source file
399
+ # to check for timestamp modification
400
+ def needed?
401
+ true
402
+ end
403
+ end
404
+ end
405
+ @content = string
406
+ pom.content pom_xml unless pom == self || pom.has_content?
407
+ self
408
+ end
409
+
410
+ protected
411
+
412
+ def has_content?
413
+ @from || @content
414
+ end
415
+
416
+ # :call-seq:
417
+ # download
418
+ #
419
+ # Downloads an artifact from one of the remote repositories, and stores it in the local
420
+ # repository. Raises an exception if the artifact is not found.
421
+ #
422
+ # This method attempts to download the artifact from each repository in the order in
423
+ # which they are returned from #remote, until successful.
424
+ def download
425
+ trace "Downloading #{to_spec}"
426
+ remote = Buildr.repositories.remote.map { |repo_url| URI === repo_url ? repo_url : URI.parse(repo_url) }
427
+ remote = remote.each { |repo_url| repo_url.path += '/' unless repo_url.path[-1] == '/' }
428
+ fail "Unable to download #{to_spec}. No remote repositories defined." if remote.empty?
429
+ exact_success = remote.find do |repo_url|
430
+ begin
431
+ path = "#{group_path}/#{id}/#{version}/#{File.basename(name)}"
432
+ download_artifact(repo_url + path)
433
+ true
434
+ rescue URI::NotFoundError
435
+ false
436
+ rescue Exception=>error
437
+ info error
438
+ trace error.backtrace.join("\n")
439
+ false
440
+ end
441
+ end
442
+
443
+ if exact_success
444
+ return
445
+ elsif snapshot?
446
+ download_m2_snapshot(remote)
447
+ else
448
+ fail_download(remote)
449
+ end
450
+ end
451
+
452
+ def download_m2_snapshot(remote_uris)
453
+ remote_uris.find do |repo_url|
454
+ snapshot_url = current_snapshot_repo_url(repo_url)
455
+ if snapshot_url
456
+ begin
457
+ download_artifact snapshot_url
458
+ true
459
+ rescue URI::NotFoundError
460
+ false
461
+ end
462
+ else
463
+ false
464
+ end
465
+ end or fail_download(remote_uris)
466
+ end
467
+
468
+ def current_snapshot_repo_url(repo_url)
469
+ begin
470
+ metadata_path = "#{group_path}/#{id}/#{version}/maven-metadata.xml"
471
+ metadata_xml = StringIO.new
472
+ URI.download repo_url + metadata_path, metadata_xml
473
+ metadata = REXML::Document.new(metadata_xml.string).root
474
+ timestamp = REXML::XPath.first(metadata, '//timestamp')
475
+ build_number = REXML::XPath.first(metadata, '//buildNumber')
476
+ error "No timestamp provided for the snapshot #{to_spec}" if timestamp.nil?
477
+ error "No build number provided for the snapshot #{to_spec}" if build_number.nil?
478
+ return nil if timestamp.nil? || build_number.nil?
479
+ snapshot_of = version[0, version.size - 9]
480
+ repo_url + "#{group_path}/#{id}/#{version}/#{id}-#{snapshot_of}-#{timestamp.text}-#{build_number.text}.#{type}"
481
+ rescue URI::NotFoundError
482
+ nil
483
+ end
484
+ end
485
+
486
+ def fail_download(remote_uris)
487
+ fail "Failed to download #{to_spec}, tried the following repositories:\n#{remote_uris.join("\n")}"
488
+ end
489
+
490
+ protected
491
+
492
+ # :call-seq:
493
+ # needed?
494
+ #
495
+ # Validates whether artifact is required to be downloaded from repository
496
+ def needed?
497
+ return true if snapshot? && File.exist?(name) && (update_snapshot? || old?)
498
+ super
499
+ end
500
+
501
+ private
502
+
503
+ # :call-seq:
504
+ # download_artifact
505
+ #
506
+ # Downloads artifact from given repository,
507
+ # supports downloading snapshot artifact with relocation on succeed to local repository
508
+ def download_artifact(path)
509
+ download_file = "#{name}.#{Time.new.to_i}"
510
+ begin
511
+ URI.download path, download_file
512
+ if File.exist?(download_file)
513
+ FileUtils.mkdir_p(File.dirname(name))
514
+ FileUtils.mv(download_file, name)
515
+ end
516
+ ensure
517
+ File.delete(download_file) if File.exist?(download_file)
518
+ end
519
+ end
520
+
521
+ # :call-seq:
522
+ # :download_needed?
523
+ #
524
+ # Validates whether artifact is required to be downloaded from repository
525
+ def download_needed?(task)
526
+ return true if !File.exist?(name)
527
+
528
+ if snapshot?
529
+ return false if offline? && File.exist?(name)
530
+ return true if update_snapshot? || old?
531
+ end
532
+
533
+ return false
534
+ end
535
+
536
+ def update_snapshot?
537
+ Buildr.application.options.update_snapshots
538
+ end
539
+
540
+ def offline?
541
+ Buildr.application.options.work_offline
542
+ end
543
+
544
+ # :call-seq:
545
+ # old?
546
+ #
547
+ # Checks whether existing artifact is older than period from build settings or one day
548
+ def old?
549
+ settings = Buildr.application.settings
550
+ time_to_be_old = settings.user[:expire_time] || settings.build[:expire_time] || 60 * 60 * 24
551
+ File.mtime(name).to_i < (Time.new.to_i - time_to_be_old)
552
+ end
553
+
554
+ end
555
+
556
+
557
+ # An artifact that is optional.
558
+ # If downloading fails, the user will be informed but it will not raise an exception.
559
+ class OptionalArtifact < Artifact
560
+
561
+ protected
562
+
563
+ # If downloading fails, the user will be informed but it will not raise an exception.
564
+ def download
565
+ super
566
+ rescue
567
+ info "Failed to download #{to_spec}. Skipping it."
568
+ end
569
+
570
+ end
571
+
572
+
573
+ # Holds the path to the local repository, URLs for remote repositories, and settings for release server.
574
+ #
575
+ # You can access this object from the #repositories method. For example:
576
+ # puts repositories.local
577
+ # repositories.remote << 'http://example.com/repo'
578
+ # repositories.release_to = 'sftp://example.com/var/www/public/repo'
579
+ class Repositories
580
+ include Singleton
581
+
582
+ # :call-seq:
583
+ # local => path
584
+ #
585
+ # Returns the path to the local repository.
586
+ #
587
+ # The default path is .m2/repository relative to the home directory.
588
+ # You can set this using the M2_REPO environment variable or the repositories/local
589
+ # value in your settings.yaml file.
590
+ def local
591
+ @local ||= File.expand_path(ENV['M2_REPO'] || ENV['local_repo'] ||
592
+ (Buildr.settings.user['repositories'] && Buildr.settings.user['repositories']['local']) ||
593
+ File.join(ENV['HOME'], '.m2/repository'))
594
+ end
595
+
596
+ # :call-seq:
597
+ # local = path
598
+ #
599
+ # Sets the path to the local repository.
600
+ #
601
+ # The best place to set the local repository path is from a buildr.rb file
602
+ # located in the .buildr directory under your home directory. That way all
603
+ # your projects will share the same path, without affecting other developers
604
+ # collaborating on these projects.
605
+ def local=(dir)
606
+ @local = dir ? File.expand_path(dir) : nil
607
+ end
608
+
609
+ # :call-seq:
610
+ # locate(spec) => path
611
+ #
612
+ # Locates an artifact in the local repository based on its specification, and returns
613
+ # a file path.
614
+ #
615
+ # For example:
616
+ # locate :group=>'log4j', :id=>'log4j', :version=>'1.1'
617
+ # => ~/.m2/repository/log4j/log4j/1.1/log4j-1.1.jar
618
+ def locate(spec)
619
+ spec = Artifact.to_hash(spec)
620
+ File.join(local, spec[:group].split('.'), spec[:id], spec[:version], Artifact.hash_to_file_name(spec))
621
+ end
622
+
623
+ # :call-seq:
624
+ # remote => Array
625
+ #
626
+ # Returns an array of all the remote repository URLs.
627
+ #
628
+ # When downloading artifacts, repositories are accessed in the order in which they appear here.
629
+ # The best way is to add repositories individually, for example:
630
+ # repositories.remote << 'http://example.com/repo'
631
+ #
632
+ # You can also specify remote repositories in the settings.yaml (per user) and build.yaml (per build)
633
+ # files. Both sets of URLs are loaded by default into this array, URLs from the personal setting
634
+ # showing first.
635
+ #
636
+ # For example:
637
+ # repositories:
638
+ # remote:
639
+ # - http://example.com/repo
640
+ # - http://elsewhere.com/repo
641
+ def remote
642
+ unless @remote
643
+ @remote = [Buildr.settings.user, Buildr.settings.build].inject([]) { |repos, hash|
644
+ repos | Array(hash['repositories'] && hash['repositories']['remote'])
645
+ }
646
+ end
647
+ @remote
648
+ end
649
+
650
+ # :call-seq:
651
+ # remote = Array
652
+ # remote = url
653
+ # remote = nil
654
+ #
655
+ # With a String argument, clears the array and set it to that single URL.
656
+ #
657
+ # With an Array argument, clears the array and set it to these specific URLs.
658
+ #
659
+ # With nil, clears the array.
660
+ def remote=(urls)
661
+ case urls
662
+ when nil then @remote = nil
663
+ when Array then @remote = urls.dup
664
+ else @remote = [urls.to_s]
665
+ end
666
+ end
667
+
668
+ # :call-seq:
669
+ # release_to = url
670
+ # release_to = hash
671
+ #
672
+ # Specifies the release server. Accepts a Hash with different repository settings
673
+ # (e.g. url, username, password), or a String to only set the repository URL.
674
+ #
675
+ # Besides the URL, all other settings depend on the transport protocol in use.
676
+ #
677
+ # For example:
678
+ # repositories.release_to = 'sftp://john:secret@example.com/var/www/repo/'
679
+ #
680
+ # repositories.release_to = { :url=>'sftp://example.com/var/www/repo/',
681
+ # :username='john', :password=>'secret' }
682
+ # Or in the settings.yaml file:
683
+ # repositories:
684
+ # release_to: sftp://john:secret@example.com/var/www/repo/
685
+ #
686
+ # repositories:
687
+ # release_to:
688
+ # url: sftp://example.com/var/www/repo/
689
+ # username: john
690
+ # password: secret
691
+ def release_to=(options)
692
+ options = { :url=>options } unless Hash === options
693
+ @release_to = options
694
+ end
695
+
696
+ # :call-seq:
697
+ # release_to => hash
698
+ #
699
+ # Returns the current release server setting as a Hash. This is a more convenient way to
700
+ # configure the settings, as it allows you to specify the settings progressively.
701
+ #
702
+ # For example, the Buildfile will contain the repository URL used by all developers:
703
+ # repositories.release_to[:url] ||= 'sftp://example.com/var/www/repo'
704
+ # Your private buildr.rb will contain your credentials:
705
+ # repositories.release_to[:username] = 'john'
706
+ # repositories.release_to[:password] = 'secret'
707
+ def release_to
708
+ unless @release_to
709
+ value = (Buildr.settings.user['repositories'] && Buildr.settings.user['repositories']['release_to']) \
710
+ || (Buildr.settings.build['repositories'] && Buildr.settings.build['repositories']['release_to'])
711
+ @release_to = Hash === value ? value.inject({}) { |hash, (key, value)| hash.update(key.to_sym=>value) } : { :url=>Array(value).first }
712
+ end
713
+ @release_to
714
+ end
715
+
716
+ end
717
+
718
+ # :call-seq:
719
+ # repositories => Repositories
720
+ #
721
+ # Returns an object you can use for setting the local repository path, remote repositories
722
+ # URL and release server settings.
723
+ #
724
+ # See Repositories.
725
+ def repositories
726
+ Repositories.instance
727
+ end
728
+
729
+ # :call-seq:
730
+ # artifact(spec) => Artifact
731
+ # artifact(spec) { |task| ... } => Artifact
732
+ #
733
+ # Creates a file task to download and install the specified artifact in the local repository.
734
+ #
735
+ # You can use a String or a Hash for the artifact specification. The file task will point at
736
+ # the artifact's path inside the local repository. You can then use this tasks as a prerequisite
737
+ # for other tasks.
738
+ #
739
+ # This task will download and install the artifact only once. In fact, it will download and
740
+ # install the artifact if the artifact does not already exist. You can enhance it if you have
741
+ # a different way of creating the artifact in the local repository. See Artifact for more details.
742
+ #
743
+ # For example, to specify an artifact:
744
+ # artifact('log4j:log4j:jar:1.1')
745
+ #
746
+ # To use the artifact in a task:
747
+ # compile.with artifact('log4j:log4j:jar:1.1')
748
+ #
749
+ # To specify an artifact and the means for creating it:
750
+ # download(artifact('dojo:dojo-widget:zip:2.0')=>
751
+ # 'http://download.dojotoolkit.org/release-2.0/dojo-2.0-widget.zip')
752
+ def artifact(spec, path = nil, &block) #:yields:task
753
+ spec = artifact_ns.fetch(spec) if spec.kind_of?(Symbol)
754
+ spec = Artifact.to_hash(spec)
755
+ unless task = Artifact.lookup(spec)
756
+ task = Artifact.define_task(path || repositories.locate(spec))
757
+ task.send :apply_spec, spec
758
+ Rake::Task['rake:artifacts'].enhance [task]
759
+ Artifact.register(task)
760
+ unless spec[:type] == :pom
761
+ Rake::Task['artifacts:sources'].enhance [task.sources_artifact]
762
+ Rake::Task['artifacts:javadoc'].enhance [task.javadoc_artifact]
763
+ end
764
+ end
765
+ task.enhance &block
766
+ end
767
+
768
+ # :call-seq:
769
+ # artifacts(*spec) => artifacts
770
+ #
771
+ # Handles multiple artifacts at a time. This method is the plural equivalent of
772
+ # #artifact, but can do more things.
773
+ #
774
+ # Returns an array of artifacts built using the supplied
775
+ # specifications, each of which can be:
776
+ # * An artifact specification (String or Hash). Returns the appropriate Artifact task.
777
+ # * An artifact of any other task. Returns the task as is.
778
+ # * A project. Returns all artifacts created (packaged) by that project.
779
+ # * A string. Returns that string, assumed to be a file name.
780
+ # * An array of artifacts or a Struct.
781
+ # * A symbol. Returns the named artifact from the current ArtifactNamespace
782
+ #
783
+ # For example, handling a collection of artifacts:
784
+ # xml = [ xerces, xalan, jaxp ]
785
+ # ws = [ axis, jax-ws, jaxb ]
786
+ # db = [ jpa, mysql, sqltools ]
787
+ # artifacts(xml, ws, db)
788
+ #
789
+ # Using artifacts created by a project:
790
+ # artifacts project('my-app') # All packages
791
+ # artifacts project('my-app').package(:war) # Only the WAR
792
+ def artifacts(*specs, &block)
793
+ specs.flatten.inject([]) do |set, spec|
794
+ case spec
795
+ when ArtifactNamespace
796
+ set |= spec.artifacts
797
+ when Symbol, Hash
798
+ set |= [artifact(spec)]
799
+ when /([^:]+:){2,4}/ # A spec as opposed to a file name.
800
+ set |= [artifact(spec)]
801
+ when String # Must always expand path.
802
+ set |= [File.expand_path(spec)]
803
+ when Project
804
+ set |= artifacts(spec.packages)
805
+ when Rake::Task
806
+ set |= [spec]
807
+ when Struct
808
+ set |= artifacts(spec.values)
809
+ else
810
+ fail "Invalid artifact specification in #{specs.inspect}"
811
+ end
812
+ end
813
+ end
814
+
815
+ def transitive(*specs)
816
+ specs.flatten.inject([]) do |set, spec|
817
+ case spec
818
+ when /([^:]+:){2,4}/ # A spec as opposed to a file name.
819
+ artifact = artifact(spec)
820
+ set |= [artifact] unless artifact.type == :pom
821
+ set |= POM.load(artifact.pom).dependencies.map { |spec| artifact(spec) }
822
+ when Hash
823
+ set |= [transitive(spec)]
824
+ when String # Must always expand path.
825
+ set |= transitive(file(File.expand_path(spec)))
826
+ when Project
827
+ set |= transitive(spec.packages)
828
+ when Rake::Task
829
+ set |= spec.respond_to?(:to_spec) ? transitive(spec.to_spec) : [spec]
830
+ when Struct
831
+ set |= transitive(spec.values)
832
+ else
833
+ fail "Invalid artifact specification in: #{specs.to_s}"
834
+ end
835
+ end
836
+ end
837
+
838
+ # :call-seq:
839
+ # group(ids, :under=>group_name, :version=>number) => artifacts
840
+ #
841
+ # Convenience method for defining multiple artifacts that belong to the same group, type and version.
842
+ # Accepts multiple artifact identifiers followed by two or three hash values:
843
+ # * :under -- The group identifier
844
+ # * :version -- The version number
845
+ # * :type -- The artifact type (optional)
846
+ # * :classifier -- The artifact classifier (optional)
847
+ #
848
+ # For example:
849
+ # group 'xbean', 'xbean_xpath', 'xmlpublic', :under=>'xmlbeans', :version=>'2.1.0'
850
+ # Or:
851
+ # group %w{xbean xbean_xpath xmlpublic}, :under=>'xmlbeans', :version=>'2.1.0'
852
+ def group(*args)
853
+ hash = args.pop
854
+ args.flatten.map do |id|
855
+ artifact :group => hash[:under],
856
+ :type => hash[:type],
857
+ :version => hash[:version],
858
+ :classifier => hash[:classifier],
859
+ :id => id
860
+ end
861
+ end
862
+
863
+ # :call-seq:
864
+ # install(artifacts) => install_task
865
+ #
866
+ # Installs the specified artifacts in the local repository as part of the install task.
867
+ #
868
+ # You can use this to install various files in the local repository, for example:
869
+ # install artifact('group:id:jar:1.0').from('some_jar.jar')
870
+ # $ buildr install
871
+ def install(*args, &block)
872
+ artifacts = artifacts(args).uniq
873
+ raise ArgumentError, 'This method can only install artifacts' unless artifacts.all? { |f| f.respond_to?(:to_spec) }
874
+ task('install').tap do |install|
875
+ install.enhance(artifacts) do
876
+ artifacts.each(&:install)
877
+ end
878
+ install.enhance &block if block
879
+ task('uninstall') do
880
+ artifacts.map(&:to_s ).each { |file| rm file if File.exist?(file) }
881
+ end
882
+ end
883
+ end
884
+
885
+ # :call-seq:
886
+ # upload(artifacts)
887
+ #
888
+ # Uploads the specified artifacts to the release server as part of the upload task.
889
+ #
890
+ # You can use this to upload various files to the release server, for example:
891
+ # upload artifact('group:id:jar:1.0').from('some_jar.jar')
892
+ # $ buildr upload
893
+ def upload(*args, &block)
894
+ artifacts = artifacts(args)
895
+ raise ArgumentError, 'This method can only upload artifacts' unless artifacts.all? { |f| f.respond_to?(:to_spec) }
896
+ upload_artifacts_tasks = artifacts.map { |artifact| artifact.upload_task }
897
+ task('upload').tap do |task|
898
+ task.enhance &block if block
899
+ task.enhance upload_artifacts_tasks
900
+ end
901
+ end
902
+
903
+ end