trinidad 1.4.6 → 1.5.0.B1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Trinidad
2
- VERSION = '1.4.6'
2
+ VERSION = '1.5.0.B1'
3
3
  end
@@ -63,23 +63,25 @@ module Trinidad
63
63
  def jruby_min_runtimes
64
64
  if min = config[:jruby_min_runtimes]
65
65
  return min.to_i # min specified overrides :threadsafe
66
- else # but :threadsafe takes precendence over default :
67
- self[:threadsafe] ? 1 : fetch_default_config_value(:jruby_min_runtimes)
66
+ else # but :threadsafe takes precedence over default
67
+ # (if no default value specified we'll end up thread-safe) :
68
+ self[:threadsafe] ? 1 : fetch_default_config_value(:jruby_min_runtimes, 1)
68
69
  end
69
70
  end
70
71
 
71
72
  def jruby_max_runtimes
72
73
  if max = config[:jruby_max_runtimes]
73
74
  return max.to_i # max specified overrides :threadsafe
74
- else # but :threadsafe takes precendence over default :
75
- self[:threadsafe] ? 1 : fetch_default_config_value(:jruby_max_runtimes)
75
+ else # but :threadsafe takes precedence over default
76
+ # (if no default value specified we'll end up thread-safe) :
77
+ self[:threadsafe] ? 1 : fetch_default_config_value(:jruby_max_runtimes, 1)
76
78
  end
77
79
  end
78
80
 
79
81
  def jruby_initial_runtimes
80
82
  if ini = config[:jruby_initial_runtimes]
81
83
  return ini.to_i # min specified overrides :threadsafe
82
- else # but :threadsafe takes precendence over default :
84
+ else # but :threadsafe takes precedence over default :
83
85
  self[:threadsafe] ? 1 :
84
86
  fetch_default_config_value(:jruby_initial_runtimes, jruby_min_runtimes)
85
87
  end
@@ -131,24 +133,30 @@ module Trinidad
131
133
  def default_web_xml; self[:default_web_xml]; end
132
134
 
133
135
  def java_lib
134
- # accepts #deprecated :libs_dir syntax
135
- self[:java_lib] || self[:libs_dir] || @@defaults[:java_lib]
136
+ self[:java_lib] || begin
137
+ if libs_dir = self[:libs_dir] # @deprecated
138
+ Helpers.deprecate "please use :java_lib instead of :libs_dir"
139
+ end
140
+ libs_dir || @@defaults[:java_lib]
141
+ end
136
142
  end
137
143
 
138
144
  def java_classes
139
- # accepts #deprecated :classes_dir syntax
140
- self[:java_classes] || self[:classes_dir] || File.join(java_lib, 'classes')
145
+ self[:java_classes] || begin
146
+ if classes_dir = self[:classes_dir] # @deprecated
147
+ Helpers.deprecate "please use :java_classes instead of :classes_dir"
148
+ end
149
+ classes_dir || File.join(java_lib, 'classes')
150
+ end
141
151
  end
142
152
 
143
153
  def java_lib_dir
144
154
  @java_lib_dir ||= self[:java_lib_dir] || expand_path(java_lib)
145
155
  end
146
- alias_method :libs_dir, :java_lib_dir # #deprecated
147
156
 
148
157
  def java_classes_dir
149
158
  @java_classes_dir ||= self[:java_classes_dir] || expand_path(java_classes)
150
159
  end
151
- alias_method :classes_dir, :java_classes_dir # #deprecated
152
160
 
153
161
  def extensions
154
162
  @extensions ||= begin
@@ -161,11 +169,14 @@ module Trinidad
161
169
  @context_params ||= {}
162
170
  add_context_param 'jruby.min.runtimes', jruby_min_runtimes
163
171
  add_context_param 'jruby.max.runtimes', jruby_max_runtimes
