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

(camel) 04/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 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";