cake 0.2.8 → 0.2.9

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 +60 -30
  2. data/lib/bake.jar +0 -0
  3. data/lib/cake.jar +0 -0
  4. metadata +4 -4
data/bin/cake CHANGED
@@ -10,11 +10,12 @@ require 'readline'
10
10
  require 'fileutils'
11
11
  require 'pp'
12
12
 
13
+ PATH_SEP = ':'
13
14
  file = File.readlink(__FILE__) rescue __FILE__
14
15
  $bakedir = Dir.getwd
15
16
  $cakedir = File.dirname(File.dirname(file))
16
- $confdir = ".cake"
17
17
  $repo = "http://clojars.org/repo/cake/cake"
18
+ $confdir = ".cake"
18
19
  File.makedirs($confdir)
19
20
 
20
21
  def get_cake(version, dest)
@@ -58,9 +59,12 @@ def snapshot(version)
58
59
  end
59
60
  end
60
61
 
61
- def extract(jar, file)
62
- dest = File.dirname(jar)
63
- system %{ jar xf #{jar} -C #{dest} #{file} }
62
+ def extract(jar, file, dest = File.dirname(jar))
63
+ log(:deps, "extracting #{file} from #{jar}") if verbose?
64
+ system %{ jar xf #{jar} #{file} }
65
+
66
+ File.makedirs(dest)
67
+ File.move(file, dest)
64
68
  "#{dest}/#{file}"
65
69
  end
66
70
 
@@ -78,7 +82,7 @@ def parse_opts!
78
82
  $opts = {}
79
83
  ARGV.each do |opt|
80
84
  case opt
81
- when /^-(\w*)$/ then $1.chars.each {|c| add_opt!(c, "")}
85
+ when /^-(\w*)$/ then $1.split('').each {|c| add_opt!(c, '')}
82
86
  when /^--?([-\w]*)=([-,\w]+)$/ then add_opt!($1, *$2.split(','))
83
87
  when /^--?([-\w]*)$/ then add_opt!($1, "")
84
88
  else add_opt!($command, opt)
@@ -114,27 +118,39 @@ def log(command, *message)
114
118
  end
115
119
  end
116
120
 
117
- CONFIG_FILE = ".cake/config"
118
- def config
119
- if @config.nil?
120
- @config = {}
121
- File.open(CONFIG_FILE, 'r') do |file|
121
+ class Config < Hash
122
+ def initialize(path)
123
+ File.open(path, 'r') do |file|
122
124
  file.each do |line|
125
+ next if ['#', '!'].include?(line[0,1])
123
126
  key, value = line.split('=', 2)
124
- @config[key.strip] = value.strip
127
+ next unless key and value
128
+ self[key.strip] = value.strip
125
129
  end
126
- end if File.exists?(CONFIG_FILE)
130
+ end if File.exists?(path)
127
131
  end
128
- @config
132
+
133
+ def [](*keys)
134
+ if keys.first.kind_of?(Symbol)
135
+ key = keys.join('.') + '.'
136
+ clone.delete_if {|k,v| not k.index(key) == 0}
137
+ else
138
+ super
139
+ end
140
+ end
141
+ end
142
+
143
+ def config
144
+ @config ||= Config.new(".cake/config")
129
145
  end
130
146
 
131
147
  class JVM
132
148
  attr_reader :type, :classpath, :libpath, :port, :pid, :pidfile, :start_time
133
149
 
134
- def initialize(classpath, libpath = nil)
150
+ def initialize(classpath, libpath)
135
151
  @type = self.class.name.downcase
136
- @classpath = classpath
137
- @libpath = libpath
152
+ @classpath = make_path(classpath)
153
+ @libpath = make_path(libpath)
138
154
  @pidfile = "#{$confdir}/#{type}.pid"
139
155
  @start_time = File.exists?(pidfile) ? File.mtime(pidfile) : Time.now
140
156
 
@@ -149,8 +165,12 @@ class JVM
149
165
  not pid.nil?
150
166
  end
151
167
 
168
+ def enabled?
169
+ true
170
+ end
171
+
152
172
  def init
153
- reload_stale_files if running?
173
+ reload_stale_files if enabled? and running?
154
174
  start
155
175
  end
156
176
 
@@ -191,7 +211,7 @@ class JVM
191
211
  MAX_PORT = 2**16
192
212
 
193
213
  def start
194
- return if running?
214
+ return if not enabled? or running?
195
215
  @port = rand(MAX_PORT - MIN_PORT) + MIN_PORT
196
216
  log(:start, "starting #{type} jvm on port #{port}") if debug?
197
217
  @pid = daemon %{ java #{java_opts} clojure.main -e "(use '#{type})(start-server #{port})" /dev/null }
@@ -227,11 +247,12 @@ class JVM
227
247
 
228
248
  def files
229
249
  files = []
230
- classpath.split(':').uniq.each do |path|
250
+ classpath.split(PATH_SEP).uniq.each do |path|
231
251
  if path =~ /(.*)\/\*$/
232
252
  files.concat Dir["#{path}.jar"] << "#{$1}/." # include the directory itself so deletions will be detected
233
253
  else
234
254
  Find.find(path) do |f|
255
+ Find.prune if f == "#{$bakedir}/src/jvm"
235
256
  files << f if File.exists?(f) and not File.directory?(f)
236
257
  end
237
258
  end
@@ -241,6 +262,12 @@ class JVM
241
262
 
242
263
  private
243
264
 
265
+ def make_path(paths)
266
+ paths.flatten.compact.collect do |path|
267
+ path[0,1] == '/' ? path : "#{$bakedir}/#{path}"
268
+ end.join(PATH_SEP)
269
+ end
270
+
244
271
  def inspect(socket)
245
272
  while line = socket.gets
246
273
  puts line
@@ -334,6 +361,10 @@ class Bake < JVM
334
361
  [ENV['JAVA_OPTS'], config['project.java_opts'], super].compact.join(' ')
335
362
  end
336
363
 
364
+ def enabled?
365
+ Dir["lib/*.jar"].any?
366
+ end
367
+
337
368
  private
338
369
 
339
370
  HISTORY_NUM = 500
@@ -406,11 +437,12 @@ lib = "#{$cakedir}/lib"
406
437
  if File.exists?("#{$cakedir}/.gitignore")
407
438
  if Dir["#{lib}/*.jar"].empty?
408
439
  # In a new git checkout, need to fetch dependencies.
409
- version = IO.read("#{$cakedir}/project.clj").first.match(/defproject cake \"(.*)\"/)[1]
410
- get_cake(version, lib)
440
+ version = IO.read("#{$cakedir}/project.clj").split("\n").first.match(/defproject cake \"(.*)\"/)[1]
441
+ cakejar = get_cake(version, lib)
442
+ extract(cakejar, "bake-#{version}.jar", "#{lib}/dev")
411
443
  end
412
- cakepath = "#{$cakedir}/src:#{lib}/*:#{lib}/dev/*"
413
- bakepath = "#{$cakedir}/bake:#{lib}/dev/*"
444
+ cakepath = ["#{$cakedir}/src", "#{lib}/*:#{lib}/dev/*"].join(PATH_SEP)
445
+ bakepath = ["#{$cakedir}/bake", "#{lib}/dev/*"].join(PATH_SEP)
414
446
  else
415
447
  cakejar = "#{lib}/cake.jar"
416
448
  bakejar = "#{lib}/bake.jar"
@@ -423,19 +455,17 @@ else
423
455
  version = current_version
424
456
  dest = "~/.m2/repository/cake/cake/#{version}"
425
457
  cakepath = get_cake(version, dest)
426
- bakepath = extract(classpath, "bake-#{version}.jar")
458
+ bakepath = extract(cakepath, "bake-#{version}.jar")
427
459
  end
428
460
  end
429
461
 
430
- srcpath = "#{$bakedir}/src:#{$bakedir}/src/clj"
431
-
432
462
  cake = Cake.new(
433
- "#{cakepath}:#{srcpath}:#{$bakedir}/lib/dev/*",
434
- "#{$bakedir}/lib/dev/native"
463
+ [cakepath, "src", "src/clj", config['cake.classpath'], "lib/dev/*"],
464
+ [config['cake.library.path'], "lib/dev/native"]
435
465
  )
436
466
  bake = Bake.new(
437
- "#{bakepath}:#{srcpath}:#{$bakedir}/classes:#{$bakedir}/test:#{$bakedir}/lib/*:#{$bakedir}/lib/dev/*",
438
- "#{$bakedir}/lib/native:#{$bakedir}/lib/dev/native"
467
+ [bakepath, "src", "src/clj", "classes", "test", config['project.classpath'], "lib/*", "lib/dev/*"],
468
+ [config['project.library.path'], "lib/native", "lib/dev/native"]
439
469
  )
440
470
 
441
471
  if $command == :kill
Binary file
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: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 8
10
- version: 0.2.8
9
+ - 9
10
+ version: 0.2.9
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-25 00:00:00 -07:00
19
+ date: 2010-06-29 00:00:00 -07:00
20
20
  default_executable: cake
21
21
  dependencies: []
22
22