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 1884f8db61a CAMEL-20928: camel-jbang - Export beans with ENV variable 
properties should silent ignore ENV missing, and also other properties missing.
1884f8db61a is described below

commit 1884f8db61a27f88ba89b82249bef584e5555fb6
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Jun 30 09:24:51 2024 +0200

    CAMEL-20928: camel-jbang - Export beans with ENV variable properties should 
silent ignore ENV missing, and also other properties missing.
---
 .../camel/dsl/jbang/core/commands/Debug.java       |  2 +-
 .../dsl/jbang/core/commands/ExportBaseCommand.java |  3 +-
 .../apache/camel/dsl/jbang/core/commands/Run.java  | 29 +++++++------
 .../java/org/apache/camel/main/KameletMain.java    |  8 +++-
 ...ndencyDownloaderPropertiesFunctionResolver.java | 50 +++++++++++++++++++++-
 5 files changed, 72 insertions(+), 20 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
index dbe70c24e01..fc1c205ce36 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
@@ -129,7 +129,7 @@ public class Debug extends Run {
 
     @Override
     public Integer doCall() throws Exception {
-        if (!silentRun) {
+        if (!exportRun) {
             printConfigurationValues("Debugging integration with the following 
configuration:");
         }
 
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 20fd0e31ac6..31fc76f161c 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
@@ -290,7 +290,6 @@ abstract class ExportBaseCommand extends CamelCommand {
     protected Integer runSilently(boolean ignoreLoadingError) throws Exception 
{
         Run run = new Run(getMain());
         // need to declare the profile to use for run
-        run.localKameletDir = localKameletDir;
         run.dependencies = dependencies;
         run.files = files;
         run.exclude = exclude;
@@ -301,7 +300,7 @@ abstract class ExportBaseCommand extends CamelCommand {
         run.springBootVersion = springBootVersion;
         run.kameletsVersion = kameletsVersion;
         run.localKameletDir = localKameletDir;
-        return run.runSilent(ignoreLoadingError);
+        return run.runExport(ignoreLoadingError);
     }
 
     protected Set<String> resolveDependencies(File settings, File profile) 
throws Exception {
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 77a409b9af6..11fcceb47c2 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
@@ -105,7 +105,7 @@ public class Run extends CamelCommand {
     private static final Pattern CLASS_PATTERN = Pattern.compile(
             "^\\s*public class\\s+([a-zA-Z0-9]*)[\\s+|;].*$", 
Pattern.MULTILINE);
 
-    public boolean silentRun;
+    public boolean exportRun;
     boolean scriptRun;
     boolean transformRun;
     boolean transformMessageRun;
@@ -308,20 +308,20 @@ public class Run extends CamelCommand {
 
     @Override
     public Integer doCall() throws Exception {
-        if (!silentRun) {
+        if (!exportRun) {
             printConfigurationValues("Running integration with the following 
configuration:");
         }
         // run
         return run();
     }
 
-    public Integer runSilent() throws Exception {
-        return runSilent(false);
+    public Integer runExport() throws Exception {
+        return runExport(false);
     }
 
-    protected Integer runSilent(boolean ignoreLoadingError) throws Exception {
+    protected Integer runExport(boolean ignoreLoadingError) throws Exception {
         // just boot silently and exit
-        this.silentRun = true;
+        this.exportRun = true;
         return run();
     }
 
@@ -443,7 +443,7 @@ public class Run extends CamelCommand {
                 String routes
                         = profileProperties != null ? 
profileProperties.getProperty("camel.main.routesIncludePattern") : null;
                 if (routes == null) {
-                    if (!silentRun) {
+                    if (!exportRun) {
                         String run = "run";
                         if (transformRun) {
                             run = "transform";
@@ -550,8 +550,9 @@ public class Run extends CamelCommand {
             }
         }
 
-        if (silentRun) {
+        if (exportRun) {
             main.setSilent(true);
+            main.addInitialProperty("camel.jbang.export", "true");
             // enable stub in silent mode so we do not use real components
             main.setStubPattern("*");
             // do not run for very long in silent run
@@ -898,7 +899,7 @@ public class Run extends CamelCommand {
         if (background) {
             Process p = pb.start();
             this.spawnPid = p.pid();
-            if (!silentRun && !transformRun && !transformMessageRun) {
+            if (!exportRun && !transformRun && !transformMessageRun) {
                 printer().println("Running Camel Quarkus integration: " + name 
+ " (version: " + eq.quarkusVersion
                                   + ") in background");
             }
@@ -974,7 +975,7 @@ public class Run extends CamelCommand {
         if (background) {
             Process p = pb.start();
             this.spawnPid = p.pid();
-            if (!silentRun && !transformRun && !transformMessageRun) {
+            if (!exportRun && !transformRun && !transformMessageRun) {
                 printer().println("Running Camel Spring Boot integration: " + 
name + " (version: " + camelVersion
                                   + ") in background");
             }
@@ -1173,7 +1174,7 @@ public class Run extends CamelCommand {
         if (background) {
             Process p = pb.start();
             this.spawnPid = p.pid();
-            if (!silentRun && !transformRun && !transformMessageRun) {
+            if (!exportRun && !transformRun && !transformMessageRun) {
                 printer().println("Running Camel integration: " + name + " 
(version: " + camelVersion
                                   + ") in background with PID: " + p.pid());
             }
@@ -1208,7 +1209,7 @@ public class Run extends CamelCommand {
         pb.command(cmds);
         Process p = pb.start();
         this.spawnPid = p.pid();
-        if (!silentRun && !transformRun && !transformMessageRun) {
+        if (!exportRun && !transformRun && !transformMessageRun) {
             printer().println("Running Camel integration: " + name + " in 
background with PID: " + p.pid());
         }
         return 0;
@@ -1285,7 +1286,7 @@ public class Run extends CamelCommand {
         if (background) {
             Process p = pb.start();
             this.spawnPid = p.pid();
-            if (!silentRun && !transformRun && !transformMessageRun) {
+            if (!exportRun && !transformRun && !transformMessageRun) {
                 printer().println("Running Camel integration: " + name + " 
(version: " + camelVersion
                                   + ") in background with PID: " + p.pid());
             }
@@ -1442,7 +1443,7 @@ public class Run extends CamelCommand {
     }
 
     private void configureLogging() throws Exception {
-        if (silentRun) {
+        if (exportRun) {
             // do not configure logging
         } else if (logging) {
             // allow to configure individual logging levels in 
application.properties
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index 16fd0d42600..6aaac8632dd 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -398,6 +398,11 @@ public class KameletMain extends MainCommandLineSupport {
         // setup backlog recorder from very start
         answer.getCamelContextExtension().setStartupStepRecorder(new 
BacklogStartupStepRecorder());
 
+        boolean export = 
"true".equals(getInitialProperties().get("camel.jbang.export"));
+        if (export) {
+            
addInitialProperty("camel.component.properties.ignore-missing-property", 
"true");
+        }
+
         boolean prompt = 
"true".equals(getInitialProperties().get("camel.jbang.prompt"));
         if (prompt) {
             answer.getPropertiesComponent().addPropertiesSource(new 
PromptPropertyPlaceholderSource());
@@ -673,7 +678,8 @@ public class KameletMain extends MainCommandLineSupport {
 
         org.apache.camel.component.properties.PropertiesComponent pc
                 = (org.apache.camel.component.properties.PropertiesComponent) 
camelContext.getPropertiesComponent();
-        pc.setPropertiesFunctionResolver(new 
DependencyDownloaderPropertiesFunctionResolver(camelContext));
+        boolean export = 
"true".equals(getInitialProperties().get("camel.jbang.export"));
+        pc.setPropertiesFunctionResolver(new 
DependencyDownloaderPropertiesFunctionResolver(camelContext, export));
     }
 
     @Override
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesFunctionResolver.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesFunctionResolver.java
index fdcdbe4e1db..6d52b9b001d 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesFunctionResolver.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesFunctionResolver.java
@@ -26,10 +26,12 @@ import org.apache.camel.spi.PropertiesFunction;
 public class DependencyDownloaderPropertiesFunctionResolver extends 
DefaultPropertiesFunctionResolver {
 
     private final DependencyDownloader downloader;
+    private final boolean export;
 
-    public DependencyDownloaderPropertiesFunctionResolver(CamelContext 
camelContext) {
+    public DependencyDownloaderPropertiesFunctionResolver(CamelContext 
camelContext, boolean export) {
         super();
         setCamelContext(camelContext);
+        this.export = export;
         this.downloader = 
getCamelContext().hasService(DependencyDownloader.class);
     }
 
@@ -77,6 +79,50 @@ public class DependencyDownloaderPropertiesFunctionResolver 
extends DefaultPrope
                         getCamelContext().getVersion());
             }
         }
-        return super.resolvePropertiesFunction(name);
+        PropertiesFunction answer = super.resolvePropertiesFunction(name);
+        if (answer != null && export) {
+            answer = new ExportPropertiesFunction(answer);
+        }
+        return answer;
+    }
+
+    private static class ExportPropertiesFunction implements 
PropertiesFunction {
+
+        private final PropertiesFunction delegate;
+
+        private ExportPropertiesFunction(PropertiesFunction delegate) {
+            this.delegate = delegate;
+        }
+
+        @Override
+        public boolean lookupFirst(String remainder) {
+            try {
+                return delegate.lookupFirst(remainder);
+            } catch (Exception e) {
+                // ignore
+            }
+            return false;
+        }
+
+        @Override
+        public String apply(String remainder) {
+            try {
+                return delegate.apply(remainder);
+            } catch (Exception e) {
+                // ignore
+            }
+            return null;
+        }
+
+        @Override
+        public String getName() {
+            return delegate.getName();
+        }
+
+        @Override
+        public boolean optional(String remainder) {
+            return true;
+        }
+
     }
 }

Reply via email to