Title: [666] trunk/rails-integration: Add the ability to add any Java webapp configuration files generated from templates.
Revision
666
Author
tantalon
Date
2007-07-16 17:50:24 -0400 (Mon, 16 Jul 2007)

Log Message

Add the ability to add any Java webapp configuration files generated from templates.
Patch by Bryan Liles.

Modified to look for the templates from WEB-INF, to keep things consistent.
Modified to use the latest web.xml, which is Servlet API 2.3 compatible.

Modified Paths

Added Paths

Diff

Added: trunk/rails-integration/plugins/goldspike-snapshot/generators/goldspike/goldspike_generator.rb (0 => 666)


--- trunk/rails-integration/plugins/goldspike-snapshot/generators/goldspike/goldspike_generator.rb	                        (rev 0)
+++ trunk/rails-integration/plugins/goldspike-snapshot/generators/goldspike/goldspike_generator.rb	2007-07-16 21:50:24 UTC (rev 666)
@@ -0,0 +1,21 @@
+class GoldspikeGenerator < Rails::Generator::Base
+  
+  def initialize(runtime_args, runtime_options = {})
+    super
+  end
+    
+  def manifest
+    record do |m|
+      m.directory 'config'
+      m.directory File.join('config', 'war_files')
+      m.template 'war.rb', File.join('config', 'war.rb')
+      m.template 'web.xml.erb', File.join('WEB-INF', 'web.xml.erb')
+    end
+  end
+  
+  protected
+  
+  def banner
+    "Usage: #{$0} goldspike"
+  end  
+end
\ No newline at end of file

Added: trunk/rails-integration/plugins/goldspike-snapshot/generators/goldspike/templates/war.rb (0 => 666)


--- trunk/rails-integration/plugins/goldspike-snapshot/generators/goldspike/templates/war.rb	                        (rev 0)
+++ trunk/rails-integration/plugins/goldspike-snapshot/generators/goldspike/templates/war.rb	2007-07-16 21:50:24 UTC (rev 666)
@@ -0,0 +1,8 @@
+# Goldspike configuration
+
+# Set the version of JRuby and GoldSpike to use:
+#maven_library 'org.jruby', 'jruby-complete', '1.0'
+#maven_library 'org.jruby.extras', 'goldspike', '1.3-SNAPSHOT'
+
+# Add a Java library from the Maven repository:
+#maven_library 'mysql', 'mysql-connector-java', '5.0.4'

Added: trunk/rails-integration/plugins/goldspike-snapshot/generators/goldspike/templates/web.xml.erb (0 => 666)


--- trunk/rails-integration/plugins/goldspike-snapshot/generators/goldspike/templates/web.xml.erb	                        (rev 0)
+++ trunk/rails-integration/plugins/goldspike-snapshot/generators/goldspike/templates/web.xml.erb	2007-07-16 21:50:24 UTC (rev 666)
@@ -0,0 +1,57 @@
+<!DOCTYPE web-app PUBLIC
+  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+  "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+
+	<context-param>
+		<param-name>jruby.standalone</param-name>
+		<param-value><%%= config.standalone %></param-value>
+	</context-param>
+
+	<%% if !config.standalone %>
+	<!-- jruby.home can be set either here, or as the system property jruby.home -->
+	<context-param>
+		<param-name>jruby.home</param-name>
+		<param-value><%%= config.jruby_home || '/usr/local/jruby' %></param-value>
+	</context-param>
+	<%% end %>
+
+	<context-param>
+		<param-name>rails.env</param-name>
+		<param-value><%%= config.rails_env %></param-value>
+	</context-param>
+
+	<context-param>
+		<param-name>files.default</param-name>
+		<param-value>rails</param-value>
+		<description>The files servlet should forward to the rails servlet if no file could be found</description>
+	</context-param>
+
+	<listener>
+		<listener-class>org.jruby.webapp.RailsContextListener</listener-class>
+	</listener>
+
+	<servlet>
+		<servlet-name>rails</servlet-name>
+		<servlet-class><%%= config.servlet %></servlet-class>
+	</servlet>
+	<servlet>
+		<servlet-name>files</servlet-name>
+		<servlet-class>org.jruby.webapp.FileServlet</servlet-class>
+	</servlet>
+
+	<!-- Allow all requests to go to the files servlet first -->
+	<servlet-mapping>
+		<servlet-name>files</servlet-name>
+		<url-pattern>/</url-pattern>
+	</servlet-mapping>
+
+	<%% if config.datasource_jndi %>
+	<resource-ref>
+		<res-ref-name><%%= config.datasource_jndi_name %></res-ref-name>
+		<res-type>javax.sql.DataSource</res-type>
+		<res-auth>Container</res-auth>
+	</resource-ref>
+	<%% end %>
+
+</web-app>
\ No newline at end of file

