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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to