trinidad_jars 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
 
@@ -40,8 +42,10 @@ Other advanced options can be found in the wiki: http://wiki.github.com/calavera
40
42
  From the version 0.8.0 Trinidad allows to extend the server with more Tomcat features, here there is a list with the current available extensions:
41
43
 
42
44
  * Database connection pooling: http://github.com/calavera/trinidad-dbpool
45
+ * Daemon, run Trinidad as a daemon: http://github.com/calavera/trinidad_daemon_extension
46
+ * Hot deploy, do hot deploys monitorizing a temporal file, ala Passenger: http://github.com/calavera/trinidad_hotdeploy_extension
43
47
 
44
- You can find further information on how to write your onw extension in the wiki: http://wiki.github.com/calavera/trinidad/extensions
48
+ You can find further information on how to write your own extension in the wiki: http://wiki.github.com/calavera/trinidad/extensions
45
49
 
46
50
  == Copyright
47
51
 
data/bin/trinidad CHANGED
@@ -5,5 +5,5 @@ $:.unshift(File.dirname(__FILE__) + '/../trinidad-libs')
5
5
 
6
6
  require "trinidad"
7
7
 
8
- opts = Trinidad::CommandLineParser.parse
9
- Trinidad::Server.new(opts).start
8
+ opts = Trinidad::CommandLineParser.parse(ARGV)
9
+ Trinidad::Server.new(opts).start
data/lib/trinidad/jars.rb CHANGED
@@ -3,16 +3,12 @@ $:.unshift(TRINIDAD_LIBS) unless
3
3
  $:.include?(TRINIDAD_LIBS) || $:.include?(File.expand_path(TRINIDAD_LIBS))
4
4
 
5
5
  module Trinidad
6
- require 'servlet-api-2.5-6.1.14'
7
- require 'jsp-api-2.1'
8
- require 'jsp-2.1'
9
6
  require 'tomcat-core'
10
- require 'jetty-util-6.1.14'
11
7
 
12
8
  require 'jruby-rack'
13
9
  require JRubyJars.jruby_rack_jar_path
14
-
15
- module Tomcat
10
+
11
+ module Tomcat
16
12
  include_package 'org.apache.catalina'
17
13
  include_package 'org.apache.catalina.startup'
18
14
  include_package 'org.apache.catalina.core'
@@ -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
@@ -1,85 +1,119 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/fakeapp'
3
+
4
+ include FakeApp
2
5
 
3
6
  describe Trinidad::CommandLineParser do
4
- it "should override classes option" do
5
- ARGV = "--classes my_classes".split
6
-
7
- options = Trinidad::CommandLineParser.parse
7
+ subject { Trinidad::CommandLineParser }
8
+
9
+ it "overrides classes option" do
10
+ args = "--classes my_classes".split
11
+
12
+ options = subject.parse(args)
8
13
  options[:classes_dir].should == 'my_classes'
9
14
  end
10
-
11
- it "should override libs option with lib option" do
12
- ARGV = "--lib my_libs".split
13
-
14
- options = Trinidad::CommandLineParser.parse
15
+
16
+ it "overrides libs option with lib option" do
17
+ args = "--lib my_libs".split
18
+
19
+ options = subject.parse(args)
15
20
  options[:libs_dir].should == 'my_libs'
16
21
  end
17
-
18
- it "should override libs option with jar option" do
19
- ARGV = "--jars my_jars".split
20
-
21
- options = Trinidad::CommandLineParser.parse
22
+
23
+ it "overrides libs option with jar option" do
24
+ args = "--jars my_jars".split
25
+
26
+ options = subject.parse(args)
22
27
  options[:libs_dir].should == 'my_jars'
23
28
  end
24
-
25
- it "should override the config file when it's especified" do
26
- ARGV = "-f #{File.join(MOCK_WEB_APP_DIR, 'tomcat.yml')}".split
27
-
28
- options = Trinidad::CommandLineParser.parse
29
- options[:environment].should == 'production'
29
+
30
+ it "uses config/trinidad.yml as the default configuration file name" do
31
+ FakeFS do
32
+ create_default_config_file
33
+ options = subject.parse(['-f'])
34
+
35
+ options[:config].should == 'config/trinidad.yml'
36
+ options[:port].should == 8080
37
+ end
30
38
  end
31
-
32
- it "should add default ssl port to options" do
33
- ARGV = '--ssl'.split
34
-
35
- options = Trinidad::CommandLineParser.parse
39
+
40
+ it "overrides the config file when it's especified" do
41
+ FakeFS do
42
+ create_custom_config_file
43
+ args = "-f config/tomcat.yml".split
44
+
45
+ options = subject.parse(args)
46
+ options[:environment].should == 'production'
47
+ end
48
+ end
49
+
50
+ it "adds default ssl port to options" do
51
+ args = '--ssl'.split
52
+
53
+ options = subject.parse(args)
36
54
  options[:ssl].should == {:port => 8443}
