You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/06/01 13:45:01 UTC

[camel] branch main updated: CAMEL-18151: camel-jbang - Export command for spring boot

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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 996b2460889 CAMEL-18151: camel-jbang - Export command for spring boot
996b2460889 is described below

commit 996b246088993438a05f3bd1d7210cd18d9809d0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Jun 1 15:44:45 2022 +0200

    CAMEL-18151: camel-jbang - Export command for spring boot
---
 .../dsl/jbang/core/commands/ExportSpringBoot.java  | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportSpringBoot.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportSpringBoot.java
index f9b03f6d8a1..f62043e11d3 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportSpringBoot.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportSpringBoot.java
@@ -119,7 +119,9 @@ class ExportSpringBoot extends CamelCommand {
         srcJavaDir.mkdirs();
         File srcResourcesDir = new File(BUILD_DIR, "src/main/resources");
         srcResourcesDir.mkdirs();
-        copySourceFiles(settings, srcJavaDir, srcResourcesDir, packageName);
+        File srcCamelResourcesDir = new File(BUILD_DIR, "src/main/resources/camel");
+        srcCamelResourcesDir.mkdirs();
+        copySourceFiles(settings, srcJavaDir, srcResourcesDir, srcCamelResourcesDir, packageName);
         // copy from settings to profile
         copySettingsAndProfile(settings, profile, srcResourcesDir);
         // create main class
@@ -226,7 +228,9 @@ class ExportSpringBoot extends CamelCommand {
         return code;
     }
 
-    private void copySourceFiles(File settings, File srcJavaDir, File srcResourcesDir, String packageName) throws Exception {
+    private void copySourceFiles(
+            File settings, File srcJavaDir, File srcResourcesDir, File srcCamelResourcesDir, String packageName)
+            throws Exception {
         // read the settings file and find the files to copy
         OrderedProperties prop = new OrderedProperties();
         prop.load(new FileInputStream(settings));
@@ -241,7 +245,8 @@ class ExportSpringBoot extends CamelCommand {
                     }
                     String ext = FileUtil.onlyExt(f, true);
                     boolean java = "java".equals(ext);
-                    File target = java ? srcJavaDir : srcResourcesDir;
+                    boolean camel = "camel.main.routesIncludePattern".equals(k) || "camel.component.kamelet.location".equals(k);
+                    File target = java ? srcJavaDir : camel ? srcCamelResourcesDir : srcResourcesDir;
                     File source = new File(f);
                     File out = new File(target, source.getName());
                     safeCopy(source, out, true);
@@ -302,13 +307,16 @@ class ExportSpringBoot extends CamelCommand {
             v = v.replaceAll("file:", "classpath:");
             if ("camel.springboot.routesIncludePattern".equals(k)) {
                 // camel.main.routesIncludePattern should remove all .java as we use spring boot to load them
+                // camel.main.routesIncludePattern should remove all file: classpath: as we copy them to src/main/resources/camel where camel auto-load from
                 v = Arrays.stream(v.split(","))
-                        .filter(n -> !n.endsWith(".java"))
+                        .filter(n -> !n.endsWith(".java") && !n.startsWith("file:") && !n.startsWith("classpath:"))
                         .collect(Collectors.joining(","));
             }
-            String line = k + "=" + v;
-            fos.write(line.getBytes(StandardCharsets.UTF_8));
-            fos.write("\n".getBytes(StandardCharsets.UTF_8));
+            if (!v.isBlank()) {
+                String line = k + "=" + v;
+                fos.write(line.getBytes(StandardCharsets.UTF_8));
+                fos.write("\n".getBytes(StandardCharsets.UTF_8));
+            }
         }
         IOHelper.close(fos);
     }