You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/01/26 18:39:50 UTC

[camel] branch main updated: CAMEL-18977: camel-joor - Make the code more flexible for native mode (#9208)

This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 73f61a40095 CAMEL-18977: camel-joor - Make the code more flexible for native mode (#9208)
73f61a40095 is described below

commit 73f61a40095f6abe8c7ed6b7568223fc1b8f23f3
Author: Nicolas Filotto <es...@users.noreply.github.com>
AuthorDate: Thu Jan 26 19:39:42 2023 +0100

    CAMEL-18977: camel-joor - Make the code more flexible for native mode (#9208)
    
    ## Motivation
    
    With the current code base, it is hard to change the behavior of the jOOR language in order to move most of the logic at build time and/or at static initialization time, without having to use ugly hacks like reflection. The goal of this task is to make the code more flexible to avoid using hacks.
    
    ## Modifications:
    
    * Add a constructor to the class `JoorLanguage` to be able to inject specific jOOR compiler and jOOR script compiler
    * Add getters for the jOOR compiler and jOOR script compiler
    * Make the method `evalCode` public to give access to the generated code.
---
 .../apache/camel/language/joor/JoorCompiler.java    |  2 +-
 .../apache/camel/language/joor/JoorLanguage.java    | 21 +++++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorCompiler.java b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorCompiler.java
index cd90a944249..3a4a17a74ec 100644
--- a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorCompiler.java
+++ b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorCompiler.java
@@ -116,7 +116,7 @@ public class JoorCompiler extends ServiceSupport implements StaticService {
         return answer;
     }
 
-    private String evalCode(CamelContext camelContext, String fqn, String script, boolean singleQuotes) {
+    public String evalCode(CamelContext camelContext, String fqn, String script, boolean singleQuotes) {
         String qn = fqn.substring(0, fqn.lastIndexOf('.'));
         String name = fqn.substring(fqn.lastIndexOf('.') + 1);
 
diff --git a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorLanguage.java b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorLanguage.java
index 6093c4a1e57..329e56d7c9f 100644
--- a/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorLanguage.java
+++ b/components/camel-joor/src/main/java/org/apache/camel/language/joor/JoorLanguage.java
@@ -41,8 +41,8 @@ public class JoorLanguage extends TypedLanguageSupport implements ScriptingLangu
     private static final Logger LOG = LoggerFactory.getLogger(JoorLanguage.class);
 
     private static Boolean java8;
-    private final JoorCompiler compiler = new JoorCompiler();
-    private final JoorScriptingCompiler scriptingCompiler = new JoorScriptingCompiler();
+    private final JoorCompiler compiler;
+    private final JoorScriptingCompiler scriptingCompiler;
     private final Set<String> imports = new TreeSet<>();
     private final Map<String, String> aliases = new HashMap<>();
 
@@ -50,6 +50,23 @@ public class JoorLanguage extends TypedLanguageSupport implements ScriptingLangu
     private boolean preCompile = true;
     private boolean singleQuotes = true;
 
+    public JoorLanguage() {
+        this(new JoorCompiler(), new JoorScriptingCompiler());
+    }
+
+    public JoorLanguage(JoorCompiler compiler, JoorScriptingCompiler scriptingCompiler) {
+        this.compiler = compiler;
+        this.scriptingCompiler = scriptingCompiler;
+    }
+
+    public JoorCompiler getCompiler() {
+        return compiler;
+    }
+
+    public JoorScriptingCompiler getScriptingCompiler() {
+        return scriptingCompiler;
+    }
+
     public String getConfigResource() {
         return configResource;
     }