Author: gk
Date: Tue May 28 10:39:00 2024
New Revision: 1918019
URL: http://svn.apache.org/viewvc?rev=1918019&view=rev
Log:
- assign class classloader to current thread classloader (if not null) for
groovy shell and handle resetting it
- use log4j2 logging
- patch update groovy-all to 3.0.21
Modified:
db/torque/trunk/torque-generator/pom.xml
db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/template/groovy/GroovyScriptOutlet.java
Modified: db/torque/trunk/torque-generator/pom.xml
URL:
http://svn.apache.org/viewvc/db/torque/trunk/torque-generator/pom.xml?rev=1918019&r1=1918018&r2=1918019&view=diff
==============================================================================
--- db/torque/trunk/torque-generator/pom.xml (original)
+++ db/torque/trunk/torque-generator/pom.xml Tue May 28 10:39:00 2024
@@ -87,7 +87,7 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
- <version>3.0.9</version>
+ <version>3.0.21</version>
<type>pom</type>
<exclusions>
<exclusion>
Modified:
db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
URL:
http://svn.apache.org/viewvc/db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java?rev=1918019&r1=1918018&r2=1918019&view=diff
==============================================================================
---
db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
(original)
+++
db/torque/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/UnitConfiguration.java
Tue May 28 10:39:00 2024
@@ -648,6 +648,8 @@ public class UnitConfiguration
.append(loglevel)
.append(", name=")
.append(templateSetName)
+ .append( ", classLoader=" )
+ .append(classLoader)
.append(")");
return result.toString();
}
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=1918019&r1=1918018&r2=1918019&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
Tue May 28 10:39:00 2024
@@ -26,6 +26,8 @@ import groovy.lang.Script;
import java.util.HashMap;
import java.util.Map;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.torque.generator.GeneratorException;
import org.apache.torque.generator.configuration.ConfigurationException;
import org.apache.torque.generator.configuration.ConfigurationProvider;
@@ -46,6 +48,13 @@ public class GroovyScriptOutlet extends
/** The cached compiled scripts, keyed by the detokenized path. */
private static Map<String, Script> cachedScripts
= new HashMap<>();
+
+ private static ClassLoader ccl = null;
+
+ /** if ClassLoader argument to getInstance is null set classLoader to
current threads context classLoader to reset it after statically initialized **/
+ private boolean contextClassLoaderSet = false;
+
+ private static Logger logger = LogManager.getLogger();
/**
* Initializes GroovyShell with provided class loader.
@@ -60,8 +69,20 @@ public class GroovyScriptOutlet extends
{
if (cl == null)
{
- cl = Thread.currentThread().getContextClassLoader();
+ logger.debug( "Provided cl ist null .." );
+ if (getClass().getClassLoader() != null) {
+ ccl = Thread.currentThread().getContextClassLoader();
+ logger.debug( "Saving current thread context
classloader:{}", ccl );
+
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ cl = Thread.currentThread().getContextClassLoader();
+ contextClassLoaderSet = true;
+ } else {
+ cl = Thread.currentThread().getContextClassLoader();
+ logger.debug( "Using default current thread context
classloader:{}", cl );
+ }
+
}
+ logger.debug( "classloader:{}", cl );
groovyShell = new GroovyShell( cl );
}
return groovyShell;
@@ -99,6 +120,7 @@ public class GroovyScriptOutlet extends
{
try
{
+
final String detokenizedPath = getDetokenizedPath(controllerState);
Script script = cachedScripts.get(detokenizedPath);
if (script == null)
@@ -121,7 +143,21 @@ public class GroovyScriptOutlet extends
throw new GeneratorException(
"Error executing groovy script " + getName(),
e);
+ } finally {
+ if (contextClassLoaderSet && ccl != null) {
+ Thread.currentThread().setContextClassLoader(ccl);
+ logger.debug( "reset context classloader:{}",
Thread.currentThread().getContextClassLoader() );
+ contextClassLoaderSet = false;
+ }
}
}
+
+// @Override
+// public void afterExecute(ControllerState controllerState)
+// {
+// super.afterExecute( controllerState );
+// Thread.currentThread().setContextClassLoader(ccl);
+// logger.debug( "reset context classloader:{}",
Thread.currentThread().getContextClassLoader() );
+// }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]