ppalaga commented on a change in pull request #2549:
URL: https://github.com/apache/camel-quarkus/pull/2549#discussion_r625665694



##########
File path: 
extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletProcessor.java
##########
@@ -16,15 +16,91 @@
  */
 package org.apache.camel.quarkus.component.kamelet.deployment;
 
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
 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 org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.dsl.yaml.YamlRoutesBuilderLoader;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.RouteTemplateDefinition;
+import org.apache.camel.quarkus.component.kamelet.KameletConfiguration;
+import org.apache.camel.quarkus.component.kamelet.KameletRecorder;
+import 
org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.ResourceHelper;
 
 class KameletProcessor {
-
+    private static final String KAMELET_LOCATION = "/camel/kamelets";
     private static final String FEATURE = "camel-kamelet";
 
     @BuildStep
     FeatureBuildItem feature() {
         return new FeatureBuildItem(FEATURE);
     }
+
+    @Record(ExecutionTime.STATIC_INIT)
+    @BuildStep
+    CamelContextCustomizerBuildItem configureTemplates(
+            KameletConfiguration configuration,
+            KameletRecorder recorder) throws Exception {
+
+        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+        List<RouteTemplateDefinition> definitions = new ArrayList<>();
+
+        try (YamlRoutesBuilderLoader ybl = new YamlRoutesBuilderLoader()) {
+            ybl.setCamelContext(new DefaultCamelContext());
+            ybl.start();
+
+            for (String kamelet : 
configuration.kamelets.orElse(Collections.emptyList())) {
+                final String path = KAMELET_LOCATION + "/" + kamelet + ".yaml";
+
+                try (InputStream is = 
KameletProcessor.class.getResourceAsStream(path)) {

Review comment:
       I think using TCCL is the safest option to load classes and resources 
after the split of class loaders in Quarkus 2.0

##########
File path: 
extensions/kamelet/runtime/src/main/java/org/apache/camel/quarkus/component/kamelet/KameletConfiguration.java
##########
@@ -0,0 +1,33 @@
+/*
+ * 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.component.kamelet;
+
+import java.util.List;
+import java.util.Optional;
+
+import io.quarkus.runtime.annotations.ConfigItem;
+import io.quarkus.runtime.annotations.ConfigPhase;
+import io.quarkus.runtime.annotations.ConfigRoot;
+
+@ConfigRoot(name = "camel.kamelet", phase = ConfigPhase.BUILD_TIME)
+public class KameletConfiguration {
+    /**
+     * List of kamelets.

Review comment:
       I guess we should be more descriptive here. Something like the following 
(not sure all is correct):
   
   ```suggestion
        * List of resource paths containing Kamelet definitions in YAML format 
   ```
   




-- 
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.

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


Reply via email to