nolman-jetty-rails 0.9.6-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/History.txt +49 -0
  2. data/Licenses.txt +37 -0
  3. data/Manifest.txt +51 -0
  4. data/PostInstall.txt +2 -0
  5. data/README.rdoc +130 -0
  6. data/Rakefile +27 -0
  7. data/TODO.txt +11 -0
  8. data/bin/jetty_merb +41 -0
  9. data/bin/jetty_rails +41 -0
  10. data/jetty-libs/core-3.1.1.jar +0 -0
  11. data/jetty-libs/jetty-6.1.14.jar +0 -0
  12. data/jetty-libs/jetty-plus-6.1.14.jar +0 -0
  13. data/jetty-libs/jetty-util-6.1.14.jar +0 -0
  14. data/jetty-libs/jsp-2.1.jar +0 -0
  15. data/jetty-libs/jsp-api-2.1.jar +0 -0
  16. data/jetty-libs/servlet-api-2.5-6.1.14.jar +0 -0
  17. data/lib/jetty_rails.rb +26 -0
  18. data/lib/jetty_rails/adapters/abstract_adapter.rb +25 -0
  19. data/lib/jetty_rails/adapters/merb_adapter.rb +34 -0
  20. data/lib/jetty_rails/adapters/rails_adapter.rb +22 -0
  21. data/lib/jetty_rails/adapters/rails_jms_adapter.rb +104 -0
  22. data/lib/jetty_rails/config/command_line_reader.rb +75 -0
  23. data/lib/jetty_rails/config/rdoc_fix.rb +28 -0
  24. data/lib/jetty_rails/handler/delegate_on_errors_handler.rb +29 -0
  25. data/lib/jetty_rails/handler/public_directory_handler.rb +24 -0
  26. data/lib/jetty_rails/handler/web_app_handler.rb +85 -0
  27. data/lib/jetty_rails/jars.rb +36 -0
  28. data/lib/jetty_rails/runner.rb +46 -0
  29. data/lib/jetty_rails/server.rb +79 -0
  30. data/lib/jetty_rails/warbler_reader.rb +13 -0
  31. data/lib/jruby-rack-0.9.7-SNAPSHOT.jar +0 -0
  32. data/script/console +10 -0
  33. data/script/destroy +14 -0
  34. data/script/generate +14 -0
  35. data/script/txt2html +71 -0
  36. data/spec/config.yml +28 -0
  37. data/spec/jetty_merb_spec.rb +195 -0
  38. data/spec/jetty_rails/config_file_spec.rb +68 -0
  39. data/spec/jetty_rails/handler/delegate_on_errors_handler_spec.rb +29 -0
  40. data/spec/jetty_rails/runner_spec.rb +162 -0
  41. data/spec/jetty_rails_sample_1.yml +13 -0
  42. data/spec/jetty_rails_sample_2.yml +28 -0
  43. data/spec/jetty_rails_spec.rb +195 -0
  44. data/spec/spec.opts +2 -0
  45. data/spec/spec_helper.rb +12 -0
  46. data/tasks/jruby.rake +7 -0
  47. data/tasks/rspec.rake +49 -0
  48. data/website/index.txt +194 -0
  49. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  50. data/website/stylesheets/screen.css +159 -0
  51. data/website/template.html.erb +56 -0
  52. metadata +174 -0
