trinidad 0.3.0
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 +19 -0
- data/LICENSE +26 -0
- data/README.rdoc +36 -0
- data/Rakefile +78 -0
- data/VERSION +1 -0
- data/bin/trinidad +9 -0
- data/lib/trinidad/command_line_parser.rb +66 -0
- data/lib/trinidad/jars.rb +26 -0
- data/lib/trinidad/server.rb +48 -0
- data/lib/trinidad/web_app.rb +103 -0
- data/lib/trinidad.rb +14 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/trinidad/command_line_parser_spec.rb +32 -0
- data/spec/trinidad/web_app_spec.rb +97 -0
- data/trinidad-libs/core-3.1.1.jar +0 -0
- data/trinidad-libs/jasper-el.jar +0 -0
- data/trinidad-libs/jasper-jdt.jar +0 -0
- data/trinidad-libs/jasper.jar +0 -0
- data/trinidad-libs/jetty-util-6.1.14.jar +0 -0
- data/trinidad-libs/jruby-rack-0.9.4.jar +0 -0
- data/trinidad-libs/jsp-2.1.jar +0 -0
- data/trinidad-libs/jsp-api-2.1.jar +0 -0
- data/trinidad-libs/servlet-api-2.5-6.1.14.jar +0 -0
- data/trinidad-libs/tomcat-core.jar +0 -0
- data/trinidad-libs/tomcat-dbcp.jar +0 -0
- data/trinidad-libs/tomcat-jasper.jar +0 -0
- metadata +80 -0
data/History.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
== 0.3.0 (2009-07-07)
|
2
|
+
|
3
|
+
* project renamed due to tomcat legal issues
|
4
|
+
|
5
|
+
== 0.2.0 (2009-06-23)
|
6
|
+
|
7
|
+
* custom configuration from a yaml file
|
8
|
+
* load options from a custom web.xml
|
9
|
+
|
10
|
+
== 0.1.2
|
11
|
+
|
12
|
+
* Autoload application custom jars and classes.
|
13
|
+
* Added some specs.
|
14
|
+
* Server refactor.
|
15
|
+
|
16
|
+
== 0.1
|
17
|
+
|
18
|
+
* Initial release.
|
19
|
+
* Running default rails applications.
|
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
== Trinidad
|
2
|
+
|
3
|
+
Copyright (c) 2009 David Calavera
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
== Additional Bundled Software
|
25
|
+
|
26
|
+
Apache Tomcat is licensed according to the terms of Apache License, Version 2.0 (current). See http://www.apache.org/licenses/LICENSE-2.0 for details.
|
data/README.rdoc
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
= trinidad
|
2
|
+
|
3
|
+
Trinidad allows you to run a rails application within an embedded Apache Tomcat container.
|
4
|
+
|
5
|
+
This project was initially called "Tomcat-rails" but due to legal issues with the ASF and the Tomcat trademark it has been renamed.
|
6
|
+
|
7
|
+
== INSTALL:
|
8
|
+
|
9
|
+
jgem install trinidad
|
10
|
+
jgem install calavera-trinidad -s http://gems.github.com
|
11
|
+
|
12
|
+
== USAGE:
|
13
|
+
|
14
|
+
cd myrailsapp
|
15
|
+
jruby -S trinidad
|
16
|
+
|
17
|
+
== CONFIGURATION:
|
18
|
+
|
19
|
+
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
|
+
|
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
|
+
|
27
|
+
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).
|
28
|
+
|
29
|
+
jruby -S trinidad -f
|
30
|
+
jruby -S trinidad --config my_custom_configuration.yml
|
31
|
+
|
32
|
+
You can also specify a default web.xml to config your web application. By default the server tries to load the file <em>config/web.xml</em> but you can modify this path adding the option <em>default_web_xml</em> within your configuration file.
|
33
|
+
|
34
|
+
== Copyright
|
35
|
+
|
36
|
+
Copyright (c) 2009 David Calavera<calavera@apache.org>. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "trinidad"
|
8
|
+
gem.summary = %Q{Simple library to run rails applications into an embedded Tomcat}
|
9
|
+
gem.email = "david.calavera@gmail.com"
|
10
|
+
gem.homepage = "http://calavera.github.com/trinidad"
|
11
|
+
gem.authors = ["David Calavera"]
|
12
|
+
gem.rubyforge_project = 'trinidad'
|
13
|
+
|
14
|
+
gem.files = FileList['bin/*', 'lib/**/*.rb', 'trinidad-libs/*.jar', 'History.txt', 'LICENSE', 'Rakefile', 'README.rdoc', 'VERSION']
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_opts = ['--options', "spec/spec.opts"]
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.spec_opts = ['--options', "spec/spec.opts"]
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
if File.exist?('VERSION.yml')
|
41
|
+
config = YAML.load(File.read('VERSION.yml'))
|
42
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
43
|
+
else
|
44
|
+
version = ""
|
45
|
+
end
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "trinidad #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
52
|
+
|
53
|
+
begin
|
54
|
+
require 'rake/contrib/sshpublisher'
|
55
|
+
namespace :rubyforge do
|
56
|
+
|
57
|
+
desc "Release gem and RDoc documentation to RubyForge"
|
58
|
+
task :release => ["rubyforge:release:gem"]
|
59
|
+
|
60
|
+
namespace :release do
|
61
|
+
desc "Publish RDoc to RubyForge."
|
62
|
+
task :docs => [:rdoc] do
|
63
|
+
config = YAML.load(
|
64
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
65
|
+
)
|
66
|
+
|
67
|
+
host = "#{config['username']}@rubyforge.org"
|
68
|
+
remote_dir = "/var/www/gforge-projects/trinidad/"
|
69
|
+
local_dir = 'rdoc'
|
70
|
+
|
71
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
rescue LoadError
|
76
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
77
|
+
end
|
78
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
data/bin/trinidad
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module Trinidad
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
class CommandLineParser
|
5
|
+
def self.parse
|
6
|
+
default_options = {
|
7
|
+
:port => 3000,
|
8
|
+
:environment => 'development',
|
9
|
+
:context_path => '/',
|
10
|
+
:libs_dir => 'lib',
|
11
|
+
:classes_dir => 'classes',
|
12
|
+
:config => 'config/tomcat.yml'
|
13
|
+
}
|
14
|
+
|
15
|
+
parser = OptionParser.new do |opts|
|
16
|
+
opts.banner = 'Trinidad server default options:'
|
17
|
+
opts.separator ''
|
18
|
+
|
19
|
+
opts.on('-e', '--env ENVIRONMENT', 'Rails environment',
|
20
|
+
"default: #{default_options[:environment]}") do |v|
|
21
|
+
default_options[:environment] = v
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-p', '--port PORT', 'Port to bind to',
|
25
|
+
"default: #{default_options[:port]}") do |v|
|
26
|
+
default_options[:port] = v
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on('-c', '--context CONTEXT_PATH', 'The application context path',
|
30
|
+
"default: #{default_options[:context_path]}") do |v|
|
31
|
+
default_options[:context_path] = v
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('--lib', '--jars LIBS_DIR', 'Directory containing jars used by the application',
|
35
|
+
"default: #{default_options[:libs_dir]}") do |v|
|
36
|
+
default_options[:libs_dir] = v
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on('--classes', '--classes CLASSES_DIR', 'Directory containing classes used by the application',
|
40
|
+
"default: #{default_options[:classes_dir]}") do |v|
|
41
|
+
default_options[:classes_dir] = v
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on('-f', '--config [CONFIG_FILE]', 'Configuration file',
|
45
|
+
"default: #{default_options[:config]}") do |v|
|
46
|
+
default_options[:config] = v if v
|
47
|
+
default_options.merge! YAML.load_file(default_options[:config])
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.on('-v', '--version', 'display the current version') do
|
51
|
+
puts File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on('-h', '--help', 'display the help') do
|
56
|
+
puts opts
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.parse!(ARGV)
|
61
|
+
end
|
62
|
+
|
63
|
+
default_options
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Trinidad
|
2
|
+
|
3
|
+
require "servlet-api-2.5-6.1.14"
|
4
|
+
require "core-3.1.1"
|
5
|
+
require "jsp-api-2.1"
|
6
|
+
require "jsp-2.1"
|
7
|
+
require 'tomcat-core'
|
8
|
+
require 'jetty-util-6.1.14'
|
9
|
+
|
10
|
+
require "jruby-rack-0.9.4"
|
11
|
+
|
12
|
+
module Tomcat
|
13
|
+
include_package 'org.apache.catalina'
|
14
|
+
include_package 'org.apache.catalina.startup'
|
15
|
+
include_package 'org.apache.catalina.core'
|
16
|
+
include_package 'org.apache.catalina.deploy'
|
17
|
+
include_package 'org.apache.catalina.loader'
|
18
|
+
|
19
|
+
include_package 'org.apache.naming.resources'
|
20
|
+
end
|
21
|
+
|
22
|
+
module Rack
|
23
|
+
include_package "org.jruby.rack"
|
24
|
+
include_package "org.jruby.rack.rails"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Trinidad
|
2
|
+
class Server
|
3
|
+
|
4
|
+
@@defaults = {
|
5
|
+
:environment => 'development',
|
6
|
+
:context_path => '/',
|
7
|
+
:libs_dir => 'lib',
|
8
|
+
:classes_dir => 'classes',
|
9
|
+
:default_web_xml => 'config/web.xml',
|
10
|
+
:port => 3000,
|
11
|
+
:jruby_min_runtimes => 1,
|
12
|
+
:jruby_max_runtimes => 5
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize(config = {})
|
16
|
+
load_config(config)
|
17
|
+
load_tomcat_server
|
18
|
+
create_web_app
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_config(config)
|
22
|
+
@config = @@defaults.merge!(config)
|
23
|
+
@config[:web_app_dir] = Dir.pwd
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_tomcat_server
|
27
|
+
@tomcat = Trinidad::Tomcat::Tomcat.new
|
28
|
+
@tomcat.setPort(@config[:port].to_i)
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_web_app
|
32
|
+
web_app = WebApp.new(@tomcat.addWebapp(@config[:context_path].to_s, @config[:web_app_dir]), @config)
|
33
|
+
|
34
|
+
web_app.load_default_web_xml
|
35
|
+
web_app.add_rack_filter
|
36
|
+
web_app.add_context_loader
|
37
|
+
web_app.add_init_params
|
38
|
+
web_app.add_web_dir_resources
|
39
|
+
|
40
|
+
web_app.add_rack_context_listener
|
41
|
+
end
|
42
|
+
|
43
|
+
def start
|
44
|
+
@tomcat.start
|
45
|
+
@tomcat.getServer().await
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Trinidad
|
2
|
+
class WebApp
|
3
|
+
attr_reader :context, :config
|
4
|
+
|
5
|
+
def initialize(context, config)
|
6
|
+
@context = context
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_rack_filter
|
11
|
+
unless rack_filter_configured?
|
12
|
+
filter_def = Trinidad::Tomcat::FilterDef.new
|
13
|
+
filter_def.setFilterName('RackFilter')
|
14
|
+
filter_def.setFilterClass('org.jruby.rack.RackFilter')
|
15
|
+
|
16
|
+
pattern = @config[:context_path][-1..-1] != '/' ? @config[:context_path] : @config[:context_path][0..-2]
|
17
|
+
filter_map = Trinidad::Tomcat::FilterMap.new
|
18
|
+
filter_map.setFilterName('RackFilter')
|
19
|
+
filter_map.addURLPattern("#{pattern}/*")
|
20
|
+
|
21
|
+
@context.addFilterDef(filter_def)
|
22
|
+
@context.addFilterMap(filter_map)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_context_loader
|
27
|
+
class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
|
28
|
+
add_application_libs(class_loader)
|
29
|
+
add_application_classes(class_loader)
|
30
|
+
|
31
|
+
loader = Trinidad::Tomcat::WebappLoader.new(class_loader)
|
32
|
+
|
33
|
+
loader.container = @context
|
34
|
+
@context.loader = loader
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_init_params
|
38
|
+
[:jruby_min_runtimes, :jruby_max_runtimes].each do |param|
|
39
|
+
param_name = param.to_s.gsub(/_/, '.')
|
40
|
+
@context.addParameter(param_name, @config[param].to_s) unless @context.findParameter(param_name)
|
41
|
+
end
|
42
|
+
|
43
|
+
@context.addParameter('jruby.initial.runtimes', @config[:jruby_min_runtimes].to_s) unless @context.findParameter('jruby.initial.runtimes')
|
44
|
+
@context.addParameter('rails.env', @config[:environment].to_s) unless @context.findParameter('rails.env')
|
45
|
+
@context.addParameter('rails.root', '/') unless @context.findParameter('rails.root')
|
46
|
+
@context.addParameter('public.root', '/public') unless @context.findParameter('public.root')
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_web_dir_resources
|
50
|
+
@context.setDocBase(File.join(@config[:web_app_dir], "public/"))
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_rack_context_listener
|
54
|
+
unless rack_listener_configured?
|
55
|
+
@context.addApplicationListener('org.jruby.rack.rails.RailsServletContextListener')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_application_libs(class_loader)
|
60
|
+
resources_dir = File.join(@config[:web_app_dir], @config[:libs_dir], '**', '*.jar')
|
61
|
+
|
62
|
+
Dir[resources_dir].each do |resource|
|
63
|
+
class_loader.addURL(java.io.File.new(resource).to_url)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_application_classes(class_loader)
|
68
|
+
resources_dir = File.join(@config[:web_app_dir], @config[:classes_dir])
|
69
|
+
class_loader.addURL(java.io.File.new(resources_dir).to_url)
|
70
|
+
end
|
71
|
+
|
72
|
+
def load_default_web_xml
|
73
|
+
default_web_xml = File.expand_path(File.join(@config[:web_app_dir], @config[:default_web_xml]))
|
74
|
+
|
75
|
+
if File.exist?(default_web_xml)
|
76
|
+
@context.setDefaultWebXml(default_web_xml)
|
77
|
+
@context.setDefaultContextXml(default_web_xml)
|
78
|
+
|
79
|
+
context_config = Trinidad::Tomcat::ContextConfig.new
|
80
|
+
context_config.setDefaultWebXml(default_web_xml)
|
81
|
+
|
82
|
+
@context.addLifecycleListener(context_config)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def rack_filter_configured?
|
87
|
+
return false if @context.getDefaultWebXml().nil?
|
88
|
+
|
89
|
+
web_xml = IO.read(@context.getDefaultWebXml())
|
90
|
+
|
91
|
+
return web_xml.include?('<servlet-class>org.jruby.rack.RackServlet') ||
|
92
|
+
web_xml.include?('<filter-class>org.jruby.rack.RackFilter')
|
93
|
+
end
|
94
|
+
|
95
|
+
def rack_listener_configured?
|
96
|
+
return false if @context.getDefaultWebXml().nil?
|
97
|
+
|
98
|
+
web_xml = IO.read(@context.getDefaultWebXml())
|
99
|
+
|
100
|
+
return web_xml.include?('<listener-class>org.jruby.rack.rails.RailsServletContextListener')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/trinidad.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require "java"
|
5
|
+
require 'rubygems'
|
6
|
+
|
7
|
+
require 'trinidad/command_line_parser'
|
8
|
+
require 'trinidad/jars'
|
9
|
+
require 'trinidad/server'
|
10
|
+
require 'trinidad/web_app'
|
11
|
+
|
12
|
+
module Trinidad
|
13
|
+
TRINIDAD_LIBS = File.dirname(__FILE__) + "/../trinidad-libs" unless defined?(TRINIDAD_LIBS)
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Trinidad::CommandLineParser do
|
4
|
+
it "should override classes option" do
|
5
|
+
ARGV = "--classes my_classes".split
|
6
|
+
|
7
|
+
options = Trinidad::CommandLineParser.parse
|
8
|
+
options[:classes_dir].should == 'my_classes'
|
9
|
+
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
|
+
options[:libs_dir].should == 'my_libs'
|
16
|
+
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
|
+
options[:libs_dir].should == 'my_jars'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should override the config file when it's especified" do
|
26
|
+
ARGV = "-f #{File.join(File.dirname(__FILE__), '..', 'web_app_mock', 'tomcat.yml')}".split
|
27
|
+
|
28
|
+
options = Trinidad::CommandLineParser.parse
|
29
|
+
options[:environment].should == 'production'
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Trinidad::WebApp do
|
4
|
+
before do
|
5
|
+
@tomcat = Trinidad::Tomcat::Tomcat.new
|
6
|
+
tomcat_web_app = @tomcat.addWebapp('/', File.dirname(__FILE__) + '/../../')
|
7
|
+
config = {
|
8
|
+
:libs_dir => 'lib',
|
9
|
+
:classes_dir => 'classes',
|
10
|
+
:default_web_xml => 'config/web.xml',
|
11
|
+
:web_app_dir => File.join(File.dirname(__FILE__), '..', 'web_app_mock'),
|
12
|
+
:jruby_min_runtimes => 2,
|
13
|
+
:jruby_max_runtimes => 6,
|
14
|
+
:context_path => '/'
|
15
|
+
}
|
16
|
+
@web_app = Trinidad::WebApp.new(tomcat_web_app, config)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should load custom jars" do
|
20
|
+
class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
|
21
|
+
@web_app.add_application_libs(class_loader)
|
22
|
+
|
23
|
+
resource = class_loader.find_class('org.ho.yaml.Yaml')
|
24
|
+
resource.should_not == nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should load custom classes" do
|
28
|
+
class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
|
29
|
+
@web_app.add_application_classes(class_loader)
|
30
|
+
|
31
|
+
resource = class_loader.find_class('HelloTomcat')
|
32
|
+
resource.should_not == nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should start application context without errors" do
|
36
|
+
start_context
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should add a filter from the default web.xml" do
|
40
|
+
start_context_with_web_xml
|
41
|
+
@web_app.context.findFilterDefs().size().should == 1
|
42
|
+
end
|
43
|
+
|
44
|
+
it "shouldn't duplicate init params" do
|
45
|
+
start_context_with_web_xml
|
46
|
+
lambda { @web_app.add_init_params }.should_not raise_error
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should load init params" do
|
50
|
+
@web_app.add_init_params
|
51
|
+
|
52
|
+
@web_app.context.findParameter('jruby.min.runtimes').should == '2'
|
53
|
+
@web_app.context.findParameter('jruby.max.runtimes').should == '6'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should configure rack filter" do
|
57
|
+
@web_app.add_rack_filter
|
58
|
+
@web_app.context.findFilterDefs().size().should == 1
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should configure rack listener" do
|
62
|
+
@web_app.add_rack_context_listener
|
63
|
+
@web_app.context.findApplicationListeners().size().should == 1
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have rack filter already configured" do
|
67
|
+
@web_app.load_default_web_xml
|
68
|
+
@web_app.rack_filter_configured?().should == true
|
69
|
+
|
70
|
+
@web_app.add_rack_filter
|
71
|
+
@web_app.context.findFilterDefs().size().should == 0
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should have rack listener already configured" do
|
75
|
+
@web_app.load_default_web_xml
|
76
|
+
@web_app.rack_listener_configured?().should == true
|
77
|
+
|
78
|
+
@web_app.add_rack_context_listener
|
79
|
+
@web_app.context.findApplicationListeners().size().should == 0
|
80
|
+
end
|
81
|
+
|
82
|
+
def start_context_with_web_xml
|
83
|
+
@web_app.load_default_web_xml
|
84
|
+
start_context
|
85
|
+
end
|
86
|
+
|
87
|
+
def start_context
|
88
|
+
load_tomcat_libs
|
89
|
+
lambda { @web_app.context.start }.should_not raise_error
|
90
|
+
end
|
91
|
+
|
92
|
+
def load_tomcat_libs
|
93
|
+
@web_app.config[:libs_dir] = File.join(File.dirname(__FILE__), '..', '..', 'tomcat-libs')
|
94
|
+
@web_app.add_context_loader
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trinidad
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Calavera
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-07 00:00:00 +02:00
|
13
|
+
default_executable: trinidad
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: david.calavera@gmail.com
|
18
|
+
executables:
|
19
|
+
- trinidad
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- History.txt
|
27
|
+
- LICENSE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- VERSION
|
31
|
+
- bin/trinidad
|
32
|
+
- lib/trinidad.rb
|
33
|
+
- lib/trinidad/command_line_parser.rb
|
34
|
+
- lib/trinidad/jars.rb
|
35
|
+
- lib/trinidad/server.rb
|
36
|
+
- lib/trinidad/web_app.rb
|
37
|
+
- trinidad-libs/core-3.1.1.jar
|
38
|
+
- trinidad-libs/jasper-el.jar
|
39
|
+
- trinidad-libs/jasper-jdt.jar
|
40
|
+
- trinidad-libs/jasper.jar
|
41
|
+
- trinidad-libs/jetty-util-6.1.14.jar
|
42
|
+
- trinidad-libs/jruby-rack-0.9.4.jar
|
43
|
+
- trinidad-libs/jsp-2.1.jar
|
44
|
+
- trinidad-libs/jsp-api-2.1.jar
|
45
|
+
- trinidad-libs/servlet-api-2.5-6.1.14.jar
|
46
|
+
- trinidad-libs/tomcat-core.jar
|
47
|
+
- trinidad-libs/tomcat-dbcp.jar
|
48
|
+
- trinidad-libs/tomcat-jasper.jar
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://calavera.github.com/trinidad
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --charset=UTF-8
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project: trinidad
|
73
|
+
rubygems_version: 1.3.4
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Simple library to run rails applications into an embedded Tomcat
|
77
|
+
test_files:
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- spec/trinidad/command_line_parser_spec.rb
|
80
|
+
- spec/trinidad/web_app_spec.rb
|