Modified: trunk/rails-integration/plugins/goldspike-snapshot/lib/create_war.rb (665 => 666)


--- trunk/rails-integration/plugins/goldspike-snapshot/lib/create_war.rb	2007-07-06 11:56:03 UTC (rev 665)
+++ trunk/rails-integration/plugins/goldspike-snapshot/lib/create_war.rb	2007-07-16 21:50:24 UTC (rev 666)
@@ -52,7 +52,7 @@
       if config.standalone
         add_ruby_libraries
       end
-      add_webxml
+      add_configuration_files
     end
 
     private
@@ -70,79 +70,25 @@
       @ruby_lib_packer.add_ruby_libraries
     end
 
-    def create_webxml
+    def add_configuration_files
       require 'erb'
-      template = <<END_OF_WEB_INF
-<!DOCTYPE web-app PUBLIC
-  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
-  "http://java.sun.com/dtd/web-app_2_3.dtd">
-<web-app>
-
-<context-param>
-  <param-name>jruby.standalone</param-name>
-  <param-value><%= config.standalone %></param-value>
-</context-param>
-
-<% if !config.standalone %>
-<!-- jruby.home can be set either here, or as the system property jruby.home -->
-<context-param>
-  <param-name>jruby.home</param-name>
-  <param-value><%= config.jruby_home || '/usr/local/jruby' %></param-value>
-</context-param>
-<% end %>
-
-<context-param>
-  <param-name>rails.env</param-name>
-  <param-value><%= config.rails_env %></param-value>
-</context-param>
-
-<context-param>
-  <param-name>files.default</param-name>
-  <param-value>rails</param-value>
-  <description>The files servlet should forward to the rails servlet if no file could be found</description>
-</context-param>
-
-<listener>
-  <listener-class>org.jruby.webapp.RailsContextListener</listener-class>
-</listener>
-
-<servlet>
-  <servlet-name>rails</servlet-name>
-  <servlet-class><%= config.servlet %></servlet-class>
-</servlet>
-<servlet>
-  <servlet-name>files</servlet-name>
-  <servlet-class>org.jruby.webapp.FileServlet</servlet-class>
-</servlet>
-
-<!-- Allow all requests to go to the files servlet first -->
-<servlet-mapping>
-  <servlet-name>files</servlet-name>
-  <url-pattern>/</url-pattern>
-</servlet-mapping>
-
-<% if config.datasource_jndi %>
-<resource-ref>
-  <res-ref-name><%= config.datasource_jndi_name %></res-ref-name>
-  <res-type>javax.sql.DataSource</res-type>
-  <res-auth>Container</res-auth>
-</resource-ref>
-<% end %>
-
-</web-app>
-END_OF_WEB_INF
-
-      erb = ERB.new(template)
-      erb.result(binding)
-    end
-
-    def add_webxml
-      unless File.exists?(File.join('WEB-INF', 'web.xml'))
-        config_webxml = File.join('config', 'web.xml')
-        webxml = File.read(config_webxml) if File.exists?(config_webxml)
-        webxml ||= create_webxml
-        File.makedirs(File.join(config.staging, 'WEB-INF'))
-        File.open(File.join(config.staging, 'WEB-INF', 'web.xml'), 'w') { |out| out << webxml }
+      File.makedirs(File.join(config.staging, 'WEB-INF'))
+      war_file_dir = File.join(config.staging, 'WEB-INF')
+      Dir.foreach(war_file_dir) do |file|        
+        output = case file
+          when /\.\Z/ # ignore dotfiles
+            nil
+          when /\.erb\Z/
+            output_file = file.gsub(/\.erb\Z/, '')
+            template = File.read(File.join(war_file_dir, file))
+            erb = ERB.new(template)
+            erb.result(binding)
+          end
+    
+        unless output.nil? 
+          File.open(File.join(config.staging, 'WEB-INF', output_file), 'w') { |out| out << output}      
+        end
+        
       end
     end
 

Modified: trunk/rails-integration/samples/helloworld-1.2.3/config/war.rb (665 => 666)


--- trunk/rails-integration/samples/helloworld-1.2.3/config/war.rb	2007-07-06 11:56:03 UTC (rev 665)
+++ trunk/rails-integration/samples/helloworld-1.2.3/config/war.rb	2007-07-16 21:50:24 UTC (rev 666)
@@ -1,3 +1,4 @@
 #compile_ruby true
 #keep_source false
+maven_library 'org.jruby', 'jruby-complete', '1.0'
 maven_library 'org.jruby.extras', 'goldspike', '1.3-SNAPSHOT'
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to