calavera-tomcat-rails 0.1.1 → 0.1.2

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/HelloTomcat.java ADDED
@@ -0,0 +1 @@
1
+ class HelloTomcat {}
data/Rakefile CHANGED
@@ -16,28 +16,21 @@ rescue LoadError
16
16
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
17
  end
18
18
 
19
- require 'rake/testtask'
20
- Rake::TestTask.new(:test) do |test|
21
- test.libs << 'lib' << 'test'
22
- test.pattern = 'test/**/*_test.rb'
23
- test.verbose = true
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_opts = ['--options', "spec/spec.opts"]
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
24
  end
25
25
 
26
- begin
27
- require 'rcov/rcovtask'
28
- Rcov::RcovTask.new do |test|
29
- test.libs << 'test'
30
- test.pattern = 'test/**/*_test.rb'
31
- test.verbose = true
32
- end
33
- rescue LoadError
34
- task :rcov do
35
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
- end
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.spec_opts = ['--options', "spec/spec.opts"]
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
37
31
  end
38
32
 
39
-
40
- task :default => :test
33
+ task :default => :spec
41
34
 
42
35
  require 'rake/rdoctask'
43
36
  Rake::RDocTask.new do |rdoc|
data/TODO.txt CHANGED
@@ -3,5 +3,4 @@
3
3
  * Add tests!!!!!!!
4
4
  * Add rdocs
5
5
  * configure it from warbler
6
- * configure it from a config file
7
- * autoload of java libraries and classes
6
+ * configure it from a config file
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -6,7 +6,9 @@ module TomcatRails
6
6
  default_options = {
7
7
  :port => '3000',
8
8
  :environment => 'development',
9
- :context_path => '/',
9
+ :context_path => '/',
10
+ :libs_dir => 'lib',
11
+ :classes_dir => 'classes'
10
12
  }
11
13
 
12
14
  parser = OptionParser.new do |opts|
@@ -28,6 +30,16 @@ module TomcatRails
28
30
  default_options[:context_path] = v
29
31
  end
30
32
 
33
+ opts.on('--lib', '--jars LIBS_DIR', 'Directory containing jars used by the application',
34
+ "default: #{default_options[:libs_dir]}") do |v|
35
+ default_options[:libs_dir] = v
36
+ end
37
+
38
+ opts.on('--classes', '--classes CLASSES_DIR', 'Directory containing classes used by the application',
39
+ "default: #{default_options[:classes_dir]}") do |v|
40
+ default_options[:classes_dir] = v
41
+ end
42
+
31
43
  opts.on('-v', '--version', 'display the current version') do
32
44
  puts File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
33
45
  exit
@@ -4,7 +4,7 @@ module TomcatRails
4
4
  @@defaults = {
5
5
  :environment => 'development',
6
6
  :context_path => '/',
7
- :lib_dir => 'lib',
7
+ :libs_dir => 'lib',
8
8
  :classes_dir => 'classes',
9
9
  :port => 3000,
10
10
  :jruby_min_runtimes => 1,
@@ -12,63 +12,29 @@ module TomcatRails
12
12
  }
13
13
 
14
14
  def initialize(config = {})
15
- @config = config.merge!(@@defaults)
15
+ @config = @@defaults.merge!(config)
16
+ @config[:web_app_dir] = Dir.pwd
16
17
 
17
18
  @tomcat = TomcatRails::Tomcat::Tomcat.new
18
- @tomcat.setPort(@config[:port])
19
+ @tomcat.setPort(@config[:port].to_i)
19
20
 
20
- web_app = @tomcat.addWebapp(@config[:context_path], Dir.pwd)
21
+ create_web_app
22
+ end
23
+
24
+ def create_web_app
25
+ web_app = WebApp.new(@tomcat.addWebapp(@config[:context_path].to_s, @config[:web_app_dir]), @config)
21
26
 
22
- add_rack_filter(web_app, @config[:context_path])
23
- add_context_loader(web_app)
24
- add_init_params(web_app)
25
- add_web_dir_resources(web_app)
27
+ web_app.add_rack_filter
28
+ web_app.add_context_loader
29
+ web_app.add_init_params
30
+ web_app.add_web_dir_resources
26
31
 
