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 2023/03/07 15:01:12 UTC
[camel] 06/08: Implements CAMEL-19044 (#9355)
This is an automated email from the ASF dual-hosted git repository.
fmariani pushed a commit to branch camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git
commit e438ff29528f9c189316d470d24870e130dcc03d
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Wed Feb 15 12:24:23 2023 -0500
Implements CAMEL-19044 (#9355)
* Implements CAMEL-19044
* Replace Vert.x JSON library to camel-util-json
---
.../core/commands/catalog/CatalogBaseCommand.java | 30 +++++++++++++++++-----
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogBaseCommand.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogBaseCommand.java
index 111d946ba50..c2da5a87677 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogBaseCommand.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogBaseCommand.java
@@ -19,6 +19,7 @@ package org.apache.camel.dsl.jbang.core.commands.catalog;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.stream.Collectors;
import com.github.freva.asciitable.AsciiTable;
@@ -33,6 +34,7 @@ import org.apache.camel.dsl.jbang.core.common.RuntimeUtil;
import org.apache.camel.dsl.jbang.core.common.VersionHelper;
import org.apache.camel.main.download.MavenGav;
import org.apache.camel.tooling.model.ArtifactModel;
+import org.apache.camel.util.json.Jsoner;
import picocli.CommandLine;
public abstract class CatalogBaseCommand extends CamelCommand {
@@ -72,6 +74,10 @@ public abstract class CatalogBaseCommand extends CamelCommand {
description = "Filter by version more recent (inclusive)")
String sinceAfter;
+ @CommandLine.Option(names = { "--json" },
+ description = "Output in JSON Format")
+ boolean jsonOutput;
+
CamelCatalog catalog;
public CatalogBaseCommand(CamelJBangMain main) {
@@ -131,12 +137,24 @@ public abstract class CatalogBaseCommand extends CamelCommand {
rows.sort(this::sortRow);
if (!rows.isEmpty()) {
- System.out.println(AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList(
- new Column().header("NAME").visible(!gav).dataAlign(HorizontalAlign.LEFT).maxWidth(30).with(r -> r.name),
- new Column().header("ARTIFACT-ID").visible(gav).dataAlign(HorizontalAlign.LEFT).with(this::shortGav),
- new Column().header("LEVEL").dataAlign(HorizontalAlign.LEFT).with(r -> r.level),
- new Column().header("SINCE").dataAlign(HorizontalAlign.RIGHT).with(r -> r.since),
- new Column().header("DESCRIPTION").dataAlign(HorizontalAlign.LEFT).with(this::shortDescription))));
+ if (jsonOutput) {
+ System.out.println(
+ Jsoner.serialize(
+ rows.stream().map(row -> Map.of(
+ "name", row.name,
+ "level", row.level,
+ "native", row.nativeSupported)).collect(Collectors.toList())));
+ } else {
+ System.out.println(AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList(
+ new Column().header("NAME").visible(!gav).dataAlign(HorizontalAlign.LEFT).maxWidth(30)
+ .with(r -> r.name),
+ new Column().header("ARTIFACT-ID").visible(gav).dataAlign(HorizontalAlign.LEFT).with(this::shortGav),
+ new Column().header("LEVEL").dataAlign(HorizontalAlign.LEFT).with(r -> r.level),
+ new Column().header("NATIVE").dataAlign(HorizontalAlign.CENTER)
+ .visible("quarkus".equals(runtime)).with(this::nativeSupported),
+ new Column().header("SINCE").dataAlign(HorizontalAlign.RIGHT).with(r -> r.since),
+ new Column().header("DESCRIPTION").dataAlign(HorizontalAlign.LEFT).with(this::shortDescription))));
+ }
}
return 0;