buildr 1.3.3-java → 1.3.4-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/CHANGELOG +76 -0
  2. data/NOTICE +1 -1
  3. data/README.rdoc +9 -21
  4. data/Rakefile +17 -34
  5. data/_buildr +3 -12
  6. data/{doc/print.toc.yaml → _jbuildr} +14 -14
  7. data/addon/buildr/cobertura.rb +5 -219
  8. data/addon/buildr/drb.rb +281 -0
  9. data/addon/buildr/emma.rb +5 -221
  10. data/addon/buildr/nailgun.rb +93 -689
  11. data/bin/buildr +0 -9
  12. data/buildr.buildfile +4 -4
  13. data/buildr.gemspec +27 -21
  14. data/doc/_layouts/default.html +82 -0
  15. data/doc/_layouts/preface.html +22 -0
  16. data/doc/{pages/artifacts.textile → artifacts.textile} +82 -42
  17. data/doc/{pages/building.textile → building.textile} +89 -47
  18. data/doc/{pages/contributing.textile → contributing.textile} +53 -45
  19. data/doc/css/default.css +6 -5
  20. data/doc/css/print.css +17 -24
  21. data/doc/css/syntax.css +7 -36
  22. data/doc/download.textile +68 -0
  23. data/doc/{pages/extending.textile → extending.textile} +45 -24
  24. data/doc/{pages/getting_started.textile → getting_started.textile} +158 -88
  25. data/doc/images/asf-logo.gif +0 -0
  26. data/doc/images/note.png +0 -0
  27. data/doc/index.textile +47 -0
  28. data/doc/{pages/languages.textile → languages.textile} +108 -54
  29. data/doc/mailing_lists.textile +25 -0
  30. data/doc/{pages/more_stuff.textile → more_stuff.textile} +152 -73
  31. data/doc/{pages/packaging.textile → packaging.textile} +181 -96
  32. data/doc/preface.textile +28 -0
  33. data/doc/{pages/projects.textile → projects.textile} +55 -40
  34. data/doc/scripts/buildr-git.rb +364 -264
  35. data/doc/scripts/gitflow.rb +296 -0
  36. data/doc/scripts/install-jruby.sh +2 -2
  37. data/doc/scripts/install-linux.sh +6 -6
  38. data/doc/scripts/install-osx.sh +2 -2
  39. data/doc/{pages/settings_profiles.textile → settings_profiles.textile} +83 -45
  40. data/doc/{pages/testing.textile → testing.textile} +77 -41
  41. data/lib/buildr.rb +5 -5
  42. data/lib/buildr/core.rb +2 -0
  43. data/lib/buildr/core/application.rb +321 -151
  44. data/lib/buildr/core/build.rb +298 -167
  45. data/lib/buildr/core/checks.rb +4 -132
  46. data/lib/buildr/core/common.rb +1 -5
  47. data/lib/buildr/core/compile.rb +3 -9
  48. data/lib/buildr/core/environment.rb +12 -3
  49. data/lib/buildr/core/filter.rb +20 -18
  50. data/lib/buildr/core/generate.rb +36 -36
  51. data/lib/buildr/core/help.rb +2 -1
  52. data/lib/buildr/core/osx.rb +46 -0
  53. data/lib/buildr/core/progressbar.rb +1 -1
  54. data/lib/buildr/core/project.rb +7 -34
  55. data/lib/buildr/core/test.rb +12 -6
  56. data/lib/buildr/core/transports.rb +13 -11
  57. data/lib/buildr/core/util.rb +14 -23
  58. data/lib/buildr/groovy/bdd.rb +3 -2
  59. data/lib/buildr/groovy/compiler.rb +1 -1
  60. data/lib/buildr/ide/eclipse.rb +31 -21
  61. data/lib/buildr/ide/idea.rb +3 -2
  62. data/lib/buildr/ide/idea7x.rb +6 -4
  63. data/lib/buildr/java/ant.rb +3 -1
  64. data/lib/buildr/java/bdd.rb +9 -7
  65. data/lib/buildr/java/cobertura.rb +243 -0
  66. data/lib/buildr/java/compiler.rb +5 -4
  67. data/lib/buildr/java/emma.rb +244 -0
  68. data/lib/buildr/java/packaging.rb +11 -8
  69. data/lib/buildr/java/pom.rb +0 -4
  70. data/lib/buildr/java/rjb.rb +1 -1
  71. data/lib/buildr/java/test_result.rb +5 -7
  72. data/lib/buildr/java/tests.rb +17 -11
  73. data/lib/buildr/packaging.rb +5 -2
  74. data/lib/buildr/packaging/archive.rb +488 -0
  75. data/lib/buildr/packaging/artifact.rb +48 -29
  76. data/lib/buildr/packaging/artifact_namespace.rb +6 -6
  77. data/lib/buildr/packaging/gems.rb +4 -4
  78. data/lib/buildr/packaging/package.rb +3 -2
  79. data/lib/buildr/packaging/tar.rb +85 -3
  80. data/lib/buildr/packaging/version_requirement.rb +172 -0
  81. data/lib/buildr/packaging/zip.rb +24 -682
  82. data/lib/buildr/packaging/ziptask.rb +313 -0
  83. data/lib/buildr/scala.rb +5 -0
  84. data/lib/buildr/scala/bdd.rb +100 -0
  85. data/lib/buildr/scala/compiler.rb +45 -4
  86. data/lib/buildr/scala/tests.rb +12 -59
  87. data/rakelib/checks.rake +57 -0
  88. data/rakelib/doc.rake +58 -68
  89. data/rakelib/jekylltask.rb +110 -0
  90. data/rakelib/package.rake +35 -37
  91. data/rakelib/release.rake +119 -35
  92. data/rakelib/rspec.rake +29 -39
  93. data/rakelib/setup.rake +21 -59
  94. data/rakelib/stage.rake +184 -26
  95. data/spec/addon/drb_spec.rb +328 -0
  96. data/spec/core/application_spec.rb +32 -25
  97. data/spec/core/build_spec.rb +336 -126
  98. data/spec/core/checks_spec.rb +292 -310
  99. data/spec/core/common_spec.rb +8 -2
  100. data/spec/core/compile_spec.rb +17 -1
  101. data/spec/core/generate_spec.rb +3 -3
  102. data/spec/core/project_spec.rb +18 -10
  103. data/spec/core/test_spec.rb +8 -1
  104. data/spec/core/transport_spec.rb +40 -3
  105. data/spec/core/util_spec.rb +67 -0
  106. data/spec/ide/eclipse_spec.rb +96 -28
  107. data/spec/ide/idea7x_spec.rb +84 -0
  108. data/spec/java/ant.rb +5 -0
  109. data/spec/java/bdd_spec.rb +12 -3
  110. data/spec/{addon → java}/cobertura_spec.rb +6 -6
  111. data/spec/{addon → java}/emma_spec.rb +5 -6
  112. data/spec/java/java_spec.rb +12 -2
  113. data/spec/java/packaging_spec.rb +31 -2
  114. data/spec/{addon → java}/test_coverage_spec.rb +3 -3
  115. data/spec/java/tests_spec.rb +5 -0
  116. data/spec/packaging/archive_spec.rb +11 -1
  117. data/spec/{core → packaging}/artifact_namespace_spec.rb +10 -2
  118. data/spec/packaging/artifact_spec.rb +44 -3
  119. data/spec/packaging/packaging_spec.rb +1 -1
  120. data/spec/sandbox.rb +17 -14
  121. data/spec/scala/bdd_spec.rb +150 -0
  122. data/spec/scala/compiler_spec.rb +27 -0
  123. data/spec/scala/scala.rb +38 -0
  124. data/spec/scala/tests_spec.rb +78 -33
  125. data/spec/spec_helpers.rb +29 -5
  126. data/spec/version_requirement_spec.rb +6 -0
  127. metadata +176 -172
  128. data/DISCLAIMER +0 -7
  129. data/doc/images/apache-incubator-logo.png +0 -0
  130. data/doc/pages/download.textile +0 -51
  131. data/doc/pages/index.textile +0 -42
  132. data/doc/pages/mailing_lists.textile +0 -17
  133. data/doc/pages/recipes.textile +0 -103
  134. data/doc/pages/troubleshooting.textile +0 -103
  135. data/doc/pages/whats_new.textile +0 -323
  136. data/doc/print.haml +0 -51
  137. data/doc/site.haml +0 -56
  138. data/doc/site.toc.yaml +0 -47
  139. data/etc/git-svn-authors +0 -16
  140. data/lib/buildr/core/application_cli.rb +0 -139
  141. data/rakelib/apache.rake +0 -191
  142. data/rakelib/changelog.rake +0 -57
  143. data/rakelib/rubyforge.rake +0 -53
  144. data/rakelib/scm.rake +0 -49
@@ -13,103 +13,39 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
- require 'benchmark'
16
+
17
17
  require 'jruby'
18
- require 'monitor'
19
- require 'ostruct'
20
18
  require 'rbconfig'
21
- require 'thread'
22
- require 'buildr/core/application_cli'
19
+ require 'tmpdir'
20
+ require 'buildr/drb'
23
21
 
24
- module Buildr #:nodoc:
25
22
 
23
+ module Buildr
24
+
25
+ # This addon is provided for fast interaction with a DRb BuildrServer (buildr/drb).
26
+ #
27
+ # This module delegates task invocation to the BuildrServer, it only implements
28
+ # nailgun required logic (server/client).
29
+ #
30
+ # Usage:
31
+ #
32
+ # buildr -r buildr/nailgun nailgun:start
33
+ #
34
+ # Once the server has been started you can invoke tasks using the nailgun client
35
+ # installed on $JRUBY_HOME/tool/nailgun. It's recommended to add this path to
36
+ # your PATH environment variable, so that the ng command is available at any dir.
37
+ #
38
+ # ng build # invoke the build task
39
+ #
26
40
  module Nailgun
27
-
28
41
  extend self
29
-
30
- attr_reader :ng
31
- @ng ||= OpenStruct.new
32
42
 
33
43
  VERSION = '0.7.1'
34
44
  NAME = "nailgun-#{VERSION}"
35
45
  URL = "http://downloads.sourceforge.net/nailgun/#{NAME}.zip"
36
46
  ARTIFACT_SPEC = "com.martiansoftware:nailgun:jar:#{VERSION}"
