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 2022/09/15 08:45:17 UTC
[camel] branch main updated (3f56cb1e4ee -> 2e72fff411f)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
from 3f56cb1e4ee CAMEL-18506: removed usages of the Async HTTP client from the test code
new 90d29506e31 CAMEL-18510: camel-jbang - init command should detect kamelet sink,source or action kind.
new 2e72fff411f CAMEL-18510: camel-jbang Run with --local-kamelet-dir support multiple dirs and to use dot as current dir.
The 2 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.
Summary of changes:
.../apache/camel/support/RouteTemplateHelper.java | 14 ++++++++-
.../apache/camel/dsl/jbang/core/commands/Init.java | 10 +++++++
.../apache/camel/dsl/jbang/core/commands/Run.java | 21 ++++++++------
.../resources/templates/kamelet-action.yaml.tmpl | 27 ++++++++++++++++++
.../resources/templates/kamelet-sink.yaml.tmpl | 33 ++++++++++++++++++++++
...{kamelet.yaml.tmpl => kamelet-source.yaml.tmpl} | 0
6 files changed, 96 insertions(+), 9 deletions(-)
create mode 100644 dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet-action.yaml.tmpl
create mode 100644 dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet-sink.yaml.tmpl
rename dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/{kamelet.yaml.tmpl => kamelet-source.yaml.tmpl} (100%)
[camel] 02/02: CAMEL-18510: camel-jbang Run with --local-kamelet-dir support multiple dirs and to use dot as current dir.
Posted by da...@apache.org.
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
commit 2e72fff411f00c652b7a8d369a63428d2bd335ae
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Sep 15 10:44:42 2022 +0200
CAMEL-18510: camel-jbang Run with --local-kamelet-dir support multiple dirs and to use dot as current dir.
---
.../apache/camel/support/RouteTemplateHelper.java | 14 +++++++++++++-
.../apache/camel/dsl/jbang/core/commands/Run.java | 21 +++++++++++++--------
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RouteTemplateHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/RouteTemplateHelper.java
index 3a7572fdd42..99c4b3cfecb 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/RouteTemplateHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/RouteTemplateHelper.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.support;
+import java.io.File;
+
import org.apache.camel.CamelContext;
import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.spi.Resource;
@@ -55,11 +57,16 @@ public final class RouteTemplateHelper {
ExtendedCamelContext ecc = camelContext.adapt(ExtendedCamelContext.class);
boolean found = false;
for (String path : location.split(",")) {
+ // using dot as current dir must be expanded into absolute path
+ if (".".equals(path) || "file:.".equals(path)) {
+ path = new File(".").getAbsolutePath();
+ path = "file:" + FileUtil.onlyPath(path);
+ }
String name = path;
Resource res = null;
// first try resource as-is if the path has an extension
String ext = FileUtil.onlyExt(path);
- if (ext != null) {
+ if (ext != null && !ext.isEmpty()) {
res = ecc.getResourceLoader().resolveResource(name);
}
if (res == null || !res.exists()) {
@@ -87,6 +94,11 @@ public final class RouteTemplateHelper {
if (!found) {
// fallback to old behaviour
String path = location;
+ // using dot as current dir must be expanded into absolute path
+ if (".".equals(path) || "file:.".equals(path)) {
+ path = new File(".").getAbsolutePath();
+ path = "file:" + FileUtil.onlyPath(path);
+ }
if (!path.endsWith("/")) {
path += "/";
}
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 da0b8f919d0..795e7e4c358 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
@@ -85,7 +85,6 @@ class Run extends CamelCommand {
private static final Pattern CLASS_PATTERN = Pattern.compile(
"^\\s*public class\\s+([a-zA-Z0-9]*)[\\s+|;].*$", Pattern.MULTILINE);
- private CamelContext context;
private boolean silentRun;
private boolean pipeRun;
@@ -162,7 +161,7 @@ class Run extends CamelCommand {
String jfrProfile;
@Option(names = { "--local-kamelet-dir" },
- description = "Local directory for loading Kamelets (takes precedence)")
+ description = "Local directory for loading Kamelets (takes precedence). Multiple directories can be specified separateed by comma.")
String localKameletDir;
@Option(names = { "--port" }, description = "Embeds a local HTTP server on this port")
@@ -544,9 +543,6 @@ class Run extends CamelCommand {
}
main.start();
-
- context = main.getCamelContext();
-
main.run();
return main.getExitCode();
@@ -636,11 +632,20 @@ class Run extends CamelCommand {
private KameletMain createMainInstance() {
KameletMain main;
- if (localKameletDir == null) {
+ if (localKameletDir == null || localKameletDir.isEmpty()) {
main = new KameletMain();
} else {
- main = new KameletMain("file:" + localKameletDir);
- writeSettings("camel.jbang.localKameletDir", localKameletDir);
+ StringJoiner sj = new StringJoiner(",");
+ String[] parts = localKameletDir.split(",");
+ for (String part : parts) {
+ part = FileUtil.compactPath(part);
+ if (!ResourceHelper.hasScheme(part)) {
+ part = "file:" + part;
+ }
+ sj.add(part);
+ }
+ main = new KameletMain(sj.toString());
+ writeSettings("camel.jbang.localKameletDir", sj.toString());
}
return main;
}
[camel] 01/02: CAMEL-18510: camel-jbang - init command should detect kamelet sink,source or action kind.
Posted by da...@apache.org.
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
commit 90d29506e317f641b4eb0c676f6d9a3ad5dcea72
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Sep 15 09:58:41 2022 +0200
CAMEL-18510: camel-jbang - init command should detect kamelet sink,source or action kind.
---
.../apache/camel/dsl/jbang/core/commands/Init.java | 10 +++++++
.../resources/templates/kamelet-action.yaml.tmpl | 27 ++++++++++++++++++
.../resources/templates/kamelet-sink.yaml.tmpl | 33 ++++++++++++++++++++++
...{kamelet.yaml.tmpl => kamelet-source.yaml.tmpl} | 0
4 files changed, 70 insertions(+)
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java
index 08de929a00a..8e81cb0f5c8 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java
@@ -73,6 +73,16 @@ class Init extends CamelCommand {
ext = "integration.yaml";
}
+ if ("kamelet.yaml".equals(ext)) {
+ if (file.contains("source")) {
+ ext = "kamelet-source.yaml";
+ } else if (file.contains("sink")) {
+ ext = "kamelet-sink.yaml";
+ } else {
+ ext = "kamelet-action.yaml";
+ }
+ }
+
String name = FileUtil.onlyName(file, false);
InputStream is = Init.class.getClassLoader().getResourceAsStream("templates/" + ext + ".tmpl");
if (is == null) {
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet-action.yaml.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet-action.yaml.tmpl
new file mode 100644
index 00000000000..9e55fcb70c6
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet-action.yaml.tmpl
@@ -0,0 +1,27 @@
+apiVersion: camel.apache.org/v1alpha1
+kind: Kamelet
+metadata:
+ name: {{ .Name }}
+ labels:
+ camel.apache.org/kamelet.type: "action"
+spec:
+ definition:
+ title: "Delay Action"
+ description: Delay the processing using a specific amount of time
+ required:
+ - milliseconds
+ properties:
+ milliseconds:
+ title: Milliseconds
+ description: The number of milliseconds of delay
+ type: integer
+ example: 1000
+ dependencies:
+ - "camel:core"
+ - "camel:kamelet"
+ template:
+ from:
+ uri: "kamelet:source"
+ steps:
+ - delay:
+ constant: "{{milliseconds}}"
\ No newline at end of file
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet-sink.yaml.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet-sink.yaml.tmpl
new file mode 100644
index 00000000000..94e131729e6
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet-sink.yaml.tmpl
@@ -0,0 +1,33 @@
+apiVersion: camel.apache.org/v1alpha1
+kind: Kamelet
+metadata:
+ name: {{ .Name }}
+ labels:
+ camel.apache.org/kamelet.type: "sink"
+spec:
+ definition:
+ title: "Log Sink"
+ description: A sink that logs all data that it receives, useful for debugging purposes.
+ properties:
+ showHeaders:
+ title: Show Headers
+ description: Show the headers received
+ type: boolean
+ default: false
+ showStreams:
+ title: Show Streams
+ description: Show the stream bodies (they may not be available in following steps)
+ type: boolean
+ default: false
+ dependencies:
+ - "camel:kamelet"
+ - "camel:log"
+ template:
+ from:
+ uri: "kamelet:source"
+ steps:
+ - to:
+ uri: "log:info"
+ parameters:
+ showHeaders: "{{?showHeaders}}"
+ showStreams: "{{?showStreams}}"
\ No newline at end of file
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet.yaml.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet-source.yaml.tmpl
similarity index 100%
rename from dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet.yaml.tmpl
rename to dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/kamelet-source.yaml.tmpl