Skip to content

Commit

Permalink
support for static (non-erb) config/web.xml and public/WEB-INF
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiokung committed Dec 2, 2008
1 parent ede415a commit 95abc3c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
27 changes: 21 additions & 6 deletions lib/jetty_rails/handler/web_app_handler.rb
Expand Up @@ -8,20 +8,22 @@ def initialize(config)
@config = config

self.class_loader = each_context_has_its_own_classloader
self.resource_base = config[:base]
self.resource_base = "#{config[:base]}/public"
self.descriptor = config[:web_xml]

add_classes_dir_to_classpath(config)
add_lib_dir_jars_to_classpath(config)

@adapter = adapter_for(config[:adapter])
self.init_params = @adapter.init_params

@adapter.event_listeners.each do |listener|
add_event_listener(listener)
end
unless File.exist?(self.descriptor)
@adapter.event_listeners.each do |listener|
add_event_listener(listener)
end

add_filter(rack_filter, "/*", Jetty::Context::DEFAULT)
add_filter(rack_filter, "/*", Jetty::Context::DEFAULT)
end
end

def self.add_adapter(adapter_key, adapter)
Expand All @@ -38,6 +40,13 @@ def self.adapters
def adapters
self.class.adapters
end

alias :get_from_public_otherwise :getResource

def getResource(resource)
return fix_for_base_url if resource == '/'
get_from_public_otherwise resource
end

protected
def rack_filter
Expand All @@ -49,18 +58,24 @@ def adapter_for(kind)
end

private
def fix_for_base_url
Jetty::FileResource.new(java.io.File.new(config[:base]).to_url)
end

def add_lib_dir_jars_to_classpath(config)
lib_dir = "#{config[:base]}/#{config[:lib_dir]}/**/*.jar"
Dir[lib_dir].each do |jar|
url = java.io.File.new(jar).to_url
self.class_loader.add_url(url)
end
end

def add_classes_dir_to_classpath(config)
classes_dir = "#{config[:base]}/#{config[:classes_dir]}"
url = java.io.File.new(classes_dir).to_url
self.class_loader.add_url(url)
end

def each_context_has_its_own_classloader()
org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
end
Expand Down
1 change: 1 addition & 0 deletions lib/jetty_rails/jars.rb
Expand Up @@ -11,6 +11,7 @@ module Jetty
include_package "org.mortbay.jetty"
include_package "org.mortbay.jetty.servlet"
include_package "org.mortbay.jetty.nio"
include_package "org.mortbay.resource"
module Handler
include_package "org.mortbay.jetty.handler"
include_package "org.mortbay.jetty.webapp"
Expand Down

0 comments on commit 95abc3c

Please sign in to comment.