37
-
38
- # Paths used to initialize a buildr runtime
39
- BUILDR_PATHS = [File.expand_path('../', File.dirname(__FILE__)),
40
- File.expand_path('../../lib', File.dirname(__FILE__))]
41
-
42
- HELP = <<-HELP.strip.gsub(/ *\n +/, "\n ")
43
- NailGun is a client, protocol, and server for running Java
44
- programs from the command line without incurring the JVM
45
- startup overhead. Nailgun integration is currently available
46
- only when running Buildr with JRuby.
47
-
48
- Buildr provides a custom nailgun server, allowing you to
49
- start a single JVM and let buildr create a queue of runtimes.
50
- These JRuby runtimes can be cached (indexed by buildfile path)
51
- and are automatically reloaded when the buildfile has been modified.
52
- Runtime caching allows you to execute tasks without
53
- spending time creating the buildr environment. Some nailgun
54
- tasks have been provided to manage the cached runtimes.
55
-
56
- To start the buildr server execute the following task:
57
-
58
- nailgun:start
59
-
60
- Server output will display a message when it becomes ready, you
61
- will also see messages when the JRuby runtimes are being created,
62
- or when a new buildr environment is being loaded on them.
63
- After the runtime queues have been populated, you can start calling
64
- buildr as you normally do, by invoking the $NAILGUN_HOME/ng binary:
65
-
66
- # on another terminal, change directory to a project.
67
- # if this project is the same nailgun:start was invoked on, it's
68
- # runtime has been cached, so no loading is performed unless
69
- # the buildfile has been modified. otherwise the buildfile
70
- # will be loaded on a previously loaded fresh-buildr runtime
71
- # and it will be cached.
72
- cd /some/buildr/project
73
- ng nailgun:help # display nailgun help
74
- ng nailgun:tasks # display overview of ng tasks
75
- ng clean compile # just invoke those two tasks
76
-
77
- Configuration and Environment Variables.
78
-
79
- Before starting the server, buildr will check if you have
80
- nailgun already installed by seeking the nailgun jar under
81
-
82
- $NAILGUN_HOME
83
-
84
- You can override this environment variable to tell buildr where
85
- to find or where to install nailgun. If missing, NAILGUN_HOME
86
- defaults to the $JRUBY_HOME/tool/nailgun directory.
87
-
88
- Buildr will also check that the nailgun client binary (ng.exe for
89
- Windows systems, ng otherwise) is installed on NAILGUN_HOME.
90
- If no binary is found, buildr will download nailgun and
91
- compile+install it.
92
-
93
- The buildr server binds itself to localhost, port 2113. You can
94
- override this when starting the nailgun server:
95
-
96
- buildr nailgun:start[4444,127.0.0.1]
97
-
98
- If you provided custom host/port settings you need
99
- to tell the nailgun client where to connect:
100
-
101
- ng --nailgun-server 127.0.0.1 --nailgun-port 4444 nailgun:tasks
102
-
103
- The buildr server starts a RuntimeFactory responsible for providing
104
- a pool of preloaded Buildr runtimes ready for task execution.
105
- You can provide a third argument to the nailgun:start task, to set
106
- the buildr queue size. You may want to increase this value if you
107
- need to load many buildfiles on the same server.
108
-
109
- Execute nailgun:tasks get an overview of available nailgun tasks.
110
- HELP
111
-
112
- private
47
+ PORT = DRbApplication::PORT + 2
48
+ ADDON_BIN = File.dirname(__FILE__)
113
49
 
114
50
  # Returns the path to JRUBY_HOME.
115
51
  def jruby_home
@@ -125,152 +61,9 @@ module Buildr #:nodoc:
125
61
  File.join(Dir.tmpdir, 'nailgun', *paths)
126
62
  end
127
63
 
