trinidad 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.8.3 (2010-04-17)
2
+
3
+ * Extensions improvements:
4
+ - Enable command line extensions.
5
+ - Allow to overload the server.
6
+
1
7
  == 0.8.2 (2010-04-09)
2
8
 
3
9
  * Fixes yaml parser error. Thank to @elskwid
data/README.rdoc CHANGED
@@ -25,6 +25,8 @@ Trinidad allows you to configure some parameters when the server is started from
25
25
  * --classes CLASSES_DIR => directory containing classes.
26
26
  * --rackup [RACKUP_FILE] => run a provided rackup file instead of a rails application, by default it's config.ru.
27
27
  * --public PUBLIC_DIR => specify the public directory for your application, by default it's 'public'.
28
+ * -t, --threadsafe => shortcut to work in threadsafe mode. Setting jruby_min_runtimes and jruby_max_runtimes to 1 in the configuration file the server behaves as the same way.
29
+ * -l, --load [EXTENSION_NAME] => loads an extension to use its command line options.
28
30
 
29
31
  The server can also be configured from a yaml file. If a file is not especified, the server tries to load the file <em>config/tomcat.yml</em>. Within this file you can add other options like jruby.min.runtimes(:jruby_min_runtimes) or jruby.max.runtimes(:jruby_max_runtimes).
30
32
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.2
1
+ 0.8.3
data/lib/trinidad.rb CHANGED
@@ -16,4 +16,5 @@ require 'trinidad/rails_web_app'
16
16
  require 'trinidad/rackup_web_app'
17
17
 
18
18
  module Trinidad
19
+ VERSION = File.read(File.expand_path('../../VERSION', __FILE__))
19
20
  end
@@ -72,11 +72,20 @@ module Trinidad
72
72
  default_options[:public] = v
73
73
  end
74
74
 
75
+ opts.on('-t', '--threadsafe', 'Threadsafe mode') do
76
+ default_options[:jruby_min_runtimes] = 1
77
+ default_options[:jruby_max_runtimes] = 1
78
+ end
79
+
75
80
  opts.on('-v', '--version', 'display the current version') do
76
81
  puts File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
77
82
  exit
78
83
  end
79
84
 
85
+ opts.on('-l', '--load EXTENSION_NAME', 'load options for a given extension') do |name|
86
+ Trinidad::Extensions.configure_options_extensions({name => {}}, opts, default_options)
87
+ end
88
+
80
89
  opts.on('-h', '--help', 'display the help') do
81
90
  puts opts
82
91
  exit
@@ -3,7 +3,7 @@ module Trinidad
3
3
  def self.configure_webapp_extensions(extensions, tomcat, app_context)
4
4
  if extensions
5
5
  extensions.each do |name, options|
6
- extension(name, 'WebAppExtension').new(options).configure(tomcat, app_context)
6
+ extension(name, 'WebAppExtension', options).configure(tomcat, app_context)
7
7
  end
8
8
  end
9
9
  end
@@ -11,15 +11,26 @@ module Trinidad
11
11
  def self.configure_server_extensions(extensions, tomcat)
12
12
  if extensions
13
13
  extensions.each do |name, options|
14
- extension(name, 'ServerExtension').new(options).configure(tomcat)
14
+ extension = extension(name, 'ServerExtension', options)
15
+ configured_tomcat = extension.configure(tomcat)
16
+ tomcat = configured_tomcat if extension.override_tomcat?
15
17
  end
16
18
  end
19
+ tomcat
17
20
  end
18
21
 
19
- def self.extension(name, type)
22
+ def self.configure_options_extensions(extensions, parser, default_options)
23
+ if extensions
24
+ extensions.each do |name, options|
25
+ extension(name, 'OptionsExtension', options).configure(parser, default_options)
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.extension(name, type, options)
20
31
  class_name = (name.to_s.camelize << type).to_sym
21
32
  load_extension(name) unless const_defined?(class_name)
22
- const_get(class_name)
33
+ const_get(class_name).new(options)
23
34
  end
24
35
 
25
36
  def self.load_extension(name)
@@ -27,7 +38,7 @@ module Trinidad
27
38
  end
28
39
 
29
40
  class Extension
