Title: [waffle-scm] [450] trunk: Resolved issues related to JRuby implementation

Diff

Deleted: trunk/examples/jruby-example/src/main/ruby/foo_bar.rb (449 => 450)

--- trunk/examples/jruby-example/src/main/ruby/foo_bar.rb	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/examples/jruby-example/src/main/ruby/foo_bar.rb	2007-12-06 14:15:44 UTC (rev 450)
@@ -1,74 +0,0 @@
-class FooBar
-
-  def index
-    @var1 = "is cool and fast, right?"
-    render("foobar.jspx")
-  end
-
-  def hola
-    errors # automatically resolves from params => req.attr => session.attr => application.attr
-  end
-
-  def ajax
-    "<h1>Hello</h1>"
-  end
-
-  def index_two
-    request[:foo] = 'bar'
-    session['bar'] = 'foo'
-    session['baz'] = 'foo'
-    application[:name] = 'Chicago'
-    p session
-
-    %{
-
-        HELLO WORLD from the index method
-        parameters: #{parameters}
-        params - #{str = ""; params.each_pair{|k,v| str << "k: #{k} v: #{v}"}}
-        request: #{request}
-        session: #{session}
-        application: #{application}
-        name: #{name}
-        servlet_context: #{servlet_context}
-        #{session['waffle.session.container']}
-
-        #{session.getServletContext().getRealPath('/WEB-INF/')}
-
-        auto resolve #{foo}
-
-        component: #{locate(java.util.List)}
-        component: #{locate(org.codehaus.waffle.example.jruby.dao.PersonDAO)}
-        component: #{locate_the_dao}
-
-        #{cls = Java::JavaClass.for_name('java.util.Vector')}
-        #{locate(Java::JavaClass.for_name('java.util.List'))}
-    }
-
-  end
-
-  def bar
-    "HELLO WORLD #{request.local_name} #{request.local_port}"
-  end
-
-  def view_jspx
-    p "CALLED!"
-    @var1 = "this is my variables value from jruby!!!!!!!!"
-    view = render("foobar.jspx")
-    p "DONE"
-    return view
-  end
-
-  def redirect_to_jspx
-    @var1 = "this is my variables value from jruby xxx"
-    return redirect_to("index.html")
-  end
-
-  def request_parameter_example
-    return "<h1>FOO: #{params['foo']}</h1>"
-  end
-
-  def request_attribute_example
-    return "<h1>FOO: #{request['foo']}</h1>"
-  end
-
-end
\ No newline at end of file

Copied: trunk/examples/jruby-example/src/main/ruby/foobar.rb (from rev 448, trunk/examples/jruby-example/src/main/ruby/foo_bar.rb) (0 => 450)

--- trunk/examples/jruby-example/src/main/ruby/foobar.rb	                        (rev 0)
+++ trunk/examples/jruby-example/src/main/ruby/foobar.rb	2007-12-06 14:15:44 UTC (rev 450)
@@ -0,0 +1,74 @@
+class FooBar
+
+  def index
+    @var1 = "is cool and fast, right?"
+    render("foobar.jspx")
+  end
+
+  def hola
+    errors # automatically resolves from params => req.attr => session.attr => application.attr
+  end
+
+  def ajax
+    "<h1>Hello</h1>"
+  end
+
+  def index_two
+    request[:foo] = 'bar'
+    session['bar'] = 'foo'
+    session['baz'] = 'foo'
+    application[:name] = 'Chicago'
+    p session
+
+    %{
+
+        HELLO WORLD from the index method
+        parameters: #{parameters}
+        params - #{str = ""; params.each_pair{|k,v| str << "k: #{k} v: #{v}"}}
+        request: #{request}
+        session: #{session}
+        application: #{application}
+        name: #{name}
+        servlet_context: #{servlet_context}
+        #{session['waffle.session.container']}
+
+        #{session.getServletContext().getRealPath('/WEB-INF/')}
+
+        auto resolve #{foo}
+
+        component: #{locate(java.util.List)}
+        component: #{locate(org.codehaus.waffle.example.jruby.dao.PersonDAO)}
+        component: #{locate_the_dao}
+
+        #{cls = Java::JavaClass.for_name('java.util.Vector')}
+        #{locate(Java::JavaClass.for_name('java.util.List'))}
+    }
+
+  end
+
+  def bar
+    "HELLO WORLD #{request.local_name} #{request.local_port}"
+  end
+
+  def view_jspx
+    p "CALLED!"
+    @var1 = "this is my variables value from jruby!!!!!!!!"
+    view = render("foobar.jspx")
+    p "DONE"
+    return view
+  end
+
+  def redirect_to_jspx
+    @var1 = "this is my variables value from jruby xxx"
+    return redirect_to("index.html")
+  end
+
+  def request_parameter_example
+    return "<h1>FOO: #{params['foo']}</h1>"
+  end
+
+  def request_attribute_example
+    return "<h1>FOO: #{request['foo']}</h1>"
+  end
+
+end
\ No newline at end of file

