jettywrapper 1.0.4 → 1.1.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/History.txt ADDED
@@ -0,0 +1,2 @@
1
+ 1.1.0
2
+ Added quiet mode, so you don't see log messages on jetty startup.
@@ -1 +1 @@
1
- GEMVERSION = "1.0.4"
1
+ GEMVERSION = "1.1.0"
data/lib/jettywrapper.rb CHANGED
@@ -70,6 +70,7 @@ class Jettywrapper
70
70
  # @param [Symbol] :java_opts A list of options to pass to the jvm
71
71
  def configure(params = {})
72
72
  hydra_server = self.instance
73
+ hydra_server.reset_process!
73
74
  hydra_server.quiet = params[:quiet].nil? ? true : params[:quiet]
74
75
  if defined?(Rails.root)
75
76
  base_path = Rails.root
@@ -247,8 +248,7 @@ class Jettywrapper
247
248
  end
248
249
  end
249
250
  Dir.chdir(@jetty_home) do
250
- process = build_process
251
- @pid = process.pid
251
+ process.start
252
252
  end
253
253
  FileUtils.makedirs(pid_dir) unless File.directory?(pid_dir)
254
254
  begin
@@ -256,16 +256,29 @@ class Jettywrapper
256
256
  rescue Errno::ENOENT, Errno::EACCES
257
257
  f = File.new(File.join(@base_path,'tmp',pid_file),"w")
258
258
  end
259
- f.puts "#{@pid}"
259
+ f.puts "#{process.pid}"
260
260
  f.close
261
- logger.debug "Wrote pid file to #{pid_path} with value #{@pid}"
261
+ logger.debug "Wrote pid file to #{pid_path} with value #{process.pid}"
262
262
  end
263
263
 
264
- def build_process
265
- process = ChildProcess.build(jetty_command)
266
- process.io.inherit!
267
- process.detach = true
268
- process.start
264
+ def process
265
+ @process ||= begin
266
+ process = ChildProcess.build(jetty_command)
267
+ if self.quiet
268
+ process.io.stderr = File.open("jettywrapper.log", "w+")
269
+ process.io.stdout = process.io.stderr
270
+ logger.warn "Logging jettywrapper stdout to #{File.expand_path(process.io.stderr.path)}"
271
+ else
272
+ process.io.inherit!
273
+ end
274
+ process.detach = true
275
+
276
+ process
277
+ end
278
+ end
279
+
280
+ def reset_process!
281
+ @process = nil
269
282
  end
270
283
  # Instance stop method. Must be called on Jettywrapper.instance
271
284
  # You're probably better off using Jettywrapper.stop(:jetty_home => "/path/to/jetty")
@@ -279,6 +292,7 @@ class Jettywrapper
279
292
  process = ChildProcess.new
280
293
  process.instance_variable_set(:@pid, pid)
281
294
  process.instance_variable_set(:@started, true)
295
+
282
296
  process.stop
283
297
  begin
284
298
  File.delete(pid_path)
@@ -76,9 +76,7 @@ module Hydra
76
76
  lambda{ ts.start }.should raise_exception
77
77
  ts.stop
78
78
  end
79
-
80
-
79
+
81
80
  end
82
-
83
81
  end
84
82
  end
@@ -73,7 +73,7 @@ module Hydra
73
73
  :jetty_home => '/tmp'
74
74
  }
75
75
  ts = Jettywrapper.configure(jetty_params)
76
- Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>5454))
76
+ Jettywrapper.any_instance.stubs(:process).returns(stub('proc', :start => nil, :pid=>5454))
77
77
  ts.stop
78
78
  ts.start
79
79
  ts.pid.should eql(5454)
@@ -86,7 +86,7 @@ module Hydra
86
86
  }
87
87
  ts = Jettywrapper.configure(jetty_params)
88
88
  ts.stop
89
- Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>2323))
89
+ Jettywrapper.any_instance.stubs(:process).returns(stub('proc', :start => nil, :pid=>2323))
90
90
  swp = Jettywrapper.start(jetty_params)
91
91
  swp.pid.should eql(2323)
92
92
  swp.pid_file.should eql("_tmp.pid")
@@ -100,7 +100,7 @@ module Hydra
100
100
  # return true if it's running, otherwise return false
101
101
  it "can get the status for a given jetty instance" do
102
102
  # Don't actually start jetty, just fake it
103
- Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>12345))
103
+ Jettywrapper.any_instance.stubs(:process).returns(stub('proc', :start => nil, :pid=>12345))
104
104
 
105
105
  jetty_params = {
106
106
  :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty")
@@ -114,7 +114,7 @@ module Hydra
114
114
 
115
115
  it "can get the pid for a given jetty instance" do
116
116
  # Don't actually start jetty, just fake it
117
- Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>54321))
117
+ Jettywrapper.any_instance.stubs(:process).returns(stub('proc', :start => nil, :pid=>54321))
118
118
  jetty_params = {
119
119
  :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty")
120
120
  }
@@ -129,7 +129,7 @@ module Hydra
129
129
  jetty_params = {
130
130
  :jetty_home => '/tmp', :jetty_port => 8777
131
131
  }
132
- Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>2323))
132
+ Jettywrapper.any_instance.stubs(:process).returns(stub('proc', :start => nil, :pid=>2323))
133
133
  swp = Jettywrapper.start(jetty_params)
134
134
  (File.file? swp.pid_path).should eql(true)
135
135
 
@@ -152,7 +152,7 @@ module Hydra
152
152
  :jetty_home => '/tmp'
153
153
  }
154
154
  ts = Jettywrapper.configure(jetty_params)
155
- Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>2222))
155
+ Jettywrapper.any_instance.stubs(:process).returns(stub('proc', :start => nil, :pid=>2222))
156
156
  ts.stop
157
157
  ts.pid_file?.should eql(false)
158
158
  ts.start
@@ -206,5 +206,21 @@ module Hydra
206
206
  end
207
207
 
208
208
  end # end of wrapping context
209
+
210
+ context "quiet mode", :quiet => true do
211
+ it "inherits the current stderr/stdout in 'loud' mode" do
212
+ ts = Jettywrapper.configure(@jetty_params.merge(:quiet => false))
213
+ process = ts.process
214
+ process.io.stderr.should == $stderr
215
+ process.io.stdout.should == $stdout
216
+ end
217
+
218
+ it "redirect stderr/stdout to a log file in quiet mode" do
219
+ ts = Jettywrapper.configure(@jetty_params.merge(:quiet => true))
220
+ process = ts.process
221
+ process.io.stderr.should_not == $stderr
222
+ process.io.stdout.should_not == $stdout
223
+ end
224
+ end
209
225
  end
210
226
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jettywrapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 4
10
- version: 1.0.4
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bess Sadler
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-11 00:00:00 -06:00
18
+ date: 2011-11-22 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -177,6 +177,7 @@ files:
177
177
  - .gitmodules
178
178
  - .rvmrc
179
179
  - Gemfile
180
+ - History.txt
180
181
  - README.textile
181
182
  - Rakefile
182
183
  - TODO.txt