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 75ca57467ef CAMEL-19802: camel-jbang - Add option to exclude files by 
pattern
75ca57467ef is described below

commit 75ca57467ef7dfb0bdaee0059022bd77468ee6b9
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sat Sep 23 14:24:48 2023 +0200

    CAMEL-19802: camel-jbang - Add option to exclude files by pattern
---
 .../modules/ROOT/pages/camel-jbang.adoc            |  3 +++
 .../camel/dsl/jbang/core/commands/Export.java      |  2 ++
 .../dsl/jbang/core/commands/ExportBaseCommand.java |  5 +++++
 .../apache/camel/dsl/jbang/core/commands/Run.java  | 25 +++++++++++++++++++++-
 4 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index a4a97ebf10f..6000e2ff3a6 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -2421,6 +2421,9 @@ The follow options related to _exporting_, can be 
configured in `application.pro
 |`camel.jbang.dependencies`
 |Additional dependencies (Use commas to separate multiple dependencies). See 
more details at xref:_adding_custom_jars[].
 
+|`camel.jbang.exclude`
+|Exclude files by name or pattern. Multiple names can be separated by comma.
+
 |`camel.jbang.classpathFiles`
 |Additional files to add to classpath (Use commas to separate multiple files). 
See more details at xref:_adding_custom_jars[].
 
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 6e10b059c92..31712c38eab 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
@@ -70,6 +70,7 @@ public class Export extends ExportBaseCommand {
             this.repos = prop.getProperty("camel.jbang.repos", this.repos);
             this.mavenSettings = 
prop.getProperty("camel.jbang.maven-settings", this.mavenSettings);
             this.mavenSettingsSecurity = 
prop.getProperty("camel.jbang.maven-settings-security", 
this.mavenSettingsSecurity);
+            this.exclude = prop.getProperty("camel.jbang.exclude", 
this.exclude);
         }
 
         if (runtime == null) {
@@ -126,6 +127,7 @@ public class Export extends ExportBaseCommand {
         cmd.secretsRefreshProviders = this.secretsRefreshProviders;
         cmd.openapi = this.openapi;
         cmd.packageName = this.packageName;
+        cmd.exclude = this.exclude;
         // run export
         return cmd.export();
     }
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 1033abeb35e..1decab8b5d2 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
@@ -96,6 +96,10 @@ abstract class ExportBaseCommand extends CamelCommand {
     @CommandLine.Option(names = { "--gav" }, description = "The Maven 
group:artifact:version")
     protected String gav;
 
+    @CommandLine.Option(names = { "--exclude" },
+                        description = "Exclude files by name or pattern. 
Multiple names can be separated by comma.")
+    String exclude;
+
     @CommandLine.Option(names = { "--maven-settings" },
                         description = "Optional location of maven setting.xml 
file to configure servers, repositories, mirrors and proxies."
                                       + " If set to \"false\", not even the 
default ~/.m2/settings.xml will be used.")
@@ -274,6 +278,7 @@ abstract class ExportBaseCommand extends CamelCommand {
         run.localKameletDir = localKameletDir;
         run.dependencies = dependencies;
         run.files = files;
+        run.exclude = exclude;
         run.openapi = openapi;
         return run.runSilent();
     }
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 04e99fbbc8b..9805aa5bcf6 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
@@ -61,6 +61,7 @@ import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.main.KameletMain;
 import org.apache.camel.main.download.DownloadListener;
 import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.AntPathMatcher;
 import org.apache.camel.util.CamelCaseOrderedProperties;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.IOHelper;
@@ -171,6 +172,10 @@ public class Run extends CamelCommand {
     @Option(names = { "--name" }, defaultValue = "CamelJBang", description = 
"The name of the Camel application")
     String name;
 
+    @Option(names = { "--exclude" },
+            description = "Exclude files by name or pattern. Multiple names 
can be separated by comma.")
+    String exclude;
+
     @Option(names = { "--logging" }, defaultValue = "true", description = "Can 
be used to turn off logging")
     boolean logging = true;
 
@@ -759,6 +764,7 @@ public class Run extends CamelCommand {
             kameletsVersion = 
answer.getProperty("camel.jbang.kameletsVersion", kameletsVersion);
             gav = answer.getProperty("camel.jbang.gav", gav);
             stub = answer.getProperty("camel.jbang.stub", stub);
+            exclude = answer.getProperty("camel.jbang.exclude", exclude);
         }
 
         if (kameletsVersion == null) {
@@ -1161,10 +1167,15 @@ public class Run extends CamelCommand {
             // relative file is okay, otherwise we assume it's a hidden file
             boolean ok = name.startsWith("..") || name.startsWith("./");
             if (!ok) {
-                return false;
+                return true;
             }
         }
 
+        // is the file excluded?
+        if (isExcluded(name, exclude)) {
+            return true;
+        }
+
         // skip dirs
         File f = new File(name);
         if (f.exists() && f.isDirectory()) {
@@ -1180,6 +1191,18 @@ public class Run extends CamelCommand {
         return false;
     }
 
+    private static boolean isExcluded(String name, String exclude) {
+        if (exclude != null) {
+            for (String pattern : exclude.split(",")) {
+                pattern = pattern.trim();
+                if (AntPathMatcher.INSTANCE.match(pattern, name)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
     private boolean jkubeFile(String name) {
         return name.endsWith(".jkube.yaml") || name.endsWith(".jkube.yml");
     }

Reply via email to