trinidad 1.4.5.B1 → 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/{History.txt → History.md} +104 -87
- data/lib/trinidad/logging.rb +36 -156
- data/lib/trinidad/server.rb +77 -52
- data/lib/trinidad/version.rb +1 -1
- data/lib/trinidad/web_app.rb +135 -118
- data/trinidad.gemspec +32 -32
- metadata +28 -29
data/lib/trinidad/version.rb
CHANGED
data/lib/trinidad/web_app.rb
CHANGED
@@ -2,9 +2,9 @@ require 'trinidad/configuration'
|
|
2
2
|
|
3
3
|
module Trinidad
|
4
4
|
class WebApp
|
5
|
-
|
5
|
+
|
6
6
|
@@defaults = Trinidad::Configuration::DEFAULTS
|
7
|
-
|
7
|
+
|
8
8
|
attr_reader :config, :default_config
|
9
9
|
|
10
10
|
def self.create(config, default_config = Trinidad.configuration)
|
@@ -23,37 +23,37 @@ module Trinidad
|
|
23
23
|
key = key.to_sym
|
24
24
|
config.key?(key) ? config[key] : default_config[key]
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def key?(key, use_default = true)
|
28
28
|
key = key.to_sym
|
29
29
|
return true if config.has_key?(key)
|
30
30
|
use_default ? default_config.key?(key) : false
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
%w{ root_dir rackup async_supported reload_strategy host_name }.each do |method|
|
34
34
|
class_eval "def #{method}; self[:'#{method}']; end"
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
alias_method :web_app_dir, :root_dir # is getting deprecated soon
|
38
38
|
def app_root; root_dir; end
|
39
|
-
|
39
|
+
|
40
40
|
# @deprecated use `self[:log]` instead
|
41
41
|
def log; self[:log]; end
|
42
|
-
|
42
|
+
|
43
43
|
def context_path
|
44
44
|
path = self[:context_path] || self[:path]
|
45
45
|
path ? path.to_s : path
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def context_name
|
49
49
|
name = self[:context_name] || self[:name]
|
50
50
|
name ? name.to_s : name
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
# NOTE: should be set to application root (base) directory thus
|
54
54
|
# JRuby-Rack correctly resolves relative paths for the context!
|
55
55
|
def doc_base; self[:doc_base] || root_dir; end
|
56
|
-
|
56
|
+
|
57
57
|
def jruby_min_runtimes
|
58
58
|
if min = config[:jruby_min_runtimes]
|
59
59
|
return min.to_i # min specified overrides :threadsafe
|
@@ -61,7 +61,7 @@ module Trinidad
|
|
61
61
|
self[:threadsafe] ? 1 : fetch_default_config_value(:jruby_min_runtimes)
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def jruby_max_runtimes
|
66
66
|
if max = config[:jruby_max_runtimes]
|
67
67
|
return max.to_i # max specified overrides :threadsafe
|
@@ -69,16 +69,16 @@ module Trinidad
|
|
69
69
|
self[:threadsafe] ? 1 : fetch_default_config_value(:jruby_max_runtimes)
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def jruby_initial_runtimes
|
74
74
|
if ini = config[:jruby_initial_runtimes]
|
75
75
|
return ini.to_i # min specified overrides :threadsafe
|
76
76
|
else # but :threadsafe takes precendence over default :
|
77
|
-
self[:threadsafe] ? 1 :
|
77
|
+
self[:threadsafe] ? 1 :
|
78
78
|
fetch_default_config_value(:jruby_initial_runtimes, jruby_min_runtimes)
|
79
79
|
end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def jruby_runtime_acquire_timeout
|
83
83
|
fetch_config_value(:jruby_runtime_acquire_timeout, 5.0) # default 10s seems too high
|
84
84
|
end
|
@@ -86,51 +86,64 @@ module Trinidad
|
|
86
86
|
def jruby_compat_version
|
87
87
|
fetch_config_value(:jruby_compat_version, RUBY_VERSION)
|
88
88
|
end
|
89
|
-
|
90
|
-
def environment
|
91
|
-
|
89
|
+
|
90
|
+
def environment
|
91
|
+
@environment ||= begin
|
92
|
+
if env = web_xml_environment
|
93
|
+
if self[:environment] && env != self[:environment]
|
94
|
+
logger.info "Ignoring set :environment '#{self[:environment]}' for " <<
|
95
|
+
"#{context_path} since it's configured in web.xml as '#{env}'"
|
96
|
+
end
|
97
|
+
else
|
98
|
+
env = self[:environment] || @@defaults[:environment]
|
99
|
+
env = env.to_s if env.is_a?(Symbol) # make sure it's a String
|
100
|
+
end
|
101
|
+
env
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
92
105
|
def public_dir
|
93
106
|
@public_dir ||= ( public_root == '/' ? root_dir : expand_path(public_root) )
|
94
107
|
end
|
95
|
-
|
108
|
+
|
96
109
|
# by (a "Rails") convention use '[RAILS_ROOT]/tmp'
|
97
110
|
def work_dir
|
98
111
|
@work_dir ||= self[:work_dir] || File.join(root_dir, 'tmp')
|
99
112
|
end
|
100
|
-
|
113
|
+
|
101
114
|
# by a "Rails" convention defaults to '[RAILS_ROOT]/log'
|
102
115
|
def log_dir
|
103
116
|
@log_dir ||= self[:log_dir] || File.join(root_dir, 'log')
|
104
117
|
end
|
105
|
-
|
118
|
+
|
106
119
|
def monitor
|
107
120
|
File.expand_path(self[:monitor] || 'restart.txt', work_dir)
|
108
121
|
end
|
109
|
-
|
122
|
+
|
110
123
|
def context_xml; self[:context_xml] || self[:default_context_xml]; end
|
111
124
|
def web_xml; self[:web_xml] || self[:default_web_xml]; end
|
112
125
|
def default_web_xml; self[:default_web_xml]; end
|
113
|
-
|
126
|
+
|
114
127
|
def java_lib
|
115
128
|
# accepts #deprecated :libs_dir syntax
|
116
129
|
self[:java_lib] || self[:libs_dir] || @@defaults[:java_lib]
|
117
130
|
end
|
118
|
-
|
131
|
+
|
119
132
|
def java_classes
|
120
133
|
# accepts #deprecated :classes_dir syntax
|
121
134
|
self[:java_classes] || self[:classes_dir] || File.join(java_lib, 'classes')
|
122
135
|
end
|
123
|
-
|
136
|
+
|
124
137
|
def java_lib_dir
|
125
138
|
@java_lib_dir ||= self[:java_lib_dir] || expand_path(java_lib)
|
126
139
|
end
|
127
140
|
alias_method :libs_dir, :java_lib_dir # #deprecated
|
128
|
-
|
141
|
+
|
129
142
|
def java_classes_dir
|
130
143
|
@java_classes_dir ||= self[:java_classes_dir] || expand_path(java_classes)
|
131
144
|
end
|
132
145
|
alias_method :classes_dir, :java_classes_dir # #deprecated
|
133
|
-
|
146
|
+
|
134
147
|
def extensions
|
135
148
|
@extensions ||= begin
|
136
149
|
extensions = default_config[:extensions] || {}
|
@@ -164,7 +177,7 @@ module Trinidad
|
|
164
177
|
@logging ||= begin
|
165
178
|
defaults = {
|
166
179
|
:level => log, # backwards compatibility
|
167
|
-
:use_parent_handlers => environment == 'development',
|
180
|
+
:use_parent_handlers => ( environment == 'development' ),
|
168
181
|
:file => {
|
169
182
|
:dir => log_dir,
|
170
183
|
:prefix => environment,
|
@@ -175,35 +188,35 @@ module Trinidad
|
|
175
188
|
Trinidad::Configuration.merge_options(defaults, self[:logging])
|
176
189
|
end
|
177
190
|
end
|
178
|
-
|
191
|
+
|
179
192
|
def deployment_descriptor
|
180
193
|
return nil if @deployment_descriptor == false
|
181
194
|
@deployment_descriptor ||= expand_path(web_xml) || false
|
182
195
|
end
|
183
|
-
|
196
|
+
|
184
197
|
# @deprecated use {#deployment_descriptor}
|
185
198
|
def default_deployment_descriptor
|
186
199
|
return nil if @default_deployment_descriptor == false
|
187
200
|
@default_deployment_descriptor ||= expand_path(default_web_xml) || false
|
188
201
|
end
|
189
|
-
|
202
|
+
|
190
203
|
def public_root
|
191
204
|
@public_root ||= ( public_config[:root] || @@defaults[:public] )
|
192
205
|
end
|
193
206
|
alias_method :public, :public_root
|
194
|
-
|
207
|
+
|
195
208
|
# we do support nested :public configuration e.g. :
|
196
209
|
# public:
|
197
210
|
# root: /assets
|
198
211
|
# cache: true
|
199
212
|
# cache_ttl: 60000
|
200
213
|
def public_config
|
201
|
-
@public_config ||=
|
202
|
-
self[:public].is_a?(String) ?
|
203
|
-
{ :root => self[:public] } :
|
214
|
+
@public_config ||=
|
215
|
+
self[:public].is_a?(String) ?
|
216
|
+
{ :root => self[:public] } :
|
204
217
|
( self[:public] || {} )
|
205
218
|
end
|
206
|
-
|
219
|
+
|
207
220
|
def aliases # :public => { :aliases => ... }
|
208
221
|
return nil unless aliases = ( self[:aliases] || public_config[:aliases] )
|
209
222
|
return aliases if aliases.is_a?(String)
|
@@ -216,49 +229,47 @@ module Trinidad
|
|
216
229
|
"#{path}=#{File.expand_path(base, root_dir)}"
|
217
230
|
end.join(',')
|
218
231
|
end
|
219
|
-
|
232
|
+
|
220
233
|
def caching_allowed? # :public => { :cached => ... }
|
221
234
|
# ((BaseDirContext) resources).setCached(isCachingAllowed())
|
222
235
|
return @caching_allowed unless @caching_allowed.nil?
|
223
236
|
@caching_allowed = self[:caching_allowed]
|
224
237
|
if @caching_allowed.nil?
|
225
238
|
@caching_allowed = public_config[:cached]
|
226
|
-
if @caching_allowed.nil?
|
227
|
-
@caching_allowed = environment != 'development'
|
228
|
-
end
|
239
|
+
@caching_allowed = environment != 'development' if @caching_allowed.nil?
|
229
240
|
end
|
230
241
|
@caching_allowed = !! @caching_allowed
|
231
242
|
end
|
232
|
-
|
243
|
+
|
233
244
|
# The cache max size in kB
|
234
245
|
def cache_max_size # :public => { :cache_max_size => ... }
|
235
246
|
# ((BaseDirContext) resources).setCacheMaxSize
|
236
247
|
self[:cache_max_size] || public_config[:cache_max_size]
|
237
248
|
end
|
238
|
-
|
249
|
+
|
239
250
|
# The max size for a cached object in kB
|
240
251
|
def cache_object_max_size # :public => { :cache_object_max_size => ... }
|
241
252
|
# ((BaseDirContext) resources).setCacheObjectMaxSize
|
242
253
|
self[:cache_object_max_size] || public_config[:cache_object_max_size]
|
243
254
|
end
|
244
|
-
|
255
|
+
|
245
256
|
# Cache entry time-to-live in millis
|
246
257
|
def cache_ttl # :public => { :cache_ttl => ... }
|
247
258
|
# ((BaseDirContext) resources).setCacheTTL
|
248
259
|
self[:cache_ttl] || public_config[:cache_ttl]
|
249
260
|
end
|
250
|
-
|
261
|
+
|
251
262
|
def class_loader
|
252
|
-
@class_loader ||=
|
263
|
+
@class_loader ||=
|
253
264
|
org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
|
254
265
|
end
|
255
|
-
|
266
|
+
|
256
267
|
def class_loader!
|
257
268
|
( @class_loader = nil ) || class_loader
|
258
269
|
end
|
259
270
|
# @deprecated replaced with {#class_loader!}
|
260
271
|
def generate_class_loader; class_loader!; end
|
261
|
-
|
272
|
+
|
262
273
|
def define_lifecycle
|
263
274
|
Trinidad::Lifecycle::WebApp::Default.new(self)
|
264
275
|
end
|
@@ -266,16 +277,16 @@ module Trinidad
|
|
266
277
|
# Reset the hold web application state so it gets re-initialized.
|
267
278
|
# Please note that the configuration objects are not cleared.
|
268
279
|
def reset!
|
269
|
-
vars = instance_variables.map(&:to_sym)
|
280
|
+
vars = instance_variables.map(&:to_sym)
|
270
281
|
vars = vars - [ :'@config', :'@default_config' ]
|
271
282
|
vars.each { |var| instance_variable_set(var, nil) }
|
272
283
|
end
|
273
|
-
|
284
|
+
|
274
285
|
DEFAULT_SERVLET_CLASS = nil # by default we resolve by it's name
|
275
286
|
DEFAULT_SERVLET_NAME = 'default'
|
276
|
-
|
277
|
-
# Returns a servlet config for the DefaultServlet.
|
278
|
-
# This servlet is setup for each and every Tomcat context and is named
|
287
|
+
|
288
|
+
# Returns a servlet config for the DefaultServlet.
|
289
|
+
# This servlet is setup for each and every Tomcat context and is named
|
279
290
|
# 'default' and mapped to '/' we allow fine tunning of this servlet.
|
280
291
|
# Return values should be interpreted as follows :
|
281
292
|
# true - do nothing leave the servlet as set-up (by default)
|
@@ -304,12 +315,12 @@ module Trinidad
|
|
304
315
|
end
|
305
316
|
end
|
306
317
|
end
|
307
|
-
|
318
|
+
|
308
319
|
JSP_SERVLET_CLASS = nil # by default we resolve by it's name
|
309
320
|
JSP_SERVLET_NAME = 'jsp'
|
310
|
-
|
311
|
-
# Returns a servlet config for the JspServlet.
|
312
|
-
# This servlet is setup by default for every Tomcat context and is named
|
321
|
+
|
322
|
+
# Returns a servlet config for the JspServlet.
|
323
|
+
# This servlet is setup by default for every Tomcat context and is named
|
313
324
|
# 'jsp' with '*.jsp' and '*.jspx' mappings.
|
314
325
|
# Return values should be interpreted as follows :
|
315
326
|
# true - do nothing leave the servlet as set-up (by default)
|
@@ -329,25 +340,25 @@ module Trinidad
|
|
329
340
|
end
|
330
341
|
end
|
331
342
|
end
|
332
|
-
|
343
|
+
|
333
344
|
RACK_SERVLET_CLASS = 'org.jruby.rack.RackServlet'
|
334
345
|
RACK_SERVLET_NAME = 'rack' # in-case of a "custom" rack servlet class
|
335
346
|
RACK_FILTER_CLASS = 'org.jruby.rack.RackFilter'
|
336
347
|
RACK_FILTER_NAME = 'rack'
|
337
|
-
|
348
|
+
|
338
349
|
# Returns a config for the RackServlet or nil if no need to set-up one.
|
339
350
|
# (to be used for dispatching to this Rack / Rails web application)
|
340
351
|
def rack_servlet
|
341
352
|
return nil if @rack_servlet == false
|
342
353
|
@rack_servlet ||= begin
|
343
354
|
rack_servlet = self[:rack_servlet] || self[:servlet] || {}
|
344
|
-
|
355
|
+
|
345
356
|
if rack_servlet.is_a?(javax.servlet.Servlet)
|
346
357
|
{ :instance => rack_servlet, :name => RACK_SERVLET_NAME, :mapping => '/*' }
|
347
358
|
else
|
348
359
|
servlet_class = rack_servlet[:class] || RACK_SERVLET_CLASS
|
349
360
|
servlet_name = rack_servlet[:name] || RACK_SERVLET_NAME
|
350
|
-
|
361
|
+
|
351
362
|
if ! web_xml_servlet?(servlet_class, servlet_name) &&
|
352
363
|
! web_xml_filter?(RACK_FILTER_CLASS, RACK_FILTER_NAME)
|
353
364
|
{
|
@@ -361,7 +372,7 @@ module Trinidad
|
|
361
372
|
}
|
362
373
|
else
|
363
374
|
if ! rack_servlet.empty?
|
364
|
-
logger.info "
|
375
|
+
logger.info "Ignoring :rack_servlet configuration for " <<
|
365
376
|
"#{context_path} due #{deployment_descriptor}"
|
366
377
|
end
|
367
378
|
false # no need to setup a rack servlet
|
@@ -371,40 +382,40 @@ module Trinidad
|
|
371
382
|
end
|
372
383
|
# @deprecated use {#rack_servlet} instead
|
373
384
|
def servlet; rack_servlet; end
|
374
|
-
|
385
|
+
|
375
386
|
def rack_listener
|
376
387
|
context_listener unless web_xml_listener?(context_listener)
|
377
388
|
end
|
378
|
-
|
389
|
+
|
379
390
|
def war?; self.class.war?(config); end
|
380
391
|
|
381
392
|
def solo?
|
382
393
|
! is_a?(WarWebApp) && config[:solo]
|
383
394
|
end
|
384
|
-
|
395
|
+
|
385
396
|
def threadsafe?
|
386
397
|
jruby_min_runtimes == 1 && jruby_max_runtimes == 1
|
387
398
|
end
|
388
|
-
|
399
|
+
|
389
400
|
protected
|
390
|
-
|
401
|
+
|
391
402
|
def context_listener
|
392
403
|
raise NotImplementedError.new "context_listener expected to be redefined"
|
393
404
|
end
|
394
|
-
|
405
|
+
|
395
406
|
def layout_class
|
396
407
|
'JRuby::Rack::FileSystemLayout' # handles Rails as well as Rack
|
397
408
|
end
|
398
|
-
|
409
|
+
|
399
410
|
def complete_config!
|
400
411
|
config[:root_dir] ||= self.class.root_dir(config, default_config)
|
401
412
|
config[:root_dir] = File.expand_path(config[:root_dir])
|
402
413
|
config[:context_path] = self.class.context_path(config, default_config)
|
403
414
|
end
|
404
|
-
|
415
|
+
|
405
416
|
public
|
406
|
-
|
407
|
-
# Returns true if there's a servlet with the given servlet-class name
|
417
|
+
|
418
|
+
# Returns true if there's a servlet with the given servlet-class name
|
408
419
|
# configured or if the optional name second argument is given it also
|
409
420
|
# checks for a servlet with the given name.
|
410
421
|
def web_xml_servlet?(servlet_class, servlet_name = nil)
|
@@ -417,7 +428,7 @@ module Trinidad
|
|
417
428
|
servlet_xpath = "/web-app/servlet[servlet-name = '#{servlet_name}']"
|
418
429
|
return !! web_xml_doc.root.elements[servlet_xpath]
|
419
430
|
end
|
420
|
-
|
431
|
+
|
421
432
|
return false if servlet_class || servlet_name
|
422
433
|
raise ArgumentError, "nor servlet_class nor servlet_name given"
|
423
434
|
end
|
@@ -433,17 +444,17 @@ module Trinidad
|
|
433
444
|
filter_xpath = "/web-app/filter[filter-name = '#{filter_name}']"
|
434
445
|
return !! web_xml_doc.root.elements[filter_xpath]
|
435
446
|
end
|
436
|
-
|
447
|
+
|
437
448
|
return false if filter_class || filter_name
|
438
449
|
raise ArgumentError, "nor filter_class nor filter_name given"
|
439
450
|
end
|
440
|
-
|
451
|
+
|
441
452
|
# Returns true if a listener definition with a given listener-class is found.
|
442
453
|
def web_xml_listener?(listener_class)
|
443
454
|
return nil unless web_xml_doc
|
444
455
|
!! web_xml_doc.root.elements["/web-app/listener[listener-class = '#{listener_class}']"]
|
445
456
|
end
|
446
|
-
|
457
|
+
|
447
458
|
# Returns a param-value for a context-param with a given param-name.
|
448
459
|
def web_xml_context_param(name)
|
449
460
|
return nil unless web_xml_doc
|
@@ -451,9 +462,11 @@ module Trinidad
|
|
451
462
|
param.elements['param-value'].text
|
452
463
|
end
|
453
464
|
end
|
454
|
-
|
465
|
+
|
466
|
+
def web_xml_environment; nil; end
|
467
|
+
|
455
468
|
private
|
456
|
-
|
469
|
+
|
457
470
|
def web_xml_doc
|
458
471
|
return @web_xml_doc || nil unless @web_xml_doc.nil?
|
459
472
|
descriptor = deployment_descriptor
|
@@ -462,13 +475,13 @@ module Trinidad
|
|
462
475
|
require 'rexml/document'
|
463
476
|
@web_xml_doc = REXML::Document.new(File.read(descriptor))
|
464
477
|
rescue REXML::ParseException => e
|
465
|
-
logger.warn "
|
478
|
+
logger.warn "Invalid deployment descriptor:[#{descriptor}]\n #{e.message}"
|
466
479
|
@web_xml_doc = false
|
467
480
|
end
|
468
481
|
@web_xml_doc || nil
|
469
482
|
end
|
470
483
|
end
|
471
|
-
|
484
|
+
|
472
485
|
def expand_path(path)
|
473
486
|
if path
|
474
487
|
path_file = java.io.File.new(path)
|
@@ -484,7 +497,7 @@ module Trinidad
|
|
484
497
|
value = config[name]
|
485
498
|
value.nil? ? fetch_default_config_value(name, default) : value
|
486
499
|
end
|
487
|
-
|
500
|
+
|
488
501
|
def fetch_default_config_value(name, default = nil)
|
489
502
|
value = default_config[name]
|
490
503
|
if value.nil?
|
@@ -494,25 +507,25 @@ module Trinidad
|
|
494
507
|
end
|
495
508
|
value
|
496
509
|
end
|
497
|
-
|
510
|
+
|
498
511
|
def logger
|
499
512
|
@logger ||= Trinidad::Logging::LogFactory.getLog('')
|
500
513
|
end
|
501
|
-
|
514
|
+
|
502
515
|
protected
|
503
|
-
|
516
|
+
|
504
517
|
def self.rackup?(config, default_config = nil)
|
505
518
|
return true if config.has_key?(:rackup)
|
506
519
|
root_dir = root_dir(config, default_config)
|
507
520
|
config_ru = (default_config && default_config[:rackup]) || 'config.ru'
|
508
521
|
# check for rackup (but still use config/environment.rb for rails 3)
|
509
|
-
if File.exists?(File.join(root_dir, config_ru)) &&
|
522
|
+
if File.exists?(File.join(root_dir, config_ru)) &&
|
510
523
|
! rails?(config, default_config) # do not :rackup a rails app
|
511
524
|
config[:rackup] = config_ru
|
512
525
|
end
|
513
526
|
config[:rackup] || ! Dir[File.join(root_dir, 'WEB-INF/**/config.ru')].empty?
|
514
527
|
end
|
515
|
-
|
528
|
+
|
516
529
|
def self.rails?(config, default_config = nil)
|
517
530
|
root_dir = root_dir(config, default_config)
|
518
531
|
# standart Rails 3.x `class Application < Rails::Application`
|
@@ -528,26 +541,26 @@ module Trinidad
|
|
528
541
|
end
|
529
542
|
false
|
530
543
|
end
|
531
|
-
|
544
|
+
|
532
545
|
def self.war?(config, default_config = nil)
|
533
546
|
root_dir = root_dir(config, default_config)
|
534
547
|
return true if root_dir && root_dir.to_s[-4..-1] == '.war'
|
535
548
|
context_path = config[:context_path] # backwards-compatibility :
|
536
549
|
context_path && context_path.to_s[-4..-1] == '.war'
|
537
550
|
end
|
538
|
-
|
551
|
+
|
539
552
|
private
|
540
|
-
|
553
|
+
|
541
554
|
def self.root_dir(config, default_config, default_dir = Dir.pwd)
|
542
555
|
# for backwards compatibility accepts the :web_app_dir "alias"
|
543
|
-
config[:root_dir] || config[:web_app_dir] ||
|
544
|
-
( default_config &&
|
556
|
+
config[:root_dir] || config[:web_app_dir] ||
|
557
|
+
( default_config &&
|
545
558
|
( default_config[:root_dir] || default_config[:web_app_dir] ) ) ||
|
546
559
|
default_dir
|
547
560
|
end
|
548
|
-
|
561
|
+
|
549
562
|
def self.context_path(config, default_config = nil)
|
550
|
-
path = config[:context_path] ||
|
563
|
+
path = config[:context_path] ||
|
551
564
|
( default_config && default_config[:context_path] )
|
552
565
|
unless path
|
553
566
|
name = config[:context_name] ||
|
@@ -557,7 +570,7 @@ module Trinidad
|
|
557
570
|
path = "/#{path}" if path.to_s[0, 1] != '/'
|
558
571
|
path.to_s
|
559
572
|
end
|
560
|
-
|
573
|
+
|
561
574
|
def self.file_line_match?(path, pattern = nil)
|
562
575
|
File.open(path) do |file|
|
563
576
|
if block_given?
|
@@ -568,20 +581,20 @@ module Trinidad
|
|
568
581
|
end
|
569
582
|
false
|
570
583
|
end
|
571
|
-
|
584
|
+
|
572
585
|
class Holder
|
573
|
-
|
586
|
+
|
574
587
|
def initialize(web_app, context)
|
575
588
|
@web_app, @context = web_app, context
|
576
589
|
end
|
577
|
-
|
590
|
+
|
578
591
|
attr_reader :web_app
|
579
592
|
attr_accessor :context
|
580
|
-
|
593
|
+
|
581
594
|
def monitor; web_app.monitor; end
|
582
|
-
|
595
|
+
|
583
596
|
attr_accessor :monitor_mtime
|
584
|
-
|
597
|
+
|
585
598
|
def try_lock
|
586
599
|
locked? ? false : lock
|
587
600
|
end
|
@@ -589,7 +602,7 @@ module Trinidad
|
|
589
602
|
def locked?; !!@lock; end
|
590
603
|
def lock; @lock = true; end
|
591
604
|
def unlock; @lock = false; end
|
592
|
-
|
605
|
+
|
593
606
|
# #deprecated behaves Hash like for (<= 1.3.5) compatibility
|
594
607
|
def [](key)
|
595
608
|
case key.to_sym
|
@@ -619,11 +632,11 @@ module Trinidad
|
|
619
632
|
else raise NoMethodError, "#{key}="
|
620
633
|
end
|
621
634
|
end
|
622
|
-
|
635
|
+
|
623
636
|
end
|
624
|
-
|
637
|
+
|
625
638
|
end
|
626
|
-
|
639
|
+
|
627
640
|
# Rack web application (looks for a "rackup" *config.ru* file).
|
628
641
|
class RackupWebApp < WebApp
|
629
642
|
|
@@ -638,9 +651,11 @@ module Trinidad
|
|
638
651
|
end
|
639
652
|
|
640
653
|
def context_listener; 'org.jruby.rack.RackServletContextListener'; end
|
641
|
-
|
654
|
+
|
655
|
+
def web_xml_environment; web_xml_context_param('rack.env'); end
|
656
|
+
|
642
657
|
end
|
643
|
-
|
658
|
+
|
644
659
|
# Rails web application specifics (supports same versions as JRuby-Rack).
|
645
660
|
class RailsWebApp < WebApp
|
646
661
|
|
@@ -651,9 +666,11 @@ module Trinidad
|
|
651
666
|
end
|
652
667
|
|
653
668
|
def context_listener; 'org.jruby.rack.rails.RailsServletContextListener'; end
|
654
|
-
|
669
|
+
|
670
|
+
def web_xml_environment; web_xml_context_param('rails.env'); end
|
671
|
+
|
655
672
|
protected
|
656
|
-
|
673
|
+
|
657
674
|
def complete_config!
|
658
675
|
super
|
659
676
|
# detect threadsafe! in config/environments/environment.rb :
|
@@ -662,13 +679,13 @@ module Trinidad
|
|
662
679
|
config[:jruby_max_runtimes] = 1 unless key?(:jruby_max_runtimes, false)
|
663
680
|
end
|
664
681
|
end
|
665
|
-
|
682
|
+
|
666
683
|
#def layout_class
|
667
684
|
#'JRuby::Rack::RailsFileSystemLayout'
|
668
685
|
#end
|
669
|
-
|
686
|
+
|
670
687
|
private
|
671
|
-
|
688
|
+
|
672
689
|
def self.threadsafe?(app_base, environment)
|
673
690
|
threadsafe_match?("#{app_base}/config/environments/#{environment}.rb") ||
|
674
691
|
threadsafe_match?("#{app_base}/config/environment.rb")
|
@@ -682,12 +699,12 @@ module Trinidad
|
|
682
699
|
)
|
683
700
|
)
|
684
701
|
end
|
685
|
-
|
702
|
+
|
686
703
|
end
|
687
|
-
|
704
|
+
|
688
705
|
# A web application for deploying (java) .war files.
|
689
706
|
class WarWebApp < WebApp
|
690
|
-
|
707
|
+
|
691
708
|
def root_dir
|
692
709
|
@root_dir ||= ( config[:root_dir] || begin
|
693
710
|
path = config[:context_path]
|
@@ -708,7 +725,7 @@ module Trinidad
|
|
708
725
|
end
|
709
726
|
|
710
727
|
def log_dir
|
711
|
-
@log_dir ||= self[:log_dir] || begin
|
728
|
+
@log_dir ||= self[:log_dir] || begin
|
712
729
|
if work_dir then work_dir
|
713
730
|
else
|
714
731
|
if root_dir[-4..-1] == '.war'
|
@@ -721,11 +738,11 @@ module Trinidad
|
|
721
738
|
end
|
722
739
|
end
|
723
740
|
end
|
724
|
-
|
741
|
+
|
725
742
|
def monitor
|
726
743
|
root_dir ? File.expand_path(root_dir) : nil # the .war file itself
|
727
744
|
end
|
728
|
-
|
745
|
+
|
729
746
|
def class_loader
|
730
747
|
@class_loader ||= nil # lifecycle will setup JRuby CL
|
731
748
|
end
|
@@ -737,7 +754,7 @@ module Trinidad
|
|
737
754
|
def layout_class
|
738
755
|
'JRuby::Rack::WebInfLayout'
|
739
756
|
end
|
740
|
-
|
757
|
+
|
741
758
|
def define_lifecycle
|
742
759
|
Trinidad::Lifecycle::WebApp::War.new(self)
|
743
760
|
end
|
@@ -745,7 +762,7 @@ module Trinidad
|
|
745
762
|
private
|
746
763
|
|
747
764
|
def warbler?; nil; end # TODO detect warbler created .war ?!
|
748
|
-
|
765
|
+
|
749
766
|
end
|
750
|
-
|
767
|
+
|
751
768
|
end
|