30
- def initialize(options)
41
+ def initialize(options = {})
31
42
  @options = options.dup
32
43
  end
33
44
  end
@@ -42,6 +53,14 @@ module Trinidad
42
53
  def configure(tomcat)
43
54
  raise NotImplementedError, "#{self.class}#configure not implemented"
44
55
  end
56
+
57
+ def override_tomcat?; false; end # hack to allow override the tomcat's instance, it should be a better way
58
+ end
59
+
60
+ class OptionsExtension < Extension
61
+ def configure(parser, default_options)
62
+ raise NotImplementedError, "#{self.class}#configure not implemented"
63
+ end
45
64
  end
46
65
  end
47
66
  end
@@ -38,7 +38,7 @@ module Trinidad
38
38
  add_ssl_connector if ssl_enabled?
39
39
  add_ajp_connector if ajp_enabled?
40
40
 
41
- Trinidad::Extensions.configure_server_extensions(@config[:extensions], @tomcat)
41
+ @tomcat = Trinidad::Extensions.configure_server_extensions(@config[:extensions], @tomcat)
42
42
  end
43
43
 
44
44
  def create_web_apps
@@ -40,12 +40,9 @@ module Trinidad
40
40
  end
41
41
 
42
42
  def add_init_params
43
- [:jruby_min_runtimes, :jruby_max_runtimes].each do |param|
44
- param_name = param.to_s.gsub(/_/, '.')
45
- add_parameter_unless_exist(param_name, @config[param].to_s)
46
- end
47
-
48
- add_parameter_unless_exist('jruby.initial.runtimes', @config[:jruby_min_runtimes].to_s)
43
+ add_parameter_unless_exist('jruby.min.runtimes', jruby_min_runtimes.to_s)
44
+ add_parameter_unless_exist('jruby.max.runtimes', jruby_max_runtimes.to_s)
45
+ add_parameter_unless_exist('jruby.initial.runtimes', jruby_min_runtimes.to_s)
49
46
  add_parameter_unless_exist('public.root', File.join('/', public_root))
50
47
  end
51
48
 
@@ -74,14 +71,14 @@ module Trinidad
74
71
  end
75
72
 
76
73
  def load_default_web_xml
77
- default_web_xml = File.expand_path(File.join(@app[:web_app_dir], default_web_xml_file))
74
+ file = File.expand_path(File.join(@app[:web_app_dir], default_web_xml))
78
75
 
79
- if File.exist?(default_web_xml)
80
- @context.setDefaultWebXml(default_web_xml)
81
- @context.setDefaultContextXml(default_web_xml)
76
+ if File.exist?(file)
77
+ @context.setDefaultWebXml(file)
78
+ @context.setDefaultContextXml(file)
82
79
 
83
80
  context_config = Trinidad::Tomcat::ContextConfig.new
84
- context_config.setDefaultWebXml(default_web_xml)
81
+ context_config.setDefaultWebXml(file)
85
82
 
86
83
  @context.addLifecycleListener(context_config)
87
84
  end
@@ -108,20 +105,11 @@ module Trinidad
108
105
  @context.findParameter('public.root') || @app[:public] || @config[:public] || 'public'
109
106
  end
110
107
 
111
- def libs_dir
112
- @app[:libs_dir] || @config[:libs_dir]
113
- end
114
-
115
- def classes_dir
116
- @app[:classes_dir] || @config[:classes_dir]
117
- end
118
-
119
- def default_web_xml_file
120
- @app[:default_web_xml] || @config[:default_web_xml]
121
- end
122
-
123
- def environment
124
- @app[:environment] || @config[:environment]
108
+ %w{libs_dir classes_dir default_web_xml environment jruby_min_runtimes jruby_max_runtimes}.each do |method_name|
109
+ define_method method_name do
110
+ sym = method_name.to_sym
111
+ @app[sym] || @config[sym]
112
+ end
125
113
  end
126
114
 
127
115
  def add_parameter_unless_exist(name, value)
