trinidad 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ == 0.9.2 (2010-05-24)
2
+
3
+ * Autoload the rackup file when it's under the directory WEB-INF.
4
+ * Let jruby-rack reads the rackup file instead of passing its content as an init parameter.
5
+ * Allow to configure the rack servlet from the configuration options.
6
+ * Allow to use crt files to configure SSL
7
+
1
8
  == 0.9.1 (2010-05-09)
2
9
 
3
10
  * Move all configuration logic to a Lifecycle listener:
@@ -5,6 +12,7 @@
5
12
  - Avoids workarounds in the hotdeploy extension.
6
13
  * Disable more Tomcat's default behaviours. Process Tlds is also disabled.
7
14
  * Allow to specify webapp extensions in the extensions root section.
15
+ * Allow to configure the Http connector.
8
16
 
9
17
  == 0.9.0 (2010-04-28)
10
18
 
@@ -11,22 +11,42 @@ This project was initially called "Tomcat-rails" but due to legal issues with th
11
11
 
12
12
  == USAGE:
13
13
 
14
- cd myrailsapp
15
- jruby -S trinidad
16
-
14
+ Rails applications:
15
+
16
+ $ cd myrailsapp
17
+ $ jruby -S trinidad
18
+
19
+ Rack applications:
20
+
21
+ $ cd myrackapplication
22
+
23
+ $ jruby -S trinidad -r path_to_rackup/rackup_file
24
+
25
+ or if the name of the file is config.ru
26
+
27
+ $ jruby -S trinidad -r path_to_rackup
28
+
29
+ or if config.ru is in the base directory
30
+
31
+ $ jruby -S trinidad -r
32
+
33
+ or if config.ru is under the directory WEB-INF
34
+
35
+ $ jruby -S trinidad
36
+
17
37
  == CONFIGURATION:
18
38
 
19
39
  Trinidad allows you to configure some parameters when the server is started from the command line, the following is a list of the currently supported options:
20
40
 
21
- * -p, --port PORT => port to bind to.
22
- * -e, --env ENVIRONMENT => rails environment.
23
- * -c, --context CONTEXT => application context path.
24
- * --lib, --jars LIBS_DIR => directory containing jars.
25
- * --classes CLASSES_DIR => directory containing classes.
26
- * --rackup [RACKUP_FILE] => run a provided rackup file instead of a rails application, by default it's config.ru.
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.
41
+ * -p, --port PORT => port to bind to.
42
+ * -e, --env ENVIRONMENT => rails environment.
43
+ * -c, --context CONTEXT => application context path.
44
+ * --lib, --jars LIBS_DIR => directory containing jars.
45
+ * --classes CLASSES_DIR => directory containing classes.
46
+ * -r, --rackup [RACKUP_FILE] => run a provided rackup file instead of a rails application, by default it's config.ru.
47
+ * --public PUBLIC_DIR => specify the public directory for your application, by default it's 'public'.
48
+ * -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.
49
+ * -l, --load EXTENSION_NAME => loads an extension to use its command line options.
30
50
 
31
51
  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).
32
52
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.9.2
@@ -3,6 +3,10 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
  require "java"
5
5
  require 'rubygems'
6
+
7
+ require 'jruby-rack'
8
+ require JRubyJars.jruby_rack_jar_path
9
+
6
10
  gem 'trinidad_jars'
7
11
 
8
12
  require 'trinidad/core_ext'
@@ -3,14 +3,13 @@ module Trinidad
3
3
 
4
4
  def init_params
5
5
  super
6
- add_parameter_unless_exist 'rackup', rackup_script
6
+ if rackup_path = rackup
7
+ rackup_path = File.join(rackup_path, 'config.ru') if File.directory?(rackup_path)
8
+ add_parameter_unless_exist('rackup.path', rackup_path)
9
+ end
7
10
  @params
8
11
  end
9
12
 
10
13
  def context_listener; 'org.jruby.rack.RackServletContextListener'; end
11
-
12
- def rackup_script
13
- File.read(File.join(web_app_dir, rackup))
14
- end
15
14
  end
16
15
  end
@@ -73,7 +73,7 @@ module Trinidad
73
73
  connector.setProperty(key.to_s, value.to_s)
74
74
  end
75
75
 
76
- @tomcat.getService().addConnector(connector)
76
+ @tomcat.service.add_connector(connector)
77
77
  connector
78
78
  end
79
79
 
@@ -87,11 +87,14 @@ module Trinidad
87
87
  :secure => true,
88
88
  :SSLEnabled => 'true'
89
89
  })
90
- options[:keystore] ||= 'ssl/keystore'
91
- options[:keystorePass] ||= 'waduswadus'
90
+
91
+ if !options[:keystore] && !options[:SSLCertificateFile]
92
+ options[:keystore] = 'ssl/keystore'
93
+ options[:keystorePass] = 'waduswadus'
94
+ end
92
95
 
93
96
  add_service_connector(options)
