You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by fm...@apache.org on 2026/02/17 13:01:19 UTC
(camel) 04/05: Add QuarkusHelper
This is an automated email from the ASF dual-hosted git repository.
fmariani pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit ec53360a31287778780321d35c02a95a31df0113
Author: Croway <fe...@gmail.com>
AuthorDate: Tue Feb 17 09:43:27 2026 +0100
Add QuarkusHelper
---
.../jbang/core/commands/version/VersionList.java | 66 +----------
.../camel/dsl/jbang/core/common/QuarkusHelper.java | 121 +++++++++++++++++++++
2 files changed, 124 insertions(+), 63 deletions(-)
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionList.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionList.java
index 82ee0cb73afd..5669fa5fa90c 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionList.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionList.java
@@ -46,6 +46,7 @@ import org.apache.camel.catalog.DefaultCamelCatalog;
import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
+import org.apache.camel.dsl.jbang.core.common.QuarkusHelper;
import org.apache.camel.dsl.jbang.core.common.RuntimeCompletionCandidates;
import org.apache.camel.dsl.jbang.core.common.RuntimeType;
import org.apache.camel.dsl.jbang.core.common.RuntimeTypeConverter;
@@ -76,8 +77,6 @@ public class VersionList extends CamelCommand {
private static final String GIT_CAMEL_QUARKUS_URL
= "https://raw.githubusercontent.com/apache/camel-website/main/content/releases/q/release-%s.md";
- private static final String QUARKUS_PLATFORM_URL = "https://registry.quarkus.io/client/platforms";
-
private static final String DEFAULT_DATE_FORMAT = "MMMM yyyy";
@CommandLine.Option(names = { "--runtime" },
@@ -181,7 +180,8 @@ public class VersionList extends CamelCommand {
// resolve actual Quarkus platform versions from registry
if (RuntimeType.quarkus == runtime) {
- resolveQuarkusPlatformVersions(rows);
+ QuarkusHelper.resolveQuarkusPlatformVersions(
+ rows, r -> r.runtimeVersion, (r, v) -> r.quarkusVersion = v);
}
if (lts) {
@@ -609,66 +609,6 @@ public class VersionList extends CamelCommand {
return null;
}
- /**
- * Resolves the actual Quarkus platform version for each row by fetching the Quarkus platform registry and matching
- * the Camel Quarkus major.minor version against stream IDs.
- */
- private void resolveQuarkusPlatformVersions(List<Row> rows) {
- try {
- HttpClient hc = HttpClient.newHttpClient();
- HttpResponse<String> res = hc.send(
- HttpRequest.newBuilder(new URI(QUARKUS_PLATFORM_URL))
- .timeout(Duration.ofSeconds(2))
- .build(),
- HttpResponse.BodyHandlers.ofString());
-
- if (res.statusCode() == 200) {
- JsonObject json = (JsonObject) Jsoner.deserialize(res.body());
- JsonArray platforms = json.getCollection("platforms");
- if (platforms != null && !platforms.isEmpty()) {
- JsonObject platform = platforms.getMap(0);
- JsonArray streams = platform.getCollection("streams");
- if (streams != null) {
- // find the latest camel quarkus version per major.minor
- java.util.Map<String, Row> latestPerStream = new java.util.LinkedHashMap<>();
- for (Row row : rows) {
- if (row.runtimeVersion != null) {
- String majorMinor = VersionHelper.getMajorMinorVersion(row.runtimeVersion);
- Row existing = latestPerStream.get(majorMinor);
- if (existing == null
- || VersionHelper.compare(row.runtimeVersion, existing.runtimeVersion) > 0) {
- latestPerStream.put(majorMinor, row);
- }
- }
- }
- // only set quarkus version on the latest row per stream
- for (var entry : latestPerStream.entrySet()) {
- String majorMinor = entry.getKey();
- for (int i = 0; i < streams.size(); i++) {
- JsonObject stream = streams.getMap(i);
- String streamId = stream.getString("id");
- if (majorMinor.equals(streamId)) {
- JsonArray releases = stream.getCollection("releases");
- if (releases != null && !releases.isEmpty()) {
- JsonObject release = releases.getMap(0);
- String quarkusCoreVersion
- = release.getString("quarkus-core-version");
- if (quarkusCoreVersion != null) {
- entry.getValue().quarkusVersion = quarkusCoreVersion;
- }
- }
- break;
- }
- }
- }
- }
- }
- }
- } catch (Exception e) {
- // ignore - if the registry is not reachable within 2 seconds, skip
- }
- }
-
private static class Row {
String coreVersion;
String runtimeVersion;
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/QuarkusHelper.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/QuarkusHelper.java
new file mode 100644
index 000000000000..8831774ffeb6
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/QuarkusHelper.java
@@ -0,0 +1,121 @@
+/*
+ * 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.dsl.jbang.core.common;
+
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.BiConsumer;
+import java.util.function.BinaryOperator;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
+
+/**
+ * Helper for resolving Quarkus platform information from the Quarkus registry.
+ */
+public final class QuarkusHelper {
+
+ public static final String QUARKUS_PLATFORM_URL_PROPERTY = "camel.jbang.quarkus.platform.url";
+ public static final String DEFAULT_QUARKUS_PLATFORM_URL = "https://registry.quarkus.io/client/platforms";
+
+ private QuarkusHelper() {
+ }
+
+ /**
+ * Returns the Quarkus platform registry URL, honoring the system property {@value #QUARKUS_PLATFORM_URL_PROPERTY}
+ * if set.
+ */
+ public static String getQuarkusPlatformUrl() {
+ return System.getProperty(QUARKUS_PLATFORM_URL_PROPERTY, DEFAULT_QUARKUS_PLATFORM_URL);
+ }
+
+ /**
+ * Resolves the actual Quarkus platform version for each row by fetching the Quarkus platform registry and matching
+ * the Camel Quarkus major.minor version against stream IDs.
+ *
+ * @param rows the list of rows to enrich with Quarkus platform versions
+ * @param runtimeVersionFunc function to extract the runtime (Camel Quarkus) version from a row
+ * @param quarkusVersionSetter consumer to set the resolved Quarkus platform version on a row
+ */
+ public static <T> void resolveQuarkusPlatformVersions(
+ List<T> rows,
+ Function<T, String> runtimeVersionFunc,
+ BiConsumer<T, String> quarkusVersionSetter) {
+
+ try {
+ HttpClient hc = HttpClient.newHttpClient();
+ HttpResponse<String> res = hc.send(
+ HttpRequest.newBuilder(new URI(getQuarkusPlatformUrl()))
+ .timeout(Duration.ofSeconds(2))
+ .build(),
+ HttpResponse.BodyHandlers.ofString());
+
+ if (res.statusCode() == 200) {
+ JsonObject json = (JsonObject) Jsoner.deserialize(res.body());
+ JsonArray platforms = json.getCollection("platforms");
+ if (platforms == null || platforms.isEmpty()) {
+ return;
+ }
+ JsonObject platform = platforms.getMap(0);
+ JsonArray streams = platform.getCollection("streams");
+ if (streams == null) {
+ return;
+ }
+
+ // keep the row with the highest runtime version per major.minor stream
+ BinaryOperator<T> keepLatest = (a, b) -> VersionHelper.compare(
+ runtimeVersionFunc.apply(a), runtimeVersionFunc.apply(b)) >= 0 ? a : b;
+
+ Map<String, T> latestPerStream = rows.stream()
+ .filter(row -> runtimeVersionFunc.apply(row) != null)
+ .collect(Collectors.toMap(
+ row -> VersionHelper.getMajorMinorVersion(runtimeVersionFunc.apply(row)),
+ Function.identity(),
+ keepLatest));
+
+ // match each major.minor against registry streams and set the quarkus version
+ latestPerStream.forEach((majorMinor, row) -> findQuarkusCoreVersion(streams, majorMinor)
+ .ifPresent(version -> quarkusVersionSetter.accept(row, version)));
+ }
+ } catch (Exception e) {
+ // ignore - if the registry is not reachable within 2 seconds, skip
+ }
+ }
+
+ /**
+ * Finds the quarkus-core-version from the registry streams that matches the given major.minor stream ID.
+ */
+ private static Optional<String> findQuarkusCoreVersion(JsonArray streams, String majorMinor) {
+ return streams.stream()
+ .map(s -> (JsonObject) s)
+ .filter(stream -> majorMinor.equals(stream.getString("id")))
+ .findFirst()
+ .map(stream -> (JsonArray) stream.getCollection("releases"))
+ .filter(releases -> !releases.isEmpty())
+ .map(releases -> (JsonObject) releases.getMap(0))
+ .map(release -> release.getString("quarkus-core-version"));
+ }
+}