Title: [577] trunk/rails-integration/plugins/goldspike-snapshot/lib: Running an embedded Jetty will now use RAILS_ENV (with a default of 'development') as the rails environment.
- Revision
- 577
- Author
- tantalon
- Date
- 2007-05-11 20:06:17 -0400 (Fri, 11 May 2007)
Log Message
Running an embedded Jetty will now use RAILS_ENV (with a default of 'development') as the rails environment.
Modified Paths
Diff
Modified: trunk/rails-integration/plugins/goldspike-snapshot/lib/run.rb (576 => 577)
--- trunk/rails-integration/plugins/goldspike-snapshot/lib/run.rb 2007-05-11 20:59:25 UTC (rev 576)
+++ trunk/rails-integration/plugins/goldspike-snapshot/lib/run.rb 2007-05-12 00:06:17 UTC (rev 577)
@@ -8,6 +8,7 @@
attr_accessor :jetty_main
attr_accessor :jetty_tmp
attr_accessor :jetty_config
+ attr_accessor :war_override
attr_accessor :classpath
def initialize(config = Configuration.instance)
@@ -15,6 +16,7 @@
@jetty_main = 'org.mortbay.start.Main'
@jetty_tmp = File.join('tmp', 'jetty')
@jetty_config = File.join(jetty_tmp, 'jetty.xml')
+ @war_override = File.join(jetty_tmp, 'war-override.xml')
end
def run_standalone
@@ -25,6 +27,7 @@
def run
add_jetty_libraries
add_jetty_config
+ add_war_override
classpath_string = classpath.join(config.os_path_separator)
java_opts = config.jetty_java_opts.dup
java_opts << ' -Xmx128m' unless java_opts =~ /-Xmx/
@@ -34,6 +37,29 @@
system(cmd)
end
+ def add_war_override
+ # always create a new override file, regardless of whether one exists
+ File.open(war_override, 'w') { |out| out << create_war_override }
+ end
+
+ def create_war_override
+ require 'erb'
+ template = <<END_OF_WEB_INF_OVERRIDE
+<web-app>
+
+<context-param>
+ <param-name>rails.env</param-name>
+ <param-value><%= config.rails_env_embedded %></param-value>
+</context-param>
+
+</web-app>
+END_OF_WEB_INF_OVERRIDE
+
+ erb = ERB.new(template)
+ erb.result(binding)
+
+ end
+
def add_jetty_libraries
# Get the Jetty libraries
@classpath = []
@@ -97,6 +123,7 @@
<Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
</Array>
</Set>
+ <Set name="overrideDescriptor"><%= war_override %></Set>
</New>
</Item>
<Item>
Modified: trunk/rails-integration/plugins/goldspike-snapshot/lib/war_config.rb (576 => 577)
--- trunk/rails-integration/plugins/goldspike-snapshot/lib/war_config.rb 2007-05-11 20:59:25 UTC (rev 576)
+++ trunk/rails-integration/plugins/goldspike-snapshot/lib/war_config.rb 2007-05-12 00:06:17 UTC (rev 577)
@@ -38,6 +38,8 @@
attr_accessor :standalone
# rails environment?
attr_accessor :rails_env
+ # rails environment to use when running with an embedded server?
+ attr_accessor :rails_env_embedded
# java libraries to include in the package
attr_accessor :java_libraries
@@ -65,6 +67,7 @@
@add_gem_dependencies = true
@servlet = 'org.jruby.webapp.RailsServlet'
@rails_env = 'production'
+ @rails_env_embedded = ENV['RAILS_ENV'] || 'development'
@datasource_jndi = false
home = ENV['HOME'] || ENV['USERPROFILE']
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel