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:02 UTC

(camel) branch main-profile created (now 5972fe23e7f)

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

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


      at 5972fe23e7f CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test

This branch includes the following new commits:

     new 5a14e5ab3d6 CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
     new 32c683b0284 CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
     new 35f691c231b CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
     new 6d32de13a23 CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
     new dedea474ab9 CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
     new 5972fe23e7f CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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

Posted by da...@apache.org.
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 dedea474ab9b64a857760448254453bb0ae7055d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 13 17:00:25 2024 +0100

    CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
---
 docs/user-manual/modules/ROOT/pages/camel-maven-plugin.adoc            | 2 ++
 tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc | 1 +
 .../src/main/java/org/apache/camel/maven/DevMojo.java                  | 3 ++-
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-maven-plugin.adoc b/docs/user-manual/modules/ROOT/pages/camel-maven-plugin.adoc
index a2b0ab8fa7b..0c0284b0d0c 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-maven-plugin.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-maven-plugin.adoc
@@ -36,6 +36,7 @@ The maven plugin *run* goal supports the following options which can be configur
 | durationMaxMessages | -1 | Sets the duration of maximum number of messages that the application will process before terminating.
 | logClasspath | false | Whether to log the classpath when starting
 | loggingLevel | OFF | Whether to use built-in console logging (uses log4j), which does not require to add any logging dependency to your project. However, the logging is fixed to log to the console, with a color style that is similar to Spring Boot. You can change the root logging level to: FATAL, ERROR, WARN, INFO, DEBUG, TRACE, OFF
+| profile |  | To run with a specific Camel Main profile (dev,test,prod)
 |===
 
 
@@ -96,6 +97,7 @@ The maven plugin *dev* goal supports the following options which can be configur
 | durationMaxMessages | -1 | Sets the duration of maximum number of messages that the application will process before terminating.
 | logClasspath | false | Whether to log the classpath when starting
 | loggingLevel | OFF | Whether to use built-in console logging (uses log4j), which does not require to add any logging dependency to your project. However, the logging is fixed to log to the console, with a color style that is similar to Spring Boot. You can change the root logging level to: FATAL, ERROR, WARN, INFO, DEBUG, TRACE, OFF
+| profile | dev | To run with a specific Camel Main profile (dev,test,prod)
 |===
 
 == camel:debug
diff --git a/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc b/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc
index 07692fd818d..0c0284b0d0c 100644
--- a/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc
+++ b/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc
@@ -97,6 +97,7 @@ The maven plugin *dev* goal supports the following options which can be configur
 | durationMaxMessages | -1 | Sets the duration of maximum number of messages that the application will process before terminating.
 | logClasspath | false | Whether to log the classpath when starting
 | loggingLevel | OFF | Whether to use built-in console logging (uses log4j), which does not require to add any logging dependency to your project. However, the logging is fixed to log to the console, with a color style that is similar to Spring Boot. You can change the root logging level to: FATAL, ERROR, WARN, INFO, DEBUG, TRACE, OFF
+| profile | dev | To run with a specific Camel Main profile (dev,test,prod)
 |===
 
 == camel:debug
