jettywrapper 1.8.2 → 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
 
data/lib/jettywrapper.rb CHANGED
@@ -4,6 +4,7 @@ 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'
@@ -14,12 +15,12 @@ Dir[File.expand_path(File.join(File.dirname(__FILE__),"tasks/*.rake"))].each { |
14
15
 
15
16
  # Jettywrapper is a Singleton class, so you can only create one jetty instance at a time.
16
17
  class Jettywrapper
17
-
18
+
18
19
  include Singleton
19
20
  include ActiveSupport::Benchmarkable
20
-
21
-
22
- attr_accessor :jetty_home # Jetty's home directory
21
+
22
+
23
+ attr_accessor :jetty_home # Jetty's home directory
23
24
  attr_accessor :port # Jetty's port. Default is 8888. Note that attribute is named port, but params passed in expect :jetty_port
24
25
  attr_accessor :startup_wait # How many seconds to wait for jetty to spin up. Default is 5.
25
26
  attr_accessor :quiet # true (default) to reduce Jetty's output
@@ -27,14 +28,14 @@ class Jettywrapper
27
28
  attr_accessor :base_path # The root of the application. Used for determining where log files and PID files should go.
28
29
  attr_accessor :java_opts # Options to pass to java (ex. ["-Xmx512mb", "-Xms128mb"])
29
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
30
-
31
+
31
32
  # configure the singleton with some defaults
32
33
  def initialize(params = {})
33
34
  self.base_path = self.class.app_root
34
35
  end
35
36
 
36
-
37
- # 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.
38
39
  # Methods outside the class << self block must be called on Jettywrapper.instance, as instance methods.
39
40
  class << self
40
41
 
@@ -68,10 +69,10 @@ class Jettywrapper
68
69
  system "curl -L #{self.url} -o #{zip_file}"
69
70
  abort "Unable to download jetty from #{self.url}" unless $?.success?
70
71
  end
71
-
72
+
72
73
  def unzip
73
74
  download unless File.exists? zip_file
74
- logger.info "Unpacking jetty..."
75
+ logger.info "Unpacking #{zip_file}..."
75
76
  tmp_save_dir = File.join tmp_dir, 'jetty_generator'
76
77
  system "unzip -d #{tmp_save_dir} -qo #{zip_file}"
77
78
  abort "Unable to unzip #{zip_file} into tmp_save_dir/" unless $?.success?
@@ -87,8 +88,8 @@ class Jettywrapper
87
88
 
88
89
  def expanded_zip_dir(tmp_save_dir)
89
90
  # This old way is more specific, but won't work for blacklight-jetty
90
- #expanded_dir = Dir[File.join(tmp_save_dir, "hydra-jetty-*")].first
91
- 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
92
93
  end
93
94
 
94
95
  def clean
@@ -112,25 +113,25 @@ class Jettywrapper
112
113
 
113
114
  def env
114
115
  @env ||= begin
115
- case
116
- when ENV['JETTYWRAPPER_ENV']
116
+ case
117
+ when ENV['JETTYWRAPPER_ENV']
117
118
  ENV['JETTYWRAPPER_ENV']
118
119
  when defined?(Rails) && Rails.respond_to?(:env)
119
120
  Rails.env
120
- when ENV['RAILS_ENV']
121
- ENV['RAILS_ENV']
122
- when ENV['environment']
123
- ENV['environment']
121
+ when ENV['RAILS_ENV']
122
+ ENV['RAILS_ENV']
123
+ when ENV['environment']
124
+ ENV['environment']
124
125
  else
125
126
  default_environment
126
127
  end
127
128
  end
128
129
  end
129
-
130
+
130
131
  def default_environment
131
132
  'development'
132
133
  end
133
-
134
+
134
135
  def load_config(config_name = env)
135
136
  @env = config_name
136
137
  jetty_file = "#{app_root}/config/jetty.yml"
@@ -159,15 +160,15 @@ class Jettywrapper
159
160
  config = jetty_yml.with_indifferent_access
160
161
  config[config_name] || config['default'.freeze]
161
162
  end
162
-
163
163
 
164
- # Set the jetty parameters. It accepts a Hash of symbols.
164
+
165
+ # Set the jetty parameters. It accepts a Hash of symbols.
165
166
  # @param [Hash<Symbol>] params
166
167
  # :jetty_home Required. Jetty's home direcotry
167
168
  # :jetty_port Jetty's port. Default is 8888. Note that attribute is named port, but params passed in expect :jetty_port
168
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.
169
170
  # :solr_home Solr's home directory. Default is jetty_home/solr
170
- # :quiet Keep True(default) to reduce jetty's output
171
+ # :quiet Keep True(default) to reduce jetty's output
171
172
  # :java_opts options to pass to the jvm (ex. ["-Xmx512mb", "-Xms128mb"])
172
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
173
174
  def configure(params = {})
@@ -183,25 +184,25 @@ class Jettywrapper
183
184
  jetty_server.jetty_opts = params[:jetty_opts] || []
184
185
  return jetty_server
185
186
  end
186
-
187
-
187
+
188
+
188
189
  # Wrap the tests. Startup jetty, yield to the test task, capture any errors, shutdown
189
- # jetty, and return the error.
190
+ # jetty, and return the error.
190
191
  # @example Using this method in a rake task
191
192
  # require 'jettywrapper'
192
193
  # desc "Spin up jetty and run tests against it"
193
194
  # task :newtest do
194
- # jetty_params = {
195
- # :jetty_home => "/path/to/jetty",
196
- # :quiet => false,
197
- # :jetty_port => 8983,
195
+ # jetty_params = {
196
+ # :jetty_home => "/path/to/jetty",
197
+ # :quiet => false,
198
+ # :jetty_port => 8983,
198
199
  # :startup_wait => 30,
199
200
  # :jetty_opts => "/etc/jetty.xml"
200
201
  # }
201
- # error = Jettywrapper.wrap(jetty_params) do
202
- # Rake::Task["rake:spec"].invoke
203
- # Rake::Task["rake:cucumber"].invoke
204
- # end
202
+ # error = Jettywrapper.wrap(jetty_params) do
203
+ # Rake::Task["rake:spec"].invoke
204
+ # Rake::Task["rake:cucumber"].invoke
205
+ # end
205
206
  # raise "test failures: #{error}" if error
206
207
  # end
207
208
  def wrap(params)
@@ -223,42 +224,42 @@ class Jettywrapper
223
224
 
224
225
  return error
225
226
  end
226
-
227
+
227
228
  # Convenience method for configuring and starting jetty with one command
228
229
  # @param [Hash] params: The configuration to use for starting jetty
229
- # @example
230
+ # @example
230
231
  # Jettywrapper.start(:jetty_home => '/path/to/jetty', :jetty_port => '8983')
231
232
  def start(params)
232
233
  Jettywrapper.configure(params)
233
234
  Jettywrapper.instance.start
234
235
  return Jettywrapper.instance
235
236
  end
236
-
237
+
237
238
  # Convenience method for configuring and starting jetty with one command. Note
238
- # that for stopping, only the :jetty_home value is required (including other values won't
239
- # hurt anything, though).
239
+ # that for stopping, only the :jetty_home value is required (including other values won't
240
+ # hurt anything, though).
240
241
  # @param [Hash] params: The jetty_home to use for stopping jetty
241
242
  # @return [Jettywrapper.instance]
242
- # @example
243
+ # @example
243
244
  # Jettywrapper.stop_with_params(:jetty_home => '/path/to/jetty')
244
245
  def stop(params)
245
246
  Jettywrapper.configure(params)
246
247
  Jettywrapper.instance.stop
247
248
  return Jettywrapper.instance
248
249
  end
249
-
250
+
250
251
  # Determine whether the jetty at the given jetty_home is running
251
252
  # @param [Hash] params: :jetty_home is required. Which jetty do you want to check the status of?
252
253
  # @return [Boolean]
253
254
  # @example
254
255
  # Jettywrapper.is_jetty_running?(:jetty_home => '/path/to/jetty')
255
- def is_jetty_running?(params)
256
+ def is_jetty_running?(params)
256
257
  Jettywrapper.configure(params)
257
258
  pid = Jettywrapper.instance.pid
258
259
  return false unless pid
259
260
  true
260
261
  end
261
-
262
+
262
263
  # Return the pid of the specified jetty, or return nil if it isn't running
263
264
  # @param [Hash] params: :jetty_home is required.
264
265
  # @return [Fixnum] or [nil]
@@ -270,7 +271,7 @@ class Jettywrapper
270
271
  return nil unless pid
271
272
  pid
272
273
  end
273
-
274
+
274
275
  # Check to see if the port is open so we can raise an error if we have a conflict
275
276
  # @param [Fixnum] port the port to check
276
277
  # @return [Boolean]
@@ -294,8 +295,8 @@ class Jettywrapper
294
295
 
295
296
  return false
296
297
  end
297
-
298
- # 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.
299
300
  def is_pid_running?(pid)
300
301
  begin
301
302
  return Process.getpgid(pid) != -1
@@ -307,7 +308,7 @@ class Jettywrapper
307
308
  def logger=(logger)
308
309
  @@logger = logger
309
310
  end
310
-
311
+
311
312
  # If ::Rails.logger is defined and is not nil, it will be returned.
312
313
  # If no logger has been defined, a new STDOUT Logger will be created.
313
314
  def logger
@@ -315,12 +316,12 @@ class Jettywrapper
315
316
  end
316
317
 
317
318
  end #end of class << self
318
-
319
+
319
320
  def logger
320
321
  self.class.logger
321
322
  end
322
-
323
- # What command is being run to invoke jetty?
323
+
324
+ # What command is being run to invoke jetty?
324
325
  def jetty_command
325
326
  ["java", java_variables, java_opts, "-jar", "start.jar", jetty_opts].flatten
326
327
  end
@@ -330,8 +331,8 @@ class Jettywrapper
330
331
  "-Dsolr.solr.home=#{Shellwords.escape(@solr_home)}"]
331
332
  end
332
333
 
333
- # Start the jetty server. Check the pid file to see if it is running already,
334
- # 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.
335
336
  # This is the instance start method. It must be called on Jettywrapper.instance
336
337
  # You're probably better off using Jettywrapper.start(:jetty_home => "/path/to/jetty")
337
338
  # @example
@@ -342,10 +343,10 @@ class Jettywrapper
342
343
  logger.debug "Starting jetty with these values: "
343
344
  logger.debug "jetty_home: #{@jetty_home}"
344
345
  logger.debug "jetty_command: #{jetty_command.join(' ')}"
345
-
346
+
346
347
  # Check to see if we can start.
347
348
  # 1. If there is a pid, check to see if it is really running
348
- # 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
349
350
  if pid
350
351
  if Jettywrapper.is_pid_running?(pid)
351
352
  raise("Server is already running with PID #{pid}")
@@ -379,12 +380,12 @@ class Jettywrapper
379
380
  begin
380
381
  Timeout::timeout(startup_wait) do
381
382
  sleep 1 until (Jettywrapper.is_port_in_use? self.port)
382
- end
383
+ end
383
384
  rescue Timeout::Error
384
385
  logger.warn "Waited #{startup_wait} seconds for jetty to start, but it is not yet listening on port #{self.port}. Continuing anyway."
385
386
  end
386
387
  end
387
-
388
+
388
389
  def process
389
390
  @process ||= begin
390
391
  process = ChildProcess.build(*jetty_command)
@@ -411,7 +412,7 @@ class Jettywrapper
411
412
  # Jettywrapper.configure(params)
412
413
  # Jettywrapper.instance.stop
413
414
  # return Jettywrapper.instance
414
- def stop
415
+ def stop
415
416
  logger.debug "Instance stop method called for pid '#{pid}'"
416
417
  if pid
417
418
  if @process
@@ -426,7 +427,7 @@ class Jettywrapper
426
427
  end
427
428
  end
428
429
  end
429
-
430
+
430
431
 
431
432
  # The fully qualified path to the pid_file
432
433
  def pid_path
@@ -438,7 +439,7 @@ class Jettywrapper
438
439
  def pid_file
439
440
  jetty_home_to_pid_file(@jetty_home)
440
441
  end
441
-
442
+
442
443
  # Take the @jetty_home value and transform it into a legal filename
443
444
  # @return [String] the name of the pid_file
444
445
  # @example
@@ -455,7 +456,7 @@ class Jettywrapper
455
456
  def pid_dir
456
457
  File.expand_path(File.join(base_path,'tmp','pids'))
457
458
  end
458
-
459
+
459
460
  # Check to see if there is a pid file already
460
461
  # @return true if the file exists, otherwise false
461
462
  def pid_file?
@@ -1,3 +1,3 @@
1
1
  class Jettywrapper
2
- VERSION = "1.8.2"
2
+ VERSION = "1.8.3"
3
3
  end
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.2
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: []