assaf-buildr 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -0,0 +1,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,102 @@
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/zip'
19
+ require 'rubyforge'
20
+ require '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
+ Gem::Package.open(name, 'w', nil) do |pkg|
63
+ pkg.metadata = spec.to_yaml
64
+ file_map.each do |path, content|
65
+ next if content.nil? || File.directory?(content.to_s)
66
+ pkg.add_file_simple(path, File.stat(name).mode & 0777, File.size(content.to_s)) do |os|
67
+ File.open(content.to_s, "rb") do |file|
68
+ os.write file.read(4096) until file.eof?
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+
78
+ module PackageAsGem
79
+
80
+ def package_as_gem(file_name) #:nodoc:
81
+ PackageGemTask.define_task(file_name).tap do |gem|
82
+ %w{ lib test doc }.each do |dir|
83
+ gem.include :from=>_(dir), :path=>dir if File.directory?(_(dir))
84
+ end
85
+ gem.spec do |spec|
86
+ spec.name = id
87
+ spec.version = version
88
+ spec.summary = full_comment
89
+ spec.has_rdoc = true
90
+ spec.rdoc_options << '--title' << comment
91
+ spec.require_path = 'lib'
92
+ end
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ class Project
99
+ include PackageAsGem
100
+ end
101
+
102
+ end
@@ -0,0 +1,233 @@
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, deploy) 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 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
+ # The project's identifier. Same as the project name, with colons replaced by dashes.
56
+ # The ID for project foo:bar is foo-bar.
57
+ def id
58
+ name.gsub(':', '-')
59
+ end
60
+
61
+ # Group used for packaging. Inherited from parent project. Defaults to the top-level project name.
62
+ attr_accessor :group
63
+
64
+ # Version used for packaging. Inherited from parent project.
65
+ attr_accessor :version
66
+
67
+ # :call-seq:
68
+ # package(type, spec?) => task
69
+ #
70
+ # Defines and returns a package created by this project.
71
+ #
72
+ # The first argument declares the package type. For example, :jar to create a JAR file.
73
+ # The package is an artifact that takes its artifact specification from the project.
74
+ # You can override the artifact specification by passing various options in the second
75
+ # argument, for example:
76
+ # package(:zip, :classifier=>'sources')
77
+ #
78
+ # Packages that are ZIP files provides various ways to include additional files, directories,
79
+ # and even merge ZIPs together. Have a look at ZipTask for more information. In case you're
80
+ # wondering, JAR and WAR packages are ZIP files.
81
+ #
82
+ # You can also enhance a JAR package using the ZipTask#with method that accepts the following options:
83
+ # * :manifest -- Specifies how to create the MANIFEST.MF. By default, uses the project's
84
+ # #manifest property.
85
+ # * :meta_inf -- Specifies files to be included in the META-INF directory. By default,
86
+ # uses the project's #meta-inf property.
87
+ #
88
+ # The WAR package supports the same options and adds a few more:
89
+ # * :classes -- Directories of class files to include in WEB-INF/classes. Includes the compile
90
+ # target directory by default.
91
+ # * :libs -- Artifacts and files to include in WEB-INF/libs. Includes the compile classpath
92
+ # dependencies by default.
93
+ #
94
+ # For example:
95
+ # define 'project' do
96
+ # define 'beans' do
97
+ # package :jar
98
+ # end
99
+ # define 'webapp' do
100
+ # compile.with project('beans')
101
+ # package(:war).with :libs=>MYSQL_JDBC
102
+ # end
103
+ # package(:zip, :classifier=>'sources').include path_to('.')
104
+ # end
105
+ #
106
+ # Two other packaging types are:
107
+ # * package :sources -- Creates a ZIP file with the source code and classifier 'sources', for use by IDEs.
108
+ # * package :javadoc -- Creates a ZIP file with the Javadocs and classifier 'javadoc'. You can use the
109
+ # javadoc method to further customize it.
110
+ #
111
+ # A package is also an artifact. The following tasks operate on packages created by the project:
112
+ # buildr upload # Upload packages created by the project
113
+ # buildr install # Install packages created by the project
114
+ # buildr package # Create packages
115
+ # buildr uninstall # Remove previously installed packages
116
+ #
117
+ # If you want to add additional packaging types, implement a method with the name package_as_[type]
118
+ # that accepts a file name and returns an appropriate Rake task. For example:
119
+ # def package_as_zip(file_name) #:nodoc:
120
+ # ZipTask.define_task(file_name)
121
+ # end
122
+ #
123
+ # The file name is determined from the specification passed to the package method, however, some
124
+ # packagers need to override this. For example, package(:sources) produces a file with the extension
125
+ # 'zip' and the classifier 'sources'. If you need to overwrite the default implementation, you should
126
+ # also include a method named package_as_[type]_respec. For example:
127
+ # def package_as_sources_spec(spec) #:nodoc:
128
+ # { :type=>:zip, :classifier=>'sources' }.merge(spec)
129
+ # end
130
+ def package(*args)
131
+ spec = Hash === args.last ? args.pop.dup : {}
132
+ if spec[:file]
133
+ rake_check_options spec, :file, :type
134
+ spec[:type] = args.shift || spec[:type] || spec[:file].split('.').last
135
+ file_name = spec[:file]
136
+ else
137
+ rake_check_options spec, *ActsAsArtifact::ARTIFACT_ATTRIBUTES
138
+ spec[:id] ||= self.id
139
+ spec[:group] ||= self.group
140
+ spec[:version] ||= self.version
141
+ spec[:type] = args.shift || spec[:type] || compile.packaging || :zip
142
+ end
143
+
144
+ packager = method("package_as_#{spec[:type]}") rescue fail("Don't know how to create a package of type #{spec[:type]}")
145
+ if packager.arity == 1
146
+ unless file_name
147
+ spec = send("package_as_#{spec[:type]}_spec", spec) if respond_to?("package_as_#{spec[:type]}_spec")
148
+ file_name = path_to(:target, Artifact.hash_to_file_name(spec))
149
+ end
150
+ package = packages.find { |pkg| pkg.name == file_name } || packager.call(file_name)
151
+ else
152
+ Buildr.application.deprecated "We changed the way package_as methods are implemented. See the package method documentation for more details."
153
+ file_name ||= path_to(:target, Artifact.hash_to_file_name(spec))
154
+ package = packager.call(file_name, spec)
155
+ end
156
+
157
+ # First time: prepare package for install, uninstall and upload tasks.
158
+ unless packages.include?(package)
159
+ # We already run build before package, but we also need to do so if the package itself is
160
+ # used as a dependency, before we get to run the package task.
161
+ task 'package'=>package
162
+ package.enhance [task('build')]
163
+
164
+ if spec[:file]
165
+ class << package ; self ; end.send(:define_method, :type) { spec[:type] }
166
+ elsif !package.respond_to?(:install)
167
+ # Make it an artifact using the specifications, and tell it how to create a POM.
168
+ package.extend ActsAsArtifact
169
+ package.send :apply_spec, spec.only(*Artifact::ARTIFACT_ATTRIBUTES)
170
+ # Another task to create the POM file.
171
+ pom = package.pom
172
+ pom.enhance do
173
+ mkpath File.dirname(pom.name), :verbose=>false
174
+ File.open(pom.name, 'w') { |file| file.write pom.pom_xml }
175
+ end
176
+ file(Buildr.repositories.locate(package)=>package) { package.install }
177
+
178
+ # Add the package to the list of packages created by this project, and
179
+ # register it as an artifact. The later is required so if we look up the spec
180
+ # we find the package in the project's target directory, instead of finding it
181
+ # in the local repository and attempting to install it.
182
+ Artifact.register package, pom
183
+ end
184
+
185
+ task('install') { package.install if package.respond_to?(:install) }
186
+ task('uninstall') { package.uninstall if package.respond_to?(:uninstall) }
187
+ task('upload') { package.upload if package.respond_to?(:upload) }
188
+
189
+ packages << package
190
+ end
191
+ package
192
+ end
193
+
194
+ # :call-seq:
195
+ # packages => tasks
196
+ #
197
+ # Returns all packages created by this project. A project may create any number of packages.
198
+ #
199
+ # This method is used whenever you pass a project to Buildr#artifact or any other method
200
+ # that accepts artifact specifications and projects. You can use it to list all packages
201
+ # created by the project. If you want to return a specific package, it is often more
202
+ # convenient to call #package with the type.
203
+ def packages
204
+ @packages ||= []
205
+ end
206
+
207
+ protected
208
+
209
+ def package_as_zip(file_name) #:nodoc:
210
+ ZipTask.define_task(file_name)
211
+ end
212
+
213
+ def package_as_tar(file_name) #:nodoc:
214
+ TarTask.define_task(file_name)
215
+ end
216
+ alias :package_as_tgz :package_as_tar
217
+
218
+ def package_as_sources_spec(spec) #:nodoc:
219
+ spec.merge(:type=>:zip, :classifier=>'sources')
220
+ end
221
+
222
+ def package_as_sources(file_name) #:nodoc:
223
+ ZipTask.define_task(file_name).tap do |zip|
224
+ zip.include :from=>compile.sources
225
+ end
226
+ end
227
+
228
+ end
229
+ end
230
+
231
+ class Buildr::Project
232
+ include Buildr::Package
233
+ end