37
55
  end
38
-
39
- it "should add custom ssl port to options" do
40
- ARGV = '--ssl 8843'.split
41
-
42
- options = Trinidad::CommandLineParser.parse
56
+
57
+ it "adds custom ssl port to options" do
58
+ args = '--ssl 8843'.split
59
+
60
+ options = subject.parse(args)
43
61
  options[:ssl].should == {:port => 8843}
44
62
  end
45
-
46
- it "should add ajp connection with default port to options" do
47
- ARGV = '--ajp'.split
48
-
49
- options = Trinidad::CommandLineParser.parse
63
+
64
+ it "adds ajp connection with default port to options" do
65
+ args = '--ajp'.split
66
+
67
+ options = subject.parse(args)
50
68
  options[:ajp].should == {:port => 8009}
51
69
  end
52
-
53
- it "should add ajp connection with coustom port to options" do
54
- ARGV = '--ajp 8099'.split
55
-
56
- options = Trinidad::CommandLineParser.parse
70
+
71
+ it "adds ajp connection with coustom port to options" do
72
+ args = '--ajp 8099'.split
73
+
74
+ options = subject.parse(args)
57
75
  options[:ajp].should == {:port => 8099}
58
76
  end
59
-
60
- it "should merge ajp options from the config file" do
61
- ARGV = "--ajp 8099 -f #{File.join(MOCK_WEB_APP_DIR, 'tomcat.yml')}".split
62
-
63
- options = Trinidad::CommandLineParser.parse
64
- options[:ajp][:port].should == 8099
65
- options[:ajp][:secure].should == true
77
+
78
+ it "merges ajp options from the config file" do
79
+ FakeFS do
80
+ create_custom_config_file
81
+ args = "--ajp 8099 -f config/tomcat.yml".split
82
+
83
+ options = subject.parse(args)
84
+ options[:ajp][:port].should == 8099
85
+ options[:ajp][:secure].should == true
86
+ end
66
87
  end
67
-
88
+
68
89
  it "uses default rackup file to configure the server" do
69
- ARGV = "--rackup".split
70
- options = Trinidad::CommandLineParser.parse
90
+ args = "--rackup".split
91
+ options = subject.parse(args)
71
92
  options[:rackup].should == 'config.ru'
72
93
  end
73
94
 
74
95
  it "uses a custom rackup file if it's provided" do
75
- ARGV = "--rackup custom_config.ru".split
76
- options = Trinidad::CommandLineParser.parse
96
+ args = "--rackup custom_config.ru".split
97
+ options = subject.parse(args)
77
98
  options[:rackup].should == 'custom_config.ru'
78
99
  end
79
100
 
80
101
  it "uses a custom public directory" do
81
- ARGV = "--public web".split
82
- options = Trinidad::CommandLineParser.parse
102
+ args = "--public web".split
103
+ options = subject.parse(args)
83
104
  options[:public].should == 'web'
84
105
  end
106
+
107
+ it "works on threadsafe mode using the shortcut" do
108
+ args = '--threadsafe'.split
109
+ options = subject.parse(args)
110
+ options[:jruby_min_runtimes].should == 1
111
+ options[:jruby_max_runtimes].should == 1
112
+ end
113
+
114
+ it "loads a given extension to add its options to the parser" do
115
+ args = "--load foo --foo".split
116
+ options = subject.parse(args)
117
+ options.has_key?(:bar).should be_true
118
+ end
85
119
  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
@@ -0,0 +1,24 @@
1
+ require 'fakefs/safe'
2
+ module FakeApp
3
+ def create_default_config_file
4
+ @default ||= config_file 'config/trinidad.yml', <<-EOF
5
+ ---
6
+ port: 8080
7
+ EOF
8
+ end
9
+
10
+ def create_custom_config_file
11
+ @custom ||= config_file 'config/tomcat.yml', <<-EOF
12
+ ---
13
+ environment: production
14
+ ajp:
15
+ port: 8099
16
+ secure: true
17
+ EOF
18
+ end
19
+
20
+ private
21
+ def config_file(path, options)
22
+ File.open(path, 'w') {|io| io.write(options) }
23
+ end
24
+ end
@@ -19,25 +19,25 @@ describe Trinidad::Server do
19
19
 
20
20
  it "should have ssl disabled when config param is nil" do
21
21
  server = Trinidad::Server.new