128
- file_tasks = lambda do
129
-
130
- dist_zip = Buildr.download(tmp_path(NAME + '.zip') => URL)
131
- dist_dir = Buildr.unzip(tmp_path(NAME) => dist_zip)
132
-
133
- nailgun_jar = file(tmp_path(NAME, NAME, NAME + '.jar'))
134
- ng.artifact = Buildr.artifact(ARTIFACT_SPEC).from(nailgun_jar)
135
- unless File.exist?(nailgun_jar.to_s)
136
- nailgun_jar.enhance [dist_dir]
137
- end
138
-
139
- compiled_bin = file(tmp_path(NAME, NAME, 'ng' + Config::CONFIG['EXEEXT']) => dist_dir.target) do |task|
140
- unless task.to_s.pathmap('%x') == '.exe'
141
- Dir.chdir(task.to_s.pathmap('%d')) do
142
- info "Compiling #{task.to_s}"
143
- system('make', task.to_s.pathmap('%f')) or
144
- fail "Nailgun binary compilation failed."
145
- end
146
- end
147
- end
148
-
149
- ng.installed_bin = file(File.expand_path(compiled_bin.to_s.pathmap('%f'), nailgun_home) => compiled_bin) do |task|
150
- mkpath task.to_s.pathmap('%d'), :verbose => false
151
- cp compiled_bin.to_s, task.to_s, :verbose => false
152
- end
153
-
154
- end # file_tasks
155
-
156
- server_tasks = lambda do
157
-
158
- desc 'Start the nailgun server'
159
- task('start', :port, :iface, :queue_size) do |task, args|
160
-
161
- [ng.installed_bin, ng.artifact].map(&:invoke)
162
-
163
- iface = args[:iface].to_s.empty? ? '127.0.0.1' : args[:iface]
164
- port = args[:port].to_s.empty? ? 2113 : args[:port].to_i
165
- queue_size = args[:queue_size].to_s.empty? ? 3 : args[:queue_size].to_i
166
-
167
- fail "Already running on Nailgun server: #{ng.server || ng.nail}" if ng.server || ng.client
168
-
169
- info 'Booting Buildr nailgun server...'
170
- top_level = Buildr.application.instance_eval { @top_level_tasks.dup }
171
- top_level.delete_if { |t| t[/nailgun/] }
172
- unless top_level.empty?
173
- raise 'Don\'t specify more targets when starting Nailgun server: #{top_level}'
174
- end
175
- ng.server_setup.call
176
-
177
- factory = RuntimeFactory.new(queue_size, queue_size)
178
- ng.server = NGServer.new(iface, port, factory)
179
-
180
- ng.server.start
181
- end
182
-
183
- desc 'Show nailgun help'
184
- task('help') do
185
- info HELP
186
- exit(0)
187
- end
188
-
189
- desc 'List nailgun tasks'
190
- task('tasks') do
191
- task_hash = Buildr.application.instance_variable_get(:@tasks)
192
- tasks = task_hash.keys.select { |k| k =~ /^nailgun:/ }
193
- width = [tasks.map { |t| task_hash[t].name_with_args.size }, 20].flatten.max
194
- tasks.each do |name|
195
- task = task_hash[name]
196
- title = task.name_with_args
197
- comment = task.full_comment
198
- info comment.empty? ? title : (" %-#{width}s # %s" % [title, comment])
199
- end
200
- exit(0)
201
- end
202
-
203
- desc 'List currently cached runtimes'
204
- task('list') do
205
- if Nailgun.ng.server
206
- Nailgun.ng.server.cached_stamps.each_pair do |bf, time|
207
- loaded = Nailgun.ng.server.loaded_times[bf]
208
- ary = [bf, "Load Timestamp", loaded, "Modification Timestamp", time]
209
- info("* %s\n %-25s %s\n %-25s %s\n\n" % ary)
210
- end
211
- else
212
- info "Not running on nailgun server"
213
- end
214
- exit(0)
215
- end
216
-
217
- desc 'Remove all cached runtimes'
218
- task('clear') do
219
- if Nailgun.ng.server
220
- Nailgun.ng.server.cached_runtimes.clear
221
- Nailgun.ng.server.cached_stamps.clear
222
- Nailgun.ng.server.loaded_times.clear
223
- info "Cleared all cached runtimes"
224
- else
225
- info "Not running on nailgun server"
226
- end
227
- exit(0)
228
- end
229
-
230
- desc 'Remove runtime for this buildfile'
231
- task('delete', :buildfile) do |task, args|
232
- if Nailgun.ng.server
233
- if args[:buildfile]
234
- buildfile = File.expand_path(args[:buildfile])
235
- else
236
- buildfile = Buildr.application.buildfile.to_s
237
- end
238
- Nailgun.ng.server.cached_runtimes.delete(buildfile)
239
- Nailgun.ng.server.cached_stamps.delete(buildfile)
240
- Nailgun.ng.server.loaded_times.delete(buildfile)
241
- info "Deleted #{buildfile} from runtime cache"
242
- else
243
- info "Not running on nailgun server"
244
- end
245
- exit(0)
246
- end
247
-
248
- end # server_tasks
249
-
250
- # Load java classes on server side.
251
- ng.server_setup = lambda do
252
-
253
- module Util
254
- include Buildr::Util
255
- end
256
-
257
- Util.add_to_sysloader ng.artifact.to_s
258
- Util.add_to_sysloader File.dirname(__FILE__)
259
-
260
- class NGClient
261
- include org.apache.buildr.BuildrNail
262
- include Client
263
- end
264
-
265
- class NGServer < com.martiansoftware.nailgun.NGServer
266
- include Server
267
- end
268
-
269
- end # server_setup
270
-
271
64
  module Util
272
65
  extend self
273
-
66
+
274
67
  def add_to_sysloader(path)
275
68
  sysloader = java.lang.ClassLoader.getSystemClassLoader
276
69
  add_url_method = java.lang.Class.forName('java.net.URLClassLoader').
@@ -279,43 +72,6 @@ module Buildr #:nodoc:
279
72
  add_url_method.invoke(sysloader, [java.io.File.new(path).toURI.toURL].to_java(java.net.URL))
280
73
  end
281
74
 