Modified: trunk/examples/jruby-example/src/main/webapp/WEB-INF/web.xml (449 => 450)

--- trunk/examples/jruby-example/src/main/webapp/WEB-INF/web.xml	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/examples/jruby-example/src/main/webapp/WEB-INF/web.xml	2007-12-06 14:15:44 UTC (rev 450)
@@ -12,7 +12,24 @@
     <param-name>org.codehaus.waffle.registrar.Registrar</param-name>
     <param-value>org.codehaus.waffle.example.jruby.JRubyRegistrar</param-value>
   </context-param>
+  <context-param>
+    <param-name>org.codehaus.waffle.monitor.RegistrarMonitor</param-name>
+    <param-value>org.codehaus.waffle.monitor.CommonsLoggingMonitor</param-value>
+  </context-param>
+  <context-param>
+    <param-name>org.codehaus.waffle.monitor.ActionMonitor</param-name>
+    <param-value>org.codehaus.waffle.monitor.CommonsLoggingMonitor</param-value>
+  </context-param>
+  <context-param>
+    <param-name>org.codehaus.waffle.monitor.ContextMonitor</param-name>
+    <param-value>org.codehaus.waffle.monitor.CommonsLoggingMonitor</param-value>
+  </context-param>
+  <context-param>
+    <param-name>org.codehaus.waffle.monitor.BindMonitor</param-name>
+    <param-value>org.codehaus.waffle.monitor.CommonsLoggingMonitor</param-value>
+  </context-param>
 
+
   <!-- Ruby Specific components -->
   <context-param>
     <param-name>org.codehaus.waffle.context.ContextContainerFactory</param-name>
@@ -30,7 +47,8 @@
   <!-- Define a relative path to the ruby script directory (for development) -->
   <context-param>
     <param-name>org.codehaus.waffle.ruby.path</param-name>
-    <param-value>dir:../src/main/ruby/</param-value><!-- this needs to be more forgiving -->
+    <param-value>dir:../../src/main/ruby/</param-value>
+    <!-- this needs to be more forgiving -->
   </context-param>
 
   <listener>
@@ -67,7 +85,7 @@
     <servlet-name>waffle</servlet-name>
     <url-pattern>*.waffle</url-pattern>
   </servlet-mapping>
-  
+
   <servlet-mapping>
     <servlet-name>rhtml</servlet-name>
     <url-pattern>*.rhtml</url-pattern>

Modified: trunk/pom.xml (449 => 450)

--- trunk/pom.xml	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/pom.xml	2007-12-06 14:15:44 UTC (rev 450)
@@ -34,7 +34,7 @@
       <dependency>
         <groupId>org.jruby</groupId>
         <artifactId>jruby-complete</artifactId>
-        <version>1.0</version>
+        <version>1.0.2</version>
         <scope>provided</scope>
       </dependency>
       <dependency>

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/RubyDataBinder.java (449 => 450)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/RubyDataBinder.java	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/RubyDataBinder.java	2007-12-06 14:15:44 UTC (rev 450)
@@ -1,9 +1,5 @@
 package org.codehaus.waffle.bind.ognl;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-
 import org.codehaus.waffle.action.ArgumentResolver;
 import org.codehaus.waffle.bind.BindErrorMessageResolver;
 import org.codehaus.waffle.bind.ValueConverterFinder;