@@ -1 +1,23 @@
1
- require File.dirname(__FILE__) + '/foo'
1
+ module Trinidad
2
+ module Extensions
3
+ class FooWebAppExtension < WebAppExtension
4
+ def configure(tomcat, app_context)
5
+ @options
6
+ end
7
+ end
8
+
9
+ class FooServerExtension < ServerExtension
10
+ def configure(tomcat)
11
+ @options
12
+ end
13
+ end
14
+
15
+ class FooOptionsExtension < OptionsExtension
16
+ def configure(parser, default_options)
17
+ parser.on('--foo') do
18
+ default_options[:bar] = true
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module Trinidad
2
+ module Extensions
3
+ class OverrideTomcatServerExtension < ServerExtension
4
+ def configure(tomcat)
5
+ Trinidad::Tomcat::Tomcat.new
6
+ end
7
+
8
+ def override_tomcat?; true; end
9
+ end
10
+ end
11
+ end
@@ -3,68 +3,68 @@ require File.dirname(__FILE__) + '/../spec_helper'
3
3
  describe Trinidad::CommandLineParser do
4
4
  it "should override classes option" do
5
5
  ARGV = "--classes my_classes".split
6
-
6
+
7
7
  options = Trinidad::CommandLineParser.parse
8
8
  options[:classes_dir].should == 'my_classes'
9
9
  end
10
-
10
+
11
11
  it "should override libs option with lib option" do
12
12
  ARGV = "--lib my_libs".split
13
-
13
+
14
14
  options = Trinidad::CommandLineParser.parse
15
15
  options[:libs_dir].should == 'my_libs'
16
16
  end
17
-
17
+
18
18
  it "should override libs option with jar option" do
19
19
  ARGV = "--jars my_jars".split
20
-
20
+
21
21
  options = Trinidad::CommandLineParser.parse
22
22
  options[:libs_dir].should == 'my_jars'
23
23
  end
24
-
24
+
25
25
  it "should override the config file when it's especified" do
26
26
  ARGV = "-f #{File.join(MOCK_WEB_APP_DIR, 'tomcat.yml')}".split
27
-
27
+
28
28
  options = Trinidad::CommandLineParser.parse
29
29
  options[:environment].should == 'production'
30
30
  end
31
-
31
+
32
32
  it "should add default ssl port to options" do
33
33
  ARGV = '--ssl'.split
34
-
34
+
35
35
  options = Trinidad::CommandLineParser.parse
36
36
  options[:ssl].should == {:port => 8443}
37
37
  end
38
-
38
+
39
39
  it "should add custom ssl port to options" do
40
40
  ARGV = '--ssl 8843'.split
41
-
41
+
42
42
  options = Trinidad::CommandLineParser.parse
43
43
  options[:ssl].should == {:port => 8843}
44
44
  end
45
-
45
+
46
46
  it "should add ajp connection with default port to options" do
47
47
  ARGV = '--ajp'.split
48
-
48
+
49
49
  options = Trinidad::CommandLineParser.parse
50
50
  options[:ajp].should == {:port => 8009}
51
51
  end
52
-
52
+
53
53
  it "should add ajp connection with coustom port to options" do
54
54
  ARGV = '--ajp 8099'.split
55
-
55
+
56
56
  options = Trinidad::CommandLineParser.parse
57
57
  options[:ajp].should == {:port => 8099}
58
58
  end
59
-
59
+
60
60
  it "should merge ajp options from the config file" do
61
61
  ARGV = "--ajp 8099 -f #{File.join(MOCK_WEB_APP_DIR, 'tomcat.yml')}".split
62
-
62
+
63
63
  options = Trinidad::CommandLineParser.parse
64
64
  options[:ajp][:port].should == 8099
65
65
  options[:ajp][:secure].should == true
66
66
  end
67
-
67
+
68
68
  it "uses default rackup file to configure the server" do
69
69
  ARGV = "--rackup".split
70
70
  options = Trinidad::CommandLineParser.parse
@@ -82,4 +82,18 @@ describe Trinidad::CommandLineParser do
82
82
  options = Trinidad::CommandLineParser.parse
83
83
  options[:public].should == 'web'
84
84
  end
