cake 0.4.11 → 0.4.13

Sign up to get free protection for your applications and to get access to all the features.
data/bin/cake CHANGED
@@ -3,7 +3,6 @@
3
3
  require 'find'
4
4
  require 'open-uri'
5
5
  require 'socket'
6
- require 'timeout'
7
6
  require 'fileutils'
8
7
  require 'io/wait'
9
8
  require 'pp'
@@ -231,47 +230,60 @@ rescue NotImplementedError, Errno::EINVAL
231
230
  file
232
231
  end
233
232
 
234
- def download(url, path)
235
- log(:deps, "downloading #{url}")
236
- open(url) do |remote|
237
- open(path, "wb") do |local|
238
- while (buf = remote.read(8192))
239
- local.write buf
233
+ def download(url, dir, opts = {})
234
+ file = File.basename(url)
235
+ path = "#{dir}/#{file}"
236
+
237
+ if opts[:force] or not File.exists?(path)
238
+ FileUtils.makedirs(dir)
239
+ open(url, progress_bar(url)) do |remote|
240
+ open(path, "wb") do |local|
241
+ while (buf = remote.read(8192)); local.write buf; end
240
242
  end
241
- end
243
+ end; puts
244
+ end
245
+ return path unless opts[:dest]
246
+
247
+ dir = File.expand_path(opts[:dest])
248
+ dest = "#{dir}/#{file}"
249
+ if opts[:force] or not File.exists?(dest)
250
+ FileUtils.makedirs(dir)
251
+ FileUtils.copy(path, dest)
242
252
  end
253
+ dest
254
+ rescue OpenURI::HTTPError
255
+ raise "resource not found: #{url}"
243
256
  end
244
257
 
245
- def get_cake(version, dest = nil, opts = {})
246
- jar = "cake-#{version}.jar"
247
- repo = File.expand_path("~/.m2/repository/cake/cake/#{version}")
248
- path = "#{repo}/#{jar}"
258
+ def get_cake(opts = {})
259
+ log(:deps, "Fetching cake dependencies...") unless @got_cake; @got_cake = true
260
+ version = cake_version(opts[:version] || :current)
261
+ download("#{$github}/jars/cake-#{version}.jar", "#{$m2}/cake/cake/#{snapshot(version)}", opts)
262
+ end
249
263
 
250
- if not File.exists?(path)
251
- url = "#{$repo}/#{jar}"
252
- log(:deps, "fetching cake libraries. this may take a moment...") unless @logged; @logged = true
253
- FileUtils.makedirs(repo)
254
- download(url, path)
255
- end
256
- return path unless dest
264
+ def get_clojure(opts = {})
265
+ version = opts[:version] || "1.2.0"
266
+ repo = opts[:repo] || "http://build.clojure.org/releases"
267
+ path = "org/clojure/clojure/#{version}"
268
+ download("#{repo}/#{path}/clojure-#{version}.jar", "#{$m2}/#{path}", opts)
269
+ end
257
270
 
258
- dest = File.expand_path(dest)
259
- FileUtils.makedirs(dest)
260
- FileUtils.copy(path, dest)
261
- "#{dest}/#{jar}"
262
- rescue OpenURI::HTTPError => e
263
- raise if opts[:raise]
264
- log(:deps, "unable to find cake version #{version} on clojars.")
265
- log(:deps, "please check http://github.com/ninjudd/cake for latest install instructions.")
266
- exit
271
+ def progress_bar(label, ch = '=', bg = '', width = 77, out = $stdout, progress = 0, total = nil)
272
+ { :progress_proc => lambda {|c| progress += ((width * c/total).to_i - progress).times { out.print_flush(ch) }},
273
+ :content_length_proc => lambda {|t| printf("%s\n[%#{width}s]\r[", label, bg); total = t}}
267
274
  end
268
275
 
269
- def current_version
270
- version = open("#{$repo}/version").gets
276
+ def cake_version(version)
277
+ return version unless version.kind_of?(Symbol)
278
+ version = open("#{$github}/#{version}").gets
271
279
  log(:deps, "most recent standalone version is #{version}") if debug?
272
280
  version
273
281
  end
274
282
 
283
+ def snapshot(version)
284
+ version.gsub(/\d{8}\.\d{6}$/, "SNAPSHOT")
285
+ end
286
+
275
287
  def extract(jar, file, dest = File.dirname(jar))
