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/03/13 13:54:33 UTC
[camel] 04/05: CAMEL-19128: camel-jbang - Add version command
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch version-list
in repository https://gitbox.apache.org/repos/asf/camel.git
commit d4b672cfb1428f2224b277c5b8d30f08658d7d88
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 13 13:17:07 2023 +0100
CAMEL-19128: camel-jbang - Add version command
---
.../jbang/core/commands/version/VersionList.java | 54 +++++++++++++++++++++-
.../camel/dsl/jbang/core/common/VersionHelper.java | 8 ++++
2 files changed, 60 insertions(+), 2 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 1107cfbfc54..159bdd8c4a2 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
@@ -50,6 +50,9 @@ public class VersionList extends CamelCommand {
@CommandLine.Option(names = { "--repo", "--repos" }, description = "Maven repository for downloading available versions")
String repo;
+ @CommandLine.Option(names = { "--lts" }, description = "Only show LTS supported releases")
+ boolean lts;
+
@CommandLine.Option(names = { "--fresh" }, description = "Make sure we use fresh (i.e. non-cached) resources")
boolean fresh;
@@ -107,7 +110,11 @@ public class VersionList extends CamelCommand {
new Column().header("QUARKUS").visible("quarkus".equalsIgnoreCase(runtime))
.headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.CENTER).with(r -> r.runtimeVersion),
new Column().header("SPRING-BOOT").visible("spring-boot".equalsIgnoreCase(runtime))
- .headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.CENTER).with(r -> r.runtimeVersion))));
+ .headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.CENTER).with(r -> r.runtimeVersion),
+ new Column().header("JDK")
+ .headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.RIGHT).with(this::jdkVersion),
+ new Column().header("SUPPORT")
+ .headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.CENTER).with(this::lts))));
return 0;
}
@@ -127,11 +134,54 @@ public class VersionList extends CamelCommand {
}
}
+ private String jdkVersion(Row r) {
+ if (VersionHelper.isGE(r.coreVersion, "4.0")) {
+ return "17";
+ } else if (VersionHelper.isGE(r.coreVersion, "3.15")) {
+ return "11, 17";
+ } else if (VersionHelper.isGE(r.coreVersion, "3.15")) {
+ return "11, 17";
+ } else if (VersionHelper.isGE(r.coreVersion, "3.0")) {
+ return "8, 11";
+ } else {
+ return "8";
+ }
+ }
+
+ private String lts(Row r) {
+ return isLtsRelease(r.coreVersion) ? "LTS" : "";
+ }
+
+ private static boolean isLtsRelease(String version) {
+ if (VersionHelper.isBetween(version, "4.0.0", "4.1")) {
+ return true;
+ } else if (VersionHelper.isBetween(version, "3.20", "3.99")) {
+ return true;
+ } else if (VersionHelper.isBetween(version, "3.18", "3.19")) {
+ return true;
+ } else if (VersionHelper.isBetween(version, "3.14", "3.15")) {
+ return true;
+ } else if (VersionHelper.isBetween(version, "3.11", "3.12")) {
+ return true;
+ } else if (VersionHelper.isBetween(version, "3.11", "3.12")) {
+ return true;
+ } else if (VersionHelper.isBetween(version, "3.7", "3.8")) {
+ return true;
+ } else if (VersionHelper.isBetween(version, "3.4", "3.5")) {
+ return true;
+ }
+ return false;
+ }
+
private boolean acceptVersion(String version) {
if (version == null) {
return false;
}
- return VersionHelper.isGE(version, minimumVersion);
+ boolean accept = VersionHelper.isGE(version, minimumVersion);
+ if (accept && lts) {
+ accept = isLtsRelease(version);
+ }
+ return accept;
}
private static class Row {
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/VersionHelper.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/VersionHelper.java
index 97ae5734405..3c60bd603da 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/VersionHelper.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/VersionHelper.java
@@ -27,6 +27,14 @@ public final class VersionHelper {
return compare(source, target) >= 0;
}
+ public static boolean isLE(String source, String target) {
+ return compare(source, target) <= 0;
+ }
+
+ public static boolean isBetween(String source, String inclusive, String exclusive) {
+ return compare(source, inclusive) >= 0 && compare(source, exclusive) < 0;
+ }
+
public static int compare(String source, String target) {
if (source == null || target == null) {
return 0;