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 b7c87bf2f4c7 CAMEL-27762: camel-jbang - AI tools check kamelet:
endpoints against the project's camel.jbang.kameletsVersion (#31091)
b7c87bf2f4c7 is described below
commit b7c87bf2f4c7e69c439ed75e749f39f81b582021
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 30 14:41:12 2026 +0100
CAMEL-27762: camel-jbang - AI tools check kamelet: endpoints against the
project's camel.jbang.kameletsVersion (#31091)
* CAMEL-27762: camel-jbang - AI tools check kamelet: endpoints against the
project's camel.jbang.kameletsVersion
* CAMEL-27762: camel-jbang - say what a null catalogVersion means
* CAMEL-27762: camel-jbang - Kamelet data types of the project's release,
and no Kamelet catalog lookup for a component doc
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../modules/ROOT/pages/camel-jbang-mcp.adoc | 12 +++
.../dsl/jbang/core/commands/ai/AuthoringTools.java | 7 +-
.../dsl/jbang/core/commands/ai/CatalogDocs.java | 55 +++++++---
.../dsl/jbang/core/commands/ai/KameletChecks.java | 28 +++--
.../jbang/core/commands/ai/KameletDefinitions.java | 81 ++++++++++++--
.../dsl/jbang/core/commands/ai/ValidatorFacts.java | 5 +-
.../jbang/core/commands/ai/KameletChecksTest.java | 120 +++++++++++++++++++++
.../dsl/jbang/core/commands/mcp/KameletTools.java | 9 +-
8 files changed, 280 insertions(+), 37 deletions(-)
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
b/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
index 2fd9eee44631..e2d7b32644c4 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
@@ -633,6 +633,18 @@ camel_catalog_find takes term (required), kind, limit,
camelVersion; got q
transformer and the body it takes or gives (see xref:body-types.adoc[Message
Body Types]).
|===
+These two tools use the Kamelets release of the Camel CLI unless they are
given a `kameletsVersion`. A project that
+runs with another release sets it in `application.properties`, as `camel run`
reads it:
+
+[source,properties]
+----
+camel.jbang.kameletsVersion=4.24.0
+----
+
+The checks of `camel_validate_source` and the file tools then look up the
`kamelet:` endpoints of the project in that
+release, and so do `camel_catalog_doc` and `camel_catalog_find` when the
client declares the project directory as its
+only root. A Kamelet that the release does not have is reported with the
version that was looked at.
+
=== Example Catalog
[cols="1,3",options="header"]
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java
index 017b38fe272c..e2515748ebb3 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java
@@ -139,10 +139,12 @@ public final class AuthoringTools {
+ " it left out: docPage=<section title> returns
one of them.")
.executor((ctx, args) -> {
applyVersion(ctx, args);
+ // the Kamelets of the release the project runs with
(CAMEL-27762)
return CatalogDocs.catalogDoc(ctx.catalog(),
args.get("name"), args.get("endpoint"),
args.get("kind"), args.get("optionsFilter"),
args.get("includeOptions"),
bool(args, "includeHeaders", false), bool(args,
"includeDoc", false),
- args.get("docPage"), integer(args, "limit",
-1)).toJson();
+ args.get("docPage"), integer(args, "limit", -1),
+
KameletDefinitions.projectVersion(ctx.projectDirectory())).toJson();
}));
registry.accept(tool("camel_catalog_find",
@@ -163,7 +165,8 @@ public final class AuthoringTools {
.executor((ctx, args) -> {
applyVersion(ctx, args);
return CatalogDocs.find(ctx.catalog(), args.get("term"),
args.get("kind"),
- integer(args, "limit", 10)).toJson();
+ integer(args, "limit", 10),
KameletDefinitions.projectVersion(ctx.projectDirectory()))
+ .toJson();
}));
registry.accept(tool("camel_catalog_sample",
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocs.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocs.java
index 4d71055711af..b3922fdc6687 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocs.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocs.java
@@ -243,12 +243,24 @@ public final class CatalogDocs {
public static JsonObject catalogDoc(
CamelCatalog catalog, String name, String endpoint, String kind,
String optionsFilter,
String includeOptions, boolean includeHeaders, boolean includeDoc,
String docPage, int limit) {
+ return catalogDoc(catalog, name, endpoint, kind, optionsFilter,
includeOptions, includeHeaders, includeDoc,
+ docPage, limit, null);
+ }
+
+ /**
+ * The same, with the Kamelets of the catalog of a version, such as the
one the project runs with
+ * (camel.jbang.kameletsVersion, CAMEL-27762); null for the one of the
Camel CLI.
+ */
+ public static JsonObject catalogDoc(
+ CamelCatalog catalog, String name, String endpoint, String kind,
String optionsFilter,
+ String includeOptions, boolean includeHeaders, boolean includeDoc,
String docPage, int limit,
+ String kameletsVersion) {
String filter = filterTerms(optionsFilter);
JsonObject answer = answer(catalog, name, endpoint, kind, filter,
includeOptions, includeHeaders, includeDoc,
- docPage, limit);
+ docPage, limit, kameletsVersion);
if (several(filter) && (endpoint == null || endpoint.isBlank()) &&
(docPage == null || docPage.isBlank())
&& !answer.containsKey("error")) {
- putUnmatchedTerms(catalog, name, kind, filter, includeOptions,
limit, answer);
+ putUnmatchedTerms(catalog, name, kind, filter, includeOptions,
limit, kameletsVersion, answer);
if (splitTerms(optionsFilter).size() > MAX_FILTER_TERMS) {
answer.put("filterNote", "only the first " + MAX_FILTER_TERMS
+ " terms of optionsFilter are searched");
}
@@ -316,10 +328,11 @@ public final class CatalogDocs {
*/
private static void putUnmatchedTerms(
CamelCatalog catalog, String name, String kind, String filter,
String includeOptions, int limit,
- JsonObject answer) {
+ String kameletsVersion, JsonObject answer) {
JsonArray unmatched = new JsonArray();
for (String term : filter.split(",")) {
- JsonObject one = answer(catalog, name, null, kind, term,
includeOptions, false, false, null, limit);
+ JsonObject one = answer(catalog, name, null, kind, term,
includeOptions, false, false, null, limit,
+ kameletsVersion);
boolean headersOnly = one.getIntegerOrDefault("matchedOptions",
-1) == 0
&& one.getIntegerOrDefault("matchedHeaders", 0) > 0;
if (!headersOnly && !matchedNothing(one)) {
@@ -343,7 +356,10 @@ public final class CatalogDocs {
private static JsonObject answer(
CamelCatalog catalog, String name, String endpoint, String kind,
String optionsFilter,
- String includeOptions, boolean includeHeaders, boolean includeDoc,
String docPage, int limit) {
+ String includeOptions, boolean includeHeaders, boolean includeDoc,
String docPage, int limit,
+ String kameletsVersion) {
+ // the Kamelet catalog is only looked up where Kamelets are needed:
loading a release (and downloading it when
+ // it is not in the local Maven repository) does not slow down the
docs of a component or an endpoint check
if (endpoint != null && !endpoint.isBlank()) {
return validateEndpoint(catalog, endpoint.trim());
}
@@ -358,7 +374,7 @@ public final class CatalogDocs {
kind = suffixKind;
}
String page = docPage != null ?
docPage.trim().toLowerCase(Locale.ROOT) : null;
- if ("kamelet".equals(kind) &&
!KameletDefinitions.catalog().containsKey(name)
+ if ("kamelet".equals(kind) &&
!KameletDefinitions.catalog(kameletsVersion).containsKey(name)
&& ("kamelet".equals(name) || page != null)) {
// the kamelet component's own docs, such as how to write a
Kamelet (docPage=custom): a model asks for
// them with kind=kamelet, which is the kind of the catalog's
Kamelets
@@ -552,13 +568,18 @@ public final class CatalogDocs {
}
}
if (kind == null || "kamelet".equals(kind)) {
- KameletDefinitions.Definition def =
KameletDefinitions.catalog().get(name);
+ Map<String, KameletDefinitions.Definition> kamelets =
KameletDefinitions.catalog(kameletsVersion);
+ KameletDefinitions.Definition def = kamelets.get(name);
if (def != null) {
return kameletDoc(def, catalog);
}
if (kind != null) {
- JsonObject err = notFound("Kamelet", name,
- KameletDefinitions.suggest(name,
KameletDefinitions.catalog().keySet(), 5));
+ JsonObject err = notFound("Kamelet", name,
KameletDefinitions.suggest(name, kamelets.keySet(), 5));
+ String version =
KameletDefinitions.catalogVersion(kameletsVersion);
+ if (version != null) {
+ // which release was looked at: a Kamelet of a newer one
needs camel.jbang.kameletsVersion
+ err.put("kameletsVersion", version);
+ }
// a Kamelet of the project is not in the catalog: how to
write one
err.put("guide", AuthoringTools.KAMELET_GUIDE);
return err;
@@ -578,7 +599,7 @@ public final class CatalogDocs {
suggestions.addAll(catalog.suggestLanguageNames(name, 3));
suggestions.addAll(catalog.suggestEipNames(name, 3));
suggestions.addAll(findBeans(catalog,
name).stream().map(PojoBeanModel::getName).limit(3).toList());
- suggestions.addAll(KameletDefinitions.suggest(name,
KameletDefinitions.catalog().keySet(), 3));
+ suggestions.addAll(KameletDefinitions.suggest(name,
KameletDefinitions.catalog(kameletsVersion).keySet(), 3));
List<String> names = new ArrayList<>(catalog.findComponentNames());
names.addAll(catalog.findDataFormatNames());
names.addAll(catalog.findLanguageNames());
@@ -647,11 +668,11 @@ public final class CatalogDocs {
}
/** The Kamelets of the catalog whose name has the term, then those whose
description has it. */
- private static List<KameletDefinitions.Definition> kameletsMatching(String
lowerTerm) {
+ private static List<KameletDefinitions.Definition> kameletsMatching(String
lowerTerm, String kameletsVersion) {
List<KameletDefinitions.Definition> byName = new ArrayList<>();
List<KameletDefinitions.Definition> byDescription = new ArrayList<>();
String dashed = lowerTerm.trim().replace(' ', '-');
- for (KameletDefinitions.Definition def :
KameletDefinitions.catalog().values()) {
+ for (KameletDefinitions.Definition def :
KameletDefinitions.catalog(kameletsVersion).values()) {
if (def.name().contains(dashed)) {
byName.add(def);
} else if (def.description() != null &&
def.description().toLowerCase(Locale.ROOT).contains(lowerTerm)) {
@@ -1188,6 +1209,14 @@ public final class CatalogDocs {
* @param limit maximum matches per kind
*/
public static JsonObject find(CamelCatalog catalog, String term, String
kind, int limit) {
+ return find(catalog, term, kind, limit, null);
+ }
+
+ /**
+ * The same, with the Kamelets of the catalog of a version, such as the
one the project runs with
+ * (camel.jbang.kameletsVersion, CAMEL-27762); null for the one of the
Camel CLI.
+ */
+ public static JsonObject find(CamelCatalog catalog, String term, String
kind, int limit, String kameletsVersion) {
if (term == null || term.isBlank()) {
return error("'term' parameter is required");
}
@@ -1280,7 +1309,7 @@ public final class CatalogDocs {
int n = 0;
int maxKamelets = kind == null ? Math.min(max, 5) : max;
String lower = term.toLowerCase(Locale.ROOT);
- for (KameletDefinitions.Definition def : kameletsMatching(lower)) {
+ for (KameletDefinitions.Definition def : kameletsMatching(lower,
kameletsVersion)) {
if (n++ >= maxKamelets) {
break;
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletChecks.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletChecks.java
index 7cc1014d4100..e13b2d9cd78f 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletChecks.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletChecks.java
@@ -89,18 +89,20 @@ public final class KameletChecks {
return errors;
}
Map<String, String> properties = directory != null ?
projectProperties(directory) : Map.of();
+ // the Kamelets of the release the project runs with, which may be
newer than the CLI's (CAMEL-27762)
+ String version = KameletDefinitions.projectVersion(directory);
for (Node root : roots) {
- walk(root, null, errors, directory, properties, unknownNames);
+ walk(root, null, errors, directory, properties, version,
unknownNames);
}
return errors;
}
private static void walk(
Node node, String parentKey, List<String> errors, Path directory,
Map<String, String> properties,
- boolean unknownNames) {
+ String version, boolean unknownNames) {
if (node instanceof SequenceNode seq) {
for (Node n : seq.getValue()) {
- walk(n, parentKey, errors, directory, properties,
unknownNames);
+ walk(n, parentKey, errors, directory, properties, version,
unknownNames);
}
} else if (node instanceof MappingNode map) {
ScalarNode uri = null;
@@ -113,16 +115,16 @@ public final class KameletChecks {
parameters = p;
} else if (ENDPOINT_KEYS.contains(key) && t.getValueNode()
instanceof ScalarNode s) {
// to: kamelet:log-sink, the short form
- check(s, null, errors, directory, properties,
unknownNames);
+ check(s, null, errors, directory, properties, version,
unknownNames);
}
}
if (uri != null && (parentKey == null ||
ENDPOINT_KEYS.contains(parentKey) || "from".equals(parentKey))) {
- check(uri, parameters, errors, directory, properties,
unknownNames);
+ check(uri, parameters, errors, directory, properties, version,
unknownNames);
}
for (NodeTuple t : map.getValue()) {
String key = t.getKeyNode() instanceof ScalarNode k ?
k.getValue() : null;
if (!"parameters".equals(key)) {
- walk(t.getValueNode(), key, errors, directory, properties,
unknownNames);
+ walk(t.getValueNode(), key, errors, directory, properties,
version, unknownNames);
}
}
}
@@ -130,7 +132,7 @@ public final class KameletChecks {
private static void check(
ScalarNode uriNode, MappingNode parameters, List<String> errors,
Path directory,
- Map<String, String> properties, boolean unknownNames) {
+ Map<String, String> properties, String version, boolean
unknownNames) {
String uri = uriNode.getValue();
if (uri == null || !uri.startsWith("kamelet:")) {
return;
@@ -149,9 +151,9 @@ public final class KameletChecks {
return;
}
int line = uriNode.getStartMark().getLine();
- KameletDefinitions.Definition def = KameletDefinitions.find(name,
directory);
+ KameletDefinitions.Definition def = KameletDefinitions.find(name,
directory, version);
if (def == null) {
- Map<String, KameletDefinitions.Definition> catalog =
KameletDefinitions.catalog();
+ Map<String, KameletDefinitions.Definition> catalog =
KameletDefinitions.catalog(version);
if (catalog.isEmpty()) {
// the catalog cannot be read: nothing to check against
return;
@@ -165,7 +167,13 @@ public final class KameletChecks {
return;
}
StringBuilder sb = new
StringBuilder(EndpointChecks.linePrefix(line)).append("kamelet:").append(name)
- .append(": no Kamelet named ").append(name).append(" in
the Kamelet catalog or the project");
+ .append(": no Kamelet named ").append(name).append(" in
the Kamelet catalog");
+ String checked = KameletDefinitions.catalogVersion(version);
+ if (checked != null) {
+ // which release was looked at: a Kamelet of a newer one needs
camel.jbang.kameletsVersion
+ sb.append(' ').append(checked);
+ }
+ sb.append(" or the project");
if (!suggestions.isEmpty()) {
sb.append(". Did you mean: ").append(String.join(", ",
suggestions));
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletDefinitions.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletDefinitions.java
index 591e78583c2f..3cb0d20e54e9 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletDefinitions.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletDefinitions.java
@@ -28,14 +28,18 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
+import org.apache.camel.dsl.jbang.run.RunProfileProperties;
import org.apache.camel.dsl.jbang.run.catalog.KameletCatalogHelper;
import org.apache.camel.dsl.jbang.run.catalog.KameletDataTypeModel;
import org.apache.camel.dsl.jbang.run.catalog.KameletModel;
import org.apache.camel.dsl.jbang.run.catalog.KameletOptionModel;
+import org.apache.camel.dsl.jbang.run.common.CamelJBangConstants;
import org.apache.camel.dsl.jbang.run.common.VersionHelper;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
@@ -93,17 +97,22 @@ public final class KameletDefinitions {
private static final Map<String, Map<String, Definition>> CATALOGS = new
ConcurrentHashMap<>();
private static volatile Map<String, Definition> testCatalog;
+ private static final Map<String, Map<String, Definition>> TEST_CATALOGS =
new ConcurrentHashMap<>();
+ private static final Map<String, AtomicInteger> TEST_LOOKUPS = new
ConcurrentHashMap<>();
private KameletDefinitions() {
}
- /** The Kamelet of the project directory, else of the catalog, or null. */
+ /**
+ * The Kamelet of the project directory, else of the catalog the project
runs with (camel.jbang.kameletsVersion, see
+ * {@link #projectVersion(Path)}), or null.
+ */
public static Definition find(String name, Path directory) {
if (name == null || name.isBlank()) {
return null;
}
Definition def = directory != null ?
projectKamelets(directory).get(name) : null;
- return def != null ? def : catalog().get(name);
+ return def != null ? def :
catalog(projectVersion(directory)).get(name);
}
/**
@@ -131,28 +140,82 @@ public final class KameletDefinitions {
* @param version the version, or null for the one of the Camel CLI
*/
public static Map<String, Definition> catalog(String version) {
- Map<String, Definition> fixed = testCatalog;
+ Map<String, Definition> fixed = version != null ?
TEST_CATALOGS.get(version) : null;
if (fixed != null) {
+ TEST_LOOKUPS.computeIfAbsent(version, v -> new
AtomicInteger()).incrementAndGet();
return fixed;
}
- if (version == null || version.isBlank()) {
- try {
- version = VersionHelper.extractKameletsVersion();
- } catch (Exception e) {
- version = null;
- }
+ fixed = testCatalog;
+ if (fixed != null) {
+ return fixed;
}
+ version = catalogVersion(version);
if (version == null) {
return Map.of();
}
return CATALOGS.computeIfAbsent(version,
KameletDefinitions::loadCatalog);
}
+ /**
+ * The version of the Kamelet catalog of a catalog lookup: the given one,
else the one of the Camel CLI. Null means
+ * that no version is given and the one of the Camel CLI cannot be read,
so no catalog is available:
+ * {@link #catalog(String)} then gives an empty one.
+ */
+ public static String catalogVersion(String version) {
+ if (version != null && !version.isBlank()) {
+ return version;
+ }
+ try {
+ return VersionHelper.extractKameletsVersion();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * The version of the Kamelet catalog a project runs with, as camel run
reads it: camel.jbang.kameletsVersion of the
+ * application.properties of the directory, or of
application-dev.properties (the profile camel run uses unless told
+ * otherwise), which wins. A newer Kamelets release than the one of the
Camel CLI has Kamelets the CLI's catalog
+ * does not (CAMEL-27762).
+ *
+ * @return the version, or null when the project sets none (or sets a
placeholder)
+ */
+ public static String projectVersion(Path directory) {
+ if (directory == null) {
+ return null;
+ }
+ try {
+ Properties properties = RunProfileProperties.load(directory, null,
"dev", new HashSet<>(), p -> {
+ });
+ String version = properties != null ?
properties.getProperty(CamelJBangConstants.KAMELETS_VERSION) : null;
+ return version != null && !version.isBlank() &&
!version.contains("{{") ? version.trim() : null;
+ } catch (Exception e) {
+ // an unreadable file sets nothing
+ return null;
+ }
+ }
+
/** The Kamelets the catalog has instead of the real catalog, for tests;
null for the real one. */
static void setTestCatalog(Map<String, Definition> kamelets) {
testCatalog = kamelets;
}
+ /** The Kamelets the catalog of a version has, for tests; null removes
them. */
+ static void setTestCatalog(String version, Map<String, Definition>
kamelets) {
+ TEST_LOOKUPS.remove(version);
+ if (kamelets != null) {
+ TEST_CATALOGS.put(version, kamelets);
+ } else {
+ TEST_CATALOGS.remove(version);
+ }
+ }
+
+ /** How often the catalog of a version set with {@link
#setTestCatalog(String, Map)} was looked up, for tests. */
+ static int testLookups(String version) {
+ AtomicInteger lookups = TEST_LOOKUPS.get(version);
+ return lookups != null ? lookups.get() : 0;
+ }
+
private static Map<String, Definition> loadCatalog(String version) {
Map<String, Definition> answer = new LinkedHashMap<>();
try {
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/ValidatorFacts.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/ValidatorFacts.java
index 7ad56b559cc1..ed57d89d2672 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/ValidatorFacts.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/ValidatorFacts.java
@@ -409,7 +409,8 @@ final class ValidatorFacts {
/**
* The data types of the Kamelets of the catalog and of the project that
declare them (CAMEL-25928): the data type
* transformers of their default in and out data types, which say the body
a Kamelet takes and gives. Only read when
- * the file uses a Kamelet.
+ * the file uses a Kamelet. The catalog is the one the project runs with
(camel.jbang.kameletsVersion, see
+ * {@link KameletDefinitions#projectVersion(Path)}), as for the kamelet:
checks (CAMEL-27762).
*/
static Map<String, ProjectFacts.KameletDataTypes> kameletDataTypes(String
content, Path directory) {
if (!content.contains("kamelet")) {
@@ -417,7 +418,7 @@ final class ValidatorFacts {
}
Map<String, ProjectFacts.KameletDataTypes> answer = new HashMap<>();
List<Map<String, KameletDefinitions.Definition>> sources = new
ArrayList<>();
- sources.add(KameletDefinitions.catalog());
+
sources.add(KameletDefinitions.catalog(KameletDefinitions.projectVersion(directory)));
if (directory != null) {
// the project's own Kamelets win over those of the catalog
sources.add(KameletDefinitions.projectKamelets(directory));
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletChecksTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletChecksTest.java
index 6fe76810d546..be5cc888b768 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletChecksTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/KameletChecksTest.java
@@ -24,6 +24,8 @@ import java.util.Map;
import org.apache.camel.catalog.CamelCatalog;
import org.apache.camel.catalog.DefaultCamelCatalog;
+import org.apache.camel.dsl.jbang.run.catalog.KameletDataTypeModel;
+import org.apache.camel.dsl.yaml.validator.ProjectFacts;
import org.apache.camel.util.json.JsonObject;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -39,6 +41,9 @@ import static org.assertj.core.api.Assertions.assertThatCode;
*/
class KameletChecksTest {
+ /** A Kamelets release that is newer than the CLI's. */
+ private static final String NEWER = "9.9.9-test";
+
private static CamelCatalog catalog;
@BeforeAll
@@ -69,11 +74,32 @@ class KameletChecksTest {
prop("showHeaders", false, "boolean", "false"),
prop("showStreams", false, "boolean", "false"))));
KameletDefinitions.setTestCatalog(kamelets);
+ // a Kamelets release newer than the CLI's: it has soap-source, which
the CLI's catalog does not
+ Map<String, KameletDefinitions.Definition> newer = new
LinkedHashMap<>();
+ newer.put("soap-source", new KameletDefinitions.Definition(
+ "soap-source", "source", "SOAP Source", "Serves a SOAP web
service from its WSDL.",
+ "the Kamelet catalog " + NEWER, List.of(
+ prop("path", true, "string", null),
+ prop("wsdlURL", true, "string", null),
+ prop("bodyFormat", false, "string", "xml")),
+ List.of(dataType("out", "application-xml"))));
+ newer.put("log-sink", kamelets.get("log-sink"));
+ KameletDefinitions.setTestCatalog(NEWER, newer);
}
@AfterAll
static void tearDown() {
KameletDefinitions.setTestCatalog(null);
+ KameletDefinitions.setTestCatalog(NEWER, null);
+ }
+
+ private static KameletDataTypeModel dataType(String direction, String
format) {
+ KameletDataTypeModel dt = new KameletDataTypeModel();
+ dt.direction = direction;
+ dt.name = format;
+ dt.format = format;
+ dt.defaultType = true;
+ return dt;
}
private static KameletDefinitions.Property prop(String name, boolean
required, String type, String defaultValue) {
@@ -794,4 +820,98 @@ class KameletChecksTest {
JsonObject all = CatalogDocs.find(catalog, "timer source", null, 10);
assertThat(all.toJson()).contains("\"kamelet:timer-source\"");
}
+
+ private static final String SOAP_ROUTE = """
+ - route:
+ from:
+ uri: kamelet:soap-source
+ parameters:
+ path: /orders
+ wsdlURL: orders.wsdl
+ %s
+ steps:
+ - to: kamelet:log-sink
+ """;
+
+ @Test
+ void theKameletsVersionOfTheProject(@TempDir Path dir) throws Exception {
+ assertThat(KameletDefinitions.projectVersion(null)).isNull();
+ assertThat(KameletDefinitions.projectVersion(dir)).isNull();
+ Files.writeString(dir.resolve("application.properties"),
"camel.jbang.kameletsVersion = 4.24.0\n");
+ assertThat(KameletDefinitions.projectVersion(dir)).isEqualTo("4.24.0");
+ // the dev profile, which camel run uses unless told otherwise, wins
over application.properties
+ Files.writeString(dir.resolve("application-dev.properties"),
"camel.jbang.kameletsVersion=4.25.0\n");
+ assertThat(KameletDefinitions.projectVersion(dir)).isEqualTo("4.25.0");
+ // a placeholder is not known before the run: the CLI's catalog
+ Files.writeString(dir.resolve("application-dev.properties"),
"camel.jbang.kameletsVersion={{kv}}\n");
+ assertThat(KameletDefinitions.projectVersion(dir)).isNull();
+ }
+
+ @Test
+ void aKameletOfTheReleaseTheProjectRunsWith(@TempDir Path dir) throws
Exception {
+ String yaml = SOAP_ROUTE.formatted("bodyFormat: json");
+ // the CLI's catalog does not have it: unknown, and the error says
which catalog was looked at
+ List<String> errors = KameletChecks.validateYaml(yaml, dir);
+ assertThat(errors).hasSize(1);
+ assertThat(errors.get(0)).contains("no Kamelet named soap-source in
the Kamelet catalog")
+ .contains("or the project")
+ .doesNotContain(NEWER);
+
+ Files.writeString(dir.resolve("application.properties"),
"camel.jbang.kameletsVersion=" + NEWER + "\n");
+ // camel run takes the Kamelets of that release, and so does the check
(CAMEL-27762)
+ assertThat(KameletChecks.validateYaml(yaml, dir)).isEmpty();
+ assertThat(KameletChecks.validateYaml(yaml, dir, false)).isEmpty();
+ // and checks the properties of the Kamelet of that release
+ List<String> wrong =
KameletChecks.validateYaml(SOAP_ROUTE.formatted("bodyFromat: json"), dir);
+ assertThat(wrong).hasSize(1);
+ assertThat(wrong.get(0)).contains("unknown property
'bodyFromat'").contains("Did you mean: bodyFormat");
+ }
+
+ @Test
+ void theDocsOfAKameletOfANewerRelease() {
+ JsonObject unknown = CatalogDocs.catalogDoc(catalog, "soap-source",
null, "kamelet", null, null, false, false,
+ null, -1, null);
+ assertThat(unknown.containsKey("error")).isTrue();
+ JsonObject doc = CatalogDocs.catalogDoc(catalog, "soap-source", null,
"kamelet", null, null, false, false,
+ null, -1, NEWER);
+ assertThat(doc.containsKey("error")).isFalse();
+ assertThat(doc.toJson()).contains("bodyFormat");
+ assertThat(CatalogDocs.find(catalog, "soap", "kamelet", 10,
NEWER).toJson())
+ .contains("\"kamelet:soap-source\"");
+ assertThat(CatalogDocs.find(catalog, "soap", "kamelet",
10).toJson()).doesNotContain("kamelet:soap-source");
+ }
+
+ @Test
+ void theDataTypesOfAKameletOfTheReleaseTheProjectRunsWith(@TempDir Path
dir) throws Exception {
+ String yaml = SOAP_ROUTE.formatted("bodyFormat: json");
+ // the CLI's catalog does not have it, so the body checks know no data
type of it
+ assertThat(ValidatorFacts.kameletDataTypes(yaml,
dir)).doesNotContainKey("soap-source");
+
+ Files.writeString(dir.resolve("application.properties"),
"camel.jbang.kameletsVersion=" + NEWER + "\n");
+ // the body checks read the data types of the same release as the
kamelet: checks (CAMEL-27762)
+ assertThat(ValidatorFacts.kameletDataTypes(yaml,
dir).get("soap-source"))
+ .isEqualTo(new ProjectFacts.KameletDataTypes(null,
"application-xml"));
+ }
+
+ @Test
+ void theDocsOfAComponentDoNotLookUpTheKameletCatalog() {
+ String version = "9.9.8-lookup-test";
+ KameletDefinitions.setTestCatalog(version, Map.of());
+ try {
+ // loading a Kamelets release can mean a download: a component or
an endpoint does not need it
+ assertThat(CatalogDocs.catalogDoc(catalog, "timer", null, null,
null, null, false, false, null, -1, version)
+ .containsKey("error")).isFalse();
+ assertThat(CatalogDocs.catalogDoc(catalog, "timer", null,
"component", "period,delay", null, false, false,
+ null, -1, version).containsKey("error")).isFalse();
+ CatalogDocs.catalogDoc(catalog, null, "timer:tick?period=1000",
null, null, null, false, false, null, -1,
+ version);
+ assertThat(KameletDefinitions.testLookups(version)).isZero();
+ // a Kamelet does
+ assertThat(CatalogDocs.catalogDoc(catalog, "soap-source", null,
"kamelet", null, null, false, false, null,
+ -1, version).containsKey("error")).isTrue();
+ assertThat(KameletDefinitions.testLookups(version)).isPositive();
+ } finally {
+ KameletDefinitions.setTestCatalog(version, null);
+ }
+ }
}
diff --git
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/KameletTools.java
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/KameletTools.java
index d75f524c43e1..51a84bb01135 100644
---
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/KameletTools.java
+++
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/KameletTools.java
@@ -163,7 +163,14 @@ public class KameletTools {
Map<String, Object> kamelets = loadKamelets(version);
Object k = kamelets != null ? kamelets.get(kamelet) : null;
if (k == null) {
- throw new ToolCallException("Kamelet not found: " + kamelet,
null);
+ // which release was looked at: a Kamelet of a newer one is
found with the version the project runs
+ // with, its camel.jbang.kameletsVersion (CAMEL-27762)
+ throw new ToolCallException(
+ "Kamelet not found: " + kamelet + " in the Kamelet
catalog " + version
+ + "; for a project that runs
another Kamelets release"
+ + " (camel.jbang.kameletsVersion
in application.properties), pass that"
+ + " version as kameletsVersion",
+ null);
}
KameletModel km = KameletCatalogHelper.createModel(k, true);