276
288
  if not File.exists?("#{dest}/#{file}")
277
289
  log(:deps, "extracting #{file} from #{jar}") if verbose?
@@ -299,7 +311,7 @@ class JVM
299
311
  @type = self.class.name.downcase
300
312
  @classpath = make_path(classpath)
301
313
  @libpath = make_path(libpath)
302
- @pidfile = "#{$confdir}/#{type}.pid"
314
+ @pidfile = ".cake/#{type}.pid"
303
315
  @load_time = File.exists?(pidfile) ? File.mtime(pidfile) : Time.now
304
316
  refresh
305
317
  end
@@ -323,10 +335,7 @@ class JVM
323
335
  Process.kill(0, @pid) # make sure pid is valid
324
336
  TCPSocket.new("localhost", @port).close if @port # make sure jvm is running on port
325
337
 
326
- if @version != $version
327
- kill
328
- reset!
329
- end
338
+ kill if @version != $version
330
339
  rescue Errno::ENOENT, Errno::ESRCH, Errno::ECONNREFUSED, Errno::EBADF, Process::Error => e
331
340
  if e.kind_of?(Errno::ECONNREFUSED)
332
341
  log(:start, "defunct #{type} jvm") if debug?
@@ -395,10 +404,10 @@ class JVM
395
404
  def start
396
405
  return unless enabled?
397
406
  if running?
398
- log(:start, "#{type} jvm already running") if $command == :start
407
+ log(:start, "#{type} jvm already running") if $command == :start and not $opts[:silent]
399
408
  return
400
409
  else
401
- log(:start, "starting #{type} jvm") if verbose? or $command == :start
410
+ log(:start, "starting #{type} jvm") if verbose? or ($command == :start and not $opts[:silent])
402
411
  @port = rand(MAX_PORT - MIN_PORT) + MIN_PORT