27
- web_app.addApplicationListener('org.jruby.rack.rails.RailsServletContextListener')
32
+ web_app.add_rack_context_listener
28
33
  end
29
34
 
30
35
  def start
31
36
  @tomcat.start
32
37
  @tomcat.getServer().await
33
38
  end
34
-
35
- private
36
- def add_rack_filter(web_app, context_path)
37
- filter_def = TomcatRails::Tomcat::FilterDef.new
38
- filter_def.setFilterName('RackFilter')
39
- filter_def.setFilterClass('org.jruby.rack.RackFilter')
40
-
41
- pattern = context_path[-1..-1] != '/' ? context_path : context_path[0..-2]
42
- filter_map = TomcatRails::Tomcat::FilterMap.new
43
- filter_map.setFilterName('RackFilter')
44
- filter_map.addURLPattern("#{pattern}/*")
45
-
46
- web_app.addFilterDef(filter_def)
47
- web_app.addFilterMap(filter_map)
48
- end
49
-
50
- def add_context_loader(web_app)
51
- class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
52
- loader = TomcatRails::Tomcat::WebappLoader.new(class_loader)
53
-
54
- loader.container = web_app
55
- web_app.loader = loader
56
- end
57
-
58
- def add_init_params(web_app)
59
- [:jruby_min_runtimes, :jruby_max_runtimes].each do |param|
60
- web_app.addParameter(param.to_s.gsub(/_/, '.'), @config[param].to_s)
61
- end
62
-
63
- web_app.addParameter('jruby.initial.runtimes', @config[:jruby_min_runtimes].to_s)
64
- web_app.addParameter('rails.env', @config[:environment].to_s)
65
- web_app.addParameter('rails.root', '/')
66
- web_app.addParameter('public.root', '/public')
67
-
68
- end
69
-
70
- def add_web_dir_resources(web_app)
71
- web_app.setDocBase(File.join(Dir.pwd, "public/"))
72
- end
73
39
  end
74
40
  end
@@ -0,0 +1,68 @@
1
+ module TomcatRails
2
+ class WebApp
3
+ attr_reader :web_app, :config
4
+
5
+ def initialize(web_app, config)
6
+ @web_app = web_app
7
+ @config = config
8
+ end
9
+
10
+ def add_rack_filter
11
+ filter_def = TomcatRails::Tomcat::FilterDef.new
12
+ filter_def.setFilterName('RackFilter')
13
+ filter_def.setFilterClass('org.jruby.rack.RackFilter')
14
+
15
+ pattern = @config[:context_path][-1..-1] != '/' ? @config[:context_path] : @config[:context_path][0..-2]
16
+ filter_map = TomcatRails::Tomcat::FilterMap.new
17
+ filter_map.setFilterName('RackFilter')
18
+ filter_map.addURLPattern("#{pattern}/*")
19
+
20
+ @web_app.addFilterDef(filter_def)
21
+ @web_app.addFilterMap(filter_map)
22
+ end
23
+
24
+ def add_context_loader
25
+ class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
26
+ add_application_libs(class_loader)
27
+ add_application_classes(class_loader)
28
+
29
+ loader = TomcatRails::Tomcat::WebappLoader.new(class_loader)
30
+
31
+ loader.container = @web_app
32
+ @web_app.loader = loader
33
+ end
34
+
35
+ def add_init_params
36
+ [:jruby_min_runtimes, :jruby_max_runtimes].each do |param|
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')
44
+
45
+ end
46
+
47
+ def add_web_dir_resources
48
+ @web_app.setDocBase(File.join(Dir.pwd, "public/"))
49
+ end
50
+
51
+ def add_rack_context_listener
52
+ @web_app.addApplicationListener('org.jruby.rack.rails.RailsServletContextListener')
53
+ end
54
+
55
+ def add_application_libs(class_loader)
56
+ resources_dir = File.join(@config[:web_app_dir], @config[:libs_dir], '**', '*.jar')
57
+
58
+ Dir[resources_dir].each do |resource|
59
+ class_loader.addURL(java.io.File.new(resource).to_url)
60
+ end
61
+ end
62
+
63
+ def add_application_classes(class_loader)
64
+ resources_dir = File.join(@config[:web_app_dir], @config[:classes_dir])
65
+ class_loader.addURL(java.io.File.new(resources_dir).to_url)
66
+ end
67
+ end
68
+ end
data/lib/tomcat-rails.rb CHANGED
@@ -7,6 +7,7 @@ require 'rubygems'
7
7
  require 'tomcat-rails/command_line_parser'
