This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-3.20.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7c44d8846fda6f4e344577f2d15a000f1ca675d9 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Mar 14 09:52:43 2023 +0100 CAMEL-19128: camel-jbang - version command to show release date/eol --- .../jbang/core/commands/version/VersionList.java | 103 +++++++++++++-------- 1 file changed, 66 insertions(+), 37 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 3946440410a..8cc69fa76aa 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,24 +16,32 @@ */ package org.apache.camel.dsl.jbang.core.commands.version; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; import com.github.freva.asciitable.AsciiTable; import com.github.freva.asciitable.Column; import com.github.freva.asciitable.HorizontalAlign; +import org.apache.camel.catalog.CamelCatalog; +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.VersionHelper; import org.apache.camel.main.KameletMain; import org.apache.camel.main.download.MavenDependencyDownloader; +import org.apache.camel.tooling.model.ReleaseModel; import picocli.CommandLine; @CommandLine.Command(name = "list", description = "Displays available Camel versions") public class VersionList extends CamelCommand { + private static final String YYYY_MM_DD = "yyyy-MM-dd"; + @CommandLine.Option(names = { "--sort" }, description = "Sort by version", defaultValue = "version") String sort; @@ -92,17 +100,34 @@ public class VersionList extends CamelCommand { return 1; } + CamelCatalog catalog = new DefaultCamelCatalog(); + List<ReleaseModel> releases = catalog.camelReleases(); + List<Row> rows = new ArrayList<>(); for (String[] v : versions) { Row row = new Row(); rows.add(row); row.coreVersion = v[0]; row.runtimeVersion = v[1]; + + // enrich with details from catalog (if we can find any) + ReleaseModel rm = releases.stream().filter(r -> v[0].equals(r.getVersion())).findFirst().orElse(null); + if (rm != null) { + row.releaseDate = rm.getDate(); + row.eolDate = rm.getEol(); + row.jdks = rm.getJdk(); + row.kind = rm.getKind(); + } + } + + if (lts) { + rows.removeIf(r -> !"lts".equalsIgnoreCase(r.kind)); } // sort rows rows.sort(this::sortRow); + // camel-quarkus is not LTS and have its own release schedule System.out.println(AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList( new Column().header("CAMEL VERSION") .headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.CENTER).with(r -> r.coreVersion), @@ -112,8 +137,12 @@ public class VersionList extends CamelCommand { .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)))); + new Column().header("KIND").visible(!"quarkus".equalsIgnoreCase(runtime)) + .headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.CENTER).with(this::kind), + new Column().header("RELEASED").visible(!"quarkus".equalsIgnoreCase(runtime)) + .headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.RIGHT).with(this::releaseDate), + new Column().header("SUPPORTED UNTIL").visible(!"quarkus".equalsIgnoreCase(runtime)) + .headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.RIGHT).with(this::eolDate)))); return 0; } @@ -134,58 +163,58 @@ 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"; + return r.jdks; + } + + private String kind(Row r) { + if (r.kind != null) { + return r.kind.toUpperCase(Locale.ROOT); } + return ""; } - private String lts(Row r) { - return isLtsRelease(r.coreVersion) ? "LTS" : ""; + private String releaseDate(Row r) { + try { + if (r.releaseDate != null) { + SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DD); + Date d = sdf.parse(r.releaseDate); + SimpleDateFormat sdf2 = new SimpleDateFormat("MMMM yyyy", Locale.US); + return sdf2.format(d); + } + } catch (Exception e) { + // ignore + } + return r.releaseDate != null ? r.releaseDate : ""; } - 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; + private String eolDate(Row r) { + try { + if (r.eolDate != null) { + SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DD); + Date d = sdf.parse(r.eolDate); + SimpleDateFormat sdf2 = new SimpleDateFormat("MMMM yyyy", Locale.US); + return sdf2.format(d); + } + } catch (Exception e) { + // ignore } - return false; + return r.eolDate != null ? r.eolDate : ""; } private boolean acceptVersion(String version) { if (version == null) { return false; } - boolean accept = VersionHelper.isGE(version, minimumVersion); - if (accept && lts) { - accept = isLtsRelease(version); - } - return accept; + return VersionHelper.isGE(version, minimumVersion); } private static class Row { String coreVersion; String runtimeVersion; + String releaseDate; + String eolDate; + String kind; + String jdks; } }