22
- server.ssl_enabled?.should == false
22
+ server.ssl_enabled?.should be_false
23
23
  end
24
24
 
25
25
  it "should have ajp disabled when config param is nil" do
26
26
  server = Trinidad::Server.new
27
- server.ajp_enabled?.should == false
27
+ server.ajp_enabled?.should be_false
28
28
  end
29
29
 
30
30
  it "should have ssl enabled when config param is a number" do
31
31
  server = Trinidad::Server.new({:ssl => {:port => 8443},
32
32
  :web_app_dir => MOCK_WEB_APP_DIR})
33
33
 
34
- server.ssl_enabled?.should == true
34
+ server.ssl_enabled?.should be_true
35
35
  end
36
36
 
37
37
  it "should have ajp enabled when config param is a number" do
38
38
  server = Trinidad::Server.new({:ajp => {:port => 8009}})
39
39
 
40
- server.ajp_enabled?.should == true
40
+ server.ajp_enabled?.should be_true
41
41
  end
42
42
 
43
43
  it "should have a connector with https scheme" do
@@ -96,6 +96,14 @@ describe Trinidad::Server do
96
96
  context.findParameter('rackup').gsub(/\s+/, ' ').should == "require 'rubygems' require 'sinatra'"
97
97
  end
98
98
 
99
+ it "removes default servlets from the application" do
100
+ server = Trinidad::Server.new({:web_app_dir => MOCK_WEB_APP_DIR})
101
+ app = server.tomcat.host.find_child('/')
102
+
103
+ app.find_child('default').should be_nil
104
+ app.find_child('jsp').should be_nil
105
+ end
106
+
99
107
  def default_context_should_be_loaded(children)
100
108
  children.should have(1).web_apps
101
109
  children[0].getDocBase().should == MOCK_WEB_APP_DIR
@@ -3,7 +3,9 @@ require File.dirname(__FILE__) + '/../spec_helper'
3
3
  describe Trinidad::WebApp do
4
4
  before do
5
5
  @tomcat = Trinidad::Tomcat::Tomcat.new
6
+ @tomcat.host.app_base = Dir.pwd
6
7
  @tomcat_web_app = @tomcat.addWebapp('/', File.dirname(__FILE__) + '/../../')
8
+
7
9
  @app = {
8
10
  :web_app_dir => MOCK_WEB_APP_DIR,
9
11
  :context_path => '/'
@@ -20,15 +22,17 @@ describe Trinidad::WebApp do
20
22
  }
21
23
  @web_app = Trinidad::RailsWebApp.new(@tomcat_web_app, @config, @app)
22
24
  end
23
-
25
+
24
26
  it "creates a RailsWebApp if rackup option is not present" do
25
- Trinidad::WebApp.create(@tomcat_web_app, @config, @app).is_a?(Trinidad::RailsWebApp).should be_true
27
+ app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app)
28
+ app.should be_an_instance_of(Trinidad::RailsWebApp)
26
29
  end
27
30
 
28
31
  it "creates a RackupWebApp if rackup option is present" do
29
32
  rackup_app = {:rackup => 'config.ru'}
30
33
  @config.deep_merge({:web_apps => {:default => rackup_app}})
31
- Trinidad::WebApp.create(@tomcat_web_app, @config, rackup_app).is_a?(Trinidad::RackupWebApp).should be_true
34
+ app = Trinidad::WebApp.create(@tomcat_web_app, @config, rackup_app)
35
+ app.should be_an_instance_of(Trinidad::RackupWebApp)
32
36
  end
33
37
 
34
38
  it "should load custom jars" do
@@ -36,15 +40,15 @@ describe Trinidad::WebApp do
36
40
  @web_app.add_application_libs(class_loader)
37
41
 
38
42
  resource = class_loader.find_class('org.ho.yaml.Yaml')
39
- resource.should_not == nil
43
+ resource.should_not be_nil
40
44
  end
41
45
 
42
46
  it "should load custom classes" do
43
47
  class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
44
48
  @web_app.add_application_classes(class_loader)
45
-
49
+
46
50
  resource = class_loader.find_class('HelloTomcat')
47
- resource.should_not == nil
51
+ resource.should_not be_nil
48
52
  end
49
53
 
50
54
  it "should start application context without errors" do
@@ -61,39 +65,68 @@ describe Trinidad::WebApp do
61
65
  lambda { @web_app.add_init_params }.should_not raise_error
62
66
  end
63
67
 
64
- it "should load init params" do
68
+ it "loads init params from configuration root" do
65
69
  @web_app.add_init_params
66
70
 
67
71
  @web_app.context.findParameter('jruby.min.runtimes').should == '2'