94
- create_default_keystore(options) unless File.exist?(options[:keystore])
97
+ create_default_keystore(options)
95
98
  end
96
99
 
97
100
  def add_http_connector
@@ -116,10 +119,12 @@ module Trinidad
116
119
  end
117
120
 
118
121
  def create_default_keystore(config)
122
+ return if !config[:keystore] || File.exist?(config[:keystore])
123
+
119
124
  keystore_file = java.io.File.new(config[:keystore])
120
125
 
121
- if (!keystore_file.parent_file.exists() &&
122
- !keystore_file.parent_file.mkdir())
126
+ if (!keystore_file.parent_file.exists &&
127
+ !keystore_file.parent_file.mkdir)
123
128
  raise "Unable to create keystore folder: " + keystore_file.parent_file.canonical_path
124
129
  end
125
130
 
@@ -138,7 +143,7 @@ module Trinidad
138
143
 
139
144
  def start
140
145
  @tomcat.start
141
- @tomcat.getServer().await
146
+ @tomcat.server.await
142
147
  end
143
148
 
144
149
  private
@@ -156,19 +161,19 @@ module Trinidad
156
161
  end
157
162
 
158
163
  def enable_naming
159
- @tomcat.getServer().addLifecycleListener(Trinidad::Tomcat::NamingContextListener.new)
164
+ @tomcat.server.add_lifecycle_listener(Trinidad::Tomcat::NamingContextListener.new)
160
165
 
161
- JSystem.setProperty("catalina.useNaming", "true")
166
+ JSystem.set_property("catalina.useNaming", "true")
162
167
 
163
168
  value = "org.apache.naming"
164
- old_value = JSystem.getProperty(JContext.URL_PKG_PREFIXES) || value
169
+ old_value = JSystem.get_property(JContext::URL_PKG_PREFIXES) || value
165
170
 
166
171
  value = value + ":" + old_value unless old_value.include?(value)
167
- JSystem.setProperty(JContext.URL_PKG_PREFIXES, value)
172
+ JSystem.set_property(JContext::URL_PKG_PREFIXES, value)
168
173
 
169
- value = JSystem.getProperty(JContext.INITIAL_CONTEXT_FACTORY)
174
+ value = JSystem.get_property(JContext::INITIAL_CONTEXT_FACTORY)
170
175
  unless value
171
- JSystem.setProperty(JContext.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory")
176
+ JSystem.set_property(JContext::INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory")
172
177
  end
173
178
  end
174
179
 
@@ -3,7 +3,7 @@ module Trinidad
3
3
  attr_reader :config, :app_config, :class_loader, :servlet
4
4
 
5
5
  def self.create(config, app_config)
6
- app_config.has_key?(:rackup) ? RackupWebApp.new(config, app_config) : RailsWebApp.new(config, app_config)
6
+ rackup?(app_config) ? RackupWebApp.new(config, app_config) : RailsWebApp.new(config, app_config)
7
7
  end
8
8
 
9
9
  def initialize(config, app_config, servlet_class = 'org.jruby.rack.RackServlet', servlet_name = 'RackServlet')
@@ -11,7 +11,8 @@ module Trinidad
11
11
  @app_config = app_config
12
12
 
13
13
  @class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
14
- @servlet = {:class => servlet_class, :name => servlet_name} unless rack_servlet_configured?
14
+
15
+ configure_rack_servlet(servlet_class, servlet_name) unless rack_servlet_configured?
15
16
  end
16
17
 
17
18
  def rack_listener
@@ -77,5 +78,18 @@ module Trinidad
77
78
  return $1
78
79
  end
79
80
  end
81
+
82
+ def configure_rack_servlet(servlet_class, servlet_name)
83
+ servlet_config = @config[:servlet] || @app_config[:servlet]
84
+ if servlet_config
85
+ servlet_class = servlet_config[:class]
86
+ servlet_name = servlet_config[:name]
87
+ end
88
+ @servlet = {:class => servlet_class, :name => servlet_name}
89
+ end
90
+
91
+ def self.rackup?(app_config)
92
+ app_config.has_key?(:rackup) || !Dir['WEB-INF/**/config.ru'].empty?
93
+ end
80
94
  end
81
95
  end
@@ -71,8 +71,8 @@ EOF
71
71
  EOF
72
72
  end
73
73
 
74
- def create_rackup_file
75
- @rackup ||= config_file 'config/config.ru', <<-EOF
74
+ def create_rackup_file(path = 'config')
75
+ @rackup ||= config_file File.join(path, 'config.ru'), <<-EOF
76
76
  require 'rubygems'
77
77
  require 'sinatra'
78
78
 
@@ -32,6 +32,7 @@ describe Trinidad::Server do
32
32
  :web_app_dir => MOCK_WEB_APP_DIR})
33
33
 
34
34
  server.ssl_enabled?.should be_true
35
+ File.exist?('ssl').should be_true
35
36
  end
36
37
 
37
38
  it "enables ajp when config param is a number" do
