calavera-tomcat-rails 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/History.txt +11 -0
- data/LICENSE +6 -0
- data/README.rdoc +15 -0
- data/Rakefile +2 -2
- data/TODO.txt +2 -3
- data/VERSION +1 -1
- data/lib/tomcat-rails/command_line_parser.rb +9 -2
- data/lib/tomcat-rails/server.rb +12 -4
- data/lib/tomcat-rails/web_app.rb +35 -17
- data/spec/tomcat-rails/command_line_parser_spec.rb +8 -0
- data/spec/tomcat-rails/web_app_spec.rb +30 -3
- data/spec/web_app_mock/config/web.xml +7 -0
- data/spec/web_app_mock/tomcat.yml +3 -0
- data/tomcat-rails.gemspec +7 -5
- metadata +7 -5
- data/HelloTomcat.java +0 -1
data/.gitignore
CHANGED
data/History.txt
CHANGED
data/LICENSE
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
== Tomcat Rails
|
2
|
+
|
1
3
|
Copyright (c) 2009 David Calavera
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
@@ -18,3 +20,7 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
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
CHANGED
@@ -12,6 +12,21 @@ This project has just born, there are a lot of things to do. Take a look at the
|
|
12
12
|
|
13
13
|
cd myrailsapp
|
14
14
|
jruby -S tomcat_rails
|
15
|
+
|
16
|
+
== CONFIGURATION:
|
17
|
+
|
18
|
+
Tomcat-Rails 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:
|
19
|
+
|
20
|
+
* -p, --port PORT => port to bind to.
|
21
|
+
* -e, --env ENVIRONMENT => rails environment.
|
22
|
+
* -c, --context CONTEXT => application context path.
|
23
|
+
* --lib, --jars LIBS_DIR => directory containing jars.
|
24
|
+
* --classes CLASSES_DIR => directory containing classes.
|
25
|
+
|
26
|
+
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).
|
27
|
+
|
28
|
+
jruby -S tomcat_rails -f
|
29
|
+
jruby -S tomcat_rails --config my_custom_configuration.yml
|
15
30
|
|
16
31
|
== Copyright
|
17
32
|
|
data/Rakefile
CHANGED
@@ -5,9 +5,9 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "tomcat-rails"
|
8
|
-
gem.summary = %Q{Simple library to run
|
8
|
+
gem.summary = %Q{Simple library to run rails applications into an embedded Tomcat}
|
9
9
|
gem.email = "david.calavera@gmail.com"
|
10
|
-
gem.homepage = "http://github.com/
|
10
|
+
gem.homepage = "http://calavera.github.com/tomcat-rails"
|
11
11
|
gem.authors = ["David Calavera"]
|
12
12
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
13
|
end
|
data/TODO.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -4,11 +4,12 @@ module TomcatRails
|
|
4
4
|
class CommandLineParser
|
5
5
|
def self.parse
|
6
6
|
default_options = {
|
7
|
-
:port =>
|
7
|
+
:port => 3000,
|
8
8
|
:environment => 'development',
|
9
9
|
:context_path => '/',
|
10
10
|
:libs_dir => 'lib',
|
11
|
-
:classes_dir => 'classes'
|
11
|
+
:classes_dir => 'classes',
|
12
|
+
:config => 'config/tomcat.yml'
|
12
13
|
}
|
13
14
|
|
14
15
|
parser = OptionParser.new do |opts|
|
@@ -38,6 +39,12 @@ module TomcatRails
|
|
38
39
|
opts.on('--classes', '--classes CLASSES_DIR', 'Directory containing classes used by the application',
|
39
40
|
"default: #{default_options[:classes_dir]}") do |v|
|
40
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])
|
41
48
|
end
|
42
49
|
|
43
50
|
opts.on('-v', '--version', 'display the current version') do
|
data/lib/tomcat-rails/server.rb
CHANGED
@@ -6,24 +6,32 @@ module TomcatRails
|
|
6
6
|
:context_path => '/',
|
7
7
|
:libs_dir => 'lib',
|
8
8
|
:classes_dir => 'classes',
|
9
|
+
:default_web_xml => 'config/web.xml',
|
9
10
|
:port => 3000,
|
10
11
|
:jruby_min_runtimes => 1,
|
11
12
|
:jruby_max_runtimes => 5
|
12
13
|
}
|
13
14
|
|
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)
|
15
22
|
@config = @@defaults.merge!(config)
|
16
23
|
@config[:web_app_dir] = Dir.pwd
|
17
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_tomcat_server
|
18
27
|
@tomcat = TomcatRails::Tomcat::Tomcat.new
|
19
28
|
@tomcat.setPort(@config[:port].to_i)
|
20
|
-
|
21
|
-
create_web_app
|
22
29
|
end
|
23
30
|
|
24
31
|
def create_web_app
|
25
32
|
web_app = WebApp.new(@tomcat.addWebapp(@config[:context_path].to_s, @config[:web_app_dir]), @config)
|
26
|
-
|
33
|
+
|
34
|
+
web_app.load_default_web_xml
|
27
35
|
web_app.add_rack_filter
|
28
36
|
web_app.add_context_loader
|
29
37
|
web_app.add_init_params
|
data/lib/tomcat-rails/web_app.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module TomcatRails
|
2
2
|
class WebApp
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :context, :config
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(context, config)
|
6
|
+
@context = context
|
7
7
|
@config = config
|
8
8
|
end
|
9
9
|
|
@@ -17,8 +17,8 @@ module TomcatRails
|
|
17
17
|
filter_map.setFilterName('RackFilter')
|
18
18
|
filter_map.addURLPattern("#{pattern}/*")
|
19
19
|
|
20
|
-
@
|
21
|
-
@
|
20
|
+
@context.addFilterDef(filter_def)
|
21
|
+
@context.addFilterMap(filter_map)
|
22
22
|
end
|
23
23
|
|
24
24
|
def add_context_loader
|
@@ -28,28 +28,25 @@ module TomcatRails
|
|
28
28
|
|
29
29
|
loader = TomcatRails::Tomcat::WebappLoader.new(class_loader)
|
30
30
|
|
31
|
-
loader.container = @
|
32
|
-
@
|
31
|
+
loader.container = @context
|
32
|
+
@context.loader = loader
|
33
33
|
end
|
34
34
|
|
35
35
|
def add_init_params
|
36
|
-
[:jruby_min_runtimes, :jruby_max_runtimes]
|
37
|
-
@web_app.addParameter(param.to_s.gsub(/_/, '.'), @config[param].to_s)
|
38
|
-
end
|
39
|
-
|
40
|
-
@web_app.addParameter('jruby.initial.runtimes', @config[:jruby_min_runtimes].to_s)
|
41
|
-
@web_app.addParameter('rails.env', @config[:environment].to_s)
|
42
|
-
@web_app.addParameter('rails.root', '/')
|
43
|
-
@web_app.addParameter('public.root', '/public')
|
36
|
+
add_init_params_array([:jruby_min_runtimes, :jruby_max_runtimes])
|
44
37
|
|
38
|
+
@context.addParameter('jruby.initial.runtimes', @config[:jruby_min_runtimes].to_s)
|
39
|
+
@context.addParameter('rails.env', @config[:environment].to_s)
|
40
|
+
@context.addParameter('rails.root', '/')
|
41
|
+
@context.addParameter('public.root', '/public')
|
45
42
|
end
|
46
43
|
|
47
44
|
def add_web_dir_resources
|
48
|
-
@
|
45
|
+
@context.setDocBase(File.join(@config[:web_app_dir], "public/"))
|
49
46
|
end
|
50
47
|
|
51
48
|
def add_rack_context_listener
|
52
|
-
@
|
49
|
+
@context.addApplicationListener('org.jruby.rack.rails.RailsServletContextListener')
|
53
50
|
end
|
54
51
|
|
55
52
|
def add_application_libs(class_loader)
|
@@ -64,5 +61,26 @@ module TomcatRails
|
|
64
61
|
resources_dir = File.join(@config[:web_app_dir], @config[:classes_dir])
|
65
62
|
class_loader.addURL(java.io.File.new(resources_dir).to_url)
|
66
63
|
end
|
64
|
+
|
65
|
+
def load_default_web_xml
|
66
|
+
default_web_xml = File.expand_path(File.join(@config[:web_app_dir], @config[:default_web_xml]))
|
67
|
+
|
68
|
+
if File.exist?(default_web_xml)
|
69
|
+
@context.setDefaultWebXml(default_web_xml)
|
70
|
+
@context.setDefaultContextXml(default_web_xml)
|
71
|
+
|
72
|
+
context_config = TomcatRails::Tomcat::ContextConfig.new
|
73
|
+
context_config.setDefaultWebXml(default_web_xml)
|
74
|
+
|
75
|
+
@context.addLifecycleListener(context_config)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
def add_init_params_array(array)
|
81
|
+
array.each do |param|
|
82
|
+
@context.addParameter(param.to_s.gsub(/_/, '.'), @config[param].to_s)
|
83
|
+
end
|
84
|
+
end
|
67
85
|
end
|
68
86
|
end
|
@@ -21,4 +21,12 @@ describe TomcatRails::CommandLineParser do
|
|
21
21
|
options = TomcatRails::CommandLineParser.parse
|
22
22
|
options[:libs_dir].should == 'my_jars'
|
23
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 = TomcatRails::CommandLineParser.parse
|
29
|
+
options[:environment].should == 'production'
|
30
|
+
end
|
31
|
+
|
24
32
|
end
|
@@ -2,12 +2,15 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
describe TomcatRails::WebApp do
|
4
4
|
before do
|
5
|
-
tomcat = TomcatRails::Tomcat::Tomcat.new
|
6
|
-
tomcat_web_app = tomcat.addWebapp('/', File.dirname(__FILE__) + '/../../')
|
5
|
+
@tomcat = TomcatRails::Tomcat::Tomcat.new
|
6
|
+
tomcat_web_app = @tomcat.addWebapp('/', File.dirname(__FILE__) + '/../../')
|
7
7
|
config = {
|
8
8
|
:libs_dir => 'lib',
|
9
9
|
:classes_dir => 'classes',
|
10
|
-
:
|
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,
|
11
14
|
}
|
12
15
|
@web_app = TomcatRails::WebApp.new(tomcat_web_app, config)
|
13
16
|
end
|
@@ -27,5 +30,29 @@ describe TomcatRails::WebApp do
|
|
27
30
|
resource = class_loader.find_class('HelloTomcat')
|
28
31
|
resource.should_not == nil
|
29
32
|
end
|
33
|
+
|
34
|
+
it "should start application context without errors" do
|
35
|
+
load_tomcat_libs
|
36
|
+
lambda { @web_app.context.start }.should_not raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should add a filter from the default web.xml" do
|
40
|
+
load_tomcat_libs
|
41
|
+
@web_app.load_default_web_xml
|
42
|
+
lambda { @web_app.context.start }.should_not raise_error
|
43
|
+
@web_app.context.findFilterDefs().size().should == 1
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should load init params" do
|
47
|
+
@web_app.add_init_params
|
48
|
+
|
49
|
+
@web_app.context.findParameter('jruby.min.runtimes').should == '2'
|
50
|
+
@web_app.context.findParameter('jruby.max.runtimes').should == '6'
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_tomcat_libs
|
54
|
+
@web_app.config[:libs_dir] = File.join(File.dirname(__FILE__), '..', '..', 'tomcat-libs')
|
55
|
+
@web_app.add_context_loader
|
56
|
+
end
|
30
57
|
|
31
58
|
end
|
data/tomcat-rails.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{tomcat-rails}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["David Calavera"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-23}
|
10
10
|
s.default_executable = %q{tomcat_rails}
|
11
11
|
s.email = %q{david.calavera@gmail.com}
|
12
12
|
s.executables = ["tomcat_rails"]
|
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.files = [
|
18
18
|
".document",
|
19
19
|
".gitignore",
|
20
|
-
"HelloTomcat.java",
|
21
20
|
"History.txt",
|
22
21
|
"LICENSE",
|
23
22
|
"README.rdoc",
|
@@ -32,9 +31,12 @@ Gem::Specification.new do |s|
|
|
32
31
|
"lib/tomcat-rails/web_app.rb",
|
33
32
|
"spec/spec.opts",
|
34
33
|
"spec/spec_helper.rb",
|
34
|
+
"spec/tomcat-rails/command_line_parser_spec.rb",
|
35
35
|
"spec/tomcat-rails/web_app_spec.rb",
|
36
36
|
"spec/web_app_mock/classes/HelloTomcat.class",
|
37
|
+
"spec/web_app_mock/config/web.xml",
|
37
38
|
"spec/web_app_mock/lib/jyaml-1.3.jar",
|
39
|
+
"spec/web_app_mock/tomcat.yml",
|
38
40
|
"tomcat-libs/core-3.1.1.jar",
|
39
41
|
"tomcat-libs/jasper-el.jar",
|
40
42
|
"tomcat-libs/jasper-jdt.jar",
|
@@ -50,11 +52,11 @@ Gem::Specification.new do |s|
|
|
50
52
|
"tomcat-rails.gemspec"
|
51
53
|
]
|
52
54
|
s.has_rdoc = true
|
53
|
-
s.homepage = %q{http://github.com/
|
55
|
+
s.homepage = %q{http://calavera.github.com/tomcat-rails}
|
54
56
|
s.rdoc_options = ["--charset=UTF-8"]
|
55
57
|
s.require_paths = ["lib"]
|
56
58
|
s.rubygems_version = %q{1.3.2}
|
57
|
-
s.summary = %q{Simple library to run
|
59
|
+
s.summary = %q{Simple library to run rails applications into an embedded Tomcat}
|
58
60
|
s.test_files = [
|
59
61
|
"spec/spec_helper.rb",
|
60
62
|
"spec/tomcat-rails/command_line_parser_spec.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calavera-tomcat-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Calavera
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-23 00:00:00 -07:00
|
13
13
|
default_executable: tomcat_rails
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -25,7 +25,6 @@ extra_rdoc_files:
|
|
25
25
|
files:
|
26
26
|
- .document
|
27
27
|
- .gitignore
|
28
|
-
- HelloTomcat.java
|
29
28
|
- History.txt
|
30
29
|
- LICENSE
|
31
30
|
- README.rdoc
|
@@ -40,9 +39,12 @@ files:
|
|
40
39
|
- lib/tomcat-rails/web_app.rb
|
41
40
|
- spec/spec.opts
|
42
41
|
- spec/spec_helper.rb
|
42
|
+
- spec/tomcat-rails/command_line_parser_spec.rb
|
43
43
|
- spec/tomcat-rails/web_app_spec.rb
|
44
44
|
- spec/web_app_mock/classes/HelloTomcat.class
|
45
|
+
- spec/web_app_mock/config/web.xml
|
45
46
|
- spec/web_app_mock/lib/jyaml-1.3.jar
|
47
|
+
- spec/web_app_mock/tomcat.yml
|
46
48
|
- tomcat-libs/core-3.1.1.jar
|
47
49
|
- tomcat-libs/jasper-el.jar
|
48
50
|
- tomcat-libs/jasper-jdt.jar
|
@@ -57,7 +59,7 @@ files:
|
|
57
59
|
- tomcat-libs/tomcat-jasper.jar
|
58
60
|
- tomcat-rails.gemspec
|
59
61
|
has_rdoc: true
|
60
|
-
homepage: http://github.com/
|
62
|
+
homepage: http://calavera.github.com/tomcat-rails
|
61
63
|
post_install_message:
|
62
64
|
rdoc_options:
|
63
65
|
- --charset=UTF-8
|
@@ -81,7 +83,7 @@ rubyforge_project:
|
|
81
83
|
rubygems_version: 1.2.0
|
82
84
|
signing_key:
|
83
85
|
specification_version: 3
|
84
|
-
summary: Simple library to run
|
86
|
+
summary: Simple library to run rails applications into an embedded Tomcat
|
85
87
|
test_files:
|
86
88
|
- spec/spec_helper.rb
|
87
89
|
- spec/tomcat-rails/command_line_parser_spec.rb
|
data/HelloTomcat.java
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
class HelloTomcat {}
|