Class: Jettywrapper
Overview
Jettywrapper is a Singleton class, so you can only create one jetty instance at a time.
Instance Attribute Summary collapse
-
#fedora_home ⇒ Object
Where is fedora located? Default is jetty_home/fedora.
-
#jetty_home ⇒ Object
Where is jetty located?.
-
#pid ⇒ Object
If Jettywrapper is running, what pid is it running as?.
-
#port ⇒ Object
What port should jetty start on? Default is 8888.
-
#quiet ⇒ Object
Keep quiet about jetty output?.
-
#solr_home ⇒ Object
Where is solr located? Default is jetty_home/solr.
-
#startup_wait ⇒ Object
After jetty starts, how long to wait until starting the tests?.
Class Method Summary collapse
-
.configure(params = {}) ⇒ Object
Set the jetty parameters.
-
.wrap(params = {}) ⇒ Object
Wrap the tests.
Instance Method Summary collapse
-
#jetty_command ⇒ Object
What command is being run to invoke jetty?.
-
#jruby_raise_error? ⇒ Boolean
Not Windows.
-
#platform_specific_start ⇒ Object
start jetty for *nix.
-
#platform_specific_stop ⇒ Object
stop jetty for *nix.
- #start ⇒ Object
- #stop ⇒ Object
Instance Attribute Details
#fedora_home ⇒ Object
Where is fedora located? Default is jetty_home/fedora
14 15 16 |
# File 'lib/jettywrapper.rb', line 14 def fedora_home @fedora_home end |
#jetty_home ⇒ Object
Where is jetty located?
10 11 12 |
# File 'lib/jettywrapper.rb', line 10 def jetty_home @jetty_home end |
#pid ⇒ Object
If Jettywrapper is running, what pid is it running as?
8 9 10 |
# File 'lib/jettywrapper.rb', line 8 def pid @pid end |
#port ⇒ Object
What port should jetty start on? Default is 8888
9 10 11 |
# File 'lib/jettywrapper.rb', line 9 def port @port end |
#quiet ⇒ Object
Keep quiet about jetty output?
12 13 14 |
# File 'lib/jettywrapper.rb', line 12 def quiet @quiet end |
#solr_home ⇒ Object
Where is solr located? Default is jetty_home/solr
13 14 15 |
# File 'lib/jettywrapper.rb', line 13 def solr_home @solr_home end |
#startup_wait ⇒ Object
After jetty starts, how long to wait until starting the tests?
11 12 13 |
# File 'lib/jettywrapper.rb', line 11 def startup_wait @startup_wait end |
Class Method Details
.configure(params = {}) ⇒ Object
Set the jetty parameters. It accepts a Hash of symbols.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jettywrapper.rb', line 31 def configure(params = {}) hydra_server = self.instance hydra_server.quiet = params[:quiet].nil? ? true : params[:quiet] if defined?(Rails.root) base_path = Rails.root else raise "You must set either RAILS_ROOT or :jetty_home so I know where jetty is" unless params[:jetty_home] end hydra_server.jetty_home = params[:jetty_home] || File.(File.join(base_path, 'jetty')) hydra_server.solr_home = params[:solr_home] || File.join( hydra_server.jetty_home, "solr") hydra_server.fedora_home = params[:fedora_home] || File.join( hydra_server.jetty_home, "fedora","default") hydra_server.port = params[:jetty_port] || 8888 hydra_server.startup_wait = params[:startup_wait] || 5 return hydra_server end |
.wrap(params = {}) ⇒ Object
Wrap the tests. Startup jetty, yield to the test task, capture any errors, shutdown jetty, and return the error.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jettywrapper.rb', line 65 def wrap(params = {}) error = false jetty_server = self.instance jetty_server.quiet = params[:quiet] || true jetty_server.jetty_home = params[:jetty_home] jetty_server.solr_home = params[:solr_home] jetty_server.port = params[:jetty_port] || 8888 jetty_server.startup_wait = params[:startup_wait] || 5 jetty_server.fedora_home = params[:fedora_home] || File.join( jetty_server.jetty_home, "fedora","default") begin # puts "starting jetty on #{RUBY_PLATFORM}" jetty_server.start sleep jetty_server.startup_wait yield rescue error = $! puts "*** Error starting hydra-jetty: #{error}" ensure # puts "stopping jetty server" jetty_server.stop end return error end |
Instance Method Details
#jetty_command ⇒ Object
What command is being run to invoke jetty?
94 95 96 |
# File 'lib/jettywrapper.rb', line 94 def jetty_command "java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} -Dfedora.home=#{@fedora_home} -jar start.jar" end |
#jruby_raise_error? ⇒ Boolean
Not Windows
134 135 136 |
# File 'lib/jettywrapper.rb', line 134 def jruby_raise_error? raise 'JRuby requires that you start solr manually, then run "rake spec" or "rake features"' if defined?(JRUBY_VERSION) end |
#platform_specific_start ⇒ Object
start jetty for *nix
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/jettywrapper.rb', line 114 def platform_specific_start puts "Starting Jetty on windows" Dir.chdir(@jetty_home) do @pid = Process.create( :app_name => jetty_command, :creation_flags => Process::DETACHED_PROCESS, :process_inherit => false, :thread_inherit => true, :cwd => "#{@jetty_home}" ).process_id end end |
#platform_specific_stop ⇒ Object
stop jetty for *nix
128 129 130 131 |
# File 'lib/jettywrapper.rb', line 128 def platform_specific_stop Process.kill(1, @pid) Process.wait end |
#start ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/jettywrapper.rb', line 98 def start puts "jetty_home: #{@jetty_home}" puts "solr_home: #{@solr_home}" puts "fedora_home: #{@fedora_home}" puts "jetty_command: #{jetty_command}" platform_specific_start end |
#stop ⇒ Object
106 107 108 |
# File 'lib/jettywrapper.rb', line 106 def stop platform_specific_stop end |