Author: gk
Date: Fri Mar 31 09:35:34 2023
New Revision: 1908844

URL: http://svn.apache.org/viewvc?rev=1908844&view=rev
Log:
- TORQUE-361: fix: Lazy initializing GroovyShell with class loader from 
unitConfiguration (unit descriptor classloader) and if null using default.

Modified:
    
db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/template/groovy/GroovyScriptOutlet.java

Modified: 
db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/template/groovy/GroovyScriptOutlet.java
URL: 
http://svn.apache.org/viewvc/db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/template/groovy/GroovyScriptOutlet.java?rev=1908844&r1=1908843&r2=1908844&view=diff
==============================================================================
--- 
db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/template/groovy/GroovyScriptOutlet.java
 (original)
+++ 
db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/template/groovy/GroovyScriptOutlet.java
 Fri Mar 31 09:35:34 2023
@@ -38,13 +38,35 @@ import org.apache.torque.generator.qname
  */
 public class GroovyScriptOutlet extends GroovyOutlet
 {
+    
     /** The groovy shell to execute groovy scripts. */
-    private static GroovyShell groovyShell = new GroovyShell();
+    private static volatile GroovyShell groovyShell = null;
+
 
     /** The cached compiled scripts, keyed by the detokenized path. */
     private static Map<String, Script> cachedScripts
         = new HashMap<>();
-
+      
+    /**
+     * Initializes GroovyShell with provided class loader.
+     * 
+     * @param cl if class loader is null uses {@link 
Thread#currentThread()}.getContextClassLoader()
+     * 
+     * @return
+     */
+    GroovyShell getInstance(ClassLoader cl)
+    {
+        if (groovyShell == null)
+        {
+            if (cl == null)
+            {
+                cl = Thread.currentThread().getContextClassLoader();
+            }
+            groovyShell = new GroovyShell( cl );
+        }
+        return groovyShell;
+    }
+    
     /**
      * Constructs a new GroovyScriptOutlet.
      *
@@ -81,7 +103,8 @@ public class GroovyScriptOutlet extends
             Script script = cachedScripts.get(detokenizedPath);
             if (script == null)
             {
-                script = groovyShell.parse(getContent(controllerState));
+                GroovyShell gs = 
getInstance(controllerState.getUnitConfiguration().getClassLoader());
+                script = gs.parse(getContent(controllerState));
                 cachedScripts.put(detokenizedPath, script);
             }
             final Binding scriptBinding = new Binding(binding);



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org
For additional commands, e-mail: torque-dev-h...@db.apache.org

Reply via email to