Class: Trinidad::WebApp
- Inherits:
-
Object
show all
- Defined in:
- lib/trinidad/web_app.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config, app_config, servlet_class = 'org.jruby.rack.RackServlet', servlet_name = 'RackServlet') ⇒ WebApp
Returns a new instance of WebApp.
20
21
22
23
24
25
26
27
|
# File 'lib/trinidad/web_app.rb', line 20
def initialize(config, app_config, servlet_class = 'org.jruby.rack.RackServlet', servlet_name = 'RackServlet')
@config = config
@app_config = app_config
generate_class_loader
configure_rack_servlet(servlet_class, servlet_name) unless rack_servlet_configured?
end
|
Instance Attribute Details
#app_config ⇒ Object
Returns the value of attribute app_config.
3
4
5
|
# File 'lib/trinidad/web_app.rb', line 3
def app_config
@app_config
end
|
#class_loader ⇒ Object
Returns the value of attribute class_loader.
3
4
5
|
# File 'lib/trinidad/web_app.rb', line 3
def class_loader
@class_loader
end
|
#config ⇒ Object
Returns the value of attribute config.
3
4
5
|
# File 'lib/trinidad/web_app.rb', line 3
def config
@config
end
|
#servlet ⇒ Object
Returns the value of attribute servlet.
3
4
5
|
# File 'lib/trinidad/web_app.rb', line 3
def servlet
@servlet
end
|
Class Method Details
.create(config, app_config) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/trinidad/web_app.rb', line 5
def self.create(config, app_config)
autodetect_configuration(config, app_config)
war?(app_config) ? WarWebApp.new(config, app_config) :
rackup?(app_config) ? RackupWebApp.new(config, app_config) : RailsWebApp.new(config, app_config)
end
|
.rackup?(app_config) ⇒ Boolean
12
13
14
|
# File 'lib/trinidad/web_app.rb', line 12
def self.rackup?(app_config)
app_config.has_key?(:rackup) || !Dir['WEB-INF/**/config.ru'].empty?
end
|
.war?(app_config) ⇒ Boolean
16
17
18
|
# File 'lib/trinidad/web_app.rb', line 16
def self.war?(app_config)
app_config[:context_path] =~ /\.war$/
end
|
Instance Method Details
#default_deployment_descriptor ⇒ Object
43
44
45
46
47
48
|
# File 'lib/trinidad/web_app.rb', line 43
def default_deployment_descriptor
@deployment_descriptor ||= if default_web_xml
file = File.expand_path(File.join(work_dir, default_web_xml))
File.exist?(file) ? file : nil
end
end
|
#define_lifecycle ⇒ Object
#environment ⇒ Object
86
|
# File 'lib/trinidad/web_app.rb', line 86
def environment; @app_config[:environment] || @config[:environment] || 'development'; end
|
#extensions ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/trinidad/web_app.rb', line 76
def extensions
@extensions ||= begin
extensions = @config[:extensions] || {}
extensions.merge!(@app_config[:extensions]) if @app_config[:extensions]
extensions
end
end
|
#generate_class_loader ⇒ Object
105
106
107
|
# File 'lib/trinidad/web_app.rb', line 105
def generate_class_loader
@class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
end
|
#init_params ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/trinidad/web_app.rb', line 33
def init_params
@params ||= {}
add_parameter_unless_exist 'jruby.min.runtimes', jruby_min_runtimes.to_s
add_parameter_unless_exist 'jruby.max.runtimes', jruby_max_runtimes.to_s
add_parameter_unless_exist 'jruby.initial.runtimes', jruby_min_runtimes.to_s
add_parameter_unless_exist 'public.root', File.join('/', public_root)
add_parameter_unless_exist 'jruby.compat.version', RUBY_VERSION
@params
end
|
#monitor ⇒ Object
96
97
98
99
|
# File 'lib/trinidad/web_app.rb', line 96
def monitor
m_file = @app_config[:monitor] || @config[:monitor] || 'tmp/restart.txt'
File.expand_path(m_file, work_dir)
end
|
#public_root ⇒ Object
64
65
66
|
# File 'lib/trinidad/web_app.rb', line 64
def public_root
@app_config[:public] || @config[:public] || 'public'
end
|
#rack_listener ⇒ Object
29
30
31
|
# File 'lib/trinidad/web_app.rb', line 29
def rack_listener
context_listener unless rack_listener_configured?
end
|
58
59
60
61
62
|
# File 'lib/trinidad/web_app.rb', line 58
def rack_listener_configured?
!!( web_xml &&
web_xml.root.elements["/web-app/listener[contains(listener-class, '#{context_listener}')]"]
)
end
|
50
51
52
53
54
55
56
|
# File 'lib/trinidad/web_app.rb', line 50
def rack_servlet_configured?
!!( web_xml && (
web_xml.root.elements["/web-app/servlet[contains(servlet-class, 'org.jruby.rack.RackServlet')]"] ||
web_xml.root.elements["/web-app/filter[contains(filter-class, 'org.jruby.rack.RackFilter')]"]
)
)
end
|
#solo? ⇒ Boolean
88
89
90
|
# File 'lib/trinidad/web_app.rb', line 88
def solo?
!self.is_a?(WarWebApp) && @app_config[:solo]
end
|
#threadsafe? ⇒ Boolean
92
93
94
|
# File 'lib/trinidad/web_app.rb', line 92
def threadsafe?
jruby_min_runtimes.to_i == 1 && jruby_max_runtimes.to_i == 1
end
|
#war? ⇒ Boolean
84
|
# File 'lib/trinidad/web_app.rb', line 84
def war?; WebApp.war?(app_config); end
|
#work_dir ⇒ Object
85
|
# File 'lib/trinidad/web_app.rb', line 85
def work_dir; web_app_dir; end
|