trinidad 1.4.3 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,20 @@
1
+ == Trinidad 1.4.4 (2012-10-19)
2
+
3
+ * make sure setting FileHandler's rotatable to false works (#82)
4
+ * first draft for web-app logging configuration to avoid use hacks e.g.
5
+ for disabling rotation (this feature is not yet official and might change)
6
+ * fix new lines (ala default Rails.logger) in console output
7
+ * set correct (JRuby-Rack) layout for web apps and use app.root
8
+ (besides rails.root)
9
+ * check whether (jruby.) params are specified in system properties (#92)
10
+ * fix JUL::ConsoleHandler - not setting up JRuby streams correctly (#88)
11
+
12
+ == Trinidad_jars 1.1.1 (2012-10-17)
13
+
14
+ * Tomcat 7.0.32 http://tomcat.apache.org/tomcat-7.0-doc/changelog.html
15
+ * avoid using the "global" (and redundant) TRINIDAD_LIBS constant
16
+ * load the .jar files instead of requiring them (no more $: polution)
17
+
1
18
  == Trinidad 1.4.3 (2012-09-20)
2
19
 
3
20
  * allow to keep (and configure) the jsp servlet (support for serving .jsp pages)
data/README.md CHANGED
@@ -235,7 +235,7 @@ This monitor file can be customized with the `monitor` configuration option.
235
235
  Since version **1.4.0** Trinidad supports 2 reload strategies :
236
236
 
237
237
  * **restart** (default) synchronous reloading (exposed by Tomcat). This strategy
238
- pauses incoming requests while it reloads the application and than serves them
238
+ pauses incoming requests while it reloads the application and then serves them
239
239
  once ready (or timeouts if it takes too long). It has been chosen as the default
240
240
  strategy since **1.4.0** due it's more predictable memory requirements.
241
241
 
@@ -40,8 +40,10 @@ module Trinidad
40
40
  :public => 'public',
41
41
  :java_lib => 'lib/java',
42
42
  :default_web_xml => 'config/web.xml',
43
- :jruby_min_runtimes => 1,
44
- :jruby_max_runtimes => 5,
43
+ :jruby_min_runtimes =>
44
+ java.lang.System.getProperty('jruby.min.runtimes') || 1,
45
+ :jruby_max_runtimes =>
46
+ java.lang.System.getProperty('jruby.max.runtimes') || 5,
45
47
  :log => 'INFO',
46
48
  :trap => true
47
49
  }
@@ -110,6 +112,7 @@ module Trinidad
110
112
 
111
113
  # a Hash like deep_merge helper
112
114
  def self.merge_options(target, current, deep = true)
115
+ return target unless current
113
116
  target_dup = target.dup
114
117
  current.keys.each do |key|
115
118
  target_dup[key] =
@@ -15,13 +15,11 @@ module Trinidad
15
15
 
16
16
  root_logger = JUL::Logger.getLogger('')
17
17
  level = parse_log_level(log_level, :INFO)
18
-
19
- out_handler = JUL::ConsoleHandler.new
20
- out_handler.setOutputStream JRuby.runtime.out
18
+
19
+ out_handler = new_console_handler JRuby.runtime.out
21
20
  out_handler.formatter = console_formatter
22
21
 
23
- err_handler = JUL::ConsoleHandler.new
24
- err_handler.setOutputStream JRuby.runtime.err
22
+ err_handler = new_console_handler JRuby.runtime.err
25
23
  err_handler.formatter = console_formatter
26
24
  err_handler.level = level.intValue > JUL::Level::WARNING.intValue ?
27
25
  level : JUL::Level::WARNING # only >= WARNING on STDERR
@@ -69,16 +67,24 @@ module Trinidad
69
67
  logger = JUL::Logger.getLogger(logger_name) # exclusive for web app
70
68
  # avoid duplicate calls - do not configure our FileHandler twice :
71
69
  return false if logger.handlers.find { |h| h.is_a?(FileHandler) }
72
- level = parse_log_level(web_app.log, nil)
73
- logger.level = level # inherits level from parent if nil
70
+ logging = web_app.logging
71
+ logger.level = parse_log_level(logging[:level], nil)
74
72
  # delegate to root (console) output only in development mode :
75
- logger.use_parent_handlers = ( web_app.environment == 'development' )
76
-
77
- prefix, suffix = web_app.environment, '.log' # {prefix}{date}{suffix}
78
- file_handler = FileHandler.new(web_app.log_dir, prefix, suffix)
79
- file_handler.rotatable = true # {prefix}{date}{suffix}
80
- file_handler.formatter = web_app_formatter
81
- logger.add_handler(file_handler)
73
+ logger.use_parent_handlers = logging[:use_parent_handlers]
74
+ # logging:
75
+ # file:
76
+ # dir: log # [RAILS_ROOT]/log
77
+ # prefix: production
78
+ # suffix: .log
79
+ if file = logging[:file]
80
+ prefix, suffix = file[:prefix], file[:suffix] # {prefix}{date}{suffix}
81
+ file_handler = FileHandler.new(file[:dir] || file[:directory], prefix, suffix)
82
+ file_handler.rotatable = file.key?(:rotatable) ? file[:rotatable] : file[:rotate]
83
+ file_handler.buffer_size = file[:buffer_size] if file[:buffer_size]
84
+ format = file.key?(:format) ? file[:format] : logging[:format]
85
+ file_handler.formatter = web_app_formatter(format) # nil uses default
86
+ logger.add_handler(file_handler)
87
+ end
82
88
  logger
83
89
  end
84
90
 
@@ -88,9 +94,9 @@ module Trinidad
88
94
  MessageFormatter.new
89
95
  end
90
96
 
91
- def self.web_app_formatter
97
+ def self.web_app_formatter(format = nil)
92
98
  # format used by Rails "2012-06-13 16:42:21 +0200"
93
- DefaultFormatter.new("yyyy-MM-dd HH:mm:ss Z")
99
+ DefaultFormatter.new(format.nil? ? 'yyyy-MM-dd HH:mm:ss Z' : format)
94
100
  end
95
101
 
96
102
  private
@@ -122,6 +128,24 @@ module Trinidad
122
128
  context.find_parameter(name) || web_app.web_xml_context_param(name)
123
129
  end
124
130
 
131
+ JUL::ConsoleHandler.class_eval do
132
+ field_accessor :sealed rescue nil
133
+ field_writer :writer rescue nil
134
+ end
135
+
136
+ def self.new_console_handler(stream)
137
+ handler = JUL::ConsoleHandler.new # sets output stream to System.err
138
+ handler.writer = nil if handler.respond_to?(:writer=) # avoid writer.close
139
+ if handler.respond_to?(:sealed) && handler.sealed
140
+ handler.sealed = false # avoid manager security checks
141
+ handler.setOutputStream(stream) # closes previous writer if != null
142
+ handler.sealed = true
143
+ else
144
+ handler.setOutputStream(stream)
145
+ end
146
+ handler
147
+ end
148
+
125
149
  # we'd achieve logging to a production.log file while rotating it (daily)
126
150
  class FileHandler < Java::OrgApacheJuli::FileHandler # :nodoc
127
151
 
@@ -133,7 +157,7 @@ module Trinidad
133
157
 
134
158
  def initialize(directory, prefix, suffix)
135
159
  super(directory, prefix, suffix)
136
- self._date = '' # to openWriter on first #publish(record)
160
+ self._date = nil # to openWriter on first #publish(record)
137
161
  end
138
162
 
139
163
  def openWriter
@@ -223,7 +247,7 @@ module Trinidad
223
247
  msg << formatThrown(record).to_s
224
248
  # since we're going to print Rails.logger logs and they tend
225
249
  # to already have the ending "\n" handle such cases nicely :
226
- if web_app_path(record.getLoggerName)
250
+ if context_name(record.getLoggerName)
227
251
  (lns = LINE_SEP) == msg[-1, 1] ? msg : msg << lns
228
252
  else
229
253
  msg << LINE_SEP
@@ -231,10 +255,11 @@ module Trinidad
231
255
  end
232
256
 
233
257
  # e.g. org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/foo]
234
- WEB_APP_LOGGER_NAME = /org\.apache\.catalina\.core\.ContainerBase.*?\[(\/.*?)\]$/
258
+ # or org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[default]
259
+ WEB_APP_LOGGER_NAME = /^org\.apache\.catalina\.core\.ContainerBase.*?\[(.*?)\]$/
235
260
 
236
261
  private
237
- def web_app_path(name)
262
+ def context_name(name)
238
263
  ( match = (name || '').match(WEB_APP_LOGGER_NAME) ) && match[1]
239
264
  end
240
265
 
@@ -190,7 +190,7 @@ module Trinidad
190
190
  # We must create them before creating the applications.
191
191
  @config[:web_apps].each do |_, app_config|
192
192
  if host_names = app_config.delete(:hosts)
193
- dir = app_config[:web_app_dir] || Dir.pwd
193
+ dir = web_app_root_dir(app_config)
194
194
  apps_base = File.dirname(dir) == '.' ? dir : File.dirname(dir)
195
195
  app_config[:host] = create_host(apps_base, host_names)
196
196
  end
@@ -225,10 +225,10 @@ module Trinidad
225
225
  private
226
226
 
227
227
  def add_default_web_app!(config)
228
- if !config[:web_apps] && !config[:apps_base] && !config[:hosts]
228
+ if ! config[:web_apps] && ! config[:apps_base] && ! config[:hosts]
229
229
  default_app = {
230
230
  :context_path => config[:context_path],
231
- :web_app_dir => config[:web_app_dir] || Dir.pwd,
231
+ :root_dir => web_app_root_dir(config),
232
232
  :log => config[:log]
233
233
  }
234
234
  default_app[:rackup] = config[:rackup] if config[:rackup]
@@ -237,6 +237,10 @@ module Trinidad
237
237
  end
238
238
  end
239
239
 
240
+ def web_app_root_dir(config, default = Dir.pwd)
241
+ config[:root_dir] || config[:web_app_dir] || default
242
+ end
243
+
240
244
  def generate_default_keystore(config)
241
245
  keystore_file = java.io.File.new(config[:keystoreFile])
242
246
 
@@ -1,3 +1,3 @@
1
1
  module Trinidad
2
- VERSION = '1.4.3'
2
+ VERSION = '1.4.4'
3
3
  end
@@ -30,12 +30,13 @@ module Trinidad
30
30
  use_default ? default_config.key?(key) : false
31
31
  end
32
32
 
33
- %w{ root_dir jruby_compat_version
34
- rackup log async_supported reload_strategy }.each do |method|
33
+ %w{ root_dir rackup log async_supported reload_strategy }.each do |method|
35
34
  class_eval "def #{method}; self[:'#{method}']; end"
36
35
  end
37
36
  alias_method :web_app_dir, :root_dir # is getting deprecated soon
38
37
 
38
+ def app_root; root_dir; end
39
+
39
40
  def context_path
40
41
  path = self[:context_path] || self[:path]
41
42
  path ? path.to_s : path
@@ -54,7 +55,7 @@ module Trinidad
54
55
  if min = config[:jruby_min_runtimes]
55
56
  return min.to_i # min specified overrides :threadsafe
56
57
  else # but :threadsafe takes precendence over default :
57
- self[:threadsafe] ? 1 : default_config[:jruby_min_runtimes]
58
+ self[:threadsafe] ? 1 : fetch_default_config_value(:jruby_min_runtimes)
58
59
  end
59
60
  end
60
61
 
@@ -62,12 +63,25 @@ module Trinidad
62
63
  if max = config[:jruby_max_runtimes]
63
64
  return max.to_i # max specified overrides :threadsafe
64
65
  else # but :threadsafe takes precendence over default :
65
- self[:threadsafe] ? 1 : default_config[:jruby_max_runtimes]
66
+ self[:threadsafe] ? 1 : fetch_default_config_value(:jruby_max_runtimes)
67
+ end
68
+ end
69
+
70
+ def jruby_initial_runtimes
71
+ if ini = config[:jruby_initial_runtimes]
72
+ return ini.to_i # min specified overrides :threadsafe
73
+ else # but :threadsafe takes precendence over default :
74
+ self[:threadsafe] ? 1 :
75
+ fetch_default_config_value(:jruby_initial_runtimes, jruby_min_runtimes)
66
76
  end
67
77
  end
68
78
 
69
79
  def jruby_runtime_acquire_timeout
70
- self[:jruby_runtime_acquire_timeout] || 5.0 # default 10s seems too high
80
+ fetch_config_value(:jruby_runtime_acquire_timeout, 5.0) # default 10s seems too high
81
+ end
82
+
83
+ def jruby_compat_version
84
+ fetch_config_value(:jruby_compat_version, RUBY_VERSION)
71
85
  end
72
86
 
73
87
  def environment; self[:environment] || @@defaults[:environment]; end # TODO check web.xml
@@ -125,10 +139,11 @@ module Trinidad
125
139
  @context_params ||= {}
126
140
  add_context_param 'jruby.min.runtimes', jruby_min_runtimes
127
141
  add_context_param 'jruby.max.runtimes', jruby_max_runtimes
128
- add_context_param 'jruby.initial.runtimes', jruby_min_runtimes
142
+ add_context_param 'jruby.initial.runtimes', jruby_initial_runtimes
129
143
  add_context_param 'jruby.runtime.acquire.timeout', jruby_runtime_acquire_timeout
130
- add_context_param 'jruby.compat.version', jruby_compat_version || RUBY_VERSION
131
- add_context_param 'public.root', File.join('/', public_root)
144
+ add_context_param 'jruby.compat.version', jruby_compat_version
145
+ add_context_param 'public.root', public_root
146
+ add_context_param 'jruby.rack.layout_class', layout_class
132
147
  @context_params
133
148
  end
134
149
  # @deprecated replaced with {#context_params}
@@ -141,6 +156,22 @@ module Trinidad
141
156
  end
142
157
  end
143
158
 
159
+ def logging
160
+ @logging ||= begin
161
+ defaults = {
162
+ :level => log, # backwards compatibility
163
+ :use_parent_handlers => environment == 'development',
164
+ :file => {
165
+ :dir => log_dir,
166
+ :prefix => environment,
167
+ :suffix => '.log',
168
+ :rotate => true
169
+ }
170
+ }
171
+ Trinidad::Configuration.merge_options(defaults, self[:logging])
172
+ end
173
+ end
174
+
144
175
  def deployment_descriptor
145
176
  return nil if @deployment_descriptor == false
146
177
  @deployment_descriptor ||= expand_path(web_xml) || false
@@ -357,8 +388,25 @@ module Trinidad
357
388
  raise NotImplementedError.new "context_listener expected to be redefined"
358
389
  end
359
390
 
391
+ if Gem::Version.create(JRuby::Rack::VERSION) > Gem::Version.create('1.1.10')
392
+ def layout_class
393
+ 'JRuby::Rack::FileSystemLayout' # handles Rails as well as Rack
394
+ end
395
+ else
396
+ def layout_class
397
+ # NOTE: we'll also need to do a GEM_PATH hack to avoid a bug :
398
+ if gem_path = ENV['GEM_PATH']
399
+ add_context_param 'gem.path', gem_path
400
+ # ENV['GEM_PATH'] will contain twice the same entry(ies) ...
401
+ end
402
+ add_context_param 'rails.root', app_root # still boots a rack app
403
+ 'JRuby::Rack::RailsFilesystemLayout' # no plain FS layout defined !
404
+ end
405
+ end
406
+
360
407
  def complete_config!
361
408
  config[:root_dir] ||= self.class.root_dir(config, default_config)
409
+ config[:root_dir] = File.expand_path(config[:root_dir])
362
410
  config[:context_path] = self.class.context_path(config, default_config)
363
411
  end
364
412
 
@@ -439,6 +487,21 @@ module Trinidad
439
487
  end
440
488
  end
441
489
  end
490
+
491
+ def fetch_config_value(name, default = nil)
492
+ value = config[name]
493
+ value.nil? ? fetch_default_config_value(name, default) : value
494
+ end
495
+
496
+ def fetch_default_config_value(name, default = nil)
497
+ value = default_config[name]
498
+ if value.nil?
499
+ # JRuby-Rack names: jruby_min_runtimes -> jruby.min.runtimes :
500
+ value = java.lang.System.getProperty(name.to_s.gsub('_', '.'))
501
+ value ||= default
502
+ end
503
+ value
504
+ end
442
505
 
443
506
  def logger
444
507
  @logger ||= Trinidad::Logging::LogFactory.getLog('')
@@ -570,6 +633,7 @@ module Trinidad
570
633
  class RackupWebApp < WebApp
571
634
 
572
635
  def context_params
636
+ add_context_param 'app.root', app_root
573
637
  add_context_param 'rack.env', environment
574
638
  if rackup = self.rackup
575
639
  rackup = File.join(rackup, 'config.ru') if File.directory?(rackup)
@@ -586,8 +650,8 @@ module Trinidad
586
650
  class RailsWebApp < WebApp
587
651
 
588
652
  def context_params
653
+ add_context_param 'rails.root', app_root
589
654
  add_context_param 'rails.env', environment
590
- add_context_param 'rails.root', '/'
591
655
  super
592
656
  end
593
657
 
@@ -604,6 +668,10 @@ module Trinidad
604
668
  end
605
669
  end
606
670
 
671
+ #def layout_class
672
+ #'JRuby::Rack::RailsFileSystemLayout'
673
+ #end
674
+
607
675
  private
608
676
 
609
677
  def self.threadsafe?(app_base, environment)
@@ -623,7 +691,7 @@ module Trinidad
623
691
  def context_path
624
692
  super.gsub(/\.war$/, '')
625
693
  end
626
-
694
+
627
695
  def log_dir
628
696
  @log_dir ||= self[:log_dir] || File.join(work_dir, 'log')
629
697
  end
@@ -640,6 +708,10 @@ module Trinidad
640
708
  Trinidad::Lifecycle::WebApp::War.new(self)
641
709
  end
642
710
 
711
+ def layout_class
712
+ 'JRuby::Rack::WebInfLayout'
713
+ end
714
+
643
715
  end
644
716
 
645
717
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: trinidad
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.4.3
5
+ version: 1.4.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Calavera
@@ -10,96 +10,96 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-09-20 00:00:00 Z
13
+ date: 2012-10-19 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: trinidad_jars
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ version_requirements: &id001 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
21
20
  - - ">="
22
21
  - !ruby/object:Gem::Version
23
22
  version: 1.1.0
23
+ requirement: *id001
24
+ prerelease: false
24
25
  type: :runtime
25
- version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: jruby-rack
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
28
+ version_requirements: &id002 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
32
31
  - - ">="
33
32
  - !ruby/object:Gem::Version
34
33
  version: 1.1.10
34
+ requirement: *id002
35
+ prerelease: false
35
36
  type: :runtime
36
- version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rack
39
- prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ version_requirements: &id003 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
42
  - - ">="
44
43
  - !ruby/object:Gem::Version
45
44
  version: "0"
45
+ requirement: *id003
46
+ prerelease: false
46
47
  type: :development
47
- version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rake
50
- prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
50
+ version_requirements: &id004 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
54
53
  - - ">="
55
54
  - !ruby/object:Gem::Version
56
55
  version: "0"
56
+ requirement: *id004
57
+ prerelease: false
57
58
  type: :development
58
- version_requirements: *id004
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rspec
61
- prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
61
+ version_requirements: &id005 !ruby/object:Gem::Requirement
63
62
  none: false
64
63
  requirements:
65
64
  - - ~>
66
65
  - !ruby/object:Gem::Version
67
66
  version: "2.10"
67
+ requirement: *id005
68
+ prerelease: false
68
69
  type: :development
69
- version_requirements: *id005
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: mocha
72
- prerelease: false
73
- requirement: &id006 !ruby/object:Gem::Requirement
72
+ version_requirements: &id006 !ruby/object:Gem::Requirement
74
73
  none: false
75
74
  requirements:
76
75
  - - ">="
77
76
  - !ruby/object:Gem::Version
78
77
  version: "0"
78
+ requirement: *id006
79
+ prerelease: false
79
80
  type: :development
80
- version_requirements: *id006
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: fakefs
83
- prerelease: false
84
- requirement: &id007 !ruby/object:Gem::Requirement
83
+ version_requirements: &id007 !ruby/object:Gem::Requirement
85
84
  none: false
86
85
  requirements:
87
86
  - - ">="
88
87
  - !ruby/object:Gem::Version
89
88
  version: 0.4.0
89
+ requirement: *id007
90
+ prerelease: false
90
91
  type: :development
91
- version_requirements: *id007
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: sinatra
94
- prerelease: false
95
- requirement: &id008 !ruby/object:Gem::Requirement
94
+ version_requirements: &id008 !ruby/object:Gem::Requirement
96
95
  none: false
97
96
  requirements:
98
97
  - - ">="
99
98
  - !ruby/object:Gem::Version
100
99
  version: "0"
100
+ requirement: *id008
101
+ prerelease: false
101
102
  type: :development
102
- version_requirements: *id008
103
103
  description: Trinidad allows you to run Rails or Rack applications within an embedded Apache Tomcat container. Serves your requests with the elegance of a cat !
104
104
  email: calavera@apache.org
105
105
  executables:
@@ -147,17 +147,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - ">="
149
149
  - !ruby/object:Gem::Version
150
+ hash: 2
151
+ segments:
152
+ - 0
150
153
  version: "0"
151
154
  required_rubygems_version: !ruby/object:Gem::Requirement
152
155
  none: false
153
156
  requirements:
154
157
  - - ">="
155
158
  - !ruby/object:Gem::Version
159
+ hash: 2
160
+ segments:
161
+ - 0
156
162
  version: "0"
157
163
  requirements: []
158
164
 
159
165
  rubyforge_project:
160
- rubygems_version: 1.8.15
166
+ rubygems_version: 1.8.24
161
167
  signing_key:
162
168
  specification_version: 3
163
169
  summary: Web server for Rails/Rack applications built upon JRuby::Rack and Apache Tomcat