282
- def benchmark(action = ['Completed'], verbose = true)
283
- result = nil
284
- times = Benchmark.measure do
285
- result = yield(action)
286
- end
287
- if verbose
288
- real = []
289
- real << ("%ih" % (times.real / 3600)) if times.real >= 3600
290
- real << ("%im" % ((times.real / 60) % 60)) if times.real >= 60
291
- real << ("%.3fs" % (times.real % 60))
292
- trace "#{[action].flatten.join(' ')} in #{real.join}"
293
- end
294
- result
295
- end
296
-
297
- def find_file(pwd, candidates, nosearch=false)
298
- candidates = [candidates].flatten
299
- buildfile = candidates.find { |c| File.file?(File.expand_path(c, pwd)) }
300
- return File.expand_path(buildfile, pwd) if buildfile
301
- return nil if nosearch
302
- updir = File.dirname(pwd)
303
- return nil if File.expand_path(updir) == File.expand_path(pwd)
304
- find_file(updir, candidates)
305
- end
306
-
307
- def exception_handling(raise_again = true, show_error = true)
308
- begin
309
- yield
310
- rescue => e
311
- if show_error
312
- error "#{e.backtrace.shift}: #{e.message}"
313
- e.backtrace.each { |i| error "\tfrom #{i}" }
314
- end
315
- raise if raise_again
316
- end
317
- end
318
-
319
75
  # invoke a java constructor
320
76
  def ctor(on_class, *args)
321
77
  parameters = []
@@ -341,300 +97,36 @@ module Buildr #:nodoc:
341
97
  ctor.newInstance(parameters.to_java(java.lang.Object))
342
98
  end
343
99
 
344
- def on_runtime(runtime, *args, &block)
345
- raise_error = lambda do |cls, msg, trace|
346
- raise RuntimeError.new(cls + ": "+ msg.to_s).tap { |e| e.set_backtrace(trace.map(&:to_s)) }
347
- end
348
- executor = runtime.object.const_get(:Module).new do
349
- extend self
350
- def runtime_exec(*args, &prc)
351
- define_method(:runtime_exec, &prc)
352
- runtime_exec(*args)
353
- rescue => e
354
- [:error, e.class.name, e.message, e.backtrace]
355
- end
356
- end
357
- result = executor.runtime_exec(*args, &block)
358
- raise_error.call(*result[1..-1]) if result.kind_of?(Array) && result.first == :error
359
- result
360
- end
361
-
362
- def set_stdio(runtime, dev)
363
- set_global = lambda do |global, constant, stream|
364
- runtime.global_variables.set(global, stream)
365
- runtime.object.send(:remove_const, constant)
366
- runtime.object.send(:const_set, constant, stream)
367
- end
368
- stdin = runtime.global_variables.get('$stdin')
369
- stdout = runtime.global_variables.get('$stdout')
370
- stderr = runtime.global_variables.get('$stderr')
371
- #stdin.close; stdout.close; stderr.close;
372
- output = Util.ctor(org.jruby.RubyIO, runtime, java.io.OutputStream => dev.out)
373
- error = Util.ctor(org.jruby.RubyIO, runtime, java.io.OutputStream => dev.err)
374
- input = Util.ctor(org.jruby.RubyIO, runtime, java.io.InputStream => dev.in)
375
- #stdin.reopen(input, 'r') # not working on jruby, :(
376
- #stdout.reopen(output, 'w')
377
- #stderr.reopen(error, 'w')
378
- set_global.call('$stdin', 'STDIN', input)
379
- set_global.call('$stdout', 'STDOUT', output)
380
- set_global.call('$stderr', 'STDERR', error)
381
- end
382
-
383
- end # module Util
384
-
385
- class FieldAccessor
386
- def initialize(obj, clazz = nil)
387
- @obj = obj
388
- clazz ||= obj.class
389
- @cls = [clazz.java_class].to_java(java.lang.Class)[0]
390
- end
391
-
392
- def [](name)
393
- field = @cls.getDeclaredField(name.to_s)
394
- field.setAccessible(true)
395
- field.get(@obj)
396
- end
397
-
398
- def []=(name, value)
399
- field = @cls.getDeclaredField(name.to_s)
400
- field.setAccessible(true)
401
- field.set(@obj, value)
402
- end
403
-
404
- def method_missing(name, value =nil)
405
- if name.to_s =~ /=$/
406
- self[name.to_s.chomp('=')] = value
407
- else
408
- self[name]
409
- end
410
- end
411
- end
412
-
413
- module NailMethods
414
-
415
- def self.extend_object(obj)
416
- super
417
- (class << obj; self; end).module_eval do
418
- alias_method :pwd, :getWorkingDirectory
419
- alias_method :server, :getNGServer
420
- end
421
- end
422
-
423
- def argv
424
- [command] + args
425
- end
426
-
427
- def attach_runtime(runtime)
428
- runtime.extend RuntimeMixin
429
- runtime.evalScriptlet %q{
430
- require 'ostruct'
431
- module Buildr
432
- module Nailgun
433
- extend self
434
- attr_reader :ng
435
- @ng = OpenStruct.new
436
- end
437
- end
438
- }
439
- runtime.Buildr::Nailgun.ng.nail = self
440
- runtime.load_service.require __FILE__
441
- runtime
442
- end
443
- private :attach_runtime
444
-
445
- def jruby
446
- @jruby ||= server.runtime_factory.new_jruby.tap do |runtime|
447
- attach_runtime(runtime)
448
- end
449
- end
450
-
451
- def buildr
452
- @buildr ||= server.runtime_factory.new_buildr.tap do |runtime|
453
- attach_runtime(runtime)
454
- end
455
- end
456
-
457
- def options
458
- @options ||= OpenStruct.new
459
- end
460
-
461
- end # NailMethods
462
-
463
- module RuntimeMixin
464
- def Buildr
465
- object.const_get(:Buildr)
466
- end
467
- end
468
-
469
- module AppMixin
470
- def load_tasks
471
- trace "Not loading tasks again"
472
- end
473
-
474
- def load_buildfile
475
- trace "Not loading buildfile again"
476
- end
477
- end
100
+ end # Util
478
101
 
