mguymon-buildr 1.4.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/CHANGELOG +1291 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +44 -0
  6. data/_buildr +35 -0
  7. data/_jbuildr +35 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/bnd.rb +147 -0
  10. data/addon/buildr/cobertura.rb +22 -0
  11. data/addon/buildr/drb.rb +281 -0
  12. data/addon/buildr/emma.rb +22 -0
  13. data/addon/buildr/hibernate.rb +149 -0
  14. data/addon/buildr/javacc.rb +85 -0
  15. data/addon/buildr/jaxb_xjc.rb +72 -0
  16. data/addon/buildr/jdepend.rb +60 -0
  17. data/addon/buildr/jetty.rb +248 -0
  18. data/addon/buildr/jibx.rb +86 -0
  19. data/addon/buildr/nailgun.rb +221 -0
  20. data/addon/buildr/openjpa.rb +88 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  23. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  27. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  28. data/addon/buildr/protobuf.rb +88 -0
  29. data/addon/buildr/xmlbeans.rb +93 -0
  30. data/bin/buildr +19 -0
  31. data/buildr.buildfile +58 -0
  32. data/buildr.gemspec +78 -0
  33. data/doc/_config.yml +1 -0
  34. data/doc/_layouts/default.html +90 -0
  35. data/doc/_layouts/preface.html +22 -0
  36. data/doc/artifacts.textile +217 -0
  37. data/doc/building.textile +276 -0
  38. data/doc/contributing.textile +268 -0
  39. data/doc/css/default.css +236 -0
  40. data/doc/css/print.css +101 -0
  41. data/doc/css/syntax.css +23 -0
  42. data/doc/download.textile +151 -0
  43. data/doc/extending.textile +212 -0
  44. data/doc/images/1442160941-frontcover.jpg +0 -0
  45. data/doc/images/asf-logo.gif +0 -0
  46. data/doc/images/asf-logo.png +0 -0
  47. data/doc/images/buildr-hires.png +0 -0
  48. data/doc/images/buildr.png +0 -0
  49. data/doc/images/favicon.png +0 -0
  50. data/doc/images/growl-icon.tiff +0 -0
  51. data/doc/images/note.png +0 -0
  52. data/doc/images/project-structure.png +0 -0
  53. data/doc/images/tip.png +0 -0
  54. data/doc/images/zbuildr.png +0 -0
  55. data/doc/images/zbuildr.tif +0 -0
  56. data/doc/index.textile +109 -0
  57. data/doc/installing.textile +284 -0
  58. data/doc/languages.textile +599 -0
  59. data/doc/mailing_lists.textile +29 -0
  60. data/doc/more_stuff.textile +845 -0
  61. data/doc/packaging.textile +618 -0
  62. data/doc/preface.textile +54 -0
  63. data/doc/projects.textile +276 -0
  64. data/doc/quick_start.textile +210 -0
  65. data/doc/releasing.textile +117 -0
  66. data/doc/scripts/buildr-git.rb +512 -0
  67. data/doc/scripts/gitflow.rb +296 -0
  68. data/doc/scripts/install-jruby.sh +44 -0
  69. data/doc/scripts/install-linux.sh +73 -0
  70. data/doc/scripts/install-osx.sh +52 -0
  71. data/doc/settings_profiles.textile +287 -0
  72. data/doc/testing.textile +247 -0
  73. data/etc/KEYS +189 -0
  74. data/lib/buildr.rb +44 -0
  75. data/lib/buildr/clojure.rb +34 -0
  76. data/lib/buildr/clojure/shell.rb +52 -0
  77. data/lib/buildr/core.rb +34 -0
  78. data/lib/buildr/core/application.rb +700 -0
  79. data/lib/buildr/core/build.rb +516 -0
  80. data/lib/buildr/core/cc.rb +166 -0
  81. data/lib/buildr/core/checks.rb +253 -0
  82. data/lib/buildr/core/common.rb +151 -0
  83. data/lib/buildr/core/compile.rb +622 -0
  84. data/lib/buildr/core/doc.rb +276 -0
  85. data/lib/buildr/core/environment.rb +129 -0
  86. data/lib/buildr/core/filter.rb +404 -0
  87. data/lib/buildr/core/generate.rb +197 -0
  88. data/lib/buildr/core/help.rb +119 -0
  89. data/lib/buildr/core/jrebel.rb +42 -0
  90. data/lib/buildr/core/linux.rb +30 -0
  91. data/lib/buildr/core/osx.rb +46 -0
  92. data/lib/buildr/core/progressbar.rb +161 -0
  93. data/lib/buildr/core/project.rb +975 -0
  94. data/lib/buildr/core/run.rb +43 -0
  95. data/lib/buildr/core/shell.rb +137 -0
  96. data/lib/buildr/core/test.rb +843 -0
  97. data/lib/buildr/core/transports.rb +575 -0
  98. data/lib/buildr/core/util.rb +537 -0
  99. data/lib/buildr/groovy.rb +20 -0
  100. data/lib/buildr/groovy/bdd.rb +106 -0
  101. data/lib/buildr/groovy/compiler.rb +153 -0
  102. data/lib/buildr/groovy/doc.rb +76 -0
  103. data/lib/buildr/groovy/shell.rb +57 -0
  104. data/lib/buildr/ide.rb +19 -0
  105. data/lib/buildr/ide/eclipse.rb +427 -0
  106. data/lib/buildr/ide/eclipse/java.rb +53 -0
  107. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  108. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  109. data/lib/buildr/ide/idea.rb +576 -0
  110. data/lib/buildr/java.rb +25 -0
  111. data/lib/buildr/java/ant.rb +94 -0
  112. data/lib/buildr/java/bdd.rb +460 -0
  113. data/lib/buildr/java/cobertura.rb +297 -0
  114. data/lib/buildr/java/commands.rb +223 -0
  115. data/lib/buildr/java/compiler.rb +135 -0
  116. data/lib/buildr/java/deprecated.rb +141 -0
  117. data/lib/buildr/java/doc.rb +86 -0
  118. data/lib/buildr/java/ecj.rb +69 -0
  119. data/lib/buildr/java/emma.rb +244 -0
  120. data/lib/buildr/java/external.rb +73 -0
  121. data/lib/buildr/java/jruby.rb +122 -0
  122. data/lib/buildr/java/jtestr_result.rb +295 -0
  123. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  124. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  125. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  126. data/lib/buildr/java/packaging.rb +734 -0
  127. data/lib/buildr/java/pom.rb +178 -0
  128. data/lib/buildr/java/rjb.rb +154 -0
  129. data/lib/buildr/java/test_result.rb +101 -0
  130. data/lib/buildr/java/tests.rb +362 -0
  131. data/lib/buildr/java/version_requirement.rb +172 -0
  132. data/lib/buildr/packaging.rb +25 -0
  133. data/lib/buildr/packaging/archive.rb +535 -0
  134. data/lib/buildr/packaging/artifact.rb +904 -0
  135. data/lib/buildr/packaging/artifact_namespace.rb +984 -0
  136. data/lib/buildr/packaging/artifact_search.rb +140 -0
  137. data/lib/buildr/packaging/gems.rb +105 -0
  138. data/lib/buildr/packaging/package.rb +249 -0
  139. data/lib/buildr/packaging/repository_array.rb +108 -0
  140. data/lib/buildr/packaging/tar.rb +189 -0
  141. data/lib/buildr/packaging/version_requirement.rb +192 -0
  142. data/lib/buildr/packaging/zip.rb +178 -0
  143. data/lib/buildr/packaging/ziptask.rb +356 -0
  144. data/lib/buildr/resources/buildr.icns +0 -0
  145. data/lib/buildr/resources/completed.png +0 -0
  146. data/lib/buildr/resources/failed.png +0 -0
  147. data/lib/buildr/resources/icons-license.txt +17 -0
  148. data/lib/buildr/run.rb +195 -0
  149. data/lib/buildr/scala.rb +26 -0
  150. data/lib/buildr/scala/bdd.rb +118 -0
  151. data/lib/buildr/scala/compiler.rb +242 -0
  152. data/lib/buildr/scala/doc.rb +142 -0
  153. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  154. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  155. data/lib/buildr/scala/shell.rb +52 -0
  156. data/lib/buildr/scala/tests.rb +171 -0
  157. data/lib/buildr/shell.rb +185 -0
  158. data/lib/buildr/version.rb +18 -0
  159. data/rakelib/all-in-one.rake +113 -0
  160. data/rakelib/checks.rake +57 -0
  161. data/rakelib/doc.rake +137 -0
  162. data/rakelib/metrics.rake +39 -0
  163. data/rakelib/package.rake +73 -0
  164. data/rakelib/release.rake +160 -0
  165. data/rakelib/rspec.rake +91 -0
  166. data/rakelib/setup.rake +66 -0
  167. data/rakelib/stage.rake +220 -0
  168. data/spec/addon/bnd_spec.rb +330 -0
  169. data/spec/addon/drb_spec.rb +328 -0
  170. data/spec/addon/jaxb_xjc_spec.rb +125 -0
  171. data/spec/core/application_spec.rb +631 -0
  172. data/spec/core/build_spec.rb +837 -0
  173. data/spec/core/cc_spec.rb +224 -0
  174. data/spec/core/checks_spec.rb +519 -0
  175. data/spec/core/common_spec.rb +725 -0
  176. data/spec/core/compile_spec.rb +658 -0
  177. data/spec/core/doc_spec.rb +195 -0
  178. data/spec/core/extension_spec.rb +201 -0
  179. data/spec/core/generate_spec.rb +33 -0
  180. data/spec/core/project_spec.rb +772 -0
  181. data/spec/core/run_spec.rb +93 -0
  182. data/spec/core/shell_spec.rb +146 -0
  183. data/spec/core/test_spec.rb +1320 -0
  184. data/spec/core/transport_spec.rb +544 -0
  185. data/spec/core/util_spec.rb +141 -0
  186. data/spec/groovy/bdd_spec.rb +80 -0
  187. data/spec/groovy/compiler_spec.rb +251 -0
  188. data/spec/groovy/doc_spec.rb +65 -0
  189. data/spec/ide/eclipse_spec.rb +739 -0
  190. data/spec/ide/idea_spec.rb +1145 -0
  191. data/spec/java/ant_spec.rb +37 -0
  192. data/spec/java/bdd_spec.rb +374 -0
  193. data/spec/java/cobertura_spec.rb +112 -0
  194. data/spec/java/commands_spec.rb +93 -0
  195. data/spec/java/compiler_spec.rb +252 -0
  196. data/spec/java/doc_spec.rb +56 -0
  197. data/spec/java/ecj_spec.rb +115 -0
  198. data/spec/java/emma_spec.rb +121 -0
  199. data/spec/java/external_spec.rb +56 -0
  200. data/spec/java/java_spec.rb +132 -0
  201. data/spec/java/packaging_spec.rb +1266 -0
  202. data/spec/java/run_spec.rb +78 -0
  203. data/spec/java/test_coverage_helper.rb +257 -0
  204. data/spec/java/tests_spec.rb +497 -0
  205. data/spec/packaging/archive_spec.rb +775 -0
  206. data/spec/packaging/artifact_namespace_spec.rb +743 -0
  207. data/spec/packaging/artifact_spec.rb +1074 -0
  208. data/spec/packaging/packaging_helper.rb +63 -0
  209. data/spec/packaging/packaging_spec.rb +719 -0
  210. data/spec/packaging/repository_array_spec.rb +109 -0
  211. data/spec/sandbox.rb +165 -0
  212. data/spec/scala/bdd_spec.rb +124 -0
  213. data/spec/scala/compiler_spec.rb +289 -0
  214. data/spec/scala/doc_spec.rb +88 -0
  215. data/spec/scala/scala.rb +38 -0
  216. data/spec/scala/tests_spec.rb +283 -0
  217. data/spec/spec_helpers.rb +369 -0
  218. data/spec/version_requirement_spec.rb +143 -0
  219. data/spec/xpath_matchers.rb +121 -0
  220. metadata +600 -0
