This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-4.8.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.8.x by this push: new ceaa589643e CAMEL-21374: camel-jbang - Export with custom kamelets should copy all of them during exporting (#16062) ceaa589643e is described below commit ceaa589643e1903e7bf9077fb16dfa14eeac3720 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Oct 23 13:18:05 2024 +0200 CAMEL-21374: camel-jbang - Export with custom kamelets should copy all of them during exporting (#16062) --- .../dsl/jbang/core/commands/ExportBaseCommand.java | 11 +++- .../apache/camel/dsl/jbang/core/commands/Run.java | 2 + .../camel/dsl/jbang/core/commands/ExportTest.java | 46 +++++++++++++ .../src/test/resources/mypipe.yaml | 36 +++++++++++ .../src/test/resources/mytimer.kamelet.yaml | 75 ++++++++++++++++++++++ 5 files changed, 169 insertions(+), 1 deletion(-) 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 ee9aaff5e6b..7518eca3cfc 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 @@ -532,7 +532,16 @@ public abstract class ExportBaseCommand extends CamelCommand { } } for (String k : SETTINGS_PROP_SOURCE_KEYS) { - String files = prop.getProperty(k); + String files; + if ("kamelet".equals(k)) { + // special for kamelet as there can be multiple entries + files = RuntimeUtil.loadPropertiesLines(settings).stream() + .filter(l -> l.startsWith("kamelet=")) + .map(l -> StringHelper.after(l, "=")) + .collect(Collectors.joining(",")); + } else { + files = prop.getProperty(k); + } if (files != null && !files.isEmpty()) { for (String f : files.split(",")) { String scheme = getScheme(f); 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 03e7a79b750..368de256543 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 @@ -890,6 +890,7 @@ public class Run extends CamelCommand { eq.camelVersion = this.camelVersion; eq.kameletsVersion = this.kameletsVersion; eq.exportDir = runDir.toString(); + eq.localKameletDir = this.localKameletDir; eq.excludes = this.excludes; eq.filePaths = this.filePaths; eq.files = this.files; @@ -960,6 +961,7 @@ public class Run extends CamelCommand { eq.camelSpringBootVersion = this.camelVersion; eq.kameletsVersion = this.kameletsVersion; eq.exportDir = runDir.toString(); + eq.localKameletDir = this.localKameletDir; eq.excludes = this.excludes; eq.filePaths = this.filePaths; eq.files = this.files; diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java index 694187f243d..3832fad4648 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java +++ b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java @@ -233,6 +233,52 @@ class ExportTest { } } + @ParameterizedTest + @MethodSource("runtimeProvider") + public void shouldExportPipeOfficialAndCustomKamelet(RuntimeType rt) throws Exception { + Export command = createCommand(rt, + new String[] { "src/test/resources/mypipe.yaml", "src/test/resources/mytimer.kamelet.yaml" }, + "--gav=examples:pipe:1.0.0", "--dir=" + workingDir, "--quiet"); + int exit = command.doCall(); + + Assertions.assertEquals(0, exit); + Model model = readMavenModel(); + Assertions.assertEquals("examples", model.getGroupId()); + Assertions.assertEquals("pipe", model.getArtifactId()); + Assertions.assertEquals("1.0.0", model.getVersion()); + + if (rt == RuntimeType.main) { + Assertions.assertTrue(containsDependency(model.getDependencies(), "org.apache.camel", "camel-kamelet", null)); + Assertions + .assertTrue( + containsDependency(model.getDependencies(), "org.apache.camel.kamelets", "camel-kamelets", null)); + Assertions.assertTrue(containsDependency(model.getDependencies(), "org.apache.camel", "camel-timer", null)); + } else if (rt == RuntimeType.springBoot) { + Assertions.assertTrue( + containsDependency(model.getDependencies(), "org.apache.camel.springboot", "camel-kamelet-starter", null)); + Assertions + .assertTrue( + containsDependency(model.getDependencies(), "org.apache.camel.kamelets", "camel-kamelets", null)); + Assertions.assertTrue( + containsDependency(model.getDependencies(), "org.apache.camel.springboot", "camel-timer-starter", null)); + } else if (rt == RuntimeType.quarkus) { + Assertions.assertTrue( + containsDependency(model.getDependencies(), "org.apache.camel.quarkus", "camel-quarkus-kamelet", null)); + Assertions + .assertTrue( + containsDependency(model.getDependencies(), "org.apache.camel.kamelets", "camel-kamelets", null)); + Assertions.assertTrue( + containsDependency(model.getDependencies(), "org.apache.camel.quarkus", "camel-quarkus-timer", null)); + } + + File f = workingDir.toPath().resolve("src/main/resources/kamelets/mytimer.kamelet.yaml").toFile(); + Assertions.assertTrue(f.isFile()); + Assertions.assertTrue(f.exists()); + f = workingDir.toPath().resolve("src/main/resources/camel/mypipe.yaml").toFile(); + Assertions.assertTrue(f.isFile()); + Assertions.assertTrue(f.exists()); + } + private Model readMavenModel() throws Exception { File f = workingDir.toPath().resolve("pom.xml").toFile(); Assertions.assertTrue(f.isFile(), "Not a pom.xml file: " + f); diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/resources/mypipe.yaml b/dsl/camel-jbang/camel-jbang-core/src/test/resources/mypipe.yaml new file mode 100644 index 00000000000..0dfcde8c030 --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-core/src/test/resources/mypipe.yaml @@ -0,0 +1,36 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +apiVersion: camel.apache.org/v1 +kind: Pipe +metadata: + name: mypipe +spec: + source: + ref: + kind: Kamelet + apiVersion: camel.apache.org/v1 + name: mytimer + properties: + message: "hello world" + sink: + ref: + kind: Kamelet + apiVersion: camel.apache.org/v1 + name: log-sink + #properties: + #key: "value" \ No newline at end of file diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/resources/mytimer.kamelet.yaml b/dsl/camel-jbang/camel-jbang-core/src/test/resources/mytimer.kamelet.yaml new file mode 100644 index 00000000000..3e21d0ffa7d --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-core/src/test/resources/mytimer.kamelet.yaml @@ -0,0 +1,75 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +apiVersion: camel.apache.org/v1 +kind: Kamelet +metadata: + name: mytimer + annotations: + camel.apache.org/kamelet.support.level: "Stable" + camel.apache.org/catalog.version: "4.9.0-SNAPSHOT" + camel.apache.org/kamelet.icon: data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gU3ZnIFZlY3RvciBJY29ucyA6IGh0dHA6Ly93d3cub25saW5ld2ViZm9udHMuY29tL2ljb24gLS0+DQo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPg0KPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm9 [...] + camel.apache.org/provider: "Custom" + camel.apache.org/kamelet.group: "Timer" + camel.apache.org/kamelet.namespace: "Scheduling" + labels: + camel.apache.org/kamelet.type: source + camel.apache.org/kamelet.verified: "true" +spec: + definition: + title: Timer Source + description: Produces periodic messages with a custom payload. + required: + - message + type: object + properties: + period: + title: Period + description: "The interval (in milliseconds) to wait between producing the next message." + type: integer + default: 1000 + message: + title: Message + description: The message to generate. + type: string + example: hello world + contentType: + title: Content Type + description: The content type of the generated message. + type: string + default: text/plain + repeatCount: + title: Repeat Count + description: Specifies a maximum limit of number of fires + type: integer + dependencies: + - "camel:core" + - "camel:timer" + - "camel:kamelet" + template: + from: + uri: timer:tick + parameters: + period: "{{period}}" + repeatCount: "{{?repeatCount}}" + steps: + - setBody: + constant: "mytimer {{message}}" + - setHeader: + name: "Content-Type" + constant: "{{contentType}}" + - to: kamelet:sink \ No newline at end of file