85
+
86
+ it "works on threadsafe mode using the shortcut" do
87
+ ARGV = '--threadsafe'.split
88
+ options = Trinidad::CommandLineParser.parse
89
+ options[:jruby_min_runtimes].should == 1
90
+ options[:jruby_max_runtimes].should == 1
91
+ end
92
+
93
+ it "loads a given extension to add its options to the parser" do
94
+ ARGV = "--load foo --foo".split
95
+ options = Trinidad::CommandLineParser.parse
96
+ options.has_key?(:bar).should be_true
97
+
98
+ end
85
99
  end
@@ -16,4 +16,25 @@ describe Trinidad::Extensions do
16
16
  lambda {Trinidad::Extensions.configure_webapp_extensions(@extensions, nil, nil)}.should_not raise_error
17
17
  lambda {Trinidad::Extensions.const_get(:FooWebAppExtension)}.should_not raise_error
18
18
  end
19
+
20
+ it "adds options to the command line parser" do
21
+ options = {}
22
+ parser = OptionParser.new
23
+ lambda {
24
+ Trinidad::Extensions.configure_options_extensions({:foo => {}}, parser, options)
25
+ }.should_not raise_error
26
+
27
+ lambda {
28
+ parser.parse! ['--foo']
29
+ options.has_key?(:bar).should be_true
30
+ }.should_not raise_error
31
+ end
32
+
33
+ it "allows to override the tomcat's instance" do
34
+ extensions = {:override_tomcat => {}}
35
+ tomcat = Trinidad::Tomcat::Tomcat.new
36
+
37
+ extended = Trinidad::Extensions.configure_server_extensions(extensions, tomcat)
38
+ extended.should_not equal(tomcat)
39
+ end
19
40
  end
@@ -20,7 +20,7 @@ describe Trinidad::WebApp do
20
20
  }
21
21
  @web_app = Trinidad::RailsWebApp.new(@tomcat_web_app, @config, @app)
22
22
  end
23
-
23
+
24
24
  it "creates a RailsWebApp if rackup option is not present" do
25
25
  Trinidad::WebApp.create(@tomcat_web_app, @config, @app).is_a?(Trinidad::RailsWebApp).should be_true
26
26
  end
@@ -42,7 +42,7 @@ describe Trinidad::WebApp do
42
42
  it "should load custom classes" do
43
43
  class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
44
44
  @web_app.add_application_classes(class_loader)
45
-
45
+
46
46
  resource = class_loader.find_class('HelloTomcat')
47
47
  resource.should_not == nil
48
48
  end
@@ -61,13 +61,25 @@ describe Trinidad::WebApp do
61
61
  lambda { @web_app.add_init_params }.should_not raise_error
62
62
  end
63
63
 
64
- it "should load init params" do
64
+ it "loads init params from configuration root" do
65
65
  @web_app.add_init_params
66
66
 
67
67
  @web_app.context.findParameter('jruby.min.runtimes').should == '2'
68
68
  @web_app.context.findParameter('jruby.max.runtimes').should == '6'
69
69
  end
70
70
 
71
+ it 'loads init params from application node' do
72
+ @app[:jruby_min_runtimes] = 4
73
+ @app[:jruby_max_runtimes] = 8
74
+ @config[:web_apps][:default] = @app
75
+
76
+ web_app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app)
77
+ web_app.add_init_params
78
+
79
+ web_app.context.findParameter('jruby.min.runtimes').should == '4'
80
+ web_app.context.findParameter('jruby.max.runtimes').should == '8'
81
+ end
82
+
71
83
  it "should configure rack filter" do
72
84
  @web_app.add_rack_filter
73
85
  @web_app.context.findFilterDefs().should have(1).filters
metadata CHANGED
@@ -1,123 +1,143 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trinidad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 8
8
+ - 3
9
+ version: 0.8.3
5
10
  platform: ruby
6
11
  authors:
7
- - David Calavera
12
+ - David Calavera
8
13
  autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-04-09 00:00:00 +02:00
17
+ date: 2010-04-17 00:00:00 +02:00
13
18
  default_executable: trinidad