479
102
  module Client
480
103
 
481
- class << self
482
- include Buildr::CommandLineInterface
483
-
484
- def options
485
- Nailgun.ng.nail.options
486
- end
487
-
488
- def rakefiles
489
- Nailgun.ng.nail.options.rakefiles
490
- end
491
-
492
- def requires
493
- Nailgun.ng.nail.options.requires
494
- end
495
-
496
- def help
497
- super
498
- puts
499
- puts 'To get a summary of Nailgun features use'
500
- puts ' nailgun:help'
501
- end
502
-
503
- def version
504
- puts super
505
- end
104
+ def main(nail)
105
+ nail.out.println "Connected to #{nail.getNGServer}"
506
106
 
507
- def do_option(opt, value)
508
- case opt
509
- when '--help'
510
- options.exit = :help
511
- when '--version'
512
- options.exit = :version
513
- when '--nosearch'
514
- options.nosearch = true
515
- else
516
- super
517
- end
518
- end
107
+ runtime = JRuby.runtime
519
108
 
520
- def sBuildr
521
- Nailgun.ng.nail.server.runtime.object.const_get(:Buildr)
522
- end
109
+ stdout = Util.ctor(org.jruby.RubyIO, runtime, java.io.OutputStream => nail.out)
110
+ stderr = Util.ctor(org.jruby.RubyIO, runtime, java.io.OutputStream => nail.err)
111
+ stdin = Util.ctor(org.jruby.RubyIO, runtime, java.io.InputStream => nail.in)
523
112
 
524
- def attach_runtime
525
- nail = Nailgun.ng.nail
526
- ARGV.replace nail.argv
527
- Dir.chdir nail.pwd
528
- nail.env.each { |k, v| ENV[k.to_s] = v.to_s }
529
-
530
- Buildr.const_set(:VERSION, sBuildr::VERSION) unless Buildr.const_defined?(:VERSION)
531
- nail.options.rakefiles = sBuildr::Application::DEFAULT_BUILDFILES.dup
532
- nail.options.requires = []
533
- end
113
+ dir = nail.getWorkingDirectory
114
+ argv = [nail.command] + nail.args
534
115
 
535
- def client(runtime, nail, &block)
536
- Util.set_stdio(runtime, nail)
537
- nailgun_module = runtime.Buildr::Nailgun
538
- nailgun_module.ng.nail = nail
539
- nailgun_module::Client.attach_runtime
540
- nailgun_module::Client.instance_eval(&block)
541
- end
542
- end
543
-
544
- def main(nail)
545
- nail.extend NailMethods
546
- info "Got connection from #{nail.pwd}"
547
-
548
- Client.client(nail.jruby, nail) do
549
-
550
- parse_options
551
- if options.exit
552
- send(options.exit)
553
- nail.exit(0)
554
- end
555
-
556
- if options.project && File.directory?(options.project)
557
- Dir.chdir(options.project)
558
- end
559
-
560
- bf = Util.find_file(Dir.pwd, options.rakefiles, options.nosearch)
561
- unless bf
562
- nail.out.println "No buildfile found at #{Dir.pwd}"
563
- nail.exit(0)
564
- end
565
-
566
- rt = nail.server.cached_runtimes[bf]
567
- old_stamp = nail.server.cached_stamps[bf] || Rake::EARLY
568
- new_stamp = rt ? rt.Buildr.application.buildfile.timestamp : Rake::EARLY
569
-
570
- if rt.nil? || new_stamp > old_stamp
571
- rt = nail.buildr
572
- app = rt.Buildr.application
573
- app.instance_variable_set(:@rakefile, bf)
574
- nail.out.println "Currently nailgun has issues reloading buildfiles, will get fixed in next release."
575
- nail.out.println "Restart your nailgun server."
576
- return nail.exit(1)
577
- else
578
- app = rt.Buildr.application.extend AppMixin
579
- app.lookup('buildr:initialize').instance_eval do
580
- @already_invoked = false
581
- @actions = []
582
- end
583
- app.instance_eval do
584
- @tasks.values.each do |task|
585
- is_project = rt.Buildr::Project.instance_variable_get(:@projects).key?(task.name)
586
- task.instance_variable_set(:@already_invoked, false) unless is_project
587
- end
588
- end
589
- end
590
-
591
- app.instance_eval do
592
- @original_dir = nail.pwd
593
- end
594
-
595
- Client.client(rt, nail) do
596
- Util.exception_handling do
597
- begin
598
- app.parse_options
599
- app.collect_tasks
600
- app.run
601
- rescue SystemExit => e
602
- nail.exit(1)
603
- end
604
- end
605
- end
606
-
607
- nail.server.cache(rt, app.buildfile)
608
- end
116
+ DRbApplication.remote_run :dir => dir, :argv => argv,
117
+ :in => stdin, :out => stdout, :err => stderr
118
+ rescue => e
119
+ nail.err.println e unless SystemExit === e
120
+ nail.exit 1
609
121
  end