68
72
  @web_app.context.findParameter('jruby.max.runtimes').should == '6'
69
73
  end
70
74
 
71
- it "should configure rack filter" do
72
- @web_app.add_rack_filter
73
- @web_app.context.findFilterDefs().should have(1).filters
75
+ it 'loads init params from application node' do
76
+ @app[:jruby_min_runtimes] = 4
77
+ @app[:jruby_max_runtimes] = 8
78
+ @config[:web_apps][:default] = @app
79
+
80
+ web_app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app)
81
+ web_app.add_init_params
82
+
83
+ web_app.context.findParameter('jruby.min.runtimes').should == '4'
84
+ web_app.context.findParameter('jruby.max.runtimes').should == '8'
85
+ end
86
+
87
+ it "configures rack handler" do
88
+ @web_app.configure_rack
89
+ @web_app.context.findChild('RackServlet').should_not be_nil
74
90
  end
75
91
 
76
- it "should configure rack listener" do
92
+ it "configures rack listener" do
77
93
  @web_app.add_rack_context_listener
78
94
  @web_app.context.findApplicationListeners().should have(1).listeners
79
95
  end
80
96
 
81
- it "should have rack filter already configured" do
97
+ it "has rack handler already configured when web.xml includes it" do
82
98
  @web_app.load_default_web_xml
83
- @web_app.rack_filter_configured?().should == true
99
+ @web_app.rack_configured?().should be_true
84
100
 
85
- @web_app.add_rack_filter
86
- @web_app.context.findFilterDefs().should have(0).filters
101
+ @web_app.configure_rack
102
+ @web_app.context.findChild('RackServlet').should be_nil
87
103
  end
88
104
 
89
- it "should have rack listener already configured" do
105
+ it "has rack listener already configured when web.xml includes it" do
90
106
  @web_app.load_default_web_xml
91
- @web_app.rack_listener_configured?().should == true
107
+ @web_app.rack_listener_configured?().should be_true
92
108
 
93
109
  @web_app.add_rack_context_listener
94
110
  @web_app.context.findApplicationListeners().should have(0).listeners
95
111
  end
96
112
 
113
+ it "loads the provided web.xml for rails applications" do
114
+ @config[:default_web_xml] = 'config/foo.xml'
115
+ app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app)
116
+
117
+ app.load_default_web_xml
118
+ app.context.default_web_xml.should =~ /rails_web.xml$/
119
+ end
120
+
121
+ it "loads the provided web.xml for rack applications" do
122
+ @config[:default_web_xml] = 'config/foo.xml'
123
+ @app[:rackup] = 'config.ru'
124
+
125
+ app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app)
126
+ app.load_default_web_xml
127
+ app.context.default_web_xml.should =~ /rackup_web.xml$/
128
+ end
129
+
97
130
  def start_context_with_web_xml
98
131
  @web_app.load_default_web_xml
99
132
  start_context
@@ -108,5 +141,4 @@ describe Trinidad::WebApp do
108
141
  @web_app.config[:libs_dir] = File.join(File.dirname(__FILE__), '..', '..', 'tomcat-libs')
109
142
  @web_app.add_context_loader
110
143
  end
111
-
112
144
  end
Binary file
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Calavera
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-07 00:00:00 +02:00
17
+ date: 2010-04-28 00:00:00 +02:00
18
18
  default_executable: trinidad
19
19
  dependencies: []
20
20
 
@@ -29,10 +29,6 @@ extra_rdoc_files:
29
29
  - README.rdoc
30
30
  files:
31
31
  - lib/trinidad/jars.rb
32
- - trinidad-libs/jetty-util-6.1.14.jar
33
- - trinidad-libs/jsp-2.1.jar
34
- - trinidad-libs/jsp-api-2.1.jar
35
- - trinidad-libs/servlet-api-2.5-6.1.14.jar
36
32
  - trinidad-libs/tomcat-core.jar
37
33
  - LICENSE
38
34
  - README.rdoc
@@ -67,10 +63,11 @@ signing_key:
67
63
  specification_version: 3
68
64
  summary: Common jars for Trinidad
69
65
  test_files:
70
- - spec/fixtures/foo.rb
71
66
  - spec/fixtures/trinidad_foo_extension.rb
67
+ - spec/fixtures/trinidad_override_tomcat_extension.rb
72
68
  - spec/spec_helper.rb
73
69
  - spec/trinidad/command_line_parser_spec.rb
74
70
  - spec/trinidad/extensions_spec.rb
71
+ - spec/trinidad/fakeapp.rb
75
72
  - spec/trinidad/server_spec.rb
76
73
  - 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
Binary file
Binary file
Binary file