incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r887965 - in /sling/trunk/contrib: launchpad/testing/src/test/resources/integration-test/scala/ scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ scripting/scala/engine/src/test/resources/scripts/ scripting/scala/interp...
Date Mon, 07 Dec 2009 15:55:00 GMT
Author: cziegeler
Date: Mon Dec  7 15:54:59 2009
New Revision: 887965

URL: http://svn.apache.org/viewvc?rev=887965&view=rev
Log:
SLING-1221 : Scala scripting: script bindings not thread safe. Apply patch from Michael Dürig

Modified:
    sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/rendering-test.scs
    sling/trunk/contrib/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaScriptEngineTest.java
    sling/trunk/contrib/scripting/scala/engine/src/test/resources/scripts/simple.scs
    sling/trunk/contrib/scripting/scala/interpreter/pom.xml
    sling/trunk/contrib/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaInterpreter.scala
    sling/trunk/contrib/scripting/scala/interpreter/src/test/scala/org/apache/sling/scripting/scala/interpreter/InterpreterTest.scala

Modified: sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/rendering-test.scs
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/rendering-test.scs?rev=887965&r1=887964&r2=887965&view=diff
==============================================================================
--- sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/rendering-test.scs
(original)
+++ sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/rendering-test.scs
Mon Dec  7 15:54:59 2009
@@ -17,8 +17,8 @@
  * under the License.
  */
 package nt.unstructured {
-  object html {
-    import html_Bindings._
+  class html(vars: htmlVars) {
+    import vars._
 
     println {
       <h1>Scala rendering result</h1>

Modified: sling/trunk/contrib/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaScriptEngineTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaScriptEngineTest.java?rev=887965&r1=887964&r2=887965&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaScriptEngineTest.java
(original)
+++ sling/trunk/contrib/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaScriptEngineTest.java
Mon Dec  7 15:54:59 2009
@@ -44,7 +44,7 @@
     }
 
     public void testEvalString() throws ScriptException, InvocationTargetException {
-        String code = "package a { object Testi { print(1 + 2)}}";
+        String code = "package a { class Testi(vars: TestiVars) { print(1 + 2)}}";
         assertEquals("3", evalScala(code));
     }
 
@@ -70,7 +70,7 @@
             // expected
         }
     }
-    
+
     public void testDefaultPackage() {
         String code = "package a { object Testi { print(1 + 2)}}";
         try {
@@ -91,7 +91,7 @@
 
     public void testNodeAccess() throws RepositoryException, NamingException, ScriptException,
InvocationTargetException {
         Node n = getTestRootNode();
-        String code = "package a { import Testi_Bindings._; object Testi { print(n.getPath)}}";
+        String code = "package a { class Testi(vars: TestiVars) { import vars._; print(n.getPath)}}";
         ScalaBindings bindings = new ScalaBindings();
         bindings.put("n", n, Node.class);
         assertEquals(n.getPath(), evalScala(code, bindings));
@@ -108,12 +108,12 @@
 
         AbstractFile src = srcDir.fileNamed("Testi");
         PrintWriter writer = new PrintWriter(src.output());
-        writer.print("package a { import Testi_Bindings._; object Testi { print(msg + \":
\" + time)}}");
+        writer.print("package a { class Testi(vars: TestiVars) { import vars._; print(msg
+ \": \" + time)}}");
         writer.close();
 
         evalScala(SCRIPT_NAME, src, bindings);
     }
-    
+
     protected String createScriptName() {
         return SCRIPT_NAME;
     }

Modified: sling/trunk/contrib/scripting/scala/engine/src/test/resources/scripts/simple.scs
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/engine/src/test/resources/scripts/simple.scs?rev=887965&r1=887964&r2=887965&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/scala/engine/src/test/resources/scripts/simple.scs (original)
+++ sling/trunk/contrib/scripting/scala/engine/src/test/resources/scripts/simple.scs Mon Dec
 7 15:54:59 2009
@@ -1,7 +1,5 @@
 package a {
-  import Testi_Bindings._
-  
-  object Testi {
+  class Testi(vars: TestiVars) {
     print(1 + 2)
   }
 }
\ No newline at end of file

Modified: sling/trunk/contrib/scripting/scala/interpreter/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/interpreter/pom.xml?rev=887965&r1=887964&r2=887965&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/scala/interpreter/pom.xml (original)
+++ sling/trunk/contrib/scripting/scala/interpreter/pom.xml Mon Dec  7 15:54:59 2009
@@ -68,9 +68,10 @@
                     <buildcommands>
                         <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
                     </buildcommands>
-                    <additionalProjectnatures>
-                        <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
-                    </additionalProjectnatures>
+                    <projectnatures>
+                        <java.lang.String>ch.epfl.lamp.sdt.core.scalanature</java.lang.String>
+                        <java.lang.String>org.eclipse.jdt.core.javanature</java.lang.String>
+                    </projectnatures>
                     <classpathContainers>
                         <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
                         <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>

Modified: sling/trunk/contrib/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaInterpreter.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaInterpreter.scala?rev=887965&r1=887964&r2=887965&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaInterpreter.scala
(original)
+++ sling/trunk/contrib/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaInterpreter.scala
Mon Dec  7 15:54:59 2009
@@ -108,8 +108,8 @@
    */
   @throws(classOf[InterpreterException])
   protected def preProcess(name: String, code: String, bindings: Bindings): String = {
-    def bind(a: (String, Argument[_])) =
-      "lazy val " + a._1 + " = bindings.getValue(\"" + a._1 + "\").asInstanceOf[" + a._2.getType.getName
+ "]"
+    def bind(arg: (String, Argument[_])) =
+      "lazy val " + arg._1 + " = bindings.getValue(\"" + arg._1 + "\").asInstanceOf[" + arg._2.getType.getName
+ "]"
 
     val compounds = packetize(name)
 
@@ -121,18 +121,16 @@
 
     code + NL + 
     packageDeclaration + " {" + NL + 
-    "  object " + className + "_Bindings { " + NL +
-    "    var bindings: org.apache.sling.scripting.scala.interpreter.Bindings = null" + NL
+ 
-         bindings.map(bind).mkString("", NL, NL) +
+    "  class " + className + "Vars(bindings: org.apache.sling.scripting.scala.interpreter.Bindings)
{ " + NL +
+         bindings.map(bind).mkString(NL) + NL + 
     "  } " + NL + 
     "  object " + className + "Runner {" + NL +
     "    def main(bindings: org.apache.sling.scripting.scala.interpreter.Bindings," + NL
+
     "             stdIn: java.io.InputStream," + NL +
     "             stdOut: java.io.OutputStream) {" + NL +
-           className + "_Bindings.bindings = bindings" + NL +  
     "      Console.withIn(stdIn) {" + NL +
     "        Console.withOut(stdOut) {" + NL +
-               className + NL +
+    "          new " + className + "(new " + className + "Vars(bindings))" + NL +
     "          stdOut.flush" + NL +
     "        }" + NL +
     "      }" + NL +

Modified: sling/trunk/contrib/scripting/scala/interpreter/src/test/scala/org/apache/sling/scripting/scala/interpreter/InterpreterTest.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/interpreter/src/test/scala/org/apache/sling/scripting/scala/interpreter/InterpreterTest.scala?rev=887965&r1=887964&r2=887965&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/scala/interpreter/src/test/scala/org/apache/sling/scripting/scala/interpreter/InterpreterTest.scala
(original)
+++ sling/trunk/contrib/scripting/scala/interpreter/src/test/scala/org/apache/sling/scripting/scala/interpreter/InterpreterTest.scala
Mon Dec  7 15:54:59 2009
@@ -74,7 +74,7 @@
     bindings.put("msg", "Hello world", classOf[String])
     bindings.put("time", time, classOf[java.util.Date])
 
-    val code = "package a { import Testi_Bindings._; object Testi { print(msg + \": \" +
time)}}"
+    val code = "package a { class Testi(vars: TestiVars) {import vars._; print(msg + \":
\" + time)}}"
     val name = "a.Testi"
 
     val out = new java.io.ByteArrayOutputStream
@@ -97,7 +97,7 @@
     bindings.put("msg", "Hello world", classOf[String])
     bindings.put("time", time, classOf[java.util.Date])
 
-    val code = "package a { import Testi_Bindings._; object Testi { print(msg + \": \" +
time)}}"
+    val code = "package a { class Testi(vars: TestiVars) {import vars._; print(msg + \":
\" + time)}}"
     val name = "a.Testi"
     
     val src = srcDir.fileNamed("Testi")
@@ -125,7 +125,7 @@
     bindings.put("msg", "Hello world", classOf[String])
     bindings.put("time", time, classOf[java.util.Date])
 
-    val code = "package a { import Testi_Bindings._; object Testi { print(msg + \": \" +
time)}}"
+    val code = "package a { class Testi(vars: TestiVars) {import vars._; print(msg + \":
\" + time)}}"
     val name = "a.Testi"
                                        
     val src = srcDir.fileNamed("Testi")



Mime
View raw message