You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/12/12 15:32:23 UTC
(camel) 03/07: CAMEL-20141: Consolidate camel-joor and camel-java-joor-dsl
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch joor
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 218b32d137748ea6f0ac07058f9df3a5223e36f7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Dec 12 12:06:08 2023 +0100
CAMEL-20141: Consolidate camel-joor and camel-java-joor-dsl
---
.../camel/language/joor/JoorScriptingCompiler.java | 24 ++++++++++++----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorScriptingCompiler.java b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorScriptingCompiler.java
index c41335ac9b7..b3bef416b69 100644
--- a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorScriptingCompiler.java
+++ b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorScriptingCompiler.java
@@ -34,15 +34,11 @@ import org.apache.camel.support.ScriptHelper;
import org.apache.camel.support.service.ServiceSupport;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StopWatch;
-import org.joor.CompileOptions;
-import org.joor.Reflect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JoorScriptingCompiler extends ServiceSupport implements StaticService {
- // TODO: Use MultiCompile
-
private static final Pattern BEAN_INJECTION_PATTERN = Pattern.compile("(#bean:)([A-Za-z0-9-_]*)");
private static final Logger LOG = LoggerFactory.getLogger(JoorScriptingCompiler.class);
@@ -87,19 +83,25 @@ public class JoorScriptingCompiler extends ServiceSupport implements StaticServi
if (LOG.isDebugEnabled()) {
LOG.debug("Compiling code:\n\n{}\n", code);
}
+ CompilationUnit unit = CompilationUnit.input();
+ unit.addClass(className, code);
+
// include classloader from Camel, so we can load any already compiled and loaded classes
- CompileOptions co = new CompileOptions();
ClassLoader parent = MethodHandles.lookup().lookupClass().getClassLoader();
if (parent instanceof URLClassLoader ucl) {
ClassLoader cl = new CamelJoorClassLoader(ucl, camelContext);
- co = new CompileOptions();
- co = co.classLoader(cl);
+ unit.withClassLoader(cl);
}
LOG.debug("Compiling: {}", className);
- Reflect ref = Reflect.compile(className, code, co);
- Class<?> clazz = ref.type();
- LOG.debug("Compiled to Java class: {}", clazz);
- answer = (JoorScriptingMethod) clazz.getConstructor(CamelContext.class).newInstance(camelContext);
+
+ CompilationUnit.Result result = MultiCompile.compileUnit(unit);
+ Class<?> clazz = result.getClass(className);
+ if (clazz != null) {
+ LOG.debug("Compiled to Java class: {}", clazz);
+ answer = (JoorScriptingMethod) clazz.getConstructor(CamelContext.class).newInstance(camelContext);
+ } else {
+ answer = null;
+ }
} catch (Exception e) {
throw new JoorCompilationException(className, code, e);
}