8
8
  require 'tomcat-rails/jars'
9
9
  require 'tomcat-rails/server'
10
+ require 'tomcat-rails/web_app'
10
11
 
11
12
  module TomcatRails
12
13
  TOMCAT_LIBS = File.dirname(__FILE__) + "/../tomcat-libs" unless defined?(TOMCAT_LIBS)
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format specdoc
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ $:.unshift(File.dirname(__FILE__) + '/../tomcat-libs')
11
+
12
+ require 'java'
13
+ require 'tomcat-rails'
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe TomcatRails::CommandLineParser do
4
+ it "should override classes option" do
5
+ ARGV = "--classes my_classes".split
6
+
7
+ options = TomcatRails::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 = TomcatRails::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 = TomcatRails::CommandLineParser.parse
22
+ options[:libs_dir].should == 'my_jars'
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe TomcatRails::WebApp do
4
+ before do
5
+ tomcat = TomcatRails::Tomcat::Tomcat.new
6
+ tomcat_web_app = tomcat.addWebapp('/', File.dirname(__FILE__) + '/../../')
7
+ config = {
8
+ :libs_dir => 'lib',
9
+ :classes_dir => 'classes',
10
+ :web_app_dir => File.join(File.dirname(__FILE__), '..', 'web_app_mock')
11
+ }
12
+ @web_app = TomcatRails::WebApp.new(tomcat_web_app, config)
13
+ end
14
+
15
+ it "should load custom jars" do
16
+ class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
17
+ @web_app.add_application_libs(class_loader)
18
+
19
+ resource = class_loader.find_class('org.ho.yaml.Yaml')
20
+ resource.should_not == nil
21
+ end
22
+
23
+ it "should load custom classes" do
24
+ class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
25
+ @web_app.add_application_classes(class_loader)
26
+
27
+ resource = class_loader.find_class('HelloTomcat')
28
+ resource.should_not == nil
29
+ end
30
+
31
+ end
Binary file
@@ -0,0 +1,73 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{tomcat-rails}
5
+ s.version = "0.1.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["David Calavera"]
9
+ s.date = %q{2009-06-13}
10
+ s.default_executable = %q{tomcat_rails}
11
+ s.email = %q{david.calavera@gmail.com}
12
+ s.executables = ["tomcat_rails"]
13
+ s.extra_rdoc_files = [
14
+ "LICENSE",
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ ".document",
19
+ ".gitignore",
20
+ "HelloTomcat.java",
21
+ "History.txt",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "TODO.txt",
26
+ "VERSION",
27
+ "bin/tomcat_rails",
28
+ "lib/tomcat-rails.rb",
29
+ "lib/tomcat-rails/command_line_parser.rb",
30
+ "lib/tomcat-rails/jars.rb",
31
+ "lib/tomcat-rails/server.rb",
32
+ "lib/tomcat-rails/web_app.rb",
33
+ "spec/spec.opts",
34
+ "spec/spec_helper.rb",
35
+ "spec/tomcat-rails/web_app_spec.rb",
36
+ "spec/web_app_mock/classes/HelloTomcat.class",
37
+ "spec/web_app_mock/lib/jyaml-1.3.jar",
38
+ "tomcat-libs/core-3.1.1.jar",
39
+ "tomcat-libs/jasper-el.jar",
40
+ "tomcat-libs/jasper-jdt.jar",
41
+ "tomcat-libs/jasper.jar",
42
+ "tomcat-libs/jetty-util-6.1.14.jar",
43
+ "tomcat-libs/jruby-rack-0.9.4.jar",
44
+ "tomcat-libs/jsp-2.1.jar",
45
+ "tomcat-libs/jsp-api-2.1.jar",
46
+ "tomcat-libs/servlet-api-2.5-6.1.14.jar",
47
+ "tomcat-libs/tomcat-core.jar",
48
+ "tomcat-libs/tomcat-dbcp.jar",
49
+ "tomcat-libs/tomcat-jasper.jar",
50
+ "tomcat-rails.gemspec"
51
+ ]
52
+ s.has_rdoc = true
53
+ s.homepage = %q{http://github.com/calavera/tomcat-rails}
54
+ s.rdoc_options = ["--charset=UTF-8"]
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.3.2}
57
+ s.summary = %q{Simple library to run a rails application into an embed Tomcat}
58
+ s.test_files = [
59
+ "spec/spec_helper.rb",
60
+ "spec/tomcat-rails/command_line_parser_spec.rb",
61
+ "spec/tomcat-rails/web_app_spec.rb"
62
+ ]
63
+
64
+ if s.respond_to? :specification_version then
65
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
66
+ s.specification_version = 3
67
+
68
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
69
+ else
70
+ end
71
+ else
72
+ end
73
+ end
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.1.1
4
+ version: 0.1.2
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-11 00:00:00 -07:00
12
+ date: 2009-06-13 00:00:00 -07:00
13
13
  default_executable: tomcat_rails
