assaf-buildr 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +27 -0
- data/Rakefile +4 -2
- data/_buildr +2 -12
- data/addon/buildr/cobertura.rb +5 -219
- data/addon/buildr/drb.rb +281 -0
- data/addon/buildr/emma.rb +5 -221
- data/addon/buildr/nailgun.rb +93 -689
- data/bin/buildr +0 -9
- data/buildr.gemspec +5 -5
- data/doc/pages/getting_started.textile +4 -4
- data/doc/pages/more_stuff.textile +49 -21
- data/doc/pages/packaging.textile +1 -1
- data/doc/pages/projects.textile +2 -2
- data/doc/pages/testing.textile +1 -1
- data/lib/buildr.rb +2 -4
- data/lib/buildr/core.rb +2 -0
- data/lib/buildr/core/application.rb +302 -147
- data/lib/buildr/core/checks.rb +3 -131
- data/lib/buildr/core/common.rb +0 -4
- data/lib/buildr/core/compile.rb +1 -7
- data/lib/buildr/core/environment.rb +0 -3
- data/lib/buildr/core/filter.rb +7 -3
- data/lib/buildr/core/generate.rb +50 -50
- data/lib/buildr/core/help.rb +2 -1
- data/lib/buildr/core/osx.rb +49 -0
- data/lib/buildr/core/progressbar.rb +1 -1
- data/lib/buildr/core/project.rb +7 -9
- data/lib/buildr/core/test.rb +3 -3
- data/lib/buildr/core/transports.rb +12 -10
- data/lib/buildr/core/util.rb +8 -3
- data/lib/buildr/groovy/bdd.rb +1 -0
- data/lib/buildr/groovy/compiler.rb +1 -1
- data/lib/buildr/ide/eclipse.rb +30 -20
- data/lib/buildr/ide/idea.rb +3 -2
- data/lib/buildr/ide/idea7x.rb +4 -2
- data/lib/buildr/java/ant.rb +1 -1
- data/lib/buildr/java/bdd.rb +2 -0
- data/lib/buildr/java/cobertura.rb +236 -0
- data/lib/buildr/java/emma.rb +238 -0
- data/lib/buildr/java/packaging.rb +6 -2
- data/lib/buildr/java/pom.rb +0 -4
- data/lib/buildr/java/test_result.rb +0 -1
- data/lib/buildr/java/tests.rb +14 -9
- data/lib/buildr/packaging.rb +5 -2
- data/lib/buildr/packaging/archive.rb +488 -0
- data/lib/buildr/packaging/artifact.rb +36 -7
- data/lib/buildr/packaging/artifact_namespace.rb +2 -2
- data/lib/buildr/packaging/gems.rb +3 -3
- data/lib/buildr/packaging/package.rb +1 -1
- data/lib/buildr/packaging/tar.rb +85 -3
- data/lib/buildr/packaging/version_requirement.rb +172 -0
- data/lib/buildr/packaging/zip.rb +24 -682
- data/lib/buildr/packaging/ziptask.rb +313 -0
- data/lib/buildr/scala/compiler.rb +1 -1
- data/lib/buildr/scala/tests.rb +2 -2
- data/rakelib/package.rake +4 -1
- data/rakelib/rspec.rake +2 -2
- data/rakelib/rubyforge.rake +6 -3
- data/rakelib/scm.rake +1 -1
- data/rakelib/setup.rake +0 -5
- data/spec/addon/drb_spec.rb +328 -0
- data/spec/core/application_spec.rb +29 -22
- data/spec/core/build_spec.rb +8 -0
- data/spec/core/checks_spec.rb +292 -310
- data/spec/core/common_spec.rb +8 -2
- data/spec/core/compile_spec.rb +17 -1
- data/spec/core/generate_spec.rb +3 -3
- data/spec/core/project_spec.rb +18 -10
- data/spec/core/test_spec.rb +8 -1
- data/spec/ide/eclipse_spec.rb +96 -28
- data/spec/java/ant.rb +5 -0
- data/spec/{addon → java}/cobertura_spec.rb +3 -3
- data/spec/{addon → java}/emma_spec.rb +3 -3
- data/spec/java/java_spec.rb +9 -1
- data/spec/java/packaging_spec.rb +19 -2
- data/spec/{addon → java}/test_coverage_spec.rb +0 -0
- data/spec/java/tests_spec.rb +5 -0
- data/spec/packaging/archive_spec.rb +1 -1
- data/spec/{core → packaging}/artifact_namespace_spec.rb +2 -2
- data/spec/packaging/artifact_spec.rb +44 -3
- data/spec/packaging/packaging_spec.rb +1 -1
- data/spec/sandbox.rb +16 -14
- data/spec/spec_helpers.rb +26 -3
- metadata +18 -11
- data/lib/buildr/core/application_cli.rb +0 -139
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
1.3.4 (Pending)
|
|
2
|
+
* Added: BUILDR-159 Improved 'check' to accept both tar and tgz archives.
|
|
3
|
+
* Added: BUILDR-164 New 'artifacts:sources' task to download source code
|
|
4
|
+
for artifact jars.
|
|
5
|
+
* Change: Introduced new options from Rake 0.8.3: -I (libdir), -R (rakelib),
|
|
6
|
+
--rules, --no-search, --silent.
|
|
7
|
+
* Changed: Upgraded to Rubyforge 1.0.1.
|
|
8
|
+
* Change: BUILDR-147 Upgraded to use Rake 0.8.3.
|
|
9
|
+
* Change: BUILDR-166 Upgraded to use RSpec 1.1.11.
|
|
10
|
+
* Change: BUILDR-171 Eclipse task generates meta-data files for projects with
|
|
11
|
+
test source code but no main source code.
|
|
12
|
+
* Change: BUILDR-177 Moved cobertura and emma extensions to lib directory.
|
|
13
|
+
* Change: BUILDR-187 Source code attachment for Eclipse .classpath.
|
|
14
|
+
* Change: BUILDR-188 Source code attachment for IDEA .iml file (Marko Sibakov).
|
|
15
|
+
* Fixed: Removed double complete/fail messages showing up on console.
|
|
16
|
+
* Fixed: BUILDR-158 Nailgun is now a delegate for buildr/drb (a pure-ruby dRuby server)
|
|
17
|
+
* Fixed: BUILDR-170 ArtifactNamespace#method_missing has a condition that is never true.
|
|
18
|
+
* Fixed: BUILDR-172 Scala compiler not loaded by default.
|
|
19
|
+
* Fixed: BUILDR-175 Fail to find child project when calling project method inside project definition.
|
|
20
|
+
* Fixed: BUILDR-192 TestNG report results are overwritten (Alexis Midon).
|
|
21
|
+
* Fixed: BUILDR-193 TestNG uses project name for suite name (not valid file
|
|
22
|
+
name on Windows).
|
|
23
|
+
* Fixed: BUILDR-194 Buildr always adds 'Manifest-Version' to generated manifest file.
|
|
24
|
+
* Fixed: BUILDR-198 Filter#run always calls mkpath with :verbose.
|
|
25
|
+
* Fixed: BUILDR-199 ArchiveTask#needed uses 'each' with no effect (Ittay Dror).
|
|
26
|
+
* Fixed: BUILDR-201 Sample project is not valid (Alexis Midon).
|
|
27
|
+
|
|
1
28
|
1.3.3 (2008-10-08)
|
|
2
29
|
* Added: JtestR support. Implemented pending jtestr specs.
|
|
3
30
|
* Added: Growl notifications (OS X only).
|
data/Rakefile
CHANGED
|
@@ -28,7 +28,9 @@ end
|
|
|
28
28
|
desc 'Compile Java libraries used by Buildr'
|
|
29
29
|
task 'compile' do
|
|
30
30
|
puts 'Compiling Java libraries ...'
|
|
31
|
-
|
|
31
|
+
args = File.expand_path('_buildr'), '--buildfile=buildr.buildfile', 'compile'
|
|
32
|
+
args << '--trace' if Rake.application.options.trace
|
|
33
|
+
sh *args
|
|
32
34
|
puts 'OK'
|
|
33
35
|
end
|
|
34
36
|
file Rake::GemPackageTask.new(spec).package_dir=>'compile'
|
|
@@ -59,4 +61,4 @@ task 'stage:check' do
|
|
|
59
61
|
# run dependency checks with JRuby. (Also, good opportunity to upgrade other
|
|
60
62
|
# platform's dependencies)
|
|
61
63
|
sh RUBY_PLATFORM =~ /java/ ? 'ruby' : 'jruby -S rake setup dependency'
|
|
62
|
-
end
|
|
64
|
+
end
|
data/_buildr
CHANGED
|
@@ -14,25 +14,15 @@
|
|
|
14
14
|
# License for the specific language governing permissions and limitations under
|
|
15
15
|
# the License.
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
# Run buildr from source, specifically for testing stuff without doing a rake install.
|
|
18
|
-
# The _BUILDR_RB environment variable can be used to set the path to the ruby/jruby executable.
|
|
19
|
-
# For example to use jruby:
|
|
20
|
-
# export _BUILDR_RB=/path/to/jruby
|
|
21
19
|
|
|
22
|
-
start = Time.now
|
|
23
20
|
require 'rubygems'
|
|
24
21
|
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib') << File.join(File.dirname(__FILE__), 'addon')
|
|
25
22
|
spec = Gem::Specification.load(File.join(File.dirname(__FILE__), 'buildr.gemspec'))
|
|
26
23
|
spec.dependencies.each do |dep|
|
|
27
24
|
gem dep.name, dep.version_requirements.to_s
|
|
28
25
|
end
|
|
26
|
+
|
|
29
27
|
require 'buildr'
|
|
30
28
|
Buildr.application.run
|
|
31
|
-
if verbose
|
|
32
|
-
elapsed = Time.now - start
|
|
33
|
-
real = []
|
|
34
|
-
real << ("%ih" % (elapsed / 3600)) if elapsed >= 3600
|
|
35
|
-
real << ("%im" % ((elapsed / 60) % 60)) if elapsed >= 60
|
|
36
|
-
real << ("%.3fs" % (elapsed % 60))
|
|
37
|
-
puts $terminal.color("Completed in #{real.join}", :green)
|
|
38
|
-
end
|
data/addon/buildr/cobertura.rb
CHANGED
|
@@ -14,223 +14,9 @@
|
|
|
14
14
|
# the License.
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# Provides the <code>cobertura:html</code> and <code>cobertura:xml</code> tasks.
|
|
23
|
-
# Require explicitly using <code>require "buildr/cobertura"</code>.
|
|
24
|
-
#
|
|
25
|
-
# You can generate cobertura reports for a single project
|
|
26
|
-
# using the project name as prefix:
|
|
27
|
-
#
|
|
28
|
-
# project_name:cobertura:html
|
|
29
|
-
#
|
|
30
|
-
# You can also specify which classes to include/exclude from instrumentation by
|
|
31
|
-
# passing a class name regexp to the <code>cobertura.include</code> or
|
|
32
|
-
# <code>cobertura.exclude</code> methods.
|
|
33
|
-
#
|
|
34
|
-
# define 'someModule' do
|
|
35
|
-
# cobertura.include 'some.package.*'
|
|
36
|
-
# cobertura.include /some.(foo|bar).*/
|
|
37
|
-
# cobertura.exclude 'some.foo.util.SimpleUtil'
|
|
38
|
-
# cobertura.exclude /*.Const(ants)?/i
|
|
39
|
-
# end
|
|
40
|
-
module Cobertura
|
|
41
|
-
|
|
42
|
-
class << self
|
|
43
|
-
|
|
44
|
-
REQUIRES = ["net.sourceforge.cobertura:cobertura:jar:1.9", "log4j:log4j:jar:1.2.9",
|
|
45
|
-
"asm:asm:jar:2.2.1", "asm:asm-tree:jar:2.2.1", "oro:oro:jar:2.0.8"] unless const_defined?('REQUIRES')
|
|
46
|
-
|
|
47
|
-
def requires()
|
|
48
|
-
@requires ||= Buildr.artifacts(REQUIRES).each(&:invoke).map(&:to_s)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def report_to(file = nil)
|
|
52
|
-
File.expand_path(File.join(*["reports/cobertura", file.to_s].compact))
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def data_file()
|
|
56
|
-
File.expand_path("reports/cobertura.ser")
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
class CoberturaConfig # :nodoc:
|
|
62
|
-
|
|
63
|
-
def initialize(project)
|
|
64
|
-
@project = project
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
attr_reader :project
|
|
68
|
-
private :project
|
|
69
|
-
|
|
70
|
-
attr_writer :data_file, :instrumented_dir, :report_dir
|
|
71
|
-
|
|
72
|
-
def data_file
|
|
73
|
-
@data_file ||= project.path_to(:reports, 'cobertura.ser')
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def instrumented_dir
|
|
77
|
-
@instrumented_dir ||= project.path_to(:target, :instrumented, :classes)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def report_dir
|
|
81
|
-
@report_dir ||= project.path_to(:reports, :cobertura)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def report_to(file = nil)
|
|
85
|
-
File.expand_path(File.join(*[report_dir, file.to_s].compact))
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# :call-seq:
|
|
89
|
-
# project.cobertura.include(*classPatterns)
|
|
90
|
-
#
|
|
91
|
-
def include(*classPatterns)
|
|
92
|
-
includes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
|
|
93
|
-
self
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def includes
|
|
97
|
-
@includeClasses ||= []
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# :call-seq:
|
|
101
|
-
# project.cobertura.exclude(*classPatterns)
|
|
102
|
-
#
|
|
103
|
-
def exclude(*classPatterns)
|
|
104
|
-
excludes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
|
|
105
|
-
self
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def excludes
|
|
109
|
-
@excludeClasses ||= []
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def sources
|
|
113
|
-
project.compile.sources
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
module CoberturaExtension # :nodoc:
|
|
118
|
-
include Buildr::Extension
|
|
119
|
-
|
|
120
|
-
def cobertura
|
|
121
|
-
@cobertura_config ||= CoberturaConfig.new(self)
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
after_define do |project|
|
|
125
|
-
cobertura = project.cobertura
|
|
126
|
-
|
|
127
|
-
namespace 'cobertura' do
|
|
128
|
-
unless project.compile.target.nil?
|
|
129
|
-
# Instrumented bytecode goes in a different directory. This task creates before running the test
|
|
130
|
-
# cases and monitors for changes in the generate bytecode.
|
|
131
|
-
instrumented = project.file(cobertura.instrumented_dir => project.compile.target) do |task|
|
|
132
|
-
mkdir_p task.to_s, :verbose => false
|
|
133
|
-
unless project.compile.sources.empty?
|
|
134
|
-
info "Instrumenting classes with cobertura data file #{cobertura.data_file}"
|
|
135
|
-
Buildr.ant "cobertura" do |ant|
|
|
136
|
-
ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
|
|
137
|
-
ant.send "cobertura-instrument", :todir=>task.to_s, :datafile=>cobertura.data_file do
|
|
138
|
-
includes, excludes = cobertura.includes, cobertura.excludes
|
|
139
|
-
|
|
140
|
-
classes_dir = project.compile.target.to_s
|
|
141
|
-
if includes.empty? && excludes.empty?
|
|
142
|
-
ant.fileset :dir => classes_dir do
|
|
143
|
-
ant.include :name => "**/*.class"
|
|
144
|
-
end
|
|
145
|
-
else
|
|
146
|
-
includes = [//] if includes.empty?
|
|
147
|
-
Dir.glob(File.join(classes_dir, "**/*.class")) do |cls|
|
|
148
|
-
cls_name = cls.gsub(/#{classes_dir}\/?|\.class$/, '').gsub('/', '.')
|
|
149
|
-
if includes.any? { |p| p === cls_name } && !excludes.any? { |p| p === cls_name }
|
|
150
|
-
ant.fileset :file => cls
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
touch task.to_s, :verbose=>false
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
task 'instrument' => instrumented
|
|
161
|
-
|
|
162
|
-
# We now have two target directories with bytecode. It would make sense to remove compile.target
|
|
163
|
-
# and add instrumented instead, but apparently Cobertura only creates some of the classes, so
|
|
164
|
-
# we need both directories and instrumented must come first.
|
|
165
|
-
project.test.dependencies.unshift cobertura.instrumented_dir
|
|
166
|
-
project.test.with Cobertura.requires
|
|
167
|
-
project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = cobertura.data_file
|
|
168
|
-
|
|
169
|
-
[:xml, :html].each do |format|
|
|
170
|
-
task format => ['instrument', 'test'] do
|
|
171
|
-
info "Creating test coverage reports in #{cobertura.report_to(format)}"
|
|
172
|
-
Buildr.ant "cobertura" do |ant|
|
|
173
|
-
ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
|
|
174
|
-
ant.send "cobertura-report", :format=>format,
|
|
175
|
-
:destdir=>cobertura.report_to(format), :datafile=>cobertura.data_file do
|
|
176
|
-
cobertura.sources.flatten.each do |src|
|
|
177
|
-
ant.fileset(:dir=>src.to_s) if File.exist?(src.to_s)
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
project.clean do
|
|
188
|
-
rm_rf [cobertura.report_to, cobertura.data_file, cobertura.instrumented_dir], :verbose=>false
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
class Buildr::Project
|
|
196
|
-
include CoberturaExtension
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
namespace "cobertura" do
|
|
200
|
-
|
|
201
|
-
task "instrument" do
|
|
202
|
-
Buildr.projects.each do |project|
|
|
203
|
-
project.cobertura.data_file = data_file
|
|
204
|
-
project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = data_file
|
|
205
|
-
instrument_task ="#{project.name}:cobertura:instrument"
|
|
206
|
-
task(instrument_task).invoke if Rake::Task.task_defined?(instrument_task)
|
|
207
|
-
end
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
[:xml, :html].each do |format|
|
|
211
|
-
report_target = report_to(format)
|
|
212
|
-
desc "Run the test cases and produce code coverage reports in #{report_target}"
|
|
213
|
-
task format => ["instrument", "test"] do
|
|
214
|
-
info "Creating test coverage reports in #{report_target}"
|
|
215
|
-
Buildr.ant "cobertura" do |ant|
|
|
216
|
-
ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
|
|
217
|
-
ant.send "cobertura-report", :destdir=>report_target, :format=>format, :datafile=>data_file do
|
|
218
|
-
Buildr.projects.map(&:cobertura).map(&:sources).flatten.each do |src|
|
|
219
|
-
ant.fileset :dir=>src.to_s if File.exist?(src.to_s)
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
task "clean" do
|
|
227
|
-
rm_rf [report_to, data_file], :verbose=>false
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
task "clean" do
|
|
232
|
-
task("cobertura:clean").invoke if Dir.pwd == Rake.application.original_dir
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
end
|
|
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"
|
|
236
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
|
+
|