lib/trinidad/web_app.rb in trinidad-1.4.5 vs lib/trinidad/web_app.rb in trinidad-1.4.6
- old
+ new
@@ -1,11 +1,11 @@
require 'trinidad/configuration'
module Trinidad
class WebApp
- @@defaults = Trinidad::Configuration::DEFAULTS
+ @@defaults = Configuration::DEFAULTS
attr_reader :config, :default_config
def self.create(config, default_config = Trinidad.configuration)
war?(config, default_config) ? WarWebApp.new(config, default_config) :
@@ -22,18 +22,22 @@
def [](key)
key = key.to_sym
config.key?(key) ? config[key] : default_config[key]
end
+ def []=(key, value)
+ config[key.to_sym] = value
+ end
+
def key?(key, use_default = true)
key = key.to_sym
return true if config.has_key?(key)
use_default ? default_config.key?(key) : false
end
- %w{ root_dir rackup async_supported reload_strategy host_name }.each do |method|
- class_eval "def #{method}; self[:'#{method}']; end"
+ %w{ root_dir rackup async_supported reload_strategy host_name }.each do
+ |method| class_eval "def #{method}; self[:'#{method}']; end"
end
alias_method :web_app_dir, :root_dir # is getting deprecated soon
def app_root; root_dir; end
@@ -52,10 +56,12 @@
# NOTE: should be set to application root (base) directory thus
# JRuby-Rack correctly resolves relative paths for the context!
def doc_base; self[:doc_base] || root_dir; end
+ def allow_linking; key?(:allow_linking) ? self[:allow_linking] : true; end
+
def jruby_min_runtimes
if min = config[:jruby_min_runtimes]
return min.to_i # min specified overrides :threadsafe
else # but :threadsafe takes precendence over default :
self[:threadsafe] ? 1 : fetch_default_config_value(:jruby_min_runtimes)
@@ -171,10 +177,13 @@
if ! param_value.nil? && ! web_xml_context_param(param_name)
@context_params[param_name] = param_value.to_s
end
end
+ # TODO: internal API - should be configurable/adjustable with context.yml !
+ def context_manager; Java::RbTrinidadContext::DefaultManager.new end
+
def logging
@logging ||= begin
defaults = {
:level => log, # backwards compatibility
:use_parent_handlers => ( environment == 'development' ),
@@ -183,11 +192,11 @@
:prefix => environment,
:suffix => '.log',
:rotate => true
}
}
- Trinidad::Configuration.merge_options(defaults, self[:logging])
+ Configuration.merge_options(defaults, self[:logging])
end
end
def deployment_descriptor
return nil if @deployment_descriptor == false
@@ -269,11 +278,11 @@
end
# @deprecated replaced with {#class_loader!}
def generate_class_loader; class_loader!; end
def define_lifecycle
- Trinidad::Lifecycle::WebApp::Default.new(self)
+ Lifecycle::WebApp::Default.new(self)
end
# Reset the hold web application state so it gets re-initialized.
# Please note that the configuration objects are not cleared.
def reset!
@@ -392,11 +401,11 @@
def solo?
! is_a?(WarWebApp) && config[:solo]
end
def threadsafe?
- jruby_min_runtimes == 1 && jruby_max_runtimes == 1
+ jruby_min_runtimes == 1 && jruby_max_runtimes == 1 # handles [:threadsafe]
end
protected
def context_listener
@@ -507,11 +516,11 @@
end
value
end
def logger
- @logger ||= Trinidad::Logging::LogFactory.getLog('')
+ @logger ||= Logging::LogFactory.getLog('')
end
protected
def self.rackup?(config, default_config = nil)
@@ -636,11 +645,11 @@
end
end
# Rack web application (looks for a "rackup" *config.ru* file).
- class RackupWebApp < WebApp
+ class RackWebApp < WebApp
def context_params
add_context_param 'app.root', app_root
add_context_param 'rack.env', environment
if rackup = self.rackup
@@ -653,10 +662,11 @@
def context_listener; 'org.jruby.rack.RackServletContextListener'; end
def web_xml_environment; web_xml_context_param('rack.env'); end
end
+ RackupWebApp = RackWebApp
# Rails web application specifics (supports same versions as JRuby-Rack).
class RailsWebApp < WebApp
def context_params
@@ -692,12 +702,12 @@
end
def self.threadsafe_match?(file)
File.exist?(file) && (
file_line_match?(file, /^[^#]*threadsafe!/) || ( # Rails 4.0
- file_line_match?(file, /^[^#]*config\.eager_load = true/) &&
- file_line_match?(file, /^[^#]*config\.cache_classes = true/)
+ file_line_match?(file, /^[^#]*config\.eager_load\s?*=\s?*true/) &&
+ file_line_match?(file, /^[^#]*config\.cache_classes\s?*=\s?*true/)
)
)
end
end
@@ -713,11 +723,11 @@
end
def context_path
@path ||= begin
path = File.basename(super)
- context_name = Trinidad::Tomcat::ContextName.new(path)
+ context_name = Tomcat::ContextName.new(path)
context_name.path # removes .war handles ## versioning
end
end
def work_dir
@@ -749,15 +759,17 @@
def context_params
warbler? ? super : @context_params ||= {}
end
+ def context_manager; nil end
+
def layout_class
'JRuby::Rack::WebInfLayout'
end
def define_lifecycle
- Trinidad::Lifecycle::WebApp::War.new(self)
+ Lifecycle::WebApp::War.new(self)
end
private
def warbler?; nil; end # TODO detect warbler created .war ?!