mguymon-buildr 1.4.5-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1291 -0
- data/LICENSE +176 -0
- data/NOTICE +26 -0
- data/README.rdoc +134 -0
- data/Rakefile +44 -0
- data/_buildr +35 -0
- data/_jbuildr +35 -0
- data/addon/buildr/antlr.rb +65 -0
- data/addon/buildr/bnd.rb +147 -0
- data/addon/buildr/cobertura.rb +22 -0
- data/addon/buildr/drb.rb +281 -0
- data/addon/buildr/emma.rb +22 -0
- data/addon/buildr/hibernate.rb +149 -0
- data/addon/buildr/javacc.rb +85 -0
- data/addon/buildr/jaxb_xjc.rb +72 -0
- data/addon/buildr/jdepend.rb +60 -0
- data/addon/buildr/jetty.rb +248 -0
- data/addon/buildr/jibx.rb +86 -0
- data/addon/buildr/nailgun.rb +221 -0
- data/addon/buildr/openjpa.rb +88 -0
- data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
- data/addon/buildr/protobuf.rb +88 -0
- data/addon/buildr/xmlbeans.rb +93 -0
- data/bin/buildr +19 -0
- data/buildr.buildfile +58 -0
- data/buildr.gemspec +78 -0
- data/doc/_config.yml +1 -0
- data/doc/_layouts/default.html +90 -0
- data/doc/_layouts/preface.html +22 -0
- data/doc/artifacts.textile +217 -0
- data/doc/building.textile +276 -0
- data/doc/contributing.textile +268 -0
- data/doc/css/default.css +236 -0
- data/doc/css/print.css +101 -0
- data/doc/css/syntax.css +23 -0
- data/doc/download.textile +151 -0
- data/doc/extending.textile +212 -0
- data/doc/images/1442160941-frontcover.jpg +0 -0
- data/doc/images/asf-logo.gif +0 -0
- data/doc/images/asf-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/favicon.png +0 -0
- data/doc/images/growl-icon.tiff +0 -0
- data/doc/images/note.png +0 -0
- data/doc/images/project-structure.png +0 -0
- data/doc/images/tip.png +0 -0
- data/doc/images/zbuildr.png +0 -0
- data/doc/images/zbuildr.tif +0 -0
- data/doc/index.textile +109 -0
- data/doc/installing.textile +284 -0
- data/doc/languages.textile +599 -0
- data/doc/mailing_lists.textile +29 -0
- data/doc/more_stuff.textile +845 -0
- data/doc/packaging.textile +618 -0
- data/doc/preface.textile +54 -0
- data/doc/projects.textile +276 -0
- data/doc/quick_start.textile +210 -0
- data/doc/releasing.textile +117 -0
- data/doc/scripts/buildr-git.rb +512 -0
- data/doc/scripts/gitflow.rb +296 -0
- data/doc/scripts/install-jruby.sh +44 -0
- data/doc/scripts/install-linux.sh +73 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/settings_profiles.textile +287 -0
- data/doc/testing.textile +247 -0
- data/etc/KEYS +189 -0
- data/lib/buildr.rb +44 -0
- data/lib/buildr/clojure.rb +34 -0
- data/lib/buildr/clojure/shell.rb +52 -0
- data/lib/buildr/core.rb +34 -0
- data/lib/buildr/core/application.rb +700 -0
- data/lib/buildr/core/build.rb +516 -0
- data/lib/buildr/core/cc.rb +166 -0
- data/lib/buildr/core/checks.rb +253 -0
- data/lib/buildr/core/common.rb +151 -0
- data/lib/buildr/core/compile.rb +622 -0
- data/lib/buildr/core/doc.rb +276 -0
- data/lib/buildr/core/environment.rb +129 -0
- data/lib/buildr/core/filter.rb +404 -0
- data/lib/buildr/core/generate.rb +197 -0
- data/lib/buildr/core/help.rb +119 -0
- data/lib/buildr/core/jrebel.rb +42 -0
- data/lib/buildr/core/linux.rb +30 -0
- data/lib/buildr/core/osx.rb +46 -0
- data/lib/buildr/core/progressbar.rb +161 -0
- data/lib/buildr/core/project.rb +975 -0
- data/lib/buildr/core/run.rb +43 -0
- data/lib/buildr/core/shell.rb +137 -0
- data/lib/buildr/core/test.rb +843 -0
- data/lib/buildr/core/transports.rb +575 -0
- data/lib/buildr/core/util.rb +537 -0
- data/lib/buildr/groovy.rb +20 -0
- data/lib/buildr/groovy/bdd.rb +106 -0
- data/lib/buildr/groovy/compiler.rb +153 -0
- data/lib/buildr/groovy/doc.rb +76 -0
- data/lib/buildr/groovy/shell.rb +57 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/buildr/ide/eclipse.rb +427 -0
- data/lib/buildr/ide/eclipse/java.rb +53 -0
- data/lib/buildr/ide/eclipse/plugin.rb +71 -0
- data/lib/buildr/ide/eclipse/scala.rb +68 -0
- data/lib/buildr/ide/idea.rb +576 -0
- data/lib/buildr/java.rb +25 -0
- data/lib/buildr/java/ant.rb +94 -0
- data/lib/buildr/java/bdd.rb +460 -0
- data/lib/buildr/java/cobertura.rb +297 -0
- data/lib/buildr/java/commands.rb +223 -0
- data/lib/buildr/java/compiler.rb +135 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/doc.rb +86 -0
- data/lib/buildr/java/ecj.rb +69 -0
- data/lib/buildr/java/emma.rb +244 -0
- data/lib/buildr/java/external.rb +73 -0
- data/lib/buildr/java/jruby.rb +122 -0
- data/lib/buildr/java/jtestr_result.rb +295 -0
- data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
- data/lib/buildr/java/packaging.rb +734 -0
- data/lib/buildr/java/pom.rb +178 -0
- data/lib/buildr/java/rjb.rb +154 -0
- data/lib/buildr/java/test_result.rb +101 -0
- data/lib/buildr/java/tests.rb +362 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/packaging.rb +25 -0
- data/lib/buildr/packaging/archive.rb +535 -0
- data/lib/buildr/packaging/artifact.rb +904 -0
- data/lib/buildr/packaging/artifact_namespace.rb +984 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +105 -0
- data/lib/buildr/packaging/package.rb +249 -0
- data/lib/buildr/packaging/repository_array.rb +108 -0
- data/lib/buildr/packaging/tar.rb +189 -0
- data/lib/buildr/packaging/version_requirement.rb +192 -0
- data/lib/buildr/packaging/zip.rb +178 -0
- data/lib/buildr/packaging/ziptask.rb +356 -0
- data/lib/buildr/resources/buildr.icns +0 -0
- data/lib/buildr/resources/completed.png +0 -0
- data/lib/buildr/resources/failed.png +0 -0
- data/lib/buildr/resources/icons-license.txt +17 -0
- data/lib/buildr/run.rb +195 -0
- data/lib/buildr/scala.rb +26 -0
- data/lib/buildr/scala/bdd.rb +118 -0
- data/lib/buildr/scala/compiler.rb +242 -0
- data/lib/buildr/scala/doc.rb +142 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
- data/lib/buildr/scala/shell.rb +52 -0
- data/lib/buildr/scala/tests.rb +171 -0
- data/lib/buildr/shell.rb +185 -0
- data/lib/buildr/version.rb +18 -0
- data/rakelib/all-in-one.rake +113 -0
- data/rakelib/checks.rake +57 -0
- data/rakelib/doc.rake +137 -0
- data/rakelib/metrics.rake +39 -0
- data/rakelib/package.rake +73 -0
- data/rakelib/release.rake +160 -0
- data/rakelib/rspec.rake +91 -0
- data/rakelib/setup.rake +66 -0
- data/rakelib/stage.rake +220 -0
- data/spec/addon/bnd_spec.rb +330 -0
- data/spec/addon/drb_spec.rb +328 -0
- data/spec/addon/jaxb_xjc_spec.rb +125 -0
- data/spec/core/application_spec.rb +631 -0
- data/spec/core/build_spec.rb +837 -0
- data/spec/core/cc_spec.rb +224 -0
- data/spec/core/checks_spec.rb +519 -0
- data/spec/core/common_spec.rb +725 -0
- data/spec/core/compile_spec.rb +658 -0
- data/spec/core/doc_spec.rb +195 -0
- data/spec/core/extension_spec.rb +201 -0
- data/spec/core/generate_spec.rb +33 -0
- data/spec/core/project_spec.rb +772 -0
- data/spec/core/run_spec.rb +93 -0
- data/spec/core/shell_spec.rb +146 -0
- data/spec/core/test_spec.rb +1320 -0
- data/spec/core/transport_spec.rb +544 -0
- data/spec/core/util_spec.rb +141 -0
- data/spec/groovy/bdd_spec.rb +80 -0
- data/spec/groovy/compiler_spec.rb +251 -0
- data/spec/groovy/doc_spec.rb +65 -0
- data/spec/ide/eclipse_spec.rb +739 -0
- data/spec/ide/idea_spec.rb +1145 -0
- data/spec/java/ant_spec.rb +37 -0
- data/spec/java/bdd_spec.rb +374 -0
- data/spec/java/cobertura_spec.rb +112 -0
- data/spec/java/commands_spec.rb +93 -0
- data/spec/java/compiler_spec.rb +252 -0
- data/spec/java/doc_spec.rb +56 -0
- data/spec/java/ecj_spec.rb +115 -0
- data/spec/java/emma_spec.rb +121 -0
- data/spec/java/external_spec.rb +56 -0
- data/spec/java/java_spec.rb +132 -0
- data/spec/java/packaging_spec.rb +1266 -0
- data/spec/java/run_spec.rb +78 -0
- data/spec/java/test_coverage_helper.rb +257 -0
- data/spec/java/tests_spec.rb +497 -0
- data/spec/packaging/archive_spec.rb +775 -0
- data/spec/packaging/artifact_namespace_spec.rb +743 -0
- data/spec/packaging/artifact_spec.rb +1074 -0
- data/spec/packaging/packaging_helper.rb +63 -0
- data/spec/packaging/packaging_spec.rb +719 -0
- data/spec/packaging/repository_array_spec.rb +109 -0
- data/spec/sandbox.rb +165 -0
- data/spec/scala/bdd_spec.rb +124 -0
- data/spec/scala/compiler_spec.rb +289 -0
- data/spec/scala/doc_spec.rb +88 -0
- data/spec/scala/scala.rb +38 -0
- data/spec/scala/tests_spec.rb +283 -0
- data/spec/spec_helpers.rb +369 -0
- data/spec/version_requirement_spec.rb +143 -0
- data/spec/xpath_matchers.rb +121 -0
- 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
|