164
- add_context_param 'jruby.initial.runtimes', jruby_initial_runtimes
165
- add_context_param 'jruby.runtime.acquire.timeout', jruby_runtime_acquire_timeout
172
+ unless threadsafe?
173
+ add_context_param 'jruby.initial.runtimes', jruby_initial_runtimes
174
+ add_context_param 'jruby.runtime.acquire.timeout', jruby_runtime_acquire_timeout
175
+ end
166
176
  add_context_param 'jruby.compat.version', jruby_compat_version
167
177
  add_context_param 'public.root', public_root
168
178
  add_context_param 'jruby.rack.layout_class', layout_class
179
+ # JRuby::Rack::ErrorApp got a bit smarter so use it, TODO maybe override ?
169
180
  add_context_param 'jruby.rack.error', false # do not start error app on errors
170
181
  @context_params
171
182
  end
@@ -220,10 +231,9 @@ module Trinidad
220
231
  # cache: true
221
232
  # cache_ttl: 60000
222
233
  def public_config
223
- @public_config ||=
224
- self[:public].is_a?(String) ?
225
- { :root => self[:public] } :
226
- ( self[:public] || {} )
234
+ @public_config ||= begin; public = self[:public]
235
+ public.is_a?(String) ? { :root => public } : ( public || {} )
236
+ end
227
237
  end
228
238
 
229
239
  def aliases # :public => { :aliases => ... }
@@ -268,17 +278,6 @@ module Trinidad
268
278
  self[:cache_ttl] || public_config[:cache_ttl]
269
279
  end
270
280
 
271
- def class_loader
272
- @class_loader ||=
273
- org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
274
- end
275
-
276
- def class_loader!
277
- ( @class_loader = nil ) || class_loader
278
- end
279
- # @deprecated replaced with {#class_loader!}
280
- def generate_class_loader; class_loader!; end
281
-
282
281
  def define_lifecycle
283
282
  Lifecycle::WebApp::Default.new(self)
284
283
  end
@@ -420,8 +419,25 @@ module Trinidad
420
419
  config[:root_dir] ||= self.class.root_dir(config, default_config)
421
420
  config[:root_dir] = File.expand_path(config[:root_dir])
422
421
  config[:context_path] = self.class.context_path(config, default_config)
422
+
423
+ return if key?(:jruby_max_runtimes) || key?(:jruby_min_runtimes)
424
+
425
+ if ( ! key?(:threadsafe) && ! detect_threadsafe? ) || self[:threadsafe] == false
426
+ max_runtimes = config[:jruby_max_runtimes] = guess_max_runtimes
427
+ if environment == 'development' || environment == 'test'
428
+ config[:jruby_min_runtimes] = 1
429
+ else
430
+ config[:jruby_min_runtimes] = max_runtimes
431
+ end
432
+ else
433
+ config[:jruby_min_runtimes] = config[:jruby_max_runtimes] = 1
434
+ end
423
435
  end
424
436
 
437
+ def detect_threadsafe?(environment = self.environment); true end
438
+
439
+ def guess_max_runtimes; 5 end
440
+
425
441
  public
426
442
 
427
443
  # Returns true if there's a servlet with the given servlet-class name
@@ -511,7 +527,7 @@ module Trinidad
511
527
  value = default_config[name]
512
528
  if value.nil?
513
529
  # JRuby-Rack names: jruby_min_runtimes -> jruby.min.runtimes :
514
- value = java.lang.System.getProperty(name.to_s.gsub('_', '.'))
530
+ value = ENV_JAVA[ name.to_s.gsub('_', '.') ]
515
531
  value ||= default
516
532
  end
517
533
  value
@@ -521,74 +537,76 @@ module Trinidad
521
537
  @logger ||= Logging::LogFactory.getLog('')
522
538
  end
523
539
 
524
- protected
540
+ class << self
525
541
 