@@ -14,12 +10,16 @@
 import org.jruby.javasupport.JavaEmbedUtils;
 import org.jruby.runtime.builtin.IRubyObject;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 public class RubyDataBinder extends OgnlDataBinder {
     private final ArgumentResolver argumentResolver;
 
     public RubyDataBinder(ValueConverterFinder valueConverterFinder,
                           BindErrorMessageResolver bindErrorMessageResolver,
-                          ArgumentResolver argumentResolver, BindMonitor bindMonitor) {
+                          ArgumentResolver argumentResolver,
+                          BindMonitor bindMonitor) {
         super(valueConverterFinder, bindErrorMessageResolver, bindMonitor);
         this.argumentResolver = argumentResolver;
     }

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/context/AbstractContextContainerFactory.java (449 => 450)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/context/AbstractContextContainerFactory.java	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/context/AbstractContextContainerFactory.java	2007-12-06 14:15:44 UTC (rev 450)
@@ -10,16 +10,15 @@
  *****************************************************************************/
 package org.codehaus.waffle.context;
 
-import static java.text.MessageFormat.format;
-
-import javax.servlet.ServletContext;
-
 import org.codehaus.waffle.WaffleException;
 import org.codehaus.waffle.i18n.MessageResources;
 import org.codehaus.waffle.monitor.ContextMonitor;
 import org.codehaus.waffle.registrar.Registrar;
 import org.codehaus.waffle.registrar.RegistrarAssistant;
 
+import javax.servlet.ServletContext;
+import static java.text.MessageFormat.format;
+
 /**
  * @author Michael Ward
  * @author Mauro Talevi
@@ -68,6 +67,11 @@
         applicationContextContainer = buildApplicationContextContainer();
         applicationContextContainer.registerComponentInstance(servletContext);
         applicationContextContainer.registerComponentInstance(messageResources);
+
+        // TODO register monitors to application context from component registry
+        // ComponentRegistry componentRegistry = ServletContextHelper.getComponentRegistry(servletContext);
+        // applicationContextContainer.registerComponentInstance(componentRegistry.getRegistrarMonitor());
+
         buildApplicationLevelRegistry();
         applicationContextContainer.start();
         contextMonitor.applicationContextContainerStarted();

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/context/pico/PicoContextContainerFactory.java (449 => 450)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/context/pico/PicoContextContainerFactory.java	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/context/pico/PicoContextContainerFactory.java	2007-12-06 14:15:44 UTC (rev 450)
@@ -10,9 +10,6 @@
  *****************************************************************************/
 package org.codehaus.waffle.context.pico;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
 import org.codehaus.waffle.Constants;
 import org.codehaus.waffle.context.AbstractContextContainerFactory;
 import org.codehaus.waffle.context.ContextContainer;
@@ -30,6 +27,9 @@
 import org.picocontainer.defaults.LifecycleStrategy;
 import org.picocontainer.monitors.NullComponentMonitor;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
 /**
  * @author Michael Ward
  * @author Mauro Talevi

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/context/pico/RubyAwarePicoContextContainerFactory.java (449 => 450)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/context/pico/RubyAwarePicoContextContainerFactory.java	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/context/pico/RubyAwarePicoContextContainerFactory.java	2007-12-06 14:15:44 UTC (rev 450)
@@ -1,10 +1,5 @@
 package org.codehaus.waffle.context.pico;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
 import org.codehaus.waffle.WaffleException;
 import org.codehaus.waffle.context.ContextContainer;
 import org.codehaus.waffle.i18n.MessageResources;
@@ -12,6 +7,12 @@
 import org.jruby.Ruby;
 import org.picocontainer.MutablePicoContainer;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+
 public class RubyAwarePicoContextContainerFactory extends PicoContextContainerFactory {
 
     public RubyAwarePicoContextContainerFactory(MessageResources messageResources, ContextMonitor contextMonitor) {
@@ -23,6 +24,7 @@
         ContextContainer contextContainer = super.buildApplicationContextContainer();
 
         Ruby runtime = Ruby.getDefaultInstance();
+        runtime.getLoadService().init(new ArrayList()); // this must be called, else we won't be able to load scripts!!
         loadRubyScriptFromClassLoader("org/codehaus/waffle/erb_extension.rb", runtime);
         loadRubyScriptFromClassLoader("org/codehaus/waffle/waffle.rb", runtime);
 

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/registrar/Registrar.java (449 => 450)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/registrar/Registrar.java	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/registrar/Registrar.java	2007-12-06 14:15:44 UTC (rev 450)
@@ -19,9 +19,18 @@
 public interface Registrar {
 
     boolean isRegistered(Object typeOrInstance);
-    
+
+    /**
+     * @param type represent both the key and type the object will be registered under
+     * @param parameters any parameters needed to satisfy the component being registered
+     */
     void register(Class<?> type, Object... parameters);
 
+    /**
+     * @param key represent the key the object will be registered under
+     * @param type represent the component type
+     * @param parameters any parameters needed to satisfy the component being registered
+     */
     void register(Object key, Class<?> type, Object... parameters);
 
     void registerInstance(Object instance);

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/registrar/RegistrarAssistant.java (449 => 450)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/registrar/RegistrarAssistant.java	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/registrar/RegistrarAssistant.java	2007-12-06 14:15:44 UTC (rev 450)
@@ -48,11 +48,11 @@
                 registrar.session();
             } else if (ContextLevel.REQUEST.equals(contextLevel)) {
                 registrar.request();
-                if ( !registrar.isRegistered(ErrorsContext.class) ){
-                    registrar.register((Object)ErrorsContext.class, DefaultErrorsContext.class);                    
+                if (!registrar.isRegistered(ErrorsContext.class)) {
+                    registrar.register((Object) ErrorsContext.class, DefaultErrorsContext.class);
                 }
-                if ( !registrar.isRegistered(MessagesContext.class) ){
-                    registrar.register((Object)MessagesContext.class, DefaultMessagesContext.class);
+                if (!registrar.isRegistered(MessagesContext.class)) {
+                    registrar.register((Object) MessagesContext.class, DefaultMessagesContext.class);
                 }
             }
         } catch (Exception e) {

Modified: trunk/waffle-core/src/main/ruby/org/codehaus/waffle/waffle.rb (449 => 450)

--- trunk/waffle-core/src/main/ruby/org/codehaus/waffle/waffle.rb	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/waffle-core/src/main/ruby/org/codehaus/waffle/waffle.rb	2007-12-06 14:15:44 UTC (rev 450)
@@ -30,7 +30,11 @@
       Dir.new(path).each do |entry|
         file = "#{path}#{entry}"
         if File.file?(file) # TODO need to recursively search directories
-          load(file) if file =~ /.rb$/
+          begin
+            load(file) if file =~ /.rb$/
+          rescue Exception => e
+            p "[WAFFLE] Error loading ruby script: #{e}" # TODO plugin monitoring/logging  
+          end
         end
       end
     end

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/context/pico/RubyAwarePicoContextContainerFactoryTest.java (449 => 450)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/context/pico/RubyAwarePicoContextContainerFactoryTest.java	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/context/pico/RubyAwarePicoContextContainerFactoryTest.java	2007-12-06 14:15:44 UTC (rev 450)
@@ -1,13 +1,13 @@
 package org.codehaus.waffle.context.pico;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 import org.codehaus.waffle.context.ContextContainer;
 import org.codehaus.waffle.monitor.SilentMonitor;
 import org.jruby.Ruby;
 import org.jruby.RubyBoolean;
+import org.jruby.RubyInteger;
 import org.jruby.javasupport.JavaEmbedUtils;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import org.junit.Test;
 import org.picocontainer.MutablePicoContainer;
 import org.picocontainer.PicoContainer;
@@ -27,6 +27,11 @@
         // ensure mixin occurred
         RubyBoolean rubyBoolean = (RubyBoolean) runtime.evalScript("Waffle::Controller.is_a? Module");
         assertTrue((Boolean) JavaEmbedUtils.rubyToJava(runtime, rubyBoolean, Boolean.class));
+
+        // ensure we can load ruby script
+        RubyInteger rubyInteger = (RubyInteger)runtime.evalScript("$LOAD_PATH.size");
+        Integer count = (Integer) JavaEmbedUtils.rubyToJava(runtime, rubyInteger, Integer.class);
+        assertTrue(count > 0);
     }
 
 }