@@ -0,0 +1,46 @@
1
+ require "jruby"
2
+
3
+ module JettyRails
4
+
5
+ class Runner
6
+ attr_reader :servers
7
+
8
+ def initialize(config = {})
9
+ @servers = {}
10
+ config.symbolize_keys!
11
+ if config[:servers].nil?
12
+ add_server(config)
13
+ else
14
+ config[:servers].each do |server_config|
15
+ server_config.symbolize_keys!
16
+ server_config.reverse_merge!(config)
17
+ server_config.delete(:servers)
18
+ add_server(server_config)
19
+ end
20
+ end
21
+ end
22
+
23
+ def add_server(config = {})
24
+ server = JettyRails::Server.new(config)
25
+ @servers[server.config[:port]] = server
26
+ end
27
+
28
+ def start
29
+ server_threads = ThreadGroup.new
30
+ @servers.each do |base, server|
31
+ log("Starting server #{base}")
32
+ server_threads.add(Thread.new do
33
+ server.start
34
+ end)
35
+ end
36
+
37
+ server_threads.list.each {|thread| thread.join } unless server_threads.list.empty?
38
+ end
39
+
40
+ private
41
+
42
+ def log(msg)
43
+ $stdout.puts(msg)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,79 @@
1
+ module JettyRails
2
+ class Server
3
+ attr_reader :config
4
+ attr_reader :app_contexts
5
+ attr_reader :server
6
+
7
+ @@defaults = {
8
+ :adapter => :rails,
9
+ :environment => 'development',
10
+ :context_path => '/',
11
+ :lib_dir => 'lib',
12
+ :classes_dir => 'classes',
13
+ :web_xml => 'config/web.xml',
14
+ :port => 8080,
15
+ :jruby_min_runtimes => 1,
16
+ :jruby_max_runtimes => 5,
17
+ :thread_pool_max => 20,
18
+ :thread_pool_min => 1,
19
+ :acceptor_size => 5
20
+ }
21
+
22
+ def initialize(config = {})
23
+ @config = config.symbolize_keys!.reverse_merge!(@@defaults)
24
+
25
+ @server = Jetty::Server.new
26
+ # setup the thread pool for the server
27
+ thread_pool = Jetty::Thread::QueuedThreadPool.new
28
+ thread_pool.set_max_threads(config[:thread_pool_max])
29
+ thread_pool.set_min_threads(config[:thread_pool_min])
30
+ @server.set_thread_pool(thread_pool)
31
+
32
+ connector = Jetty::SelectChannelConnector.new
33
+ connector.set_acceptors(config[:acceptor_size])
34
+ connector.port = config[:port]
35
+ if config[:stats_on]
36
+ connector.stats_on = true
37
+ end
38
+ @server.add_connector(connector)
39
+
40
+ if config[:apps].nil?
41
+ add_app(config)
42
+ else
43
+ config[:apps].each do |app_config|
44
+ app_config.reverse_merge!(config)
45
+ app_config.delete(:apps)
46
+ add_app(app_config)
47
+ end
48
+ end
49
+ end
50
+
51
+ def add_app(config)
52
+ raise 'Base dir to be run must be provided' unless config[:base]
53
+ config[:context_path].extend ContextPath
54
+
55
+ @server.add_handler(JettyRails::Handler::PublicDirectoryHandler.new(config))
56
+ web_app_handler = JettyRails::Handler::WebAppHandler.new(config)
57
+ (@app_contexts ||= []) << web_app_handler
58
+ @server.add_handler(web_app_handler)
59
+ end
60
+
61
+ def start
62
+ @server.start
63
+ @server.join
64
+ end
65
+
66
+
67
+ private
68
+ def read_warble_config
69
+ require 'warbler'
70
+ WarblerReader.new(config)
71
+ end
72
+
73
+ module ContextPath
74
+ def root?
75
+ self == '/'
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,13 @@
1
+ class WarblerReader
2
+
3
+ def initialize(config)
4
+ # TODO ignore jruby and jruby-rack
5
+ warbler_config = load("#{config[:base]}/config/warble.rb")
6
+ warbler_config.java_libs.each do |jar|
7
+ require jar
8
+ end
9
+ # TODO require custom classes
10
+ end
11
+
12
+
13
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/jetty-rails.rb'}"
9
+ puts "Loading jetty-rails gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.dirname(__FILE__) + "/../Rakefile"
4
+ require 'rubyforge'
5
+ require 'redcloth'
6
+ require 'syntax/convertors/html'
7
+ require 'erb'
8
+
9
+ download = "http://rubyforge.org/projects/#{$hoe.rubyforge_name}"
10
+ version = $hoe.version
11
+
12
+ def rubyforge_project_id
13
+ RubyForge.new.configure.autoconfig["group_ids"][$hoe.rubyforge_name]
14
+ end
15
+
16
+ class Fixnum
17
+ def ordinal
18
+ # teens
19
+ return 'th' if (10..19).include?(self % 100)
20
+ # others
21
+ case self % 10
22
+ when 1: return 'st'
23
+ when 2: return 'nd'
24
+ when 3: return 'rd'
25
+ else return 'th'
26
+ end
27
+ end
28
+ end
29
+
30
+ class Time
31
+ def pretty
32
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
33
+ end
34
+ end
35
+
36
+ def convert_syntax(syntax, source)
37
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
38
+ end
39
+
40
+ if ARGV.length >= 1
41
+ src, template = ARGV
42
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
43
+ else
44
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
45
+ exit!
46
+ end
47
+
48
+ template = ERB.new(File.open(template).read)
49
+
50
+ title = nil
51
+ body = nil
52
+ File.open(src) do |fsrc|
53
+ title_text = fsrc.readline
54
+ body_text_template = fsrc.read
55
+ body_text = ERB.new(body_text_template).result(binding)
56
+ syntax_items = []
57
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
58
+ ident = syntax_items.length
59
+ element, syntax, source = $1, $2, $3
60
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
61
+ "syntax-temp-#{ident}"
62
+ }
63
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
64
+ body = RedCloth.new(body_text).to_html
65
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
66
+ end
67
+ stat = File.stat(src)
68
+ created = stat.ctime
69
+ modified = stat.mtime
70
+
71
+ $stdout << template.result(binding)
@@ -0,0 +1,28 @@
1
+ ---
2
+ :servers:
3
+ - :context_path: /testA
4
+ :base: /
5
+ :adapter: :rails
6
+ :environment: development
7
+ :port: 3000
8
+ :lib_dir: lib/**/*.jar
9
+ :jruby_min_runtimes: 2
10
+ - :context_path: /testB
11
+ :base: /testing
12
+ :adapter: :merb
13
+ :port: 4000
14
+ - :port: 8080
15
+ :apps:
16
+ - :context_path: /testC
17
+ :base: /testing
18
+ :adapter: :merb
19
+ :environment: test
20
+ - :context_path: /testD
21
+ :base: /something
22
+ :adapter: :rails
23
+ :environment: production
24
+ :jruby_min_runtimes: 1
25
+ :jruby_max_runtimes: 2
26
+ :thread_pool_max: 40
27
+ :thread_pool_min: 1
28
+ :acceptor_size: 20
@@ -0,0 +1,195 @@
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 == :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 == 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 == 4000
50
+ runner
51
+ end
52
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
53
+ end
54
+
55
+ it "should not set classes dir by default" do
56
+ runner = mock("runner", :null_object => true)
57
+ JettyRails::Runner.should_receive(:new) do |config|
58
+ config.should_not have_key(:classes_dir)
59
+ runner
60
+ end
61
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
62
+ end
63
+
64
+ it "should not set lib dir by default" do
65
+ runner = mock("runner", :null_object => true)
66
+ JettyRails::Runner.should_receive(:new) do |config|
67
+ config.should_not have_key(:lib_dir)
68
+ runner
69
+ end
70
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
71
+ end
72
+ end
73
+
74
+ describe "binary executable with command line arguments" do
75
+
76
+ it "should take the first command line argument as basedir" do
77
+ ARGV[0] = '/any/app/dir'
78
+ runner = mock("runner", :null_object => true)
79
+ JettyRails::Runner.should_receive(:new) do |config|
80
+ config.should have_key(:base)
81
+ config[:base].should == '/any/app/dir'
82
+ runner
83
+ end
84
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
85
+ end
86
+
87
+ it "should take --context-path command line option as context path" do
88
+ ARGV[0] = '--context-path'
89
+ ARGV[1] = '/myapp'
90
+ runner = mock("runner", :null_object => true)
91
+ JettyRails::Runner.should_receive(:new) do |config|
92
+ config.should have_key(:context_path)
93
+ config[:context_path].should == '/myapp'
94
+ runner
95
+ end
96
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
97
+ end
98
+
99
+ it "should take -u command line option as context path" do
100
+ ARGV[0] = '-u'
101
+ ARGV[1] = '/myapp'
102
+ runner = mock("runner", :null_object => true)
103
+ JettyRails::Runner.should_receive(:new) do |config|
104
+ config.should have_key(:context_path)
105
+ config[:context_path].should == '/myapp'
106
+ runner
107
+ end
108
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
109
+ end
110
+
111
+ it "should take --environment command line option as custom environment" do
112
+ ARGV[0] = '--environment'
113
+ ARGV[1] = 'production'
114
+ runner = mock("runner", :null_object => true)
115
+ JettyRails::Runner.should_receive(:new) do |config|
116
+ config.should have_key(:environment)
117
+ config[:environment].should == 'production'
118
+ runner
119
+ end
120
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
121
+ end
122
+
123
+ it "should take -e command line option as custom environment" do
124
+ ARGV[0] = '-e'
125
+ ARGV[1] = 'production'
126
+ runner = mock("runner", :null_object => true)
127
+ JettyRails::Runner.should_receive(:new) do |config|
128
+ config.should have_key(:environment)
129
+ config[:environment].should == 'production'
130
+ runner
131
+ end
132
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
133
+ end
134
+
135
+ it "should take --port command line option as custom server port" do
136
+ ARGV[0] = '--port'
137
+ ARGV[1] = '80'
138
+ runner = mock("runner", :null_object => true)
139
+ JettyRails::Runner.should_receive(:new) do |config|
140
+ config.should have_key(:port)
141
+ config[:port].should == 80
142
+ runner
143
+ end
144
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
145
+ end
146
+
147
+ it "should take -p command line option as custom server port" do
148
+ ARGV[0] = '-p'
149
+ ARGV[1] = '80'
150
+ runner = mock("runner", :null_object => true)
151
+ JettyRails::Runner.should_receive(:new) do |config|
152
+ config.should have_key(:port)
153
+ config[:port].should == 80
154
+ runner
155
+ end
156
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
157
+ end
158
+
159
+ it "should take --classes command line option as custom classes dir" do
160
+ ARGV[0] = '--classes'
161
+ ARGV[1] = 'build/java/classes'
162
+ runner = mock("runner", :null_object => true)
163
+ JettyRails::Runner.should_receive(:new) do |config|
164
+ config.should have_key(:classes_dir)
165
+ config[:classes_dir].should == 'build/java/classes'
166
+ runner
167
+ end
168
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
169
+ end
170
+
171
+ it "should take --lib command line option as custom jars dir" do
172
+ ARGV[0] = '--lib'
173
+ ARGV[1] = 'java/jars'
174
+ runner = mock("runner", :null_object => true)
175
+ JettyRails::Runner.should_receive(:new) do |config|
176
+ config.should have_key(:lib_dir)
177
+ config[:lib_dir].should == 'java/jars'
178
+ runner
179
+ end
180
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
181
+ end
182
+
183
+ it "should take --jars command line option as custom jars dir" do
184
+ ARGV[0] = '--jars'
185
+ ARGV[1] = 'java/jars'
186
+ runner = mock("runner", :null_object => true)
187
+ JettyRails::Runner.should_receive(:new) do |config|
188
+ config.should have_key(:lib_dir)
189
+ config[:lib_dir].should == 'java/jars'
190
+ runner
191
+ end
192
+ load File.dirname(__FILE__) + '/../bin/jetty_merb'
193
+ end
194
+
195
+ end