guard-spork 1.1.0 → 1.2.0

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/README.md CHANGED
@@ -100,6 +100,7 @@ Available options:
100
100
  :cucumber => false
101
101
  :rspec => false
102
102
  :test_unit => false
103
+ :minitest => false
103
104
  :bundler => false # Don't use "bundle exec"
104
105
  :test_unit_port => 1233 # Default: 8988
105
106
  :rspec_port => 1234 # Default: 8989
@@ -1,5 +1,8 @@
1
1
  require 'guard'
2
2
  require 'guard/guard'
3
+ require 'sys/proctable'
4
+ require 'childprocess'
5
+ require 'rinda/ring'
3
6
 
4
7
  module Guard
5
8
  class Spork < Guard
@@ -62,7 +62,17 @@ module Guard
62
62
  end
63
63
 
64
64
  def ps_spork_pids
65
- `ps aux | awk '/spork/&&!/awk/{print $2;}'`.split("\n").map { |pid| pid.to_i }
65
+ unless SporkInstance.windows?
66
+ `ps aux | awk '/spork/&&!/awk/{print $2;}'`.split("\n").map { |pid| pid.to_i }
67
+ else
68
+ Sys::ProcTable.ps.reduce([]) do |spork_pids, process|
69
+ spork_process = process.cmdline =~ /spork/ ||
70
+ process.cmdline =~ /ring_server/ ||
71
+ process.cmdline =~ /magazine_slave_provider/
72
+ spork_pids << process.pid if spork_process
73
+ spork_pids
74
+ end
75
+ end
66
76
  end
67
77
 
68
78
  def find_instances(type = nil)
@@ -1,7 +1,7 @@
1
1
  module Guard
2
2
  class Spork
3
3
  class SporkInstance
4
- attr_reader :type, :env, :port, :options, :pid
4
+ attr_reader :type, :env, :port, :options, :pid, :process
5
5
 
6
6
  def initialize(type, port, env, options)
7
7
  @type = type
@@ -26,24 +26,39 @@ module Guard
26
26
  end
27
27
 
28
28
  def start
29
- @pid = fork do
30
- env_exec env, command
29
+ cmd = [command]
30
+
31
+ if self.class.windows?
32
+ cmd = ["cmd", "/C"] + cmd
31
33
  end
34
+
35
+ @process = ChildProcess.build *cmd
36
+ @process.environment.merge!(env)
37
+ @process.io.inherit!
38
+ @process.start
39
+ @pid = @process.pid
32
40
  end
33
41
 
34
42
  def stop
35
- ::Process.kill('TERM', pid)
43
+ unless self.class.windows?
44
+ process.stop
45
+ else
46
+ kill_all_child_processes
47
+ end
36
48
  end
37
49
 
38
50
  def alive?
39
- return false unless pid
40
- ::Process.waitpid(pid, ::Process::WNOHANG).nil?
51
+ pid && process.alive?
41
52
  end
42
53
 
43
54
  def running?
44
- return false unless pid
55
+ return false unless alive?
45
56
  TCPSocket.new('localhost', port).close
46
- true
57
+ if self.class.windows?
58
+ running_on_windows?
59
+ else
60
+ true
61
+ end
47
62
  rescue Errno::ECONNREFUSED
48
63
  false
49
64
  end
@@ -67,13 +82,8 @@ module Guard
67
82
  parts.join(" ")
68
83
  end
69
84
 
70
- def env_exec(environment, command)
71
- if RUBY_VERSION > "1.9"
72
- exec environment, command
73
- else
74
- environment.each_pair { |key, value| ENV[key] = value }
75
- exec command
76
- end
85
+ def self.windows?
86
+ RUBY_PLATFORM =~ /mswin|msys|mingw/
77
87
  end
78
88
 
79
89
  private
@@ -86,6 +96,31 @@ module Guard
86
96
  options[:foreman]
87
97
  end
88
98
 
99
+ def kill_all_child_processes
100
+ all_pids_for(pid).each do |pid|
101
+ Process.kill 9, pid
102
+ end
103
+ end
104
+
105
+ def all_pids_for(parent_pid)
106
+ pids = [parent_pid]
107
+ Sys::ProcTable.ps do |process|
108
+ pids += all_pids_for(process.pid) if process.ppid == parent_pid
109
+ end
110
+ pids
111
+ end
112
+
113
+ def running_on_windows?
114
+ DRb.start_service
115
+ # make sure that ringfinger is not taken from cache, because it won't
116
+ # work after guard-spork has been restarted
117
+ Rinda::RingFinger.class_variable_set :@@finger, nil
118
+ ts = Rinda::RingFinger.primary
119
+ ts.read_all([:name, :MagazineSlave, nil, nil]).size > 0
120
+ rescue DRb::DRbConnError
121
+ false
122
+ end
123
+
89
124
  end
90
125
  end
91
126
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module SporkVersion
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-spork
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-21 00:00:00.000000000 Z
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
@@ -43,6 +43,38 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.8.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: childprocess
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sys-proctable
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
46
78
  - !ruby/object:Gem::Dependency
47
79
  name: bundler
48
80
  requirement: !ruby/object:Gem::Requirement