incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r689731 - in /incubator/sling/trunk/scripting/ruby: pom.xml src/main/java/org/apache/sling/scripting/ruby/ErbScriptEngine.java
Date Thu, 28 Aug 2008 06:43:10 GMT
Author: bdelacretaz
Date: Wed Aug 27 23:43:09 2008
New Revision: 689731

URL: http://svn.apache.org/viewvc?rev=689731&view=rev
Log:
SLING-632 - downgrade jruby to 1.0 due to missing dependencies for 1.1.1

Modified:
    incubator/sling/trunk/scripting/ruby/pom.xml
    incubator/sling/trunk/scripting/ruby/src/main/java/org/apache/sling/scripting/ruby/ErbScriptEngine.java

Modified: incubator/sling/trunk/scripting/ruby/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/ruby/pom.xml?rev=689731&r1=689730&r2=689731&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/ruby/pom.xml (original)
+++ incubator/sling/trunk/scripting/ruby/pom.xml Wed Aug 27 23:43:09 2008
@@ -62,10 +62,9 @@
                         <Import-Package>
                             javax.swing.*;
                             org.apache.bsf.*;
-                            sun.misc; resolution:=optional,
-                            *
+                            sun.misc; resolution:=optional
                         </Import-Package>
-                        
+                        <DynamicImport-Package>*</DynamicImport-Package>
                         <ScriptEngine-Name>${pom.name}</ScriptEngine-Name>
                         <ScriptEngine-Version>${pom.version}</ScriptEngine-Version>
                     </instructions>
@@ -102,7 +101,7 @@
         <dependency>
             <groupId>org.jruby</groupId>
             <artifactId>jruby-complete</artifactId>
-            <version>1.1.1</version>
+            <version>1.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: incubator/sling/trunk/scripting/ruby/src/main/java/org/apache/sling/scripting/ruby/ErbScriptEngine.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/ruby/src/main/java/org/apache/sling/scripting/ruby/ErbScriptEngine.java?rev=689731&r1=689730&r2=689731&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/ruby/src/main/java/org/apache/sling/scripting/ruby/ErbScriptEngine.java
(original)
+++ incubator/sling/trunk/scripting/ruby/src/main/java/org/apache/sling/scripting/ruby/ErbScriptEngine.java
Wed Aug 27 23:43:09 2008
@@ -33,7 +33,7 @@
 import org.jruby.runtime.builtin.IRubyObject;
 
 /**
- * A ScriptEngine that uses ruby erb templates to render a Resource.
+ * JRuby ScriptEngine
  */
 public class ErbScriptEngine extends AbstractSlingScriptEngine {
 
@@ -46,12 +46,18 @@
     public ErbScriptEngine(ErbScriptEngineFactory factory) {
         super(factory);
 
-        runtime = Ruby.newInstance();
-        runtime.evalScriptlet("require 'java';require 'erb';self.send :include, ERB::Util;class
ERB;def get_binding;binding;end;attr_reader :props;def set_props(p);@props = p;"
-            + "for name,v in @props;instance_eval \"def #{name}; @props['#{name}'];end\";end;end;end;");
-
-        erbModule = runtime.getClassFromPath("ERB");
-        bindingSym = RubySymbol.newSymbol(runtime, "get_binding");
+        final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+        try {
+        	Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            runtime = Ruby.getDefaultInstance();
+            runtime.evalScript("require 'java';require 'erb';self.send :include, ERB::Util;class
ERB;def get_binding;binding;end;attr_reader :props;def set_props(p);@props = p;"
+                + "for name,v in @props;instance_eval \"def #{name}; @props['#{name}'];end\";end;end;end;");
+
+            erbModule = runtime.getClassFromPath("ERB");
+            bindingSym = RubySymbol.newSymbol(runtime, "get_binding");
+        } finally {
+        	Thread.currentThread().setContextClassLoader(oldClassLoader);
+        }
     }
 
     public Object eval(Reader script, ScriptContext scriptContext)
@@ -66,10 +72,12 @@
         // ensure GET request
         if (!"GET".equals(helper.getRequest().getMethod())) {
             throw new ScriptException(
-                "FreeMarker templates only support GET requests");
+                "JRuby scripting only supports GET requests");
         }
 
+        final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
         try {
+        	Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
             StringBuffer scriptString = new StringBuffer();
             BufferedReader bufferedScript = new BufferedReader(script);
             String nextLine = bufferedScript.readLine();
@@ -97,8 +105,11 @@
                 (String) JavaEmbedUtils.invokeMethod(runtime, erb, "result",
                     new Object[] { binding }, String.class));
         } catch (Throwable t) {
-            throw new ScriptException("Failure running Ruby script:"
-                + t.getMessage());
+        	final ScriptException ex = new ScriptException("Failure running Ruby script:" +
t);
+        	ex.initCause(t);
+        	throw ex;
+        } finally {
+        	Thread.currentThread().setContextClassLoader(oldClassLoader);
         }
         return null;
     }



Mime
View raw message