cake 0.3.8 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/cake +48 -22
  2. data/lib/bake.jar +0 -0
  3. data/lib/cake.jar +0 -0
  4. metadata +4 -4
data/bin/cake CHANGED
@@ -6,9 +6,13 @@ require 'rexml/document'
6
6
  require 'socket'
7
7
  require 'timeout'
8
8
  require 'fileutils'
9
+ require 'io/wait'
10
+ require 'pp'
9
11
 
10
- if RUBY_PLATFORM =~ /(mingw|mswin)32$/
12
+ if RUBY_PLATFORM =~ /(mingw|mswin)(32|64)$/
11
13
  require 'win32/process'
14
+ TERM = 'BRK'
15
+ KILL = 'KILL'
12
16
  PATH_SEP = ';'
13
17
  $home = ENV['HOMEDRIVE'] + ENV['HOMEPATH']
14
18
 
@@ -16,6 +20,8 @@ if RUBY_PLATFORM =~ /(mingw|mswin)32$/
16
20
  Process.create(:app_name => cmd).process_id
17
21
  end
18
22
  else
23
+ TERM = 'TERM'
24
+ KILL = 'KILL'
19
25
  PATH_SEP = ':'
20
26
  $home = File.expand_path("~")
21
27
 
@@ -47,11 +53,11 @@ rescue LoadError => e
47
53
  end
48
54
 
49
55
  class IO
50
- def gets_nonblock
56
+ def gets_nonblock(delim = "\n")
51
57
  line = ""
52
58
  while c = read_nonblock(1)
53
59
  line << c
54
- break if c == "\n"
60
+ break if c == delim
55
61
  end
56
62
  line
57
63
  rescue Errno::EAGAIN, EOFError => e
@@ -228,6 +234,10 @@ def config
228
234
  @config ||= Configuration.new(".cake/config")
229
235
  end
230
236
 
237
+ def ps
238
+ `jps -v`.split("\n").select {|l| l =~ /cake\.project/}
239
+ end
240
+
231
241
  class JVM
232
242
  attr_reader :type, :classpath, :libpath, :port, :pid, :pidfile, :load_time
233
243
 
@@ -343,7 +353,7 @@ class JVM
343
353
  end
344
354
 
345
355
  def kill
346
- Process.kill($opts[:"9"] ? "KILL" : "TERM", pid) if pid
356
+ Process.kill($opts[:"9"] ? KILL : TERM, pid) if pid
347
357
  end
348
358
 
349
359
  def files
@@ -452,25 +462,40 @@ private
452
462
  end
453
463
  end
454
464
 
455
- def read_until_prompt(socket)
456
- while ready = select([socket, $stdin])[0]
457
- if ready.first == socket
465
+ def read_until_prompt(socket, wait = 0.01, read_timeout = 3)
466
+ prompt = nil
467
+ while read_timeout -= wait
468
+ while socket.wait(wait)
458
469
  line = socket.gets_nonblock
459
- return $1 if line =~ /^#{REPL_PROMPT}(.*)$/
460
- $stdout.print line
461
- $stdout.flush
462
- else
463
- socket.puts($stdin.gets)
470
+ if line =~ /^#{REPL_PROMPT}(.*)$/
471
+ prompt = $1
472
+ else
473
+ $stdout.print line
474
+ $stdout.flush
475
+ end
464
476
  end
477
+ break if prompt
478
+
479
+ while $stdin.ready?
480
+ socket.puts($stdin.gets)
481
+ end if read_timeout <= 0
465
482
  end
483
+ prompt
466
484
  end
467
485
 
468
- def complete?(input)
469
- return true if input.empty?
486
+ def validate(input)
487
+ return input if input.empty?
470
488
  with_socket do |socket|
471
489
  socket.write(":validate #{input.join("\n").strip}")
472
490
  socket.close_write # send eof
473
- socket.gets != "incomplete\n"
491
+ results = socket.gets(nil)
492
+
493
+ return if results == "incomplete\n"
494
+ if results == "invalid\n"
495
+ input.join(' ').strip
496
+ else
497
+ results.strip
498
+ end
474
499
  end
475
500
  end
476
501
 
@@ -481,9 +506,9 @@ private
481
506
  Readline.completion_proc = method(:completions)
482
507
  while line = Readline.readline(prompt)
483
508
  input << line
484
- if complete?(input)
485
- Readline::HISTORY.push(input.join(' ').strip)
486
- return input.join("\n").strip
509
+ if valid_input = validate(input)
510
+ Readline::HISTORY.push(valid_input)
511
+ return valid_input
487
512
  end
488
513
  prompt[-2] = ?*
489
514
  end
@@ -513,7 +538,8 @@ class Cake < JVM
513
538
  def send_command(command, args = [])
514
539
  with_socket do |socket|
515
540
  args = args.collect{|arg| '"' + arg.gsub('"', '\"').gsub("\n", "\\n") + '"'}
516
- cmd = %{[#{command} [#{args.join(' ')}] #{bakeport || "nil"} "#{$pwd}"] "#{READLINE}"}
541
+ env = command == :run ? ('{' + ENV.collect {|k,v| "#{k.inspect} #{v.inspect}"}.join(' ') + '}') : 'nil'
542
+ cmd = %{[#{command} [#{args.join(' ')}] #{bakeport || 'nil'} "#{$pwd}" #{env}] "#{READLINE}"}
517
543
  log(command, "sending: " + cmd) if debug?
518
544
  socket.write(cmd)
519
545
  while (line = socket.gets)
@@ -606,9 +632,9 @@ bake = Bake.new(
606
632
 
607
633
  if $command == :kill
608
634
  if $opts[:all]
609
- `jps -v | grep cake.project`.split("\n").each do |line|
635
+ ps.each do |line|
610
636
  pid = line.split(' ').first.to_i
611
- Process.kill($opts[:"9"] ? "KILL" : "TERM", pid)
637
+ Process.kill($opts[:"9"] ? KILL : TERM, pid)
612
638
  end
613
639
  else
614
640
  cake.kill
@@ -616,7 +642,7 @@ if $command == :kill
616
642
  end
617
643
  exit
618
644
  elsif $command == :ps
619
- puts `jps -v | grep cake.project`.sort.reverse
645
+ puts ps.sort.reverse
620
646
  exit
621
647
  elsif restart? or config_updated?
622
648
  cake.stop
data/lib/bake.jar CHANGED
Binary file
data/lib/cake.jar CHANGED
Binary file
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cake
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 8
10
- version: 0.3.8
9
+ - 11
10
+ version: 0.3.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin Balthrop
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-09 00:00:00 -07:00
19
+ date: 2010-08-11 00:00:00 -07:00
20
20
  default_executable: cake
21
21
  dependencies: []
22
22