jetty-rails 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ == 0.0.1 2008-04-24
2
+
3
+ * Initial release
4
+
5
+ * Running default rails applications inside Jetty
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Fabio Kung
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.txt
6
+ Rakefile
7
+ bin/jetty_rails
8
+ config/hoe.rb
9
+ config/requirements.rb
10
+ lib/jetty-6.1.9.jar
11
+ lib/jetty-plus-6.1.9.jar
12
+ lib/jetty-util-6.1.9.jar
13
+ lib/jetty_rails.rb
14
+ lib/jetty_rails/jars.rb
15
+ lib/jetty_rails/runner.rb
16
+ lib/jetty_rails/version.rb
17
+ lib/jruby-rack-1.0-SNAPSHOT.jar
18
+ lib/servlet-api-2.5-6.1.9.jar
19
+ script/console
20
+ script/destroy
21
+ script/generate
22
+ script/txt2html
23
+ setup.rb
24
+ spec/jetty_rails/runner_spec.rb
25
+ spec/jetty_rails_spec.rb
26
+ spec/spec.opts
27
+ spec/spec_helper.rb
28
+ tasks/deployment.rake
29
+ tasks/environment.rake
30
+ tasks/rspec.rake
31
+ tasks/website.rake
32
+ website/index.html
33
+ website/index.txt
34
+ website/javascripts/rounded_corners_lite.inc.js
35
+ website/stylesheets/screen.css
36
+ website/template.html.erb
@@ -0,0 +1,2 @@
1
+
2
+ For more information on jetty-rails, see http://jetty-rails.rubyforge.org
@@ -0,0 +1,57 @@
1
+ = jetty-rails
2
+
3
+ jetty-rails.rubyforge.net
4
+
5
+ == DESCRIPTION:
6
+
7
+ jetty_rails aims to run any Warbler based jruby on rails applications with Jetty Container, loading configuration from Warbler.
8
+
9
+ This project is useful for people developing jruby on rails apps that can not use mongrel for development. Rails applications integrated with servlet based applications in the same context would be a reasonable reason.
10
+
11
+ The project has born from my own needs. I needed to run JForum (http://jforum.net) on the same context of my jruby on rails application. I wanted to integrate HttpSessions (avoiding single sign on) and use ServletContext in-memory cache store.
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ * FIX (list of features or problems)
16
+
17
+ == SYNOPSIS:
18
+
19
+ * FIX (code sample of usage)
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * FIX (list of requirements)
24
+
25
+ * To generate coverage report with jruby (>= 1.1) follow
26
+ http://www.ruby-forum.com/topic/146252 and:
27
+
28
+ jruby -S rake rcov
29
+
30
+ == INSTALL:
31
+
32
+ * FIX (sudo gem install, anything else)
33
+
34
+ == LICENSE:
35
+
36
+ (The MIT License)
37
+
38
+ Copyright (c) 2008 FIX
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining
41
+ a copy of this software and associated documentation files (the
42
+ 'Software'), to deal in the Software without restriction, including
43
+ without limitation the rights to use, copy, modify, merge, publish,
44
+ distribute, sublicense, and/or sell copies of the Software, and to
45
+ permit persons to whom the Software is furnished to do so, subject to
46
+ the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be
49
+ included in all copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
52
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
53
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
54
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
55
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
56
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
57
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env jruby
2
+ require "java"
3
+ require "jetty_rails"
4
+
5
+ def print_usage
6
+ puts 'jruby -S jetty_rails <basedir> <context-path> <environment>'
7
+ end
8
+
9
+ if ARGV[0] == '--help'
10
+ print_usage
11
+ else
12
+ config = {}
13
+ config[:base] = ARGV[0] || Dir.pwd
14
+ config[:context_path] = ARGV[1] unless ARGV[1].nil?
15
+ config[:environment] = ARGV[2] unless ARGV[2].nil?
16
+
17
+ runner = JettyRails::Runner.new(config)
18
+ runner.start
19
+ end
@@ -0,0 +1,73 @@
1
+ require 'jetty_rails/version'
2
+
3
+ AUTHOR = 'Fabio Kung' # can also be an array of Authors
4
+ EMAIL = "fabio.kung@gmail.com"
5
+ DESCRIPTION = "description of gem"
6
+ GEM_NAME = 'jetty-rails' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'jetty-rails' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ ['activesupport', '>= 1.3.1']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "unknown"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = JettyRails::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'jetty-rails documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["spec/**/*_spec.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ # p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
Binary file
Binary file
Binary file
@@ -0,0 +1,12 @@
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
+ require "activesupport"
7
+ require "jetty_rails/jars"
8
+ require "jetty_rails/runner"
9
+
10
+ module JettyRails
11
+ JETTY_RAILS_HOME = File.dirname(__FILE__) + "/.." unless defined?(JETTY_RAILS_HOME)
12
+ end
@@ -0,0 +1,19 @@
1
+ require "jetty-6.1.9"
2
+ require "servlet-api-2.5-6.1.9"
3
+ require "jetty-util-6.1.9"
4
+ require "jetty-plus-6.1.9"
5
+
6
+ module Jetty
7
+ include_package "org.mortbay.jetty"
8
+ include_package "org.mortbay.jetty.servlet"
9
+ module Handler
10
+ include_package "org.mortbay.jetty.handler"
11
+ include_package "org.mortbay.jetty.webapp"
12
+ end
13
+ end
14
+
15
+ require "jruby-rack-1.0-SNAPSHOT"
16
+ module Rack
17
+ include_package "org.jruby.rack"
18
+ include_package "org.jruby.rack.rails"
19
+ end
@@ -0,0 +1,60 @@
1
+ require "jruby"
2
+
3
+ module JettyRails
4
+
5
+ class Runner
6
+ attr_reader :config
7
+ attr_reader :server
8
+ attr_reader :app_context
9
+
10
+ @@defaults = {
11
+ :environment => 'development',
12
+ :context_path => '/'
13
+ }
14
+
15
+ def initialize(config = {})
16
+ @config = config.symbolize_keys!.reverse_merge!(@@defaults)
17
+ raise 'Basedir to be run must be provided' unless config[:base]
18
+
19
+ @server = Jetty::Server.new 8080
20
+
21
+ add_public_dir_to server
22
+ install_rack_on server
23
+ end
24
+
25
+ def start
26
+ @server.start
27
+ @server.join
28
+ end
29
+
30
+ private
31
+ def rack_filter
32
+ Jetty::FilterHolder.new(Rack::RackFilter.new)
33
+ end
34
+
35
+ def add_public_dir_to(server)
36
+ @resources = Jetty::Handler::ResourceHandler.new
37
+ @resources.resource_base = config[:base] + '/public'
38
+ server.add_handler(@resources)
39
+ end
40
+
41
+ def install_rack_on(server)
42
+ #TODO root context should be configurable
43
+ @app_context = Jetty::Handler::WebAppContext.new("/", config[:context_path])
44
+ @app_context.class_loader = JRuby.runtime.jruby_class_loader
45
+ @app_context.resource_base = config[:base]
46
+
47
+ # refer to goldspike and jruby-rack documentation
48
+ @app_context.init_params = {
49
+ 'rails.root' => '/',
50
+ 'public.root' => '/public',
51
+ 'rails.env' => config[:environment],
52
+ 'gem.path' => 'tmp/war/WEB-INF/gems'
53
+ }
54
+
55
+ @app_context.add_event_listener(Rack::RailsServletContextListener.new)
56
+ @app_context.add_filter(rack_filter, "/*", Jetty::Context::DEFAULT)
57
+ server.add_handler(@app_context)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,8 @@
1
+ module JettyRails #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+
6
+ STRING = [MAJOR, MINOR].join('.')
7
+ end
8
+ 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,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ GEM_NAME = 'jetty-rails' # what ppl will type to install your gem
4
+ RUBYFORGE_PROJECT = 'jetty-rails'
5
+
6
+ require 'rubygems'
7
+ begin
8
+ require 'newgem'
9
+ require 'rubyforge'
10
+ rescue LoadError
11
+ puts "\n\nGenerating the website requires the newgem RubyGem"
12
+ puts "Install: gem install newgem\n\n"
13
+ exit(1)
14
+ end
15
+ require 'redcloth'
16
+ require 'syntax/convertors/html'
17
+ require 'erb'
18
+ require File.dirname(__FILE__) + "/../lib/jetty_rails/version.rb"
19
+
20
+ version = JettyRails::VERSION::STRING
21
+ download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
22
+
23
+ def rubyforge_project_id
24
+ RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
25
+ end
26
+
27
+ class Fixnum
28
+ def ordinal
29
+ # teens
30
+ return 'th' if (10..19).include?(self % 100)
31
+ # others
32
+ case self % 10
33
+ when 1: return 'st'
34
+ when 2: return 'nd'
35
+ when 3: return 'rd'
36
+ else return 'th'
37
+ end
38
+ end
39
+ end
40
+
41
+ class Time
42
+ def pretty
43
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
44
+ end
45
+ end
46
+
47
+ def convert_syntax(syntax, source)
48
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
49
+ end
50
+
51
+ if ARGV.length >= 1
52
+ src, template = ARGV
53
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
54
+ else
55
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
56
+ exit!
57
+ end
58
+
59
+ template = ERB.new(File.open(template).read)
60
+
61
+ title = nil
62
+ body = nil
63
+ File.open(src) do |fsrc|
64
+ title_text = fsrc.readline
65
+ body_text_template = fsrc.read
66
+ body_text = ERB.new(body_text_template).result(binding)
67
+ syntax_items = []
68
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
69
+ ident = syntax_items.length
70
+ element, syntax, source = $1, $2, $3
71
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
72
+ "syntax-temp-#{ident}"
73
+ }
74
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
75
+ body = RedCloth.new(body_text).to_html
76
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
77
+ end
78
+ stat = File.stat(src)
79
+ created = stat.ctime
80
+ modified = stat.mtime
81
+
82
+ $stdout << template.result(binding)