jettywrapper 1.8.0 → 1.8.3

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.
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ file = File.expand_path("../../Gemfile", __FILE__)
4
+
5
+ if File.exists?(file)
6
+ puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
7
+ instance_eval File.read(file)
8
+ end
9
+
10
+ gem 'activesupport', '~> 4.1.1'
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ file = File.expand_path("../../Gemfile", __FILE__)
4
+
5
+ if File.exists?(file)
6
+ puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
7
+ instance_eval File.read(file)
8
+ end
9
+
10
+ gem 'activesupport', '~> 4.2.0.beta2'
data/jettywrapper.gemspec CHANGED
@@ -14,8 +14,8 @@ Gem::Specification.new do |s|
14
14
  s.description = %q{Spin up a jetty instance (e.g., the one at https://github.com/projecthydra/hydra-jetty) and wrap test in it. This lets us run tests against a real copy of solr and fedora.}
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
17
- # s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
17
  s.require_paths = ["lib"]
18
+ s.license = 'APACHE2'
19
19
 
20
20
  s.required_rubygems_version = ">= 1.3.6"
21
21
 
@@ -1,3 +1,3 @@
1
1
  class Jettywrapper
2
- VERSION = "1.8.0"
2
+ VERSION = "1.8.3"
3
3
  end
data/lib/jettywrapper.rb CHANGED
@@ -4,21 +4,23 @@ require 'shellwords'
4
4
  require 'socket'
5
5
  require 'timeout'
6
6
  require 'childprocess'
7
+ require 'active_support/benchmarkable'
7
8
  require 'active_support/core_ext/hash'
8
9
  require 'erb'
9
10
  require 'yaml'
11
+ require 'logger'
10
12
 
11
13
  Dir[File.expand_path(File.join(File.dirname(__FILE__),"tasks/*.rake"))].each { |ext| load ext } if defined?(Rake)
12
14
 
13
15
 
14
16
  # Jettywrapper is a Singleton class, so you can only create one jetty instance at a time.
15
17
  class Jettywrapper
16
-
18
+
17
19
  include Singleton
18
20
  include ActiveSupport::Benchmarkable
19
-
20
-
21
- attr_accessor :jetty_home # Jetty's home directory
21
+
22
+
23
+ attr_accessor :jetty_home # Jetty's home directory
22
24
  attr_accessor :port # Jetty's port. Default is 8888. Note that attribute is named port, but params passed in expect :jetty_port
23
25
  attr_accessor :startup_wait # How many seconds to wait for jetty to spin up. Default is 5.
24
26
  attr_accessor :quiet # true (default) to reduce Jetty's output
@@ -26,14 +28,14 @@ class Jettywrapper
26
28
  attr_accessor :base_path # The root of the application. Used for determining where log files and PID files should go.
27
29
  attr_accessor :java_opts # Options to pass to java (ex. ["-Xmx512mb", "-Xms128mb"])
28
30
  attr_accessor :jetty_opts # Options to pass to jetty (ex. ["etc/my_jetty.xml", "etc/other.xml"] as in http://wiki.eclipse.org/Jetty/Reference/jetty.xml_usage
29
-
31
+
30
32
  # configure the singleton with some defaults
31
33
  def initialize(params = {})
32
34
  self.base_path = self.class.app_root
33
35
  end
34
36
 
35
-
36
- # Methods inside of the class << self block can be called directly on Jettywrapper, as class methods.
37
+
38
+ # Methods inside of the class << self block can be called directly on Jettywrapper, as class methods.
37
39
  # Methods outside the class << self block must be called on Jettywrapper.instance, as instance methods.
38
40
  class << self
39
41
 
@@ -67,10 +69,10 @@ class Jettywrapper
67
69
  system "curl -L #{self.url} -o #{zip_file}"
68
70
  abort "Unable to download jetty from #{self.url}" unless $?.success?
69
71
  end
70
-
72
+
71
73
  def unzip
72
74
  download unless File.exists? zip_file
73
- logger.info "Unpacking jetty..."
75
+ logger.info "Unpacking #{zip_file}..."
74
76
  tmp_save_dir = File.join tmp_dir, 'jetty_generator'
75
77
  system "unzip -d #{tmp_save_dir} -qo #{zip_file}"
76
78
  abort "Unable to unzip #{zip_file} into tmp_save_dir/" unless $?.success?
@@ -86,8 +88,8 @@ class Jettywrapper
86
88
 
87
89
  def expanded_zip_dir(tmp_save_dir)
88
90
  # This old way is more specific, but won't work for blacklight-jetty
89
- #expanded_dir = Dir[File.join(tmp_save_dir, "hydra-jetty-*")].first
90
- Dir[File.join(tmp_save_dir, "*")].first
91
+ #expanded_dir = Dir[File.join(tmp_save_dir, "hydra-jetty-*")].first
92
+ Dir[File.join(tmp_save_dir, "*")].first
91
93
  end
92
94
 
93
95
  def clean
@@ -111,25 +113,25 @@ class Jettywrapper
111
113
 
112
114
  def env
113
115
  @env ||= begin
114
- case
115
- when ENV['JETTYWRAPPER_ENV']
116
+ case
117
+ when ENV['JETTYWRAPPER_ENV']
116
118
  ENV['JETTYWRAPPER_ENV']
117
119
  when defined?(Rails) && Rails.respond_to?(:env)
118
120
  Rails.env
119
- when ENV['RAILS_ENV']
120
- ENV['RAILS_ENV']
121
- when ENV['environment']
122
- ENV['environment']
121
+ when ENV['RAILS_ENV']
122
+ ENV['RAILS_ENV']
123
+ when ENV['environment']
124
+ ENV['environment']
123
125
  else
124
126
  default_environment
125
127
  end
126
128
  end
127
129
  end
128
-
130
+
129
131
  def default_environment
130
132
  'development'
131
133
  end
132
-
134
+
133
135
  def load_config(config_name = env)
134
136
  @env = config_name
135
137
  jetty_file = "#{app_root}/config/jetty.yml"
@@ -158,15 +160,15 @@ class Jettywrapper
158
160
  config = jetty_yml.with_indifferent_access
159
161
  config[config_name] || config['default'.freeze]
160
162
  end
161
-
162
163
 
163
- # Set the jetty parameters. It accepts a Hash of symbols.
164
+
165
+ # Set the jetty parameters. It accepts a Hash of symbols.
164
166
  # @param [Hash<Symbol>] params
165
167
  # :jetty_home Required. Jetty's home direcotry
166
168
  # :jetty_port Jetty's port. Default is 8888. Note that attribute is named port, but params passed in expect :jetty_port
167
169
  # :startup_wait How many seconds to wait for jetty to spin up. Default is 5. If jetty doesn't finish spinning up, tests can fail because they can't reach jetty.
168
170
  # :solr_home Solr's home directory. Default is jetty_home/solr
169
- # :quiet Keep True(default) to reduce jetty's output
171
+ # :quiet Keep True(default) to reduce jetty's output
170
172
  # :java_opts options to pass to the jvm (ex. ["-Xmx512mb", "-Xms128mb"])
171
173
  # :jetty_opts options to pass to jetty (ex. ["etc/my_jetty.xml", "etc/other.xml"] as in http://wiki.eclipse.org/Jetty/Reference/jetty.xml_usage
172
174
  def configure(params = {})
@@ -182,25 +184,25 @@ class Jettywrapper
182
184
  jetty_server.jetty_opts = params[:jetty_opts] || []
183
185
  return jetty_server
184
186
  end
185
-
186
-
187
+
188
+
187
189
  # Wrap the tests. Startup jetty, yield to the test task, capture any errors, shutdown
188
- # jetty, and return the error.
190
+ # jetty, and return the error.
189
191
  # @example Using this method in a rake task
190
192
  # require 'jettywrapper'
191
193
  # desc "Spin up jetty and run tests against it"
192
194
  # task :newtest do
193
- # jetty_params = {
194
- # :jetty_home => "/path/to/jetty",
195
- # :quiet => false,
196
- # :jetty_port => 8983,
195
+ # jetty_params = {
196
+ # :jetty_home => "/path/to/jetty",
197
+ # :quiet => false,
198
+ # :jetty_port => 8983,
197
199
  # :startup_wait => 30,
198
200
  # :jetty_opts => "/etc/jetty.xml"
199
201
  # }
200
- # error = Jettywrapper.wrap(jetty_params) do
201
- # Rake::Task["rake:spec"].invoke
202
- # Rake::Task["rake:cucumber"].invoke
203
- # end
202
+ # error = Jettywrapper.wrap(jetty_params) do
203
+ # Rake::Task["rake:spec"].invoke
204
+ # Rake::Task["rake:cucumber"].invoke
205
+ # end
204
206
  # raise "test failures: #{error}" if error
205
207
  # end
206
208
  def wrap(params)
@@ -222,42 +224,42 @@ class Jettywrapper
222
224
 
223
225
  return error
224
226
  end
225
-
227
+
226
228
  # Convenience method for configuring and starting jetty with one command
227
229
  # @param [Hash] params: The configuration to use for starting jetty
228
- # @example
230
+ # @example
229
231
  # Jettywrapper.start(:jetty_home => '/path/to/jetty', :jetty_port => '8983')
230
232
  def start(params)
231
233
  Jettywrapper.configure(params)
232
234
  Jettywrapper.instance.start
233
235
  return Jettywrapper.instance
234
236
  end
235
-
237
+
236
238
  # Convenience method for configuring and starting jetty with one command. Note
237
- # that for stopping, only the :jetty_home value is required (including other values won't
238
- # hurt anything, though).
239
+ # that for stopping, only the :jetty_home value is required (including other values won't
240
+ # hurt anything, though).
239
241
  # @param [Hash] params: The jetty_home to use for stopping jetty
240
242
  # @return [Jettywrapper.instance]
241
- # @example
243
+ # @example
242
244
  # Jettywrapper.stop_with_params(:jetty_home => '/path/to/jetty')
243
245
  def stop(params)
244
246
  Jettywrapper.configure(params)
245
247
  Jettywrapper.instance.stop
246
248
  return Jettywrapper.instance
247
249
  end
248
-
250
+
249
251
  # Determine whether the jetty at the given jetty_home is running
250
252
  # @param [Hash] params: :jetty_home is required. Which jetty do you want to check the status of?
251
253
  # @return [Boolean]
252
254
  # @example
253
255
  # Jettywrapper.is_jetty_running?(:jetty_home => '/path/to/jetty')
254
- def is_jetty_running?(params)
256
+ def is_jetty_running?(params)
255
257
  Jettywrapper.configure(params)
256
258
  pid = Jettywrapper.instance.pid
257
259
  return false unless pid
258
260
  true
259
261
  end
260
-
262
+
261
263
  # Return the pid of the specified jetty, or return nil if it isn't running
262
264
  # @param [Hash] params: :jetty_home is required.
263
265
  # @return [Fixnum] or [nil]
@@ -269,7 +271,7 @@ class Jettywrapper
269
271
  return nil unless pid
270
272
  pid
271
273
  end
272
-
274
+
273
275
  # Check to see if the port is open so we can raise an error if we have a conflict
274
276
  # @param [Fixnum] port the port to check
275
277
  # @return [Boolean]
@@ -293,8 +295,8 @@ class Jettywrapper
293
295
 
294
296
  return false
295
297
  end
296
-
297
- # Check to see if the pid is actually running. This only works on unix.
298
+
299
+ # Check to see if the pid is actually running. This only works on unix.
298
300
  def is_pid_running?(pid)
299
301
  begin
300
302
  return Process.getpgid(pid) != -1
@@ -306,20 +308,20 @@ class Jettywrapper
306
308
  def logger=(logger)
307
309
  @@logger = logger
308
310
  end
309
-
310
- # If ::Rails.logger is defined, that will be returned.
311
+
312
+ # If ::Rails.logger is defined and is not nil, it will be returned.
311
313
  # If no logger has been defined, a new STDOUT Logger will be created.
312
314
  def logger
313
- @@logger ||= defined?(::Rails) ? ::Rails.logger : ::Logger.new(STDOUT)
315
+ @@logger ||= defined?(::Rails) && Rails.logger ? ::Rails.logger : ::Logger.new(STDOUT)
314
316
  end
315
317
 
316
318
  end #end of class << self
317
-
319
+
318
320
  def logger
319
321
  self.class.logger
320
322
  end
321
-
322
- # What command is being run to invoke jetty?
323
+
324
+ # What command is being run to invoke jetty?
323
325
  def jetty_command
324
326
  ["java", java_variables, java_opts, "-jar", "start.jar", jetty_opts].flatten
325
327
  end
@@ -329,8 +331,8 @@ class Jettywrapper
329
331
  "-Dsolr.solr.home=#{Shellwords.escape(@solr_home)}"]
330
332
  end
331
333
 
332
- # Start the jetty server. Check the pid file to see if it is running already,
333
- # and stop it if so. After you start jetty, write the PID to a file.
334
+ # Start the jetty server. Check the pid file to see if it is running already,
335
+ # and stop it if so. After you start jetty, write the PID to a file.
334
336
  # This is the instance start method. It must be called on Jettywrapper.instance
335
337
  # You're probably better off using Jettywrapper.start(:jetty_home => "/path/to/jetty")
336
338
  # @example
@@ -341,10 +343,10 @@ class Jettywrapper
341
343
  logger.debug "Starting jetty with these values: "
342
344
  logger.debug "jetty_home: #{@jetty_home}"
343
345
  logger.debug "jetty_command: #{jetty_command.join(' ')}"
344
-
346
+
345
347
  # Check to see if we can start.
346
348
  # 1. If there is a pid, check to see if it is really running
347
- # 2. Check to see if anything is blocking the port we want to use
349
+ # 2. Check to see if anything is blocking the port we want to use
348
350
  if pid
349
351
  if Jettywrapper.is_pid_running?(pid)
350
352
  raise("Server is already running with PID #{pid}")
@@ -378,12 +380,12 @@ class Jettywrapper
378
380
  begin
379
381
  Timeout::timeout(startup_wait) do
380
382
  sleep 1 until (Jettywrapper.is_port_in_use? self.port)
381
- end
383
+ end
382
384
  rescue Timeout::Error
383
385
  logger.warn "Waited #{startup_wait} seconds for jetty to start, but it is not yet listening on port #{self.port}. Continuing anyway."
384
386
  end
385
387
  end
386
-
388
+
387
389
  def process
388
390
  @process ||= begin
389
391
  process = ChildProcess.build(*jetty_command)
@@ -410,7 +412,7 @@ class Jettywrapper
410
412
  # Jettywrapper.configure(params)
411
413
  # Jettywrapper.instance.stop
412
414
  # return Jettywrapper.instance
413
- def stop
415
+ def stop
414
416
  logger.debug "Instance stop method called for pid '#{pid}'"
415
417
  if pid
416
418
  if @process
@@ -425,7 +427,7 @@ class Jettywrapper
425
427
  end
426
428
  end
427
429
  end
428
-
430
+
429
431
 
430
432
  # The fully qualified path to the pid_file
431
433
  def pid_path
@@ -437,7 +439,7 @@ class Jettywrapper
437
439
  def pid_file
438
440
  jetty_home_to_pid_file(@jetty_home)
439
441
  end
440
-
442
+
441
443
  # Take the @jetty_home value and transform it into a legal filename
442
444
  # @return [String] the name of the pid_file
443
445
  # @example
@@ -454,7 +456,7 @@ class Jettywrapper
454
456
  def pid_dir
455
457
  File.expand_path(File.join(base_path,'tmp','pids'))
456
458
  end
457
-
459
+
458
460
  # Check to see if there is a pid file already
459
461
  # @return true if the file exists, otherwise false
460
462
  def pid_file?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jettywrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-07-18 00:00:00.000000000 Z
13
+ date: 2014-10-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: logger
@@ -139,10 +139,13 @@ files:
139
139
  - CONTRIBUTING.md
140
140
  - Gemfile
141
141
  - History.txt
142
+ - LICENSE
142
143
  - README.textile
143
144
  - Rakefile
144
145
  - TODO.txt
145
146
  - config/jetty.yml
147
+ - gemfiles/rails4.1.gemfile
148
+ - gemfiles/rails4.2.beta.gemfile
146
149
  - jettywrapper.gemspec
147
150
  - lib/jettywrapper.rb
148
151
  - lib/jettywrapper/version.rb
@@ -152,7 +155,8 @@ files:
152
155
  - spec/spec_helper.rb
153
156
  - tasks/jettywrapper.rake
154
157
  homepage: https://github.com/projecthydra/jettywrapper
155
- licenses: []
158
+ licenses:
159
+ - APACHE2
156
160
  metadata: {}
157
161
  post_install_message:
158
162
  rdoc_options: []