14
14
  dependencies: []
15
15
 
@@ -25,6 +25,7 @@ extra_rdoc_files:
25
25
  files:
26
26
  - .document
27
27
  - .gitignore
28
+ - HelloTomcat.java
28
29
  - History.txt
29
30
  - LICENSE
30
31
  - README.rdoc
@@ -36,8 +37,12 @@ files:
36
37
  - lib/tomcat-rails/command_line_parser.rb
37
38
  - lib/tomcat-rails/jars.rb
38
39
  - lib/tomcat-rails/server.rb
39
- - test/test_helper.rb
40
- - test/tomcat-rails_test.rb
40
+ - lib/tomcat-rails/web_app.rb
41
+ - spec/spec.opts
42
+ - spec/spec_helper.rb
43
+ - spec/tomcat-rails/web_app_spec.rb
44
+ - spec/web_app_mock/classes/HelloTomcat.class
45
+ - spec/web_app_mock/lib/jyaml-1.3.jar
41
46
  - tomcat-libs/core-3.1.1.jar
42
47
  - tomcat-libs/jasper-el.jar
43
48
  - tomcat-libs/jasper-jdt.jar
@@ -50,6 +55,7 @@ files:
50
55
  - tomcat-libs/tomcat-core.jar
51
56
  - tomcat-libs/tomcat-dbcp.jar
52
57
  - tomcat-libs/tomcat-jasper.jar
58
+ - tomcat-rails.gemspec
53
59
  has_rdoc: true
54
60
  homepage: http://github.com/calavera/tomcat-rails
55
61
  post_install_message:
@@ -77,5 +83,6 @@ signing_key:
77
83
  specification_version: 3
78
84
  summary: Simple library to run a rails application into an embed Tomcat
79
85
  test_files:
80
- - test/test_helper.rb
81
- - test/tomcat-rails_test.rb
86
+ - spec/spec_helper.rb
87
+ - spec/tomcat-rails/command_line_parser_spec.rb
88
+ - spec/tomcat-rails/web_app_spec.rb
data/test/test_helper.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $:.unshift(File.dirname(__FILE__) + '/../lib')
6
- $:.unshift(File.dirname(__FILE__) + '/../jetty-libs')
7
-
8
- require 'tomcat-rails'
9
-
10
- class Test::Unit::TestCase
11
- end
@@ -1,5 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TomcatRailsTest < Test::Unit::TestCase
4
-
5
- end