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

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


The following commit(s) were added to refs/heads/camel-3.x by this push:
     new 485da6eaf7d CAMEL-18977: camel-joor - Make the code more flexible for 
native mode (#9216)
485da6eaf7d is described below

commit 485da6eaf7d13ed35693d6b5e750b310d59270fc
Author: Nicolas Filotto <[email protected]>
AuthorDate: Fri Jan 27 08:56:59 2023 +0100

    CAMEL-18977: camel-joor - Make the code more flexible for native mode 
(#9216)
    
    ## 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;
     }

Reply via email to