@@ -0,0 +1,140 @@
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 'hpricot'
18
+
19
+
20
+ module Buildr
21
+
22
+ # Search best artifact version from remote repositories
23
+ module ArtifactSearch
24
+ extend self
25
+
26
+ def include(method = nil)
27
+ (@includes ||= []).tap { push method if method }
28
+ end
29
+
30
+ def exclude(method = nil)
31
+ (@excludes ||= []).tap { push method if method }
32
+ end
33
+
34
+ # TODO: return the url for best matching repo
35
+ def best_version(spec, *methods)
36
+ spec = Artifact.to_hash(spec)
37
+ spec[:version] = requirement = VersionRequirement.create(spec[:version])
38
+ select = lambda do |candidates|
39
+ candidates.find { |candidate| requirement.satisfied_by?(candidate) }
40
+ end
41
+ result = nil
42
+ methods = search_methods if methods.empty?
43
+ if requirement.composed?
44
+ until result || methods.empty?
45
+ method = methods.shift
46
+ type = method.keys.first
47
+ from = method[type]
48
+ if (include.empty? || !(include & [:all, type, from]).empty?) &&
49
+ (exclude & [:all, type, from]).empty?
50
+ if from.respond_to?(:call)
51
+ versions = from.call(spec.dup)
52
+ else
53
+ versions = send("#{type}_versions", spec.dup, *from)
54
+ end
55
+ result = select[versions]
56
+ end
57
+ end
58
+ end
59
+ result ||= requirement.default
60
+ raise "Could not find #{Artifact.to_spec(spec)}" +
61
+ "\n You may need to use an specific version instead of a requirement" unless result
62
+ spec.merge :version => result
63
+ end
64
+
65
+ def requirement?(spec)
66
+ VersionRequirement.requirement?(spec[:version])
67
+ end
68
+
69
+ private
70
+ def search_methods
71
+ [].tap do
72
+ push :runtime => [Artifact.list]
73
+ push :local => Buildr.repositories.local
74
+ Buildr.repositories.remote.each { |remote| push :remote => remote }
75
+ push :mvnrepository => []
76
+ end
77
+ end
78
+
79
+ def depend_version(spec)
80
+ spec[:version][/[\w\.]+/]
81
+ end
82
+
83
+ def runtime_versions(spec, artifacts)
84
+ spec_classif = spec.values_at(:group, :id, :type)
85
+ artifacts.inject([]) do |in_memory, str|
86
+ candidate = Artifact.to_hash(str)
87
+ if spec_classif == candidate.values_at(:group, :id, :type)
88
+ in_memory << candidate[:version]
89
+ end
90
+ in_memory
91
+ end
92
+ end
93
+
94
+ def local_versions(spec, repo)
95
+ path = (spec[:group].split(/\./) + [spec[:id]]).flatten.join('/')
96
+ Dir[File.expand_path(path + "/*", repo)].map { |d| d.pathmap("%f") }.sort.reverse
97
+ end
98
+
99
+ def remote_versions(art, base, from = :metadata, fallback = true)
100
+ path = (art[:group].split(/\./) + [art[:id]]).flatten.join('/')
101
+ base ||= "http://mirrors.ibiblio.org/pub/mirrors/maven2"
102
+ uris = {:metadata => "#{base}/#{path}/maven-metadata.xml"}
103
+ uris[:listing] = "#{base}/#{path}/" if base =~ /^https?:/
104
+ xml = nil
105
+ until xml || uris.empty?
106
+ begin
107
+ xml = URI.read(uris.delete(from))
108
+ rescue URI::NotFoundError => e
109
+ from = fallback ? uris.keys.first : nil
110
+ end
111
+ end
112
+ return [] unless xml
113
+ doc = Hpricot(xml)
114
+ case from
115
+ when :metadata then
116
+ doc.search("versions/version").map(&:innerHTML).reverse
117
+ when :listing then
118
+ doc.search("a[@href]").inject([]) { |vers, a|
119
+ vers << a.innerHTML.chop if a.innerHTML[-1..-1] == '/'
120
+ vers
121
+ }.sort.reverse
122
+ else
123
+ fail "Don't know how to parse #{from}: \n#{xml.inspect}"
124
+ end
125
+ end
126
+
127
+ def mvnrepository_versions(art)
128
+ uri = "http://www.mvnrepository.com/artifact/#{art[:group]}/#{art[:id]}"
129
+ xml = begin
130
+ URI.read(uri)
131
+ rescue URI::NotFoundError => e
132
+ puts e.class, e
133
+ return []
134
+ end
135
+ doc = Hpricot(xml)
136
+ doc.search("table.grid/tr/td[1]/a").map(&:innerHTML)
137
+ end
138
+
139
+ end # ArtifactSearch
140
+ end
@@ -0,0 +1,105 @@
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/packaging/package'
18
+ require 'buildr/packaging/archive'
19
+ gem 'rubyforge' ; autoload :RubyForge, 'rubyforge'
20
+ Gem.autoload :Package, 'rubygems/package'
21
+
22
+
23
+ module Buildr
24
+
25
+ class PackageGemTask < ArchiveTask
26
+
27
+ def initialize(*args)
28
+ super
29
+ @spec = Gem::Specification.new
30
+ prepare do
31
+ include(changelog) if changelog
32
+ end
33
+ end
34
+
35
+ attr_accessor :changelog
36
+
37
+ def spec
38
+ yield @spec if block_given?
39
+ @spec
40
+ end
41
+
42
+ def install
43
+ Util::Gems.command 'install', name
44
+ end
45
+
46
+ def uninstall
47
+ Util::Gems.command 'uninstall', spec.name, '-v', spec.version.to_s
48
+ end
49
+
50
+ def upload
51
+ rubyforge = RubyForge.new
52
+ rubyforge.login
53
+ rubyforge.userconfig.merge!('release_changes'=>changelog.to_s, 'preformatted'=>true) if changelog
54
+ rubyforge.add_release spec.rubyforge_project.downcase, spec.name.downcase, spec.version, package(:gem).to_s
55
+ end
56
+
57
+ private
58
+
59
+ def create_from(file_map)
60
+ spec.mark_version
61
+ spec.validate
62
+
63
+ File.open(name, 'wb') do |io|
64
+ Gem::Package.open(io, 'w', nil) do |pkg|
65
+ pkg.metadata = spec.to_yaml
66
+ file_map.each do |path, content|
67
+ next if content.nil? || File.directory?(content.to_s)
68
+ pkg.add_file_simple(path, File.stat(content.to_s).mode & 0777, File.size(content.to_s)) do |os|
69
+ File.open(content.to_s, "rb") do |file|
70
+ os.write file.read(4096) until file.eof?
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+
81
+ module PackageAsGem #:nodoc:
82
+
83
+ def package_as_gem(file_name) #:nodoc:
84
+ PackageGemTask.define_task(file_name).tap do |gem|
85
+ %w{ lib test doc }.each do |dir|
86
+ gem.include :from=>_(dir), :path=>dir if File.directory?(_(dir))
87
+ end
88
+ gem.spec do |spec|
89
+ spec.name = id
90
+ spec.version = version.gsub('-','.') # RubyGems doesn't like '-' in version numbers
91
+ spec.summary = full_comment
92
+ spec.has_rdoc = true
93
+ spec.rdoc_options << '--title' << comment
94
+ spec.require_path = 'lib'
95
+ end
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ class Project
102
+ include PackageAsGem
103
+ end
104
+
105
+ end
@@ -0,0 +1,249 @@
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/compile'
19
+ require 'buildr/packaging/artifact'
20
+
21
+
22
+ module Buildr
23
+ # Methods added to Project to support packaging and tasks for packaging,
24
+ # installing and uploading packages.
25
+ module Package
26
+
27
+ include Extension
28
+
29
+ first_time do
30
+ desc 'Create packages'
31
+ Project.local_task('package'=>'build') { |name| "Packaging #{name}" }
32
+ desc 'Install packages created by the project'
33
+ Project.local_task('install'=>'package') { |name| "Installing packages from #{name}" }
34
+ desc 'Remove previously installed packages'
35
+ Project.local_task('uninstall') { |name| "Uninstalling packages from #{name}" }
36
+ desc 'Upload packages created by the project'
37
+ Project.local_task('upload'=>'package') { |name| "Deploying packages from #{name}" }
38
+ # Anything that comes after local packaging (install, upload) executes the integration tests,
39
+ # which do not conflict with integration invoking the project's own packaging (package=>
40
+ # integration=>foo:package is not circular, just confusing to debug.)
41
+ task 'package' do
42
+ task('integration').invoke if Buildr.options.test && Buildr.application.original_dir == Dir.pwd
43
+ end
44
+ end
45
+
46
+ before_define(:package => :build) do |project|
47
+ [ :package, :install, :uninstall, :upload ].each { |name| project.recursive_task name }
48
+ # Need to run build before package, since package is often used as a dependency by tasks that
49
+ # expect build to happen.
50
+ project.task('package'=>project.task('build'))
51
+ project.group ||= project.parent && project.parent.group || project.name
52
+ project.version ||= project.parent && project.parent.version
53
+ end
54
+
55
+ after_define(:package)
56
+
57
+ # The project's identifier. Same as the project name, with colons replaced by dashes.
58
+ # The ID for project foo:bar is foo-bar.
59
+ def id
60
+ name.gsub(':', '-')
61
+ end
62
+
63
+ # Group used for packaging. Inherited from parent project. Defaults to the top-level project name.
64
+ attr_accessor :group
65
+
66
+ # Version used for packaging. Inherited from parent project.
67
+ attr_accessor :version
68
+
69
+ # :call-seq:
70
+ # package(type, spec?) => task
71
+ #
72
+ # Defines and returns a package created by this project.
73
+ #
74
+ # The first argument declares the package type. For example, :jar to create a JAR file.
75
+ # The package is an artifact that takes its artifact specification from the project.
76
+ # You can override the artifact specification by passing various options in the second
77
+ # argument, for example:
78
+ # package(:zip, :classifier=>'sources')
79
+ #
80
+ # Packages that are ZIP files provides various ways to include additional files, directories,
81
+ # and even merge ZIPs together. Have a look at ZipTask for more information. In case you're
82
+ # wondering, JAR and WAR packages are ZIP files.
83
+ #
84
+ # You can also enhance a JAR package using the ZipTask#with method that accepts the following options:
85
+ # * :manifest -- Specifies how to create the MANIFEST.MF. By default, uses the project's
86
+ # #manifest property.
87
+ # * :meta_inf -- Specifies files to be included in the META-INF directory. By default,
88
+ # uses the project's #meta-inf property.
89
+ #
90
+ # The WAR package supports the same options and adds a few more:
91
+ # * :classes -- Directories of class files to include in WEB-INF/classes. Includes the compile
92
+ # target directory by default.
93
+ # * :libs -- Artifacts and files to include in WEB-INF/libs. Includes the compile classpath
94
+ # dependencies by default.
95
+ #
96
+ # For example:
97
+ # define 'project' do
98
+ # define 'beans' do
99
+ # package :jar
100
+ # end
101
+ # define 'webapp' do
102
+ # compile.with project('beans')
103
+ # package(:war).with :libs=>MYSQL_JDBC
104
+ # end
105
+ # package(:zip, :classifier=>'sources').include path_to('.')
106
+ # end
107
+ #
108
+ # Two other packaging types are:
109
+ # * package :sources -- Creates a JAR file with the source code and classifier 'sources', for use by IDEs.
110
+ # * package :javadoc -- Creates a ZIP file with the Javadocs and classifier 'javadoc'. You can use the
111
+ # javadoc method to further customize it.
112
+ #
113
+ # A package is also an artifact. The following tasks operate on packages created by the project:
114
+ # buildr upload # Upload packages created by the project
115
+ # buildr install # Install packages created by the project
116
+ # buildr package # Create packages
117
+ # buildr uninstall # Remove previously installed packages
118
+ #
119
+ # If you want to add additional packaging types, implement a method with the name package_as_[type]
120
+ # that accepts a file name and returns an appropriate Rake task. For example:
121
+ # def package_as_zip(file_name) #:nodoc:
122
+ # ZipTask.define_task(file_name)
123
+ # end
124
+ #
125
+ # The file name is determined from the specification passed to the package method, however, some
126
+ # packagers need to override this. For example, package(:sources) produces a file with the extension
127
+ # 'jar' and the classifier 'sources'. If you need to overwrite the default implementation, you should
128
+ # also include a method named package_as_[type]_spec. For example:
129
+ # def package_as_sources_spec(spec) #:nodoc:
130
+ # # Change the source distribution to .zip extension
131
+ # spec.merge({ :type=>:zip, :classifier=>'sources' })
132
+ # end
133
+ def package(*args)
134
+ spec = Hash === args.last ? args.pop.dup : {}
135
+ no_options = spec.empty? # since spec is mutated
136
+ if spec[:file]
137
+ rake_check_options spec, :file, :type
138
+ spec[:type] = args.shift || spec[:type] || spec[:file].split('.').last.to_sym
139
+ file_name = spec[:file]
140
+ else
141
+ rake_check_options spec, *ActsAsArtifact::ARTIFACT_ATTRIBUTES
142
+ spec[:id] ||= self.id
143
+ spec[:group] ||= self.group
144
+ spec[:version] ||= self.version
145
+ spec[:type] = args.shift || spec[:type] || compile.packaging || :zip
146
+ end
147
+
148
+ packager = method("package_as_#{spec[:type]}") rescue fail("Don't know how to create a package of type #{spec[:type]}")
149
+ if packager.arity == 1
150
+ unless file_name
151
+ spec = send("package_as_#{spec[:type]}_spec", spec) if respond_to?("package_as_#{spec[:type]}_spec")
152
+ file_name = path_to(:target, Artifact.hash_to_file_name(spec))
153
+ end
154
+ package = (no_options && packages.detect { |pkg| pkg.type == spec[:type] && (pkg.id.nil? || pkg.id == spec[:id]) &&
155
+ (pkg.respond_to?(:classifier) ? pkg.classifier : nil) == spec[:classifier]}) ||
156
+ packages.find { |pkg| pkg.name == file_name } ||
157
+ packager.call(file_name)
158
+ else
159
+ Buildr.application.deprecated "We changed the way package_as methods are implemented. See the package method documentation for more details."
160
+ file_name ||= path_to(:target, Artifact.hash_to_file_name(spec))
161
+ package = packager.call(file_name, spec)
162
+ end
163
+
164
+ # First time: prepare package for install, uninstall and upload tasks.
165
+ unless packages.include?(package)
166
+ # We already run build before package, but we also need to do so if the package itself is
167
+ # used as a dependency, before we get to run the package task.
168
+ task 'package'=>package
169
+ package.enhance [task('build')]
170
+ package.enhance { info "Packaging #{File.basename(file_name)}" }
171
+ if spec[:file]
172
+ class << package ; self ; end.send(:define_method, :type) { spec[:type] }
173
+ class << package ; self ; end.send(:define_method, :id) { nil }
174
+ else
175
+ # Make it an artifact using the specifications, and tell it how to create a POM.
176
+ package.extend ActsAsArtifact
177
+ package.send :apply_spec, spec.only(*Artifact::ARTIFACT_ATTRIBUTES)
178
+
179
+ # Create pom associated with package
180
+ class << package
181
+ def pom
182
+ unless @pom
183
+ pom_filename = Util.replace_extension(self.name, 'pom')
184
+ spec = {:group=>group, :id=>id, :version=>version, :type=>:pom}
185
+ @pom = Buildr.artifact(spec, pom_filename)
186
+ @pom.content @pom.pom_xml
187
+ end
188
+ @pom
189
+ end
190
+ end
191
+
192
+ file(Buildr.repositories.locate(package)=>package) { package.install }
193
+
194
+ # Add the package to the list of packages created by this project, and
195
+ # register it as an artifact. The later is required so if we look up the spec
196
+ # we find the package in the project's target directory, instead of finding it
197
+ # in the local repository and attempting to install it.
198
+ Artifact.register package, package.pom
199
+ end
200
+
201
+ task('install') { package.install if package.respond_to?(:install) }
202
+ task('uninstall') { package.uninstall if package.respond_to?(:uninstall) }
203
+ task('upload') { package.upload if package.respond_to?(:upload) }
204
+
205
+ packages << package
206
+ end
207
+ package
208
+ end
209
+
210
+ # :call-seq:
211
+ # packages => tasks
212
+ #
213
+ # Returns all packages created by this project. A project may create any number of packages.
214
+ #
215
+ # This method is used whenever you pass a project to Buildr#artifact or any other method
216
+ # that accepts artifact specifications and projects. You can use it to list all packages
217
+ # created by the project. If you want to return a specific package, it is often more
218
+ # convenient to call #package with the type.
219
+ def packages
220
+ @packages ||= []
221
+ end
222
+
223
+ protected
224
+
225
+ def package_as_zip(file_name) #:nodoc:
226
+ ZipTask.define_task(file_name)
227
+ end
228
+
229
+ def package_as_tar(file_name) #:nodoc:
230
+ TarTask.define_task(file_name)
231
+ end
232
+ alias :package_as_tgz :package_as_tar
233
+
234
+ def package_as_sources_spec(spec) #:nodoc:
235
+ spec.merge(:type=>:jar, :classifier=>'sources')
236
+ end
237
+
238
+ def package_as_sources(file_name) #:nodoc:
239
+ ZipTask.define_task(file_name).tap do |zip|
240
+ zip.include :from=>[compile.sources, resources.target].compact
241
+ end
242
+ end
243
+
244
+ end
245
+ end
246
+
247
+ class Buildr::Project
248
+ include Buildr::Package
249
+ end