cake 0.3.4 → 0.3.6
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/bin/cake +66 -40
- data/lib/bake.jar +0 -0
- data/lib/cake.jar +0 -0
- metadata +4 -4
data/bin/cake
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Save your fork, there's cake!"
|
3
|
-
require 'ftools'
|
4
3
|
require 'find'
|
5
4
|
require 'open-uri'
|
6
5
|
require 'rexml/document'
|
7
6
|
require 'socket'
|
8
7
|
require 'timeout'
|
9
8
|
require 'fileutils'
|
10
|
-
require 'pp'
|
11
9
|
|
12
10
|
begin
|
13
11
|
require 'readline'
|
@@ -24,6 +22,19 @@ rescue LoadError => e
|
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
25
|
+
class IO
|
26
|
+
def gets_nonblock
|
27
|
+
line = ""
|
28
|
+
while c = read_nonblock(1)
|
29
|
+
line << c
|
30
|
+
break if c == "\n"
|
31
|
+
end
|
32
|
+
line
|
33
|
+
rescue Errno::EAGAIN, EOFError => e
|
34
|
+
line
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
27
38
|
def project_dir(dir)
|
28
39
|
while dir != "/"
|
29
40
|
return dir if [".cake", "project.clj", "build.clj"].any? {|file| File.exists?("#{dir}/#{file}")}
|
@@ -34,14 +45,15 @@ end
|
|
34
45
|
|
35
46
|
PATH_SEP = ':'
|
36
47
|
file = File.readlink(__FILE__) rescue __FILE__
|
37
|
-
$
|
48
|
+
$pwd = Dir.getwd
|
49
|
+
$bakedir = project_dir($pwd)
|
38
50
|
$cakedir = File.dirname(File.dirname(file))
|
39
51
|
$repo = "http://clojars.org/repo/cake/cake"
|
40
52
|
$confdir = ".cake"
|
41
53
|
Dir.chdir($bakedir)
|
42
|
-
|
54
|
+
FileUtils.makedirs($confdir)
|
43
55
|
|
44
|
-
def get_cake(version, dest = nil)
|
56
|
+
def get_cake(version, dest = nil, opts = {})
|
45
57
|
jar = version =~ /(.*)-SNAPSHOT/ ? "cake-#{$1}-#{snapshot(version)}.jar" : "cake-#{version}.jar"
|
46
58
|
repo = File.expand_path("~/.m2/repository/cake/cake/#{version}")
|
47
59
|
path = "#{repo}/#{jar}"
|
@@ -49,7 +61,8 @@ def get_cake(version, dest = nil)
|
|
49
61
|
if not File.exists?(path)
|
50
62
|
log(:deps, "fetching cake libraries. this may take a moment...")
|
51
63
|
url = "#{$repo}/#{version}/#{jar}"
|
52
|
-
|
64
|
+
log(:deps, "downloading #{url}") if verbose?
|
65
|
+
FileUtils.makedirs(repo)
|
53
66
|
open(url) do |jarfile|
|
54
67
|
open(path, "wb") do |file|
|
55
68
|
while (buf = jarfile.read(8192))
|
@@ -61,10 +74,11 @@ def get_cake(version, dest = nil)
|
|
61
74
|
return path unless dest
|
62
75
|
|
63
76
|
dest = File.expand_path(dest)
|
64
|
-
|
65
|
-
|
77
|
+
FileUtils.makedirs(dest)
|
78
|
+
FileUtils.copy(path, dest)
|
66
79
|
"#{dest}/#{jar}"
|
67
80
|
rescue OpenURI::HTTPError => e
|
81
|
+
raise if opts[:raise]
|
68
82
|
log(:deps, "unable to find cake version #{version} on clojars.")
|
69
83
|
log(:deps, "please check http://github.com/ninjudd/cake for latest install instructions.")
|
70
84
|
exit
|
@@ -92,8 +106,8 @@ def extract(jar, file, dest = File.dirname(jar))
|
|
92
106
|
log(:deps, "extracting #{file} from #{jar}") if verbose?
|
93
107
|
ret = system %{ jar xf #{jar} #{file} }
|
94
108
|
raise "cannot find jar command" unless ret
|
95
|
-
|
96
|
-
|
109
|
+
FileUtils.makedirs(dest)
|
110
|
+
FileUtils.move(file, dest)
|
97
111
|
end
|
98
112
|
"#{dest}/#{file}"
|
99
113
|
end
|
@@ -202,7 +216,7 @@ class JVM
|
|
202
216
|
end
|
203
217
|
|
204
218
|
def refresh
|
205
|
-
@pid, @port = IO.read(pidfile).map {|l| l.to_i}
|
219
|
+
@pid, @port = IO.read(pidfile).split("\n").map {|l| l.to_i}
|
206
220
|
Process.kill(0, @pid) # make sure pid is valid
|
207
221
|
TCPSocket.new("localhost", @port).close if @port # make sure jvm is running on port
|
208
222
|
rescue Errno::ENOENT, Errno::ESRCH, Errno::ECONNREFUSED => e
|
@@ -266,7 +280,7 @@ class JVM
|
|
266
280
|
@pid = daemon %{ java -Dcake.project=#{$bakedir} #{java_opts} clojure.main -e "(use '#{type})(start-server #{port})" /dev/null }
|
267
281
|
File.open(pidfile, 'w') {|f| f.write("#{pid}\n#{port}\n") }
|
268
282
|
end
|
269
|
-
rescue Errno::EADDRNOTAVAIL => e
|
283
|
+
rescue Errno::EADDRNOTAVAIL => e # port already in use
|
270
284
|
retry
|
271
285
|
end
|
272
286
|
|
@@ -302,7 +316,7 @@ class JVM
|
|
302
316
|
Find.find(path) do |f|
|
303
317
|
Find.prune if f == "#{$bakedir}/src/jvm"
|
304
318
|
files << f if File.exists?(f) and not File.directory?(f)
|
305
|
-
end
|
319
|
+
end if File.exists?(path)
|
306
320
|
end
|
307
321
|
end
|
308
322
|
files
|
@@ -310,7 +324,7 @@ class JVM
|
|
310
324
|
|
311
325
|
def ping
|
312
326
|
return unless enabled?
|
313
|
-
with_socket
|
327
|
+
with_socket do |socket|
|
314
328
|
socket.write ":ping\n"
|
315
329
|
log($command, "#{type} jvm not running") unless socket.gets == "pong\n"
|
316
330
|
end
|
@@ -333,6 +347,17 @@ class JVM
|
|
333
347
|
save_history
|
334
348
|
end
|
335
349
|
|
350
|
+
def eval(forms = $opts[:eval])
|
351
|
+
forms = forms.join(' ')
|
352
|
+
with_socket do |socket|
|
353
|
+
log(:eval, forms) if debug?
|
354
|
+
socket.write(':eval [' + forms + ']')
|
355
|
+
while (line = socket.gets)
|
356
|
+
puts line
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
336
361
|
private
|
337
362
|
|
338
363
|
def make_path(paths)
|
@@ -367,7 +392,7 @@ private
|
|
367
392
|
pid
|
368
393
|
end
|
369
394
|
|
370
|
-
def with_socket(retries =
|
395
|
+
def with_socket(retries = 20)
|
371
396
|
return unless port
|
372
397
|
socket = TCPSocket.new("localhost", port)
|
373
398
|
result = yield(socket)
|
@@ -375,6 +400,7 @@ private
|
|
375
400
|
rescue Errno::ECONNREFUSED => e
|
376
401
|
sleep 1
|
377
402
|
retry if (retries -= 1) >= 0
|
403
|
+
log($command, "timeout while connecting to #{type} jvm")
|
378
404
|
exit
|
379
405
|
ensure
|
380
406
|
socket.close if socket
|
@@ -396,9 +422,15 @@ private
|
|
396
422
|
end
|
397
423
|
|
398
424
|
def read_until_prompt(socket)
|
399
|
-
while
|
400
|
-
|
401
|
-
|
425
|
+
while ready = select([socket, $stdin])[0]
|
426
|
+
if ready.first == socket
|
427
|
+
line = socket.gets_nonblock
|
428
|
+
return $1 if line =~ /^#{REPL_PROMPT}(.*)$/
|
429
|
+
$stdout.print line
|
430
|
+
$stdout.flush
|
431
|
+
else
|
432
|
+
socket.puts($stdin.gets)
|
433
|
+
end
|
402
434
|
end
|
403
435
|
end
|
404
436
|
|
@@ -450,7 +482,7 @@ class Cake < JVM
|
|
450
482
|
def send_command(command, args = [])
|
451
483
|
with_socket do |socket|
|
452
484
|
args = args.collect{|arg| '"' + arg.gsub('"', '\"').gsub("\n", "\\n") + '"'}
|
453
|
-
cmd = %{
|
485
|
+
cmd = %{[#{command} [#{args.join(' ')}] #{bakeport || "nil"} "#{$pwd}"] "#{READLINE}"}
|
454
486
|
log(command, "sending: " + cmd) if debug?
|
455
487
|
socket.write(cmd)
|
456
488
|
while (line = socket.gets)
|
@@ -498,17 +530,6 @@ class Bake < JVM
|
|
498
530
|
def enabled?
|
499
531
|
Dir["lib/*.jar"].any?
|
500
532
|
end
|
501
|
-
|
502
|
-
def eval(*forms)
|
503
|
-
forms = forms.join(' ')
|
504
|
-
with_socket do |socket|
|
505
|
-
log(:eval, forms) if debug?
|
506
|
-
socket.write('[' + forms + ']')
|
507
|
-
while (line = socket.gets)
|
508
|
-
puts line
|
509
|
-
end
|
510
|
-
end
|
511
|
-
end
|
512
533
|
end
|
513
534
|
|
514
535
|
# Bootstrap cake dependencies.
|
@@ -516,8 +537,13 @@ lib = "#{$cakedir}/lib"
|
|
516
537
|
if File.exists?("#{$cakedir}/.gitignore") and File.exists?("#{$cakedir}/project.clj")
|
517
538
|
if Dir["#{lib}/*.jar"].empty? or Dir["#{lib}/dev/*.jar"].empty?
|
518
539
|
# In a new git checkout, need to fetch dependencies.
|
519
|
-
|
520
|
-
|
540
|
+
begin
|
541
|
+
version = IO.read("#{$cakedir}/project.clj").split("\n").first.match(/defproject cake \"(.*)\"/)[1]
|
542
|
+
cakejar = get_cake(version, lib, :raise => true)
|
543
|
+
rescue OpenURI::HTTPError => e
|
544
|
+
version = current_version
|
545
|
+
cakejar = get_cake(version, lib)
|
546
|
+
end
|
521
547
|
extract(cakejar, "bake-#{version}.jar", "#{lib}/dev")
|
522
548
|
end
|
523
549
|
|
@@ -572,7 +598,7 @@ if not [:deps, :clean].include?($command) and File.exists?('project.clj')
|
|
572
598
|
if newer?('project.clj', 'pom.xml')
|
573
599
|
cake.send_command(:deps)
|
574
600
|
cake.init
|
575
|
-
elsif
|
601
|
+
elsif config['swank.auto-start'] or config['swank']
|
576
602
|
cake.send_command(:"swank-deps")
|
577
603
|
cake.init
|
578
604
|
end
|
@@ -580,17 +606,16 @@ if not [:deps, :clean].include?($command) and File.exists?('project.clj')
|
|
580
606
|
bake.init
|
581
607
|
end
|
582
608
|
|
583
|
-
if $command
|
609
|
+
if [:repl, :eval].include?($command)
|
584
610
|
if File.exists?('project.clj') and not $opts[:cake]
|
585
|
-
bake.
|
611
|
+
bake.send($command)
|
586
612
|
else
|
587
|
-
cake.
|
613
|
+
cake.send($command)
|
588
614
|
end
|
589
|
-
elsif $command == :eval
|
590
|
-
bake.eval(*$opts[:eval])
|
591
615
|
elsif [:start, :reload, :restart].include?($command)
|
592
616
|
if $opts[:l] or $opts[:log]
|
593
|
-
system("
|
617
|
+
system("touch .cake/project.log")
|
618
|
+
system("tail -f .cake/project.log")
|
594
619
|
else
|
595
620
|
cake.ping
|
596
621
|
bake.ping
|
@@ -598,6 +623,7 @@ elsif [:start, :reload, :restart].include?($command)
|
|
598
623
|
else
|
599
624
|
cake.bakeport = bake.port
|
600
625
|
if $command == :autotest
|
626
|
+
cake.send_command(:autotest)
|
601
627
|
interval = $opts[:autotest].last.to_i if $opts[:autotest]
|
602
628
|
interval = interval || (config['autotest.interval'].to_i if config['autotest.interval']) || 1
|
603
629
|
run_tests = true
|
@@ -608,7 +634,7 @@ else
|
|
608
634
|
args << "--report"
|
609
635
|
ran = true
|
610
636
|
end
|
611
|
-
cake.send_command(
|
637
|
+
cake.send_command(:test, args) if run_tests
|
612
638
|
run_tests = bake.reload
|
613
639
|
cake.reload
|
614
640
|
sleep(interval)
|
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:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 6
|
10
|
+
version: 0.3.6
|
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-
|
19
|
+
date: 2010-08-04 00:00:00 -07:00
|
20
20
|
default_executable: cake
|
21
21
|
dependencies: []
|
22
22
|
|