403
412
  @pid = daemon %{java #{vm_opts} -Dcake.project="#{$bakedir}" #{java_opts} clojure.main -e "(use '#{type}.core) (start-server #{port})"}
404
413
  File.open(pidfile, 'w') {|f| f.write("#{pid}\n#{port}\n#{$version}\n") }
@@ -428,11 +437,14 @@ class JVM
428
437
  end
429
438
 
430
439
  def kill
431
- return unless pid
432
- signal = $opts[:"9"] ? KILL : TERM
433
- log(:kill, "sending #{signal} signal to #{type} jvm") if debug?
434
- Process.kill(signal, pid)
435
- reset!
440
+ if pid
441
+ signal = $opts[:"9"] ? KILL : TERM
442
+ log(:kill, "sending #{signal} signal to #{type} jvm") if debug?
443
+ Process.kill(signal, pid)
444
+ reset!
445
+ else
446
+ log(:kill, "#{type} jvm not running") if $command == :kill
447
+ end
436
448
  end
437
449
 
438
450
  def files
@@ -475,16 +487,16 @@ class JVM
475
487
  save_history
476
488
  end
477
489
 
478
- def run(file = $script)
490
+ def run
479
491
  with_socket do |socket|
480
- log(:run, "running file #{file}") if debug?
481
- socket.write(":run #{$vars} #{file.inspect}")
492
+ log(:run, "running file #{$script}") if debug?
493
+ socket.write(":run #{$vars} #{$script.inspect}")
482
494
  socket.duplex($stdin, $stdout)
483
495
  end
484
496
  end
485
497
 
486
- def eval(forms = $opts[:eval])
487
- forms = forms.collect do |form|
498
+ def eval
499
+ forms = $opts[:eval].collect do |form|
488
500
  form == '-' ? $stdin.gets(nil) : form
489
501
  end.join(' ')
490
502
  forms = "(doall (map println [#{forms}]))" unless $opts[:q]
@@ -496,7 +508,8 @@ class JVM
496
508
  end
497
509
 
498
510
  EOL = "EOL__#{rand}"
499
- def filter(forms = $opts[:filter])
511
+ def filter
512
+ forms = $opts[:filter]
500
513
  with_socket do |socket|
501
514
  socket.write %(:filter #{$vars} "#{EOL}")
502
515
  while line = $stdin.gets
@@ -646,6 +659,7 @@ class Cake < JVM
646
659
  end
647
660
 
648
661
  def java_opts
662
+ # bootclasspath = %{-Xbootclasspath/a:"#{$clojure}"}
649
663
  [ENV['CAKE_JAVA_OPTS'], $config['cake.java_opts'], super].compact.join(' ')
650
664
  end
651
665
 
@@ -675,16 +689,16 @@ class Bake < JVM
675
689
  end
676
690
 
677
691
  def enabled?
678
- Dir["lib/*.jar"].any?
692
+ Dir['lib/*.jar'].any?
679
693
  end
680
694
  end
681
695
 
682
- #==================================
683
-
684
- FileUtils.makedirs("#{$home}/.cake")
685
- project_clj = "#{$home}/.cake/project.clj"
686
- File.open(project_clj, 'w') do |file|
687
- file.write <<END
696
+ def initialize_cake_dirs
697
+ FileUtils.makedirs("#{$bakedir}/.cake")
698
+ FileUtils.makedirs("#{$home}/.cake")
699
+ project_clj = "#{$home}/.cake/project.clj"
700
+ File.open(project_clj, 'w') do |file|
701
+ file.write <<END
688
702
  (defproject global "0.0.0"
689
703
  :description "Don't rename this project, but you can change the version if you want."
690
704
  :dependencies [[clojure "1.2.0"]
@@ -698,21 +712,24 @@ File.open(project_clj, 'w') do |file|
698
712
  ;; 4. Configuration options in ~/.cake/config are used in all projects.
699
713
  ;;--------------------
700
714
  END
701
- end unless File.exists?(project_clj)
715
+ end unless File.exists?(project_clj)
716
+ end
717
+
718
+ #==================================
702
719
 
703
720
  parse_opts!
704
721
  $script = File.expand_path($opts[:run].first) if $opts[:run]
705
722
  $pwd = Dir.getwd
706
723
  $bakedir = project_dir($pwd)
707
724
  $cakedir = File.dirname(File.dirname(readlink(__FILE__)))
708
- $repo = "http://github.com/ninjudd/cake-standalone/raw/master"
709
- $confdir = ".cake"
725
+ $github = "http://github.com/ninjudd/cake-standalone/raw/master"
726
+ $m2 = "#{$home}/.m2/repository"
710
727
  $config = Configuration.new("#{$home}/.cake/config", ".cake/config")
711
- $timeout = ($config['connect.timeout'] || 20).to_i
712
728
  $vars = {:env => ENV.to_hash, :pwd => $pwd, :args => ARGV, :opts => $opts, :script => $0}.to_clj
729
+ $timeout = ($config['connect.timeout'] || 20).to_i
713
730
 
714
731
  Dir.chdir($bakedir)
715
- FileUtils.makedirs($confdir)
732
+ initialize_cake_dirs
716
733
 
717
734
  if debug?
718
735
  puts "config: #{$config.inspect}"
@@ -733,21 +750,18 @@ if File.exists?("#{$cakedir}/.gitignore") and File.exists?(project)
733
750
  $version = IO.read(project).split("\n").first.match(/defproject cake \"(.*)\"/)[1]
734
751
  log(:deps, "project.clj version is #{$version}") if debug?
735
752
 
736
- FileUtils.remove_dir(lib, true) if newer?(project, lib)
753
+ # Force new cake libs if cake's project.clj has changed.
754
+ FileUtils.remove_dir(lib, true) if newer?(project, lib) and not $config['cake.disable-auto-deps']
755
+
737
756
  if Dir["#{lib}/*.jar"].empty? or Dir["#{lib}/dev/*.jar"].empty?
738
- # In a new git checkout, need to fetch dependencies.
739
- begin
740
- version = $version
741
- cakejar = get_cake(version, lib, :raise => true)
742
- rescue OpenURI::HTTPError => e
743
- version = current_version
744
- cakejar = get_cake(version, lib)
745
- end
746
- extract(cakejar, "bake-#{version}.jar", "#{lib}/dev")
757
+ # In a new git checkout, need to fetch dependencies.
758
+ cakejar = get_cake(:version => $version, :dest => lib) rescue get_cake(:version => :current, :dest => lib)
759
+ extract(cakejar, "bake.jar", "#{lib}/dev")
747
760
  end
761
+ $clojure = get_clojure(:dest => lib)
748
762
 
749
- cakepath = ["#{$cakedir}/src", "#{lib}/*:#{lib}/dev/*"].join(PATH_SEP)
750
- bakepath = ["#{$cakedir}/bake", "#{lib}/dev/*"].join(PATH_SEP)
763
+ cakepath = ["#{$cakedir}/src", "#{lib}/*:#{lib}/dev/*"]
764
+ bakepath = ["#{$cakedir}/bake", "#{lib}/dev/*"]
751
765
  else
752
766
  cakejar = "#{lib}/cake.jar"
753
767
  bakejar = "#{lib}/bake.jar"
@@ -756,23 +770,32 @@ else
756
770
  log(:cake, "running from gem") if verbose?
757
771
  if $command == :upgrade
758
772
  log(:upgrade, "checking for updates to cake gem")
759
- system('gem update cake')
773
+ system('gem update cake --no-ri --no-rdoc')
760
774
  end
761
775
 
762
776
  $version = File.basename(File.dirname(lib)).split('-')[1]
763
- cakepath = cakejar
777
+ $clojure = "#{lib}/clojure.jar"
778
+
779
+ cakepath = [cakejar, $clojure]
764
780
  bakepath = bakejar
765
781
  else
766
782
  # Standalone script.
767
783
  log(:cake, "running from standalone script") if verbose?
768
- download("http://github.com/ninjudd/cake/raw/master/bin/cake", __FILE__) if $command == :upgrade
784
+ download("#{$github}/cake", __FILE__, :force => true) if $command == :upgrade
785
+
786
+ $version = cake_version(:stable)
787
+ cakejar = get_cake(:version => $version)
788
+ $clojure = get_clojure
769
789
 
770
- $version = current_version
771
- cakepath = get_cake($version)
772
- bakepath = extract(cakepath, "bake-#{$version}.jar")
790
+ cakepath = [cakejar, $clojure]
791
+ bakepath = extract(cakejar, "bake.jar")
773
792
  end
774
793
  end
775
- exec("cake deps") if $command == :upgrade
794
+
795
+ if $command == :upgrade
796
+ system($0, "start", "--silent")
797
+ exec($0, "--version")
798
+ end
776
799
 
777
800
  cake = Cake.new(
778
801
  [cakepath, "src", "src/clj", $config['cake.claspath'], "lib/dev/*", "#{$home}/.cake/lib/dev/*"],
@@ -787,11 +810,13 @@ if $command == :default and $opts[:version]
787
810
  puts "cake #{$version}"
788
811
  exit
789
812
  elsif $command == :kill
790
- if $opts[:all]
791
- ps.each do |line|
813
+ if $opts[:all] or $opts[:kill] == ['all']
814
+ puts "'cake kill --all' is deprecated, in the future use 'cake kill all' instead" if $opts[:all]
815
+ num = ps.each do |line|
792
816
  pid = line.split(' ').first.to_i
793
817
  Process.kill($opts[:"9"] ? KILL : TERM, pid)
794
- end
818
+ end.size
819
+ puts "No matching processes belonging to you were found" if num == 0
795
820
  else
796
821
  cake.kill
797
822
  bake.kill
@@ -9,6 +9,6 @@ Gem::Specification.new do |s|
9
9
  s.description = "Save your fork, there's cake!"
10
10
  s.email = 'code@justinbalthrop.com'
11
11
  s.executables = ['cake']
12
- s.files = ['cake.gemspec', 'bin/cake', 'lib/cake.jar', 'lib/bake.jar']
12
+ s.files = ['cake.gemspec', 'bin/cake', 'lib/cake.jar', 'lib/bake.jar', 'lib/clojure.jar']
13
13
  s.homepage = 'http://github.com/ninjudd/cake'
14
14
  end
Binary file
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: 25
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 11
10
- version: 0.4.11
9
+ - 13
10
+ version: 0.4.13
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-30 00:00:00 -07:00
19
+ date: 2010-09-09 00:00:00 -07:00
20
20
  default_executable: cake
21
21
  dependencies: []
22
22
 
@@ -33,6 +33,7 @@ files:
33
33
  - bin/cake
34
34
  - lib/cake.jar
35
35
  - lib/bake.jar
36
+ - lib/clojure.jar
36
37
  has_rdoc: true
37
38
  homepage: http://github.com/ninjudd/cake
38
39
  licenses: []