610
122
 
611
- end # class Client
123
+ end # Client
612
124
 
613
125
  module Server
614
-
615
- attr_reader :runtime_factory
616
- attr_reader :cached_runtimes
617
- attr_reader :cached_stamps
618
- attr_reader :loaded_times
619
-
620
- def initialize(host = 'localhost', port = 2113, buildr_factory = nil)
621
- super(java.net.InetAddress.get_by_name(host), port)
622
- @cached_runtimes = {}
623
- @cached_stamps = {}
624
- @loaded_times = {}
625
- cache(runtime, Buildr.application.buildfile)
626
- @runtime_factory = buildr_factory
627
- @host, @port = host, port
628
- end
629
-
630
- def cache(runtime, buildfile)
631
- cached_runtimes[buildfile.to_s] = runtime
632
- cached_stamps[buildfile.to_s] = buildfile.timestamp
633
- loaded_times[buildfile.to_s] = Time.now
634
- end
635
-
636
- def runtime
637
- JRuby.runtime.extend RuntimeMixin
126
+ def initialize(host, port)
127
+ @host = host || "*"
128
+ @port = port
129
+ super(host, port)
638
130
  end
639
131
 
640
132
  def start
@@ -642,7 +134,6 @@ module Buildr #:nodoc:
642
134
 
643
135
  NGClient::Main.nail = NGClient.new
644
136
  self.default_nail_class = NGClient::Main
645
- runtime_factory.start
646
137
 
647
138
  @thread = java.lang.Thread.new(self)
648
139
  @thread.setName(to_s)
@@ -653,165 +144,78 @@ module Buildr #:nodoc:
653
144
  end
654
145
 
655
146
  def stop
656
- runtime_factory.stop
657
147
  @thread.kill
658
148
  end
659
149
 
660
150
  def to_s
661
- self.class.name+'('+[Buildr.application.version, @host, @port].join(', ')+')'
151
+ version = "Buildr #{Buildr::VERSION} #{RUBY_PLATFORM[/java/] && '(JRuby '+JRUBY_VERSION+')'}"
152
+ self.class.name+'('+[version, @host, @port].join(', ')+')'
662
153
  end
663
- end # module Server
664
-
665
- class RuntimeFactory
666
-
667
- attr_accessor :buildrs_size, :jrubys_size
668
-
669
- def initialize(buildrs_size = 1, jrubys_size = nil)
670
- # jrubys_size ||= buildrs_size
671
- @buildrs_size = buildrs_size < 1 ? 1 : buildrs_size
672
- # @jrubys_size = jrubys_size < 1 ? 1 : jrubys_size
154
+ end # Server
673
155
 
674
- @buildrs = [].extend(MonitorMixin)
675
- @buildrs_ready = @buildrs.new_cond
676
- @buildrs_needed = @buildrs.new_cond
677
-
678
- @buildrs_creators = [].extend(MonitorMixin)
156
+ namespace(:nailgun) do
679
157
 
680
- # @jrubys = [].extend(MonitorMixin)
681
- # @jrubys_ready = @jrubys.new_cond
682
- # @jrubys_needed = @jrubys.new_cond
683
-
684
- # @jrubys_creators = [].extend(MonitorMixin)
685
- end
158
+ dist_zip = Buildr.download(tmp_path(NAME + '.zip') => URL)
159
+ dist_dir = Buildr.unzip(tmp_path(NAME) => dist_zip)
686
160
 
687
- def new_buildr
688
- get(:buildr)
689
- end
161
+ nailgun_jar = file(tmp_path(NAME, NAME, NAME + '.jar'))
162
+ nailgun_jar.enhance [dist_dir] unless File.exist?(nailgun_jar.to_s)
690
163
 
691
- def new_jruby(&block)
692
- # get(:jruby)
693
- create_jruby(0, &block)
164
+ attr_reader :artifact
165
+ @artifact = Buildr.artifact(ARTIFACT_SPEC).from(nailgun_jar)
166
+
167
+ compiled_bin = file(tmp_path(NAME, NAME, 'ng' + Config::CONFIG['EXEEXT']) => dist_dir.target) do |task|
168
+ unless task.to_s.pathmap('%x') == '.exe'
169
+ Dir.chdir(task.to_s.pathmap('%d')) do
170
+ info "Compiling #{task.to_s}"
171
+ system('make', task.to_s.pathmap('%f')) or
172
+ fail "Nailgun binary compilation failed."
173
+ end
174
+ end
694
175
  end
695
176
 
696
- def start
697
- trace "Starting Buildr runtime factory"
698
- # @jruby_creator = Thread.new { loop { create :jruby } }
699
- # @jruby_creator.priority = -2
700
- @buildr_creator = Thread.new { loop { create :buildr } }
701
- @buildr_creator.priority = 1
177
+ attr_reader :installed_bin
178
+ @installed_bin = file(File.expand_path(compiled_bin.to_s.pathmap('%f'), nailgun_home) => compiled_bin) do |task|
179
+ mkpath task.to_s.pathmap('%d'), :verbose => false
180
+ cp compiled_bin.to_s, task.to_s, :verbose => false
702
181
  end
