This is an automated email from the ASF dual-hosted git repository. nfilotto pushed a commit to branch 4452/disable-aot-compilation in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 1ff28f5f160a8d959bf4189677fe97101043ccb5 Author: Nicolas Filotto <[email protected]> AuthorDate: Fri Jan 27 16:10:27 2023 +0100 Ref #4452: Allow to disable AOT compilation of jOOR expressions --- .../ROOT/pages/reference/extensions/joor.adoc | 6 ++++++ .../component/joor/deployment/JoorProcessor.java | 21 ++++++++++++++++++--- .../joor/runtime/JoorExpressionConfig.java | 4 ++++ .../camel/quarkus/component/joor/it/JoorRoute.java | 2 +- .../joor/src/main/resources/application.properties | 18 ++++++++++++++++++ integration-tests/joor/src/main/resources/bean.joor | 21 --------------------- integration-tests/joor/src/main/resources/bean.txt | 4 ++++ pom.xml | 1 - 8 files changed, 51 insertions(+), 26 deletions(-) diff --git a/docs/modules/ROOT/pages/reference/extensions/joor.adoc b/docs/modules/ROOT/pages/reference/extensions/joor.adoc index f137afe196..afec564b52 100644 --- a/docs/modules/ROOT/pages/reference/extensions/joor.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/joor.adoc @@ -74,6 +74,12 @@ The specific location of the configuration of the jOOR language. The specific default result type of an expression expressed in jOOR language. | `string` | + +|icon:lock[title=Fixed at build time] [[quarkus.camel.joor.compile-ahead-of-time]]`link:#quarkus.camel.joor.compile-ahead-of-time[quarkus.camel.joor.compile-ahead-of-time]` + +In JVM mode, indicates whether the expressions must be compiled ahead-of-time. +| `boolean` +| `false` |=== [.configuration-legend] diff --git a/extensions/joor/deployment/src/main/java/org/apache/camel/quarkus/component/joor/deployment/JoorProcessor.java b/extensions/joor/deployment/src/main/java/org/apache/camel/quarkus/component/joor/deployment/JoorProcessor.java index 938855be4d..19bee37f1c 100644 --- a/extensions/joor/deployment/src/main/java/org/apache/camel/quarkus/component/joor/deployment/JoorProcessor.java +++ b/extensions/joor/deployment/src/main/java/org/apache/camel/quarkus/component/joor/deployment/JoorProcessor.java @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.function.BooleanSupplier; import java.util.stream.Collectors; import io.quarkus.bootstrap.model.ApplicationModel; @@ -31,6 +32,7 @@ import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.GeneratedClassBuildItem; +import io.quarkus.deployment.pkg.PackageConfig; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.deployment.recording.RecorderContext; import io.quarkus.maven.dependency.ResolvedDependency; @@ -70,7 +72,7 @@ class JoorProcessor { return new FeatureBuildItem(FEATURE); } - @BuildStep + @BuildStep(onlyIf = CompileAheadOfTime.class) void collectExpressions(JoorExpressionConfig config, ExpressionExtractionResultBuildItem result, List<ExpressionBuildItem> expressions, @@ -121,7 +123,7 @@ class JoorProcessor { } } - @BuildStep + @BuildStep(onlyIf = CompileAheadOfTime.class) void compileExpressions(CurateOutcomeBuildItem curateOutcomeBuildItem, List<JoorExpressionSourceBuildItem> sources, BuildProducer<GeneratedClassBuildItem> generatedClass) { @@ -159,7 +161,7 @@ class JoorProcessor { } @Record(ExecutionTime.STATIC_INIT) - @BuildStep + @BuildStep(onlyIf = CompileAheadOfTime.class) @Consume(CamelContextBuildItem.class) CamelBeanBuildItem configureLanguage( JoorExpressionConfig config, @@ -208,4 +210,17 @@ class JoorProcessor { throw new RuntimeException("Cannot extract the generated code from the compiler", e); } } + + /** + * Indicates whether the AOT compilation of the jOOR expressions should be done. + */ + public static final class CompileAheadOfTime implements BooleanSupplier { + JoorExpressionConfig config; + PackageConfig packageConfig; + + @Override + public boolean getAsBoolean() { + return config.compileAheadOfTime || packageConfig.type.equalsIgnoreCase(PackageConfig.NATIVE); + } + } } diff --git a/extensions/joor/runtime/src/main/java/org/apache/camel/quarkus/component/joor/runtime/JoorExpressionConfig.java b/extensions/joor/runtime/src/main/java/org/apache/camel/quarkus/component/joor/runtime/JoorExpressionConfig.java index 1758f33c94..44c2cfa85f 100644 --- a/extensions/joor/runtime/src/main/java/org/apache/camel/quarkus/component/joor/runtime/JoorExpressionConfig.java +++ b/extensions/joor/runtime/src/main/java/org/apache/camel/quarkus/component/joor/runtime/JoorExpressionConfig.java @@ -39,4 +39,8 @@ public class JoorExpressionConfig { /** The specific default result type of an expression expressed in jOOR language. */ @ConfigItem public Optional<String> resultType; + + /** In JVM mode, indicates whether the expressions must be compiled ahead-of-time. */ + @ConfigItem(defaultValue = "false") + public boolean compileAheadOfTime; } diff --git a/integration-tests/joor/src/main/java/org/apache/camel/quarkus/component/joor/it/JoorRoute.java b/integration-tests/joor/src/main/java/org/apache/camel/quarkus/component/joor/it/JoorRoute.java index 801e29aeb2..5475697aed 100644 --- a/integration-tests/joor/src/main/java/org/apache/camel/quarkus/component/joor/it/JoorRoute.java +++ b/integration-tests/joor/src/main/java/org/apache/camel/quarkus/component/joor/it/JoorRoute.java @@ -24,7 +24,7 @@ public class JoorRoute extends RouteBuilder { public void configure() { routeTemplate("whereTo") .templateParameter("bar") - .templateBean("myBar", "joor", "resource:classpath:bean.joor") + .templateBean("myBar", "joor", "resource:classpath:bean.txt") .from("kamelet:source") .to("bean:{{myBar}}"); diff --git a/integration-tests/joor/src/main/resources/application.properties b/integration-tests/joor/src/main/resources/application.properties new file mode 100644 index 0000000000..b591c25ea9 --- /dev/null +++ b/integration-tests/joor/src/main/resources/application.properties @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +quarkus.camel.joor.compile-ahead-of-time=true diff --git a/integration-tests/joor/src/main/resources/bean.joor b/integration-tests/joor/src/main/resources/bean.joor deleted file mode 100644 index a41fc5efbc..0000000000 --- a/integration-tests/joor/src/main/resources/bean.joor +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -var bean = new org.apache.camel.quarkus.component.joor.it.JoorBean(); -// rtc is RouteTemplateContext -bean.setBar(rtc.getProperty('bar', String.class)); -return bean; diff --git a/integration-tests/joor/src/main/resources/bean.txt b/integration-tests/joor/src/main/resources/bean.txt new file mode 100644 index 0000000000..b0ec3042a0 --- /dev/null +++ b/integration-tests/joor/src/main/resources/bean.txt @@ -0,0 +1,4 @@ +var bean = new org.apache.camel.quarkus.component.joor.it.JoorBean(); +// rtc is RouteTemplateContext +bean.setBar(rtc.getProperty('bar', String.class)); +return bean; diff --git a/pom.xml b/pom.xml index 9daf1f8c34..e4506141bf 100644 --- a/pom.xml +++ b/pom.xml @@ -552,7 +552,6 @@ <Jenkinsfile>SLASHSTAR_STYLE</Jenkinsfile> <Jenkinsfile.quarkus>SLASHSTAR_STYLE</Jenkinsfile.quarkus> <Jenkinsfile.sonarcloud>SLASHSTAR_STYLE</Jenkinsfile.sonarcloud> - <joor>SLASHSTAR_STYLE</joor> <jsh>SLASHSTAR_STYLE</jsh> <mjs>SLASHSTAR_STYLE</mjs> <properties>CAMEL_PROPERTIES_STYLE</properties>
