cake 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cake +69 -17
- data/lib/bake.jar +0 -0
- data/lib/cake.jar +0 -0
- metadata +4 -4
data/bin/cake
CHANGED
@@ -11,6 +11,7 @@ require 'fileutils'
|
|
11
11
|
require 'pp'
|
12
12
|
|
13
13
|
file = File.readlink(__FILE__) rescue __FILE__
|
14
|
+
$bakedir = Dir.getwd
|
14
15
|
$cakedir = File.dirname(File.dirname(file))
|
15
16
|
$confdir = ".cake"
|
16
17
|
$repo = "http://clojars.org/repo/cake/cake"
|
@@ -95,8 +96,12 @@ def verbose?
|
|
95
96
|
debug? or $opts[:v] or $opts[:verbose]
|
96
97
|
end
|
97
98
|
|
99
|
+
def config_updated?
|
100
|
+
newer?(".cake/config", ".cake/cake.pid") or newer?(".cake/config", ".cake/bake.pid")
|
101
|
+
end
|
102
|
+
|
98
103
|
def restart?
|
99
|
-
$opts[:r] or $opts[:restart] or [:stop, :restart].include?($command)
|
104
|
+
$opts[:r] or $opts[:restart] or [:stop, :restart].include?($command) or config_updated?
|
100
105
|
end
|
101
106
|
|
102
107
|
def admin_command?
|
@@ -109,12 +114,27 @@ def log(command, *message)
|
|
109
114
|
end
|
110
115
|
end
|
111
116
|
|
117
|
+
CONFIG_FILE = ".cake/config"
|
118
|
+
def config
|
119
|
+
if @config.nil?
|
120
|
+
@config = {}
|
121
|
+
File.open(CONFIG_FILE, 'r') do |file|
|
122
|
+
file.each do |line|
|
123
|
+
key, value = line.split('=', 2)
|
124
|
+
@config[key.strip] = value.strip
|
125
|
+
end
|
126
|
+
end if File.exists?(CONFIG_FILE)
|
127
|
+
end
|
128
|
+
@config
|
129
|
+
end
|
130
|
+
|
112
131
|
class JVM
|
113
|
-
attr_reader :type, :classpath, :port, :pid, :pidfile, :start_time
|
132
|
+
attr_reader :type, :classpath, :libpath, :port, :pid, :pidfile, :start_time
|
114
133
|
|
115
|
-
def initialize(classpath)
|
134
|
+
def initialize(classpath, libpath = nil)
|
116
135
|
@type = self.class.name.downcase
|
117
136
|
@classpath = classpath
|
137
|
+
@libpath = libpath
|
118
138
|
@pidfile = "#{$confdir}/#{type}.pid"
|
119
139
|
@start_time = File.exists?(pidfile) ? File.mtime(pidfile) : Time.now
|
120
140
|
|
@@ -163,6 +183,10 @@ class JVM
|
|
163
183
|
end
|
164
184
|
end
|
165
185
|
|
186
|
+
def java_opts
|
187
|
+
"-cp #{classpath} -Djava.library.path=#{libpath}"
|
188
|
+
end
|
189
|
+
|
166
190
|
MIN_PORT = 2**13
|
167
191
|
MAX_PORT = 2**16
|
168
192
|
|
@@ -170,7 +194,7 @@ class JVM
|
|
170
194
|
return if running?
|
171
195
|
@port = rand(MAX_PORT - MIN_PORT) + MIN_PORT
|
172
196
|
log(:start, "starting #{type} jvm on port #{port}") if debug?
|
173
|
-
@pid = daemon %{ java
|
197
|
+
@pid = daemon %{ java #{java_opts} clojure.main -e "(use '#{type})(start-server #{port})" /dev/null }
|
174
198
|
File.open(pidfile, 'w') {|f| f.write("#{pid}\n#{port}\n") }
|
175
199
|
log(:start, "#{type} jvm started") if verbose?
|
176
200
|
rescue Errno::EADDRNOTAVAIL => e
|
@@ -243,7 +267,7 @@ private
|
|
243
267
|
pid
|
244
268
|
end
|
245
269
|
|
246
|
-
def with_socket(retries =
|
270
|
+
def with_socket(retries = 10)
|
247
271
|
return unless port
|
248
272
|
socket = TCPSocket.new("localhost", port)
|
249
273
|
result = yield(socket)
|
@@ -273,15 +297,19 @@ class Cake < JVM
|
|
273
297
|
command
|
274
298
|
end
|
275
299
|
end
|
300
|
+
|
301
|
+
def java_opts
|
302
|
+
[ENV['CAKE_JAVA_OPTS'], config['cake.java_opts'], super].compact.join(' ')
|
303
|
+
end
|
276
304
|
end
|
277
305
|
|
278
306
|
class Bake < JVM
|
279
|
-
MARKER = rand.to_s
|
307
|
+
MARKER = "=#{rand.to_s}="
|
280
308
|
PROMPT = /^(.*)#{MARKER}$/
|
281
309
|
START_REPL = <<-END
|
282
310
|
(clojure.main/repl
|
283
311
|
:init #(in-ns 'user)
|
284
|
-
:prompt #(printf "%s
|
312
|
+
:prompt #(printf "%s#{MARKER}\n" (ns-name *ns*)))
|
285
313
|
END
|
286
314
|
|
287
315
|
def repl
|
@@ -291,8 +319,8 @@ class Bake < JVM
|
|
291
319
|
socket.write START_REPL
|
292
320
|
socket.gets # burn extra prompt
|
293
321
|
|
294
|
-
while
|
295
|
-
line = readline
|
322
|
+
while @ns = read_until_prompt(socket)
|
323
|
+
line = readline
|
296
324
|
return unless line
|
297
325
|
socket.write(line + "\n")
|
298
326
|
end
|
@@ -302,6 +330,10 @@ class Bake < JVM
|
|
302
330
|
save_history
|
303
331
|
end
|
304
332
|
|
333
|
+
def java_opts
|
334
|
+
[ENV['JAVA_OPTS'], config['project.java_opts'], super].compact.join(' ')
|
335
|
+
end
|
336
|
+
|
305
337
|
private
|
306
338
|
|
307
339
|
HISTORY_NUM = 500
|
@@ -336,9 +368,12 @@ private
|
|
336
368
|
end
|
337
369
|
end
|
338
370
|
|
339
|
-
|
371
|
+
Readline.completer_word_break_characters = " \t\n\"'`~@;#&{}()[]"
|
372
|
+
|
373
|
+
def readline
|
340
374
|
input = []
|
341
|
-
prompt =
|
375
|
+
prompt = "#{@ns}=> "
|
376
|
+
Readline.completion_proc = method(:completions)
|
342
377
|
while line = Readline.readline(prompt)
|
343
378
|
input << line
|
344
379
|
if complete?(input)
|
@@ -352,6 +387,18 @@ private
|
|
352
387
|
Readline::HISTORY.push(input)
|
353
388
|
retry
|
354
389
|
end
|
390
|
+
|
391
|
+
def completions(prefix)
|
392
|
+
return [] if prefix.empty?
|
393
|
+
with_socket do |socket|
|
394
|
+
socket.write(":completions [\"#{prefix}\" #{@ns}]\n")
|
395
|
+
completions = []
|
396
|
+
while line = socket.gets
|
397
|
+
completions << line.chomp
|
398
|
+
end
|
399
|
+
completions
|
400
|
+
end
|
401
|
+
end
|
355
402
|
end
|
356
403
|
|
357
404
|
# Bootstrap cake dependencies.
|
@@ -362,8 +409,8 @@ if File.exists?("#{$cakedir}/.gitignore")
|
|
362
409
|
version = IO.read("#{$cakedir}/project.clj").first.match(/defproject cake \"(.*)\"/)[1]
|
363
410
|
get_cake(version, lib)
|
364
411
|
end
|
365
|
-
cakepath = "#{$cakedir}/src:#{lib}/*"
|
366
|
-
bakepath = "#{$cakedir}/bake"
|
412
|
+
cakepath = "#{$cakedir}/src:#{lib}/*:#{lib}/dev/*"
|
413
|
+
bakepath = "#{$cakedir}/bake:#{lib}/dev/*"
|
367
414
|
else
|
368
415
|
cakejar = "#{lib}/cake.jar"
|
369
416
|
bakejar = "#{lib}/bake.jar"
|
@@ -380,11 +427,16 @@ else
|
|
380
427
|
end
|
381
428
|
end
|
382
429
|
|
383
|
-
|
384
|
-
srcpath = "#{pwd}/src:#{pwd}/src/clj"
|
430
|
+
srcpath = "#{$bakedir}/src:#{$bakedir}/src/clj"
|
385
431
|
|
386
|
-
cake = Cake.new(
|
387
|
-
|
432
|
+
cake = Cake.new(
|
433
|
+
"#{cakepath}:#{srcpath}:#{$bakedir}/lib/dev/*",
|
434
|
+
"#{$bakedir}/lib/dev/native"
|
435
|
+
)
|
436
|
+
bake = Bake.new(
|
437
|
+
"#{bakepath}:#{srcpath}:#{$bakedir}/classes:#{$bakedir}/test:#{$bakedir}/lib/*:#{$bakedir}/lib/dev/*",
|
438
|
+
"#{$bakedir}/lib/native:#{$bakedir}/lib/dev/native"
|
439
|
+
)
|
388
440
|
|
389
441
|
if $command == :kill
|
390
442
|
cake.kill
|
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: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 8
|
10
|
+
version: 0.2.8
|
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-06-
|
19
|
+
date: 2010-06-25 00:00:00 -07:00
|
20
20
|
default_executable: cake
|
21
21
|
dependencies: []
|
22
22
|
|