526
- def self.rackup?(config, default_config = nil)
527
- return true if config.has_key?(:rackup)
528
- root_dir = root_dir(config, default_config)
529
- config_ru = (default_config && default_config[:rackup]) || 'config.ru'
530
- # check for rackup (but still use config/environment.rb for rails 3)
531
- if File.exists?(File.join(root_dir, config_ru)) &&
532
- ! rails?(config, default_config) # do not :rackup a rails app
533
- config[:rackup] = config_ru
534
- end
535
- config[:rackup] || ! Dir[File.join(root_dir, 'WEB-INF/**/config.ru')].empty?
536
- end
537
-
538
- def self.rails?(config, default_config = nil)
539
- root_dir = root_dir(config, default_config)
540
- # standart Rails 3.x `class Application < Rails::Application`
541
- if File.exists?(application = File.join(root_dir, 'config/application.rb'))
542
- return true if file_line_match?(application, /^[^#]*Rails::Application/)
543
- end
544
- if File.exists?(environment = File.join(root_dir, 'config/environment.rb'))
545
- return true if file_line_match?(environment) do |line|
546
- # customized Rails 3.x, expects a `Rails::Application` subclass
547
- # or a plain-old Rails 2.3 with `RAILS_GEM_VERSION = '2.3.14'`
548
- line =~ /^[^#]*Rails::Application/ || line =~ /^[^#]*RAILS_GEM_VERSION/
542
+ def rackup?(config, default_config = nil)
543
+ return true if config.has_key?(:rackup)
544
+ root_dir = root_dir(config, default_config)
545
+ config_ru = (default_config && default_config[:rackup]) || 'config.ru'
546
+ # check for rackup (but still use config/environment.rb for rails 3)
547
+ if File.exists?(File.join(root_dir, config_ru)) &&
548
+ ! rails?(config, default_config) # do not :rackup a rails app
549
+ config[:rackup] = config_ru
549
550
  end
551
+ config[:rackup] || ! Dir[File.join(root_dir, 'WEB-INF/**/config.ru')].empty?
550
552
  end
551
- false
552
- end
553
553
 
554
- def self.war?(config, default_config = nil)
555
- root_dir = root_dir(config, default_config)
556
- return true if root_dir && root_dir.to_s[-4..-1] == '.war'
557
- context_path = config[:context_path] # backwards-compatibility :
558
- context_path && context_path.to_s[-4..-1] == '.war'
559
- end
554
+ def rails?(config, default_config = nil)
555
+ root_dir = root_dir(config, default_config)
556
+ # standard Rails 3.x/4.x `class Application < Rails::Application`
557
+ if File.exists?(application = File.join(root_dir, 'config/application.rb'))
558
+ return true if file_line_match?(application, /^[^#]*Rails::Application/)
559
+ end
560
+ if File.exists?(environment = File.join(root_dir, 'config/environment.rb'))
561
+ return true if file_line_match?(environment) do |line|
562
+ # customized Rails >= 3.x, expects a `Rails::Application` subclass
563
+ # or a plain-old Rails 2.3 with `RAILS_GEM_VERSION = '2.3.14'`
564
+ line =~ /^[^#]*Rails::Application/ || line =~ /^[^#]*RAILS_GEM_VERSION/
565
+ end
566
+ end
567
+ false
568
+ end
560
569
 
561
- private
570
+ def war?(config, default_config = nil)
571
+ root_dir = root_dir(config, default_config)
572
+ return true if root_dir && root_dir.to_s[-4..-1] == '.war'
573
+ context_path = config[:context_path] # backwards-compatibility :
574
+ context_path && context_path.to_s[-4..-1] == '.war'
575
+ end
562
576
 
563
- def self.root_dir(config, default_config, default_dir = Dir.pwd)
564
- # for backwards compatibility accepts the :web_app_dir "alias"
565
- config[:root_dir] || config[:web_app_dir] ||
566
- ( default_config &&
567
- ( default_config[:root_dir] || default_config[:web_app_dir] ) ) ||
568
- default_dir
569
- end
577
+ def root_dir(config, default_config, default_dir = Dir.pwd)
578
+ # for backwards compatibility accepts the :web_app_dir "alias"
579
+ config[:root_dir] || config[:web_app_dir] ||
580
+ ( default_config &&
581
+ ( default_config[:root_dir] || default_config[:web_app_dir] ) ) ||
582
+ default_dir
583
+ end
570
584
 
571
- def self.context_path(config, default_config = nil)
572
- path = config[:context_path] ||
573
- ( default_config && default_config[:context_path] )
574
- unless path
575
- name = config[:context_name] ||
576
- ( default_config && default_config[:context_name] )
577
- path = name.to_s == 'default' ? '/' : "/#{name}"
585
+ def context_path(config, default_config = nil)
586
+ path = config[:context_path] ||
587
+ ( default_config && default_config[:context_path] )
588
+ unless path
589
+ name = config[:context_name] ||
590
+ ( default_config && default_config[:context_name] )
591
+ path = name.to_s == 'default' ? '/' : "/#{name}"
592
+ end
593
+ path = "/#{path}" if path.to_s[0, 1] != '/'
594
+ path.to_s
578
595
  end
579
- path = "/#{path}" if path.to_s[0, 1] != '/'
580
- path.to_s
581
- end
582
596
 
583
- def self.file_line_match?(path, pattern = nil)
584
- File.open(path) do |file|
585
- if block_given?
586
- file.each_line { |line| return true if yield(line) }
587
- else
588
- file.each_line { |line| return true if line =~ pattern }
597
+ private
598
+
599
+ def file_line_match?(path, pattern = nil)
600
+ File.open(path) do |file|
601
+ if block_given?
602
+ file.each_line { |line| return true if yield(line) }
603
+ else
604
+ file.each_line { |line| return true if line =~ pattern }
605
+ end
589
606
  end
607
+ false
590
608
  end
591
- false
609
+
592
610
  end
593
611
 
594
612
  class Holder
@@ -612,36 +630,6 @@ module Trinidad
612
630
  def lock; @lock = true; end
613
631
  def unlock; @lock = false; end
614
632
 
615
- # #deprecated behaves Hash like for (<= 1.3.5) compatibility
616
- def [](key)
617
- case key.to_sym
618
- when :app then
619
- web_app
620
- when :context then
621
- context
622
- when :lock then
623
- @lock
624
- when :monitor then
625
- monitor
626
- when :mtime then
627
- monitor_mtime
628
- else raise NoMethodError, key.to_s
629
- end
630
- end
631
-
632
- # #deprecated behaves Hash like for (<= 1.3.5) compatibility
633
- def []=(key, val)
634
- case key.to_sym
635
- when :context then
636
- self.context=(val)
637
- when :lock then
638
- @lock = val
639
- when :mtime then
640
- self.monitor_mtime=(val)
641
- else raise NoMethodError, "#{key}="
642
- end
643
- end
644
-
645
633
  end
646
634
 
647
635
  end
@@ -681,21 +669,42 @@ module Trinidad
681
669
 
682
670
  protected
683
671
 
684
- def complete_config!
685
- super
686
- # detect threadsafe! in config/environments/environment.rb :
687
- if ! key?(:threadsafe) && self.class.threadsafe?(root_dir, environment)
688
- config[:jruby_min_runtimes] = 1 unless key?(:jruby_min_runtimes, false)
689
- config[:jruby_max_runtimes] = 1 unless key?(:jruby_max_runtimes, false)
672
+ # NOTE: maybe we can guess these based on connector maxThreads?
673
+ # def guess_max_runtimes; 5 end
674
+
675
+ def detect_threadsafe?(environment = self.environment)
676
+ if environment == 'development' || environment == 'test'
677
+ # NOTE: it's best for development/test to use the same setup as in
678
+ # production by default, thread-safe likely won't be detected as :
679
+ #
680
+ # __environments/development.rb__
681
+ #
682
+ # # In the development environment your application's code is reloaded on
683
+ # # every request. This slows down response time but is perfect for development
684
+ # # since you don't have to restart the web server when you make code changes.
685
+ # config.cache_classes = false
686
+ #
687
+ # # Do not eager load code on boot.
688
+ # config.eager_load = false
689
+ #
690
+ # __environments/test.rb__
691
+ #
692
+ # # The test environment is used exclusively to run your application's
693
+ # # test suite. You never need to work with it otherwise. Remember that
694
+ # # your test database is "scratch space" for the test suite and is wiped
695
+ # # and recreated between test runs. Don't rely on the data there!
696
+ # config.cache_classes = true
697
+ #
698
+ # # Do not eager load code on boot. This avoids loading your whole application
699
+ # # just for the purpose of running a single test. If you are using a tool that
700
+ # # preloads Rails for running tests, you may have to set it to true.
701
+ # config.eager_load = false
702
+ #
703
+ return self.class.threadsafe?(root_dir, 'production')
690
704
  end
705
+ self.class.threadsafe?(root_dir, environment)
691
706
  end
692
707
 
693
- #def layout_class
694
- #'JRuby::Rack::RailsFileSystemLayout'
695
- #end
696
-
697
- private
698
-
699
708
  def self.threadsafe?(app_base, environment)
700
709
  threadsafe_match?("#{app_base}/config/environments/#{environment}.rb") ||
701
710
  threadsafe_match?("#{app_base}/config/environment.rb")
@@ -703,7 +712,7 @@ module Trinidad
703
712
 
704
713
  def self.threadsafe_match?(file)
705
714
  File.exist?(file) && (
706
- file_line_match?(file, /^[^#]*threadsafe!/) || ( # Rails 4.0
715
+ file_line_match?(file, /^[^#]*threadsafe!/) || ( # Rails 4.x
707
716
  file_line_match?(file, /^[^#]*config\.eager_load\s?*=\s?*true/) &&
708
717
  file_line_match?(file, /^[^#]*config\.cache_classes\s?*=\s?*true/)
709
718
  )
@@ -753,10 +762,6 @@ module Trinidad
753
762
  root_dir ? File.expand_path(root_dir) : nil # the .war file itself
754
763
  end
755
764
 
756
- def class_loader
757
- @class_loader ||= nil # lifecycle will setup JRuby CL
758
- end
759
-
760
765
  def context_params
761
766
  warbler? ? super : @context_params ||= {}
762
767
  end
@@ -1,10 +1,10 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require 'trinidad/version'
4
2
 
5
3
  Gem::Specification.new do |gem|
6
4
  gem.name = 'trinidad'
7
- gem.version = Trinidad::VERSION
5
+
6
+ path = File.expand_path("lib/trinidad/version.rb", File.dirname(__FILE__))
7
+ gem.version = File.read(path).match( /.*VERSION\s*=\s*['"](.*)['"]/m )[1]
8
8
 
9
9
  gem.summary = "Web server for Rails/Rack applications built upon JRuby::Rack and Apache Tomcat"
10
10
  gem.description = "Trinidad allows you to run Rails or Rack applications within " <<
@@ -22,13 +22,10 @@ Gem::Specification.new do |gem|
22
22
  gem.rdoc_options = ["--charset=UTF-8"]
23
23
  gem.extra_rdoc_files = %w[README.md LICENSE]
24
24
 
25
- gem.add_dependency('trinidad_jars', '>= 1.3.0', '< 1.5.0')
26
- gem.add_dependency('jruby-rack', '~> 1.1.13')
25
+ gem.add_dependency('trinidad_jars', '>= 1.4.0', '< 1.6.0')
26
+ gem.add_dependency('jruby-rack', '~> 1.1.14')
27
27
 
28
- gem.add_development_dependency('rake')
29
28
  gem.add_development_dependency('rspec', '~> 2.14.1')
30
- gem.add_development_dependency('mocha', '~> 0.12.1')
31
- gem.add_development_dependency('fakefs', '>= 0.4.0')
32
29
 
33
30
  gem.files = `git ls-files`.split("\n").sort.
34
31
  reject { |file| file =~ /^\./ }. # .gitignore, .travis.yml
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trinidad
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.6
4
+ version: 1.5.0.B1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Calavera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-28 00:00:00.000000000 Z
11
+ date: 2014-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trinidad_jars
@@ -16,18 +16,18 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.0
19
+ version: 1.4.0
20
20
  - - <
21
21
  - !ruby/object:Gem::Version
22
- version: 1.5.0
22
+ version: 1.6.0
23
23
  requirement: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '>='
26
26
  - !ruby/object:Gem::Version
27
- version: 1.3.0
27
+ version: 1.4.0
28
28
  - - <
29
29
  - !ruby/object:Gem::Version
30
- version: 1.5.0
30
+ version: 1.6.0
31
31
  prerelease: false
32
32
  type: :runtime
33
33
  - !ruby/object:Gem::Dependency
@@ -36,28 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - ~>
38
38
  - !ruby/object:Gem::Version
39
- version: 1.1.13
39
+ version: 1.1.14
40
40
  requirement: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
- version: 1.1.13
44
+ version: 1.1.14
45
45
  prerelease: false
46
46
  type: :runtime
47
- - !ruby/object:Gem::Dependency
48
- name: rake
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- requirement: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - '>='
57
- - !ruby/object:Gem::Version
58
- version: '0'
59
- prerelease: false
60
- type: :development
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: rspec
63
49
  version_requirements: !ruby/object:Gem::Requirement
@@ -72,34 +58,6 @@ dependencies:
72
58
  version: 2.14.1
73
59
  prerelease: false
74
60
  type: :development
75
- - !ruby/object:Gem::Dependency
76
- name: mocha
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ~>
80
- - !ruby/object:Gem::Version
81
- version: 0.12.1
82
- requirement: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ~>
85
- - !ruby/object:Gem::Version
86
- version: 0.12.1
87
- prerelease: false
88
- type: :development
89
- - !ruby/object:Gem::Dependency
90
- name: fakefs
91
- version_requirements: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - '>='
94
- - !ruby/object:Gem::Version
95
- version: 0.4.0
96
- requirement: !ruby/object:Gem::Requirement
97
- requirements:
98
- - - '>='
99
- - !ruby/object:Gem::Version
100
- version: 0.4.0
101
- prerelease: false
102
- type: :development
103
61
  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
62
  email: calavera@apache.org
105
63
  executables:
@@ -117,7 +75,7 @@ files:
117
75
  - bin/trinidad
118
76
  - lib/rack/handler/trinidad.rb
119
77
  - lib/trinidad.rb
120
- - lib/trinidad/command_line_parser.rb
78
+ - lib/trinidad/cli.rb
121
79
  - lib/trinidad/configuration.rb
122
80
  - lib/trinidad/extensions.rb
123
81
  - lib/trinidad/helpers.rb
@@ -151,12 +109,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
109
  version: '0'
152
110
  required_rubygems_version: !ruby/object:Gem::Requirement
153
111
  requirements:
154
- - - '>='
112
+ - - '>'
155
113
  - !ruby/object:Gem::Version
156
- version: '0'
114
+ version: 1.3.1
157
115
  requirements: []
158
116
  rubyforge_project:
159
- rubygems_version: 2.1.9
117
+ rubygems_version: 2.2.2
160
118
  signing_key:
161
119
  specification_version: 4
162
120
  summary: Web server for Rails/Rack applications built upon JRuby::Rack and Apache Tomcat