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 0208c0c65c6 CAMEL-18035: camel-jbang - Run * should better detect what
is Camel routes and what are misc files
0208c0c65c6 is described below
commit 0208c0c65c6077c1ba9325ae1195755cd89695fd
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue May 3 15:10:58 2022 +0200
CAMEL-18035: camel-jbang - Run * should better detect what is Camel routes
and what are misc files
---
.../org/apache/camel/dsl/jbang/core/commands/Run.java | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
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 0a30cf76078..0a3d5278b6f 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
@@ -492,9 +492,24 @@ class Run implements Callable<Integer> {
return lockFile;
}
- private boolean knownFile(String file) {
+ private boolean knownFile(String file) throws Exception {
String ext = FileUtil.onlyExt(file, true);
if (ext != null) {
+ // special for yaml or xml, as we need to check if they have camel
or not
+ if ("xml".equals(ext) || "yaml".equals(ext)) {
+ // load content into memory
+ try (FileInputStream fis = new FileInputStream(file)) {
+ String data = IOHelper.loadText(fis);
+ if ("xml".equals(ext)) {
+ return data.contains("<routes") ||
data.contains("<routeConfiguration") || data.contains("<rests");
+ } else {
+ return data.contains("- from:") || data.contains("-
route:") || data.contains("- route-configuration:")
+ || data.contains("- rest:");
+ }
+ }
+ }
+ // if the ext is an accepted file then we include it as a
potential route
+ // (java files need to be included as route to support
pojos/processors with routes)
return Arrays.stream(ACCEPTED_FILE_EXT).anyMatch(e ->
e.equalsIgnoreCase(ext));
} else {
// assume match as it can be wildcard or dir