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 2025/04/24 07:59:41 UTC
(camel) 02/02: CAMEL-22015: camel-jbang - Export with language/dataformat component should resolve dependency
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.10.x
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 248f7026ede9c19d4d2b18d11228484218322ebc
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Apr 24 09:58:18 2025 +0200
CAMEL-22015: camel-jbang - Export with language/dataformat component should resolve dependency
---
.../camel/dsl/jbang/core/commands/ExportTest.java | 4 +-
.../java/org/apache/camel/main/KameletMain.java | 2 +
.../main/download/DownloadEndpointStrategy.java | 64 ++++++++++++++++++++++
3 files changed, 68 insertions(+), 2 deletions(-)
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 565f332a77b..9638633a61d 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
@@ -551,7 +551,7 @@ class ExportTest {
Assertions.assertEquals("route", model.getArtifactId());
Assertions.assertEquals("1.0.0", model.getVersion());
- /* if (rt == RuntimeType.main) {
+ if (rt == RuntimeType.main) {
Assertions.assertTrue(containsDependency(model.getDependencies(), "org.apache.camel", "camel-groovy", null));
} else if (rt == RuntimeType.springBoot) {
Assertions.assertTrue(
@@ -559,7 +559,7 @@ class ExportTest {
} else if (rt == RuntimeType.quarkus) {
Assertions.assertTrue(
containsDependency(model.getDependencies(), "org.apache.camel.quarkus", "camel-quarkus-groovy", null));
- }*/
+ }
File f = workingDir.toPath().resolve("src/main/resources/demo.groovy").toFile();
Assertions.assertTrue(f.isFile());
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 dc93855cff4..2559fb89448 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
@@ -58,6 +58,7 @@ import org.apache.camel.main.download.DependencyDownloaderRoutesLoader;
import org.apache.camel.main.download.DependencyDownloaderStrategy;
import org.apache.camel.main.download.DependencyDownloaderTransformerResolver;
import org.apache.camel.main.download.DependencyDownloaderUriFactoryResolver;
+import org.apache.camel.main.download.DownloadEndpointStrategy;
import org.apache.camel.main.download.DownloadListener;
import org.apache.camel.main.download.DownloadModelineParser;
import org.apache.camel.main.download.ExportPropertiesParser;
@@ -623,6 +624,7 @@ public class KameletMain extends MainCommandLineSupport {
ff, answer, Optional.ofNullable(camelVersion).map(Object::toString).orElse(null), export);
answer.getCamelContextExtension().addContextPlugin(PeriodTaskResolver.class, ptr);
+ answer.getCamelContextExtension().registerEndpointCallback(new DownloadEndpointStrategy(answer, silent));
answer.getCamelContextExtension().addContextPlugin(ComponentResolver.class,
new DependencyDownloaderComponentResolver(answer, stubPattern, silent, transform));
answer.getCamelContextExtension().addContextPlugin(DataFormatResolver.class,
diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DownloadEndpointStrategy.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DownloadEndpointStrategy.java
new file mode 100644
index 00000000000..2fb0559c9ed
--- /dev/null
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DownloadEndpointStrategy.java
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+package org.apache.camel.main.download;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.spi.EndpointStrategy;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.StringHelper;
+
+public class DownloadEndpointStrategy implements EndpointStrategy {
+
+ private final CamelContext camelContext;
+
+ public DownloadEndpointStrategy(CamelContext camelContext, boolean silent) {
+ this.camelContext = camelContext;
+ }
+
+ @Override
+ public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
+ String scheme = StringHelper.before(uri, ":");
+
+ if ("language".equals(scheme)) {
+ String name = extractName(uri);
+ if (name != null) {
+ camelContext.resolveLanguage(name);
+ }
+ } else if ("dataformat".equals(scheme)) {
+ String name = extractName(uri);
+ if (name != null) {
+ camelContext.resolveDataFormat(name);
+ }
+ }
+ return endpoint;
+ }
+
+ private static String extractName(String uri) {
+ uri = StringHelper.before(uri, "?", uri);
+ int count = StringHelper.countChar(uri, ':');
+ String name;
+ if (count > 1) {
+ name = StringHelper.between(uri, ":", ":");
+ } else {
+ name = StringHelper.after(uri, ":");
+ }
+ name = FileUtil.stripLeadingSeparator(name);
+ return name;
+ }
+
+}