703
182
 
704
- def stop
705
- @buildr_creator.kill if @buildr_creator
706
- # @jruby_creator.kill if @jruby_creator
183
+ task('drb-notice') do
184
+ info ''
185
+ info 'Running in JRuby, a nailgun server will be started so that'
186
+ info 'you can use your nailgun client to invoke buildr tasks: '
187
+ info ''
188
+ info ' '+Nailgun.installed_bin.to_s
189
+ info ''
707
190
  end
708
191
 
709
- private
710
- def get(thing)
711
- collection = instance_variable_get("@#{thing}s")
712
- needs = instance_variable_get("@#{thing}s_needed")
713
- ready = instance_variable_get("@#{thing}s_ready")
714
- result = nil
715
- collection.synchronize do
716
- if collection.empty?
717
- trace "no #{thing} available, ask to create more"
718
- needs.broadcast
719
- trace "should be creating #{thing}"
720
- ready.wait_while { collection.empty? }
721
- end
722
- trace "Getting my #{thing}"
723
- result = collection.shift
724
- trace "would need more #{thing}s"
725
- needs.broadcast
726
- trace "got my #{thing}: #{result.inspect}"
727
- Thread.pass
728
- end
729
- trace "returning #{result.inspect}"
730
- result
192
+ task('drb' => ['drb-notice', 'start'])
193
+
194
+ desc 'Start the nailgun server'
195
+ task('start' => [installed_bin, 'setup']) do |task|
196
+ server = NGServer.new(nil, PORT)
197
+ server.start
731
198
  end
732
199
 
733
- def create(thing, *args, &block)
734
- Util.exception_handling do
735
- creator = needed(thing)
736
- collection = instance_variable_get("@#{thing}s")
737
- ready = instance_variable_get("@#{thing}s_ready")
738
- needs = instance_variable_get("@#{thing}s_needed")
739
- unless creator
740
- collection.synchronize do
741
- trace "awake those wanting a #{thing}"
742
- ready.broadcast
743
- Thread.pass
744
- trace "wait until more #{thing}s are needed"
745
- # needs.wait(1); return
746
- needs.wait_until { creator = needed(thing) }
747
- end
748
- end
749
- trace "About to create #{thing} # #{creator}"
750
- method = "create_#{thing}"
751
- creators = instance_variable_get("@#{thing}s_creators")
752
- trace "registering creator for #{thing} #{creator}"
753
- creators.synchronize { creators << creator }
754
- result = send(method, creator, *args, &block)
755
- trace "created #{thing}[#{creator}] => #{result.inspect}"
756
- creators.synchronize do
757
- trace "unregistering creator for #{thing} #{creator}"
758
- creators.delete(creator)
759
- collection.synchronize do
760
- trace "adding object on queue for #{thing} #{creator}"
761
- collection << result
762
- end
763
- end
200
+ task('setup' => artifact) do
201
+ module Util
202
+ include Buildr::Util
764
203
  end
765
- end
766
-
767
- def needed(thing)
768
- collection = instance_variable_get("@#{thing}s")
769
- creators = instance_variable_get("@#{thing}s_creators")
770
- size = instance_variable_get("@#{thing}s_size")
771
- collection.synchronize do
772
- count = collection.size
773
- if count < size
774
- count += creators.synchronize { creators.size }
775
- end
776
- count if count < size
204
+
205
+ Util.add_to_sysloader artifact.to_s
206
+ Util.add_to_sysloader ADDON_BIN
207
+
208
+ class NGClient
209
+ include org.apache.buildr.BuildrNail
210
+ include Client
777
211
  end
212
+
213
+ class NGServer < com.martiansoftware.nailgun.NGServer
214
+ include Server
215
+ end
778
216
  end
779
217
 
780
- def create_jruby(creator, &block)
781
- Util.exception_handling do
782
- trace "Creating jruby[#{creator}]"
783
- Util.benchmark do |header|
784
- cfg = org.jruby.RubyInstanceConfig.new
785
- yield cfg if block_given?
786
- jruby = org.jruby.Ruby.newInstance(cfg)
787
- jruby.load_service.load_path.unshift *BUILDR_PATHS
788
- header.replace ["Created jruby[#{creator}]", jruby]
789
- jruby
790
- end
791
- end
792
- end
793
-
794
- def create_buildr(creator)
795
- Util.exception_handling do
796
- trace "Obtaining jruby to load buildr[#{creator}] on it"
797
- jruby = new_jruby
798
- trace "Loading buildr[#{creator}] on #{jruby} ..."
799
- Util.benchmark ["Loaded buildr[#{creator}] on #{jruby}"] do
800
- load_service = jruby.load_service
801
- load_service.require 'rubygems'
802
- load_service.require 'buildr'
803
- end
804
- jruby
805
- end
806
- end
218
+ end # ng_tasks
807
219
 
808
- end # RuntimeFactory
809
-
810
- if Buildr.respond_to?(:application) && ng.nail.nil?
811
- Buildr.application.in_namespace(:nailgun, &file_tasks)
812
- Buildr.application.in_namespace(:nailgun, &server_tasks)
813
- end
814
-
815
220
  end # module Nailgun
816
-
817
221
  end