Modified: trunk/waffle.ipr (449 => 450)

--- trunk/waffle.ipr	2007-12-05 12:27:33 UTC (rev 449)
+++ trunk/waffle.ipr	2007-12-06 14:15:44 UTC (rev 450)
@@ -45,6 +45,7 @@
       <entry name="?*.html" />
       <entry name="?*.dtd" />
       <entry name="?*.tld" />
+      <entry name="?*.rb" />
     </wildcardResourcePatterns>
   </component>
   <component name="DependenciesAnalyzeManager">
@@ -107,8 +108,33 @@
               <file url="" />
             </files>
           </module>
+          <module name="waffle-jruby-example">
+            <files>
+              <file url="" />
+            </files>
+          </module>
+          <module name="waffle-mydvds-example">
+            <files>
+              <file url="" />
+            </files>
+          </module>
+          <module name="waffle">
+            <files>
+              <file url="" />
+              <file url="" />
+            </files>
+          </module>
         </modules>
       </facet-type>
+      <facet-type id="hibernate">
+        <modules>
+          <module name="waffle-mydvds-example">
+            <files>
+              <file url="" />
+            </files>
+          </module>
+        </modules>
+      </facet-type>
     </autodetection-disabled>
   </component>
   <component name="GlobalLibrariesConfigurable.UI">


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to