- Revision
- 128
- Author
- mward
- Date
- 2007-06-01 09:09:52 -0500 (Fri, 01 Jun 2007)
Log Message
rolledback last checkin ... not what we want
Modified Paths
- trunk/core/src/main/java/org/codehaus/waffle/context/pico/RubyScriptLoader.java
- trunk/core/src/main/java/org/codehaus/waffle/monitor/ConsoleMonitor.java
- trunk/core/src/main/ruby/waffle.rb
- trunk/core/src/test/java/org/codehaus/waffle/context/pico/RubyScriptLoaderTest.java
- trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/RubyScriptReloader.java
- trunk/examples/jruby-example/src/main/ruby/ruby/foo_bar.rb
- trunk/examples/jruby-example/src/main/webapp/WEB-INF/web.xml
Diff
Modified: trunk/core/src/main/java/org/codehaus/waffle/context/pico/RubyScriptLoader.java (127 => 128)
--- trunk/core/src/main/java/org/codehaus/waffle/context/pico/RubyScriptLoader.java 2007-06-01 12:52:25 UTC (rev 127) +++ trunk/core/src/main/java/org/codehaus/waffle/context/pico/RubyScriptLoader.java 2007-06-01 14:09:52 UTC (rev 128) @@ -1,27 +1,40 @@ package org.codehaus.waffle.context.pico; import org.jruby.Ruby; -import org.jruby.RubyModule; import org.jruby.javasupport.JavaEmbedUtils; +import org.jruby.runtime.builtin.IRubyObject; import org.picocontainer.Startable; import javax.servlet.ServletContext; public class RubyScriptLoader implements Startable { + public static final String RUBY_SCRIPT_PATH_KEY = "org.codehaus.waffle.ruby.path"; public static final String DEFAULT_RUBY_SCRIPT_PATH = "/WEB-INF/classes/ruby/"; private final ServletContext servletContext; private final Ruby runtime; + private final String rubyScriptPath; public RubyScriptLoader(ServletContext servletContext, Ruby runtime) { this.servletContext = servletContext; this.runtime = runtime; + + String path = servletContext.getInitParameter(RUBY_SCRIPT_PATH_KEY); + + if(path == null) { + rubyScriptPath = DEFAULT_RUBY_SCRIPT_PATH; + } else { + rubyScriptPath = path; + } } public void start() { - RubyModule rubyModule = runtime.getClassFromPath("Waffle::ScriptLoader"); - rubyModule.callMethod(runtime.getCurrentContext(), "servlet_context=", JavaEmbedUtils.javaToRuby(runtime, servletContext)); - rubyModule.callMethod(runtime.getCurrentContext(), "load_all"); + runtime.getClassFromPath("Waffle::ScriptLoader") + .callMethod(runtime.getCurrentContext(), "load_all", + new IRubyObject[]{ + JavaEmbedUtils.javaToRuby(runtime, rubyScriptPath), + JavaEmbedUtils.javaToRuby(runtime, servletContext) + }); } public void stop() {
Modified: trunk/core/src/main/java/org/codehaus/waffle/monitor/ConsoleMonitor.java (127 => 128)
--- trunk/core/src/main/java/org/codehaus/waffle/monitor/ConsoleMonitor.java 2007-06-01 12:52:25 UTC (rev 127) +++ trunk/core/src/main/java/org/codehaus/waffle/monitor/ConsoleMonitor.java 2007-06-01 14:09:52 UTC (rev 128) @@ -10,10 +10,10 @@ *****************************************************************************/ package org.codehaus.waffle.monitor; +import java.util.Set; + import org.codehaus.waffle.action.MethodDefinition; -import java.util.Set; - /** * Implementation of Monitor that writes to console * @@ -44,5 +44,6 @@ public void methodNameResolved(String methodName, String methodKey, Set<String> keys) { write("Method name '"+methodName+"' found for key '"+methodKey+"' among keys "+keys); } - + + }
Modified: trunk/core/src/main/ruby/waffle.rb (127 => 128)
--- trunk/core/src/main/ruby/waffle.rb 2007-06-01 12:52:25 UTC (rev 127) +++ trunk/core/src/main/ruby/waffle.rb 2007-06-01 14:09:52 UTC (rev 128) @@ -4,14 +4,22 @@ # load/require files class ScriptLoader + def ScriptLoader.load_all(prefix, servlet_context) - def ScriptLoader.servlet_context=(servlet_context) - @@_servlet_context = servlet_context + if (prefix.gsub!(/^dir:/, '')) + @@_ruby_script_path = prefix + ScriptLoader.load_from_file_system + else + servlet_context.getResourcePaths(prefix).each do |path| # this would be for production!! + require path.gsub(Regexp.new("^#{prefix}"), 'ruby/') + end + end end - def ScriptLoader.load_all(prefix="/WEB-INF/classes/ruby/") - @@_servlet_context.getResourcePaths(prefix).each do |path| - load @@_servlet_context.getRealPath("#{path}") # TODO need to support 'require' for production!! + def ScriptLoader.load_from_file_system + Dir.new(@@_ruby_script_path).each do |entry| + file = "#{@@_ruby_script_path}#{entry}" + load(file) if File.file?(file) # TODO need to ensure it is a *.rb file ... need to recursively search directories end end end
Modified: trunk/core/src/test/java/org/codehaus/waffle/context/pico/RubyScriptLoaderTest.java (127 => 128)
--- trunk/core/src/test/java/org/codehaus/waffle/context/pico/RubyScriptLoaderTest.java 2007-06-01 12:52:25 UTC (rev 127) +++ trunk/core/src/test/java/org/codehaus/waffle/context/pico/RubyScriptLoaderTest.java 2007-06-01 14:09:52 UTC (rev 128) @@ -1,5 +1,6 @@ package org.codehaus.waffle.context.pico; +import org.jmock.Expectations; import org.jmock.Mockery; import org.jmock.integration.junit4.JMock; import org.jmock.integration.junit4.JUnit4Mockery; @@ -19,14 +20,17 @@ public void startShouldFindAllResourcesAndLoadScriptsIntoRubyRuntime() { final ServletContext servletContext = context.mock(ServletContext.class); + context.checking(new Expectations() {{ + one (servletContext).getInitParameter(RubyScriptLoader.RUBY_SCRIPT_PATH_KEY); + will(returnValue(null)); + }}); + String script = "module Waffle\n" + " class ScriptLoader\n" + - " def ScriptLoader.servlet_context=(servlet_context)\n" + - " $sc = servlet_context\n" + - " end\n" + " def ScriptLoader.load_all(*args)\n" + - " $arg1 = 'called'\n" + + " $arg1 = args[0]\n" + + " $arg2 = args[1]\n" + " end\n" + " end\n" + "end\n"; @@ -38,7 +42,7 @@ loader.start(); // Ensure Waffle::ScriptLoader.load_all was called - Assert.assertEquals("called", JavaUtil.convertRubyToJava(runtime.evalScript("$arg1"))); - Assert.assertEquals(servletContext, JavaUtil.convertRubyToJava(runtime.evalScript("$sc"))); + Assert.assertEquals("/WEB-INF/classes/ruby/", JavaUtil.convertRubyToJava(runtime.evalScript("$arg1"))); + Assert.assertEquals(servletContext, JavaUtil.convertRubyToJava(runtime.evalScript("$arg2"))); } }
Modified: trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/RubyScriptReloader.java (127 => 128)
--- trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/RubyScriptReloader.java 2007-06-01 12:52:25 UTC (rev 127) +++ trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/RubyScriptReloader.java 2007-06-01 14:09:52 UTC (rev 128) @@ -16,7 +16,7 @@ } public void start() { - runtime.evalScript("Waffle::ScriptLoader.load_all"); + runtime.evalScript("Waffle::ScriptLoader.load_from_file_system"); } public void stop() {
Modified: trunk/examples/jruby-example/src/main/ruby/ruby/foo_bar.rb (127 => 128)
--- trunk/examples/jruby-example/src/main/ruby/ruby/foo_bar.rb 2007-06-01 12:52:25 UTC (rev 127) +++ trunk/examples/jruby-example/src/main/ruby/ruby/foo_bar.rb 2007-06-01 14:09:52 UTC (rev 128) @@ -12,6 +12,9 @@ #{session['waffle.session.container']} #{session.getServletContext().getRealPath('/WEB-INF/')} + + +YES } rescue Exception => e return e
Modified: trunk/examples/jruby-example/src/main/webapp/WEB-INF/web.xml (127 => 128)
--- trunk/examples/jruby-example/src/main/webapp/WEB-INF/web.xml 2007-06-01 12:52:25 UTC (rev 127) +++ trunk/examples/jruby-example/src/main/webapp/WEB-INF/web.xml 2007-06-01 14:09:52 UTC (rev 128) @@ -8,6 +8,7 @@ <display-name>Waffle JRuby Example</display-name> + <!-- 1. This is how an application registers its custom Registrar --> <context-param> <param-name>org.codehaus.waffle.registrar.Registrar</param-name> @@ -28,6 +29,11 @@ <param-value>org.codehaus.waffle.controller.RubyControllerDefinitionFactory</param-value> </context-param> + <context-param> + <param-name>org.codehaus.waffle.ruby.path</param-name> + <param-value>dir:/Users/mward/development/waffle/examples/jruby-example/src/main/ruby/ruby/</param-value><!-- this needs to be more forgiving --> + </context-param> + <listener> <listener-class>org.codehaus.waffle.context.pico.PicoWaffleContextListener</listener-class> </listener>
To unsubscribe from this list please visit:
