Class: Ji2p::Startup::Bootstrap
Instance Method Summary collapse
- #boot! ⇒ Object
- #check_and_set_props! ⇒ Object
- #get_system_property(value) ⇒ Object
- #i2p_loaded? ⇒ Boolean
-
#initialize(defaults = {'i2p.dir.config' => TMPDIR}) ⇒ Bootstrap
constructor
A new instance of Bootstrap.
- #load_jars ⇒ Object
- #set_system_property(key, value) ⇒ Object
Constructor Details
Instance Method Details
#boot! ⇒ Object
53 54 55 56 57 58 |
# File 'lib/ji2p/startup/bootstrap.rb', line 53 def boot! check_and_set_props! load_jars unless i2p_loaded? RouterManager.start_router! RouterManager.router_context end |
#check_and_set_props! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ji2p/startup/bootstrap.rb', line 37 def check_and_set_props! if System.getProperties['i2p.dir.base'].nil? unless ENV['I2PDIR'].nil? System.setProperty 'i2p.dir.base', ENV['I2PDIR'].to_s else raise ArgumentError, 'The system property i2p.dir.base is missing!', caller if @defaults['i2p.dir.base'].nil? end end if System.getProperties['i2p.dir.config'].nil? raise ArgumentError, 'The system property i2p.dir.config is missing!', caller if @defaults['i2p.dir.config'].nil? System.setProperty 'i2p.dir.config', @defaults['i2p.dir.config'] end System.setProperty 'java.awt.headless', 'true' if System.getProperties['java.awt.headless'].nil? System.setProperty 'java.library.path', "#{System.getProperties['i2p.dir.base']}/lib" if System.getProperties['java.library.path'].nil? end |
#get_system_property(value) ⇒ Object
16 17 18 |
# File 'lib/ji2p/startup/bootstrap.rb', line 16 def get_system_property value System.getProperty[value.to_s] end |
#i2p_loaded? ⇒ Boolean
31 32 33 34 35 |
# File 'lib/ji2p/startup/bootstrap.rb', line 31 def i2p_loaded? java_import java.lang.Thread cl = Thread.currentThread.getContextClassLoader cl.getURLs.select { |item| item.to_s.include? 'i2p.jar' }.size > 0 end |
#load_jars ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ji2p/startup/bootstrap.rb', line 20 def load_jars java_import java.lang.Thread java_import java.net.URL cl = Thread.currentThread.getContextClassLoader dirname = System.getProperties['i2p.dir.base'] Dir["#{dirname}/lib/**.jar"].each do |jar| u = Java::JavaNet::URL.new "file://#{jar}" cl.addURL u end end |
#set_system_property(key, value) ⇒ Object
12 13 14 |
# File 'lib/ji2p/startup/bootstrap.rb', line 12 def set_system_property key, value System.setProperty key.to_s, value.to_s end |