mguymon-buildr 1.4.5
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 +649 -0
@@ -0,0 +1,65 @@
|
|
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/java'
|
18
|
+
|
19
|
+
|
20
|
+
module Buildr
|
21
|
+
# Provides ANTLR grammar generation tasks. Require explicitly using <code>require "buildr/antlr"</code>.
|
22
|
+
module ANTLR
|
23
|
+
REQUIRES = [ "org.antlr:antlr:jar:3.0", "antlr:antlr:jar:2.7.7", "org.antlr:stringtemplate:jar:3.0" ]
|
24
|
+
|
25
|
+
Java.classpath << REQUIRES
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def antlr(*args)
|
29
|
+
options = Hash === args.last ? args.pop : {}
|
30
|
+
rake_check_options options, :output, :token
|
31
|
+
|
32
|
+
args = args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? FileList[f + "/**/*.g"] : f }.flatten
|
33
|
+
args = ["-o", options[:output]] + args if options[:output]
|
34
|
+
if options[:token]
|
35
|
+
# antlr expects the token directory to exist when it starts
|
36
|
+
mkdir_p options[:token]
|
37
|
+
args = ["-lib", options[:token]] + args
|
38
|
+
end
|
39
|
+
Java.load
|
40
|
+
#Java.org.antlr.Tool.new_with_sig("[Ljava.lang.String;", args).process
|
41
|
+
Java.org.antlr.Tool.new(args.to_java(Java.java.lang.String)).process
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def antlr(*args)
|
46
|
+
if Hash === args.last
|
47
|
+
options = args.pop
|
48
|
+
in_package = options[:in_package].split(".")
|
49
|
+
token = options[:token].split(".") if options[:token]
|
50
|
+
else
|
51
|
+
in_package = []; token = nil
|
52
|
+
end
|
53
|
+
file(path_to(:target, :generated, :antlr)=>args.flatten) do |task|
|
54
|
+
args = {:output=>File.join(task.name, in_package)}
|
55
|
+
args.merge!({:token=>File.join(task.name, token)}) if token
|
56
|
+
ANTLR.antlr task.prerequisites, args
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
class Project
|
63
|
+
include ANTLR
|
64
|
+
end
|
65
|
+
end
|
data/addon/buildr/bnd.rb
ADDED
@@ -0,0 +1,147 @@
|
|
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
|
+
module Buildr
|
17
|
+
module Bnd
|
18
|
+
class << self
|
19
|
+
# The specs for requirements
|
20
|
+
def dependencies
|
21
|
+
["biz.aQute:bnd:jar:0.0.384"]
|
22
|
+
end
|
23
|
+
|
24
|
+
# Repositories containing the requirements
|
25
|
+
def remote_repository
|
26
|
+
"http://www.aQute.biz/repo"
|
27
|
+
end
|
28
|
+
|
29
|
+
def bnd_main(*args)
|
30
|
+
cp = Buildr.artifacts(self.dependencies).each(&:invoke).map(&:to_s)
|
31
|
+
Java::Commands.java 'aQute.bnd.main.bnd', *(args + [{ :classpath => cp }])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class BundleTask < Rake::FileTask
|
36
|
+
attr_reader :project
|
37
|
+
attr_accessor :classpath
|
38
|
+
|
39
|
+
def [](key)
|
40
|
+
@params[key]
|
41
|
+
end
|
42
|
+
|
43
|
+
def []=(key, value)
|
44
|
+
@params[key] = value
|
45
|
+
end
|
46
|
+
|
47
|
+
def classpath_element(dependencies)
|
48
|
+
artifacts = Buildr.artifacts([dependencies])
|
49
|
+
self.prerequisites << artifacts
|
50
|
+
artifacts.each do |dependency|
|
51
|
+
self.classpath << dependency.to_s
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_params
|
56
|
+
params = self.project.manifest.merge(@params).reject { |k, v| v.nil? }
|
57
|
+
params["-classpath"] ||= self.classpath.collect(&:to_s).join(", ")
|
58
|
+
params['Bundle-SymbolicName'] ||= [self.project.group, self.project.name.gsub(':', '.')].join('.')
|
59
|
+
params['Bundle-Name'] ||= self.project.comment || self.project.name
|
60
|
+
params['Bundle-Description'] ||= self.project.comment
|
61
|
+
params['Bundle-Version'] ||= self.project.version
|
62
|
+
if params["Include-Resource"].nil? && !project.resources.target.nil?
|
63
|
+
params["Include-Resource"] = "#{project.resources.target}/"
|
64
|
+
end
|
65
|
+
params['-removeheaders'] ||= "Include-Resource,Bnd-LastModified,Created-By,Implementation-Title,Tool"
|
66
|
+
|
67
|
+
params
|
68
|
+
end
|
69
|
+
|
70
|
+
def project=(project)
|
71
|
+
@project = project
|
72
|
+
end
|
73
|
+
|
74
|
+
def classpath=(classpath)
|
75
|
+
@classpath = []
|
76
|
+
Buildr.artifacts([classpath.flatten.compact]).each do |dependency|
|
77
|
+
self.prerequisites << dependency
|
78
|
+
@classpath << dependency.to_s
|
79
|
+
end
|
80
|
+
@classpath
|
81
|
+
end
|
82
|
+
|
83
|
+
def classpath
|
84
|
+
@classpath ||= ([project.compile.target] + project.compile.dependencies).flatten.compact
|
85
|
+
end
|
86
|
+
|
87
|
+
protected
|
88
|
+
|
89
|
+
def initialize(*args) #:nodoc:
|
90
|
+
super
|
91
|
+
@params = {}
|
92
|
+
enhance do
|
93
|
+
filename = self.name
|
94
|
+
# Generate BND file with same name as target jar but different extension
|
95
|
+
bnd_filename = filename.sub /(\.jar)?$/, '.bnd'
|
96
|
+
|
97
|
+
params = self.to_params
|
98
|
+
params["-output"] = filename
|
99
|
+
File.open(bnd_filename, 'w') do |f|
|
100
|
+
f.print params.collect { |k, v| "#{k}=#{v}" }.join("\n")
|
101
|
+
end
|
102
|
+
|
103
|
+
Buildr::Bnd.bnd_main( "build", "-noeclipse", bnd_filename )
|
104
|
+
begin
|
105
|
+
Buildr::Bnd.bnd_main( "print", "-verify", filename )
|
106
|
+
rescue => e
|
107
|
+
rm filename
|
108
|
+
raise e
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
module ProjectExtension
|
115
|
+
include Extension
|
116
|
+
|
117
|
+
first_time do
|
118
|
+
desc "Does `bnd print` on the packaged bundle and stdouts the output for inspection"
|
119
|
+
Project.local_task("bnd:print")
|
120
|
+
end
|
121
|
+
|
122
|
+
def package_as_bundle(filename)
|
123
|
+
project.task('bnd:print' => [filename]) do |task|
|
124
|
+
Buildr::Bnd.bnd_main("print", filename)
|
125
|
+
end
|
126
|
+
|
127
|
+
dirname = File.dirname(filename)
|
128
|
+
directory(dirname)
|
129
|
+
|
130
|
+
# Add Buildr.application.buildfile so it will rebuild if we change settings
|
131
|
+
task = BundleTask.define_task(filename => [Buildr.application.buildfile, dirname])
|
132
|
+
task.project = self
|
133
|
+
# the last task is the task considered the packaging task
|
134
|
+
task
|
135
|
+
end
|
136
|
+
|
137
|
+
# Change the bundle package to .jar extension
|
138
|
+
def package_as_bundle_spec(spec)
|
139
|
+
spec.merge(:type => :jar)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
class Buildr::Project
|
146
|
+
include Buildr::Bnd::ProjectExtension
|
147
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
+
if Buildr::VERSION < '1.5'
|
18
|
+
Buildr.application.deprecated "'buildr/cobertura', use 'buildr/java/cobertura' instead"
|
19
|
+
require 'buildr/java/cobertura'
|
20
|
+
else
|
21
|
+
raise "#{__FILE__} should be removed since its use is deprecated since version 1.3.4"
|
22
|
+
end
|
data/addon/buildr/drb.rb
ADDED
@@ -0,0 +1,281 @@
|
|
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 'delegate'
|
18
|
+
require 'drb/drb'
|
19
|
+
|
20
|
+
|
21
|
+
module Buildr
|
22
|
+
|
23
|
+
# This addon allows you start a DRb server hosting a buildfile, so that
|
24
|
+
# you can later invoke tasks on it without having to load
|
25
|
+
# the complete buildr runtime again.
|
26
|
+
#
|
27
|
+
# Usage:
|
28
|
+
#
|
29
|
+
# buildr -r buildr/drb drb:start
|
30
|
+
#
|
31
|
+
# Once the server has been started you can invoke tasks using a simple script:
|
32
|
+
#
|
33
|
+
# #!/usr/bin/env ruby
|
34
|
+
# require 'rubygems'
|
35
|
+
# require 'buildr/drb'
|
36
|
+
# Buildr::DRbApplication.run
|
37
|
+
#
|
38
|
+
# Save this script as 'dbuildr', make it executable and use it to invoke tasks.
|
39
|
+
#
|
40
|
+
# dbuildr clean compile
|
41
|
+
#
|
42
|
+
# The dbuildr script will run as the server if there isn't one already running.
|
43
|
+
# Subsequent calls to dbuildr will act as the client and invoke the tasks you
|
44
|
+
# provide in the server.
|
45
|
+
# If the buildfile has been modified it will be reloaded on the BuildrServer.
|
46
|
+
#
|
47
|
+
# JRuby users can use a nailgun client to invoke tasks as fast as possible
|
48
|
+
# without having to incur JVM startup time.
|
49
|
+
# See the documentation for buildr/nailgun.
|
50
|
+
module DRbApplication
|
51
|
+
|
52
|
+
port = ENV['DRB_PORT'] || 2111
|
53
|
+
PORT = port.to_i
|
54
|
+
|
55
|
+
class SavedTask #:nodoc:
|
56
|
+
|
57
|
+
def initialize(original)
|
58
|
+
@original = original.clone
|
59
|
+
@prerequisites = original.prerequisites.clone if original.respond_to?(:prerequisites)
|
60
|
+
@actions = original.actions.clone if original.respond_to?(:actions)
|
61
|
+
end
|
62
|
+
|
63
|
+
def name
|
64
|
+
@original.name
|
65
|
+
end
|
66
|
+
|
67
|
+
def actions
|
68
|
+
@actions ||= []
|
69
|
+
end
|
70
|
+
|
71
|
+
def prerequisites
|
72
|
+
@prerequisites ||= []
|
73
|
+
end
|
74
|
+
|
75
|
+
def define!
|
76
|
+
@original.class.send(:define_task, @original.name => prerequisites).tap do |task|
|
77
|
+
task.comment = @original.comment
|
78
|
+
actions.each { |action| task.enhance &action }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end # SavedTask
|
82
|
+
|
83
|
+
class Snapshot #:nodoc:
|
84
|
+
|
85
|
+
attr_accessor :projects, :tasks, :rules, :layout, :options
|
86
|
+
|
87
|
+
# save the tasks,rules,layout defined by buildr
|
88
|
+
def initialize
|
89
|
+
@rules = Buildr.application.instance_eval { @rules || [] }.clone
|
90
|
+
@options = Buildr.application.options.clone
|
91
|
+
@options.rakelib ||= ['tasks']
|
92
|
+
@layout = Layout.default.clone
|
93
|
+
@projects = Project.instance_eval { @projects || {} }.clone
|
94
|
+
@tasks = Buildr.application.tasks.inject({}) do |hash, original|
|
95
|
+
unless projects.key? original.name # don't save project definitions
|
96
|
+
hash.update original.name => SavedTask.new(original)
|
97
|
+
end
|
98
|
+
hash
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end # Snapshot
|
103
|
+
|
104
|
+
class << self
|
105
|
+
|
106
|
+
attr_accessor :original, :snapshot
|
107
|
+
|
108
|
+
def run
|
109
|
+
begin
|
110
|
+
client = connect
|
111
|
+
rescue DRb::DRbConnError => e
|
112
|
+
run_server!
|
113
|
+
else
|
114
|
+
run_client(client)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def client_uri
|
119
|
+
"druby://:#{PORT + 1}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def remote_run(cfg)
|
123
|
+
with_config(cfg) { Buildr.application.remote_run(self) }
|
124
|
+
rescue => e
|
125
|
+
cfg[:err].puts e.message
|
126
|
+
e.backtrace.each { |b| cfg[:err].puts "\tfrom #{b}" }
|
127
|
+
raise e
|
128
|
+
end
|
129
|
+
|
130
|
+
def save_snapshot(app)
|
131
|
+
if app.instance_eval { @rakefile }
|
132
|
+
@snapshot = self::Snapshot.new
|
133
|
+
app.buildfile_reloaded!
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def server_uri
|
140
|
+
"druby://:#{PORT}"
|
141
|
+
end
|
142
|
+
|
143
|
+
def connect
|
144
|
+
buildr = DRbObject.new(nil, server_uri)
|
145
|
+
uri = buildr.client_uri # obtain our uri from the server
|
146
|
+
DRb.start_service(uri)
|
147
|
+
buildr
|
148
|
+
end
|
149
|
+
|
150
|
+
def run_client(client)
|
151
|
+
client.remote_run :dir => Dir.pwd, :argv => ARGV,
|
152
|
+
:in => $stdin, :out => $stdout, :err => $stderr
|
153
|
+
end
|
154
|
+
|
155
|
+
def setup
|
156
|
+
unless original
|
157
|
+
# Create the stdio delegator that can be cached (eg by fileutils)
|
158
|
+
delegate_stdio
|
159
|
+
|
160
|
+
# Lazily load buildr the first time it's needed
|
161
|
+
require 'buildr'
|
162
|
+
|
163
|
+
# Save the tasks,rules,layout defined by buildr
|
164
|
+
# before loading any project
|
165
|
+
@original = self::Snapshot.new
|
166
|
+
|
167
|
+
Buildr.application.extend self
|
168
|
+
save_snapshot(Buildr.application)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def run_server
|
173
|
+
setup
|
174
|
+
DRb.start_service(server_uri, self)
|
175
|
+
puts "#{self} waiting on #{server_uri}"
|
176
|
+
end
|
177
|
+
|
178
|
+
def run_server!
|
179
|
+
setup
|
180
|
+
if RUBY_PLATFORM[/java/]
|
181
|
+
require 'buildr/nailgun'
|
182
|
+
Buildr.application['nailgun:drb'].invoke
|
183
|
+
else
|
184
|
+
run_server
|
185
|
+
DRb.thread.join
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def delegate_stdio
|
190
|
+
$stdin = SimpleDelegator.new($stdin)
|
191
|
+
$stdout = SimpleDelegator.new($stdout)
|
192
|
+
$stderr = SimpleDelegator.new($stderr)
|
193
|
+
end
|
194
|
+
|
195
|
+
def with_config(remote)
|
196
|
+
@invoked = true
|
197
|
+
set = lambda do |env|
|
198
|
+
ARGV.replace env[:argv]
|
199
|
+
$stdin.__setobj__(env[:in])
|
200
|
+
$stdout.__setobj__(env[:out])
|
201
|
+
$stderr.__setobj__(env[:err])
|
202
|
+
Buildr.application.instance_variable_set :@original_dir, env[:dir]
|
203
|
+
end
|
204
|
+
original = {
|
205
|
+
:dir => Buildr.application.instance_variable_get(:@original_dir),
|
206
|
+
:argv => ARGV,
|
207
|
+
:in => $stdin.__getobj__,
|
208
|
+
:out => $stdout.__getobj__,
|
209
|
+
:err => $stderr.__getobj__
|
210
|
+
}
|
211
|
+
begin
|
212
|
+
set[remote]
|
213
|
+
yield
|
214
|
+
ensure
|
215
|
+
set[original]
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
end # class << DRbApplication
|
220
|
+
|
221
|
+
def remote_run(server)
|
222
|
+
@options = server.original.options.clone
|
223
|
+
init 'Distributed Buildr'
|
224
|
+
if @rakefile
|
225
|
+
if buildfile_needs_reload?
|
226
|
+
reload_buildfile(server, server.original)
|
227
|
+
else
|
228
|
+
clear_invoked_tasks(server.snapshot || server.original)
|
229
|
+
end
|
230
|
+
else
|
231
|
+
reload_buildfile(server, server.original)
|
232
|
+
end
|
233
|
+
top_level
|
234
|
+
end
|
235
|
+
|
236
|
+
def buildfile_reloaded!
|
237
|
+
@last_loaded = buildfile.timestamp if @rakefile
|
238
|
+
end
|
239
|
+
|
240
|
+
private
|
241
|
+
|
242
|
+
def buildfile_needs_reload?
|
243
|
+
!@last_loaded || @last_loaded < buildfile.timestamp
|
244
|
+
end
|
245
|
+
|
246
|
+
def reload_buildfile(server, snapshot)
|
247
|
+
clear_for_reload(snapshot)
|
248
|
+
load_buildfile
|
249
|
+
server.save_snapshot(self)
|
250
|
+
end
|
251
|
+
|
252
|
+
def clear_for_reload(snapshot)
|
253
|
+
Project.clear
|
254
|
+
@tasks = {}
|
255
|
+
@rules = snapshot.rules.clone
|
256
|
+
snapshot.tasks.each_pair { |name, saved| saved.define! }
|
257
|
+
Layout.default = snapshot.layout.clone
|
258
|
+
end
|
259
|
+
|
260
|
+
def clear_invoked_tasks(snapshot)
|
261
|
+
@rules = snapshot.rules.clone
|
262
|
+
(@tasks.keys - snapshot.projects.keys).each do |name|
|
263
|
+
if saved = snapshot.tasks[name]
|
264
|
+
# reenable this task, restoring its actions/prereqs
|
265
|
+
task = @tasks[name]
|
266
|
+
task.reenable
|
267
|
+
task.prerequisites.replace saved.prerequisites.clone
|
268
|
+
task.actions.replace saved.actions.clone
|
269
|
+
else
|
270
|
+
# tasks generated at runtime, drop it
|
271
|
+
@tasks.delete(name)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
task('drb:start') { run_server! } if Buildr.respond_to?(:application)
|
277
|
+
|
278
|
+
end # DRbApplication
|
279
|
+
|
280
|
+
end
|
281
|
+
|