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 2023/04/03 11:43:42 UTC
[camel] branch camel-3.x updated: CAMEL-19237: camel-jbang - version list for newer releases to include details
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.x by this push:
new 17dc6b18790 CAMEL-19237: camel-jbang - version list for newer releases to include details
17dc6b18790 is described below
commit 17dc6b18790fd029479638b2388c77297ed76fd3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Apr 3 13:43:05 2023 +0200
CAMEL-19237: camel-jbang - version list for newer releases to include details
---
.../jbang/core/commands/version/VersionList.java | 57 ++++++++++++++++++++++
1 file changed, 57 insertions(+)
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 46333a9c697..96ea27a6e23 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
@@ -16,7 +16,14 @@
*/
package org.apache.camel.dsl.jbang.core.commands.version;
+import java.io.LineNumberReader;
+import java.io.StringReader;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
import java.text.SimpleDateFormat;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -35,6 +42,7 @@ import org.apache.camel.dsl.jbang.core.common.VersionHelper;
import org.apache.camel.main.KameletMain;
import org.apache.camel.main.download.MavenDependencyDownloader;
import org.apache.camel.tooling.model.ReleaseModel;
+import org.apache.camel.util.StringHelper;
import picocli.CommandLine;
@CommandLine.Command(name = "list", description = "Displays available Camel versions")
@@ -42,6 +50,11 @@ public class VersionList extends CamelCommand {
private static final String YYYY_MM_DD = "yyyy-MM-dd";
+ private static final String GIT_CAMEL_URL
+ = "https://raw.githubusercontent.com/apache/camel-website/main/content/releases/release-%s.md";
+ private static final String GIT_CAMEL_QUARKUS_URL
+ = "https://raw.githubusercontent.com/apache/camel-website/main/content/releases/q/release-%s.md";
+
@CommandLine.Option(names = { "--sort" },
description = "Sort by version", defaultValue = "version")
String sort;
@@ -112,6 +125,13 @@ public class VersionList extends CamelCommand {
// enrich with details from catalog (if we can find any)
String catalogVersion = "quarkus".equals(runtime) ? v[1] : v[0];
ReleaseModel rm = releases.stream().filter(r -> catalogVersion.equals(r.getVersion())).findFirst().orElse(null);
+ if (rm == null) {
+ // unknown release but if it's an Apache Camel release we can grab from online
+ int dots = StringHelper.countChar(v[0], '.');
+ if (dots == 2) {
+ rm = onlineRelease(runtime, row.coreVersion);
+ }
+ }
if (rm != null) {
row.releaseDate = rm.getDate();
row.eolDate = rm.getEol();
@@ -208,6 +228,43 @@ public class VersionList extends CamelCommand {
return VersionHelper.isGE(version, minimumVersion);
}
+ private ReleaseModel onlineRelease(String runtime, String coreVersion) throws Exception {
+ String gitUrl = String.format("quarkus".equals(runtime) ? GIT_CAMEL_QUARKUS_URL : GIT_CAMEL_URL, coreVersion);
+
+ HttpClient hc = HttpClient.newHttpClient();
+ HttpResponse<String> res = hc.send(HttpRequest.newBuilder(new URI(gitUrl)).timeout(Duration.ofSeconds(20)).build(),
+ HttpResponse.BodyHandlers.ofString());
+
+ if (res.statusCode() == 200) {
+ ReleaseModel model = new ReleaseModel();
+ LineNumberReader lr = new LineNumberReader(new StringReader(res.body()));
+ String line = lr.readLine();
+ while (line != null) {
+ if (line.startsWith("date:")) {
+ model.setDate(line.substring(5).trim());
+ } else if (line.startsWith("version:")) {
+ model.setVersion(line.substring(8).trim());
+ } else if (line.startsWith("eol:")) {
+ model.setEol(line.substring(4).trim());
+ } else if (line.startsWith("kind:")) {
+ model.setKind(line.substring(5).trim());
+ } else if (line.startsWith("jdk:")) {
+ String s = line.substring(4).trim();
+ if (s.startsWith("[") && s.endsWith("]")) {
+ s = s.substring(1, s.length() - 1);
+ }
+ model.setJdk(s);
+ }
+ line = lr.readLine();
+ }
+ if (model.getVersion() != null) {
+ return model;
+ }
+ }
+
+ return null;
+ }
+
private static class Row {
String coreVersion;
String runtimeVersion;