You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/12/23 13:51:45 UTC

[GitHub] [camel-quarkus] essobedo opened a new pull request, #4359: Ref #4358: Java jOOR DSL native support

essobedo opened a new pull request, #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359

   fixes #4358
   
   ## Motivation
   
   [To support routes written in Java language in Camel-K](https://github.com/apache/camel-k/issues/3023), we have to make the extension `java-joor-dsl` compatible with the native mode.
   
   ## Modifications
   
   The main idea is to compile the java resources using jOOR at build time and ignore runtime compilation requests.
   
   * Move the extension to native using the `promote` mojo
   * Declare class resources as generated without any modifications
   * Compile java resources using jOOR and declare the result as generated
   * Register the default constructor of the generated classes for reflection
   * Instantiate and register the `RoutesBuilder` at runtime
   * Substitute the body of the methods `doLoadRoutesBuilders` to do nothing at runtime
   
   Note: I had to use an ugly workaround to provide the classpath, I intend to change the code in Camel to clean it up later.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] ppalaga commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1062425385


##########
extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.quarkus.dsl.java.joor.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+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.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.maven.dependency.ResolvedDependency;
+import io.quarkus.paths.PathCollection;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.CamelContext;
+import org.apache.camel.dsl.java.joor.CompilationUnit;
+import org.apache.camel.dsl.java.joor.MultiCompile;
+import org.apache.camel.quarkus.core.deployment.main.CamelMainHelper;
+import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
+import org.apache.camel.quarkus.dsl.java.joor.runtime.JavaJoorDslRecorder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JavaJoorDslProcessor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JavaJoorDslProcessor.class);
+    private static final String FEATURE = "camel-java-joor-dsl";
+
+    private static final Pattern PACKAGE_PATTERN = Pattern.compile(
+            "^\\s*package\\s+([a-zA-Z][\\.\\w]*)\\s*;.*$", Pattern.MULTILINE);
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    void loadClassesAOT(BuildProducer<JavaJoorGeneratedClassBuildItem> generatedClass) throws Exception {
+        LOG.debug("Loading .class resources");
+        CamelMainHelper.forEachMatchingResource(
+                resource -> {
+                    if (!resource.getLocation().endsWith(".class")) {
+                        return;
+                    }
+                    try (InputStream is = resource.getInputStream()) {
+                        generatedClass
+                                .produce(new JavaJoorGeneratedClassBuildItem(asClassName(resource), resource.getLocation(),
+                                        is.readAllBytes()));
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+    }

Review Comment:
   Hm... https://issues.apache.org/jira/browse/CAMEL-18014 says 
   
   > When compiling with camel-java-dsl we can have it capture the compiled byte code, which allows us to write to disk, which we can make possible as a build step, that allows to load the routes from disk and avoid the compilation step at runtime.
   
   @davsclaus is that use case described somewhere in more details? I mean what is build time and runtime for Camel JBang? I mostly wonder why would the build time part need to pass the .class files as resources to the runtime? Why can runtime simply pick those via stock java class path? Does this use case make any sense on Quarkus?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] ppalaga commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1059635279


##########
extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.quarkus.dsl.java.joor.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+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.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.maven.dependency.ResolvedDependency;
+import io.quarkus.paths.PathCollection;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.CamelContext;
+import org.apache.camel.dsl.java.joor.CompilationUnit;
+import org.apache.camel.dsl.java.joor.MultiCompile;
+import org.apache.camel.quarkus.core.deployment.main.CamelMainHelper;
+import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
+import org.apache.camel.quarkus.dsl.java.joor.runtime.JavaJoorDslRecorder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JavaJoorDslProcessor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JavaJoorDslProcessor.class);
+    private static final String FEATURE = "camel-java-joor-dsl";
+
+    private static final Pattern PACKAGE_PATTERN = Pattern.compile(
+            "^\\s*package\\s+([a-zA-Z][\\.\\w]*)\\s*;.*$", Pattern.MULTILINE);
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    void loadClassesAOT(BuildProducer<JavaJoorGeneratedClassBuildItem> generatedClass) throws Exception {
+        LOG.debug("Loading .class resources");
+        CamelMainHelper.forEachMatchingResource(
+                resource -> {
+                    if (!resource.getLocation().endsWith(".class")) {
+                        return;
+                    }
+                    try (InputStream is = resource.getInputStream()) {
+                        generatedClass
+                                .produce(new JavaJoorGeneratedClassBuildItem(asClassName(resource), resource.getLocation(),
+                                        is.readAllBytes()));
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+    }

Review Comment:
   Isn't Java actually loading those classes without our extension needing to do anything?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
essobedo commented on PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#issuecomment-1372524702

   > I think we can remove the .class also in camel core for java-joor dsl as its not really needed anymore. I think (I am getting older so its maybe no longer there) there is an option in camel-main to configure a "compile directory" so removing would also need to remove that.
   
   The related ticket https://issues.apache.org/jira/browse/CAMEL-18864, I can do it asap
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
essobedo commented on PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#issuecomment-1372199399

   @ppalaga ok let's see the answer of @davsclaus and I will make the corresponding changes


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
essobedo commented on PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#issuecomment-1364584960

   Unless I miss something, the build failure is not related to those changes since the extension `java-joor-dsl` is part of the group 13 while the group 03 is failing


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] davsclaus commented on pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
davsclaus commented on PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#issuecomment-1372498183

   The .class is from https://issues.apache.org/jira/browse/CAMEL-18014 back at the time when camel-jbang and (indirectly also camel-k) could benefit from pre-loading java routes from .class that was compiled via java dsl (joor).
   
   However since we have less of that need as camel-jbang now exports to standard quarkus/SB and allow it to compile java dsl as regular java.
   
   The current Camel K however still has a limitation as all the DSL are runtime loaded and "compiled", also .java so there is a big cost to run java routes in camel-k as on startup. 
   
   Even if there is a special Camel Quarkus build-step then Camel K cannot benefit from that, as it bootup a "empty" Camel.
   
   I think we can remove the .class also in camel core for java-joor dsl as its not really needed anymore.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] ppalaga commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1059635057


##########
extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.quarkus.dsl.java.joor.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+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.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.maven.dependency.ResolvedDependency;
+import io.quarkus.paths.PathCollection;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.CamelContext;
+import org.apache.camel.dsl.java.joor.CompilationUnit;
+import org.apache.camel.dsl.java.joor.MultiCompile;
+import org.apache.camel.quarkus.core.deployment.main.CamelMainHelper;
+import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
+import org.apache.camel.quarkus.dsl.java.joor.runtime.JavaJoorDslRecorder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JavaJoorDslProcessor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JavaJoorDslProcessor.class);
+    private static final String FEATURE = "camel-java-joor-dsl";
+
+    private static final Pattern PACKAGE_PATTERN = Pattern.compile(
+            "^\\s*package\\s+([a-zA-Z][\\.\\w]*)\\s*;.*$", Pattern.MULTILINE);
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    void loadClassesAOT(BuildProducer<JavaJoorGeneratedClassBuildItem> generatedClass) throws Exception {
+        LOG.debug("Loading .class resources");
+        CamelMainHelper.forEachMatchingResource(
+                resource -> {
+                    if (!resource.getLocation().endsWith(".class")) {
+                        return;
+                    }
+                    try (InputStream is = resource.getInputStream()) {
+                        generatedClass
+                                .produce(new JavaJoorGeneratedClassBuildItem(asClassName(resource), resource.getLocation(),
+                                        is.readAllBytes()));
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+    }

Review Comment:
   Why would anybody want to pass .class files as resources? Is this also supported by plain Camel?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] ppalaga commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1059634543


##########
extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.quarkus.dsl.java.joor.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+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.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.maven.dependency.ResolvedDependency;
+import io.quarkus.paths.PathCollection;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.CamelContext;
+import org.apache.camel.dsl.java.joor.CompilationUnit;
+import org.apache.camel.dsl.java.joor.MultiCompile;
+import org.apache.camel.quarkus.core.deployment.main.CamelMainHelper;
+import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
+import org.apache.camel.quarkus.dsl.java.joor.runtime.JavaJoorDslRecorder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JavaJoorDslProcessor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JavaJoorDslProcessor.class);
+    private static final String FEATURE = "camel-java-joor-dsl";
+
+    private static final Pattern PACKAGE_PATTERN = Pattern.compile(
+            "^\\s*package\\s+([a-zA-Z][\\.\\w]*)\\s*;.*$", Pattern.MULTILINE);
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    void loadClassesAOT(BuildProducer<JavaJoorGeneratedClassBuildItem> generatedClass) throws Exception {
+        LOG.debug("Loading .class resources");
+        CamelMainHelper.forEachMatchingResource(
+                resource -> {
+                    if (!resource.getLocation().endsWith(".class")) {
+                        return;
+                    }
+                    try (InputStream is = resource.getInputStream()) {
+                        generatedClass
+                                .produce(new JavaJoorGeneratedClassBuildItem(asClassName(resource), resource.getLocation(),
+                                        is.readAllBytes()));
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    void compileClassesAOT(BuildProducer<JavaJoorGeneratedClassBuildItem> generatedClass,
+            CurateOutcomeBuildItem curateOutcomeBuildItem) throws Exception {
+        Map<String, Resource> nameToResource = new HashMap<>();
+        LOG.debug("Loading .java resources");
+        CompilationUnit unit = CompilationUnit.input();
+        CamelMainHelper.forEachMatchingResource(
+                resource -> {
+                    if (!resource.getLocation().endsWith(".java")) {
+                        return;
+                    }
+                    try (InputStream is = resource.getInputStream()) {
+                        String content = IOHelper.loadText(is);
+                        String name = determineName(resource, content);
+                        unit.addClass(name, content);
+                        nameToResource.put(name, resource);
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+        if (nameToResource.isEmpty()) {
+            return;
+        }
+        // Temporary workaround until being able to provide the classpath somehow to the method MultiCompile.compileUnit

Review Comment:
   Could you please paste an issue or PR URL here so that future readers know what is this blocked by?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
essobedo commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1062668894


##########
extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.quarkus.dsl.java.joor.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+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.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.maven.dependency.ResolvedDependency;
+import io.quarkus.paths.PathCollection;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.CamelContext;
+import org.apache.camel.dsl.java.joor.CompilationUnit;
+import org.apache.camel.dsl.java.joor.MultiCompile;
+import org.apache.camel.quarkus.core.deployment.main.CamelMainHelper;
+import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
+import org.apache.camel.quarkus.dsl.java.joor.runtime.JavaJoorDslRecorder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JavaJoorDslProcessor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JavaJoorDslProcessor.class);
+    private static final String FEATURE = "camel-java-joor-dsl";
+
+    private static final Pattern PACKAGE_PATTERN = Pattern.compile(
+            "^\\s*package\\s+([a-zA-Z][\\.\\w]*)\\s*;.*$", Pattern.MULTILINE);
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    void loadClassesAOT(BuildProducer<JavaJoorGeneratedClassBuildItem> generatedClass) throws Exception {
+        LOG.debug("Loading .class resources");
+        CamelMainHelper.forEachMatchingResource(
+                resource -> {
+                    if (!resource.getLocation().endsWith(".class")) {
+                        return;
+                    }
+                    try (InputStream is = resource.getInputStream()) {
+                        generatedClass
+                                .produce(new JavaJoorGeneratedClassBuildItem(asClassName(resource), resource.getLocation(),
+                                        is.readAllBytes()));
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+    }

Review Comment:
   I guess, I can remove the support of class files to keep it simple



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton merged pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
jamesnetherton merged PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] ppalaga commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1059629189


##########
integration-tests/foundation-grouped/pom.xml:
##########
@@ -96,12 +96,10 @@
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-log</artifactId>
         </dependency>
-        <!-- https://github.com/apache/camel-quarkus/issues/4225

Review Comment:
   camel-quarkus-microprofile-fault-tolerance should be kept out otherwise you'll keep getting the failure in foundation-grouped/pom.xml



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
essobedo commented on PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#issuecomment-1373394239

   As it is my first contribution to the project, I'm not really aware of the validation process, I assume that someone from the team will merge it once the process is complete. Let me know if it is not the case.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
essobedo commented on PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#issuecomment-1372519822

   @davsclaus thx for your answer
   
   > Even if there is a special Camel Quarkus build-step then Camel K cannot benefit from that, as it bootup a "empty" Camel.
   
   I know, I have already something working to make it possible at Camel-K level but first, I need it to be released and a new version of camel-k-runtime depending on this new version of camel-quarkus
   
   > 
   > I think we can remove the .class also in camel core for java-joor dsl as its not really needed anymore. I think (I am getting older so its maybe no longer there) there is an option in camel-main to configure a "compile directory" so removing would also need to remove that.
   
   I removed it from Camel Quarkus for now
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
essobedo commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1061520348


##########
extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.quarkus.dsl.java.joor.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+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.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.maven.dependency.ResolvedDependency;
+import io.quarkus.paths.PathCollection;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.CamelContext;
+import org.apache.camel.dsl.java.joor.CompilationUnit;
+import org.apache.camel.dsl.java.joor.MultiCompile;
+import org.apache.camel.quarkus.core.deployment.main.CamelMainHelper;
+import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
+import org.apache.camel.quarkus.dsl.java.joor.runtime.JavaJoorDslRecorder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JavaJoorDslProcessor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JavaJoorDslProcessor.class);
+    private static final String FEATURE = "camel-java-joor-dsl";
+
+    private static final Pattern PACKAGE_PATTERN = Pattern.compile(
+            "^\\s*package\\s+([a-zA-Z][\\.\\w]*)\\s*;.*$", Pattern.MULTILINE);
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    void loadClassesAOT(BuildProducer<JavaJoorGeneratedClassBuildItem> generatedClass) throws Exception {
+        LOG.debug("Loading .class resources");
+        CamelMainHelper.forEachMatchingResource(
+                resource -> {
+                    if (!resource.getLocation().endsWith(".class")) {
+                        return;
+                    }
+                    try (InputStream is = resource.getInputStream()) {
+                        generatedClass
+                                .produce(new JavaJoorGeneratedClassBuildItem(asClassName(resource), resource.getLocation(),
+                                        is.readAllBytes()));
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+    }

Review Comment:
   > Why would anybody want to pass .class files as resources? Is this also supported by plain Camel?
   
   Yes it also supported by Camel as you can see [here](https://github.com/apache/camel/blob/main/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/ClassRoutesBuilderLoader.java)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] ppalaga commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1062425385


##########
extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.quarkus.dsl.java.joor.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+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.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.maven.dependency.ResolvedDependency;
+import io.quarkus.paths.PathCollection;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.CamelContext;
+import org.apache.camel.dsl.java.joor.CompilationUnit;
+import org.apache.camel.dsl.java.joor.MultiCompile;
+import org.apache.camel.quarkus.core.deployment.main.CamelMainHelper;
+import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
+import org.apache.camel.quarkus.dsl.java.joor.runtime.JavaJoorDslRecorder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JavaJoorDslProcessor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JavaJoorDslProcessor.class);
+    private static final String FEATURE = "camel-java-joor-dsl";
+
+    private static final Pattern PACKAGE_PATTERN = Pattern.compile(
+            "^\\s*package\\s+([a-zA-Z][\\.\\w]*)\\s*;.*$", Pattern.MULTILINE);
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    void loadClassesAOT(BuildProducer<JavaJoorGeneratedClassBuildItem> generatedClass) throws Exception {
+        LOG.debug("Loading .class resources");
+        CamelMainHelper.forEachMatchingResource(
+                resource -> {
+                    if (!resource.getLocation().endsWith(".class")) {
+                        return;
+                    }
+                    try (InputStream is = resource.getInputStream()) {
+                        generatedClass
+                                .produce(new JavaJoorGeneratedClassBuildItem(asClassName(resource), resource.getLocation(),
+                                        is.readAllBytes()));
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+    }

Review Comment:
   Hm... https://issues.apache.org/jira/browse/CAMEL-18014 says 
   
   > When compiling with camel-java-dsl we can have it capture the compiled byte code, which allows us to write to disk, which we can make possible as a build step, that allows to load the routes from disk and avoid the compilation step at runtime.
   
   @davsclaus is that use case described somewhere in more details? I mean what is build time and runtime for Camel JBang? I mostly wonder why would the build time part need to pass the .class files as resources to the runtime? Why can't runtime simply pick those via stock java class path? Does this use case make any sense on Quarkus?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] ppalaga commented on pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
ppalaga commented on PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#issuecomment-1372169685

   Thanks @essobedo, the last open thing for me is the `.class` resource loading. IMO, we should either
   
   A. not support it at all (throw an exception if somebody tries to use it) or
   
   B. If the `.class` resource loading makes sense on Quarkus, then there should be a test covering it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] aldettinger commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
aldettinger commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1062457935


##########
extensions/java-joor-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/java/joor/runtime/JavaJoorDslRecorder.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+package org.apache.camel.quarkus.dsl.java.joor.runtime;
+
+import java.lang.reflect.Modifier;
+
+import io.quarkus.runtime.RuntimeValue;
+import io.quarkus.runtime.annotations.Recorder;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.ResourceAware;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.ObjectHelper;
+
+@Recorder
+public class JavaJoorDslRecorder {
+    public void registerRoutesBuilder(RuntimeValue<CamelContext> context, String className, String location) throws Exception {
+        Class<?> clazz = Class.forName(className);
+        boolean skip = clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())
+                || Modifier.isPrivate(clazz.getModifiers());
+        // must have a default no-arg constructor to be able to create an instance
+        boolean ctr = ObjectHelper.hasDefaultNoArgConstructor(clazz);
+        if (ctr && !skip) {
+            // create a new instance of the class
+            try {
+                Object obj = context.getValue().getInjector().newInstance(clazz);
+                if (obj instanceof RoutesBuilder) {
+                    // inject context and resource
+                    CamelContextAware.trySetCamelContext(obj, context.getValue());
+                    ResourceAware.trySetResource(obj, ResourceHelper.fromString(location, ""));
+                    context.getValue().addRoutes((RoutesBuilder) obj);
+                }
+            } catch (Exception e) {
+                throw new RuntimeCamelException("Cannot create instance of class: " + className, e);
+            }
+        }
+    }

Review Comment:
   Would there be value in logging/warning about non matched items ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] ppalaga commented on pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
ppalaga commented on PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#issuecomment-1368209404

   @essobedo very nice! I have left some minor questions and comments inline.
   
   In addition to that, I'd vote for 
   
   * Removing the dependency on quarkus-resteasy-jsonb in the test. We generally prefer a minimal set of dependencies in integration tests to avoid the risk that the additional dependency fixes some native issue in the test, but otherwise the extension under test would not work without it. We have seen this happening with quarkus-resteasy-jackson, maybe it would not happen with quarkus-resteasy-jsonb, but anyway, it is easy to do without by splitting to context lookups into multiple REST endpoints as I tried to implement here: https://github.com/ppalaga/camel-quarkus/commit/ef0361fe28c261c5d621fc2ab07433c58a4aa7a3#diff-050e5976f7d86cda20a440f5326cc7fd3f6dbe5ae9f52700c53329a4da1033f7R46-R73
   * Adding a test that checks that the jOOR route really works - something like this: https://github.com/ppalaga/camel-quarkus/commit/ef0361fe28c261c5d621fc2ab07433c58a4aa7a3#diff-050e5976f7d86cda20a440f5326cc7fd3f6dbe5ae9f52700c53329a4da1033f7R75-R81
   
   If you like the above proposal feel free to amend the commit https://github.com/ppalaga/camel-quarkus/commit/ef0361fe28c261c5d621fc2ab07433c58a4aa7a3 to this PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
essobedo commented on PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#issuecomment-1370999213

   @ppalaga Thx peter for the help and remarks. I added you as co-author if it is fine with you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
essobedo commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1062709601


##########
extensions/java-joor-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/java/joor/runtime/JavaJoorDslRecorder.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+package org.apache.camel.quarkus.dsl.java.joor.runtime;
+
+import java.lang.reflect.Modifier;
+
+import io.quarkus.runtime.RuntimeValue;
+import io.quarkus.runtime.annotations.Recorder;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.ResourceAware;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.ObjectHelper;
+
+@Recorder
+public class JavaJoorDslRecorder {
+    public void registerRoutesBuilder(RuntimeValue<CamelContext> context, String className, String location) throws Exception {
+        Class<?> clazz = Class.forName(className);
+        boolean skip = clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())
+                || Modifier.isPrivate(clazz.getModifiers());
+        // must have a default no-arg constructor to be able to create an instance
+        boolean ctr = ObjectHelper.hasDefaultNoArgConstructor(clazz);
+        if (ctr && !skip) {
+            // create a new instance of the class
+            try {
+                Object obj = context.getValue().getInjector().newInstance(clazz);
+                if (obj instanceof RoutesBuilder) {
+                    // inject context and resource
+                    CamelContextAware.trySetCamelContext(obj, context.getValue());
+                    ResourceAware.trySetResource(obj, ResourceHelper.fromString(location, ""));
+                    context.getValue().addRoutes((RoutesBuilder) obj);
+                }
+            } catch (Exception e) {
+                throw new RuntimeCamelException("Cannot create instance of class: " + className, e);
+            }
+        }
+    }

Review Comment:
   Done, thx for the feedback



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] essobedo commented on a diff in pull request #4359: Ref #4358: Java jOOR DSL native support

Posted by GitBox <gi...@apache.org>.
essobedo commented on code in PR #4359:
URL: https://github.com/apache/camel-quarkus/pull/4359#discussion_r1062710135


##########
extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.quarkus.dsl.java.joor.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+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.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.maven.dependency.ResolvedDependency;
+import io.quarkus.paths.PathCollection;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.CamelContext;
+import org.apache.camel.dsl.java.joor.CompilationUnit;
+import org.apache.camel.dsl.java.joor.MultiCompile;
+import org.apache.camel.quarkus.core.deployment.main.CamelMainHelper;
+import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
+import org.apache.camel.quarkus.dsl.java.joor.runtime.JavaJoorDslRecorder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JavaJoorDslProcessor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JavaJoorDslProcessor.class);
+    private static final String FEATURE = "camel-java-joor-dsl";
+
+    private static final Pattern PACKAGE_PATTERN = Pattern.compile(
+            "^\\s*package\\s+([a-zA-Z][\\.\\w]*)\\s*;.*$", Pattern.MULTILINE);
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    void loadClassesAOT(BuildProducer<JavaJoorGeneratedClassBuildItem> generatedClass) throws Exception {
+        LOG.debug("Loading .class resources");
+        CamelMainHelper.forEachMatchingResource(
+                resource -> {
+                    if (!resource.getLocation().endsWith(".class")) {
+                        return;
+                    }
+                    try (InputStream is = resource.getInputStream()) {
+                        generatedClass
+                                .produce(new JavaJoorGeneratedClassBuildItem(asClassName(resource), resource.getLocation(),
+                                        is.readAllBytes()));
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+    }

Review Comment:
   class files support removed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org