14
19
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rack
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "1.0"
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: jruby-rack
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: trinidad_jars
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 0.1.1
44
- version:
45
- - !ruby/object:Gem::Dependency
46
- name: rspec
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
54
- version:
55
- - !ruby/object:Gem::Dependency
56
- name: mocha
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- version:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rack
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ version: "1.0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: jruby-rack
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :runtime
44
+ version_requirements: *id002
45
+ - !ruby/object:Gem::Dependency
46
+ name: trinidad_jars
47
+ prerelease: false
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ - 1
55
+ - 1
56
+ version: 0.1.1
57
+ type: :runtime
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id004
71
+ - !ruby/object:Gem::Dependency
72
+ name: mocha
73
+ prerelease: false
74
+ requirement: &id005 !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ type: :development
82
+ version_requirements: *id005
65
83
  description:
66
84
  email: calavera@apache.org
67
85
  executables:
68
- - trinidad
86
+ - trinidad
69
87
  extensions: []
70
88
 
71
89
  extra_rdoc_files:
72
- - LICENSE
73
- - README.rdoc
90
+ - LICENSE
91
+ - README.rdoc
74
92
  files:
75
- - History.txt
76
- - LICENSE
77
- - README.rdoc
78
- - VERSION
79
- - bin/trinidad
80
- - lib/trinidad.rb
81
- - lib/trinidad/command_line_parser.rb
82
- - lib/trinidad/core_ext.rb
83
- - lib/trinidad/extensions.rb
84
- - lib/trinidad/rackup_web_app.rb
85
- - lib/trinidad/rails_web_app.rb
86
- - lib/trinidad/server.rb
87
- - lib/trinidad/web_app.rb
93
+ - History.txt
94
+ - LICENSE
95
+ - README.rdoc
96
+ - VERSION
97
+ - bin/trinidad
98
+ - lib/trinidad.rb
99
+ - lib/trinidad/command_line_parser.rb
100
+ - lib/trinidad/core_ext.rb
101
+ - lib/trinidad/extensions.rb
102
+ - lib/trinidad/rackup_web_app.rb
103
+ - lib/trinidad/rails_web_app.rb
104
+ - lib/trinidad/server.rb
105
+ - lib/trinidad/web_app.rb
88
106
  has_rdoc: true
89
107
  homepage: http://calavera.github.com/trinidad
90
108
  licenses: []
91
109
 
92
110
  post_install_message:
93
111
  rdoc_options:
94
- - --charset=UTF-8
112
+ - --charset=UTF-8
95
113
  require_paths:
96
- - lib
114
+ - lib
97
115
  required_ruby_version: !ruby/object:Gem::Requirement
98
116
  requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: "0"
102
- version:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ segments:
120
+ - 0
121
+ version: "0"
103
122
  required_rubygems_version: !ruby/object:Gem::Requirement
104
123
  requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- version: "0"
108
- version:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ segments:
127
+ - 0
128
+ version: "0"
109
129
  requirements: []
110
130
 
111
131
  rubyforge_project: trinidad
112
- rubygems_version: 1.3.5
132
+ rubygems_version: 1.3.6
113
133
  signing_key:
114
134
  specification_version: 3
115
135
  summary: Simple library to run rails applications into an embedded Tomcat
116
136
  test_files:
117
- - spec/spec_helper.rb
118
- - spec/trinidad/extensions_spec.rb
119
- - spec/trinidad/command_line_parser_spec.rb
120
- - spec/trinidad/server_spec.rb
121
- - spec/trinidad/web_app_spec.rb
122
- - spec/fixtures/foo.rb
123
- - spec/fixtures/trinidad_foo_extension.rb
137
+ - spec/fixtures/trinidad_foo_extension.rb
138
+ - spec/fixtures/trinidad_override_tomcat_extension.rb
139
+ - spec/spec_helper.rb
140
+ - spec/trinidad/command_line_parser_spec.rb
141
+ - spec/trinidad/extensions_spec.rb
142
+ - spec/trinidad/server_spec.rb
143
+ - spec/trinidad/web_app_spec.rb
data/spec/fixtures/foo.rb DELETED
@@ -1,15 +0,0 @@
1
- module Trinidad
2
- module Extensions
3
- class FooWebAppExtension < WebAppExtension
4
- def configure(tomcat, app_context)
5
- @options
6
- end
7
- end
8
-
9
- class FooServerExtension < ServerExtension
10
- def configure(tomcat)
11
- @options
12
- end
13
- end
14
- end
15
- end