diff --git a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java
index 6d05ad46631..82d1dd18d65 100644
--- a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java
+++ b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java
@@ -50,7 +50,8 @@ public class DevMojo extends RunMojo {
         // use absolute path for dir
         dir = new File(dir).getAbsolutePath();
 
-        System.setProperty("camel.main.profile", "dev");
+        // use dev profile by default
+        System.setProperty("camel.main.profile", profile == null ? "dev" : profile);
         System.setProperty("camel.main.routesReloadEnabled", "true");
         System.setProperty("camel.main.routesReloadDirectory", dir);
         System.setProperty("camel.main.routesReloadDirectoryRecursive", "true");


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

Posted by da...@apache.org.
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 5972fe23e7fe9fddace9133160749c48b46e7dd0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 13 17:25:59 2024 +0100

    CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
---
 .../src/main/java/org/apache/camel/main/BaseMainSupport.java  | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 52065f24cde..da315a53a79 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -363,9 +363,20 @@ public abstract class BaseMainSupport extends BaseService {
         if (pc.getLocations().isEmpty()) {
             String locations = propertyPlaceholderLocations;
             if (locations == null) {
+                // ENV/SYS takes precedence, then java configured value
                 String profile = MainHelper.lookupPropertyFromSysOrEnv(MainConstants.PROFILE)
                         .orElse(mainConfigurationProperties.getProfile());
+                if (profile == null) {
+                    // fallback to check if application.properties has a profile
+                    Properties prop = new Properties();
+                    try (InputStream is
+                            = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, "application.properties")) {
+                        prop.load(is);
+                    }
+                    profile = prop.getProperty("camel.main.profile");
+                }
                 if (profile != null) {
+                    mainConfigurationProperties.setProfile(profile);
                     String loc = profilePropertyPlaceholderLocation(profile);
                     defaultPropertyPlaceholderLocation = loc + "," + defaultPropertyPlaceholderLocation;
                 }


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

Posted by da...@apache.org.
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 35f691c231ba4a913a39d76db7a519e168f1054d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 13 15:54:46 2024 +0100

    CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
---
 docs/user-manual/modules/ROOT/pages/camel-jbang.adoc | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index fb287b02931..9031ef4a580 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -547,6 +547,14 @@ However, you may want to run Camel JBang in a more production like situation, wh
 camel run hello.java --profile=prod
 ----
 
+You can have profile specific configuration in configuration files using the naming style `application-<profile>.properties`,
+such as in the following:
+
+- `application.properties` - Common configuration that is always in use (default).
+- `application-dev.properties` - Developer specific configuration for  the `dev` profile.
+- `application-prod.properties` - Developer specific configuration for  the `prod` profile.
+
+The profile specific configuration will override values in the common configuration.
 
 === Downloading JARs over the internet
 
@@ -3112,6 +3120,8 @@ camel export --runtime=quarkus --gav=com.foo:acme:1.0-SNAPSHOT --directory=../my
 
 TIP: See the possible options by running: `camel export --help` for more details.
 
+NOTE: You cannot use `--profile` option when exporting to Camel Quarkus.
+
 === Exporting to Camel Main
 
 The command `export --runtime=camel-main` will export your current Camel JBang file(s) to a Maven based


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

Posted by da...@apache.org.
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 5a14e5ab3d6b47c34a9aa4e47bcc9fd055e47e51
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 13 15:38:23 2024 +0100

    CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
---
 .../properties/ClasspathPropertiesSource.java      |  9 ++-
 .../component/properties/FilePropertiesSource.java |  9 ++-
 .../component/properties/PropertiesComponent.java  | 14 ++--
 .../component/properties/RefPropertiesSource.java  | 15 +++-
 .../org/apache/camel/main/BaseMainSupport.java     | 13 +++-
 .../apache/camel/main/MainCommandLineSupport.java  |  7 ++
 .../java/org/apache/camel/main/MainConstants.java  |  5 ++
 .../org/apache/camel/main/ProfileConfigurer.java   |  6 +-
 .../camel/dsl/jbang/core/commands/Export.java      | 63 ++++++++--------
 .../dsl/jbang/core/commands/ExportBaseCommand.java |  4 +
 .../dsl/jbang/core/commands/ExportCamelMain.java   | 34 +++++++++
 .../apache/camel/dsl/jbang/core/commands/Run.java  | 86 +++++++++++++++-------
 12 files changed, 199 insertions(+), 66 deletions(-)

diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/ClasspathPropertiesSource.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/ClasspathPropertiesSource.java
index 264628995c3..d897f61135d 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/ClasspathPropertiesSource.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/ClasspathPropertiesSource.java
@@ -31,8 +31,15 @@ import org.apache.camel.util.OrderedProperties;
 
 public class ClasspathPropertiesSource extends AbstractLocationPropertiesSource implements Ordered {
 
+    private final int order;
+
     public ClasspathPropertiesSource(PropertiesComponent propertiesComponent, PropertiesLocation location) {
+        this(propertiesComponent, location, 400);
+    }
+
+    public ClasspathPropertiesSource(PropertiesComponent propertiesComponent, PropertiesLocation location, int order) {
         super(propertiesComponent, location);
+        this.order = order;
     }
 
     @Override
@@ -71,6 +78,6 @@ public class ClasspathPropertiesSource extends AbstractLocationPropertiesSource
 
     @Override
     public int getOrder() {
-        return 300;
+        return order;
     }
 }
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/FilePropertiesSource.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/FilePropertiesSource.java
index 88cc980c2d9..3fb197cfb2a 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/FilePropertiesSource.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/FilePropertiesSource.java
@@ -32,8 +32,15 @@ import org.apache.camel.util.OrderedProperties;
 
 public class FilePropertiesSource extends AbstractLocationPropertiesSource implements Ordered {
 
+    private final int order;
+
     protected FilePropertiesSource(PropertiesComponent propertiesComponent, PropertiesLocation location) {
+        this(propertiesComponent, location, 300);
+    }
+
+    protected FilePropertiesSource(PropertiesComponent propertiesComponent, PropertiesLocation location, int order) {
         super(propertiesComponent, location);
+        this.order = order;
     }
 
     @Override
@@ -69,6 +76,6 @@ public class FilePropertiesSource extends AbstractLocationPropertiesSource imple
 
     @Override
     public int getOrder() {
-        return 100;
+        return order;
     }
 }
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 4a13c4e0e4a..d7acf6218b9 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -353,8 +353,10 @@ public class PropertiesComponent extends ServiceSupport
 
         // we need to re-create the property sources which may have already been created from locations
         this.sources.removeIf(s -> s instanceof LocationPropertiesSource);
+        // ensure order we want as given in the locations
+        int order = 100;
         for (PropertiesLocation loc : locations) {
-            addPropertiesLocationsAsPropertiesSource(loc);
+            addPropertiesLocationsAsPropertiesSource(loc, order++);
         }
     }
 
@@ -386,6 +388,8 @@ public class PropertiesComponent extends ServiceSupport
     public void addLocation(String location) {
         if (location != null) {
             List<PropertiesLocation> newLocations = new ArrayList<>();
+            // add in reverse order as
+
             for (String loc : location.split(",")) {
                 newLocations.add(new PropertiesLocation(loc));
             }
@@ -793,13 +797,13 @@ public class PropertiesComponent extends ServiceSupport
         ServiceHelper.stopAndShutdownServices(sources, propertiesFunctionResolver);
     }
 
-    private void addPropertiesLocationsAsPropertiesSource(PropertiesLocation location) {
+    private void addPropertiesLocationsAsPropertiesSource(PropertiesLocation location, int order) {
         if ("ref".equals(location.getResolver())) {
-            addPropertiesSource(new RefPropertiesSource(this, location));
+            addPropertiesSource(new RefPropertiesSource(this, location, order));
         } else if ("file".equals(location.getResolver())) {
-            addPropertiesSource(new FilePropertiesSource(this, location));
+            addPropertiesSource(new FilePropertiesSource(this, location, order));
         } else if ("classpath".equals(location.getResolver())) {
-            addPropertiesSource(new ClasspathPropertiesSource(this, location));
+            addPropertiesSource(new ClasspathPropertiesSource(this, location, order));
         }
     }
 
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java
index 7b199e5cdc2..4eb90dcc5da 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java
@@ -20,17 +20,24 @@ import java.io.FileNotFoundException;
 import java.util.Map;
 import java.util.Properties;
 
+import org.apache.camel.Ordered;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.util.OrderedProperties;
 
-public class RefPropertiesSource implements LocationPropertiesSource {
+public class RefPropertiesSource implements LocationPropertiesSource, Ordered {
 
+    private final int order;
     private final PropertiesComponent propertiesComponent;
     private final PropertiesLocation location;
 
     public RefPropertiesSource(PropertiesComponent propertiesComponent, PropertiesLocation location) {
+        this(propertiesComponent, location, 200);
+    }
+
+    public RefPropertiesSource(PropertiesComponent propertiesComponent, PropertiesLocation location, int order) {
         this.propertiesComponent = propertiesComponent;
         this.location = location;
+        this.order = order;
     }
 
     @Override
@@ -71,4 +78,10 @@ public class RefPropertiesSource implements LocationPropertiesSource {
 
         return answer;
     }
+
+    @Override
+    public int getOrder() {
+        return order;
+    }
+
 }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 84c41283ba9..52065f24cde 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -102,6 +102,7 @@ import org.apache.camel.vault.VaultConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.main.MainConstants.profilePropertyPlaceholderLocation;
 import static org.apache.camel.main.MainHelper.computeProperties;
 import static org.apache.camel.main.MainHelper.optionKey;
 import static org.apache.camel.main.MainHelper.setPropertiesOnTarget;
@@ -362,6 +363,12 @@ public abstract class BaseMainSupport extends BaseService {
         if (pc.getLocations().isEmpty()) {
             String locations = propertyPlaceholderLocations;
             if (locations == null) {
+                String profile = MainHelper.lookupPropertyFromSysOrEnv(MainConstants.PROFILE)
+                        .orElse(mainConfigurationProperties.getProfile());
+                if (profile != null) {
+                    String loc = profilePropertyPlaceholderLocation(profile);
+                    defaultPropertyPlaceholderLocation = loc + "," + defaultPropertyPlaceholderLocation;
+                }
                 locations
                         = MainHelper.lookupPropertyFromSysOrEnv(MainConstants.PROPERTY_PLACEHOLDER_LOCATION)
                                 .orElse(defaultPropertyPlaceholderLocation);
@@ -371,11 +378,11 @@ public abstract class BaseMainSupport extends BaseService {
             }
             if (!Objects.equals(locations, "false")) {
                 pc.addLocation(locations);
-                if (MainConstants.DEFAULT_PROPERTY_PLACEHOLDER_LOCATION.equals(locations)) {
-                    LOG.debug("Using properties from: {}", locations);
+                if (defaultPropertyPlaceholderLocation.equals(locations)) {
+                    LOG.debug("Properties location: {}", locations);
                 } else {
                     // if not default location then log at INFO
-                    LOG.info("Using properties from: {}", locations);
+                    LOG.info("Properties location: {}", locations);
                 }
             }
         }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainCommandLineSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/MainCommandLineSupport.java
index caa145f5a89..7e1322d7dc0 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainCommandLineSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainCommandLineSupport.java
@@ -233,6 +233,13 @@ public abstract class MainCommandLineSupport extends MainSupport {
 
     @Override
     protected void configurePropertiesService(CamelContext camelContext) throws Exception {
+        if (mainConfigurationProperties.getProfile() != null) {
+            // setup property placeholder location to include the profile based properties file also
+            defaultPropertyPlaceholderLocation
+                    = String.format("classpath:application-%s.properties;optional=true," + defaultPropertyPlaceholderLocation,
+                            mainConfigurationProperties.getProfile());
+        }
+
         super.configurePropertiesService(camelContext);
 
         PropertiesComponent pc = camelContext.getPropertiesComponent();
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java b/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java
index 808722a3aa4..2a0302161e5 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java
@@ -23,8 +23,13 @@ public final class MainConstants {
     public static final String OVERRIDE_PROPERTIES_LOCATION = "camel.main.override-properties-location";
     public static final String PROPERTY_PLACEHOLDER_LOCATION = "camel.main.property-placeholder-location";
     public static final String PLATFORM_HTTP_SERVER = "platform-http-server";
+    public static final String PROFILE = "camel.main.profile";
 
     private MainConstants() {
     }
 
+    static String profilePropertyPlaceholderLocation(String profile) {
+        return "classpath:application-" + profile + ".properties;optional=true";
+    }
+
 }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/ProfileConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/ProfileConfigurer.java
index 83ce2603e0f..8af6a99701e 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/ProfileConfigurer.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/ProfileConfigurer.java
@@ -32,7 +32,11 @@ public class ProfileConfigurer {
 
     public static void configure(CamelContext camelContext, String profile, MainConfigurationProperties config)
             throws Exception {
-        if (profile == null || "prod".equals(profile)) {
+        if (profile == null) {
+            // no profile is active
+            return;
+        }
+        if ("prod".equals(profile)) {
             LOG.info("The application is starting with profile: production");
             return; // no need to do special configuration
         }
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java
index ae6ef2ff17b..650de02b114 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java
@@ -35,17 +35,41 @@ public class Export extends ExportBaseCommand {
 
     @Override
     protected Integer export() throws Exception {
-        File profile = new File("application.properties");
-        if (profile.exists()) {
+        // application.properties
+        doLoadAndInitProfileProperties(new File("application.properties"));
+        if (profile != null) {
+            // override from profile specific configuration
+            doLoadAndInitProfileProperties(new File("application-" + profile + ".properties"));
+        }
+
+        if (runtime == null) {
+            System.err.println("The runtime option must be specified");
+            return 1;
+        }
+        if (gav == null) {
+            System.err.println("The gav option must be specified");
+            return 1;
+        }
+
+        if ("spring-boot".equals(runtime) || "camel-spring-boot".equals(runtime)) {
+            return export(new ExportSpringBoot(getMain()));
+        } else if ("quarkus".equals(runtime) || "camel-quarkus".equals(runtime)) {
+            return export(new ExportQuarkus(getMain()));
+        } else if ("main".equals(runtime) || "camel-main".equals(runtime)) {
+            return export(new ExportCamelMain(getMain()));
+        } else {
+            System.err.println("Unknown runtime: " + runtime);
+            return 1;
+        }
+    }
+
+    private void doLoadAndInitProfileProperties(File file) throws Exception {
+        if (file.exists()) {
             Properties prop = new CamelCaseOrderedProperties();
-            RuntimeUtil.loadProperties(prop, profile);
+            RuntimeUtil.loadProperties(prop, file);
             // read runtime and gav from profile if not configured
-            if (this.runtime == null) {
-                this.runtime = prop.getProperty("camel.jbang.runtime");
-            }
-            if (this.gav == null) {
-                this.gav = prop.getProperty("camel.jbang.gav");
-            }
+            this.runtime = prop.getProperty("camel.jbang.runtime", this.runtime);
+            this.gav = prop.getProperty("camel.jbang.gav", this.gav);
             // allow configuring versions from profile
             this.javaVersion = prop.getProperty("camel.jbang.javaVersion", this.javaVersion);
             this.camelVersion = prop.getProperty("camel.jbang.camelVersion", this.camelVersion);
@@ -72,26 +96,6 @@ public class Export extends ExportBaseCommand {
                     mavenApacheSnapshotEnabled ? "true" : "false"));
             this.exclude = prop.getProperty("camel.jbang.exclude", this.exclude);
         }
-
-        if (runtime == null) {
-            System.err.println("The runtime option must be specified");
-            return 1;
-        }
-        if (gav == null) {
-            System.err.println("The gav option must be specified");
-            return 1;
-        }
-
-        if ("spring-boot".equals(runtime) || "camel-spring-boot".equals(runtime)) {
-            return export(new ExportSpringBoot(getMain()));
-        } else if ("quarkus".equals(runtime) || "camel-quarkus".equals(runtime)) {
-            return export(new ExportQuarkus(getMain()));
-        } else if ("main".equals(runtime) || "camel-main".equals(runtime)) {
-            return export(new ExportCamelMain(getMain()));
-        } else {
-            System.err.println("Unknown runtime: " + runtime);
-            return 1;
-        }
     }
 
     protected Integer export(ExportBaseCommand cmd) throws Exception {
@@ -111,6 +115,7 @@ public class Export extends ExportBaseCommand {
         cmd.javaVersion = this.javaVersion;
         cmd.camelVersion = this.camelVersion;
         cmd.kameletsVersion = this.kameletsVersion;
+        cmd.profile = this.profile;
         cmd.localKameletDir = this.localKameletDir;
         cmd.logging = this.logging;
         cmd.loggingLevel = this.loggingLevel;
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 de639ddf831..c6c97e189d3 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
@@ -139,6 +139,10 @@ abstract class ExportBaseCommand extends CamelCommand {
             "--kamelets-version" }, description = "Apache Camel Kamelets version")
     protected String kameletsVersion;
 
+    @CommandLine.Option(names = { "--profile" }, scope = CommandLine.ScopeType.INHERIT,
+                        description = "Profile to export (dev, test, or prod).")
+    String profile;
+
     @CommandLine.Option(names = { "--local-kamelet-dir" },
                         description = "Local directory for loading Kamelets (takes precedence)")
     protected String localKameletDir;
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 1c6753fde44..d632644ef34 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,6 +17,7 @@
 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;
@@ -99,6 +100,9 @@ class ExportCamelMain extends Export {
         srcCamelResourcesDir.mkdirs();
         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,
                 srcKameletsResourcesDir, srcPackageName);
@@ -151,6 +155,35 @@ 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(":");
 
@@ -330,6 +363,7 @@ 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/Run.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index f380ede69ad..a6b42b06273 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -503,9 +503,6 @@ public class Run extends CamelCommand {
         writeSetting(main, profileProperties, "camel.jbang.metrics", metrics ? "true" : "false");
         writeSetting(main, profileProperties, "camel.jbang.console", console ? "true" : "false");
         writeSetting(main, profileProperties, "camel.jbang.verbose", verbose ? "true" : "false");
-        if ("dev".equals(profile)) {
-            writeSetting(main, profileProperties, "camel.jbang.backlogTracing", "true");
-        }
         // the runtime version of Camel is what is loaded via the catalog
         writeSetting(main, profileProperties, "camel.jbang.camel-version", new DefaultCamelCatalog().getCatalogVersion());
 
@@ -612,17 +609,19 @@ public class Run extends CamelCommand {
 
             // check for properties files
             if (file.endsWith(".properties")) {
-                if (!ResourceHelper.hasScheme(file) && !file.startsWith("github:")) {
-                    file = "file:" + file;
-                }
-                if (ObjectHelper.isEmpty(propertiesFiles)) {
-                    propertiesFiles = file;
-                } else {
-                    propertiesFiles = propertiesFiles + "," + file;
-                }
-                if (dev && file.startsWith("file:")) {
-                    // we can only reload if file based
-                    sjReload.add(file.substring(5));
+                if (acceptPropertiesFile(file)) {
+                    if (!ResourceHelper.hasScheme(file) && !file.startsWith("github:")) {
+                        file = "file:" + file;
+                    }
+                    if (ObjectHelper.isEmpty(propertiesFiles)) {
+                        propertiesFiles = file;
+                    } else {
+                        propertiesFiles = propertiesFiles + "," + file;
+                    }
+                    if (dev && file.startsWith("file:")) {
+                        // we can only reload if file based
+                        sjReload.add(file.substring(5));
+                    }
                 }
                 continue;
             }
@@ -725,15 +724,26 @@ public class Run extends CamelCommand {
 
         if (propertiesFiles != null) {
             String[] filesLocation = propertiesFiles.split(",");
+            // sort so general application.properties comes first (we should load profile first)
+            List<String> names = new ArrayList<>(List.of(filesLocation));
+            names.sort((o1, o2) -> {
+                // make sure application.properties is last
+                if (o1.endsWith("application.properties")) {
+                    return 1;
+                } else if (o2.endsWith("application.properties")) {
+                    return -1;
+                }
+                return 0;
+            });
             StringBuilder locations = new StringBuilder();
-            for (String file : filesLocation) {
+            for (String file : names) {
                 if (!file.startsWith("file:")) {
                     if (!file.startsWith("/")) {
                         file = FileSystems.getDefault().getPath("").toAbsolutePath() + File.separator + file;
                     }
                     file = "file://" + file;
                 }
-                if (locations.length() > 0) {
+                if (!locations.isEmpty()) {
                     locations.append(",");
                 }
                 locations.append(file);
@@ -745,9 +755,9 @@ public class Run extends CamelCommand {
             } else {
                 loc = locations.toString();
             }
-            // TODO: remove duplicates in loc
             main.addInitialProperty("camel.component.properties.location", loc);
             writeSettings("camel.component.properties.location", loc);
+            main.setPropertyPlaceholderLocations(loc);
         }
 
         // merge existing dependencies with --deps
@@ -803,6 +813,15 @@ public class Run extends CamelCommand {
         }
     }
 
+    private boolean acceptPropertiesFile(String file) {
+        String name = FileUtil.onlyName(file);
+        if (profile != null && name.startsWith("application-")) {
+            // only accept the file that matches the correct profile
+            return ("application-" + profile).equals(name);
+        }
+        return true;
+    }
+
     protected void doAddInitialProperty(KameletMain main) {
         // noop
     }
@@ -844,12 +863,37 @@ public class Run extends CamelCommand {
             return answer;
         }
 
+        // application.properties
         File profilePropertiesFile;
         if (sourceDir != null) {
             profilePropertiesFile = new File(sourceDir, "application.properties");
         } else {
             profilePropertiesFile = new File("application.properties");
         }
+        // based application-profile.properties
+        answer = doLoadAndInitProfileProperties(profilePropertiesFile);
+
+        if (profile != null) {
+            if (sourceDir != null) {
+                profilePropertiesFile = new File(sourceDir, "application-" + profile + ".properties");
+            } else {
+                profilePropertiesFile = new File("application-" + profile + ".properties");
+            }
+            // application-profile.properties should override standard application.properties
+            Properties override = doLoadAndInitProfileProperties(profilePropertiesFile);
+            if (override != null) {
+                answer.putAll(override);
+            }
+        }
+
+        if (kameletsVersion == null) {
+            kameletsVersion = VersionHelper.extractKameletsVersion();
+        }
+        return answer;
+    }
+
+    private Properties doLoadAndInitProfileProperties(File profilePropertiesFile) throws Exception {
+        Properties answer = null;
         if (profilePropertiesFile.exists()) {
             answer = loadProfileProperties(profilePropertiesFile);
             // logging level/color may be configured in the properties file
@@ -858,11 +902,6 @@ public class Run extends CamelCommand {
                     = "true".equals(answer.getProperty("loggingColor", loggingColor ? "true" : "false"));
             loggingJson
                     = "true".equals(answer.getProperty("loggingJson", loggingJson ? "true" : "false"));
-            if (propertiesFiles == null) {
-                propertiesFiles = "file:" + profilePropertiesFile.getPath();
-            } else {
-                propertiesFiles = propertiesFiles + ",file:" + profilePropertiesFile.getPath();
-            }
             repos = answer.getProperty("camel.jbang.repos", repos);
             mavenSettings = answer.getProperty("camel.jbang.maven-settings", mavenSettings);
             mavenSettingsSecurity = answer.getProperty("camel.jbang.maven-settings-security", mavenSettingsSecurity);
@@ -881,9 +920,6 @@ public class Run extends CamelCommand {
             exclude = answer.getProperty("camel.jbang.exclude", exclude);
         }
 
-        if (kameletsVersion == null) {
-            kameletsVersion = VersionHelper.extractKameletsVersion();
-        }
         return answer;
     }
 


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

Posted by da...@apache.org.
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);


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

Posted by da...@apache.org.
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 6d32de13a2376d63973e0b8072a825a2177aea22
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 13 16:55:40 2024 +0100

    CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
---
 .../java/org/apache/camel/main/MainCommandLineSupport.java     |  8 ++++++++
 .../camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc   |  1 +
 .../src/main/java/org/apache/camel/maven/DevMojo.java          |  3 +--
 .../src/main/java/org/apache/camel/maven/RunMojo.java          | 10 ++++++++++
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainCommandLineSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/MainCommandLineSupport.java
index 7e1322d7dc0..0c092f7b02e 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainCommandLineSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainCommandLineSupport.java
@@ -169,6 +169,14 @@ public abstract class MainCommandLineSupport extends MainSupport {
                 configure().withCompileWorkDir(parameter);
             }
         });
+        addOption(new ParameterOption(
+                "pro", "profile",
+                "Camel profile to use when running. (dev,test,prod)",
+                "profile") {
+            protected void doProcess(String arg, String parameter, LinkedList<String> remainingArgs) {
+                configure().withProfile(parameter);
+            }
+        });
     }
 
     /**
diff --git a/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc b/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc
index a2b0ab8fa7b..07692fd818d 100644
--- a/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc
+++ b/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc
@@ -36,6 +36,7 @@ The maven plugin *run* goal supports the following options which can be configur
 | durationMaxMessages | -1 | Sets the duration of maximum number of messages that the application will process before terminating.
 | logClasspath | false | Whether to log the classpath when starting
 | loggingLevel | OFF | Whether to use built-in console logging (uses log4j), which does not require to add any logging dependency to your project. However, the logging is fixed to log to the console, with a color style that is similar to Spring Boot. You can change the root logging level to: FATAL, ERROR, WARN, INFO, DEBUG, TRACE, OFF
+| profile |  | To run with a specific Camel Main profile (dev,test,prod)
 |===
 
 
diff --git a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java
index 7842d44af72..6d05ad46631 100644
--- a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java
+++ b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java
@@ -35,8 +35,6 @@ public class DevMojo extends RunMojo {
 
     /**
      * Enable routes reloading
-     *
-     * @throws Exception
      */
     @Override
     protected void beforeBootstrapCamel() throws Exception {
@@ -52,6 +50,7 @@ public class DevMojo extends RunMojo {
         // use absolute path for dir
         dir = new File(dir).getAbsolutePath();
 
+        System.setProperty("camel.main.profile", "dev");
         System.setProperty("camel.main.routesReloadEnabled", "true");
         System.setProperty("camel.main.routesReloadDirectory", dir);
         System.setProperty("camel.main.routesReloadDirectoryRecursive", "true");
diff --git a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunMojo.java b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunMojo.java
index 76f6b986f5c..e1a347441c9 100644
--- a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunMojo.java
+++ b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunMojo.java
@@ -138,6 +138,12 @@ public class RunMojo extends AbstractExecMojo {
     @Parameter(property = "camel.useKamelet")
     protected Boolean useKamelet;
 
+    /**
+     * To run with a specific Camel Main profile (dev,test,prod)
+     */
+    @Parameter(property = "camel.profile")
+    protected String profile;
+
     protected String extendedPluginDependencyArtifactId;
 
     @Component
@@ -342,6 +348,10 @@ public class RunMojo extends AbstractExecMojo {
         if (arguments != null) {
             args.addAll(Arrays.asList(arguments));
         }
+        if (profile != null) {
+            args.add("-profile");
+            args.add(profile);
+        }
 
         if (mainClass == null && usingKameletMain) {
             mainClass = "org.apache.camel.main.KameletMain";