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 2024/03/13 16:29:04 UTC

(camel) 02/06: CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test

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

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

commit 32c683b0284de9057eeedf6330b1f68fd7d5e2ac
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 13 15:46:46 2024 +0100

    CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
---
 .../dsl/jbang/core/commands/ExportBaseCommand.java | 29 ++++++++++++++++++++
 .../dsl/jbang/core/commands/ExportCamelMain.java   | 32 ----------------------
 .../dsl/jbang/core/commands/ExportSpringBoot.java  |  2 ++
 3 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java
index c6c97e189d3..d7463f2977a 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java
@@ -858,6 +858,35 @@ abstract class ExportBaseCommand extends CamelCommand {
         }
     }
 
+    protected void copyApplicationPropertiesFiles(File srcResourcesDir) throws Exception {
+        File[] files = new File(".").listFiles(f -> {
+            if (!f.isFile()) {
+                return false;
+            }
+            String ext = FileUtil.onlyExt(f.getName());
+            String name = FileUtil.onlyName(f.getName());
+            if (!"properties".equals(ext)) {
+                return false;
+            }
+            if (name.equals("application")) {
+                // skip generic as its handled specially
+                return false;
+            }
+            if (profile == null) {
+                // accept all kind of configuration files
+                return name.startsWith("application");
+            } else {
+                // only accept the configuration file that matches the profile
+                return name.equals("application-" + profile);
+            }
+        });
+        if (files != null) {
+            for (File f : files) {
+                safeCopy(f, new File(srcResourcesDir, f.getName()), true);
+            }
+        }
+    }
+
     private MavenDownloader getDownloader() {
         if (downloader == null) {
             init();
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
index d632644ef34..6e5fdd58e10 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
@@ -17,7 +17,6 @@
 package org.apache.camel.dsl.jbang.core.commands;
 
 import java.io.File;
-import java.io.FileFilter;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -101,7 +100,6 @@ class ExportCamelMain extends Export {
         File srcKameletsResourcesDir = new File(BUILD_DIR, "src/main/resources/kamelets");
         srcKameletsResourcesDir.mkdirs();
         // copy application properties files
-        // TODO: spring boot
         copyApplicationPropertiesFiles(srcResourcesDir);
         // copy source files
         copySourceFiles(settings, profile, srcJavaDirRoot, srcJavaDir, srcResourcesDir, srcCamelResourcesDir,
@@ -155,35 +153,6 @@ class ExportCamelMain extends Export {
         return 0;
     }
 
-    protected void copyApplicationPropertiesFiles(File srcResourcesDir) throws Exception {
-        File[] files = new File(".").listFiles(f -> {
-            if (!f.isFile()) {
-                return false;
-            }
-            String ext = FileUtil.onlyExt(f.getName());
-            String name = FileUtil.onlyName(f.getName());
-            if (!"properties".equals(ext)) {
-                return false;
-            }
-            if (name.equals("application")) {
-                // skip generic as its handled specially
-                return false;
-            }
-            if (profile == null) {
-                // accept all kind of configuration files
-                return name.startsWith("application");
-            } else {
-                // only accept the configuration file that matches the profile
-                return name.equals("application-" + profile);
-            }
-        });
-        if (files != null) {
-            for (File f : files) {
-                safeCopy(f, new File(srcResourcesDir, f.getName()), true);
-            }
-        }
-    }
-
     private void createMavenPom(File settings, File profile, File pom, Set<String> deps, String packageName) throws Exception {
         String[] ids = gav.split(":");
 
@@ -363,7 +332,6 @@ class ExportCamelMain extends Export {
         IOHelper.writeText(context, new FileOutputStream(srcJavaDir + "/" + mainClassname + ".java", false));
     }
 
-
     @Override
     protected void copySourceFiles(
             File settings, File profile, File srcJavaDirRoot, File srcJavaDir, File srcResourcesDir, File srcCamelResourcesDir,
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 694cbdfee6b..ce80383e76c 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
@@ -102,6 +102,8 @@ class ExportSpringBoot extends Export {
         srcCamelResourcesDir.mkdirs();
         File srcKameletsResourcesDir = new File(BUILD_DIR, "src/main/resources/kamelets");
         srcKameletsResourcesDir.mkdirs();
+        // copy application properties files
+        copyApplicationPropertiesFiles(srcResourcesDir);
         // copy source files
         copySourceFiles(settings, profile, srcJavaDirRoot, srcJavaDir, srcResourcesDir, srcCamelResourcesDir,
                 srcKameletsResourcesDir, srcPackageName);