@@ -131,24 +132,38 @@ describe Trinidad::Server do
131
132
  connector.get_property('maxKeepAliveRequests').should == 4
132
133
  connector.get_property('socket.bufferPool').should == '1000'
133
134
  end
134
-
135
+
135
136
  it "adds the WebAppLifecycleListener to each webapp" do
136
137
  server = Trinidad::Server.new({:web_app_dir => MOCK_WEB_APP_DIR})
137
138
  app_context = server.tomcat.host.find_child('/')
138
-
139
+
139
140
  app_context.find_lifecycle_listeners.map {|l| l.class.name }.should include('Trinidad::WebAppLifecycleListener')
140
141
  end
141
-
142
+
142
143
  it "loads application extensions from the root of the configuration" do
143
144
  server = Trinidad::Server.new({
144
145
  :web_app_dir => MOCK_WEB_APP_DIR,
145
146
  :extensions => { :foo => {} }
146
147
  })
147
-
148
+
148
149
  app_context = server.tomcat.host.find_child('/')
149
150
  app_context.doc_base.should == 'foo_app_extension'
150
151
  end
151
152
 
153
+ it "doesn't create a default keystore when the option SSLCertificateFile is present in the ssl configuration options" do
154
+ require 'fileutils'
155
+ FileUtils.rm_rf 'ssl'
156
+
157
+ server = Trinidad::Server.new({
158
+ :ssl => {
159
+ :port => 8443,
160
+ :SSLCertificateFile => '/usr/local/ssl/server.crt'
161
+ },
162
+ :web_app_dir => MOCK_WEB_APP_DIR})
163
+
164
+ File.exist?('ssl').should be_false
165
+ end
166
+
152
167
  def default_context_should_be_loaded(children)
153
168
  children.should have(1).web_apps
154
169
  children[0].doc_base.should == MOCK_WEB_APP_DIR
@@ -174,6 +174,6 @@ describe Trinidad::WebAppLifecycleListener do
174
174
  listener.context = Trinidad::Tomcat::StandardContext.new
175
175
  listener.configure_init_params
176
176
 
177
- listener.context.find_parameter('rackup').should == "require 'rubygems'\nrequire 'sinatra'"
177
+ listener.context.find_parameter('rackup.path').should == "config.ru"
178
178
  end
179
179
  end
@@ -75,7 +75,7 @@ describe Trinidad::WebApp do
75
75
  })
76
76
 
77
77
  parameters = app.init_params
78
- parameters['rackup'].should =~ /run App/
78
+ parameters['rackup.path'].should == 'config/config.ru'
79
79
  end
80
80
  end
81
81
 
@@ -130,4 +130,46 @@ describe Trinidad::WebApp do
130
130
  app = Trinidad::WebApp.create(config, app_config)
131
131
  app.extensions[:hotdeploy].should include(:delay)
132
132
  end
133
+
134
+ it "creates a rackup application when the rackup file is under WEB-INF directory" do
135
+ FakeFS do
136
+ create_rackup_file('WEB-INF')
137
+ app = Trinidad::WebApp.create({}, {})
138
+
139
+ app.should be_an_instance_of(Trinidad::RackupWebApp)
140
+ end
141
+ end
142
+
143
+ it "doesn't add the rackup init parameter when the rackup file is under WEB-INF directory" do
144
+ FakeFS do
145
+ create_rackup_file('WEB-INF')
146
+ app = Trinidad::WebApp.create({}, {})
147
+
148
+ app.init_params.should_not include('rackup.path')
149
+ end
150
+ end
151
+
152
+ it "loads rackup file from a given directory" do
153
+ FakeFS do
154
+ create_rackup_file('rack')
155
+ app = Trinidad::WebApp.create({}, {
156
+ :web_app_dir => Dir.pwd,
157
+ :rackup => 'rack'
158
+ })
159
+ app.init_params.should include('rackup.path')
160
+ app.init_params['rackup.path'].should == 'rack/config.ru'
161
+ end
162
+ end
163
+
164
+ it "allows to configure the servlet from the configuration options" do
165
+ app = Trinidad::WebApp.create({}, {
166
+ :servlet => {
167
+ :class => 'org.jruby.trinidad.FakeServlet',
168
+ :name => 'FakeServlet'
169
+ }
170
+ })
171
+
172
+ app.servlet[:class].should == 'org.jruby.trinidad.FakeServlet'
173
+ app.servlet[:name].should == 'FakeServlet'
174
+ end
133
175
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 1
9
- version: 0.9.1
8
+ - 2
9
+ version: 0.9.2
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-05-09 00:00:00 +02:00
17
+ date: 2010-05-24 00:00:00 +02:00
18
18
  default_executable: trinidad
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -38,8 +38,10 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  segments:
41
+ - 1
41
42
  - 0
42
- version: "0"
43
+ - 1
44
+ version: 1.0.1
43
45
  type: :runtime
44
46
  version_requirements: *id002
45
47
  - !ruby/object:Gem::Dependency