jetty-rails 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -4,6 +4,7 @@ Manifest.txt
4
4
  PostInstall.txt
5
5
  README.txt
6
6
  Rakefile
7
+ bin/jetty_merb
7
8
  bin/jetty_rails
8
9
  config/hoe.rb
9
10
  config/requirements.rb
@@ -11,6 +12,8 @@ lib/jetty-6.1.9.jar
11
12
  lib/jetty-plus-6.1.9.jar
12
13
  lib/jetty-util-6.1.9.jar
13
14
  lib/jetty_rails.rb
15
+ lib/jetty_rails/adapters/merb_adapter.rb
16
+ lib/jetty_rails/adapters/rails_adapter.rb
14
17
  lib/jetty_rails/handler/delegate_on_errors_handler.rb
15
18
  lib/jetty_rails/jars.rb
16
19
  lib/jetty_rails/runner.rb
@@ -22,6 +25,7 @@ script/destroy
22
25
  script/generate
23
26
  script/txt2html
24
27
  setup.rb
28
+ spec/jetty_merb_spec.rb
25
29
  spec/jetty_rails/handler/delegate_on_errors_handler_spec.rb
26
30
  spec/jetty_rails/runner_spec.rb
27
31
  spec/jetty_rails_spec.rb
data/bin/jetty_merb ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ # == Synopsis
4
+ #
5
+ # jetty_merb: jetty server for merb applications
6
+ #
7
+ # == Usage
8
+ #
9
+ # jetty_merb [OPTION] ... BASEDIR
10
+ #
11
+ # -h, --help::
12
+ # show help
13
+ #
14
+ # --context-path PATH, -u PATH::
15
+ # change the application context path (default: '/')
16
+ #
17
+ # --port PORT, -p PORT::
18
+ # change server port (default: 4000)
19
+ #
20
+ # --environment ENV, -e ENV::
21
+ # change rails environment (default: development)
22
+ #
23
+ # BASEDIR (optional): directory to be run (default: current).
24
+
25
+ require "java"
26
+ require "jetty_rails"
27
+ require 'rdoc/usage'
28
+ require 'getoptlong'
29
+
30
+ # fix to work with rubygems (use current file instead of main)
31
+ def RDoc.usage_no_exit(*args)
32
+ comment = File.open(__FILE__) do |file|
33
+ find_comment(file)
34
+ end
35
+
36
+ comment = comment.gsub(/^\s*#/, '')
37
+
38
+ markup = SM::SimpleMarkup.new
39
+ flow_convertor = SM::ToFlow.new
40
+
41
+ flow = markup.convert(comment, flow_convertor)
42
+
43
+ format = "plain"
44
+
45
+ unless args.empty?
46
+ flow = extract_sections(flow, args)
47
+ end
48
+
49
+ options = RI::Options.instance
50
+ if args = ENV["RI"]
51
+ options.parse(args.split)
52
+ end
53
+ formatter = options.formatter.new(options, "")
54
+ formatter.display_flow(flow)
55
+ end
56
+
57
+ opts = GetoptLong.new(
58
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
59
+ [ '--context-path', '-u', GetoptLong::REQUIRED_ARGUMENT ],
60
+ [ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT ],
61
+ [ '--environment', '-e', GetoptLong::REQUIRED_ARGUMENT ]
62
+ )
63
+
64
+ config = {
65
+ :base => Dir.pwd,
66
+ :port => 4000,
67
+ :adapter => :merb
68
+ }
69
+
70
+ opts.each do |opt, arg|
71
+ case opt
72
+ when '--help'
73
+ RDoc::usage
74
+ when '--context-path'
75
+ config[:context_path] = arg
76
+ when '--port'
77
+ config[:port] = arg.to_i
78
+ when '--environment'
79
+ config[:environment] = arg
80
+ end
81
+ end
82
+
83
+ config[:base] = ARGV.shift unless ARGV.empty?
84
+
85
+ runner = JettyRails::Runner.new(config)
86
+ runner.start
data/bin/jetty_rails CHANGED
@@ -6,7 +6,7 @@
6
6
  #
7
7
  # == Usage
8
8
  #
9
- # jetty_tails [OPTION] ... BASEDIR
9
+ # jetty_rails [OPTION] ... BASEDIR
10
10
  #
11
11
  # -h, --help::
12
12
  # show help
@@ -15,7 +15,7 @@
15
15
  # change the application context path (default: '/')
16
16
  #
17
17
  # --port PORT, -p PORT::
18
- # change server port (default: 8080)
18
+ # change server port (default: 3000)
19
19
  #
20
20
  # --environment ENV, -e ENV::
21
21
  # change rails environment (default: development)
@@ -62,7 +62,9 @@ opts = GetoptLong.new(
62
62
  )
63
63
 
64
64
  config = {
65
- :base => Dir.pwd
65
+ :base => Dir.pwd,
66
+ :port => 3000,
67
+ :adapter => :rails
66
68
  }
67
69
 
68
70
  opts.each do |opt, arg|
data/lib/jetty_rails.rb CHANGED
@@ -5,6 +5,8 @@ require "java"
5
5
  require "rubygems"
6
6
  require "activesupport"
7
7
  require "jetty_rails/jars"
8
+ require "jetty_rails/adapters/rails_adapter"
9
+ require "jetty_rails/adapters/merb_adapter"
8
10
  require "jetty_rails/runner"
9
11
  require "jetty_rails/handler/delegate_on_errors_handler"
10
12
 
@@ -0,0 +1,28 @@
1
+ module JettyRails
2
+ module Adapters
3
+
4
+ class MerbAdapter
5
+ attr_reader :config
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def init_params
12
+ # please refer to goldspike and jruby-rack documentation
13
+ @merb_params ||= {
14
+ 'merb.root' => '/',
15
+ 'public.root' => '/public',
16
+ 'merb.environment' => config[:environment],
17
+ 'gem.path' => 'tmp/war/WEB-INF/gems'
18
+ }
19
+ end
20
+
21
+ def rack_event_listener
22
+ Rack::MerbServletContextListener.new
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module JettyRails
2
+ module Adapters
3
+
4
+ class RailsAdapter
5
+ attr_reader :config
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def init_params
12
+ # please refer to goldspike and jruby-rack documentation
13
+ @rails_params ||= {
14
+ 'rails.root' => '/',
15
+ 'public.root' => '/public',
16
+ 'rails.env' => config[:environment],
17
+ 'gem.path' => 'tmp/war/WEB-INF/gems'
18
+ }
19
+ end
20
+
21
+ def rack_event_listener
22
+ Rack::RailsServletContextListener.new
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -7,6 +7,7 @@ module JettyRails
7
7
  module Jetty
8
8
  include_package "org.mortbay.jetty"
9
9
  include_package "org.mortbay.jetty.servlet"
10
+ include_package "org.mortbay.jetty.nio"
10
11
  module Handler
11
12
  include_package "org.mortbay.jetty.handler"
12
13
  include_package "org.mortbay.jetty.webapp"
@@ -17,6 +18,7 @@ module JettyRails
17
18
  module Rack
18
19
  include_package "org.jruby.rack"
19
20
  include_package "org.jruby.rack.rails"
21
+ include_package "org.jruby.rack.merb"
20
22
  end
21
23
 
22
24
  end
@@ -8,18 +8,27 @@ module JettyRails
8
8
  attr_reader :app_context
9
9
 
10
10
  @@defaults = {
11
+ :adapter => :rails,
11
12
  :environment => 'development',
12
13
  :context_path => '/',
13
14
  :port => 8080
14
15
  }
15
16
 
17
+ @@adapters = {
18
+ :rails => JettyRails::Adapters::RailsAdapter,
19
+ :merb => JettyRails::Adapters::MerbAdapter
20
+ }
21
+
16
22
  def initialize(config = {})
17
23
  @config = config.symbolize_keys!.reverse_merge!(@@defaults)
18
24
  add_root_method_to @config[:context_path]
19
25
 
20
26
  raise 'Basedir to be run must be provided' unless config[:base]
21
27
 
22
- @server = Jetty::Server.new(config[:port])
28
+ @server = Jetty::Server.new
29
+ connector = Jetty::SelectChannelConnector.new
30
+ connector.port = config[:port]
31
+ @server.add_connector(connector)
23
32
 
24
33
  add_public_dir_to server
25
34
  install_rack_on server
@@ -52,15 +61,10 @@ module JettyRails
52
61
  @app_context.class_loader = JRuby.runtime.jruby_class_loader
53
62
  @app_context.resource_base = config[:base]
54
63
 
55
- # refer to goldspike and jruby-rack documentation
56
- @app_context.init_params = {
57
- 'rails.root' => '/',
58
- 'public.root' => '/public',
59
- 'rails.env' => config[:environment],
60
- 'gem.path' => 'tmp/war/WEB-INF/gems'
61
- }
64
+ adapter = adapter_for config[:adapter]
65
+ @app_context.init_params = adapter.init_params
66
+ @app_context.add_event_listener(adapter.rack_event_listener)
62
67
 
63
- @app_context.add_event_listener(Rack::RailsServletContextListener.new)
64
68
  @app_context.add_filter(rack_filter, "/*", Jetty::Context::DEFAULT)
65
69
  server.add_handler(@app_context)
66
70
  end
@@ -77,5 +81,9 @@ module JettyRails
77
81
  end
78
82
  end
79
83
 
84
+ def adapter_for(kind)
85
+ @@adapters[kind.to_sym].new(config)
86
+ end
87
+
80
88
  end
81
89
  end
@@ -1,7 +1,7 @@
1
1
  module JettyRails #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 3
4
+ MINOR = 4
5
5
 
6
6
  STRING = [MAJOR, MINOR].join('.')
7
7
  end
@@ -0,0 +1,142 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "binary executable with no command line arguments" do
4
+
5
+ it "should set adapter to merb" do
6
+ runner = mock("runner", :null_object => true)
7
+ current_dir = Dir.pwd
8
+ JettyRails::Runner.should_receive(:new) do |config|
9
+ config.should have_key(:adapter)
10
+ config[:adapter].should eql(:merb)
11
+ runner
12
+ end
13
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
14
+ end
15
+
16
+ it "should provide the current execution dir as basedir" do
17
+ runner = mock("runner", :null_object => true)
18
+ current_dir = Dir.pwd
19
+ JettyRails::Runner.should_receive(:new) do |config|
20
+ config.should have_key(:base)
21
+ config[:base].should eql(current_dir)
22
+ runner
23
+ end
24
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
25
+ end
26
+
27
+ it "should not set the context path by default" do
28
+ runner = mock("runner", :null_object => true)
29
+ JettyRails::Runner.should_receive(:new) do |config|
30
+ config.should_not have_key(:context_path)
31
+ runner
32
+ end
33
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
34
+ end
35
+
36
+ it "should not set the environment by default" do
37
+ runner = mock("runner", :null_object => true)
38
+ JettyRails::Runner.should_receive(:new) do |config|
39
+ config.should_not have_key(:environment)
40
+ runner
41
+ end
42
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
43
+ end
44
+
45
+ it "should set the port to 4000 by default" do
46
+ runner = mock("runner", :null_object => true)
47
+ JettyRails::Runner.should_receive(:new) do |config|
48
+ config.should have_key(:port)
49
+ config[:port].should eql(4000)
50
+ runner
51
+ end
52
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
53
+ end
54
+
55
+ end
56
+
57
+ describe "binary executable with command line arguments" do
58
+
59
+ it "should take the first command line argument as basedir" do
60
+ ARGV[0] = '/any/app/dir'
61
+ runner = mock("runner", :null_object => true)
62
+ JettyRails::Runner.should_receive(:new) do |config|
63
+ config.should have_key(:base)
64
+ config[:base].should eql('/any/app/dir')
65
+ runner
66
+ end
67
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
68
+ end
69
+
70
+ it "should take --context-path command line option as context path" do
71
+ ARGV[0] = '--context-path'
72
+ ARGV[1] = '/myapp'
73
+ runner = mock("runner", :null_object => true)
74
+ JettyRails::Runner.should_receive(:new) do |config|
75
+ config.should have_key(:context_path)
76
+ config[:context_path].should eql('/myapp')
77
+ runner
78
+ end
79
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
80
+ end
81
+
82
+ it "should take -u command line option as context path" do
83
+ ARGV[0] = '-u'
84
+ ARGV[1] = '/myapp'
85
+ runner = mock("runner", :null_object => true)
86
+ JettyRails::Runner.should_receive(:new) do |config|
87
+ config.should have_key(:context_path)
88
+ config[:context_path].should eql('/myapp')
89
+ runner
90
+ end
91
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
92
+ end
93
+
94
+ it "should take --environment command line option as custom environment" do
95
+ ARGV[0] = '--environment'
96
+ ARGV[1] = 'production'
97
+ runner = mock("runner", :null_object => true)
98
+ JettyRails::Runner.should_receive(:new) do |config|
99
+ config.should have_key(:environment)
100
+ config[:environment].should eql('production')
101
+ runner
102
+ end
103
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
104
+ end
105
+
106
+ it "should take -e command line option as custom environment" do
107
+ ARGV[0] = '-e'
108
+ ARGV[1] = 'production'
109
+ runner = mock("runner", :null_object => true)
110
+ JettyRails::Runner.should_receive(:new) do |config|
111
+ config.should have_key(:environment)
112
+ config[:environment].should eql('production')
113
+ runner
114
+ end
115
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
116
+ end
117
+
118
+ it "should take --port command line option as custom server port" do
119
+ ARGV[0] = '--port'
120
+ ARGV[1] = '80'
121
+ runner = mock("runner", :null_object => true)
122
+ JettyRails::Runner.should_receive(:new) do |config|
123
+ config.should have_key(:port)
124
+ config[:port].should eql(80)
125
+ runner
126
+ end
127
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
128
+ end
129
+
130
+ it "should take -p command line option as custom server port" do
131
+ ARGV[0] = '-p'
132
+ ARGV[1] = '80'
133
+ runner = mock("runner", :null_object => true)
134
+ JettyRails::Runner.should_receive(:new) do |config|
135
+ config.should have_key(:port)
136
+ config[:port].should eql(80)
137
+ runner
138
+ end
139
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
140
+ end
141
+
142
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- describe JettyRails::Runner, "with no extra configuration" do
3
+ describe JettyRails::Runner, "with no extra configuration (rails adapter)" do
4
4
  it "should require basedir to be run" do
5
5
  lambda { JettyRails::Runner.new }.should raise_error
6
6
  end
@@ -113,3 +113,34 @@ describe JettyRails::Runner, "with custom configuration" do
113
113
  context_handlers.size.should eql(2) # one for static, one for dynamic
114
114
  end
115
115
  end
116
+
117
+ describe JettyRails::Runner, "with merb adapter" do
118
+
119
+ it "should set merb root" do
120
+ runner = JettyRails::Runner.new :adapter => :merb, :base => Dir.pwd
121
+ runner.app_context.init_params['merb.root'].should eql('/')
122
+ end
123
+
124
+ it "should set public root" do
125
+ runner = JettyRails::Runner.new :adapter => :merb, :base => Dir.pwd
126
+ runner.app_context.init_params['public.root'].should eql('/public')
127
+ end
128
+
129
+ it "should set gem path" do
130
+ runner = JettyRails::Runner.new :adapter => :merb, :base => Dir.pwd
131
+ runner.app_context.init_params['gem.path'].should eql('tmp/war/WEB-INF/gems')
132
+ end
133
+
134
+ it "should set merb environment to development" do
135
+ runner = JettyRails::Runner.new :adapter => :merb, :base => Dir.pwd
136
+ runner.app_context.init_params['merb.environment'].should eql('development')
137
+ end
138
+
139
+ it "should install MerbServletContextListener" do
140
+ runner = JettyRails::Runner.new :adapter => :merb, :base => Dir.pwd
141
+ listeners = runner.app_context.event_listeners
142
+ listeners.size.should eql(1)
143
+ listeners[0].should be_kind_of(JettyRails::Rack::MerbServletContextListener)
144
+ end
145
+ end
146
+
@@ -2,6 +2,17 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe "binary executable with no command line arguments" do
4
4
 
5
+ it "should set adapter to rails" do
6
+ runner = mock("runner", :null_object => true)
7
+ current_dir = Dir.pwd
8
+ JettyRails::Runner.should_receive(:new) do |config|
9
+ config.should have_key(:adapter)
10
+ config[:adapter].should eql(:rails)
11
+ runner
12
+ end
13
+ load File.dirname(__FILE__) + '/../bin/jetty_rails'
14
+ end
15
+
5
16
  it "should provide the current execution dir as basedir" do
6
17
  runner = mock("runner", :null_object => true)
7
18
  current_dir = Dir.pwd
@@ -31,10 +42,11 @@ describe "binary executable with no command line arguments" do
31
42
  load File.dirname(__FILE__) + '/../bin/jetty_rails'
32
43
  end
33
44
 
34
- it "should not set the port by default" do
45
+ it "should set the port to 3000 by default" do
35
46
  runner = mock("runner", :null_object => true)
36
47
  JettyRails::Runner.should_receive(:new) do |config|
37
- config.should_not have_key(:port)
48
+ config.should have_key(:port)
49
+ config[:port].should eql(3000)
38
50
  runner
39
51
  end
40
52
  load File.dirname(__FILE__) + '/../bin/jetty_rails'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jetty-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.3"
4
+ version: "0.4"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Kung
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-10 00:00:00 -03:00
12
+ date: 2008-05-22 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -25,6 +25,7 @@ description: jetty server for rails applications
25
25
  email:
26
26
  - fabio.kung@gmail.com
27
27
  executables:
28
+ - jetty_merb
28
29
  - jetty_rails
29
30
  extensions: []
30
31
 
@@ -41,6 +42,7 @@ files:
41
42
  - PostInstall.txt
42
43
  - README.txt
43
44
  - Rakefile
45
+ - bin/jetty_merb
44
46
  - bin/jetty_rails
45
47
  - config/hoe.rb
46
48
  - config/requirements.rb
@@ -48,6 +50,8 @@ files:
48
50
  - lib/jetty-plus-6.1.9.jar
49
51
  - lib/jetty-util-6.1.9.jar
50
52
  - lib/jetty_rails.rb
53
+ - lib/jetty_rails/adapters/merb_adapter.rb
54
+ - lib/jetty_rails/adapters/rails_adapter.rb
51
55
  - lib/jetty_rails/handler/delegate_on_errors_handler.rb
52
56
  - lib/jetty_rails/jars.rb
53
57
  - lib/jetty_rails/runner.rb
@@ -59,6 +63,7 @@ files:
59
63
  - script/generate
60
64
  - script/txt2html
61
65
  - setup.rb
66
+ - spec/jetty_merb_spec.rb
62
67
  - spec/jetty_rails/handler/delegate_on_errors_handler_spec.rb
63
68
  - spec/jetty_rails/runner_spec.rb
64
69
  - spec/jetty_rails_spec.rb
@@ -99,6 +104,7 @@ signing_key:
99
104
  specification_version: 2
100
105
  summary: jetty server for rails applications
101
106
  test_files:
107
+ - spec/jetty_merb_spec.rb
102
108
  - spec/jetty_rails/handler/delegate_on_errors_handler_spec.rb
103
109
  - spec/jetty_rails/runner_spec.rb
104
110
  - spec/jetty_rails_spec.rb