Module: LiferayDatabaseConfigReader

Defined in:
lib/liferay_database_config_reader.rb

Constant Summary collapse

CATALINA_HOME =
java.lang.System.getProperty('catalina.home') || ''
PROPERTIES_EXT_FILE =
'portal-ext.properties'
WEB_INF_CLASSES =
CATALINA_HOME + '/webapps/ROOT/WEB-INF/classes/'

Class Method Summary collapse

Class Method Details

.attrObject



34
# File 'lib/liferay_database_config_reader.rb', line 34

def self.attr; @@properties end

.init!(path = File.expand_path(WEB_INF_CLASSES + PROPERTIES_EXT_FILE)) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/liferay_database_config_reader.rb', line 13

def self.init! path = File.expand_path(WEB_INF_CLASSES + PROPERTIES_EXT_FILE)
  log "RAILS_ENV=#{ENV['RAILS_ENV']}"
  log "reading #{path}"

  properties = Properties.new
  properties.load(FileInputStream.new(path))
  url = properties.getProperty("jdbc.default.url")

  @@properties[:username] = properties.getProperty("jdbc.default.username")
  @@properties[:password] = properties.getProperty("jdbc.default.password")

  fragments = url.split /\/+/
  raise "Fail to check adapter, host and database in liferay config file" if fragments.nil? or fragments.size < 3

  @@properties[:adapter] = fragments[0].gsub(':', '')
  @@properties[:host], @@properties[:port] = fragments[1].split(':')
  @@properties[:database] = fragments[2]
  
  log "adapter: #{attr[:adapter]}, host: #{attr[:host]}:#{attr[:port]}, database: #{attr[:database]}\n"
end

.log(msg) ⇒ Object



36
37
38
39
# File 'lib/liferay_database_config_reader.rb', line 36

def self.log msg
  msg = "[LiferayDatabaseReader] :: #{msg}"
  (defined? RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER.info(msg) : STDOUT.puts(msg)
end